From ce7dec11118ca389dbd25b21bd0a94c54216706e Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Wed, 30 Sep 2026 08:01:58 -0400 Subject: [PATCH 1/2] test: prove a downgrade needing reconciliation never reports a terminal --- .../stores/billingOperationStore.test.ts | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/platform/workspace/stores/billingOperationStore.test.ts b/src/platform/workspace/stores/billingOperationStore.test.ts index bbaae9f3a28..59715aeef73 100644 --- a/src/platform/workspace/stores/billingOperationStore.test.ts +++ b/src/platform/workspace/stores/billingOperationStore.test.ts @@ -1361,6 +1361,70 @@ describe('billingOperationStore', () => { ) }) + it('closes a downgrade to personal that needs reconciliation with one failed terminal', async () => { + vi.mocked(workspaceApi.getBillingOpStatus).mockResolvedValue({ + id: 'op-downgrade', + status: 'reconciliation_needed', + authentication_state: 'reconciliation_needed', + started_at: new Date().toISOString() + }) + + const store = useBillingOperationStore() + const terminal = store.startOperation('op-downgrade', 'subscription', { + tier: 'creator', + cycle: 'monthly', + checkoutType: 'change', + attemptStartedAt: Date.now(), + downgradeToPersonal: { + memberRemovalCount: 3, + memberRemovalFailures: 0, + targetTier: 'creator', + startedAt: Date.now() - 7_000 + } + }) + await vi.advanceTimersByTimeAsync(0) + expect((await terminal).status).toBe('reconciliation_needed') + await vi.runAllTimersAsync() + + const downgradeEvents = vi + .mocked(useTelemetry()?.trackBillingEvent) + ?.mock.calls.map(([event]) => event) + .filter((event) => event.operation === 'downgrade_to_personal') + expect(downgradeEvents).toEqual([ + { + operation: 'downgrade_to_personal', + stage: 'failed', + outcome: 'failure', + member_removal_count: 3, + member_removal_failures: 0, + target_tier: 'creator', + failure_category: 'reconciliation_needed', + duration_ms: expect.any(Number) + } + ]) + expect(downgradeEvents?.[0]?.duration_ms).toBeGreaterThanOrEqual(7_000) + }) + + it('reports no downgrade terminal when a subscription that is not a downgrade needs reconciliation', async () => { + vi.mocked(workspaceApi.getBillingOpStatus).mockResolvedValue({ + id: 'op-reconcile', + status: 'reconciliation_needed', + authentication_state: 'reconciliation_needed', + started_at: new Date().toISOString() + }) + + const store = useBillingOperationStore() + const terminal = store.startOperation('op-reconcile', 'subscription', { + attemptStartedAt: Date.now() + }) + await vi.advanceTimersByTimeAsync(0) + + expect((await terminal).status).toBe('reconciliation_needed') + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( + expect.objectContaining({ operation: 'downgrade_to_personal' }) + ) + }) + it('categorizes a subscription poll failure naming a connectivity issue as network, not a provider decline', async () => { vi.mocked(workspaceApi.getBillingOpStatus).mockResolvedValue({ id: 'op-1', From 24f30072901bd14396ba9bf4a41f88d45ac791af Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Wed, 30 Sep 2026 08:04:43 -0400 Subject: [PATCH 2/2] fix: report a terminal when a downgrade to personal needs reconciliation --- .../workspace/stores/billingOperationStore.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/platform/workspace/stores/billingOperationStore.ts b/src/platform/workspace/stores/billingOperationStore.ts index ae6db438b90..f47a7711da8 100644 --- a/src/platform/workspace/stores/billingOperationStore.ts +++ b/src/platform/workspace/stores/billingOperationStore.ts @@ -1033,6 +1033,19 @@ export const useBillingOperationStore = defineStore('billingOperation', () => { duration_ms: now - operation.businessAttemptStartedAt }) } + if (operation.downgradeToPersonal) { + telemetry?.trackBillingEvent({ + operation: 'downgrade_to_personal', + stage: 'failed', + outcome: 'failure', + member_removal_count: operation.downgradeToPersonal.memberRemovalCount, + member_removal_failures: + operation.downgradeToPersonal.memberRemovalFailures, + target_tier: operation.downgradeToPersonal.targetTier, + failure_category: 'reconciliation_needed', + duration_ms: now - operation.downgradeToPersonal.startedAt + }) + } resolveTerminal(opId) }