You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(wsl): skip orcad version GC on reconnects once a pass left nothing behind - #35027
Each time a WSL distro restarts, the WSL host reconnects and checks the distro for old Orca server versions to delete. After a restart there is never anything new to delete, but the check still costs about nine round trips into the distro (~110–190 ms on CI) before the first terminal can open. This PR skips that check on reconnects once a check has already come back clean.
What Changed
gcOldRemoteInstallVersions, gcOldOrcadVersions and pruneManagedOrcadVersions now return true only when the pass ran and left no stale version dir behind. A pass returns false if it was skipped (unknown daemon version, unreadable transaction), if the listing failed, if extra pins were unknown, if a candidate was kept, or if it errored. Their SSH callers ignore the new return value, so SSH behaves exactly as before.
New wsl-orcad-version-gc-memo.ts: the WSL deploy calls pruneWslOrcadVersionsUntilClean(environmentId, …). After a clean pass, later connects in the same app session skip GC while the pins stay the same. The key is environment id, remote home, active version and proven live-daemon version. Activating another version or a daemon change runs GC again, and so does a different distro.
Why
From the restart baseline in #34864, the post-readiness tail of each WSL connect is about 14 guest commands (≈0.15–0.19 s), and version GC is most of it. I chose to skip a pass that is known to be clean rather than move GC into the background after the connect. Background guest commands after ensure resolves could fall back to a fresh wsl.exe if the distro stopped meanwhile. That would boot a stopped distro from a background path, which E9 forbids. The deploy's transport also retires its command loops when the deploy returns. The memo removes the work with no background activity at all.
What it costs: a version dir kept for a transient reason (an installer lock, a failed probe) makes the pass "not clean", so it keeps being retried. Only a fully clean pass is memoized. A dir can only become stale through an activation or a daemon change, and both change the key.
Flag-off: no change. The memo is only reached from the WSL host deploy (deployAndLaunchWslOrcad), which runs only with WSL hosts enabled (ORCA_INTERNAL_WSL_HOSTS). The shared GC functions only gained a return value. User-risk: low. In the worst case an old orcad version dir stays on disk inside the distro until the next app launch, an activation, or a daemon change. GC itself is unchanged.
Linked Issue
Internal WSL-via-orcad tracker, D3 bar (restart → first usable prompt). Phase breakdown: #35005.
Visual Proof
N/A: no UI.
Testing
wsl-orcad-version-gc-memo.test.ts: skips after a clean pass; keeps running while passes leave things behind; reruns when the active version, the daemon or the distro changes.
orcad-managed-version-gc.test.ts and orcad-remote-gc.test.ts cover the clean and not-clean results: pinned versions still count as clean, and a kept candidate is not clean.
Existing GC, deploy and termination suites pass. pnpm tc, typecheck:ci, code-quality, anti-slop and ast-grep pass locally.
Automated tests added/updated
Status
Ready. The WSL2 lane will show the dropped post-readiness commands once #35005's phase receipt is in main.
Checklist
This PR is small and focused
I explained what changed and why
N/A for visuals with reason
Self-reviewed for correctness, security, and performance
Cross-platform, SSH/remote impact considered (SSH ignores the return value)
pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (CI runs the rest)
…ng behind
A distro restart reconnects with the same active version and daemon, so the ~9 guest commands of
version GC find nothing new. GC now reports whether it left any stale version dir behind; the WSL
deploy skips it for the rest of the app session once a pass under the same active version and
daemon version came back clean. SSH callers ignore the new return value.
STATUS: ready. Head 31eafb2. Checks run: pnpm tc, typecheck:ci, the GC/deploy/termination suites, code-quality:changed, anti-slop, ast-grep. Open question for reviewers: a version dir kept for a transient reason keeps GC running on every connect. Only a fully clean pass is memoized, per app session.
Remote and managed Orcad garbage-collection functions now return a boolean that indicates whether pruning is clean. WSL deployment uses a memoized pruning function. It skips pruning for a previously successful set of environment and version inputs, and retries when pruning is unclean or those inputs change.
Priority: Low
Merge Risk: Low · up to 31eaf
Unused directories can remain on disk longer than intended. The change is mergeable with awareness of deferred cleanup.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 50.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 checks: 4 passed
Check name
Status
Explanation
Title check
The title clearly describes the main change: skipping Orcad version GC on WSL reconnects after a clean pass.
Description check
The description is detailed and covers the change, rationale, issue reference, testing, visual proof, risks, and checklist. Some optional template sections are omitted, but the core required informati…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Description check
Explanation
The description is detailed and covers the change, rationale, issue reference, testing, visual proof, risks, and checklist. Some optional template sections are omitted, but the core required information is present.
Full details: Docstring Coverage
Explanation
Docstring coverage is 50.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 6 functions across 11 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches: 💡 2
📝 Generate docstrings: 💡
Commit to this branch
Create a new PR
🛠️ Fix failing CI checks: 💡
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Propagate failed runtime move and deletion operations.
gcRemoteNodeRuntimeStore records failed moveTree and removeTree calls, but gcOldOrcadVersions returns only versionsClean. The WSL memo can therefore cache a clean result and skip the next retry after a runtime-store cleanup failure.
Return and propagate an unclean result specifically for failed move or deletion operations. Keep the existing absent-or-held lock result unchanged, and do not infer failure from intentional pinned or referenced entries.
Minor · Functional Correctness · Quick win
Supported by static analysis
Script executed:
sed -n '35,115p' src/main/managed-server/install/remote-node-runtime-store-gc.ts
sed -n '175,260p' src/main/managed-server/install/remote-node-runtime-store-gc.ts
sed -n '75,100p' src/main/managed-server/install/orcad-remote-gc.ts
Repository: stablyai/orca
Length of output: 6233
Propagate cap-deferred runtimes as not clean.
planRuntimeStoreGc removes at most eight entries. If more than eight verified entries are eligible, later entries enter plan.kept even though no deletion failed. gcOldOrcadVersions discards this runtime-store result and returns only versionsClean, so the WSL memo can cache a clean pass and skip the next batch. Tracking failed removals alone does not cover this normal bounded-batch case.
Report cap-deferred eligible entries through the runtime GC result and include that signal in the value returned to the WSL memo.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Keep a failed tombstone cleanup eligible for retry.
cleanupRemoteInstallGcTombstones logs a confirmed deletion failure and continues. If the listing contains only that tombstone, this branch returns true. WSL then skips later cleanup attempts for the same key, leaving the tombstone until another event changes the key or restarts the app. Propagate tombstone-cleanup success into the clean result. (raw.githubusercontent.com)
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Do not report a capped listing as clean.
The listing command returns at most 64 entries. If a host has 65 stale version directories, this pass can remove the first 64 and return true while the last directory was never inspected. WSL then memoizes the result and skips later passes for the same key. Return false when the listing reaches its limit, or make the listing exhaustive. (raw.githubusercontent.com)
set -o pipefail
printf'%s\n''--- activation pin helper ---'
sed -n '150,235p' src/main/managed-server/activation/orcad-activation-record.ts
printf'%s\n''--- WSL deploy caller ---'
sed -n '230,325p' src/main/wsl/wsl-orcad-deploy.ts
printf'%s\n''--- WSL deploy surrounding flow ---'
sed -n '1,230p' src/main/wsl/wsl-orcad-deploy.ts
printf'%s\n''--- activation record model and writers ---'
rg -n -F --glob '*.ts' -e 'type OrcadActivationRecord' -e 'interface OrcadActivationRecord' -e 'activeVersion' -e 'previousVersion' -e 'rollbackVersion' -e 'transaction' src/main/managed-server/activation src/main/managed-server
Repository: stablyai/orca
Length of output: 42011
Invalidate the clean memo when the observed pins change.
cleanHosts retains historical keys. After clean passes for A, B, and C, returning to A can skip GC even though B is no longer pinned and can be stale. An intervening false pass has the same problem if the earlier clean key remains eligible.
Invalidate the environment’s clean state when a different key is observed, before awaiting prune. Record a clean result only if that key is still current when the pass completes. This prevents overlapping older passes from restoring stale results.
Suggested fix
-const cleanHosts = new Set<string>()+const cleanKeys = new Map<string, string>()+const observedKeys = new Map<string, string>()+const generations = new Map<string, number>()
...
- if (cleanHosts.has(key)) {+ let generation = generations.get(environmentId) ?? 0+ if (observedKeys.get(environmentId) !== key) {+ observedKeys.set(environmentId, key)+ cleanKeys.delete(environmentId)+ generation += 1+ generations.set(environmentId, generation)+ }+ if (cleanKeys.get(environmentId) === key) {
return
}
if (await prune(args)) {
- cleanHosts.add(key)+ if (+ generations.get(environmentId) === generation &&+ observedKeys.get(environmentId) === key+ ) {+ cleanKeys.set(environmentId, key)+ }
}
}
export function resetWslOrcadVersionGcMemoForTests(): void {
- cleanHosts.clear()+ cleanKeys.clear()+ observedKeys.clear()+ generations.clear()
}
Add tests for returning to the first version, an intervening false pass, and overlapping calls.
STATUS — memo update: the phase baseline for staged readiness (c), held-socket lane.
Source: lane run 40797934871 at #35530 head 3b7f46e, which is stacked on #35526 (merged). Values are medians of 3 restarts, in ms.
Comparability:firstOutputMs from #35526 onward can't be compared with earlier lane baselines. The old lane opened a fresh connection for every request, and each one spawned a new wsl.exe, which inflated those numbers.
ubuntu-24.04
debian-12
fedora-41
restart → first output
3556
2728
4283
host start (ensure)
2741
2042
3498
· boot + holder
582
415
735
· pre-launch checks (20 cmds)
407
267
599
· orcad startup (host view)
1377
1060
1735
· after ready + bridge + pairing
264
214
345
terminal.create
194
151
245
send → first output
623
529
530
orcad: boot before first phase
831
607
996
orcad: daemon phase
221
145
270
orcad: profile phase
112
82
142
orcad: daemon end → ready
199
127
259
orcad: readyMs
1252
892
1517
bridge-exec floor
593
340
656
What (c) can reach: publishing readiness right after cli-launcher plus profile would cut about 250–500 ms of orcad's startup (profile end → rpc end). Boot before the first phase (about 600–1000 ms of module load) and host-side pre-launch checks (about 270–600 ms) remain. The runner was noisy across distros in this run: debian is about 0.23 s over the 2.5 s bar, and fedora is about 1.8 s over.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
Each time a WSL distro restarts, the WSL host reconnects and checks the distro for old Orca server versions to delete. After a restart there is never anything new to delete, but the check still costs about nine round trips into the distro (~110–190 ms on CI) before the first terminal can open. This PR skips that check on reconnects once a check has already come back clean.
What Changed
gcOldRemoteInstallVersions,gcOldOrcadVersionsandpruneManagedOrcadVersionsnow returntrueonly when the pass ran and left no stale version dir behind. A pass returnsfalseif it was skipped (unknown daemon version, unreadable transaction), if the listing failed, if extra pins were unknown, if a candidate was kept, or if it errored. Their SSH callers ignore the new return value, so SSH behaves exactly as before.wsl-orcad-version-gc-memo.ts: the WSL deploy callspruneWslOrcadVersionsUntilClean(environmentId, …). After a clean pass, later connects in the same app session skip GC while the pins stay the same. The key is environment id, remote home, active version and proven live-daemon version. Activating another version or a daemon change runs GC again, and so does a different distro.Why
From the restart baseline in #34864, the post-readiness tail of each WSL connect is about 14 guest commands (≈0.15–0.19 s), and version GC is most of it. I chose to skip a pass that is known to be clean rather than move GC into the background after the connect. Background guest commands after
ensureresolves could fall back to a freshwsl.exeif the distro stopped meanwhile. That would boot a stopped distro from a background path, which E9 forbids. The deploy's transport also retires its command loops when the deploy returns. The memo removes the work with no background activity at all.What it costs: a version dir kept for a transient reason (an installer lock, a failed probe) makes the pass "not clean", so it keeps being retried. Only a fully clean pass is memoized. A dir can only become stale through an activation or a daemon change, and both change the key.
Flag-off: no change. The memo is only reached from the WSL host deploy (
deployAndLaunchWslOrcad), which runs only with WSL hosts enabled (ORCA_INTERNAL_WSL_HOSTS). The shared GC functions only gained a return value.User-risk: low. In the worst case an old orcad version dir stays on disk inside the distro until the next app launch, an activation, or a daemon change. GC itself is unchanged.
Linked Issue
Internal WSL-via-orcad tracker, D3 bar (restart → first usable prompt). Phase breakdown: #35005.
Visual Proof
N/A: no UI.
Testing
wsl-orcad-version-gc-memo.test.ts: skips after a clean pass; keeps running while passes leave things behind; reruns when the active version, the daemon or the distro changes.orcad-managed-version-gc.test.tsandorcad-remote-gc.test.tscover the clean and not-clean results: pinned versions still count as clean, and a kept candidate is not clean.pnpm tc,typecheck:ci, code-quality, anti-slop and ast-grep pass locally.Status
Ready. The WSL2 lane will show the dropped post-readiness commands once #35005's phase receipt is in main.
Checklist
N/Afor visuals with reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (CI runs the rest)