From d2006ae140411b8537a396885dc9be3ab86769b8 Mon Sep 17 00:00:00 2001 From: wishforge Date: Mon, 9 Nov 2026 05:35:57 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Run=20an=20executor=20with=20the?= =?UTF-8?q?=20run's=20own=20credential,=20not=20the=20operator's=20login?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In development the worker handed Claude Code both the tenant's key and the operator's logged-in home. The CLI signs in with the login it finds there, so the gateway saw a subscription credential it does not accept and answered 401 "Invalid API key provided" — the run then waited on provider_error with its work saved. A run that carries a credential of its own now gets an empty home, exactly like a Copilot answer; the operator's login stays for runs that have nothing else to sign in with. --- apps/worker/src/providers.ts | 15 ++++++++++----- tests/providers.test.ts | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/apps/worker/src/providers.ts b/apps/worker/src/providers.ts index 7fe4f90..906393d 100644 --- a/apps/worker/src/providers.ts +++ b/apps/worker/src/providers.ts @@ -51,12 +51,16 @@ export const providerRegistry: Record = { isolationConfirmed: true, allowUnsandboxed: config.sandboxMode === 'host', }), - 'claude-code': (config, context, isolatedHome) => - new ClaudeCodeAdapter({ + 'claude-code': (config, context, isolatedHome) => { + const credentialEnv = cliCredential(context, 'ANTHROPIC_API_KEY', 'ANTHROPIC_BASE_URL'); + return new ClaudeCodeAdapter({ binary: config.providerBinaries?.['claude-code'], isolatedHome, - credentialEnv: cliCredential(context, 'ANTHROPIC_API_KEY', 'ANTHROPIC_BASE_URL'), - ...(config.claudeAuthHome && config.sandboxMode === 'host' + credentialEnv, + // The operator's login and a tenant credential never travel together: with both present the + // CLI signs in with the login it finds in that home, and the gateway rejects it (401). A run + // that has a credential of its own therefore gets an empty home, exactly like a Copilot answer. + ...(config.claudeAuthHome && config.sandboxMode === 'host' && !credentialEnv ? { localAuth: { home: config.claudeAuthHome, developmentHost: true as const } } : {}), ...(config.claudeCommandSandbox @@ -70,7 +74,8 @@ export const providerRegistry: Record = { } : {}), isolationConfirmed: true, - }), + }); + }, }; /** Reject native login configuration before connecting a worker to Temporal. */ diff --git a/tests/providers.test.ts b/tests/providers.test.ts index 9e91a62..c78de8d 100644 --- a/tests/providers.test.ts +++ b/tests/providers.test.ts @@ -70,6 +70,26 @@ describe('model gateways', () => { ANTHROPIC_BASE_URL: 'https://ai-api.example', }); }); + it('never hands the operator login to a CLI that has a credential of its own', () => { + const settings = { + providerBinaries: { 'claude-code': '/usr/bin/true' }, + claudeAuthHome: '/Users/operator', + sandboxMode: 'host', + }; + const adapter = (context: RunContext) => + providerRegistry['claude-code'](settings as never, context, '/tmp/home') as unknown as { + config: { localAuth?: unknown }; + }; + // Both at once let the CLI sign in with the login found in that home, and a gateway answers 401. + expect(adapter({ providerCredential: { apiKey: 'fixture-key' } } as unknown as RunContext).config.localAuth).toBe( + undefined, + ); + // With no credential of its own, the development login is the only way to sign in. + expect(adapter({} as unknown as RunContext).config.localAuth).toEqual({ + home: '/Users/operator', + developmentHost: true, + }); + }); }); describe('executor registry', () => {