Repository navigation
fix(terminal): skip an escape tail an abandoned hidden-output restore would print - #33905
Conversation
Walkthrough
Priority: Merge Risk:
|
… would print (#33766) Main drops a hidden pane's renderer delivery after its model ingests the bytes, so the first chunk sent on reveal can begin inside an escape whose start was dropped. When the restore is abandoned, the renderer resets its parser and writes the queued chunks, and xterm printed the tail (';242m', the rest of a Codex OSC title). Main tracks each PTY's escape state over every accepted payload and labels the first delivery after a hidden or pending-cap drop with the escape it resumes inside (gapEscapeState). Only the abandon path strips that continuation; a successful restore keeps every byte so the snapshot's pending escape tail can complete. No label means no change.
25933c8 to
c8120bf
Compare
There was a problem hiding this comment.
Actionable comments posted: 1

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
f26b6de4-d815-47b2-b7b7-c47b258d8e62
Files selected for processing: 19-
src/main/ipc/pty/delivery/accept.tssrc/main/ipc/pty/delivery/exit.tssrc/main/ipc/pty/delivery/flush.tssrc/main/ipc/pty/delivery/payload.tssrc/main/ipc/pty/delivery/pending.tssrc/main/ipc/pty/delivery/pty-gap-escape-state.tssrc/main/ipc/pty/delivery/pty-hidden-delivery-gate.tssrc/main/ipc/pty/delivery/pty-ipc-gap-escape-state.test.tssrc/main/ipc/pty/delivery/pty-pending-data-drain-contract.tssrc/main/ipc/pty/session.tssrc/preload/api/pty-api.tssrc/preload/api/pty-bridge-stream-and-serialization.tssrc/renderer/src/components/terminal-pane/pty-connection-hidden-restore-loss-disclosure.test.tssrc/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-abandon.tssrc/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-chunk.tssrc/renderer/src/components/terminal-pane/pty-connection/live-data-callback.tssrc/renderer/src/components/terminal-pane/pty-connection/pending-hidden-output-restore-chunk.tssrc/renderer/src/components/terminal-pane/pty-dispatcher.tssrc/shared/terminal-partial-escape-tail.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
-
| switch (state) { | ||
| case 'esc': | ||
| if (code === ESC) { | ||
| return i | ||
| } | ||
| state = stateAfterEscByte(code) | ||
| if (state === 'ground') { | ||
| return i + 1 | ||
| } | ||
| break | ||
| case 'escIntermediate': | ||
| if (code === ESC) { | ||
| return i | ||
| } | ||
| if (code >= 0x30 && code <= 0x7e) { | ||
| return i + 1 | ||
| } | ||
| break | ||
| case 'csi': | ||
| if (code === ESC) { | ||
| return i | ||
| } | ||
| if (code >= 0x40 && code <= 0x7e) { | ||
| return i + 1 | ||
| } | ||
| break | ||
| case 'osc': | ||
| case 'string': | ||
| if (code === BEL && state === 'osc') { | ||
| return i + 1 | ||
| } | ||
| // Keep an ESC that may start a new sequence; if it was a split ST, its backslash later completes a no-op ST. | ||
| if (code === ESC) { | ||
| return chunk.charCodeAt(i + 1) === 0x5c ? i + 2 : i | ||
| } | ||
| break | ||
| } |
There was a problem hiding this comment.
Fix the non-exhaustive switch (state). It fails the Oxlint CI step.
The switch in openEscapeContinuationLength has no oscEsc or stringEsc case. The pipeline log reports this non-exhaustive switch at line 179 and the lint step exits with code 1, so the PR cannot merge.
The two states are unreachable at runtime. STATE_BY_PREFIX never maps to them, and stateAfterEscByte never returns them. Add an explicit no-op case so the switch is exhaustive and the intent is documented.
🐛 Proposed fix
-
case 'osc': case 'string': if (code === BEL && state === 'osc') { return i + 1 } // Keep an ESC that may start a new sequence; if it was a split ST, its backslash later completes a no-op ST. if (code === ESC) { return chunk.charCodeAt(i + 1) === 0x5c ? i + 2 : i } break + case 'oscEsc': + case 'stringEsc': + // Unreachable: the ESC inside OSC/string is resolved in the 'osc'/'string' case above. + break }
Committable suggestion
-
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.Suggested changeswitch (state) { case 'esc': if (code === ESC) { return i } state = stateAfterEscByte(code) if (state === 'ground') { return i + 1 } break case 'escIntermediate': if (code === ESC) { return i } if (code >= 0x30 && code <= 0x7e) { return i + 1 } break case 'csi': if (code === ESC) { return i } if (code >= 0x40 && code <= 0x7e) { return i + 1 } break case 'osc': case 'string': if (code === BEL && state === 'osc') { return i + 1 } // Keep an ESC that may start a new sequence; if it was a split ST, its backslash later completes a no-op ST. if (code === ESC) { return chunk.charCodeAt(i + 1) === 0x5c ? i + 2 : i } break } switch (state) { case 'esc': if (code === ESC) { return i } state = stateAfterEscByte(code) if (state === 'ground') { return i + 1 } break case 'escIntermediate': if (code === ESC) { return i } if (code >= 0x30 && code <= 0x7e) { return i + 1 } break case 'csi': if (code === ESC) { return i } if (code >= 0x40 && code <= 0x7e) { return i + 1 } break case 'osc': case 'string': if (code === BEL && state === 'osc') { return i + 1 } // Keep an ESC that may start a new sequence; if it was a split ST, its backslash later completes a no-op ST. if (code === ESC) { return chunk.charCodeAt(i + 1) === 0x5c ? i + 2 : i } break case 'oscEsc': case 'stringEsc': // Unreachable: the ESC inside OSC/string is resolved in the 'osc'/'string' case above. break }
🧰 Tools
Source: Pipeline failures
ELI5
While a terminal tab is in the background, Orca stops sending its output to the screen. When you come back, sending can resume partway through a color code or a title update. If the screen then can't be rebuilt from Orca's saved copy, the second half of that code was drawn as text, for example
;242minside a diff line orial refactoring PRs | cleanup-dumb-exportsin a Codex input row. Now the main process labels where sending resumed inside such a code, and the screen skips exactly that leftover when it has to carry on without the saved copy.What Changed
abandonHiddenOutputRestoreAndDrainPendingForegroundwrites a parser reset and then the queued live bytes. If the dropped bytes had ended inside an escape sequence, xterm printed its tail.delivery/pty-gap-escape-state.ts,accept.ts):advanceTerminalEscapeBoundaryover every accepted payload, whether delivered or dropped.recordHiddenRendererPtyDataDrop) and the pending-capdroppedOutputpath mark a gap.gapEscapeState, the state before that payload, only when it is non-empty.PtyDataMeta.gapEscapeStatereachesPendingHiddenOutputRestoreChunk, but only when the queued data is the chunk exactly as it arrived.skipOpenEscapeContinuation(shared). That cut ends at the terminator (consumed), at ST (consumed), or at an ESC that starts a new sequence (kept). An escape still open at the end of a chunk is carried into the next one.Why
Only main sees the bytes it dropped, so only main knows whether the resumed stream starts inside an escape. Main can't trim the bytes itself: a successful restore whose snapshot was captured at the gap carries the open escape as
pendingEscapeTailAnsi, and it needs every continuation byte to complete it. Main's model can lag delivery, so that snapshot can predate the resumed chunk. Labelling the resume point and stripping only on the abandon path is exact on both paths.I considered and rejected a renderer-only heuristic (strip a leading
;…m, or text up to BEL/ST, after any gap). It ate real output such asbuild done\a.The hydration double-write half of #33766 (doubled and ghosted TUI frames after a reveal) ships separately.
Linked Issue
Refs #33766
Visual Proof
N/A. This is a byte-stream fix. The tests render the written bytes in a headless xterm and assert that the cut-off tail is not printed.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
New
src/main/ipc/pty/delivery/pty-ipc-gap-escape-state.test.ts. It drives the realregisterPtyHandlersdelivery path: hide the pane, drop a chunk that ends inside an OSC title, an SGR sequence, or right after a bare ESC, then reveal.\x1b],\x1b[or\x1b.build done\aafter a clean boundary carries no label.In
pty-connection-hidden-restore-loss-disclosure.test.ts(R5 local abandon):build done\asurvives.pendingEscapeTailAnsiwrites the labeled continuation intact, with no tail and no banner.pnpm check:changed --maxWorkers=2: the changed-code quality gate passes after fixing test casts; the full run was still going under local load (avg ~70) when pushed, so CI covers typecheck and the suite.Platform: macOS. The change is platform-neutral.
Review
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)