Skip to content

fix(runtime): seed terminal previews and titles from restore payloads - #12579

Merged
Jinwoo-H merged 2 commits into
mainfrom
restore-payload-record-seed
Aug 5, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
restore-payload-record-seed

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

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/title only ever populated from live bytes via runtime.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 as connected: true with blank title/preview and an empty terminal read tail 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.

  • New 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 existing applySeededAgentStatus seed precedent (live-tracked title outranks payload).
  • Wired in ipc/pty.ts right after registerPty, independent of the renderer-authority emulator gate, so desktop (where the headless emulator seed is skipped) still seeds records.
  • lastTitle threaded through pty-spawn-result, the daemon adapter reattach result, and the cold-restore payload cache (inside the payload so cached re-delivery keeps it).
  • Strict seed semantics: only empty never-output records accept a seed; lastOutputAt/waitBlockedAt are 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

  • New terminal-restore-record-seed.test.ts (7) + 3 end-to-end cases in pty.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.
  • Suites: pty.test.ts 437 ✅, orca-runtime.test.ts 1022 ✅, daemon-pty-adapter / cold-restore-payload-cache / terminal-list-stale-leaf-liveness ✅; tsc node ✅; oxlint ✅. Independently re-verified by the coordinating session (448/448 across the three key files).

Review notes

  • ANSI safety: same normalizer as live bytes (no escape leakage; CR spinner redraws collapse; slice re-anchors after the first newline so a mid-escape cap can't corrupt).
  • Cost: one bounded 256 KiB parse per restore, at spawn time only.
  • Known non-goal: the runtime-controller createTerminal spawn path never ingested restore payloads before either (pre-existing; restart-restore flows go through the renderer spawn handler this covers).

@Jinwoo-H
Jinwoo-H changed the base branch from terminal-session-restore-upgrade-repro to main August 5, 2026 00:20
OrcaWin added 2 commits August 4, 2026 20:22
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.
@Jinwoo-H
Jinwoo-H force-pushed the restore-payload-record-seed branch from f24b9f0 to ebcb3c7 Compare August 5, 2026 00:22
@Jinwoo-H
Jinwoo-H merged commit 51ca82d into main Aug 5, 2026
46 checks passed
@Jinwoo-H
Jinwoo-H deleted the restore-payload-record-seed branch August 5, 2026 00:25
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c710adf4-46bd-4622-97de-c2e98607a37d

📥 Commits

Reviewing files that changed from the base of the PR and between 3d8131d and ebcb3c7.

📒 Files selected for processing (7)
  • src/main/daemon/cold-restore-payload-cache.ts
  • src/main/daemon/daemon-pty-adapter.ts
  • src/main/ipc/pty.test.ts
  • src/main/ipc/pty.ts
  • src/main/providers/pty-spawn-result.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/terminal-restore-record-seed.test.ts

📝 Walkthrough

Walkthrough

PTY 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
  • Create stacked PR
  • Commit on current branch

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.

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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]>
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.

2 participants