fix(auth): reconcile committed OAuth cancellation

This commit is contained in:
Federico Jaramillo Martinez
2026-07-18 07:48:27 +02:00
parent aca168a311
commit 3c3741b565
5 changed files with 137 additions and 20 deletions
+12 -3
View File
@@ -53,8 +53,9 @@ export class AuthService {
static async create(deps: AuthServiceDependencies = {}): Promise<AuthService> {
const runtime = deps.runtime ?? (deps.agentDir === undefined ? await ModelRuntime.create({}) : await createModelRuntimeForAgentDir(deps.agentDir));
const authFlows = deps.authFlows ?? new OAuthLoginFlowService();
return new AuthService(runtime, authFlows, deps.logger ?? noopLogger);
const logger = deps.logger ?? noopLogger;
const authFlows = deps.authFlows ?? new OAuthLoginFlowService({ logger });
return new AuthService(runtime, authFlows, logger);
}
subscribe(listener: AuthChangeListener): () => void {
@@ -130,11 +131,19 @@ export class AuthService {
const results = await Promise.allSettled([...this.listeners].map(async (listener) => listener(change)));
for (const result of results) {
if (result.status === "rejected") {
this.logger.error({ err: result.reason, ...context }, "auth-change listener failed");
this.logErrorNoThrow({ err: result.reason, ...context }, "auth-change listener failed");
}
}
}
private logErrorNoThrow(details: Record<string, unknown>, message: string): void {
try {
this.logger.error(details, message);
} catch {
// A diagnostic failure cannot turn an already-committed auth mutation into an API failure.
}
}
private async requireApiKeyLoginProvider(providerId: string) {
await this.runtime.reloadConfig();
const provider = getLoginProviderOptions(this.runtime, "api_key").find((option) => option.id === providerId);