Repository navigation
fix(wsl): main's background terminal starts never start a stopped WSL distro - #35865
Conversation
Walkthrough
Priority: Merge Risk:
|
[Medium impact] The change reaches main-side terminal starts in WSL workspaces. The PR needs the two existing fixes before merging: background OpenCode preparation can still boot WSL, and explicit desktop wake or restart can remain held. FindingsSummaryAdds a default background-start flag to main-side terminal starts and extends the WSL hold to fresh terminals.
|
| // Default-deny (E9): a main-side start is background work unless its caller names the user's act. | ||
| if (!ctx.preAdoptedStablePane && args.wslUserAct !== true) { | ||
| ctx.spawnOptions.wslBackgroundStart = true | ||
| } |
There was a problem hiding this comment.
OpenCode probes start WSL early
buildRuntimePtySpawnOptions calls assemblePtySpawnLaunchOptions before the stopped-distro check. When the OpenCode cache is cold, that preparation runs a guest --version command through runWslProcess. A background restore that resumes OpenCode can therefore boot the distro before the provider checks wslBackgroundStart. The later check sees a running distro and allows the start.
Check the distro before any guest launch preparation, while keeping wslUserAct launches allowed.
Knowledge Base Used: Stop WSL watchers from killing cold distro boots
This comment has been minimized.
This comment has been minimized.
3f71c3f to
c3ae8bd
Compare
| // Default-deny (E9): a main-side start is background work unless its caller names the user's act. | ||
| if (!ctx.preAdoptedStablePane && args.wslUserAct !== true) { | ||
| ctx.spawnOptions.wslBackgroundStart = true | ||
| } |
There was a problem hiding this comment.
In the layout-owner build, explicit desktop wake and restart requests still call ensureRestoredPaneStarted(pane) without wslUserAct. This new default marks those requests as background work. When their WSL distro is stopped, the hold rejects the start, so the user's requested terminal stays held.
Pass wslUserAct: true from explicit wake and restart requests while keeping passive restores unmarked.
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

Major · Release the resume claim when WSL holds the start. · restored-pane-materialize.ts:310
src/main/runtime/session-lifecycle/projection/restored-pane-materialize.ts:310
🎯 Functional Correctness | 🟠 Major | ⚡ Quick winRelease the resume claim when WSL holds the start.
A background restore can receive a WSL hold after
onPtySpawnDispatchedsetsdispatched. Although the hold proves no PTY started,settleFailure(true, err)retains the claim indefinitely. A later conversation resume into another pane then returnsheld_elsewhere, even after a same-pane retry succeeds. (raw.githubusercontent.com)Treat the authoritative WSL hold errors as proven non-spawn failures when settling the claim.

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:
08039cee-78a3-4d33-a3d0-f27acb77fc30
Files selected for processing: 28-
src/main/daemon/daemon-pty-adapter-wsl-passive-restore-hold.test.tssrc/main/daemon/daemon-wsl-passive-restore-hold.tssrc/main/ipc/pty/runtime/spawn-options.tssrc/main/ipc/pty/runtime/spawn-preflight-requested-shell.test.tssrc/main/ipc/pty/runtime/spawn-state.tssrc/main/providers/pty-provider-contract.tssrc/main/runtime/orca-runtime-create-agent-session.tssrc/main/runtime/orca-runtime-create-terminal-dependencies.tssrc/main/runtime/rpc/methods/agent-launch-floating-workspace.test.tssrc/main/runtime/rpc/methods/agent-launch-surfaces.tssrc/main/runtime/rpc/methods/agent-launch.test.tssrc/main/runtime/rpc/methods/agent-session.test.tssrc/main/runtime/rpc/methods/terminal/terminal-lifecycle-methods.tssrc/main/runtime/runtime-pty-controller-contract.tssrc/main/runtime/runtime-terminal-contracts.tssrc/main/runtime/session-construction/agent-session/get-agent-session-execution-namespace.tssrc/main/runtime/session-lifecycle/projection/perform-mobile-session-pty-records-refresh.tssrc/main/runtime/session-lifecycle/projection/restored-pane-materialize.tssrc/main/runtime/session-lifecycle/projection/resume-agent-session-in-workspace.tssrc/main/runtime/terminal/launch/failed-start-pane.tssrc/main/runtime/terminal/launch/mobile-terminal-chat-fork-create.tssrc/main/runtime/terminal/launch/mobile-terminal-create.tssrc/main/runtime/terminal/launch/mobile-terminal-owned-create.tssrc/main/runtime/terminal/launch/mobile-terminal-renderer-create.tssrc/main/runtime/terminal/launch/terminal-split-in-main.tssrc/main/runtime/terminal/launch/terminal-split-surface.tssrc/main/runtime/terminal/launch/terminal-split.tssrc/main/runtime/terminal/recovery/restored-pane-start.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
-
| // Default-deny (E9): a main-side start is background work unless its caller names the user's act. | ||
| if (!ctx.preAdoptedStablePane && args.wslUserAct !== true) { | ||
| ctx.spawnOptions.wslBackgroundStart = true |
There was a problem hiding this comment.
Check the WSL state before launch preparation.
When a background OpenCode launch targets a stopped WSL distro, assemblePtySpawnLaunchOptions runs before this marker is set. Its OpenCode capability probe can execute wsl.exe on a cold cache. That probe starts the distro before the daemon’s hold check. The later check can then see a running distro and allow the background terminal. Move the settled-state check ahead of guest-side preparation, or prevent guest probes for held background starts. Add a cold-cache test for this path. (raw.githubusercontent.com)
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

Major · Carry wslUserAct into new-workspace startup terminals. · headless-automation-agent-launch.ts:71
src/main/automations/headless-automation-agent-launch.ts:71
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy liftCarry
wslUserActinto new-workspace startup terminals.For
new_per_run, the startup terminal is created bycreateManagedWorktree, notlaunchAgentTerminal. That path omitswslUserAct, so a non-scheduled run can be held when its WSL distro is stopped. Forward the trigger and preserve the missing marker for scheduled runs.Suggested fix
- type HeadlessAutomationRunForWorkspace = Pick<AutomationRun, 'id' | 'title' | 'scheduledFor'> + type HeadlessAutomationRunForWorkspace = Pick< + AutomationRun, + 'id' | 'title' | 'scheduledFor' | 'trigger' + > return { repoSelector: repo.id, name: buildHeadlessAutomationWorkspaceName(run.title, run.scheduledFor), + ...(run.trigger === 'scheduled' ? {} : { wslUserAct: true as const }),startupAgent?: TuiAgent + wslUserAct?: truetelemetry: sequencedStartup.telemetry, + ...(request.wslUserAct ? { wslUserAct: true } : {}), // Keep failed starts visible in their panes.

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:
51ec8824-ec94-402b-8462-bfbd7669603f
Files selected for processing: 5-
src/main/automations/headless-automation-agent-launch.test.tssrc/main/automations/headless-automation-agent-launch.tssrc/main/automations/runtime-automation-service.test.tssrc/main/runtime/terminal/launch/terminal-create-deduplication.tstests/e2e/launch-agent-background-session-remote.unit.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
-
… distro Every start main makes through the runtime controller is background work unless its caller names the user's act (CLI and window creates and splits, paired-client creates and tab opens, agent launches and sessions, conversation resumes). #35813's hold now also holds those fresh and restored starts while the distro is stopped or unverifiable.
…pectations A headless automation's Run now names the user's act through launchAgentTerminal, so it may start a stopped WSL distro; a scheduled run stays background and is held. The paired-client background create expectation now includes wslUserAct.
…ssively With #35899's folder stat gate, the runtime preflight passes passiveWslRestore = !wslUserAct, so a background start never stats a stopped distro's folder as a user act before the daemon hold.
952597b to
891ed99
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

Major · Hold background starts before resolving the startup cwd. · spawn-preflight.ts:70
src/main/ipc/pty/runtime/spawn-preflight.ts:70
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy liftHold background starts before resolving the startup cwd.
For a non-folder WSL workspace with a POSIX
cwd,resolvePtySpawnStartupTargetcan callwslUncDirectoryExistsAsync. That probe runswsl.exe -d … --execbefore the daemon receiveswslBackgroundStart, so it can boot a stopped distro. Apply the background hold before the probe, including for fresh sessions. (raw.githubusercontent.com)

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:
36563b82-df9d-4080-a2dc-85f07d9be8b4
Files selected for processing: 2-
src/main/ipc/pty/runtime/spawn-preflight-requested-shell.test.tssrc/main/ipc/pty/runtime/spawn-preflight.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.
-
| localPtySpawnCwd(args) | ||
| localPtySpawnCwd(args), | ||
| // Main's background start must not stat a stopped distro's folder as a user act (E9). | ||
| args.wslUserAct !== true |
There was a problem hiding this comment.
Require a fresh distro check before the folder stat.
The passive admission path uses blockedWslDistroForPath, which can reuse a running result for 60 seconds. If the distro stops without a stop notification during that lease, the subsequent folder stat can boot it before the daemon checks it. Use a fresh running-state check for this admission path. (raw.githubusercontent.com)
ELI5
When Orca's own background work opens a terminal in a WSL workspace whose distro is stopped, starting that terminal (
wsl.exe) boots the distro with nobody asking. That work includes agent orchestration, recovery and main's own restores. #35813 stopped this for terminals the window restores by itself. This PR does the same for terminals main starts.A terminal you ask for still starts the distro as before. That covers a CLI command (typed by you or by an agent), a window or phone create, an agent launch, or a resumed conversation.
User risk: low to medium.
terminal_held_wsl_distro_stopped:<distro>, orterminal_held_wsl_distro_unverifiable:<distro>when the read can't tell (fix(wsl): a held pane whose distro could not be checked says so, not that it stopped #35860).What Changed
spawnPtyFromRuntimeControllerstarted any main-side terminal, and a\\wsl.localhostcwd started its distro. fix(wsl): a passive restore never starts a stopped WSL distro; its bridge panes wait with Start #35813's hold only covered the window's passive restores.wslBackgroundStart: trueunless its caller passeswslUserAct: true(spawn-options.ts). Renderer IPC spawns don't go through this, so fix(wsl): a passive restore never starts a stopped WSL distro; its bridge panes wait with Start #35813's rules still govern them.holdPassiveRestoreOfStoppedWslDistronow also holds awslBackgroundStartspawn, fresh or restored, unlessreadWslDistroRunningState(..., { retryUnverifiable: true })saysrunning. It throws the same hold error, built with fix(wsl): a held pane whose distro could not be checked says so, not that it stopped #35860'swslDistroHoldMessage(distro, state). Attach-only spawns and non-WSL cwds are untouched.createTerminal/ split options →callerSpawnScope/spawnInAdmittedPane→RuntimePtySpawnArgs.passiveWslRestore = wslUserAct !== trueinto fix(wsl): never boot a stopped distro to check a folder workspace's path #35899's folder-workspace admission check. That way a background start in a folder workspace never stats a stopped distro's UNC folder as a user act before the daemon hold.wslUserAct: true):terminal.createandterminal.split(both paths)startWindowTabTerminal)runCreateMobileSessionTerminal) and chat forksautomatictrigger stays background, via a newRestoredPaneTrigger.wslUserActlaunchAgentTerminal({ wslUserAct }). A scheduled run stays background (fix(automations): a scheduled run never starts a stopped WSL distro #35857 also gates scheduled runs at dispatch).running.MobileTerminalCreateOptionsmoved frommobile-terminal-renderer-create.tstomobile-terminal-create.ts, besideOwnedMobileTerminalCreateOptions, to keep that file under max-lines. It's a type move only.Why
Known gaps (not in this PR):
Linked Issue
N/A (maintainer change; follow-up noted on #35813)
Visual Proof
N/A: no UI change in this PR.
Testing
daemon-pty-adapter-wsl-passive-restore-hold.test.ts(realDaemonServer):spawn-preflight-requested-shell.test.ts:wslBackgroundStart, and one marked withwslUserActdoesn't;headless-automation-agent-launch.test.ts: a headless Run now passeswslUserAct; a scheduled run doesn't, so the hold applies.agent-launch*.test.ts,agent-session.test.tsandtests/e2e/launch-agent-background-session-remote.unit.test.ts(Claude and Codex): exact createTerminal expectations now includewslUserAct: true.pnpm tc,pnpm run typecheck:ci,oxlint, the anti-slop lint,check:code-quality:changed, the ast-grep test and gates, and the daemon, pty and runtime suites.daemon-shutdown-final-checkpoint-caller-deadline,terminal-tail-redraw-wall-time) failed under full load and pass alone.Review
Agent skill upstream boundary
Notes
wslDistroForPathfinds no distro, so the hold never fires there.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)