TUI: fix hang on second agent submission
ober
a5b1d0d9b5cb6d862b96c4547b0e6a842244d02a
--- a/src/jcode/ui/tui.ss +++ b/src/jcode/ui/tui.ss @@ -797,13 +797,23 @@ ;; Capture current generation; if the user ESCs while we're blocked in ;; the pre-stream "thinking" phase, main bumps gen and ignores our ;; future events. We still abort cleanly on the next callback. - (let ((gen (tui-run-gen))) + ;; + ;; current-error-port and current-log-level are thread-local parameters + ;; in Chez, so a spawned worker does NOT see the main thread's redirect. + ;; Without capturing here, log-info calls in the worker fprintf to the + ;; real TTY that termbox owns in raw mode — the second invocation hangs + ;; when the TTY's output buffer backs up. + (let ((gen (tui-run-gen)) + (err-port (current-error-port)) + (log-lvl (current-log-level))) (spawn (lambda () (tui-log "worker: entered gen=~a main-thread=~a" gen (*main-thread*)) (try (parameterize - ((current-provider-override p-override) + ((current-error-port err-port) + (current-log-level log-lvl) + (current-provider-override p-override) (current-model-override m-override) (current-stream-cb (lambda (token)