Skip to content

engine: a finished turn no longer reads busy for ten minutes (#130) - #143

Merged
Lexus2016 merged 2 commits into
mainfrom
fix/130-engine-busy-detector
Nov 15, 2026
Merged

Lexus2016 merged 2 commits into
mainfrom
fix/130-engine-busy-detector

Conversation

@Lexus2016

@Lexus2016 Lexus2016 commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Fixes #130.

What was wrong

paneBusy() gates every exit of the subscription engine's poll loop except the idle watchdog: the turn-end break is endTurnSeen && !busy && !gotNewBytes, and the quiet safety net only counts polls where !busy. A pane that reads busy forever therefore holds a turn the TUI has already finished open for CLAUDE_IDLE_TIMEOUT_MS (10 min), then ends it as "interactive engine timed out". That is the reported symptom: the live pane shows the answer, the web UI keeps waiting.

Two signals could read a finished pane as busy indefinitely:

  1. The elapsed-timer regex ran over the whole pane. /\d+s\s*[·)]/ was meant for the spinner line, but CLI 2.1.311 renders a finished subagent as `Done (${uses} · ${tokens} · ${duration})` (the template is in the shipped bundle), so ⎿ Done (3 tool uses · 12.4k tokens · 8s) matches 8s) for as long as it stays on screen.
  2. Animation was any change of the whole pane. A statusline clock below the input box, or a person typing a draft into the live pane, changes the capture between polls and read as a spinner.

The fix

  • When an input box is recognised (_conversationAboveInputBox), both content signals look only at the conversation above it, and the timer signal only at the spinner: an ellipsis verb, then (…Ns · / …Ns) (SPINNER_TIMER_RE), in the last few lines above the box.
  • When no box is recognised (a dialog replaced it), the whole pane is diffed as before, but the timer must still be spinner-shaped. With the old regex a Done (… 8s) line above a permission dialog read as busy. That forces awaiting false, so input_needed was never sent, and the turn hung on exactly the question the user was meant to answer: the "back-and-forth" case in the report.
  • The box detector is separate from _inInputBox()/RULE_RE, which stay unchanged. Widening RULE_RE lets a dialog under a labeled header read as the input box and silences the Terminal Access For Prompt Interactions #20 prompt detector. The box's lower rule must sit within 6 lines of the bottom. The top rule is the nearest rule above it, may carry a label (a chat opened with --name draws its title into it), and needs only 3 leading dashes. A mismatch returns null (pre-fix behaviour) and never searches further up the history.
  • esc to interrupt is still matched on the whole pane.
  • The idle-timeout error now says which signal last held the pane busy (The pane still looked busy (spinner|animation|legacy-marker).), so if this recurs the report names the cause.

The idle reaper (#141) calls the same paneBusy() (it also has its own isLive guard for a running turn), so a finished pane with a Done (…) line on screen is now reapable too.

Reviewed by an independent model (agy) over two rounds. Round 1: the RULE_RE widening, a mid-history box match and the history-wide spinner scan were all fixed. Round 2: narrow labeled rules, the no-box Done case and an indented caret were fixed. Its remaining points (an early return null falling back to the old behaviour; the reaper relying on isLive) are the safe direction by design.

The other two points in the issue

  • awaitAnnounced stuck after an answer: already handled. awaiting is !busy && !gotNewBytes && paneAwaitingInput(pane) (claude-interactive.js, poll loop), so the first poll with new transcript bytes after an answer clears it and sends input_resolved. The case where it could stay set was the stuck-busy pane this PR fixes.
  • Frames only going to the original socket: on the chat path the engine's ws is the turn's WsProxy (server.js params.ws: proxy). It buffers while the browser is away, and subscribe_session re-attaches it to the new socket. done is also broadcast to every watcher (broadcastToSessionExcept, both success and error paths). Still open: after a full page reload, a pending input_needed banner is not re-sent to the new page. That is a separate follow-up.

Tests

test/pane-busy.test.js (new, wired into npm test, 22 cases):

  • Idle: finished-subagent line, ticking statusline, typed draft, unlabeled box, ellipsis+seconds higher up in a finished answer, a dialog under a Done (… 8s) line (which is also announced as a prompt).
  • Busy: spinner line, spinner tick, new text, the older Cogitating… (8s · esc to interrupt) shape, the reaper suite's bare marker, a spinner below a framed quote with no box, a narrow labeled top rule over a history prompt.
  • Widgets: a dialog under a labeled header rule is still a widget.

Mutation-checked: each of the 7 constraints reverted on its own turns at least one case red.

npm test is green locally (Node 26). Unrelated: test/global-workspace.test.js is flaky on its own (1 of ~7 runs). Its in_progress fixtures race the server's 3 s startup recovery (server.js startup setTimeout). That is reported separately and not touched here.

I could not reproduce the reporter's exact session. The fix targets the cause I can demonstrate from the code and the CLI's own output format.

paneBusy() gates every exit of the subscription poll loop except the idle
watchdog, so a pane that reads busy forever ends a turn the TUI already
finished as a 10-minute timeout while the live pane shows the answer.

- The elapsed-timer signal matched the whole pane. CLI 2.1.311 renders a
  finished subagent as "Done (3 tool uses · 12.4k tokens · 8s)", which
  matched for as long as it stayed on screen. It now matches only a
  spinner-shaped line (ellipsis verb), above the input box.
- The animation signal diffed the whole pane, so a statusline clock or a
  draft typed into the live pane read as a spinner. It now diffs only the
  conversation above the input box; no box on screen falls back to the
  whole pane as before.
- RULE_RE accepts a labeled rule: a chat opened with --name draws its title
  into the box's top rule, and the box was invisible in exactly the
  studio's chats (which also let a numbered draft read as a #20 widget).
- The idle-timeout error names the signal that last held the pane busy.

test/pane-busy.test.js pins both directions; each change reverted alone
turns cases red.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T13:08:23.886305Z 8d2a4f9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

- RULE_RE is back to unlabeled: widening it let a dialog under a labeled
  header read as the input box and silenced the #20 prompt detector. The
  box is found by its own BOX_RULE_RE / _conversationAboveInputBox.
- The box must sit at the bottom (lower rule within 6 lines), its top rule
  is the NEAREST rule above (3 dashes suffice for a narrow labeled rule),
  and a mismatch returns null instead of searching into the history.
- The spinner is looked for in the last lines above the box only.
- With no box (a dialog), the timer must still be spinner-shaped: a
  finished subagent line above a permission dialog read as busy and kept
  input_needed from ever being sent.
@Lexus2016
Lexus2016 merged commit 3972899 into main Nov 15, 2026
3 checks passed
@Lexus2016
Lexus2016 deleted the fix/130-engine-busy-detector branch November 15, 2026 13:51
Lexus2016 added a commit that referenced this pull request Nov 16, 2026
…ing on (#130) (#144)

The subscription engine announces a blocking TUI prompt once (input_needed)
and withdraws it once (input_resolved). A page reloaded in between got a new
socket that saw neither frame and a fresh tab state with nothing to redraw
the banner from, so the chat showed a running turn and no question. This is
the part #143 left open.

- The engine reports both edges through an optional onPromptState callback,
  from wsSendAll, the one place both frames go through.
- engine-prompts.js keeps the open prompt per session; all three
  runInteractiveSingle call sites (chat, Kanban task, Telegram) feed it.
- subscribe_session replays it only without noCatchUp (a background tab that
  never reloaded still has it) and only while isSessionLive(), so a prompt
  left by a crash between the edges is dropped, not shown.

test/engine-prompt-replay.test.js boots a real server whose fake claude draws
the trust screen: a foreground subscribe gets the prompt, a noCatchUp one and
one after the turn ended do not. It fails on the two positive checks without
the replay.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Live pane and web UI out of sync: task shown finished in live pane, web UI stays waiting

1 participant