Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.
TypeScript adeagent-ideai-agentsautomationbotclaude-codecodexghosttygrok-bothermes-agentmobile-appmuseopenclawopencodeorchestrationpiruntimeterminalworktreesyc-backed
fix(wsl): read a distro's automount root once per start, the default /mnt/ too (#36097)
Neila4c0b16eebe3
diff --git a/src/main/wsl/wsl-automount-root.test.ts b/src/main/wsl/wsl-automount-root.test.tsindex 9eeebdadd70..a43ac4866e7 100644--- a/src/main/wsl/wsl-automount-root.test.ts+++ b/src/main/wsl/wsl-automount-root.test.ts@@ -98,3 +98,67 @@ describe('followWslAutomountRoots', () => {expect(knownWslAutomountRoots()).toEqual(['/mnt/'])})})++describe('followWslAutomountRoots: one guest read per distro start', () => {+ /** Settles the reads one confirmed list started before the next probe. */+ async function observeRunning(times: number): Promise<void> {+ for (let i = 0; i < times; i++) {+ await listRunning(['Ubuntu'])+ await new Promise((resolve) => setImmediate(resolve))+ }+ }++ it.each(['/mnt/', '/custom/'])(+ 'reads a %s root once across many running observations, and once more after a restart',+ async (root) => {+ let reads = 0+ follow(async () => {+ reads += 1+ return root+ })+ await observeRunning(10)+ expect(reads).toBe(1)++ await listRunning([])+ await observeRunning(10)+ expect(reads).toBe(2)+ }+ )++ it('retries a read that failed or found nothing, then stops once one succeeds', async () => {+ const results: (string | null | Error)[] = [new Error('wsl.exe timed out'), null, '/mnt/']+ let reads = 0+ follow(async () => {+ const result = reads < results.length ? results[reads] : '/mnt/'+ reads += 1+ if (result instanceof Error) {+ throw result+ }+ return result+ })+ await observeRunning(6)+ expect(reads).toBe(3)+ })++ it('reads again after a restart even when the stop came while a read was in flight', async () => {+ let reads = 0+ let finishFirst: (root: string) => void = () => {}+ follow(+ (): Promise<string> =>+ new Promise((resolve) => {+ reads += 1+ if (reads === 1) {+ finishFirst = resolve+ } else {+ resolve('/mnt/')+ }+ })+ )+ await listRunning(['Ubuntu'])+ await listRunning([])+ finishFirst('/mnt/')+ await new Promise((resolve) => setImmediate(resolve))+ await observeRunning(3)+ expect(reads).toBe(2)+ })+})diff --git a/src/main/wsl/wsl-automount-root.ts b/src/main/wsl/wsl-automount-root.tsindex ab42df886a2..f74e8cb4025 100644--- a/src/main/wsl/wsl-automount-root.ts+++ b/src/main/wsl/wsl-automount-root.ts@@ -22,7 +22,11 @@ const READ_TIMEOUT_MS = 5_000export type WslAutomountRootReader = (distro: string) => Promise<string | null>const roots = new Map<string, string>()+// Read since its last start, the default `/mnt/` too: one guest launch per start, not per probe.+const readSinceStart = new Set<string>()const pending = new Set<string>()+// Bumped on a stop, so a read still in flight then neither marks the restarted distro read.+const stopCounts = new Map<string, number>()const changeListeners = new Set<() => void>()function distroKey(distro: string): string {@@ -57,7 +61,7 @@ export function followWslAutomountRoots(const wantedKeys = new Set(wanted().map(distroKey))for (const distro of running) {const key = distroKey(distro)- if (!wantedKeys.has(key) || roots.has(key) || pending.has(key)) {+ if (!wantedKeys.has(key) || readSinceStart.has(key) || pending.has(key)) {continue}// A list probed mid-stop still names the distro, and wsl.exe would boot it again. The cache@@ -66,9 +70,15 @@ export function followWslAutomountRoots(continue}pending.add(key)+ const stopCount = stopCounts.get(key) ?? 0void read(distro).then((root) => {- if (root && root !== DEFAULT_WSL_AUTOMOUNT_ROOT) {+ // Unread (null) retries on the next probe; a stop mid-read leaves it for the restart.+ if (!root || (stopCounts.get(key) ?? 0) !== stopCount) {+ return+ }+ readSinceStart.add(key)+ if (root !== DEFAULT_WSL_AUTOMOUNT_ROOT) {roots.set(key, root)changed()}@@ -81,7 +91,10 @@ export function followWslAutomountRoots(const stopStopped = onRunningWslDistrosStopped((stopped) => {let removed = falsefor (const distro of stopped) {- removed = roots.delete(distroKey(distro)) || removed+ const key = distroKey(distro)+ stopCounts.set(key, (stopCounts.get(key) ?? 0) + 1)+ readSinceStart.delete(key)+ removed = roots.delete(key) || removed}if (removed) {changed()@@ -132,6 +145,8 @@ export function parseWslAutomountRoot(drivePath: string | null): string | null {export function resetWslAutomountRootsForTests(): void {roots.clear()+ readSinceStart.clear()pending.clear()+ stopCounts.clear()changeListeners.clear()}