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
feat(wsl): let an idle WSL host's orcad exit after 5 minutes (#36243)
Neil7971ccf1ca49
diff --git a/src/main/managed-server/install/orcad-remote-launch.test.ts b/src/main/managed-server/install/orcad-remote-launch.test.tsindex 9cb8d2fb4cb..278cb655334 100644--- a/src/main/managed-server/install/orcad-remote-launch.test.ts+++ b/src/main/managed-server/install/orcad-remote-launch.test.ts@@ -2,8 +2,12 @@ import { spawn, spawnSync } from 'node:child_process'import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'import { tmpdir } from 'node:os'import { join } from 'node:path'-import { describe, expect, it } from 'vitest'+import { afterEach, describe, expect, it, vi } from 'vitest'import { ORCAD_MANAGED_ACTIVATION_ROOT_ENV } from '../../../shared/orcad-managed-launch-env'+import {+ ORCAD_IDLE_TIMEOUT_ENV,+ WSL_ORCAD_IDLE_EXIT_TIMEOUT_MS+} from '../../../shared/orcad-idle-exit'import {ORCAD_READINESS_FILENAME,@@ -77,6 +81,24 @@ describe('orcadLaunchCommand', () => {)})+ describe('idle timeout', () => {+ afterEach(() => vi.unstubAllEnvs())++ it('never forwards a shorter idle timeout to an SSH launch, even from the desktop env', () => {+ vi.stubEnv(ORCAD_IDLE_TIMEOUT_ENV, String(WSL_ORCAD_IDLE_EXIT_TIMEOUT_MS))++ expect(orcadLaunchCommand(posix, SPEC)).not.toContain(ORCAD_IDLE_TIMEOUT_ENV)+ })++ it('carries the host-supplied idle timeout on a WSL (setsid) launch', () => {+ const command = orcadLaunchCommand(posix, SPEC, 'setsid', [+ [ORCAD_IDLE_TIMEOUT_ENV, String(WSL_ORCAD_IDLE_EXIT_TIMEOUT_MS)]+ ])++ expect(command).toContain(`${ORCAD_IDLE_TIMEOUT_ENV}='300000'`)+ })+ })+it('declares the Windows refusal instead of emitting a command that cannot work', () => {expect(() => orcadLaunchCommand(windows, SPEC)).toThrow(OrcadRemoteLaunchUnsupportedError)})diff --git a/src/main/orcad/orcad-managed-idle-exit.test.ts b/src/main/orcad/orcad-managed-idle-exit.test.tsindex 8f412217662..d8435c727f7 100644--- a/src/main/orcad/orcad-managed-idle-exit.test.ts+++ b/src/main/orcad/orcad-managed-idle-exit.test.ts@@ -10,7 +10,9 @@ import {} from './orcad-managed-idle-exit'import {ORCAD_E2E_IDLE_TIMEOUT_ENV,- ORCAD_IDLE_EXIT_TIMEOUT_MS+ ORCAD_IDLE_EXIT_TIMEOUT_MS,+ ORCAD_IDLE_TIMEOUT_ENV,+ WSL_ORCAD_IDLE_EXIT_TIMEOUT_MS} from '../../shared/orcad-idle-exit'import { ORCAD_MANAGED_ACTIVATION_ROOT_ENV } from '../../shared/orcad-managed-launch-env'@@ -69,6 +71,35 @@ describe('resolveOrcadManagedIdleExit', () => {})})+describe('client-chosen idle timeout', () => {+ const resolve = (env: NodeJS.ProcessEnv) =>+ resolveOrcadManagedIdleExit({ [ORCAD_MANAGED_ACTIVATION_ROOT_ENV]: '/f', ...env })?.timeoutMs++ it('honours the WSL launch value', () => {+ expect(resolve({ [ORCAD_IDLE_TIMEOUT_ENV]: String(WSL_ORCAD_IDLE_EXIT_TIMEOUT_MS) })).toBe(+ 5 * 60_000+ )+ expect(resolve({ [ORCAD_IDLE_TIMEOUT_ENV]: '60000' })).toBe(60_000)+ })++ it.each(['', '59999', '0', '-1', '1.5', 'abc', String(ORCAD_IDLE_EXIT_TIMEOUT_MS + 1)])(+ 'keeps the default for an unset, invalid, too short or longer value (%j)',+ (raw) => {+ expect(resolve({ [ORCAD_IDLE_TIMEOUT_ENV]: raw })).toBe(ORCAD_IDLE_EXIT_TIMEOUT_MS)+ }+ )++ it('lets a test timeout win over it', () => {+ expect(+ resolve({ [ORCAD_IDLE_TIMEOUT_ENV]: '300000', [ORCAD_E2E_IDLE_TIMEOUT_ENV]: '3000' })+ ).toBe(3_000)+ })++ it('stays off for a server the user started, whatever the value', () => {+ expect(resolveOrcadManagedIdleExit({ [ORCAD_IDLE_TIMEOUT_ENV]: '300000' })).toBeNull()+ })+})+describe('createOrcadIdleProbes', () => {it('reads an unused host as idle on every probe', async () => {expect(await verdicts(idlePorts())).toEqual({diff --git a/src/main/orcad/orcad-managed-idle-exit.ts b/src/main/orcad/orcad-managed-idle-exit.tsindex e01ae82071b..ec298b5b830 100644--- a/src/main/orcad/orcad-managed-idle-exit.ts+++ b/src/main/orcad/orcad-managed-idle-exit.ts@@ -5,7 +5,11 @@ import { RELAY_INSTALL_LOCK_NAME } from '../../shared/relay-install-lock-name'import { hasErrorCode } from '../daemon/daemon-process-inspection'import type { RuntimeRpcClientActivity } from '../runtime/runtime-rpc/runtime-rpc-shutdown'import { ORCAD_MANAGED_ACTIVATION_ROOT_ENV } from '../../shared/orcad-managed-launch-env'-import { ORCAD_IDLE_EXIT_TIMEOUT_MS, readOrcadE2EIdleTimeoutMs } from '../../shared/orcad-idle-exit'+import {+ ORCAD_IDLE_EXIT_TIMEOUT_MS,+ readOrcadE2EIdleTimeoutMs,+ readOrcadIdleTimeoutMs+} from '../../shared/orcad-idle-exit'import {OrcadIdleExitMonitor,type OrcadIdleExitEvidence,@@ -24,7 +28,8 @@ export function resolveOrcadManagedIdleExit(return null}return {- timeoutMs: readOrcadE2EIdleTimeoutMs(env) ?? ORCAD_IDLE_EXIT_TIMEOUT_MS,+ timeoutMs:+ readOrcadE2EIdleTimeoutMs(env) ?? readOrcadIdleTimeoutMs(env) ?? ORCAD_IDLE_EXIT_TIMEOUT_MS,activationRoot}}diff --git a/src/main/wsl/wsl-orcad-host-transport.test.ts b/src/main/wsl/wsl-orcad-host-transport.test.tsindex f23339f6dd9..1e713cfd1d1 100644--- a/src/main/wsl/wsl-orcad-host-transport.test.ts+++ b/src/main/wsl/wsl-orcad-host-transport.test.ts@@ -1,4 +1,5 @@import { ORCAD_WSL_DISTRO_GUID_ENV } from '../orcad/orcad-migration-wsl-destination'+import { ORCAD_IDLE_TIMEOUT_ENV } from '../../shared/orcad-idle-exit'import { EventEmitter } from 'node:events'import { PassThrough, Readable } from 'node:stream'import { describe, expect, it, vi } from 'vitest'@@ -216,8 +217,11 @@ describe('createWslOrcadHostTransport', () => {readDistroRegistryId: async (distro) => (distro === 'Ubuntu-24.04' ? id : null)})await expect(make('1a2b')?.orcadLaunchEnv?.({ fullVersion: '0.1.0+abc' })).resolves.toEqual([- [ORCAD_WSL_DISTRO_GUID_ENV, '1a2b']+ [ORCAD_WSL_DISTRO_GUID_ENV, '1a2b'],+ [ORCAD_IDLE_TIMEOUT_ENV, '300000']+ ])+ await expect(make(null)?.orcadLaunchEnv?.({ fullVersion: '0.1.0+abc' })).resolves.toEqual([+ [ORCAD_IDLE_TIMEOUT_ENV, '300000']])- await expect(make(null)?.orcadLaunchEnv?.({ fullVersion: '0.1.0+abc' })).resolves.toEqual([])})})diff --git a/src/main/wsl/wsl-orcad-host-transport.ts b/src/main/wsl/wsl-orcad-host-transport.tsindex b2acdd11f93..71146788c11 100644--- a/src/main/wsl/wsl-orcad-host-transport.ts+++ b/src/main/wsl/wsl-orcad-host-transport.ts@@ -19,6 +19,10 @@ import { resolveWslExecutablePath } from './wsl-executable-path'import { noteWslDistroLaunched } from '../wsl-background-distro-gate'import { readWslDistroRegistryIdShared } from './wsl-distro-registry-id'import { ORCAD_WSL_DISTRO_GUID_ENV } from '../orcad/orcad-migration-wsl-destination'+import {+ ORCAD_IDLE_TIMEOUT_ENV,+ WSL_ORCAD_IDLE_EXIT_TIMEOUT_MS+} from '../../shared/orcad-idle-exit'import type { WslOrcadHostTarget } from './wsl-orcad-host-target'export type WslOrcadHostTransport = OrcadHostTransport & {@@ -99,11 +103,15 @@ export function createWslOrcadHostTransport(// Without systemd, nohup children die with wsl.exe; launch orcad in a new session.orcadLaunchDetach: 'setsid',// D1b-2: bind launches to the registration the guest cannot read itself.+ // An idle orcad alone keeps the distro running, so it exits sooner here than on SSH.orcadLaunchEnv: async () => {const id = await (options.readDistroRegistryId ?? readWslDistroRegistryIdShared)(target.distro)- return id ? [[ORCAD_WSL_DISTRO_GUID_ENV, id]] : []+ return [+ ...(id ? [[ORCAD_WSL_DISTRO_GUID_ENV, id] as const] : []),+ [ORCAD_IDLE_TIMEOUT_ENV, String(WSL_ORCAD_IDLE_EXIT_TIMEOUT_MS)]+ ]},usesSystemSshTransport: () => false,// One transport, one wsl.exe lane: nothing underneath is ever replaced.diff --git a/src/shared/orcad-idle-exit.ts b/src/shared/orcad-idle-exit.tsindex 2d8fc972bdb..e0c70237909 100644--- a/src/shared/orcad-idle-exit.ts+++ b/src/shared/orcad-idle-exit.ts@@ -14,6 +14,23 @@ export function readOrcadE2EIdleTimeoutMs(env: NodeJS.ProcessEnv): number | null: null}+/** Client-chosen quiet period for the hosts it launches; older orcads ignore it and keep the default. */+export const ORCAD_IDLE_TIMEOUT_ENV = 'ORCA_ORCAD_IDLE_TIMEOUT_MS'+const ORCAD_IDLE_TIMEOUT_MIN_MS = 60_000+/** WSL hosts: an idle orcad holds the distro's VM (about 1.2 GB); a cold reopen costs about 4 s. */+export const WSL_ORCAD_IDLE_EXIT_TIMEOUT_MS = 5 * 60_000++/** Only shortens the default; anything unset, malformed or under a minute keeps it. */+export function readOrcadIdleTimeoutMs(env: NodeJS.ProcessEnv): number | null {+ const raw = env[ORCAD_IDLE_TIMEOUT_ENV]+ const value = raw ? Number(raw) : Number.NaN+ return Number.isSafeInteger(value) &&+ value >= ORCAD_IDLE_TIMEOUT_MIN_MS &&+ value <= ORCAD_IDLE_EXIT_TIMEOUT_MS+ ? value+ : null+}+/** Written to the data root just before an idle stop; the next start reports and clears it. */export const ORCAD_IDLE_STOP_RECORD_FILENAME = 'orcad-idle-stop.json'