From ddf6cfe09f19e494c42fa145e0e07af4741d287e Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 10 Nov 2026 17:40:14 -0800 Subject: [PATCH] fix(cloud): a provider 401 drops the dead account placeholder from all the person's running sandboxes --- cloud/apps/sandbox-control/src/index.ts | 5 +++-- cloud/apps/sandbox-control/test/agent-accounts.test.ts | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cloud/apps/sandbox-control/src/index.ts b/cloud/apps/sandbox-control/src/index.ts index 45cb59d83b2..086f62003a4 100644 --- a/cloud/apps/sandbox-control/src/index.ts +++ b/cloud/apps/sandbox-control/src/index.ts @@ -379,9 +379,10 @@ function egressRoutes(env: Env, deps: Deps): (row: SandboxRow, host: string) => const handled = provider.onUnauthorized ? keyring.then((ring) => provider.onUnauthorized!({ db: env.SANDBOX_DB, keyring: ring, userId: row.user_id, now, waitUntil })) : markAgentCredentialRevoked(env.SANDBOX_DB, row.user_id, agent, now) - const work = handled.then(() => { + // Every running sandbox of this person drops the dead placeholder, not only this one. + const work = handled.then(async () => { forgetAccountCredential(row.user_id, agent) - scheduleEnvRefresh(env, deps, row) + await refreshOwnersSandboxes(env, deps, row.user_id) }) if (deps.waitUntil) { deps.waitUntil(work.catch(() => undefined)) diff --git a/cloud/apps/sandbox-control/test/agent-accounts.test.ts b/cloud/apps/sandbox-control/test/agent-accounts.test.ts index 0efcdc84aaf..6b14debc3ae 100644 --- a/cloud/apps/sandbox-control/test/agent-accounts.test.ts +++ b/cloud/apps/sandbox-control/test/agent-accounts.test.ts @@ -181,11 +181,19 @@ describe('egress-time Source (D10) and shared workspaces (D13)', () => { await h.call('PUT', '/v1/agent-credentials/claude', { bearer: mia, body: { token: SETUP_TOKEN } }) const created = await h.call('POST', '/v1/sandboxes', { body: { workspaceId: 'ws-1', machineSize: 'standard' }, bearer: mia }) const id: string = created.body.sandbox.id + const other = await h.call('POST', '/v1/sandboxes', { body: { workspaceId: 'ws-2', machineSize: 'standard' }, bearer: mia }) + const otherSession: string = other.body.sandbox.session.id reply.status = 401 expect((await proxied(id, 'api.anthropic.com', { authorization: `Bearer orca-ph-claude-account-${id}` })).status).toBe(401) expect((await h.call('GET', '/v1/agent-credentials', { bearer: mia })).body.claude.state).toBe('revoked') // Already off the account: no placeholder in new shells, and the proxy refuses with a clear reason. await vi.waitFor(() => expect(lastEnv(ENV_COMMAND).CLAUDE_CODE_OAUTH_TOKEN).toBeUndefined()) + // The person's other running workspace drops the dead placeholder too. + await vi.waitFor(() => { + const refreshed = h.vercel.commands.filter((c) => c.command === ENV_COMMAND && c.sessionId === otherSession) + expect(refreshed.length).toBeGreaterThan(0) + expect(decode(refreshed.at(-1)!.env.ORCA_SECRET_ENV).CLAUDE_CODE_OAUTH_TOKEN).toBeUndefined() + }) expect((await proxied(id, 'api.anthropic.com', { authorization: `Bearer orca-ph-claude-account-${id}` })).status).toBe(403) })