From 4765c194d4a137e0bbf643bfdc702daff0a653b0 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 10 Nov 2026 07:09:27 -0800 Subject: [PATCH] fix(cloud): remember only a host's 'cloud' answer; ask again after 'not cloud' (re-review LOW) --- .../hosted-sandbox/cloud-desktop-keys.test.ts | 31 +++++++++++++++++++ src/main/hosted-sandbox/cloud-desktop-keys.ts | 6 +++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/main/hosted-sandbox/cloud-desktop-keys.test.ts b/src/main/hosted-sandbox/cloud-desktop-keys.test.ts index 6a4c1f88f93..6eaf532d4c8 100644 --- a/src/main/hosted-sandbox/cloud-desktop-keys.test.ts +++ b/src/main/hosted-sandbox/cloud-desktop-keys.test.ts @@ -213,3 +213,34 @@ describe('withHostAgentApiKeyEnv asks the host', () => { ) }) }) + +describe('host answer cache', () => { + it('asks again after a "not cloud" answer, so a re-paired id that is now a cloud VM gets no keys', async () => { + const { setCloudDesktopKeysUserDataPath, withHostAgentApiKeyEnv } = + await import('./cloud-desktop-keys') + setCloudDesktopKeysUserDataPath('/u') + environments.set('env-repaired', { + source: 'manual', + endpoints: [{ endpoint: 'wss://10.0.0.9:6768' }] + }) + launchEnv = { CODEX_API_KEY: 'custom-name-real-key' } + const params = { launchAgent: 'codex', command: 'codex', env: {} } + const answer = (caps: string[]) => async () => ({ + ok: true as const, + id: 's', + result: { capabilities: caps }, + _meta: { runtimeId: 'r' } + }) + expect( + await withHostAgentApiKeyEnv('env-repaired', 'terminal.create', params, answer([])) + ).not.toBe(params) + expect( + await withHostAgentApiKeyEnv( + 'env-repaired', + 'terminal.create', + params, + answer(['host.orca-cloud.v1']) + ) + ).toBe(params) + }) +}) diff --git a/src/main/hosted-sandbox/cloud-desktop-keys.ts b/src/main/hosted-sandbox/cloud-desktop-keys.ts index ceb130b3f15..0e329a7409e 100644 --- a/src/main/hosted-sandbox/cloud-desktop-keys.ts +++ b/src/main/hosted-sandbox/cloud-desktop-keys.ts @@ -127,7 +127,11 @@ async function hostSaysOrcaCloud( return null } const cloud = capabilities.includes(ORCA_CLOUD_HOST_RUNTIME_CAPABILITY) - hostKinds.set(environmentId, { cloud, at: Date.now() }) + // Only "cloud" is remembered: it can only withhold keys. A "not cloud" answer is asked again on + // the next launch, so a re-paired id that now points at a cloud VM is never sent keys from cache. + if (cloud) { + hostKinds.set(environmentId, { cloud, at: Date.now() }) + } return cloud } catch { return null