Skip to content

fix(wsl): don't start a stopped distro to read a repo's default base ref - #35778

Merged
nwparker merged 2 commits into
mainfrom
nwparker/e9-base-ref-gate
Oct 29, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/e9-base-ref-gate

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​273 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​273
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​91 $\color{#cf222e}{\Huge{\mathbf{−}}}$​45 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​46

ELI5

If you stop a WSL distro and then open a repo's Settings page, Orca starts the distro again just to look up the repo's default branch. Now Orca leaves the distro stopped and shows the default branch as unknown, as it already does for folder projects.

What Changed

  • Before: opening a repo's Settings page (base-ref picker) on Windows ran git for-each-ref and git remote through the repo's WSL distro. If the user had stopped that distro, this started it again. A remote client that asks a Windows host for the same value (repo.baseRefDefault) touched the host's \\wsl.localhost path the same way.
  • After: both reads first ask whether the repo's distro is running, using the same check that guards the other background reads (blockedWslDistroForPath). If the distro is stopped, or WSL can't say, they return the existing unknown result { defaultBaseRef: null, remoteCount: 0 } without running Git. The picker already shows that state.
  • A refused read names the distro (refusedWslDistro, a new optional field) and asks main to tell the renderer once that distro is running again, over the existing preflight:wslDistroRunning broadcast that refused preflight checks already use. Settings (BaseRefPicker) and Source Control (useSourceControlBaseRefDefault) both load the default through a new watchRuntimeRepoBaseRefDefault, which reads it again when that broadcast names the distro. So once the user starts the distro, the default and base comparison come back without switching repos.
  • Windows-host repos (no WSL path and no WSL Git), SSH repos and folder projects are unchanged.

Why

Background work must never start a distro the user stopped. Only the user's own actions may (rule E9). Opening a Settings page is a passive view. The real-WSL guard test found this path: a Settings visit started the distro about 0.2 s after the stop had been confirmed.

I used the path check instead of the exec-only check because it handles both cases with one call: a \\wsl.localhost repo path, and a Windows path whose Git runs inside WSL. The exec-only check falls back to the default distro when no distro is named, which would wrongly gate repos whose Git runs on Windows.

Returning "unknown" reuses a state the UI already handles. The picker falls back to its existing label, and source control skips the comparison rather than using a made-up base.

Flag-off: in bridge mode (WSL hosts off), Git runs on the Windows host against the \\wsl.localhost path, and the path check covers it. In host mode (WSL hosts on), Git runs inside the distro, which is covered by passing wslDistro.
User-risk: while a distro is stopped, its repo's Settings page and Source Control show the default base as unknown. Once the user starts the distro (opens a terminal, expands a folder, and so on), both read it again on their own. Remote clients of a paired host get unknown, and they read the value again on their next visit, because the host's broadcast reaches only its own windows.

Linked Issue

Fixes #

Visual Proof

N/A. No new UI. A stopped distro shows the picker's existing unknown/fallback state.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

New tests in src/main/ipc/repos/base-ref-default-wsl-gate.test.ts, using the real gate and a simulated Windows platform:

  • With the distro stopped or unverifiable, the IPC handler returns unknown and Git doesn't run. This holds for a \\wsl.localhost repo and for a Windows path whose Git runs in WSL.
  • A refusal returns refusedWslDistro, and main sends preflight:wslDistroRunning once that distro is noted running.
  • A running distro reads normally.
  • Windows-host repos stay ungated, and folder and SSH repos keep their existing result.
  • The runtime repo.baseRefDefault read returns unknown for a stopped distro and reads normally once it runs.

New tests in src/renderer/src/runtime/runtime-repo-base-ref-default-wsl-retry.test.ts:

  • After a refusal, the default is read again when the refusing distro is reported running. The distro name is matched case-insensitively, and the listener is removed.
  • Other distros are ignored.
  • Cancelling stops listening.
  • A result that wasn't refused never listens.

repos-remote-base-ref-queries.test.ts stubs the gate, so it doesn't hide the routing that test checks. Local checks: pnpm tc, pnpm run typecheck:ci, check:code-quality:changed and anti-slop oxlint all pass. The real-WSL lane (#35590) re-runs on top of this.

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

  • Remote compatibility: refusedWslDistro is a new optional field on the local IPC result. The runtime RPC result and params are unchanged.
  • SSH: unchanged; SSH repos still return unknown from this handler.
  • Performance: at most one wsl.exe --list --running per minute, from the shared running lease.

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)

Opening a repo's Settings pane ran git for-each-ref and git remote through
the repo's WSL distro, which started it after the user had stopped it (E9).
Background reads now return the existing unknown result while the distro is
stopped; an explicit refresh can pass wakeWslDistro. The runtime RPC that
serves the same read to paired clients is gated the same way.
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with a non-blocking timing issue in the automatic refresh.

Findings

  1. P2 Base ref misses the refresh ▶

Summary

Prevents passive default-base reads from starting a stopped WSL distro.

  • Base-ref reads avoid stopped WSL distros, and local views retry when they start.

Diagram

sequenceDiagram
  participant R as Renderer
  participant M as Main
  participant W as WSL terminal
  R->>M: Read default base
  M->>M: Refuse and register wake notice
  W->>M: Terminal starts
  M-->>R: Distro running event
  M-->>R: Refused result
  R->>R: Install listener too late
Loading

Reviews (2) · Last reviewed commit: "fix(wsl): re-read a refused default base..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

Base-ref queries now return an unknown result and identify the refused WSL distro when access is blocked. IPC handlers register a retry notification, and renderer watchers retry the query when that distro starts. The settings picker and source-control hook use the watcher and its cleanup function. Tests cover stopped, running, and unverifiable distros, retry matching, cancellation, and non-WSL repositories.

Priority: Normal

Merge Risk: Low · up to e945d

On Windows with WSL repos, the default base ref normally refreshes automatically once the distro starts. In a rare timing window the retry can be missed and the base ref stays unknown until the view reloads. Fixing the listener ordering would close the gap, but it is unlikely to block merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 20.00% 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 summarizes the main change: prevent a stopped WSL distro from starting just to read a repository’s default base ref.
Description check Passed The description covers the required sections and explains the behavior, rationale, testing, and compatibility impact. The linked-issue field is blank, and manual testing and some checks are not marked…
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 covers the required sections and explains the behavior, rationale, testing, and compatibility impact. The linked-issue field is blank, and manual testing and some checks are not marked complete; add an issue link if required for this contributor, and update the test status when available.

Full details: Docstring Coverage

Explanation

Docstring coverage is 20.00% 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 5 functions across 10 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.

A refused read now names the distro and defers a preflight:wslDistroRunning
broadcast; Settings and Source Control re-ask on it, so base comparison
returns without a repo switch. Drops the unused wakeWslDistro option.
Comment on lines +61 to +64
const refused = result.refusedWslDistro?.toLowerCase()
const onDistroRunning = window.api.preflight?.onWslDistroRunning
if (refused && typeof onDistroRunning === 'function') {
stopRetry = onDistroRunning((distro) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Base ref misses the refresh

watchRuntimeRepoBaseRefDefault starts listening only after the refused request resolves. If a WSL terminal finishes opening while that reply is in flight, main can send preflight:wslDistroRunning before this listener exists. Main removes the deferred task when it sends the event, and neither side replays it.

The picker then stays unknown, and source control keeps skipping the default-base comparison, even though the distro is running. Subscribe before sending the request and remember matching events received while it is pending.

Knowledge Base Used: Desktop application platform

@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: 4811bfbe-28be-4293-bc8d-3810800bc748
Commits

Reviewing files that changed from the base of the PR and between 2f66379 and e945dd4.

Files selected for processing: 9
  • src/main/ipc/preflight-wsl-refusal-retry.ts
  • src/main/ipc/repos-remote-base-ref-queries.test.ts
  • src/main/ipc/repos/base-ref-default-wsl-gate.test.ts
  • src/main/ipc/repos/base-ref-query-handlers.ts
  • src/renderer/src/components/right-sidebar/source-control/sync/use-base-ref-default.ts
  • src/renderer/src/components/settings/BaseRefPicker.tsx
  • src/renderer/src/runtime/runtime-repo-base-ref-default-wsl-retry.test.ts
  • src/renderer/src/runtime/runtime-repo-client.ts
  • src/shared/repo-types.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 +61 to +64
const refused = result.refusedWslDistro?.toLowerCase()
const onDistroRunning = window.api.preflight?.onWslDistroRunning
if (refused && typeof onDistroRunning === 'function') {
stopRetry = onDistroRunning((distro) => {

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.

Minor · Stability & Availability · Quick win

Supported by static analysis

Script executed:

sed -n '1,80p' src/main/ipc/preflight-wsl-refusal-retry.ts
sed -n '1,120p' src/renderer/src/runtime/runtime-repo-client.ts
rg -n 'onceWslDistroRunning|wslDistroRunning|onWslDistroRunning' src --glob '!*.test.ts'

Repository: stablyai/orca

Length of output: 6199


Script executed:

printf '%s\\n' '--- WSL gate references ---'
rg -n -F -- 'deferUntilWslDistroRunning' src/main
printf '%s\\n' '--- WSL gate implementation ---'
rg --files src/main | rg 'wsl-background-distro-gate'
printf '%s\\n' '--- retry watcher consumers ---'
rg -n -F -- 'watchRuntimeRepoBaseRefDefault' src/renderer
printf '%s\\n' '--- preflight retry bridge ---'
nl -ba src/renderer/src/hooks/ipc-events/preflight-wsl-retry-ipc-bridge.ts
printf '%s\\n' '--- preflight API binding ---'
nl -ba src/preload/api/preflight-bridge.ts | sed -n '1,70p'
printf '%s\\n' '--- main default-base-ref WSL path ---'
rg -n -F -- 'broadcastWhenWslDistroRunning' src/main
printf '%s\\n' '--- related base-ref handler ---'
nl -ba src/main/ipc/repos/base-ref-query-handlers.ts | sed -n '1,240p'

Repository: stablyai/orca

Length of output: 15316


Script executed:

printf '%s\\n' '--- deferred helper and status probe ---'
nl -ba src/main/wsl-background-distro-gate.ts | sed -n '1,270p'
printf '%s\\n' '--- Settings picker consumer ---'
nl -ba src/renderer/src/components/settings/BaseRefPicker.tsx | sed -n '1,145p'
printf '%s\\n' '--- Source Control consumer hook ---'
nl -ba src/renderer/src/components/right-sidebar/source-control/sync/use-base-ref-default.ts | sed -n '1,150p'
printf '%s\\n' '--- base-ref retry tests ---'
nl -ba src/renderer/src/runtime/runtime-repo-base-ref-default-wsl-retry.test.ts | sed -n '1,130p'
printf '%s\\n' '--- consumer trigger references ---'
rg -n -F -e 'BaseRefPicker' -e 'useBaseRefDefault' -e 'onResult:' src/renderer/src/components/settings src/renderer/src/components/right-sidebar/source-control src/renderer/src/runtime --glob '*.ts' --glob '*.tsx'

Repository: stablyai/orca

Length of output: 27976


Script executed:

printf '%s\\n' '--- confirmed-running cache callbacks ---'
rg -n -F -e 'onConfirmedRunningWslDistros' -e 'peekConfirmedRunningWslDistros' -e 'listRunningWslDistrosAsync' src/main/wsl-running-distro-cache.ts src/main/wsl
nl -ba src/main/wsl-running-distro-cache.ts | sed -n '1,260p'
printf '%s\\n' '--- blocked WSL path implementation ---'
rg -n -F -- 'blockedWslDistroForPath' src/main/wsl
printf '%s\\n' '--- relevant stopped/unverifiable gate ---'
nl -ba src/main/wsl/wsl-unc-access-gate.ts | sed -n '1,240p'
printf '%s\\n' '--- retry test exact callback order ---'
nl -ba src/renderer/src/runtime/runtime-repo-base-ref-default-wsl-retry.test.ts | sed -n '38,52p'

Repository: stablyai/orca

Length of output: 15476


Script executed:

printf '%s\\n' '--- runtime base-ref handlers ---'
rg -n -F -e 'repo.baseRefDefault' -e 'refusedWslDistro' -e 'getBaseRefDefault' src/main src/renderer/src/runtime --glob '*.ts' --glob '*.tsx'
printf '%s\\n' '--- matching handler blocks ---'
rg -l -F -- 'repo.baseRefDefault' src/main | while read -r f; do echo "--- $f"; nl -ba "$f" | sed -n '1,220p'; done
printf '%s\\n' '--- runtime client target binding ---'
nl -ba src/renderer/src/runtime/runtime-client-target.ts | sed -n '1,140p'

Repository: stablyai/orca

Length of output: 39389


Script executed:

printf '%s\\n' '--- runtime repository ref queries ---'
nl -ba src/main/runtime/runtime-repository-ref-queries.ts | sed -n '1,130p'
printf '%s\\n' '--- repo RPC default-base-ref method ---'
rg -n -F -e 'getDefault(' -e 'defaultBaseRef' src/main/runtime/rpc/methods/repo.ts src/main/runtime
printf '%s\\n' '--- exact surrounding RPC/query blocks ---'
nl -ba src/main/runtime/rpc/methods/repo.ts | sed -n '220,390p'
nl -ba src/main/runtime/runtime-repository-ref-queries.ts | sed -n '1,100p'

Repository: stablyai/orca

Length of output: 9341


Handle the retry event before the refusal request completes.

deferUntilWslDistroRunning waits for a later confirmed-running observation and does not replay missed events. The renderer installs onWslDistroRunning only after the refusal result resolves. If the event arrives during that response window, no retry occurs until another load. Register the listener before the request and buffer matching events until the refusal is known, or re-check the distro after registering the deferred task.

@nwparker
nwparker merged commit 3d236c3 into main Oct 29, 2026
55 checks passed
nwparker added a commit that referenced this pull request Oct 29, 2026
#35778's base-move refetch test expected every shown-history read to
wake a stopped WSL distro; only the user's own act does now.
nwparker added a commit that referenced this pull request Oct 29, 2026
…wn act (#35854)

* fix(wsl): Commits history wakes a stopped distro only on the user's own act

Showing Commits woke the distro on every mount, remount and re-show. Now
only the user expanding Commits in the same worktree, or the user's own
switch to the workspace (once per switch), may start it; the Refresh
button keeps its explicit wake (E9).

* test: a mount and a base-ref move read Commits history in the background

#35778's base-move refetch test expected every shown-history read to
wake a stopped WSL distro; only the user's own act does now.
nwparker added a commit that referenced this pull request Oct 29, 2026
…ate the skip

A host-path project whose Git runs in WSL passes its project distro to the stopped-distro check (as #35778 does). wslDistroStopped is translated into the 10 other locales.
nwparker added a commit that referenced this pull request Oct 29, 2026
…35857)

* fix(automations): a scheduled run never starts a stopped WSL distro

Scheduled runs whose target is on a stopped (or unverifiable) WSL distro skip with a coded, retryable wslDistroStopped reason naming the distro, checked at the tick and again at dispatch; repeated ticks fold into one skip. Run now is the user's act and still starts it.

* fix(automations): gate host-path WSL projects by their distro; translate the skip

A host-path project whose Git runs in WSL passes its project distro to the stopped-distro check (as #35778 does). wslDistroStopped is translated into the 10 other locales.
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