Skip to content

fix(wsl): main's background terminal starts never start a stopped WSL distro - #35865

Merged
nwparker merged 3 commits into
mainfrom
nwparker/wsl-background-start-gate
Oct 29, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/wsl-background-start-gate

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​120 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​115
Prod 26 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​119 $\color{#cf222e}{\Huge{\mathbf{−}}}$​53 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​66

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.

What Changed

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

  • I manually tested these changes locally
  • Automated tests added/updated:
    • daemon-pty-adapter-wsl-passive-restore-hold.test.ts (real DaemonServer):
      • a background new terminal, and a background restore of a saved pane, are held with nothing spawned while the distro is stopped;
      • once the distro runs, they spawn;
      • non-WSL starts are untouched.
    • spawn-preflight-requested-shell.test.ts:
      • an unmarked runtime spawn carries wslBackgroundStart, and one marked with wslUserAct doesn't;
      • the folder admission check is passive unless the start is the user's act.
    • headless-automation-agent-launch.test.ts: a headless Run now passes wslUserAct; a scheduled run doesn't, so the hold applies.
    • agent-launch*.test.ts, agent-session.test.ts and tests/e2e/launch-agent-background-session-remote.unit.test.ts (Claude and Codex): exact createTerminal expectations now include wslUserAct: true.
  • Ran 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.
    • Two timing-bound tests (daemon-shutdown-final-checkpoint-caller-deadline, terminal-tail-redraw-wall-time) failed under full load and pass alone.

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 and orcad hosts: the runtime controller refuses SSH execution, and inside a WSL guest wslDistroForPath finds no distro, so the hold never fires there.
  • Mixed versions: nothing changes on the wire. The flags live inside main's spawn options.

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

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The change marks non-pre-adopted PTY starts as background starts unless the caller marks a user action. The daemon checks WSL distribution state for background starts and qualifying passive restores. Runtime launch, mobile terminal, restored-pane, automation, and split paths now pass the user-action marker where applicable. Tests cover background-start hold behavior and verify that user-action markers are forwarded.

Priority: Normal

Merge Risk: Moderate · up to 891ed

This change aims to stop background terminal starts from booting a stopped WSL distro. Two preflight paths can still start one before the hold runs: the folder check can reuse a stale running result, and the startup working-directory probe runs before the hold. Previously raised concerns about launch preparation, held restores and automation launches also remain open. Fix these before merge, or explicitly accept the gaps.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… 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 describes the main change: preventing main-side background terminal starts from booting stopped WSL distributions.
Description check Passed The description includes all required sections and clearly explains the user impact, implementation, rationale, testing, known gaps, and compatibility considerations. It also records the two timing-bo…
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 includes all required sections and clearly explains the user impact, implementation, rationale, testing, known gaps, and compatibility considerations. It also records the two timing-bound test failures and the absence of manual testing.

Full details: Docstring Coverage

Explanation

Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 34 files.

Resolution

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

Finishing Touches: 💡 1
📝 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.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 3/5

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

Findings

  1. P1 OpenCode probes start WSL early ▶
  2. P1 Requested terminals stay held ▶

Summary

Adds a default background-start flag to main-side terminal starts and extends the WSL hold to fresh terminals.

  • Main's background terminal starts wait for a running WSL distro.
  • Explicit terminal, agent, and tab requests keep their ability to start WSL.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Main-side terminal request] --> B{wslUserAct?}
  B -->|Yes| C[Leave background flag unset]
  B -->|No| D[Set wslBackgroundStart]
  C --> E[Provider spawn]
  D --> E
  E --> F{Daemon WSL hold applies?}
  F -->|No| G[Continue]
  F -->|Yes| H{Distro proven running?}
  H -->|Yes| G
  H -->|No| I[Return named hold error]
Loading

Reviews (4) · Last reviewed commit: "fix(wsl): main's background start checks..." · Reviewed by Greptile

Comment on lines +127 to +130
// 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
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 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

@greptile-apps

This comment has been minimized.

@nwparker
nwparker force-pushed the nwparker/wsl-background-start-gate branch from 3f71c3f to c3ae8bd Compare October 29, 2026 09:41
Comment on lines +127 to +130
// 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
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Requested terminals stay held

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.

@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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

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 win

Release the resume claim when WSL holds the start.

A background restore can receive a WSL hold after onPtySpawnDispatched sets dispatched. Although the hold proves no PTY started, settleFailure(true, err) retains the claim indefinitely. A later conversation resume into another pane then returns held_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
Commits

Reviewing files that changed from the base of the PR and between a50b996 and c3ae8bd.

Files selected for processing: 28
  • src/main/daemon/daemon-pty-adapter-wsl-passive-restore-hold.test.ts
  • src/main/daemon/daemon-wsl-passive-restore-hold.ts
  • src/main/ipc/pty/runtime/spawn-options.ts
  • src/main/ipc/pty/runtime/spawn-preflight-requested-shell.test.ts
  • src/main/ipc/pty/runtime/spawn-state.ts
  • src/main/providers/pty-provider-contract.ts
  • src/main/runtime/orca-runtime-create-agent-session.ts
  • src/main/runtime/orca-runtime-create-terminal-dependencies.ts
  • src/main/runtime/rpc/methods/agent-launch-floating-workspace.test.ts
  • src/main/runtime/rpc/methods/agent-launch-surfaces.ts
  • src/main/runtime/rpc/methods/agent-launch.test.ts
  • src/main/runtime/rpc/methods/agent-session.test.ts
  • src/main/runtime/rpc/methods/terminal/terminal-lifecycle-methods.ts
  • src/main/runtime/runtime-pty-controller-contract.ts
  • src/main/runtime/runtime-terminal-contracts.ts
  • src/main/runtime/session-construction/agent-session/get-agent-session-execution-namespace.ts
  • src/main/runtime/session-lifecycle/projection/perform-mobile-session-pty-records-refresh.ts
  • src/main/runtime/session-lifecycle/projection/restored-pane-materialize.ts
  • src/main/runtime/session-lifecycle/projection/resume-agent-session-in-workspace.ts
  • src/main/runtime/terminal/launch/failed-start-pane.ts
  • src/main/runtime/terminal/launch/mobile-terminal-chat-fork-create.ts
  • src/main/runtime/terminal/launch/mobile-terminal-create.ts
  • src/main/runtime/terminal/launch/mobile-terminal-owned-create.ts
  • src/main/runtime/terminal/launch/mobile-terminal-renderer-create.ts
  • src/main/runtime/terminal/launch/terminal-split-in-main.ts
  • src/main/runtime/terminal/launch/terminal-split-surface.ts
  • src/main/runtime/terminal/launch/terminal-split.ts
  • src/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.

Comment on lines +127 to +129
// 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

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.

Major · Functional Correctness · Heavy lift

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)

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

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 lift

Carry wslUserAct into new-workspace startup terminals.

For new_per_run, the startup terminal is created by createManagedWorktree, not launchAgentTerminal. That path omits wslUserAct, 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?: true
        telemetry: 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
Commits

Reviewing files that changed from the base of the PR and between c3ae8bd and 952597b.

Files selected for processing: 5
  • src/main/automations/headless-automation-agent-launch.test.ts
  • src/main/automations/headless-automation-agent-launch.ts
  • src/main/automations/runtime-automation-service.test.ts
  • src/main/runtime/terminal/launch/terminal-create-deduplication.ts
  • tests/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.
@nwparker
nwparker force-pushed the nwparker/wsl-background-start-gate branch from 952597b to 891ed99 Compare October 29, 2026 10:39

@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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

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 lift

Hold background starts before resolving the startup cwd.

For a non-folder WSL workspace with a POSIX cwd, resolvePtySpawnStartupTarget can call wslUncDirectoryExistsAsync. That probe runs wsl.exe -d … --exec before the daemon receives wslBackgroundStart, 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
Commits

Reviewing files that changed from the base of the PR and between 952597b and 891ed99.

Files selected for processing: 2
  • src/main/ipc/pty/runtime/spawn-preflight-requested-shell.test.ts
  • src/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

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.

Major · Functional Correctness · Quick win

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)

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