Skip to content

feat(runtime): clients read a migrated pane's scrollback from its host (D1b-6d-1) - #29526

Closed
nwparker wants to merge 4 commits into
nwparker/wsl-move-reset-to-zerofrom
nwparker/wsl-mover-d1b-6d1-host-scrollback
Closed

nwparker wants to merge 4 commits into
nwparker/wsl-move-reset-to-zerofrom
nwparker/wsl-mover-d1b-6d1-host-scrollback

Conversation

@nwparker

@nwparker nwparker commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​528 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​528
Prod 22 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​726 $\color{#cf222e}{\Huge{\mathbf{−}}}$​112 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​614

Stacked for owner review — not to be merged by the agent. Bottom of the WSL-mover review stack (next: D1b-7a). Per the owner's merge policy this PR touches shared user paths, listed below.

Shared paths this PR touches

  • Every remote-runtime terminal pane's mount (SSH-converted hosts, paired runtimes, WSL hosts): TerminalPane can hold mount for up to 3 s, but only when the tab's own host is already known to serve scrollback reads.
  • Shared renderer capability cache (runtime-compatibility-cache.ts, moved from runtime-rpc-client.ts with re-exports): it now also remembers "unsupported" for the peek. Async callers are unchanged.
  • A new runtime RPC on every host (session.readTerminalScrollback) and its phone routing.
  • Preload: a new sync IPC session:has-terminal-scrollback-sync on the desktop, and a stub in the web preload.
  • Host routing: the tab's host comes from getExplicitRuntimeEnvironmentIdForWorktree (owner-only, never the focused host). That keeps the focus-read ratchet at baseline.

ELI5

A terminal pane on a remote Orca host shows its earlier output by replaying a saved copy. Today the app reads that copy only from this computer's disk. After a WSL project moves to its WSL host, this computer's copy is eventually cleaned up, and so it is for a web client that never had one. Either way the pane comes back empty. This PR lets the app ask the host for the saved copy when the local one is missing. Panes on hosts that don't support the new request open exactly as before, with no added wait.

What Changed

This is step D1b-6d-1 of the lossless WSL project mover. It also helps converted SSH hosts and web clients.

On the host:

  • New method: session.readTerminalScrollback takes {worktree, ref} and returns {buffer}, the same tail the desktop's own read returns.
  • Guarded:
    • It needs the workspace permission.
    • The ref must look like v1-<32 hex>.
    • It returns only refs that a tab in that worktree's session names. Anything else, or a missing file, gets the same terminal_scrollback_not_found, so a caller can't probe for refs in another workspace.
    • Files over the 5 MB store limit are refused before anything is read.
    • The read is asynchronous, so it doesn't block the host.
  • Wire: advertised with the new capability session.terminal-scrollback-read.v1 and routed for phones; the params catalog is updated.

On the client:

  • When a pane waits: a remote pane whose saved copy is missing locally holds mount for at most 3 seconds, showing the existing "Restoring terminal…" placeholder, and only when the host is already known to serve copies.
    • Unknown or old hosts: the pane mounts immediately while the answer is fetched in the background, once per host.
    • Live panes: they never wait, because their live screen replaces the history anyway.
  • What it reads: the client checks only that the local file exists, never reading its bytes during render. It then fetches each missing copy from the host and stores the bytes as local-only scrollback, which the normal restore replays.
    • Late and failed reads: bytes that arrive after the pane mounts are dropped. A read that times out or fails can be retried later, for example after the host reconnects.
  • Shared change: the capability cache now also remembers a host's "unsupported" answer for the same 60 seconds, so many tabs on an older host don't each ask. Other callers of the async capability check still re-check after a "no" and see host upgrades. The cache code moved into its own file, with re-exports, so existing imports still work.
  • Web clients: they use the same path, since they have no local copy.
  • Cleanup: unchanged in this PR. A comment at the cleanup site points to the host read.

Why

The move hands a pane's tabs to its host, and cleanup then deletes this computer's copy of the scrollback. Without a host read, moved panes would lose their history. A capability-gated method is the only way that's safe with mixed versions. Older hosts never get the call, and older clients never make it.

The client waits only when the host is known to serve the read. Waiting on every remote pane while checking would have added up to 3 seconds to many pane mounts, especially for web clients.

Linked Issue

N/A (maintainer; tracked in the WSL-via-orcad implementation tracker, step D1b-6).

Visual Proof

N/A: no new UI. The existing "Restoring terminal…" placeholder may show briefly when a host serves a missing copy.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Host:

    • returns bytes for a held ref;
    • refuses a ref from another worktree without reading;
    • refuses unknown worktrees, missing files and missing sessions;
    • refuses oversize files before reading.
  • Registration: the method is registered once, the capability is advertised, and the params schema rejects malformed refs.

  • Client:

    • no hold when the capability is unknown or absent;
    • the hold applies once it's cached as present;
    • the background check runs once per host;
    • leaves with a live terminal are skipped;
    • the local copy is checked only once;
    • failures are retried, while not-found and stored copies are not;
    • reads abort at the deadline;
    • bytes never land in an already-mounted pane;
    • local panes never call the host;
    • the web preload path works.
  • Cache: the capability peek, the cached old-host answer, and async callers still re-checking.

  • Checks: pnpm tc:node, pnpm tc:web, both oxlint configs, and the changed-code quality gate pass. One test failed in a full run and passed when rerun alone: structured-agent-shell-environment.test.ts (14/14 alone).

  • End-to-end: not added yet. The scenario only exists once the move's desktop rewrite (D1b-7) moves tabs off the local partition, so it will come with that step.

  • Adversarial review: found one HIGH issue (hold latency before the capability was known) and five MEDIUM/LOW issues, all fixed here:

    • a synchronous file read during render;
    • one failure disabling recovery for the session;
    • wasted reads after mount;
    • a blocking host read;
    • a size check that never ran.

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

This touches every remote-runtime pane: SSH-converted hosts, paired runtimes and WSL hosts. Hosts without the capability behave exactly as before, with no hold and no extra request per tab.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

  • Last reviewed commit: b86fcc6
  • Latest commit, not reviewed: d034364bee12d1b8af2329bf32f2354590463332

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 25f87947-2c81-47b6-b12f-a450fde64416
📥 Commits

Reviewing files that changed from the base of the PR and between 9b87fc4 and b86fcc6.

📒 Files selected for processing: 1
  • src/renderer/src/components/terminal-pane/remote-snapshot-alt-screen-host-chain.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

📝 Walkthrough

The change adds host-side RPC access to stored terminal scrollback and renderer hydration for eligible terminal tabs. Snapshot references are validated, checked against the selected worktree, and size-checked before the host reads them. The renderer uses cached runtime capability status to determine whether to hold mounting for a pending read, and stores returned data only while the tab and snapshot reference remain eligible.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to b86fc

The test setup change does not establish a merge-blocking issue. Merge after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 44 functions across 28 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main change: clients read migrated terminal scrollback from the host.
Description check Passed The description is mostly complete and directly matches the change. It covers the user impact, implementation, rationale, testing, compatibility, visual proof, and checklist. The maintainer-specific l…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is mostly complete and directly matches the change. It covers the user impact, implementation, rationale, testing, compatibility, visual proof, and checklist. The maintainer-specific linked-issue exception is addressed, and the reported isolated test failure is disclosed.

✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔇 Additional comments: 27
src/main/terminal-scrollback-snapshot-nonblocking-reads.ts: 1

1-71: LGTM!

src/main/terminal-scrollback-snapshots.ts: 1

57-60: LGTM!

Also applies to: 125-129, 267-272

src/main/persistence/loading-store/session-host-partitions.ts: 1

119-139: LGTM!

src/main/persistence-workspace-session-scrollback.test.ts: 1

413-418: LGTM!

src/main/persistence/migrating-orcad-catalog/orcad-source-scrollback-cleanup.ts: 1

17-17: LGTM!

src/main/ipc/session.ts: 1

78-86: LGTM!

src/preload/api/session-bridge.ts: 1

13-15: LGTM!

src/preload/api/workspace-session-api.ts: 1

25-26: LGTM!

src/renderer/src/web/preload-api/web-workspace-session-api.ts: 1

88-90: LGTM!

src/shared/rpc-contract/session-terminal-scrollback-params.ts: 1

1-11: LGTM!

src/shared/session-tabs-runtime-capabilities.ts: 1

10-18: LGTM!

src/main/runtime/runtime-store-contract.ts: 1

56-57: LGTM!

src/main/runtime/host-terminal-scrollback-read.ts: 1

1-57: LGTM!

src/main/runtime/orca-runtime-migration-catalog.ts: 1

157-177: LGTM!

src/main/runtime/rpc/methods/session-terminal-scrollback.ts: 1

1-13: LGTM!

src/main/runtime/rpc/methods/index.ts: 1

75-75: LGTM!

src/main/runtime/runtime-rpc/runtime-rpc-mobile-method-routing.ts: 1

166-166: LGTM!

src/main/runtime/rpc/methods/session-terminal-scrollback.test.ts: 1

1-29: LGTM!

src/main/runtime/host-terminal-scrollback-read.test.ts: 1

1-135: LGTM!

src/renderer/src/runtime/runtime-compatibility-cache.ts: 1

1-130: LGTM!

src/renderer/src/runtime/runtime-rpc-client.ts: 1

12-26: LGTM!

Also applies to: 103-104, 120-120, 149-150, 167-167

src/renderer/src/runtime/runtime-rpc-client-capability-peek.test.ts: 1

1-71: LGTM!

src/renderer/src/runtime/host-terminal-scrollback-hydration.test.ts: 1

1-234: LGTM!

src/renderer/src/components/terminal-pane/use-host-terminal-scrollback-hold.ts: 1

1-35: LGTM!

src/renderer/src/components/terminal-pane/use-host-terminal-scrollback-hold.test.ts: 1

1-53: LGTM!

src/renderer/src/components/terminal-pane/TerminalPane.tsx: 1

2-18: LGTM!

src/renderer/src/runtime/host-terminal-scrollback-hydration.ts-99-117: 1

99-117: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Do not cache localSnapshotRefs permanently.

localSnapshotRefs stores a positive result and never removes it. A local snapshot can disappear later in the same renderer session. The orcad migration cleanup deletes local copies of host-run panes, and the comment at orcad-source-scrollback-cleanup.ts Line 17 says those panes recover from the host. If a ref was cached before that deletion, planHostScrollbackHydration still skips the leaf. The pane then mounts with no history and does not ask the host.

The cached stat is cheap to repeat because the plan runs only for leaves with no PTY and no buffer. Remove the cache, or remove a ref from it when the local read returns null.

Proposed fix
 function hasLocalSnapshotCached(ref: string, deps: HostTerminalScrollbackHydrationDeps): boolean {
-  if (localSnapshotRefs.has(ref)) {
-    return true
-  }
-  if (!deps.hasLocalSnapshot(ref)) {
-    return false
-  }
-  localSnapshotRefs.add(ref)
-  return true
+  return deps.hasLocalSnapshot(ref)
 }

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: aa9ecf77-dd87-467f-b2c8-24acfd423466
📥 Commits

Reviewing files that changed from the base of the PR and between 5167994 and fc6d0b0.

⛔ Files ignored due to path filters: 1
  • src/shared/rpc-contract/rpc-params-catalog.generated.ts is excluded by !**/*.generated.*
📒 Files selected for processing: 27
  • src/main/ipc/session.ts
  • src/main/persistence-workspace-session-scrollback.test.ts
  • src/main/persistence/loading-store/session-host-partitions.ts
  • src/main/persistence/migrating-orcad-catalog/orcad-source-scrollback-cleanup.ts
  • src/main/runtime/host-terminal-scrollback-read.test.ts
  • src/main/runtime/host-terminal-scrollback-read.ts
  • src/main/runtime/orca-runtime-migration-catalog.ts
  • src/main/runtime/rpc/methods/index.ts
  • src/main/runtime/rpc/methods/session-terminal-scrollback.test.ts
  • src/main/runtime/rpc/methods/session-terminal-scrollback.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-mobile-method-routing.ts
  • src/main/runtime/runtime-store-contract.ts
  • src/main/terminal-scrollback-snapshot-nonblocking-reads.ts
  • src/main/terminal-scrollback-snapshots.ts
  • src/preload/api/session-bridge.ts
  • src/preload/api/workspace-session-api.ts
  • src/renderer/src/components/terminal-pane/TerminalPane.tsx
  • src/renderer/src/components/terminal-pane/use-host-terminal-scrollback-hold.test.ts
  • src/renderer/src/components/terminal-pane/use-host-terminal-scrollback-hold.ts
  • src/renderer/src/runtime/host-terminal-scrollback-hydration.test.ts
  • src/renderer/src/runtime/host-terminal-scrollback-hydration.ts
  • src/renderer/src/runtime/runtime-compatibility-cache.ts
  • src/renderer/src/runtime/runtime-rpc-client-capability-peek.test.ts
  • src/renderer/src/runtime/runtime-rpc-client.ts
  • src/renderer/src/web/preload-api/web-workspace-session-api.ts
  • src/shared/rpc-contract/session-terminal-scrollback-params.ts
  • src/shared/session-tabs-runtime-capabilities.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

@nwparker
nwparker force-pushed the nwparker/wsl-mover-d1b-6d1-host-scrollback branch 3 times, most recently from 371a5d0 to 9b87fc4 Compare October 16, 2026 12:02
@nwparker
nwparker force-pushed the nwparker/wsl-mover-d1b-6d1-host-scrollback branch from b86fcc6 to 2e3663b Compare October 16, 2026 12:41
@nwparker
nwparker force-pushed the nwparker/wsl-mover-d1b-6d1-host-scrollback branch 2 times, most recently from f24ad83 to d034364 Compare October 20, 2026 23:15
@nwparker
nwparker changed the base branch from main to nwparker/wsl-move-reset-to-zero October 20, 2026 23:17
@nwparker
nwparker force-pushed the nwparker/wsl-move-reset-to-zero branch from 326cf4f to 50762d2 Compare October 21, 2026 00:44
@nwparker
nwparker force-pushed the nwparker/wsl-mover-d1b-6d1-host-scrollback branch from d034364 to b303971 Compare October 21, 2026 00:44
@nwparker

Copy link
Copy Markdown
Contributor Author

Contained in the dark landing PR #34059 (its head commit is an ancestor of the landing branch). Closing in favour of it; branch kept.

@nwparker nwparker closed this Oct 26, 2026
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.

1 participant