Repository navigation
fix(relay): reset input modes a dead program left on in SSH terminals - #23488
Conversation
SSH relay PTYs now run the same recovery barrier as the local daemon: between startup ingress and the replay buffer/publish sink, it pauses at an OSC 133;D that closes a command which left input modes or the alternate screen armed, proves the shell owns the PTY foreground on the execution host, and on proof injects the process-boundary ground ahead of the prompt. Teardown flushes held bytes through releaseRelayIngress. The barrier now holds only the D marker's terminator and carries the ground on it as one transformed emission over exactly one raw unit. Previously the ground was a zero-raw emission, which source-credit delivery accepts but never sends, so live output and replay diverged. Every emission now covers at least one raw unit; refuted, timed-out, overflowed and flushed episodes release the terminator unmodified.
…aw span Treat a trigger end below 1 as unsplittable instead of trusting the scanner's clamp, arm the bail timer before queueing the terminator, and build the relay's startup ingress unconditionally beside its barrier.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Important Review skippedReview was skipped as selected files did not have any reviewable changes. ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 (6)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughThe scanner now reports the start offset of an unclean-death trigger. The recovery barrier holds the complete marker during foreground confirmation and appends the process-boundary ground sequence to it when confirmation succeeds and the process remains alive. PtyHandler routes startup ingress through the barrier and flushes held output during ingress teardown. Tests cover marker splitting, proof outcomes, snapshots, published output, and replay. Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to The reviewed terminal-recovery changes are mergeable after normal checks. No actionable issue remains from this review. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The new SSH recovery path can briefly hold terminal output and send a reset to attached clients, but the inspected path requires confirmation that the shell is foregrounded and the terminal is alive. Failed confirmation releases the original output. No introduced security finding was established, though runtime coverage remains incomplete. Retained concerns Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
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 |
… on an escape boundary The scanner now reports where the unclean-death D mark starts; the barrier releases everything before it and holds the mark itself (bounded to 4K, so the grounded span stays inside a relay source frame). A snapshot taken mid-proof therefore has no open OSC for consumers that do not restore the pending escape tail. The relay defines PTY liveness once.
There was a problem hiding this comment.
ℹ️ No critical issues — one test-coverage suggestion inline.
Reviewed changes
- Relay wiring —
src/relay/pty-handler.tsnow builds aTerminalShellRecoveryBarrierper managed PTY (reusingconfirmPtyShellForeground) between its startup ingress and output emitter, and teardown flushes then disposes it afterdrainAndClose(). - Barrier emission shape — the OSC 133;D trigger's last raw byte is now held and re-emitted as one transformed span (
terminator + ground, one raw unit) instead of a zero-length ground span, so credit-windowed delivery and sequence-based snapshot dedup stop dropping it.end >= 1was added tosplittable, the bail timer is armed before the terminator is queued, andreleaseTerminatorowns the ground release plustrySetOwner. - Type/wiring cleanups —
confirmPtyShellForegroundacceptsshellPath: string | undefined; the relay's startup ingress is built unconditionally (??=→=).
Verified locally: pnpm test src/relay src/main/daemon passes (402 files, 4167 tests, 52 skipped), including the new src/relay/pty-handler-shell-recovery.test.ts. I traced the raw-sequence conservation (head end-1 + terminator 1 = the old trigger end) and the relay source-credit path (sourceLengthSu = rawLength = 1, indivisible, sent/acked once) — both are consistent with the PR's claim that the zero-length span previously died in delivery.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| if (sourceCredit) { | ||
| expect(frames.every((frame) => frame?.params?.sourceLengthSu !== undefined)).toBe(true) |
There was a problem hiding this comment.
The source-credit assertion only checks that sourceLengthSu exists, so a regression reporting the grounded span's raw length as its payload length — which would over-drain the source window and advance the client model by ~250x — would still pass. Pin the grounded frame's sourceLengthSu (and rawLength) to 1; that one-raw-unit span is the entire fix this PR is built around.
| if (sourceCredit) { | |
| expect(frames.every((frame) => frame?.params?.sourceLengthSu !== undefined)).toBe(true) | |
| if (sourceCredit) { | |
| expect(frames.every((frame) => frame?.params?.sourceLengthSu !== undefined)).toBe(true) | |
| const grounded = frames.find((frame) => | |
| String(frame?.params?.data ?? '').includes(PROCESS_BOUNDARY_GROUND) | |
| ) | |
| expect(grounded?.params?.sourceLengthSu).toBe(1) |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes (incremental since c411408)
- Hold the whole OSC 133;D mark —
terminal-shell-recovery-barrier.tsnow holds the entire command-done marker (bounded toMAX_HELD_MARK_CHARS = 4096) and rides the ground on it, instead of holding only its last byte. This keeps a snapshot taken during the ownership proof ending before the marker, so the emulator has no dangling open OSC. - Scanner reports the marker start —
terminal-shell-lifecycle-scanner.tsaddsuncleanDeathTriggerStartso the barrier can split at the marker's start rather than arbitrarily; it clamps to 0 when the marker began in an earlier chunk. - Tests — new
process-boundary-groundtest assertspendingEscapeTailAnsiis undefined mid-proof (this fails under the previous last-byte-only hold, so it genuinely pins the behavior), plus scanner and barrier assertions for the new split.
I read the incremental diff end to end and re-ran the whole src/relay + src/main/daemon suite on 92e24c2 (402 files, 4168 tests pass, 52 skipped). The raw-sequence arithmetic stays conserved (head start + held mark end-start = the old trigger end), no bytes are reordered, and the relay source-credit span remains one indivisible non-zero-length unit. The unaddressed item from my prior review (the relay test only asserting sourceLengthSu !== undefined rather than its value) still stands as an optional test-hardening suggestion; nothing new blocks merge.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
When a terminal program such as a coding agent or
vimdies without cleaning up, the terminal can be left in special keyboard or mouse modes. After that, keys like Shift+Enter or Option chords send garbled input to the shell. Local terminals already clean this up automatically once the shell is back in control (#22739). SSH terminals didn't; this PR gives them the same cleanup.What Changed
src/relay/pty-handler.tsputs the existingTerminalShellRecoveryBarrierbetween each SSH terminal's startup ingress and its output emitter, using the same foreground proof the local daemon uses.terminal-shell-recovery-barrier.tsnow holds back the whole "command finished" signal (OSC 133;D) during the check. It then releases the signal together with the reset as one output span that covers real raw bytes.Why
Linked Issue
Follow-up to #22739 (local process-boundary cleanup); no separate issue.
Visual Proof
N/A: this changes byte-stream recovery after a program dies, and it's covered by stream-level tests rather than a UI change.
Testing
Tests:
src/relay/pty-handler-shell-recovery.test.tsruns 8 tests, each with source-credit delivery and with the older delivery path:133;D + reset + prompt.ESC|\).pnpm run typecheck,check:code-quality:changedandbuild:relaypass.src/relay+src/main/daemonsuite passes, apart from tworepro-13767-shell-ready-marker-lost-to-exectests that also fail on main.Platforms: the remote foreground proof is
psstat on POSIX relays. Windows relays use job membership, and without job info the proof fails, which leaves the bytes unchanged.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
Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)