Skip to content

fix(terminal): ground a program that dies with input modes armed on the normal screen - #22739

Merged
Jinwoo-H merged 22 commits into
mainfrom
scroll-freeze-detector
Sep 25, 2026
Merged

Jinwoo-H merged 22 commits into
mainfrom
scroll-freeze-detector

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​507 $\color{#cf222e}{\Huge{\mathbf{−}}}$​21 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​486
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​204 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​188

ELI5

Orca's terminal backend has a crash detector. When a program dies and leaves settings like mouse capture turned on, the detector turns them off, but it only watched full-screen programs. A small program that turned the mouse on and then exited would leave it on in Orca's backend, and when you came back to that terminal (or opened it on mobile), moving the mouse typed junk into the shell. Now the detector watches for any leftover input settings, not just full-screen ones.

Stacked on #22735, which is stacked on #22732. Windows checks are in progress (see Notes).

What Changed

Before: a normal-screen (not full-screen) program that arms mouse tracking, focus reporting, keypad or kitty keyboard flags and exits without disabling them was cleaned up only in the desktop renderer. The daemon's live emulator kept the modes and re-armed them on the next reattach, and on mobile, where no renderer cleanup runs. That's the #13077 family: mouse reports printed as garbage at the prompt.

Mechanism: TerminalShellRecoveryBarrier already grounds a dead program in the recorded stream, but its trigger in TerminalShellLifecycleScanner only fires when the alternate screen is still up at OSC 133;D ("command finished").

After:

  • What the scanner tracks: armed input modes, in a new TerminalArmedInputModes:
    • mouse protocols and encodings, ?1004 and ?66
    • kitty flags, as separate main and alt stacks that mirror xterm's screen swap and its 16-entry cap
    • ?2004 and ?1 are excluded, because shells arm them at their own prompts
  • One owner per armed mode: host (only focus reporting ?1004, the one mode a terminal host arms for itself: armed before any OSC 133 marker, like ConPTY's ?1004h, or by a prompt that a 133;C proved ended), prompt (armed outside a command, unproven until C), command (armed after C), or stale (anything else still on; the ground clears it but it never triggers). Mouse, keypad and kitty modes are never the host's, so a tmux that dies with mouse on before the first prompt is cleared like any other program. Host arming is sticky, so a program re-sending ?1004h changes nothing. A full reset (ESC c, sent by reset) clears the modes but neither "a command is running" nor host focus ownership: ConPTY answers RIS by re-sending ?1004h mid-command, and that must stay the host's. A shell that never emits C (PowerShell without PSReadLine) never has a command mode, so only an alt-screen death triggers there.
  • The trigger: at OSC 133;D it is now "alt screen or a command input mode".
  • Host focus survives the ground: when the host owns ?1004, the barrier emits the ground without its ?1004l (buildProcessBoundaryGround in terminal-mode-reset-profiles.ts, the single source of the byte order). Nothing is turned off and back on, so the injected bytes contain no enables: every consumer that scans them for ownership (the daemon scanner, the runtime's PtyShellOwnershipMirror, the renderer) sees only disables, and xterm sends no spurious focus report. Kitty flags are cleared on both screens; fish sets them with =5u at its prompt and clears them with =0u before running a command. On Windows, ConPTY arms focus reporting before the first prompt for the pane's whole life; without this, the first ground turned it off for good. ?2004/?1 need nothing extra: bash, zsh and PSReadLine arm them at each prompt and disarm them before 133;C, and the queued prompt after the ground re-arms them. Cold restore keeps the full ground: the seed is written into the emulator before the new ConPTY's first bytes, so its ?1004h lands after it.
  • No new delay on ordinary prompts: a plain prompt never waits for the proof; the hold only starts when the trigger fires.
  • WSL panes are not grounded, because they spawn wsl.exe, which the shell proof doesn't recognize. A test pins this, and the renderer keeps covering them. There's no behavior change for WSL.

Why

This fixes the stale modes where they originate, in the daemon's recorded stream, so every consumer sees the same state: reattach, mobile and durable history. The alternative was adding more renderer-side reset rules, but that leaves the daemon wrong and still re-arms mobile. It's the third of three changes; the renderer's reset rules stay, as the fallback for hosts and panes the daemon can't prove (WSL, shells without OSC 133, the SSH relay).

Linked Issue

Fixes #13077

Visual Proof

N/A: this is daemon stream behavior with no UI change. It's covered by unit tests and the existing terminal-reattach-mouse-mode-leak e2e (below). #22732/#22735 were validated in the running app separately.

Testing

  • New unit tests fail on fix(terminal): one process-boundary ground for every known or proven boundary #22735's head and pass here (9 of 12 failed before):

    • A normal-screen program dies with mouse+SGR, focus, a kitty push or keypad armed: the ground is recorded, and the live emulator ends with mouse none and no ?1004h.
    • One-shot: a trigger doesn't fire again at the next prompt.
    • Prompt-owned modes: a prompt that leaves modes on never triggers.
    • The ground stays inert: it doesn't re-trigger.
    • Two Session-level proof tests.
  • Host focus: a stream with ?1004h before 133;A, then 133;C, a ?1003h arm and 133;D;1 ends with focus on and mouse none; the injected ground has no ?1004l and no enables, and both the barrier and a real PtyShellOwnershipMirror fed the released bytes settle on owner shell (on the previous head the mirror read undefined). Mouse armed before the first marker is cleared, with no mouse enable in the ground. A ?1003h leaked past a refuted proof is turned off by the next confirmed ground.

  • Negative controls:

    • a ?2004h/?1h prompt never holds
    • a clean disable before exit doesn't trigger
    • a refuted proof flushes without the ground
  • Kitty per-screen and cap cases:

    • a TUI that pushes flags on the alt screen and exits with ?1049l doesn't trigger
    • a TUI that dies on the alt screen with flags pushed does trigger
    • 101 pushes followed by the ground can't be uncovered by a later pop
  • e2e terminal-reattach-mouse-mode-leak.spec.ts: passes on a fresh build. The arming program now stays alive through the warm reattach, and the pane is checked before it is interrupted, so the daemon can't have grounded it and only the renderer's reattach reset can disarm the pane. Dropping mouse modes from POST_REPLAY_REATTACH_RESET makes it fail ("never disarmed", any).

  • Ownership bugs from review (each test fails on dc597b4): a 133;D without a C no longer triggers on host modes; an enable after a mid-command ESC c stays the command's; a program re-sending a host enable keeps it the host's.

  • Suites and gates:

    • src/main/daemon: all pass except two repro-13767 real-PTY tests that time out on this machine's sqlite 3.54 (pre-existing).
    • pnpm tc, oxlint and check:code-quality:changed are clean.
  • Platform: macOS only so far.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

  • Independent review: found two issues, both fixed:
    • kitty flags were modelled as one stack, which caused a false trigger after a clean alt-screen exit
    • the kitty stack was unbounded
  • Also checked by the review:
    • no false positives from Orca's injected bash/zsh/PowerShell integration
    • no lost detection compared with today
    • no scanner cost regression on repaint-heavy output

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

In progress / open:

  • Windows (to run on a Windows machine):
    1. PowerShell/PSReadLine: a program arms ?1003h?1006h or ?1004h and exits. Expect the proof to pass and the ground to land before the next prompt, and a plain dir never pauses.
    2. The same with the child still running or stopped: the proof must refute, with no ground.
    3. cmd.exe: no OSC 133, so no trigger.
    4. A WSL pane: no ground.
    5. Git Bash: trigger plus ground.
    6. Whether ConPTY arms ?1004h at session start. Confirmed (every fresh ConPTY pane sends ESC[1t ESC[c ESC[?1004h ESC[?9001h before the first OSC 133;A); focus reporting now survives the ground (see After). Still to re-check on Windows.
  • fish: only a synthetic fish-style prompt is tested; there is no recorded fish 4 transcript yet. The prompt-ownership rule covers the case where fish leaves modes on at its prompt.

Unchanged:

  • The SSH relay has no host emulator; its bash/zsh integration already emits OSC 133.
  • There is no wire change: the ground is disable-only bytes that were already in use.

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)

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.
…he normal screen

The daemon's in-stream crash detector only fired when a program died with
the alternate screen up. A normal-buffer program that armed mouse tracking,
focus reporting, keypad or kitty keyboard flags and exited without
disabling them was cleaned up only in the renderer, so the daemon kept the
modes and re-armed them on the next reattach, mobile included (#13077's
garbage-at-the-prompt family).

The lifecycle scanner now tracks armed input modes (mouse protocols and
encodings, ?1004, ?66, and kitty flags as per-screen stacks that mirror
xterm's main/alt swap and its 16-entry cap). ?2004 and ?1 are excluded:
shells arm them at their own prompts. Modes armed when a command starts
(OSC 133;C) count as the shell's, so a prompt that leaves modes on never
triggers. At OSC 133;D the trigger is now "alt screen or a program-armed
input mode", still one-shot and still gated by the shell proof, and the
existing PROCESS_BOUNDARY_GROUND is recorded through the stream so live
and durable history change together.

WSL panes spawn wsl.exe, which the shell proof does not recognise, so the
detector never grounds them; a test pins that and the renderer keeps
covering them. The mouse-leak e2e now keeps its arming process alive until
the live pane is checked, because the daemon grounds a proven exit.
@Jinwoo-H
Jinwoo-H marked this pull request as ready for review September 25, 2026 00:00

@pullfrog pullfrog 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.

ℹ️ No critical issues — the model matches xterm's kitty semantics and the new tests are meaningful. Two informational notes and one suggestion on the e2e's coverage.

Reviewed changes

  • New TerminalArmedInputModes model (src/main/daemon/terminal-armed-input-modes.ts): tracks the armed private modes (9, 1000, 1002, 1003, 1004, 1005, 1006, 1015, 1016, 66) plus per-screen kitty keyboard flags and stacks (capped at 16), with shell ownership captured at OSC 133;C. ?2004/?1 are excluded because shells arm them at their own prompts.
  • Scanner trigger widened (src/main/daemon/terminal-shell-lifecycle-scanner.ts): uncleanDeath now fires at OSC 133;D when the alt screen is up or a program-armed tracked mode survives, and the kitty regex / scan-tail matcher now include CSI < n u (pop) which feeds the model. RIS resets the model too.
  • Tests: new terminal-shell-armed-input-mode-recovery.test.ts (scanner arming + one-shot + Session-level ground recording/refutation), a WSL shell-proof pin, and the existing reattach e2e whose precondition now keeps the arming process alive.

I verified the model against @xterm/xterm's KittyKeyboard (push/pop/set modes, 16-entry eviction) and InputHandler (?47/?1047/?1049 flag swap) — the screen-key deletion is correctly evaluated before onAlternateScreen flips, so switchScreen removes the source screen's key. All 40 scanner/armed-mode tests and the 2 WSL pin tests pass locally.

ℹ️ Windows: ?1004 provenance is still unresolved

The POSIX tests can't cover the one Windows item in the Notes. Because 1004 is tracked and only becomes shell-owned if it is armed before an OSC 133;C, the outcome hinges on whether ConPTY / PSReadLine arms focus reporting at the command start (after C) or at the prompt. If it is the former, every Windows command would trip the trigger and pay the proof pause plus a ground.

Technical details
# Windows ?1004 provenance

## Affected sites
- `src/main/daemon/terminal-armed-input-modes.ts:4` — `1004` is in `TRACKED_PRIVATE_MODES`.
- `src/main/daemon/terminal-shell-lifecycle-scanner.ts:131` — trigger when `inputModes.hasProgramArmedModes`.

## Required outcome
- Confirm that on Windows the shell (not the PTY/ConPTY layer, after `OSC 133;C`) arms `?1004`, so a plain command does not trip the trigger. The author's Notes list this as open ("Whether ConPTY arms `?1004h` at session start").

## Open questions for the human
- If ConPTY arms `?1004h` per command, should `1004` be excluded from `TRACKED_PRIVATE_MODES` (or shell-owned on Windows) the way `?2004`/`?1` are?

ℹ️ The ground clears only the on-screen kitty stack

PROCESS_BOUNDARY_GROUND emits ?1049l before CSI <99u / CSI =0u. ?1049l parks the dying TUI's flags into altFlags and leaves altStack untouched, so the pop/set run against the normal buffer's stack and only zero flags. The new model mirrors this faithfully (switchScreen carries altFlags), but the new "the ground can always clear it" test only exercises the main stack — a dead alt-screen TUI's off-screen kitty state survives and is restored by the next ?1049h.

Technical details
# Off-screen kitty state survives the ground

## Affected sites
- `src/shared/terminal-mode-reset-profiles.ts:50,63` — `?1049l` precedes `RESET_KITTY_KEYBOARD_PROTOCOL` (`\x1b[<99u\x1b[=0u`).
- `src/main/daemon/terminal-armed-input-modes.ts:56-58` — model carries `kittyAltFlags` across the swap.
- `src/main/daemon/terminal-shell-armed-input-mode-recovery.test.ts:90` — "bounds the kitty stack so the ground can always clear it" (main stack only).

## Required outcome
- Decide whether the ground should also reset the inactive screen's kitty flags/stack. xterm restores `altFlags` on the next `?1049h`, so an alt-screen TUI that does not negotiate kitty can inherit the dead TUI's flags.

## Open questions for the human
- Is this in scope for the stacked branch, or a known limitation of the #22735 ground? The root cause (`RESET_KITTY_KEYBOARD_PROTOCOL`) predates this PR; it is called out because the new model and test now depend on the property.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

…cess-boundary ground

ConPTY arms focus reporting (?1004h) before the first prompt, and the live
recovery ground cleared it for the rest of the pane. The barrier now re-arms
the modes that were on at OSC 133;C right after the ground, so only the dead
program's modes are reset.
… command

A mode a program leaked past a refuted proof was still on at the next OSC
133;C, so the baseline snapshot re-armed it after a later ground. Record who
armed each mode instead: only enables outside a command (before any marker,
or between 133;A/D and C) form the baseline.

@pullfrog pullfrog 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.

Important

A redundant re-enable of an already-armed host mode revokes its host ownership, so a later ground clears it and never restores it.

Reviewed changes

Since the prior review at 4349d4b, the delta extends the armed-input-mode model so shell- and host-armed modes survive the process-boundary ground.

  • Host/shell ownership tracking (src/main/daemon/terminal-armed-input-modes.ts): a hostArmed set plus an inCommand flag capture modes enabled outside a command (ConPTY's ?1004h, shell prompt modes), and markCommandStart records a per-command baselinePrivateModes/baselineKittyFlags at OSC 133;C. markPromptBoundary clears inCommand on 133;A/D.
  • Ground re-assertion (src/main/daemon/terminal-shell-recovery-barrier.ts:286-289): the confirmed ground now releases PROCESS_BOUNDARY_GROUND followed by scanner.reassertCommandBaseline(), re-arming only the modes that were host/shell-owned at C.
  • Scanner wiring (src/main/daemon/terminal-shell-lifecycle-scanner.ts:81-84,131-133): reassertCommandBaseline() delegates to the model, and 133;A/D mark the prompt boundary.
  • Tests: new scanner baseline-reassert case, two Session cases (ConPTY ?1004h survives the ground; a mode leaked past a refuted proof is cleared and not re-asserted), and the reattach e2e / its header reworded for the in-stream ground.

I verified the new ownership transfer path against @xterm/xterm's kitty screen-swap semantics; the barrier's ground scan still contains no enables or OSC 133, so the re-assert cannot re-open the one-shot trigger. One issue inline.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

…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
…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.
Each armed mode now has one owner: host (before any marker, or a prompt a
133;C proved), prompt (unproven until C), command, or stale (left past a D).
Host arming is sticky, 133;D demotes command modes (the one-shot), and the
ground re-asserts only host modes. Fixes a D without C triggering on host
modes, an ESC c mid-command turning later enables into host modes, and a
program's repeated host enable dropping host ownership. The reattach e2e now
keeps the arming program alive so only the reattach reset can disarm it.
fish, the one shell that pushes kitty flags at its prompt, pops them before
running a command and re-pushes at the next prompt, so the ground never needs
to restore them. Only host private modes are re-asserted now.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

Since the prior review at 7effeb0, the only feature delta is ed3bc18; the three commits before it are base-merges that changed none of the PR's files.

  • Single ownership map (src/main/daemon/terminal-armed-input-modes.ts): replaced the armed/shellOwned/hostArmed/inCommand fields with one Map<ModeKey, ModeOwner> (host/prompt/command/stale), an enableOwner, and hostKittyFlags.
  • Ownership transitions: 133;C promotes prompt keys to host; 133;D demotes command/prompt keys to stale and reports whether a command-owned mode survived; a re-enable of an already-host-owned mode is now a no-op.
  • Ground path (terminal-shell-lifecycle-scanner.ts:85, terminal-shell-recovery-barrier.ts:284): groundProcessBoundary() captures hostModes() before scanning the reset, then re-asserts and re-claims them as the host's.
  • Tests: new Session cases for the redundant host re-enable and the mid-command ESC c ownership, scanner cases for prompt→host promotion, and the process-boundary fixture gained a leading 133;A.

Both prior Pullfrog threads are addressed by this commit and have been resolved. I re-ran the three touched suites (30 tests, all pass) and traced the host-stickiness fix, the no-133;C path, and the kitty screen-swap/ground interactions; the refactor preserves the ConPTY focus-survival and clean-alt-exit behavior.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog 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.

ℹ️ No critical issues — two minor suggestions inline, both about the fish assumption the re-assertion removal rests on.

Reviewed changes

Since the prior review at ed3bc18, the delta is d594a6561b (plus a base-merge that changed no feature files):

  • Dropped host kitty-flag tracking (src/main/daemon/terminal-armed-input-modes.ts): hostKittyFlags and the claim/disarm helpers are gone; hostPrivateModes() reports only host-owned numeric modes, and reassertHostModes() emits only those bytes (no CSI > flags u).
  • Ground no longer re-asserts kitty flags (terminal-shell-lifecycle-scanner.ts:85-89); scanning PROCESS_BOUNDARY_GROUND is what zeroes them.
  • Test: the reassert case now expects ${PROCESS_BOUNDARY_GROUND}\x1b[?1004h only.

I verified the removal is safe for the shell it names: upstream fish clears the kitty keyboard protocol (CSI = 0 u) before every command and re-sets it (CSI = 5 u) at each prompt, so the next prompt repairs a ground. Two minor notes inline about the comment wording and the synthetic fixture not matching that real sequence.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H changed the base branch from scroll-freeze-ground to main September 25, 2026 03:38
# Conflicts:
#	src/main/daemon/process-boundary-ground.test.ts
#	src/main/daemon/terminal-shell-recovery-barrier.ts
@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 3299d5f3-c954-4bc5-8bee-eddb9a2860de

📥 Commits

Reviewing files that changed from the base of the PR and between 7e57944 and a9c9265.

📒 Files selected for processing (6)
  • src/main/daemon/process-boundary-ground.test.ts
  • src/main/daemon/process-boundary-host-focus.test.ts
  • src/main/daemon/terminal-armed-input-modes.ts
  • src/main/daemon/terminal-shell-armed-input-mode-recovery.test.ts
  • src/main/daemon/terminal-shell-lifecycle-scanner.ts
  • src/shared/terminal-mode-reset-profiles.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/daemon/process-boundary-ground.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The change tracks ownership of selected private terminal modes and Kitty keyboard flags. The lifecycle scanner uses that state to detect unclean command endings and build process-boundary resets that preserve host-owned focus reporting. The recovery barrier releases the scanner-generated reset. Tests cover scanner and session recovery, Windows WSL foreground proof, and mouse-mode behavior during terminal reattach.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to a9c92

The previously identified recovery failure is prevented by the current ownership rules. No identified issue remains to block merging after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to a9c92

The reviewed recovery path adds a foreground-shell check before resetting terminal modes and preserves focus reporting owned by the host. No new security issue was established, but platform behavior and review coverage are not complete.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The inspected path affects the terminal-mode state and released output of the session whose subprocess supplies the PTY stream. The available evidence does not establish a broader service or tenant-level effect.

Security Findings and Attack Paths

  • inferred — A child process able to write terminal control sequences can reach the widened normal-screen trigger by emitting recognized mode enables and lifecycle markers. That scanner event alone does not authorize a reset: the barrier requires foreground-shell confirmation and a live process. No bypass was established in the inspected path.

Trust Boundaries and Controls

  • observed — Session recovery obtains foreground proof through its subprocess handle. Local proof checks the spawned shell and foreground process state, or on Windows requires the PTY job inspection to identify only the shell; unavailable proof returns false.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: grounding normal-screen programs that exit with input modes armed.
Description check ✅ Passed The description is detailed and follows the required structure. It explains the user impact, mechanism, rationale, linked issue, testing, and review status. It honestly records that manual testing, fu…
Linked Issues check ✅ Passed Issue #13077 is closed and provides historical context only. No active directly linked issue remains. Therefore, this pull request has no linked-issue coding requirements.
Out of Scope Changes check ✅ Passed The changes remain within the recovery scope described in the pull request. They refine host-owned focus reporting, command-owned mode recovery, process-boundary grounding, shell-ownership checks, and…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

ConPTY answers a mid-command ESC c by re-sending ?1004h, which reset() had
recorded as the command's, so the ground turned host focus reporting off for
the rest of the pane. RIS now drops only non-host ownership.

@pullfrog pullfrog 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.

ℹ️ No new issues in the delta — 7e57944 is a correct, focused fix. Two prior minor suggestions (the fish comment wording and the synthetic fixture) remain open, so this review does not approve.

Reviewed changes

Since the prior pullfrog review at b3741f1 (5f58ff4 was a zero-delta base-merge), the only feature delta is 7e57944:

  • Host ownership survives a full reset (src/main/daemon/terminal-armed-input-modes.ts:133-146): reset() no longer calls owners.clear(). It drops every non-host owner plus all kitty flags/stacks and onAlternateScreen, but retains host-owned numeric modes. ConPTY answers ESC c by re-sending ?1004h ?9001h; under the old clear, that re-enable would be attributed to enableOwner='command', so the next 133;D ground would clear focus reporting and re-assert nothing. The retained host key makes the re-enable a sticky-host no-op.
  • New Session test (src/main/daemon/terminal-shell-armed-input-mode-recovery.test.ts:219-236): mid-command RIS, then ConPTY's ?1004h ?9001h re-arm alongside a command-armed ?1000h, asserts the recorded ground is ${PROCESS_BOUNDARY_GROUND}\x1b[?1004h, mouse ends none, and ?1004h survives. It fails against the previous owners.clear().

I ran the three touched suites (31 tests) and they pass. The change is additive to the existing ownership tests (keeps an enable after a mid-command full reset owned by the command, keeps a host mode host-owned when a program re-sends its enable) and does not alter the trigger path.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@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

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: fbd45eaa-ccb2-4536-a2bb-3fcc4f084f73

📥 Commits

Reviewing files that changed from the base of the PR and between 5f58ff4 and 7e57944.

📒 Files selected for processing (2)
  • src/main/daemon/terminal-armed-input-modes.ts
  • src/main/daemon/terminal-shell-armed-input-mode-recovery.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.

…the ground

Host ownership covered every mode armed before the first marker, so a tmux
that died with mouse on had it re-armed by the ground. And the re-assert's
?1004h enable made the runtime's ownership mirror revoke, so remote owners
never settled on Windows. Only ?1004 can be host-owned now, and the ground
skips its ?1004l instead of turning it off and back on, so injected bytes
carry no enables.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

Since the prior pullfrog review at 7e57944, the delta is a9c9265 ("let only the host own focus reporting and leave it in the ground"). The two prior minor threads (fish push/pop wording and the synthetic fish fixture) are addressed here and were resolved during this run.

  • Only focus reporting can be host-owned (src/main/daemon/terminal-armed-input-modes.ts): a new HOST_ARMABLE_MODE = 1004 and ownerForEnable() map a pre-marker enable of any other mode to prompt instead of host, and markCommandStart() promotes a prompt-owned ?1004 to host while demoting the rest to stale. Mouse, keypad and kitty armed before the first marker no longer survive a ground.
  • The ground keeps focus instead of re-asserting it (src/shared/terminal-mode-reset-profiles.ts, terminal-shell-lifecycle-scanner.ts, terminal-shell-recovery-barrier.ts): buildProcessBoundaryGround({ keepFocusReporting }) drops ?1004l when focus is host-owned, so the emitted bytes carry no enable a consumer scans for ownership; hostPrivateModes/reassertHostModes are gone. PROCESS_BOUNDARY_GROUND is now the non-focus-preserving variant.
  • New process-boundary-host-focus.test.ts: asserts the ground injects only ?25h, ConPTY focus survives without a ?1004l and PtyShellOwnershipMirror.owner settles on shell, and a command-armed ?1004 is still grounded. Verified the mouse/focus cases fail against 7e57944's re-assertion path.
  • Test/fixture updates: recovery-suite titles and the fish fixture now use buildProcessBoundaryGround / fish's real \x1b[=5u / \x1b[=0u sequence; the process-boundary-ground.test.ts comment is reworded.

I read the full PR diff and ran the seven touched suites (terminal-shell-lifecycle-scanner, terminal-shell-armed-input-mode-recovery, process-boundary-ground, process-boundary-host-focus, terminal-shell-recovery-barrier, terminal-mode-reset-profiles, agent-foreground-process-wsl-shell-proof) — 92 tests pass.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

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.

[Bug] Orca terminals start spawning random characters

1 participant