Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/oauth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,11 @@ export async function refreshAnthropicAccountWithLock(
clearOAuthRefreshIntent(provider, accountId, generation);
return fresh.access;
} catch (error) {
if (error instanceof OAuthMutationBusyError) throw error;
if (!terminal(error)) throw error;
if (error instanceof OAuthMutationBusyError || error instanceof OAuthTokenRefreshStaleError) throw error;
if (!terminal(error)) {
clearOAuthRefreshIntent(provider, accountId, generation);
throw error;
}
await markAccountNeedsReauthIfGeneration(provider, accountId, generation, writerGeneration);
clearOAuthRefreshIntent(provider, accountId, generation);
throw new OAuthLoginRequiredError(provider);
Expand Down
8 changes: 7 additions & 1 deletion tests/oauth-refresh.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ describe("oauth refresh hardening", () => {
expect(getCredential("xai")?.source).toBe("oauth");
});

test("Anthropic transient failures do not mark needsReauth", async () => {
test("Anthropic transient failures remain retryable without marking needsReauth", async () => {
for (const [index, error] of [
new AnthropicTokenError("server", 503, undefined),
new AnthropicTokenError("timeout", undefined, undefined),
Expand All @@ -484,6 +484,12 @@ describe("oauth refresh hardening", () => {
const id = getAccountSet("anthropic")!.activeAccountId;
await expect(refreshAnthropicAccountWithLock("anthropic", id, { ...OAUTH_PROVIDERS.anthropic!, refresh: async () => { throw error; } }, getAccountCredential("anthropic", id)!)).rejects.toBe(error);
expect(getAccountSet("anthropic")!.accounts.find(account => account.id === id)!.needsReauth).toBeUndefined();
expect(readOAuthRefreshIntent("anthropic", id)).toBeUndefined();
await expect(refreshAnthropicAccountWithLock("anthropic", id, {
...OAUTH_PROVIDERS.anthropic!,
refresh: async () => ({ access: `fresh-${index}`, refresh: `rt-fresh-${index}`, expires: Date.now() + 3600_000 }),
}, getAccountCredential("anthropic", id)!)).resolves.toBe(`fresh-${index}`);
expect(getAccountSet("anthropic")!.accounts.find(account => account.id === id)!.needsReauth).toBeUndefined();
}
});

Expand Down
Loading