Repository navigation
fix(terminal): keep a dead app's input modes recoverable after a refuted proof - #23474
Conversation
|
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: 📥 CommitsReviewing files that changed from the base of the PR and between fed9343c7b66092410d61e2fbfb5d8837fdaf93e and 71ecc3c. 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughCommand-owned input modes remain active after command-end markers. The lifecycle scanner now checks every OSC 133;D for active input modes or alternate-screen activity. Tests cover repeated foreground confirmation attempts, confirmed recovery grounding, output ordering, mouse tracking, and shell ownership confirmation. Priority: ➖ Normal Merge Risk: 🔵 Low · up to Repeated command-end markers may increase terminal-daemon work when foreground confirmation is unavailable. This is a bounded merge risk that warrants owner awareness. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to Repeated checks fix a real recovery failure, but a program that emits many command-end markers may impose substantially more work on the terminal daemon. An exceptional shutdown path may also leave its ownership model stale. The extent of either effect in production is not established. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 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 |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟡 Minor · Process the state-only suffix in one pass. · terminal-shell-recovery-barrier.ts:204
src/main/daemon/terminal-shell-recovery-barrier.ts:204
🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick winProcess the state-only suffix in one pass.
When
confirmShellForegroundis unavailable,consumeForStateOnlyre-scans the remaining suffix after each uncleanOSC 133;D. WithaltActivestill true, every marker stopsscanner.scan, so the total scan work can grow quadratically for a large emission. The current emission is released first, but this synchronous replay can delay later PTY emissions.Add a state-only scanner path that processes the suffix once while applying every marker's state transition.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: eb86e937-a5a2-4eb8-8da2-cc2f1bd2d5fe
📥 Commits
Reviewing files that changed from the base of the PR and between 838769d and d59e86065fce53d06f01a85a8953e05b7cd17d8b.
📒 Files selected for processing (11)
src/main/daemon/pty-subprocess-wsl-launch.test.tssrc/main/daemon/pty-subprocess/pty-shell-foreground-confirmation.tssrc/main/daemon/pty-subprocess/subprocess-handle.tssrc/main/daemon/session-output-pipeline.tssrc/main/daemon/terminal-armed-input-modes.tssrc/main/daemon/terminal-shell-armed-input-mode-recovery.test.tssrc/main/daemon/terminal-shell-lifecycle-scanner.test.tssrc/main/daemon/terminal-shell-lifecycle-scanner.tssrc/main/daemon/terminal-shell-recovery-barrier.test.tssrc/main/daemon/terminal-shell-recovery-barrier.tssrc/main/runtime/pty-shell-ownership-mirror.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
d59e860 to
fed9343
Compare
There was a problem hiding this comment.
ℹ️ No critical issues — two small test-quality nits.
Reviewed changes
- Repeated, not one-shot, unclean-death checks —
TerminalShellLifecycleScannerlosesuncleanTriggerArmed, andTerminalArmedInputModes.markCommandEnd()no longer demotescommand-owned modes tostale, so every OSC 133;D with a command mode or the alternate screen still active re-opens a recovery episode. - Unprovable terminals never pause —
TerminalShellRecoveryBarriernow takesconfirmShellForeground: (() => Promise<boolean>) | undefinedand releases bytes without holding when it is absent;subprocess-handle.tsomits the proof forwsl.exe/non-shell spawns via the newcanConfirmPtyShellForegroundgate, andsession-output-pipeline.tspropagates the absence instead of coercing tofalse. - Test coverage — new scanner, barrier, session, mirror, and WSL-gate tests for leaked-
Drecovery, the live-TUI "ask at every D" path, and the no-proof terminal.
I checked the main correctness question this redesign raises — whether a live agent's leaked D could ever get a confirmed proof and ground a running app. confirmShellForegroundProcess (src/main/providers/agent-foreground-process.ts:91) sorts matching shells by depth and inspects only the shallowest, which is the spawned root, so a nested shell's foreground + cannot confirm. That holds for the direct POSIX spawn, the macOS login trampoline, and the Windows job checks (windows-shell-alone-in-job.ts). No issue there.
Technical details
# Verification of the confirmed-proof concern
## Affected sites
- src/main/providers/agent-foreground-process.ts:99-108 — `foregroundShell` selection and `confirmed` computation.
- src/main/providers/agent-foreground-process.test.ts:249-271 — fixtures where a depth-3/nested shell is `S+` while the root shell is not; all resolve `false`.
## Required outcome
- No change required. Recorded so a future reviewer does not re-open the "nested shell confirms" question.ℹ️ Nitpicks
src/main/daemon/terminal-shell-armed-input-mode-recovery.test.ts:347— the comment "the one-shot trigger re-arms only on a new enable" is now stale; this PR removes the one-shot. The test still passes, but only because the leftover?1003command-owned mode keeps re-triggering, not because of the fresh?1000harm — worth updating the comment or the test's intent.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No new changes to review — the head advanced (d59e860 → fed9343) but the diff against
mainis byte-identical.
Reviewed changes
- Nothing new since the prior review. The two minor test-quality notes from that review (
terminal-shell-armed-input-mode-recovery.test.ts:394vacuous assertion; stale one-shot comment at line 347) still apply and are not repeated here.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…ted proof A command's armed input modes were demoted at the first OSC 133;D whether or not the foreground proof confirmed, and the alternate-screen trigger was spent the same way. A full-screen agent's nested command shells leak their own D onto the main PTY; the refuted proof for that stray D used up the only trigger, so the app's real death later went unrecovered. Every D now re-asks while a command's mode (or the alternate screen) is still up; only the confirmed ground or the app's own disable clears it. Proofs that can never succeed (wsl.exe, no Windows job reads) already refute immediately without spawning anything. The accepted cost is one process read plus a bounded output hold per D while a command-owned mode stays up and the proof keeps refuting: a live agent leaking D, a stopped job, a nested subshell, or an rc that execs another shell.
fed9343 to
71ecc3c
Compare
There was a problem hiding this comment.
✅ No new issues found — the new commit narrows the change to the two production files and the repeated-trigger fix, and the prior review's only open thread is resolved.
Reviewed changes
- Reverted the optional-proof/no-pause design —
TerminalShellRecoveryBarrier,subprocess-handle,session-output-pipeline, andpty-shell-foreground-confirmationreturn tomain;canConfirmPtyShellForegroundand the WSL gate test are gone. The reverted files are byte-identical to base, so no fresh code to review there. - Kept the repeated unclean-death trigger —
TerminalShellLifecycleScannerdropsuncleanTriggerArmedanduncleanDeath = markCommandEnd() || altActive;markCommandEnd()no longer demotes command-owned modes, so every133;Dwith a command mode or the alt screen still up re-asks. - Reworked the tests to match — scanner/barrier/session/mirror cases now assert re-asking at every
D, byte-identical in-order release on refutation, recovery when the real deathDarrives while a strayDis still being proven, and no re-trigger after a confirmed ground; the no-proof terminal tests were removed with the feature.
I verified the reversion's load-bearing claim — that unprovable terminals refute without spawning — holds: confirmShellForegroundProcess early-returns on !isShellProcess (src/main/providers/agent-foreground-process.ts:73), and isWindowsShellAloneInJob returns false on absent job membership before reading the process table (src/main/providers/windows-shell-alone-in-job.ts:27). Ran the four changed suites (81 pass) and pnpm tc:node (clean).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
When a terminal program crashes without switching its special keyboard or mouse modes back off, Orca's terminal host is supposed to switch them off once the shell prompt returns. One stray "command finished" signal could make the host give up on that for good, so a later real crash left the shell receiving garbage key codes. The host now keeps checking until the modes are actually cleared.
What Changed
The local terminal daemon (#22735, #22739) watches for the shell's command-finished mark (OSC 133;D). When a command left input modes armed (Kitty keyboard, mouse or focus reporting, or the alternate screen), the daemon checks that the shell owns the foreground again. If it does, it injects a reset into the output stream.
Why
A bounded retry was considered first. It still loses recovery once an agent has run more than a couple of nested commands, since each one can leak a mark. Re-checking at every mark adds no state.
Checks that can never succeed (a
wsl.exespawn, or Windows without job reads): these already answer "no" immediately, without starting any process, so the hold resolves within microtasks.Cost while an agent is alive and leaking marks: each leaked mark holds that terminal's output until the check resolves. That's one process read, about 100 ms at p95, and output is released unchanged after 750 ms at most. The renderer's #9608 path already does a foreground read at each of these marks for agent terminals.
Stopped jobs (Ctrl+Z): they refute cheaply at each prompt until resumed or killed. After a resume the app still owns its modes; after a kill, the next mark recovers.
Linked Issue
N/A (maintainer fix to unreleased #22739)
Visual Proof
N/A: host-side stream logic, covered by unit tests; no UI change.
Testing
New scanner, barrier, session and mirror tests:
Results:
repro-13767tests, which also fail on unmodifiedmainlocally.pnpm run typecheckis clean.Review
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
psor Windows job membership. On WSL and builds without job reads it answers "no" immediately.execon another shell.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)