🐛 Run an executor with the run's own credential, not the operator's login
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.
This commit is contained in:
parent
ac3c185cbc
commit
d2006ae140
@ -51,12 +51,16 @@ export const providerRegistry: Record<ProviderId, Factory> = {
|
||||
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<ProviderId, Factory> = {
|
||||
}
|
||||
: {}),
|
||||
isolationConfirmed: true,
|
||||
}),
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
/** Reject native login configuration before connecting a worker to Temporal. */
|
||||
|
||||
@ -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', () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user