Skip to content

perf(wsl): skip orcad version GC on reconnects once a pass left nothing behind - #35027

Merged
nwparker merged 1 commit into
mainfrom
nwparker/wsl-orcad-gc-once
Oct 28, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/wsl-orcad-gc-once

Conversation

@nwparker

@nwparker nwparker commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​84 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​79
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​52 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​39

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

Copy link
Copy Markdown
Contributor Author

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.

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

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: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning 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 Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly describes the main change: skipping Orcad version GC on WSL reconnects after a clean pass.
Description check Passed 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 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 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@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: 5


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: aaf8955e-b022-4d09-9270-e4d262bb91d5
Commits

Reviewing files that changed from the base of the PR and between 9785906 and 31eafb2.

Files selected for processing: 11
  • src/main/managed-server/install/orcad-remote-gc.test.ts
  • src/main/managed-server/install/orcad-remote-gc.ts
  • src/main/managed-server/install/remote-install-gc-termination.test.ts
  • src/main/managed-server/install/remote-install-gc.ts
  • src/main/managed-server/install/remote-versioned-install.test.ts
  • src/main/managed-server/lifecycle/orcad-managed-version-gc.test.ts
  • src/main/managed-server/lifecycle/orcad-managed-version-gc.ts
  • src/main/wsl/wsl-orcad-deploy.test.ts
  • src/main/wsl/wsl-orcad-deploy.ts
  • src/main/wsl/wsl-orcad-version-gc-memo.test.ts
  • src/main/wsl/wsl-orcad-version-gc-memo.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.

Comment on lines 89 to 95
signal: options.signal
})
}
return versionsClean
}

/** Null means unknown host state and keeps every candidate; otherwise pin anything not proven dead. */

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


if (candidates.length === 0) {
return
return 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.

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)

`[${model.id}] GC: removed ${removed.length} stale version dir(s): ${removed.join(', ')}${keptSuffix}`
)
}
return kept.length === 0

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 · 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)

Comment on lines +22 to +23
if (cleanHosts.has(key)) {
return

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 · Functional Correctness · Quick win

Supported by static analysis

Script executed:

cat src/main/wsl/wsl-orcad-version-gc-memo.ts
sed -n '1,150p' src/main/managed-server/install/orcad-remote-gc.ts
cat src/main/wsl/wsl-orcad-version-gc-memo.test.ts

Repository: stablyai/orca

Length of output: 8237


Script executed:

set -o pipefail
printf '%s\n' '--- managed GC symbols and callers ---'
rg -n -F --glob '*.ts' -e 'type ManagedOrcadPruneArgs' -e 'interface ManagedOrcadPruneArgs' -e 'function pruneManagedOrcadVersions' -e 'pruneManagedOrcadVersions(' -e 'pruneWslOrcadVersionsUntilClean' -e 'orcadGcPinnedDirNames' src/main
printf '%s\n' '--- managed GC implementation ---'
sed -n '1,260p' src/main/managed-server/lifecycle/orcad-managed-version-gc.ts
printf '%s\n' '--- activation pin helper ---'
rg -n -F --glob '*.ts' -e 'function orcadGcPinnedDirNames' -e 'export function orcadGcPinnedDirNames' -e 'orcadGcPinnedDirNames' src/main/managed-server src/main
printf '%s\n' '--- memo callers ---'
rg -n -F --glob '*.ts' -e 'pruneWslOrcadVersionsUntilClean' src/main

Repository: stablyai/orca

Length of output: 10105


Script executed:

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.

@nwparker
nwparker merged commit 19e0b84 into main Oct 28, 2026
82 of 84 checks passed
@nwparker

nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor Author

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.

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