Skip to content

fix(terminal): a WSL bridge pane that lost its distro keeps its session across a relaunch - #34200

Merged
nwparker merged 1 commit into
mainfrom
nwparker/wsl-distro-loss-relaunch-restore
Oct 27, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/wsl-distro-loss-relaunch-restore

Conversation

@nwparker

@nwparker nwparker commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​139 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​138
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​21 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​16

ELI5

If a WSL distro is stopped (for example with wsl --terminate) while Orca has terminals open in it, Orca keeps those terminal tabs so they can come back. But after you quit and reopen Orca, those tabs started brand-new, empty shells, and the saved output was never used. Now they come back with their old output, the same way they do after a terminal-daemon crash.

What Changed

  • Before (verify-15b, step 5e, on a build that includes fix(terminal): a WSL bridge pane whose distro went away keeps its tab and cold-restores #34095): wsl --terminate the distro, then quit and relaunch. p10, p1 and p5 opened new sessions (new ids …p10@@973afe32, …p1@@85b95082, …p5@@c982ceb4 in the daemon log) with no history. p1's 49.5 KB checkpoint, still unended, was never read.
  • After: the kept tab is still bound to its old session after the relaunch, so opening it cold-restores that session's history.
  • Mechanism. fix(terminal): a WSL bridge pane whose distro went away keeps its tab and cold-restores #34095 made the bridge pane's exit "host loss": exit code -1, history left unended, tab kept in the window. But main's exit handling (onPtyExit) treats every exit the provider reports (providerExitObserved) as permanent. It retired the pane from the saved workspace session, removing the leaf and tab binding and its incarnation. On the next launch the tab had no session id, so the window spawned a fresh one. The adapter now labels that exit hostLost. The pty listener forwards it to onPtyExit, and the runtime keeps the pane's saved surface. Sleep panes and SSH panes that lose their connection already get this treatment. The process is still recorded as exited.

Why

  • The label comes from the one place that knows. Only the adapter's distro check knows the exit was host loss. A -1 code alone can't tell it apart from a failed stop or a real node-pty exit.
  • A private, main-only field. I used a field on the provider's exit event rather than a new TerminalExitCause reason. A new reason would be published to paired clients and phones. This field never leaves main, so nothing changes on the wire.
  • Not the restart path. I did not reuse the "replaced by restart" stop. The window would then respawn the pane as soon as it's shown, which would boot the distro the user just stopped.

Linked Issue

Internal: WSL via orcad, verify-15b 5e (relaunch after wsl --terminate loses sessions).

Visual Proof

N/A. This is about saved state. The tests reproduce the lost binding; verify-15c repeats the 5e check on Windows.

Testing

  • Automated tests added/updated. Each fails with the production change reverted:
    • src/main/runtime/wsl-distro-loss-exit-retention.test.ts: a host-loss exit, then quit, then the saved session still binds the leaf to its session and incarnation. A shell's own exit still retires the leaf.
    • src/main/ipc/pty/pty-host-lost-exit.test.ts: the pty listener passes hostLost to the runtime, and never adds it to an ordinary exit.
    • daemon-pty-adapter-wsl-distro-loss.test.ts: the host-loss exit carries hostLost; a normal exit doesn't.
  • pnpm tc, the ipc/pty, runtime exit-lifecycle, retirement and daemon adapter suites (166 files, 1,615 tests), and check:code-quality:changed pass.

User risk: only WSL bridge panes whose distro is confirmed gone are affected (#34095's path). Such a tab now keeps its session, and opening it restores that session (and boots the distro, as opening it does today). Everything else, including a shell's own exit, is unchanged.

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

  • SSH: untouched. The label is only set by the WSL bridge distro-loss path, and SSH exits go through their own route.
  • Wire: nothing changes. hostLost lives only in main's provider-to-runtime event.
  • Layout-owner build (off in shipped builds): that build's applyProcessExit still unbinds a leaf on any negative code. It will need the same exception before that path ships.

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 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0ebb2b77-5d16-4e53-b03a-15478d8b3161
Commits

Reviewing files that changed from the base of the PR and between 3708fac and 932a77a.

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

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ccb30de4-ef96-4853-85f1-fae7f20c8dfe
Commits

Reviewing files that changed from the base of the PR and between 7f846fd and 3708fac.

Files selected for processing: 9
  • src/main/daemon/daemon-pty-adapter-wsl-distro-loss.test.ts
  • src/main/daemon/daemon-pty-adapter.ts
  • src/main/daemon/daemon-pty-listener-emission.ts
  • src/main/daemon/daemon-pty-router-events.ts
  • src/main/ipc/pty/provider/bind-listeners.ts
  • src/main/ipc/pty/pty-host-lost-exit.test.ts
  • src/main/providers/pty-provider-contract.ts
  • src/main/runtime/terminal/lifecycle/pty-exit-lifecycle.ts
  • src/main/runtime/wsl-distro-loss-exit-retention.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

Host-loss exits now carry a hostLost flag from the daemon through provider listeners to the runtime. The runtime uses the flag to preserve terminal surfaces and mobile session snapshots. Tests cover flag propagation and workspace state retention after host loss, alongside ordinary exit behavior.

Estimated code review effort

Priority: Normal

Severity of issue fixed: Low

Merge Risk: Minimal · previous review 3708f

No actionable issue is established for this change; it is mergeable 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 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within survi… 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 identifies the terminal fix and the retained WSL session after relaunch. It matches the main change.
Description check Passed The description is detailed and covers the user impact, mechanism, rationale, testing, scope, and compatibility considerations. The Linked Issue section does not contain an actual issue link, and the …
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 detailed and covers the user impact, mechanism, rationale, testing, scope, and compatibility considerations. The Linked Issue section does not contain an actual issue link, and the full lint, typecheck, test, and build checklist items remain unchecked, but the description is otherwise mostly complete.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 9 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

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

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.

…on across a relaunch

#34095 turns a bridge pane's exit into host loss (code -1) when its distro is
gone, so the window keeps the tab and the history stays unended. But main's
exit handling still retired the pane's surface from the saved workspace
session, as for any provider-observed exit, so the next launch found no
session id for the tab and started a fresh shell instead of cold-restoring.

The adapter now labels that exit hostLost, the pty listener forwards it, and
the runtime keeps the surface, as it already does for a sleep or an SSH loss.

Co-Authored-By: Claude <[email protected]>
@nwparker
nwparker force-pushed the nwparker/wsl-distro-loss-relaunch-restore branch from 3708fac to 932a77a Compare October 27, 2026 03:01
@nwparker
nwparker merged commit ea1cb2f into main Oct 27, 2026
53 checks passed
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