Repository navigation
fix(terminal): recover rejected paired-runtime input (STA-2830) - #12675
Conversation
📝 WalkthroughWalkthroughTerminal streaming now negotiates 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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 |
… remount (STA-2830) The WriteUnavailable signal reached the renderer and then died. `onWriteUnavailable` routed to `requestTerminalPaneRecovery` with `requireAuthoritativeLiveness: true`, which probes `pty:hasPty`. For a paired pane the id is `remote:<env>@@<handle>`: `ptyOwnership` never holds it and `parseAppSshPtyId` ignores it, so the lookup falls through to the local provider, whose "not in my table" came back as an authoritative `false`. Recovery returned early and no remount ever happened. Two fixes, both about not inventing evidence: - `pty:hasPty` now returns null for a `remote:` id instead of routing it to the local provider, mirroring the guard `pty:kill` already has. Main cannot know another host's PTY state, so it says so. - A host rejection now takes a distinct recovery reason, `input-rejected-by-host`, that consults no local probe. The probe is not made to lie: the frame itself is the evidence, it came from the process that owns the PTY over a live connection, and the remount preserves the session rather than destroying it. Local ids keep the probe, where a `false` really does mean the shell died. Tests: a cross-boundary contract runs the real dispatcher, multiplexer, transport and pty-connection together and requires the remount for every answer the probe can give; an un-negotiated legacy binary subscriber must never receive opcode 17.
The signal was delivered, then discardedIndependent review found that this PR's headline benefit was inert in production, and it reproduces: the
What now carries it throughTwo changes, both about not inventing evidence. 1. 2. A host rejection takes a recovery path that needs no local liveness proof. New reason On the governing rule — unprovable liveness must never authorize destroying a session, and an ambiguous answer must never be read as proof — to be explicit about which option I took:
Local (daemon / app-SSH) ids keep the probe: there main's registry genuinely can answer, and a Proving the whole chainEvery pre-existing test for this signal stopped at the transport callback, which is exactly why the dead last hop went unnoticed — and an in-renderer test could not have caught it, because they all mock New: Red/green: 3 failed → 3 passed. On the delivery-only implementation the first assertion (host frame arrives) passed and the remount assertion failed in all three cases; after the fix all three pass. It lives under The surviving mutantDeleting the legacy-binary capability gate at Added: an un-negotiated legacy binary subscriber ( Verified by deleting the gate: 1 failed / 62 passed. Restored by re-applying the edit (no Mutation results for every production change
Each was restored by re-applying the edit and re-verified green. Gate title
Verification
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/e2e/paired-runtime-rejected-input-remount.unit.test.ts (1)
425-427: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMove the per-test teardown into
afterEach.
binding.dispose()and_resetTerminalPaneRecoveryForTests()run only on the success path. If anyvi.waitForabove times out, the binding stays live. Its timers and store subscribers then keep running against the previous module instance afterafterEachdeletesglobalThis.window, which can turn one failing case into cascading failures or unhandled errors in the remaining parametrized cases.Register the teardown as soon as the binding exists.
♻️ Proposed teardown that survives a failed assertion
afterEach(() => { + cleanup?.() + cleanup = null delete (globalThis as { window?: unknown }).window })+let cleanup: (() => void) | null = nullconst binding = connectPanePty(pane as never, createManager() as never, deps as never) + cleanup = () => { + binding.dispose() + _resetTerminalPaneRecoveryForTests() + } await vi.waitFor(() => { expect(deps.paneTransportsRef.current.get(1)?.getPtyId()).toBe(REMOTE_PTY_ID) })- binding.dispose() - _resetTerminalPaneRecoveryForTests() })
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 24fcd206-56c9-4805-8ce0-80115d3dabe9
📒 Files selected for processing (8)
config/reliability-gates.jsoncsrc/main/ipc/pty.test.tssrc/main/ipc/pty.tssrc/main/runtime/rpc/terminal-multiplex.test.tssrc/renderer/src/components/terminal-pane/pty-connection.tssrc/renderer/src/components/terminal-pane/terminal-pane-recovery.test.tssrc/renderer/src/components/terminal-pane/terminal-pane-recovery.tstests/e2e/paired-runtime-rejected-input-remount.unit.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/main/runtime/rpc/terminal-multiplex.test.ts
- config/reliability-gates.jsonc
…lyai#12675) With a desktop client paired to a remote Orca runtime, terminal panes could report connected, writable, and `terminal.send` returning accepted — yet keystrokes never reached the agent. No error, no banner, no recovery; input silently vanished. The ticket was really two bugs. The attach half was already fixed by stablyai#12589 (subscriber-driven daemon attach), confirmed by reproducing against current main. This fixes the remaining half: a write the host refuses had no way to tell anyone. A capability-negotiated `WriteUnavailable` opcode carries that refusal back to the client, where it feeds the pane's pre-existing recovery hook. Capability gating matters because decoders reject unknown opcodes on desktop — and, worse, silently drop them on mobile — so the signal is negotiated in the subscribe handshake. Verified per direction: an old host strips the unknown Subscribe key, an old client omits it so the host never emits, and capability cannot be inherited across resubscribe. Independent review then found the signal was being delivered and discarded: recovery demanded an authoritative liveness answer, and `pty:hasPty` had no `remote:` guard, so a paired pane's id fell through to the LOCAL provider, which returned false, and recovery bailed before remounting. Every test stopped at the transport boundary, so all of them passed while the pane stayed just as stuck. `pty:kill` already had exactly that guard. The fix makes main answer LESS rather than claim more: `pty:hasPty` now returns unknown for a `remote:` id instead of a fabricated false, because main cannot speak for another host's PTY. The remount is then authorized by positive evidence — the process that owns the PTY stating it refused this specific write over a live negotiated connection — not by inference from silence. Local and app-SSH ids keep the probe, where a false genuinely means the shell died. Nothing is destroyed on this path; the remount rebuilds the renderer over the session it already had. An end-to-end test now carries a rejected write from the host through to an actual remount, which no prior test did. A surviving mutant was also killed: the legacy-binary capability gate could previously be deleted with nothing turning red. The reliability gate stays experimental — live paired journeys and mixed installed-release evidence remain uncollected. Fixes STA-2830.
Summary
Fixes STA-2830's remaining silent-input invariant for paired-runtime terminals.
Commit
72245918a1/ #12589 already fixed the reported attach failure: subscribing to a never-activated daemon session now attaches its provider output pipeline without requiring the host renderer to open the project. That original attach state no longer reproduces on currentmain.A narrower failure still reproduced: the renderer accepted an Input frame locally, the authoritative host
runtime.sendTerminalrejected it before any process write, and the host discarded the rejection without sending any recovery signal. The pane therefore kept reporting success while the keystroke vanished.This change:
WriteUnavailable = 17for rejected writes;onWriteUnavailablerecovery hook;terminal.sendfallback results andterminal_not_writablefailures through the same hook;config/reliability-gates.jsonc.Reproduction on current main
Baseline:
e5f49e0e1d(currentorigin/mainwhen the oracle was established).Test-only oracle result before production changes:
sendTerminalwas called exactly once;17never returned;Compatibility
The new opcode is never sent without
capabilities.writeUnavailable: 1on that stream.Tests also reuse a multiplex stream ID and detach/reattach the same renderer handle before releasing held rejections; neither stale failure can recover the replacement stream or pane lifecycle.
Verification
Integrated deterministic gate:
pnpm exec vitest run --config config/vitest.config.ts \ src/main/runtime/rpc/terminal-multiplex.test.ts \ src/renderer/src/runtime/runtime-terminal-stream.test.ts \ src/renderer/src/runtime/remote-runtime-terminal-parse-backpressure.test.ts \ src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts \ --reporter=dotResult after rebasing onto
15ef69a814: 4 files, 197 tests passed.Additional checks:
pnpm run typecheck— passedoxlint— passedoxfmt --check— passedpnpm run check:reliability-gates— passed, 67 gatesIndependent mutation evidence:
terminal.sendfallback recovery: focused fallback oracle failed 1/1.Each mutation was restored by the exact inverse edit; its focused oracle returned green before final validation.
Deliberate gaps
orca servejourney was collected.connected: trueare still tracked separately in STA-2896; this PR makes rejected writes recoverable but does not rewrite graph-sync liveness.Fixes STA-2830.