Skip to content

fix(terminal): skip an escape tail an abandoned hidden-output restore would print - #33905

Merged
nwparker merged 2 commits into
mainfrom
nwparker/issue-33766-display-interleave
Oct 26, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/issue-33766-display-interleave

Conversation

@nwparker

@nwparker nwparker commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​209 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​207
Prod 17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​200 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​190

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 ;242m inside a diff line or ial refactoring PRs | cleanup-dumb-exports in 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

  • Before: for a hidden pane, the main process parses each chunk into its own copy of the terminal (its model), then drops it instead of sending it to the renderer. On reveal, sending resumes with the next chunk, wherever it starts. When the reveal snapshot can't be applied ("main recovery was unavailable", the R5 retries running out, or the deadline abandon path), abandonHiddenOutputRestoreAndDrainPendingForeground writes a parser reset and then the queued live bytes. If the dropped bytes had ended inside an escape sequence, xterm printed its tail.
  • After:
    • Main (delivery/pty-gap-escape-state.ts, accept.ts):
      • Tracks each PTY's escape-parser state with advanceTerminalEscapeBoundary over every accepted payload, whether delivered or dropped.
      • Every hidden drop (recordHiddenRendererPtyDataDrop) and the pending-cap droppedOutput path mark a gap.
      • The first payload delivered after a gap carries gapEscapeState, the state before that payload, only when it is non-empty.
      • The field stays with the start of a pending batch through flush, immediate send and exit drain; flush remainders never carry it.
      • Main never trims bytes.
    • Renderer:
      • PtyDataMeta.gapEscapeState reaches PendingHiddenOutputRestoreChunk, but only when the queued data is the chunk exactly as it arrived.
      • On the abandon path, after the gap reset (not when an intact replay tail is preserved), a labeled chunk the snapshot did not slice has the continuation removed by 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.
      • Without the field nothing changes, so remote hosts and older mains behave as before.

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 as build 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 real registerPtyHandlers delivery path: hide the pane, drop a chunk that ends inside an OSC title, an SGR sequence, or right after a bare ESC, then reveal.

    • The first delivery is untrimmed and labeled \x1b], \x1b[ or \x1b.
    • build done\a after a clean boundary carries no label.
  • In pty-connection-hidden-restore-loss-disclosure.test.ts (R5 local abandon):

    • Labeled OSC and SGR continuations print no tail, and the banner and prompt still show.
    • Unlabeled build done\a survives.
    • A successful restore whose snapshot sits at the gap with pendingEscapeTailAnsi writes 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Mixed versions: one new optional IPC field. Older renderers ignore it, and with no field the renderer does nothing.
  • Remote/SSH: remote streams don't pass through this gate, so they are unchanged.
  • Performance: one boundary scan per accepted chunk in main. ESC-free chunks take a fast path, and only the state is kept, never the payload.
  • Mobile: unaffected. Mobile reads main's model, which still receives every byte.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

PTY delivery now tracks open escape state across renderer data gaps and includes that state in delivered payloads. The renderer carries the metadata through restore queues and skips escape continuations when replaying pending output after an abandoned restore. Tests cover split OSC, SGR, and CSI sequences, clean drop boundaries, and snapshot slicing.

Priority: Pending latest changes

Merge Risk: Moderate · up to c8120

The static-analysis check blocks merging until the switch is made exhaustive. The identified edge case in resumed terminal output should be tracked separately.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 26.92% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 26 functions across 19 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title follows the conventional commit style and names the main change: the abandoned hidden-output restore now skips an escape sequence tail that it would otherwise print. The changeset matches th…
Linked Issues check Passed Issue #33766 has no explicit acceptance criteria or coding requirements. The PR directly addresses its reported terminal display symptom. Main tracks the escape state across hidden PTY drops, carries …
Out of Scope Changes check Passed The changes remain within the scope of #33766. The modified main, preload, renderer, shared escape parser, and test files implement or verify hidden local PTY recovery after a dropped byte stream. No …
Description check Passed The pull request description is complete and follows the required structure. It explains the user impact, changes, rationale, linked issue, testing, compatibility, performance, and checklist status. I…
Full details: Title check

Explanation

The title follows the conventional commit style and names the main change: the abandoned hidden-output restore now skips an escape sequence tail that it would otherwise print. The changeset matches this, adding gap escape-state tracking in main and an abandon-path skip in the renderer, with tests. The title is specific to the fix and does not list files.

Full details: Linked Issues check

Explanation

Issue #33766 has no explicit acceptance criteria or coding requirements. The PR directly addresses its reported terminal display symptom. Main tracks the escape state across hidden PTY drops, carries the state to the renderer, and the abandon path skips only the stale continuation. Tests cover split OSC, SGR, and CSI sequences, plus clean-boundary output. The inspected tests also verify that resumed data remains untrimmed in main and that the renderer removes only the stale tail.

Full details: Out of Scope Changes check

Explanation

The changes remain within the scope of #33766. The modified main, preload, renderer, shared escape parser, and test files implement or verify hidden local PTY recovery after a dropped byte stream. No unrelated product behavior or unrelated feature is demonstrated.

Full details: Description check

Explanation

The pull request description is complete and follows the required structure. It explains the user impact, changes, rationale, linked issue, testing, compatibility, performance, and checklist status. It records that manual testing was not performed and that CI will cover incomplete local checks. The linked issue uses Refs #33766 instead of Fixes #, and the AI Disclosure section is not filled, but these do not prevent review.

Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

… 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.
@nwparker
nwparker force-pushed the nwparker/issue-33766-display-interleave branch from 25933c8 to c8120bf Compare October 26, 2026 13:11
@nwparker nwparker changed the title fix(terminal): resume delivery after a hidden drop at a clean escape boundary fix(terminal): skip an escape tail an abandoned hidden-output restore would print Oct 26, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Commits

Reviewing files that changed from the base of the PR and between 639d529 and c8120bf.

Files selected for processing: 19
  • src/main/ipc/pty/delivery/accept.ts
  • src/main/ipc/pty/delivery/exit.ts
  • src/main/ipc/pty/delivery/flush.ts
  • src/main/ipc/pty/delivery/payload.ts
  • src/main/ipc/pty/delivery/pending.ts
  • src/main/ipc/pty/delivery/pty-gap-escape-state.ts
  • src/main/ipc/pty/delivery/pty-hidden-delivery-gate.ts
  • src/main/ipc/pty/delivery/pty-ipc-gap-escape-state.test.ts
  • src/main/ipc/pty/delivery/pty-pending-data-drain-contract.ts
  • src/main/ipc/pty/session.ts
  • src/preload/api/pty-api.ts
  • src/preload/api/pty-bridge-stream-and-serialization.ts
  • src/renderer/src/components/terminal-pane/pty-connection-hidden-restore-loss-disclosure.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-abandon.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-chunk.ts
  • src/renderer/src/components/terminal-pane/pty-connection/live-data-callback.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pending-hidden-output-restore-chunk.ts
  • src/renderer/src/components/terminal-pane/pty-dispatcher.ts
  • src/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.

Comment on lines +179 to +215
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
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major · Functional Correctness · Quick win

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 change
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
}
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
🪛 GitHub Actions: PR 33905 | source d1eda39 | workflow d1eda39 | unit full / 13_static analysis and typecheck.txt

[error] 179-179: Oxlint reported a non-exhaustive switch: cases "oscEsc" and "stringEsc" are not matched. The lint step failed with exit code 1.

🪛 GitHub Actions: PR 33905 | source d1eda39 | workflow d1eda39 | unit full / static analysis and typecheck

[error] 179-179: Oxlint reported a non-exhaustive switch: cases "oscEsc" and "stringEsc" are not matched. The oxlint command failed with exit code 1.

Source: Pipeline failures

@nwparker
nwparker merged commit a93f73c into main Oct 26, 2026
54 checks passed
@nwparker
nwparker deleted the nwparker/issue-33766-display-interleave branch October 26, 2026 13:33
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