Skip to content

fix(agent-hooks): the WSL hook relay stays down while its distro is stopped (E9) - #34195

Merged
nwparker merged 3 commits into
mainfrom
nwparker/wsl-hook-relay-no-boot-restart
Oct 27, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/wsl-hook-relay-no-boot-restart

Conversation

@nwparker

@nwparker nwparker commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​185 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​184
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​151 $\color{#cf222e}{\Huge{\mathbf{−}}}$​22 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​129

ELI5

After wsl --terminate, the WSL hook relay (which carries agent status from WSL terminals back to Orca) noticed its link had died and, about 10 s later, restarted. The restart ran wsl.exe … launch.sh, which switched the stopped distro back on. Now the relay stays down while its distro is stopped, and comes back by itself when the distro runs again or when you open a WSL terminal.

What Changed

  • Fresh running-list read. The relay's restart already asked whether the distro runs, but any confirmed answer counted, including one from a running-list read that started before the link died.
    • It now passes startedAfter, set to the moment the restart check runs, so only a read that started then can allow the restart. A read that started just after the terminate, while WSL still listed the distro, can't. This reuses the shared rule in wsl-running-distro-cache.ts.
    • isWslDistroRunning and listConfirmedRunningWslDistros take the option and pass it through.
    • A failed read still counts as stopped.
  • Stay down, come back.
    • When the distro isn't confirmed running, the relay drops its state as before and stays down.
    • It also registers deferUntilWslDistroRunning, so it restarts once something else, such as the user, is seen to have started the distro. It never boots the distro itself.
    • Opening a WSL terminal still re-ensures it immediately, as before.
    • Before dropping the state, it saves every relay config field: the managed Codex home, the Claude agent view and config dirs, the OpenCode overlays, and the pi/omp setups. The deferred restart seeds them back for the ensure call, so the relay comes back with everything it had. If that ensure gives up (gate closed, no bundle), the seed is removed. A relay that a terminal already brought back stays as it is.
    • After 30 s it re-reads the running list once. If an earlier read failed while the distro was actually running, this brings the relay back without waiting for a terminal. The re-read and the deferred restart share one guard, so the relay restarts at most once.
  • Files: src/main/agent-hooks/wsl-hook-relay-recovery.ts, wsl-hook-relay-state-machine.ts (the restart and recovery wiring moved here so the manager stays within the line limit), wsl-hook-relay-manager.ts, wsl-hook-relay-deps.ts, src/main/wsl-background-distro-gate.ts.

Why

E9 says nothing boots a stopped distro in the background. The relay's restart is background work. The startedAfter rule is the one the WSL host liveness code already uses after an exit.

Linked Issue

WSL re-write, gate E9. Evidence: verify-15b final (5e-2-terminate-log.txt, logs-noauto/).

Visual Proof

N/A: no UI.

Testing

  • wsl-hook-relay-recovery.test.ts: the restart's running-list read is anchored at check time, not at the terminate; after a terminate the relay stays down, never restarts on its own, and restarts once the deferred "distro runs again" fires.
  • The deferred restart uses the config saved before the drop, and the restart seed carries every config field. A seed is removed if the ensure gives up, and a relay a terminal already brought back is left alone. The 30 s re-read restarts a relay that is actually running exactly once.
  • All hook relay suites (67) pass, plus the other callers of isWslDistroRunning (codex runtime home routing, kimi, guest pane processes, running-distro cache).
  • pnpm tc:node and check:code-quality:changed pass.

Review

Self-reviewed.

Agent skill upstream boundary

  • Not applicable.

Notes

  • Flag-off: the hook relay serves WSL bridge panes for every user. It isn't behind the WSL hosts gate, so this change applies with the gate closed too. The only difference users can see is that a relay whose distro was stopped stays down until the distro runs again or a WSL terminal opens; before, it booted the distro.
  • Not ruled out: at the terminate, the same log has fs:readDir realpath on \\wsl.localhost\<distro>\…\p10 erroring. Access to a \\wsl.localhost path can itself start a stopped distro, so the file explorer reading a bridge project's UNC path may be a second background booter. That needs process-level evidence to confirm.

…topped (E9)

verify-15b: after `wsl --terminate`, the relay link died ("mux disposed
(connection_lost); scheduling restart") and about 10 s later a `wsl.exe … launch.sh`
restart booted the stopped distro. The restart already asked whether the distro
runs, but any running-list answer would do, including one from a read that started
before the link died. Now:
- only a confirmed running-list read started after the link died can allow the
  restart (the shared startedAfter rule; a failed read counts as stopped);
- while the distro is stopped the relay stays down, and it comes back on its own once
  something else confirms the distro runs again (deferUntilWslDistroRunning), or when
  a WSL terminal re-ensures it as before. Nothing in recovery boots a distro.

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The WSL distro gate now accepts an optional startedAfter timestamp. Relay recovery passes the link-death time to the running-state probe. If the distro is stopped or the probe fails, recovery drops the current state and defers a restart until the distro runs again. The deferred task checks that the relay is not disposed before restarting it.

Priority: Normal

Merge Risk: Moderate · up to 05189

After a stopped WSL distro starts again, a relay using a redirected Codex home may restart without restoring its hooks. Preserve the installation context before merging.

Pre-merge checks: Passed 3 · Failed 1 · Inconclusive 1

Failed Failed checks: 1 warning · 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.67% 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 surv… Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Inconclusive The description follows the template well: it has ELI5, What Changed, Why, Linked Issue, Visual Proof (N/A with reason), Testing with checkboxes, Review, Agent skill upstream boundary, and Notes. The … 1. Replace the free-text Linked Issue with an actual issue reference (for example, 'Fixes #NNNN'), or confirm the author is a StablyAI maintainer and that no issue is needed. 2. State whether the changes were manually tested locally and on …
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly identifies the WSL hook relay recovery bug and the E9 fix.
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: Docstring Coverage

Explanation

Docstring coverage is 66.67% 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 3 functions across 6 files.

Resolution

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

Full details: Description check

Explanation

The description follows the template well: it has ELI5, What Changed, Why, Linked Issue, Visual Proof (N/A with reason), Testing with checkboxes, Review, Agent skill upstream boundary, and Notes. The change is clearly explained with before/after behavior and mechanism. Gaps: the Linked Issue section cites a 'WSL re-write, gate E9' and verify log rather than a GitHub issue reference like 'Fixes #', and the template asks for an actual linked issue for outside contributors. The Testing checklist does not show that manual testing was done (the first box is unchecked), and the Checklist section is absent. The AI Disclosure section is empty, which is acceptable only if the author is a StablyAI team member. The Testing section does not state which platforms were tested (Windows/WSL is implied but not explicitly listed as manually tested). Notes do not explicitly address Security, Mobile, or performance, although flag-off and remote/WSL impact are discussed.

Resolution

  1. Replace the free-text Linked Issue with an actual issue reference (for example, 'Fixes #NNNN'), or confirm the author is a StablyAI maintainer and that no issue is needed. 2. State whether the changes were manually tested locally and on which platforms (Windows with WSL, and others as applicable), or explain why manual testing was not done. 3. Add a brief statement covering security, cross-platform (Linux, Windows, Mac), SSH/remote, mobile, backward compatibility, and performance, as the template's Notes section requests. 4. Address the template's Checklist section, or confirm which items apply. 5. Fill in the AI Disclosure section if the author is not a StablyAI team member. 6. Optionally, clarify the Visual Proof N/A reason is sufficient (it is: no UI).
Finishing Touches
📝 Generate docstrings
  • 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.

@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.

Actionable comments posted: 1


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: ac1070dc-00c0-4ee3-95f3-24421da02d0d
Commits

Reviewing files that changed from the base of the PR and between 028f609 and 0518921.

Files selected for processing: 6
  • src/main/agent-hooks/wsl-hook-relay-deps.ts
  • src/main/agent-hooks/wsl-hook-relay-manager.test.ts
  • src/main/agent-hooks/wsl-hook-relay-manager.ts
  • src/main/agent-hooks/wsl-hook-relay-recovery.test.ts
  • src/main/agent-hooks/wsl-hook-relay-recovery.ts
  • src/main/wsl-background-distro-gate.ts

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

…rred relay restart

A stopped verdict dropped the relay state before the deferred restart ran, so the
relay came back without the managed Codex home or the pi/omp launch setups.
Capture them first and pass them through. Also re-probe once after 30 s so a
failed running-list read while the distro is up does not leave the relay down.
…ep all relay config

The running-list read must start when the restart check runs, not when the link
died: a read begun right after a terminate can still list the distro. A deferred
restart now seeds every relay config field (Codex home, Claude agent view and
config dirs, OpenCode overlays, pi/omp setups) so ensure brings them back.
@nwparker
nwparker merged commit 584b112 into main Oct 27, 2026
3 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