Repository navigation
fix(billing): retry transient context initialization failures #16124
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
Changes from all commits
d9d84bb
9e4a8c9
a4cfd53
37218c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,8 @@ import type { | |
| PreviewSubscribeOptions, | ||
| SubscribeOptions | ||
| } from '@/platform/workspace/api/workspaceApi' | ||
| import { reportError } from '@/platform/telemetry/reportError' | ||
| import { categorizeBillingApiError } from '@/platform/telemetry/utils/billingFailureCategory' | ||
| import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' | ||
|
|
||
| import type { | ||
|
|
@@ -31,6 +33,7 @@ import { useWorkspaceBilling } from '@/platform/workspace/composables/useWorkspa | |
| // new sub is never misrouted even before its credit stop is populated. | ||
| const LEGACY_TEAM_PLAN_SLUG_PREFIX = 'team-' | ||
| const PER_CREDIT_TEAM_PLAN_SLUG_PREFIX = 'team_per_credit_' | ||
| const INITIALIZATION_RETRY_DELAYS_MS = [500, 2_000] | ||
|
|
||
| function isTeamPlanSlug(planSlug: string | null | undefined): boolean { | ||
| const normalizedSlug = planSlug?.toLowerCase() | ||
|
|
@@ -240,15 +243,10 @@ function useBillingContextInternal(): BillingContext { | |
| // Reset and reinitialize when the active workspace or billing backend changes. | ||
| watch( | ||
| [() => store.activeWorkspace?.id, () => type.value], | ||
| async ([newWorkspaceId]) => { | ||
| ([newWorkspaceId]) => { | ||
| resetBillingState() | ||
| if (!newWorkspaceId) return | ||
|
|
||
| try { | ||
| await initialize() | ||
| } catch (err) { | ||
| console.error('Failed to initialize billing context:', err) | ||
| } | ||
| void initialize().catch(() => {}) | ||
| }, | ||
| { immediate: true } | ||
| ) | ||
|
|
@@ -260,13 +258,33 @@ function useBillingContextInternal(): BillingContext { | |
| isLoading.value = true | ||
| error.value = null | ||
| try { | ||
| await adapter.initialize() | ||
| for (let attempt = 0; ; attempt++) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| try { | ||
| await adapter.initialize() | ||
| break | ||
| } catch (err) { | ||
| if (activeContext.value !== adapter) return | ||
| if ( | ||
| attempt >= INITIALIZATION_RETRY_DELAYS_MS.length || | ||
| categorizeBillingApiError(err) !== 'network' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we preserve the HTTP status when
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed and fixed in a4cfd53 — thanks, this was a real misclassification. Root cause.
Fix. Carry the server-provided status through both wrappers. Nothing is inferred client-side: Regression coverage — both new tests fail on the parent commit with
I checked the rest of the initialization surface for the same class of bug: the workspace rail propagates raw Also folded in CodeRabbit's non-blocking timer nit: the three in-test Verification: |
||
| ) { | ||
| throw err | ||
| } | ||
| const retryDelay = INITIALIZATION_RETRY_DELAYS_MS[attempt] | ||
| await new Promise((resolve) => setTimeout(resolve, retryDelay)) | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| if (activeContext.value !== adapter) return | ||
| } | ||
| } | ||
| if (activeContext.value !== adapter) return | ||
| isInitialized.value = true | ||
| } catch (err) { | ||
| if (activeContext.value !== adapter) return | ||
| error.value = | ||
| err instanceof Error ? err.message : 'Failed to initialize billing' | ||
| reportError(err, { | ||
| errorType: 'billing_context_initialization_failure', | ||
| tags: { billing_backend: type.value } | ||
| }) | ||
| throw err | ||
| } finally { | ||
| if (activeContext.value === adapter) isLoading.value = false | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.