Repository navigation
fix(terminal): one process-boundary ground for every known or proven boundary - #22735
Conversation
A durable checkpoint was folded from the previous checkpoint plus recorded output, so it inherited that checkpoint's modes forever. After a daemon restart killed a full-screen TUI and a new process started inline, the chain kept the dead TUI's alt screen and mouse tracking (?1049h ?1003h ?1006h) while the live emulator was clean. Every reattach and getBufferSnapshot served the stale chain, the renderer re-armed mouse tracking, and wheel scrolling went to a program that never asked for it: scrolling froze. Each full checkpoint is now the live snapshot verbatim (screen, layout, alt frame, modes, owner) with only the normal-buffer rows live has evicted taken from the durable replay. A checkpoint can no longer carry a dead process's modes, and checkpoints already poisoned on disk heal on the next compaction. - The first fold after a cold restore replays the same seed segments live was given, so rows line up even over a dead TUI's alt screen. - Idle zero-record folds keep the disk copy when it already agrees with live, so quit and relaunch bursts don't replay every session. - Held teardown bytes are already in the drained records and the live snapshot, so they are no longer replayed twice or appended as a tail. - The bounded getBufferSnapshot path honors the requested depth even when the live window is deeper, without phantom link rows. - The fold's ownership scanner and frame merge are removed; owner and frame come from live.
…boundary Three copies of the "the process that armed these modes is gone" reset had drifted: the cold-restore seed cleared only pen and mouse, the recovery barrier used the renderer's dead-TUI profile, and the cold-restore payload had none. A cold restore therefore left the dead process's focus reporting, bracketed paste, application cursor and keypad modes armed in the live emulator, the first checkpoint, and main's mirror. And the seed wrote the dead process's torn escape after the reset, so the new shell's first bytes could complete it (for example retitling the pane). PROCESS_BOUNDARY_GROUND replaces them: CAN, leave the alt screen without moving the normal-buffer cursor, every mouse protocol and encoding off, focus/paste/app-cursor/keypad off, cursor shown and style reset, kitty popped, SGR reset, grounded DECSC. It stays inert for the lifecycle scanner. The seed, the recovery barrier, and the cold-restore payload all use it, and the seed no longer carries the torn tail. The first fold after a cold restore now always rebases on live, because focus and keypad are not in TerminalModes and the zero-record shortcut could not see them differ.
There was a problem hiding this comment.
ℹ️ No critical issues — minor suggestions inline.
Reviewed changes
- One process-boundary ground: new
PROCESS_BOUNDARY_GROUNDinsrc/shared/terminal-mode-reset-profiles.tsreplaces bothCOLD_RESTORE_SEED_MODE_RESETand the recovery barrier's use of the renderer'sPOST_REPLAY_DEAD_TUI_RESET; it adds focus reporting, bracketed paste, application cursor/keypad, legacy mouse encodings, a leading CAN, and a DECSC-before-?1049l. - Cold-restore seed:
getRecoveredHistorySeedSegmentsnow appends the ground and dropspendingEscapeTailAnsi, so a new process never completes the dead process's torn escape. - Cold-restore payload:
buildColdRestorePayloadappends the ground, so main's mirror — not only the renderer's reset — gets grounded. - Forced first-fold rebase:
buildDurableCheckpointSnapshotskips the disk-agrees shortcut whenpendingRecordsAreComplete(take.seq === 1), because focus/keypad are invisible toTerminalModes. - Tests: new
process-boundary-ground.test.tsplus updates pinning the ground at the seed, scanner, barrier and profile layers.
I verified the load-bearing ?1049l claim against xterm and xterm.js source: the saved-cursor register is per-buffer and ?1049l restores unconditionally, so the DECSC ordering is correct on both buffers.
ℹ️ The renderer's dead-TUI reset is deliberately left un-grounded
The PR grounds every daemon boundary but leaves POST_REPLAY_DEAD_TUI_RESET (src/shared/terminal-mode-reset-profiles.ts:28) without ?1l/?66l/?2004l; the body describes that profile as the policy "for hosts without a daemon model." On such a host, does a daemon-side ground still reach the pane on the dead-TUI boundary, or is grounding the renderer profile a follow-up? This is a scope question with no line to anchor.
Technical details
# Renderer dead-TUI reset scope
## Affected sites
- `src/shared/terminal-mode-reset-profiles.ts:28` — `POST_REPLAY_DEAD_TUI_RESET` = `?1049l` + `POST_REPLAY_REATTACH_RESET`; includes `?1004l` but not `?1l`/`?66l`/`?2004l`/`?1005l`/`?1015l`.
- `src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-snapshot.ts:154` — used when `terminalOwner === 'shell'` and alt-screen.
- `src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-follow-reset.ts:148` — same for the reattach reset sequence.
## Required outcome
- Confirm whether the daemonless path reaches a state where a dead TUI's app cursor/keypad/paste bits persist in the renderer's xterm, or whether some daemon ground always precedes it.
## Open questions for the human
- Is the renderer profile intended to remain the boundary reset for daemonless hosts indefinitely, or is it a follow-up?DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| // Why no pendingEscapeTailAnsi: every seed starts a new process, whose first bytes | ||
| // must not complete an escape the dead one left half-written. | ||
| const [firstRecovered, ...remainingRecovered] = recovered | ||
| const groundedRecovered = firstRecovered | ||
| ? [`${RESET_GRAPHIC_RENDITION}${firstRecovered}`, ...remainingRecovered] | ||
| : [] | ||
| return [...groundedRecovered, COLD_RESTORE_SEED_MODE_RESET, ...(escapeTail ? [escapeTail] : [])] | ||
| return [ | ||
| `${RESET_GRAPHIC_RENDITION}${firstRecovered}`, | ||
| ...remainingRecovered, | ||
| PROCESS_BOUNDARY_GROUND |
There was a problem hiding this comment.
The seed now drops pendingEscapeTailAnsi, but restoreSegments in daemon-durable-history-snapshot.ts:155-163 — used by buildDurableCheckpointSnapshot on every non-first fold — still replays it ahead of the pending records. The disk-reconstruction path therefore keeps the exact torn-escape completion this PR removes from the live seed, so the two base-segment builders now disagree about the tail. I could not construct a deterministic live corruption from it (the first fold commits a tail-free checkpoint that later folds read), but the non-first-fold path is untested and the fix is one line.
Technical details
# Torn-tail policy differs between the live seed and the durable replay
## Affected sites
- `src/main/daemon/terminal-history-seed-segments.ts:29-35` — seed drops `pendingEscapeTailAnsi` and appends `PROCESS_BOUNDARY_GROUND`.
- `src/main/daemon/daemon-durable-history-snapshot.ts:64-66` — non-first folds call `restoreSegments` instead of the seed.
- `src/main/daemon/daemon-durable-history-snapshot.ts:155-163` — `restoreSegments` still appends `restoreInfo.pendingEscapeTailAnsi` last, before the replayed pending records.
- `src/main/daemon/history-reader.ts:294` — the `restoreInfo` handed to `restoreSegments` can already carry a disk tail.
- `src/main/daemon/process-boundary-ground.test.ts:78-100` — both rebuild calls pass `pendingRecordsAreComplete: true`, so `restoreSegments` is never exercised here.
## Required outcome
- The base reconstructed for the durable replay must match the base the live emulator was seeded with, so replayed pending records parse from the same parser state.
## Suggested approach (optional)
- Drop (or CAN-abort) `pendingEscapeTailAnsi` in `restoreSegments` to match the seed, and add a non-first-fold fixture carrying a tail to pin the invariant.…t folds and trims Stop seeding persisted OSC link ranges into the fold replay: they index the base buffer, so rows evicted by pending output left a link on the wrong text. The serializer already writes OSC 8 into the ANSI the fold replays. Re-apply kitty keyboard flags when replaying a snapshot for trimming, since rehydrateSequences omits them. Bound a smaller restore request by trimming the committed checkpoint instead of re-reading disk and rebasing the live window at a smaller depth.
# Conflicts: # src/main/daemon/daemon-durable-history-snapshot.ts
…ble fold The live window's override cap now derives from the restore depth, so live can never be deeper than the fold. pendingRecords and isFirstTake are required.
# Conflicts: # src/main/daemon/daemon-durable-history-snapshot.ts
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (11)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughCold-restore and confirmed-crash recovery now append or emit Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to No additional merge-blocking risk was established for the terminal grounding change. Complete normal checks before merging. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change clears terminal settings left by a dead process before the next shell runs. No new access path or demonstrated security regression was found, though coverage of all terminal environments is incomplete. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
…round Kitty keyboard stacks are per screen, so resetting only after ?1049l left a dead TUI's alt-screen flags for the next alt-screen app. Also drop the inert CAN from the ground (every site grounds after complete bytes) and correct two stale comments.

ELI5
When a program in a terminal dies, Orca has to switch off the settings it had asked for: mouse capture, full-screen mode, special paste handling and so on. Orca had three separate "switch it all off" lists that had drifted apart. The one used after a restart only switched off the mouse and colors, so the new program inherited the old one's other settings. This PR replaces the three lists with one complete list and uses it everywhere.
Stacked on #22732 (review that first).
What Changed
Before:
?1004h), bracketed paste (?2004h), application cursor (?1h) and keypad (?66h) modes stayed armed. They stayed in the daemon's live emulator, the first durable checkpoint, and main's mirror, which mobile reads.Mechanism: three drifting copies of the process-boundary reset:
COLD_RESTORE_SEED_MODE_RESET: pen and mouse only.POST_REPLAY_DEAD_TUI_RESET.After: one
PROCESS_BOUNDARY_GROUNDinterminal-mode-reset-profiles.ts, built from existing named pieces:?1049l, preceded by a DECSC. xterm's?1049lalways restores the saved cursor, so the save keeps the normal-buffer cursor in place. On the alt buffer, it still returns to the shell's pre-TUI position.It stays inert for the lifecycle scanner: no OSC 133, and nothing it treats as a new owner.
Where it's used:
The renderer's own reset profiles are unchanged; they remain the policy for hosts without a daemon model.
On the first fold after a cold restore, the live terminal was seeded with the saved checkpoint plus the ground, so the saved copy never matches it. #22732's "skip the rebase when disk already agrees with live" shortcut is therefore skipped on that first fold.
Why
One constant used at every boundary Orca knows about (a cold restore) or proves (the barrier) removes the drift at its source. Adding the missing bits to each copy would keep three copies that drift again. The ground only turns modes off, so it can't arm anything for a live program.
Linked Issue
Related: #13077. This clears the stale modes that make a shell print mouse reports as garbage after a cold restore. The in-stream detector for normal-buffer programs that die is a follow-up, so this doesn't close #13077.
Visual Proof
N/A. This changes daemon and main-process terminal state, not the UI; it's covered by tests that assert emulator modes, cursor position and the pane title. I didn't demo it in the running app.
Testing
New tests fail on #22732's head and pass here:
TerminalModescan't see the stale modes.Also covered:
Test suites:
src/main/daemon, the shared reset-profile tests and rendererterminal-pane: 6,709 pass. The only failures are tworepro-13767real-PTY tests that also fail on the base commit on this machine.cross-version-terminal-wire: passes.Checks:
pnpm tc,oxlintandcheck:code-quality:changedare clean.Platform: tests ran on macOS only.
AI Disclosure
Review
Independently reviewed and ready.
?1049lchoice: checked against xterm's source (?1049lalways calls restoreCursor, and the saved cursor is per buffer) and with scratch tests on both buffers. In one normal-buffer case, the old bytes jumped the cursor up and overwrote a line; the new ones don't.Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
?1005/?1015are ignored by xterm and only disable modes on other hosts.?47/?1047(not?1049) still restores a stale normal-buffer cursor. The old bytes did the same.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)