Repository navigation
fix(status-bar): escalate stuck Claude "Refreshing sign-in" after timeout #10060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
innocarpe
wants to merge
3
commits into
stablyai:main
from
innocarpe:fix/claude-refreshing-sign-in-escalate
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/renderer/src/components/status-bar/repro-8974-refreshing-sign-in-stuck.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /** | ||
| * Issue #8974 — Claude usage stuck on "Refreshing sign-in". | ||
| * | ||
| * Transient failureKinds map to soft "Refreshing sign-in" copy while repair is | ||
| * in flight. Once `refreshingSinceMs` ages past the escalate window, the UI | ||
| * must leave the indefinite spinner and surface re-auth copy / CTA. | ||
| * | ||
| * Re-run: | ||
| * pnpm exec vitest run --config config/vitest.config.ts \ | ||
| * src/renderer/src/components/status-bar/repro-8974-refreshing-sign-in-stuck.test.ts | ||
| */ | ||
| import { describe, expect, it, vi } from 'vitest' | ||
|
|
||
| vi.mock('@/i18n/i18n', () => ({ | ||
| translate: (_key: string, fallback: string) => fallback | ||
| })) | ||
|
|
||
| import { | ||
| CLAUDE_REFRESHING_SIGN_IN_ESCALATE_AFTER_MS, | ||
| stampClaudeRefreshingSince | ||
| } from '../../../../shared/claude-refreshing-sign-in' | ||
| import type { ProviderRateLimits } from '../../../../shared/rate-limit-types' | ||
| import { getProviderUsageErrorMessage, getProviderUsageStatusLabel } from './usage-error-copy' | ||
| import { getUsageRosterRowState } from './usage-roster-row-state' | ||
|
|
||
| function claudeError(failureKind: string, refreshingSinceMs?: number): ProviderRateLimits { | ||
| return { | ||
| provider: 'claude', | ||
| status: 'error', | ||
| error: 'token expired', | ||
| updatedAt: Date.now(), | ||
| session: null, | ||
| weekly: null, | ||
| monthly: null, | ||
| usageMetadata: { | ||
| failureKind: failureKind as never, | ||
| ...(refreshingSinceMs != null ? { refreshingSinceMs } : {}) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| describe('issue #8974 Refreshing sign-in escalation', () => { | ||
| it('maps auth-refresh failureKinds to Refreshing sign-in while the window is open', () => { | ||
| const now = Date.now() | ||
| for (const kind of [ | ||
| 'stale-token', | ||
| 'refreshable-credentials-without-token', | ||
| 'delegated-refresh-required' | ||
| ]) { | ||
| const p = claudeError(kind, now) | ||
| expect(getProviderUsageStatusLabel(p)).toBe('Refreshing sign-in') | ||
| expect(getProviderUsageErrorMessage(p)).toMatch(/sign-in is being refreshed/i) | ||
| expect(getUsageRosterRowState(p, false)).toEqual({ | ||
| kind: 'error', | ||
| statusLabel: 'Refreshing sign-in' | ||
| }) | ||
| } | ||
| }) | ||
|
|
||
| it('escalates copy and roster CTA once refreshingSinceMs ages out', () => { | ||
| const since = Date.now() - CLAUDE_REFRESHING_SIGN_IN_ESCALATE_AFTER_MS | ||
| const p = claudeError('stale-token', since) | ||
|
|
||
| expect(getProviderUsageStatusLabel(p)).toBe('Sign-in needs refresh') | ||
| expect(getProviderUsageErrorMessage(p)).toMatch(/could not be refreshed/i) | ||
| expect(getUsageRosterRowState(p, false)).toEqual({ | ||
| kind: 'sign-in', | ||
| statusLabel: 'Sign-in needs refresh' | ||
| }) | ||
| }) | ||
|
|
||
| it('preserves the first refresh stamp so continuous polls can escalate', () => { | ||
| // Keep the synthetic clock near Date.now() so label helpers (which read wall clock) stay in-window. | ||
| const t0 = Date.now() - 90_000 | ||
| let state = stampClaudeRefreshingSince(claudeError('stale-token'), null, t0) | ||
| for (let i = 1; i <= 5; i++) { | ||
| state = stampClaudeRefreshingSince( | ||
| claudeError(i % 2 === 0 ? 'stale-token' : 'refreshable-credentials-without-token'), | ||
| state, | ||
| t0 + i * 5_000 | ||
| ) | ||
| } | ||
| expect(state.usageMetadata?.refreshingSinceMs).toBe(t0) | ||
| // ~90s + 25s still under the 2-minute escalate window. | ||
| expect(getProviderUsageStatusLabel(state)).toBe('Refreshing sign-in') | ||
|
|
||
| const escalated = claudeError( | ||
| 'stale-token', | ||
| Date.now() - CLAUDE_REFRESHING_SIGN_IN_ESCALATE_AFTER_MS | ||
| ) | ||
| expect(getProviderUsageStatusLabel(escalated)).toBe('Sign-in needs refresh') | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import type { ProviderRateLimits } from './rate-limit-types' | ||
| import { | ||
| CLAUDE_REFRESHING_SIGN_IN_ESCALATE_AFTER_MS, | ||
| isClaudeRefreshingSignInEscalated, | ||
| stampClaudeRefreshingSince | ||
| } from './claude-refreshing-sign-in' | ||
|
|
||
| function claudeError( | ||
| failureKind: string, | ||
| overrides: Partial<ProviderRateLimits> = {} | ||
| ): ProviderRateLimits { | ||
| return { | ||
| provider: 'claude', | ||
| status: 'error', | ||
| error: 'token expired', | ||
| updatedAt: Date.now(), | ||
| session: null, | ||
| weekly: null, | ||
| monthly: null, | ||
| usageMetadata: { failureKind: failureKind as never }, | ||
| ...overrides | ||
| } | ||
| } | ||
|
|
||
| describe('stampClaudeRefreshingSince', () => { | ||
| it('stamps refreshingSinceMs on first Claude refreshing failure', () => { | ||
| const now = 1_700_000_000_000 | ||
| const stamped = stampClaudeRefreshingSince(claudeError('stale-token'), null, now) | ||
| expect(stamped.usageMetadata?.refreshingSinceMs).toBe(now) | ||
| }) | ||
|
|
||
| it('preserves the original stamp across continuous refreshing failures', () => { | ||
| const first = 1_700_000_000_000 | ||
| const later = first + 30_000 | ||
| const previous = stampClaudeRefreshingSince(claudeError('stale-token'), null, first) | ||
| const next = stampClaudeRefreshingSince( | ||
| claudeError('refreshable-credentials-without-token'), | ||
| previous, | ||
| later | ||
| ) | ||
| expect(next.usageMetadata?.refreshingSinceMs).toBe(first) | ||
| }) | ||
|
|
||
| it('clears the stamp when usage recovers', () => { | ||
| const previous = stampClaudeRefreshingSince( | ||
| claudeError('stale-token'), | ||
| null, | ||
| 1_700_000_000_000 | ||
| ) | ||
| const ok: ProviderRateLimits = { | ||
| provider: 'claude', | ||
| status: 'ok', | ||
| error: null, | ||
| updatedAt: Date.now(), | ||
| session: { usedPercent: 10, windowMinutes: 300, resetsAt: null, resetDescription: null }, | ||
| weekly: null, | ||
| usageMetadata: { | ||
| source: 'oauth', | ||
| refreshingSinceMs: previous.usageMetadata?.refreshingSinceMs | ||
| } | ||
| } | ||
| const recovered = stampClaudeRefreshingSince(ok, previous) | ||
| expect(recovered.usageMetadata?.refreshingSinceMs).toBeUndefined() | ||
| }) | ||
|
|
||
| it('does not stamp non-Claude providers', () => { | ||
| const p: ProviderRateLimits = { | ||
| provider: 'codex', | ||
| status: 'error', | ||
| error: 'token expired', | ||
| updatedAt: Date.now(), | ||
| session: null, | ||
| weekly: null, | ||
| usageMetadata: { failureKind: 'stale-token' } | ||
| } | ||
| expect(stampClaudeRefreshingSince(p, null).usageMetadata?.refreshingSinceMs).toBeUndefined() | ||
| }) | ||
| }) | ||
|
|
||
| describe('isClaudeRefreshingSignInEscalated', () => { | ||
| it('is false while the refresh window is still open', () => { | ||
| const since = 1_700_000_000_000 | ||
| const p = stampClaudeRefreshingSince(claudeError('stale-token'), null, since) | ||
| expect( | ||
| isClaudeRefreshingSignInEscalated(p, since + CLAUDE_REFRESHING_SIGN_IN_ESCALATE_AFTER_MS - 1) | ||
| ).toBe(false) | ||
| }) | ||
|
|
||
| it('is true once the refresh window ages out (#8974)', () => { | ||
| const since = 1_700_000_000_000 | ||
| const p = stampClaudeRefreshingSince(claudeError('stale-token'), null, since) | ||
| expect( | ||
| isClaudeRefreshingSignInEscalated(p, since + CLAUDE_REFRESHING_SIGN_IN_ESCALATE_AFTER_MS) | ||
| ).toBe(true) | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.