Repository navigation
fix(terminal): drop terminal questions from the reconnect replay - #36185
KiroCrewCaptain merged 1 commit into
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: removing questions from the replay snapshot on the server fixes the stated cause for every client that reattaches, and a revert undoes it cleanly. Notes
[DESIGN-REVIEWED] 34311e2 Description read[DESCRIPTION-READ] 6f9f16e9f06996f8d9b1b849f545b12a574933a17e7d053f09706c432a06ee97 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS This is a reported defect (#36172), fixed on the one replay path, with tests that pin the exact bytes the replay sends. Nothing blocks. What this change shipsInventory (3 items) — 3 justifiedIntent: after a reload, popout or reconnect, the dashboard terminal's shell prompt no longer holds junk such as
[FIRST-PRINCIPLES-REVIEWED] 34311e2 Description read[DESCRIPTION-READ] 6763598580e15bdc893a855641253430208f1e7911b6bd7404227f5eee86586e That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findings (all downgraded on adjudication)GPT 6.1 flagged blocking issues on This comment is updated in place on each push. Review detailsBLOCKING -- src/kiro_crew/dashboard/handlers/terminal_transport.py:350 -- Preserve unanswered queries emitted while disconnected
Adjudication (Opus 5.5) — is blocking on each finding proportionate?F1 — LOW harm. I confirmed every condition the failure needs. The real fix needs a new "delivered up to" byte offset on the session. It has to be written on the hot output path and at disconnect, and kept consistent with the ring's truncation at False positive or not applicable? A repository writer can comment: |
Code change approver recommendation: ApproveWhy: the decider estimates an 8% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes. The server now strips the questions xterm.js answers (DSR/CPR, DA1/DA2, DECRQM, DECRQSS, OSC 4/10-12 colour queries) from the scrollback snapshot replayed on reattach. Catch-up and live output are untouched. Catch-up accounting uses output_bytes/sent_output_bytes, not the replay length, so dropping bytes shifts no offsets. scrollback has one writer and is read only in _replace_terminal_ws, the single replay path. Each regex branch matches only query sequences, and colour-set and draw sequences are kept. The new test pins the replayed bytes exactly and would fail on base. No auth, protocol or frontend change; the trust surface only shrinks. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
1f8ba44 to
d7103e0
Compare
bolichen97
left a comment
There was a problem hiding this comment.
Read the full diff. The fix is right: removing terminal questions from the replayed scrollback stops a fresh xterm.js from answering them into the shell (#36172). It leaves catch-up bytes alone, and the test pins that the screen, the colour change and the OSC 7 cwd report survive. One part needs a change.
Please replace the regex with a byte scanner. This PR adds _TERMINAL_QUERY_RE = re.compile(...) and _TERMINAL_QUERY_RE.sub(b"", data) in terminal_transport.py. The project does not take new regex-based handling in product code. A pattern over escape sequences is also easy to get subtly wrong in a security-relevant stream.
A small structured pass fits better: walk data and, on ESC (0x1b), look at the next byte.
[: read the CSI. Take an optional private marker (?/>), then parameter bytes (digits and;), then optional intermediate bytes (0x20-0x2f, e.g.$), then the final byte (0x40-0x7e). Drop the whole sequence only for the question forms you listed: finaln, finalc, or intermediate$with finalp. Otherwise copy it through.]: read the OSC up toBELorESC \. Split the body on;and drop it only when the first field is4(with every value?) or10/11/12with?values.P: drop a DCS whose body starts with$q, up toESC \.- Anything else, and any sequence cut off at the end of the buffer, is copied through unchanged, as the regex does today.
That keeps the same behavior, reads as the terminal grammar it implements, and makes the "which forms count" list explicit. The existing test can stay as is. Everything else in the PR is fine.
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (3 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: the terminal reconnect replay drops old terminal queries so a fresh terminal does not type their answers into the shell; live catch-up bytes are unchanged. Test added.
d7103e0 to
6935534
Compare
|
@bolichen97 thanks for the review. Replace the regex with a byte scanner -- fixed in 6935534.
The branch is rebased onto current |
A reattach replays the session's scrollback into a freshly reset xterm.js. xterm.js answers every old OSC 11 / DSR / DA question in it through onData, and the answers reached the shell as typed junk on the prompt (11;rgb:ffff/ffff/ffff;1R). Strip those questions from the replay snapshot. Closes #36172
|
Rebased: main moved in test/test_reply_format_once.py (#36290 fixed main's red #36279, which failed Backend Tests shard 8 on Linux, macOS and Windows and the Coverage Gate here) (9b32941 -> b7a4e1e); CI re-running. Shard 7 was not main's red: attempt 1 hit 120 s timeouts in unrelated tests, attempt 2 lost its self-hosted runner. No change to this PR's three files. |
6935534 to
34311e2
Compare
|
bolichen97
left a comment
There was a problem hiding this comment.
Approve. Thanks for the change. I re-reviewed the whole diff on this head. All checks are green, including Publish readiness signal after its rate-limited run was rerun.
- The regex from our earlier change request is gone: no product file in this diff imports
reor compiles a pattern._strip_terminal_querieswalks eachESCwith plain byte checks._csi_query_endreads the marker, parameters, intermediates and final byte, and looks up the result in_CSI_QUERIES._string_endfinds the BEL or ST that closes an OSC/DCS string, and_is_colour_querysplits the OSC body on;. - It drops only the questions xterm.js answers: DSR/CPR, DA1/DA2, DECRQM, the OSC 4/10/11/12 colour queries and DECRQSS. Look-alikes (
CSI > 4 n, colour sets) and sequences cut off at the ring's end pass through byte for byte, as the second test pins. - The strip runs only on the retained scrollback replayed into a fresh terminal. Catch-up bytes are live output and stay as they are, so a program still running gets its answer. Nothing is refused.
Auto-merge is already on, so I left it as it is.
Problem / Motivation
Goal: Opening or reattaching the dashboard terminal no longer leaves junk like
11;rgb:ffff/ffff/ffff;1Rtyped on the shell prompt.When the user opens the terminal panel, the zsh prompt already holds text they never typed:
11;rgb:ffff/ffff/ffff;1R11;rgb:ffff/ffff/ffff4;1R;1R;1. Pressing Enter runs it, and zsh printscommand not found: 11,no such file or directory: rgb:ffff/ffff/ffff, and so on. The text is the terminal's own answers to old questions: the background colour (OSC 11) and the cursor position (DSR 6).Why it matters
Anyone whose shell, prompt theme or tools ask the terminal a question (colour probe, cursor position, device attributes) gets junk on the prompt after a reload, a popout or a reconnect. It reads like the dashboard typed into their shell, and one Enter runs it as a command.
Not a goal
onDatawiring, the takeover protocol, or any auth or origin check on the terminal socket.0x9b/0x9d); real output uses the 7-bitESCforms.What changed (motivation → approach → change)
Symptom → cause → fix:
_replace_terminal_ws)reset()s xterm.js and writes the old bytes into itterm.onData, which sends to the PTYterminal_transport.pygains_strip_terminal_queries(re-exported through theterminal.pyfacade), a byte scanner that walks eachESC, reads the CSI, OSC or DCS by the terminal grammar, and removes only the questions xterm.js answers (DSR/CPR, DA1/DA2, DECRQM, DECRQSS, OSC 4/10/11/12 colour queries) from the replay snapshot. Look-alikes such asCSI > 4 n(a key-modifier reset) and colour SETs, and any sequence cut off at the end of the buffer, pass through unchanged. A question draws nothing, so the replayed screen is the same. Catch-up bytes produced during the takeover itself are left as they are: they are live output and may still want an answer.The fix sits on the server so every client that reattaches (page reload, popout, mobile, a second window) gets clean history, with no frontend change.
Backwards compatibility
Compatible: replay drops only terminal questions, which never change the screen; live output, catch-up bytes and every other replayed byte are sent unchanged.
Removes nothing: no route, key, frame type or public function is removed or renamed; the socket protocol is unchanged.
Tests
test_replay_drops_terminal_questions_but_keeps_the_screen(test/test_terminal_handler_pty_writes.py): a scrollback holding a prompt, ten question kinds and an OSC 7 cwd report replays as the prompt and the cwd report only, and the new socket still takes ownership.test_replay_strip_keeps_everything_that_is_not_a_question(same file): look-alikes, colour SETs, a DECRQSS ended by BEL, and cut-off sequences pass through byte for byte.Proof: PROVEN test/test_terminal_handler_pty_writes.py::TestWriteSerialization::test_replay_drops_terminal_questions_but_keeps_the_screen (head 34311e2)
Local:
scripts/local-gate.py(backend related 110 passed, frontend related 14672 passed),make build, flake8, isort, black, mypy,tsc -p tsconfig.app.json, semgrep (semgrep/, diff-scoped),test/test_flake_pattern_ratchet.py. The new test is a pure in-memory mock with no timing or ordering dependency.Manual verification
N/A — unit coverage sufficient: the defect is which bytes the replay sends, and the test asserts those bytes exactly. Repro steps are in #36172.
Screenshots / video
N/A — backend-only diff; no frontend file changed.
Related Issues
Closes #36172
Sibling sweep
Swept: git grep -nE "scrollback" -- 'src/**/*.py'
Sibling: src/kiro_crew/dashboard/handlers/terminal_transport.py -- changed here
Sibling: src/kiro_crew/sprites_session/terminal.py -- not affected -- runs as the PTY child and keeps no buffer; its output rides the same transport replay
Sibling: website/src/utils/terminalRegistry.ts -- not affected -- writes only server frames into xterm; the frontend keeps no replay buffer of its own
Pattern harvest
Not generalizable: the terminal has one replay path (
_replace_terminal_ws), and this PR fixes it there.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license.