Repository navigation
fix(wsl): skip stopped distros during background CLI/quota checks - #21013
RoxasZohbi wants to merge 3 commits into
Conversation
Two independent code paths were booting a stopped WSL distro just from launching Orca, with no workspace open (stablyai#20184): - Startup CLI-bridge registration reconciliation execs into any distro that hasn't been inspected for the current app version yet, with no check for whether it's already running. - The background usage/rate-limit refresh (~1s after every window creation) resolves a WSL-hosted account's home path unconditionally, even when that account's distro is stopped. Both now check listRunningWslDistrosAsync() first and skip the distro entirely if it isn't already running, instead of waking it. This is the same reusable guard the codebase already uses elsewhere for this exact purpose. prepareForRateLimitFetch (Codex) and its resolver type are now async to support the running-distro check; threaded the await through every call site in the rate-limit service and the reset-credit coordinator. Updated affected tests to the new async contract, and added dedicated regression tests for both triggers. This addresses two of the mechanisms behind stablyai#20184; not marked as Fixes since another contributor may be independently working the first one.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe change restricts WSL registration repair and rate-limit home preparation to distros that are already running. WSL distro names are normalized before matching. Home-path resolution becomes asynchronous, and rate-limit cycle callers now await it. Reset-credit consumption rejects target changes detected during home preparation. Tests add running-distro mocks, await the updated APIs, and cover stopped-distro and stale-result behavior. Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to The change avoids starting stopped WSL distributions and rejects stale asynchronous reset requests, with no concrete merge-blocking risk remaining. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 2322933d-7792-47f6-917f-b23ee78efd4c
📒 Files selected for processing (20)
src/main/cli/wsl-cli-registration-reconciliation.test.tssrc/main/cli/wsl-cli-registration-reconciliation.tssrc/main/codex-accounts/codex-reset-credit-coordinator.tssrc/main/codex-accounts/runtime-home-managed-auth-recovery.test.tssrc/main/codex-accounts/runtime-home-per-account-homes.test.tssrc/main/codex-accounts/runtime-home-real-home-lane-routing.test.tssrc/main/codex-accounts/runtime-home-retained-auth-provenance.test.tssrc/main/codex-accounts/runtime-home-service-home-routing.tssrc/main/codex-accounts/runtime-home-service-per-account-migration.test.tssrc/main/codex-accounts/runtime-home-service-state.tssrc/main/codex-accounts/runtime-home-wsl-managed-accounts.test.tssrc/main/codex-accounts/runtime-home-wsl-system-default.test.tssrc/main/codex-accounts/sta-4422-transient-ownership-error.test.tssrc/main/rate-limits/service-account-target-selection.test.tssrc/main/rate-limits/service-inactive-account-previews.test.tssrc/main/rate-limits/service/service-fetch-targets.tssrc/main/rate-limits/service/service-full-cycle-application.tssrc/main/rate-limits/service/service-full-cycle-preparation.tssrc/main/rate-limits/service/service-provider-cycles.tssrc/main/rate-limits/service/service-types.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| throw new Error('A previous reset attempt for this target still has an unknown outcome.') | ||
| } | ||
| const homeResolution = this.dependencies.runtimeHome.prepareForRateLimitFetch(target) | ||
| const homeResolution = await this.dependencies.runtimeHome.prepareForRateLimitFetch(target) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Revalidate target after home preparation.
The checks before this await do not protect the provider mutation after it. If the user changes the Codex target while home preparation lists WSL distros, this call still spends reset credit against the old target. This conflicts with the existing changed-target rejection contract.
Re-read the active target and selected account after the await. Reject the operation if either value no longer matches the initial state.
There was a problem hiding this comment.
Caution
This PR leaves the test suite red. Three tests fail on Linux CI (all pass at base caa465d, verified in a clean worktree). Unit tests run on ubuntu-latest, so at least one is a guaranteed CI failure. Inline comments carry the exact failures and the minimal fixes.
Reviewed changes
- CLI-bridge reconciliation skips stopped distros —
wsl-cli-registration-reconciliation.tsgains alistRunningDistrosoption and filters candidates throughlistRunningWslDistrosAsyncbeforerepairManagedRegistration()execes into them. - Codex quota poll skips stopped distros —
prepareForRateLimitFetchbecomes async and returns{ kind: 'skip' }for a WSL target whose distro is not running, via a newisWslDistroRunningForRateLimitFetchgate. - Async plumbing —
CodexHomePathResolvernow returns aPromise;resolveCodexHomeis async and awaited at four rate-limit call sites; the reset-credit coordinator awaitsprepareForRateLimitFetch; the abstract signature inruntime-home-service-state.tschanges. - Tests — regression tests added for both triggers; WSL account/rate-limit tests migrated to the async contract.
ℹ️ Stopped distros no longer get their CLI bridge reconciled automatically
Reconciliation runs only once, at startup (main-process-ready-foundation.ts:105), and is now filtered to distros that are already running. A distro that is stopped on every launch therefore never has its managed orca bridge repaired until the user runs the Settings install/repair action — previously the startup pass would boot it and repair. The new comment documents this tradeoff, so flagging it only to confirm the follow-up path is real (e.g. an on-demand reconcile when a WSL workspace is first opened) rather than relying solely on Settings.
Technical details
# CLI-bridge reconciliation no longer self-heals on later distro start
## Affected sites
- `src/main/startup/main-process-ready-foundation.ts:105` — the only production trigger of `reconcileManagedWslCliRegistrations`.
- `src/main/cli/wsl-cli-registration-reconciliation.ts:117-122` — candidates are filtered to currently-running distros.
## Required outcome
- Confirm the intended recovery path for a bridge that goes stale while every relevant distro is stopped at startup, so it cannot silently persist across app updates.
## Open questions for the human
- Is a stale managed launcher acceptable until the user opens a WSL workspace, or should reconciliation re-run once a distro starts?ℹ️ Nitpicks
src/main/codex-accounts/service-test-harness.ts:82,89still typesRuntimeHomeStub.prepareForRateLimitFetchas returningCodexRateLimitHomeResolutionsynchronously, andservice-reset-credit-target-routing.test.ts:171still usesmockReturnValue. It compiles only because callers castas never; tightening the stub toPromise<...>would keep it honest against the new abstract contract.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| if (wslTarget.wslDistro && !(await this.isWslDistroRunningForRateLimitFetch(wslTarget))) { | ||
| return { kind: 'skip' } | ||
| } |
There was a problem hiding this comment.
This skip is on the user-initiated reset-credit path too, not just passive background polls: codex-reset-credit-coordinator.ts:160 awaits prepareForRateLimitFetch(target) and rejects with ManagedCodexHomeTemporarilyUnavailableError on skip. So a reset requested for a WSL-hosted account whose distro is stopped now surfaces "Codex account files are temporarily locked. Retry in a moment." instead of booting the distro — worth confirming that's the intended behavior for an explicit user action, since the PR scope is described as background checks.
Technical details
# Skip guard also covers the user-initiated reset-credit consume path
## Affected sites
- `src/main/codex-accounts/runtime-home-service-home-routing.ts:267-269` — returns `{ kind: 'skip' }` for a stopped WSL distro.
- `src/main/codex-accounts/codex-reset-credit-coordinator.ts:160-165` — awaited by `serializeMutation`; `skip` throws `ManagedCodexHomeTemporarilyUnavailableError`.
- `src/main/startup/main-process-account-services.ts:70-72` — the same resolver feeds the passive `RateLimitService` poll.
## Required outcome
- Decide whether an explicit reset should be allowed to wake the target distro, or whether the UI should suppress/reset that affordance while the distro is stopped (and the error message should describe the stopped distro rather than locked files).
## Open questions for the human
- Can the reset-credit UI be reached for a WSL account while its distro is stopped, or is the offer refreshed away by the skipped poll?Fix a race introduced when prepareForRateLimitFetch became async (it now lists WSL distros). Re-check the active Codex target and selected account around the await in codex-reset-credit-coordinator so a changed selection cannot be spent against. Make the runtimeHome test stub return a Promise and add regression tests that simulate the target/account changing while home resolution is pending. Also capture codexFetchGeneration earlier in the full-cycle preparation so a stale full-refresh result cannot overwrite a newer reset outcome.
There was a problem hiding this comment.
ℹ️ No new issues in this delta — the new commit is a clean race fix. This is not an approval because the previously reported test failures are still open.
Reviewed changes
Since the prior pullfrog review (5dfb8ea), one commit landed (21d82f2):
- Reset-credit race closed —
consumeCurrent()re-reads the active target and selected account after awaitingprepareForRateLimitFetch(), rejecting if either changed during the WSL-distro listing gap. - Stale Codex generation captured earlier —
codexGenerationnow snapshots beforeresolveCodexHome()awaits, so a concurrent reset that bumps the generation can no longer let a stale full-refresh result overwrite the newer selection. - Test harness matched to the async contract —
RuntimeHomeStub.prepareForRateLimitFetchis now typed to return aPromise, and the reset-routing test usesmockResolvedValue(the prior nitpick). - Regression tests added — cover the target changing while home resolution is pending, and a stale cycle result landing over a newer reset. I confirmed the latter fails against the pre-fix code (
usedPercentstays 100) and passes with it, so it is real coverage.
Note: the three tests flagged in the prior review still fail at this head (verified locally; only the two rate-limit ones fall under src/main/rate-limits, the third is src/main/cli/wsl-cli-installer.test.ts). The open review threads carry the exact failures and fixes, so I have not repeated them inline. pnpm tc:node passes and no other test regressions were introduced by the race fixes.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Stabilize tests affected by async resolveCodexHome and WSL behavior. In wsl-cli-installer.test.ts add listRunningDistros to include running Ubuntu. In service-refresh-orchestration.test.ts increase flushMicrotasks to 8 and add a comment explaining resolveCodexHome is now async (pushing settlement past the default flush). In service-window-activation.test.ts add an extra microtask await and comment to ensure the fetch cycle runs after the async resolve. These changes make timing deterministic and prevent intermittent test flakes.
There was a problem hiding this comment.
ℹ️ No new issues in this delta — the new commit resolves the two prior test failures, so the suite is green again. Approval is withheld only because the one remaining open design-question thread on the reset-credit path is still unaddressed.
Reviewed changes
Since the prior pullfrog review (21d82f2), one commit landed (647f65d), touching only the tests that were red:
- WSL installer test taught the running-distro filter —
wsl-cli-installer.test.ts:440now injectslistRunningDistros: async () => ['Ubuntu'], so the reconciliation call under test still repairs instead of returning[]. - Rate-limit microtask flushes widened —
service-refresh-orchestration.test.ts:287flushes 8 microtasks andservice-window-activation.test.ts:136-138awaits one extraPromise.resolve(), covering the microtask that the now-asyncresolveCodexHomeinserts even with no resolver registered.
Verified locally: all three previously failing tests pass and the full src/main/rate-limits, src/main/codex-accounts, and src/main/cli suites are green (118 files, 1044 tests). Both prior threads anchored to those failures have been resolved.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Hi @AmethystLiang, just checking in on this one since it's been open a couple of weeks. Happy to make any changes if something needs adjusting. |
Records the official issue check behind the WSL switch: stablyai#20184 is still open and its fix PR stablyai#21013 is unmerged, so the patch stays. Also documents the build procedure, the pnpm shim workaround, the max-lines overage, and the esbuild temp-dir workaround.
sorry this got lost for a bit, please ping me in the future. Working on it |
|
Thank you @RoxasZohbi for digging into #20184 and for the clear root-cause write-up here. We're closing this in favor of #27684, which takes a broader approach: one shared gate that defers background work until a distro is running (so CLI registration still completes in the same session instead of waiting for the next launch), and it covers a few more triggers (fish-history cleanup, the Claude/Kimi usage polls, and the pre-update Codex login sync). Your Codex home-resolution race fix and its regression test applied to our branch too. They're ported into #27684 as a separate commit with you as co-author, and the PR description credits this PR. Thanks again! |

Author (X/Twitter): SyedZohaib2623
ELI5
Just opening Orca (with no workspace open at all) was quietly booting up
a stopped WSL virtual machine in the background. This fixes two separate
places in the code that were each capable of causing that on their own.
What Changed
Two independent code paths were booting a stopped WSL distro just from launching Orca, with no workspace open (#20184):
Both now check
listRunningWslDistrosAsync()first and skip the distro entirely if it isn't already running, instead of waking it. This is the same reusable guard the codebase already uses elsewhere for this exact purpose.prepareForRateLimitFetch(Codex) and its resolver type are now async to support the running-distro check; threaded theawaitthrough every call site in the rate-limit service and the reset-credit coordinator. Updated affected tests to the new async contract, and added dedicated regression tests for both triggers.Why
Booting a stopped WSL distro is a multi-second, resource-heavy operation the user never asked for and has no way to opt out of — it happened purely as a side effect of passive background housekeeping (a version-bump check, a status-bar quota refresh), with no workspace open and no WSL feature actually in use.
Linked Issue
This addresses two of the mechanisms behind #20184; not marked as
Fixes #20184since another contributor may be independently working the first one (see the issue thread for the shared root-cause writeup).Visual Proof
https://www.loom.com/share/5b0c9e4d80ab433cbd5095641ebf5fc9
Testing
Manual verification (Windows, WSL2):
pnpm build:unpack(packaged build required, since this path only runs whenapp.isPackaged), shut down WSL, launched with no workspace — distro stayed stopped.pnpm devwith no workspace — distro stayed stopped (previously reproduced the bug reliably before this fix).Automated: added regression tests for both triggers, verified each fails against the pre-fix code and passes against the fix.
Platforms tested: Windows only (this bug is Windows/WSL-specific by nature).
AI Disclosure
Claude (Sonnet 5, via Claude Code) was used throughout: reproducing the bug, tracing both root causes, implementing the fix, and writing the regression tests, all reviewed and directed by me at each step.
Review
win32/WSL-specific code paths already; no effect on macOS or Linux behavior.listRunningWslDistrosAsync()call (awsl.exe --list --runningprobe, not a distro boot) before each affected path.Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Found and fixed two independent triggers for the same reported symptom; documented both on the issue thread before implementing. A third, related gap (Claude's WSL-hosted account rate-limit fetch likely has the same unconditional-resolve issue) was identified but intentionally left out of scope for this PR.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)