Repository navigation
fix(runtime): seed terminal previews and titles from restore payloads - #12579
Conversation
After an app relaunch the PTY daemon survives and spawn silently reattaches, but the restore payload (reattach snapshot, cold-restore scrollback, relay replay, lastTitle) arrives as a spawn RPC result and never passes through runtime.onPtyData — the only feeder of the terminal records behind `terminal list`/`terminal read`. Every restart therefore left connected terminals with empty title/preview/lastOutputAt and a zero-line read tail, blinding orchestrators that poll terminals. The spawn flow now calls runtime.seedTerminalRestoreTail with the restore text and lastTitle, unconditionally of the renderer-authority emulator gate (the records are main-side only). The seed reuses the live path's normalize/tail/preview pipeline on a capped 256 KiB suffix (re-anchored at a line boundary so a cut escape cannot leak), only fills records that never saw output (a remount reattach cannot re-apply history), routes titles through the applySeededAgentStatus precedent (state writes only — no waiters, no side-effect facts), and never stamps lastOutputAt or waitBlockedAt: restored bytes are historical, not fresh activity. lastTitle is threaded from the daemon reattach snapshot and cold-restore checkpoint into PtySpawnResult; relay replays seed preview only. SSH and runtime-controller paths are unchanged — seeding is gated on the fields existing.
…prime the wait baseline Follow-ups to the restore-record seed, from independent verification: 1. The runtime-controller spawn flow (createTerminal background creates — headless `orca serve`/CLI — and pane splits) never consumed restore payloads, so the exact orchestrator-blindness this fix targets survived on the topology that needs it most. The extraction now lives in one helper called from both spawn choke points (renderer pty:spawn and the controller flow); the runtime's empty-record guard makes overlapping seeds a no-op. 2. The throttled per-PTY wait scanner starts with a null baseline, so a permission prompt visible only in seeded HISTORY read as newly gained on the first benign live chunk and stamped waitBlockedAt "now". Seeding now primes the scanner baseline from the seeded tail without stamping; only a signal appearing in genuinely new output counts. 3. Cap re-anchoring accepts \r as well as \n (newline-free CR-redraw streams), consuming a full \r\n pair so the seed does not start with a phantom blank line.
f24b9f0 to
ebcb3c7
Compare
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughPTY restore payloads now include optional OSC title metadata. Daemon reattach and cold-restore results propagate titles into PTY spawn results. PTY spawn paths seed runtime restore records with normalized historical tails and titles. Runtime logic bounds and truncates restored output, preserves live output precedence, initializes historical wait state, and avoids activity side effects. Tests cover renderer, serializer-owned, cold-restore, headless, title, truncation, and orphan PTY scenarios. ✨ Finishing Touches📝 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 |
…stablyai#12579) * fix(terminal): seed list/read records from reattach restore payloads After an app relaunch the PTY daemon survives and spawn silently reattaches, but the restore payload (reattach snapshot, cold-restore scrollback, relay replay, lastTitle) arrives as a spawn RPC result and never passes through runtime.onPtyData — the only feeder of the terminal records behind `terminal list`/`terminal read`. Every restart therefore left connected terminals with empty title/preview/lastOutputAt and a zero-line read tail, blinding orchestrators that poll terminals. The spawn flow now calls runtime.seedTerminalRestoreTail with the restore text and lastTitle, unconditionally of the renderer-authority emulator gate (the records are main-side only). The seed reuses the live path's normalize/tail/preview pipeline on a capped 256 KiB suffix (re-anchored at a line boundary so a cut escape cannot leak), only fills records that never saw output (a remount reattach cannot re-apply history), routes titles through the applySeededAgentStatus precedent (state writes only — no waiters, no side-effect facts), and never stamps lastOutputAt or waitBlockedAt: restored bytes are historical, not fresh activity. lastTitle is threaded from the daemon reattach snapshot and cold-restore checkpoint into PtySpawnResult; relay replays seed preview only. SSH and runtime-controller paths are unchanged — seeding is gated on the fields existing. * fix(terminal): seed restore records on the controller spawn path and prime the wait baseline Follow-ups to the restore-record seed, from independent verification: 1. The runtime-controller spawn flow (createTerminal background creates — headless `orca serve`/CLI — and pane splits) never consumed restore payloads, so the exact orchestrator-blindness this fix targets survived on the topology that needs it most. The extraction now lives in one helper called from both spawn choke points (renderer pty:spawn and the controller flow); the runtime's empty-record guard makes overlapping seeds a no-op. 2. The throttled per-PTY wait scanner starts with a null baseline, so a permission prompt visible only in seeded HISTORY read as newly gained on the first benign live chunk and stamped waitBlockedAt "now". Seeding now primes the scanner baseline from the seeded tail without stamping; only a signal appearing in genuinely new output counts. 3. Cap re-anchoring accepts \r as well as \n (newline-free CR-redraw streams), consuming a full \r\n pair so the seed does not start with a phantom blank line. --------- Co-authored-by: OrcaWin <[email protected]>
Stacked on #12574 (sibling of #12578; different regions of the same files, no overlap).
Summary
After a restart, the app silently reattaches to daemon-surviving PTYs, but
lastOutputAt/preview/titleonly ever populated from live bytes viaruntime.onPtyData— restore payloads (reattach snapshot, cold-restore scrollback, replay) arrived as RPC results and were never written into the model. Every reattached terminal therefore read asconnected: truewith blank title/preview and an emptyterminal readtail until it printed something new — the blindfold on autonomous orchestrators polling terminals after any restart (demonstrated live on run6-review-pr-12042:status: running, zero lines), and half the blast radius of the remote-host blank-pane handoff.seedTerminalRestoreTail(ptyId, {text?, lastTitle?}): runs the restore payload's 256 KiB tail suffix through the exact live pipeline (normalizeTerminalChunk→appendNormalizedToTailBuffer→ transcript →buildPreview) into the pty record and every bound leaf; titles route through the existingapplySeededAgentStatusseed precedent (live-tracked title outranks payload).ipc/pty.tsright afterregisterPty, independent of the renderer-authority emulator gate, so desktop (where the headless emulator seed is skipped) still seeds records.lastTitlethreaded throughpty-spawn-result, the daemon adapter reattach result, and the cold-restore payload cache (inside the payload so cached re-delivery keeps it).lastOutputAt/waitBlockedAtare never written (historical scrollback must not fake recency); no side-effect facts emitted; live bytes simply append on top; re-seeds are no-ops.Test plan
terminal-restore-record-seed.test.ts(7) + 3 end-to-end cases inpty.test.ts(real-runtime reattach spawn → non-empty preview/title + null lastOutputAt + readable tail; renderer-pre-signaled desktop path seeds records while the emulator seed stays skipped; cold-restore payload wiring). All red without the fix (verified by stashing sources: 5 fail), green with it.pty.test.ts437 ✅,orca-runtime.test.ts1022 ✅, daemon-pty-adapter / cold-restore-payload-cache / terminal-list-stale-leaf-liveness ✅;tscnode ✅;oxlint✅. Independently re-verified by the coordinating session (448/448 across the three key files).Review notes
createTerminalspawn path never ingested restore payloads before either (pre-existing; restart-restore flows go through the renderer spawn handler this covers).