Repository navigation
fix(chat): keep Stop ahead of the next message without reordering typing - #1112
Conversation
The composer's Stop now marks its input frame with stop: true. The bridge sends that lone ESC in the pane's serialized turn through send_text, after the settle that follows the pane's last pty keystroke, and records it like pty typing so the next message still waits and checks again for a question. Plain terminal ESC keeps the pty's FIFO order. Fixes #1107.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Summary
Merge Risk: ⚪ Minimal · up to
|
Problem
Pressing Stop in the chat composer and sending a message right after can deliver the message to the agent before the Escape (#1107). The Stop was an unqueued WS
inputof a lone ESC, written into the PTY sidecar, where a successful write only means the bytes were queued in the pipe. The followingsubmitgoes through a herdr RPC after a guessedTYPED_SETTLE_MS(300 ms), on a separate channel, so on a loaded machine the paste can overtake the Escape. CI caught it once on main: run 38584912670 expected"\u001bafter\r"and received"after\u001b\r".Design
shared/protocol.ts: theinputframe gets an optional, documentedstop?: true. Only the composer's Stop sets it:abortTurninPaneTerminal.tsxmarks itsterm.input(ESC), so the ESC still passes the existingonDataguards (hidden/observe/held pane, held-draft rules, sticky-modifier chords), andHerdrSocket.sendInputaddsstop: trueonly for that lone ESC. Older servers ignore the field and keep their current behavior.server/index.ts: an attached-paneinputwithstop: trueand text exactly ESC runs in the pane's serialized queue. It first waits out the same settle thekeyspath uses after the pane's last PTY keystroke (KEY_SETTLE_MS, orTYPED_SETTLE_MSafter an ESC), so it never overtakes typing still in the sidecar. Then it is sent through the authorizedpaneSendTextpath, so a following submit queued behind it waits for it. After that call succeeds it is recorded like PTY typing (lastTyped+typedEscape), sosubmitText/dispatchPendingTextstill waitTYPED_SETTLE_MSand check again for a blocked prompt before pasting. The settle wait is one helper (settleAfterTyping) shared with thekeyspath, soserver/index.tskeeps its fixed-sleep count of 8.inputESC (terminal typing, Vim) stays on the FIFO PTY path, unchanged. The mirrored (no PTY) branch is unchanged.site/demo/transport.tsaccepts the field and types the ESC like any key.Why not #1106
#1106 routed every lone ESC through
paneSendText. That let an ordinary terminal ESC overtake bytes typed just before it that were still in the sidecar (x, ESC,ydelivered as ESC,y,x; in Vimithen ESC could arrive reversed). It also dropped the Stop's settle bookkeeping, which madepending-input.contract.test.tsfail (agent_blockedexpected). Here only the explicit Stop changes path, it waits behind earlier typing, and it keeps the bookkeeping.Tests
server/submit.contract.test.ts: the ported fix(chat): keep Stop ahead of the following message #1106 interleaving test now sends the Stop withstop: true. It holds a PTY ESC until the later RPC paste completes, waits oninput-readyinstead ofBun.sleep(300)(so the file's fixed-sleep baseline drops from 6 to 5), and keeps the exact"\u001bafter\r"assertion.origin/main'sserver/index.ts): fails, received"after\r"instead of"\u001bafter\r".keeps a terminal ESC in order with the typing around it: holds PTY writes until all three frames were written, or until anything sent through herdr reaches the pane. Framesx, ESC,y\rmust arrive as"x\u001by\r". An implementation that moves a plain ESC to send_text would deliver ESC first.server/pending-input.contract.test.ts: the existing Stop settling-gap case runs unchanged for the plain ESC frame, and also runs a second time withstop: true. Its assertions are the same in both runs.src/lib/ws.test.ts: onlysendInput(..., true)putsstop: trueon the wire.scripts/ui-regression.ts: the composer's Escape-with-draft Stop asserts that the frame is{ type: "input", text: ESC, stop: true }.Commands (on isolated check sessions):
git show origin/main:server/index.ts > server/index.ts; bun run check run sh -c 'bun test ./server/submit.contract.test.ts -t "Stop only once the Stop reached|terminal ESC in order"': exit 1. The interleaving test fails ("after\r"received,"\u001bafter\r"expected) and the FIFO test passes (plain ESC order was already correct on main).bun run check run sh -c 'bun test ./server/submit.contract.test.ts ./server/pending-input.contract.test.ts ./server/prompt.contract.test.ts ./server/omo-prompt.contract.test.ts ./server/keys-lifecycle.contract.test.ts ./server/input-membership.contract.test.ts': exit 0, 166 pass / 0 fail.bun run check run sh -c 'bun test ./server/submit.contract.test.ts -t "terminal ESC in order"': exit 1, received"\u001by\rx".bun run check run sh -c 'bun run build && bun scripts/ui-regression.ts && bun scripts/sticky-modifiers-regression.ts': exit 0.bun run typecheck: exit 0.bun run test:unit: exit 0, 3612 pass / 0 fail / 8 skip.Fixes #1107