Skip to content

engine: a reloaded page is told about a prompt the turn is still waiting on (#130) - #144

Merged
Lexus2016 merged 1 commit into
mainfrom
fix/130-replay-input-needed
Nov 16, 2026
Merged

Lexus2016 merged 1 commit into
mainfrom
fix/130-replay-input-needed

Conversation

@Lexus2016

Copy link
Copy Markdown
Owner

Follow-up to #130 / #143, the gap stated in the #143 description and in the issue comment: after a full page reload, a pending input_needed banner was not re-sent.

What was wrong

The subscription engine announces a blocking TUI prompt once (input_needed) and withdraws it once (input_resolved). A page reloaded while the turn waits gets a new socket that saw neither frame, plus a fresh tab state with nothing to redraw the banner from. The chat showed a running turn and no question. WsProxy replay does not cover this: it only buffers frames sent while no socket was attached, and this frame went out to the socket that existed then.

The fix

  • Engine: runInteractiveSingle takes an optional onPromptState(frame|null), called from wsSendAll, the one place both edges go through. It fires only for those two frame types, so a future frame routed through there cannot erase an open prompt. The engine's finally already sends the closing edge on every exit path.
  • engine-prompts.js (pure, no sockets): keeps the open prompt per session. All three call sites feed it: chat, Kanban task and Telegram.
  • subscribe_session replays it only:
    • without noCatchUp, because a background tab that never reloaded still holds the prompt and would just be notified twice;
    • while isSessionLive(), so a prompt left behind by a crash between the two edges is dropped rather than shown.
  • The replayed frame is the original plus tabId (the session id when the engine sent none) and replayed: true. The input_needed shape is otherwise unchanged.

Tests

  • test/engine-prompt-replay.test.js (new, real server and tmux, self-skips without tmux, ~16 s). The fake claude draws the real trust screen, so the turn waits on a prompt. Results:

    • a foreground subscribe gets the prompt, with the right tab and text;
    • a noCatchUp subscribe does not;
    • a subscribe after the turn ended does not.

    With the replay line removed, exactly the two positive checks fail.

  • test/engine-prompts.test.js (new): drives the store and pins that every runInteractiveSingle call site feeds it, plus the !noCatchUp / isSessionLive guards.

  • test/claude-firstrun.test.js: onPromptState hears the prompt open, then close, on a live pane.

  • Mutation checks: removing any one call site's wiring, the noCatchUp guard, the liveness check, or the engine callback each turns a test red.

npm test is green locally (TEST_PORT=4391; another session on this machine was running the suite on the default ports at the same time).

An independent review (agy) raised six points. One became the type guard above. The others do not hold here:

  • tabs are keyed by session id, and the client takes d.tabId || activeTabId;
  • isSessionLive reads the turn registries, not session existence;
  • the Telegram params object carries sessionId;
  • every exit path clears the entry, so there is no leak.

Not covered

The browser rendering of the replayed frame is the existing input_needed handler (renderInputNeededCard). The integration test proves the server sends it to a reloaded page, but I did not drive a real browser through a reload.

…ing on (#130)

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 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-16T07:55:05.268170Z 765c16e 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.

@Lexus2016
Lexus2016 merged commit f46ddf5 into main Nov 16, 2026
3 checks passed
@Lexus2016
Lexus2016 deleted the fix/130-replay-input-needed branch November 16, 2026 07:57
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.

1 participant