Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(inbox): handle 404 from refund summary on flag mismatch (#71263)

posthog[bot]a6ae50156b35
diff --git a/frontend/src/scenes/inbox/logics/inboxUsageLogic.test.ts b/frontend/src/scenes/inbox/logics/inboxUsageLogic.test.ts
index 1ed166b90f7c..1ce8bd4e1f38 100644
--- a/frontend/src/scenes/inbox/logics/inboxUsageLogic.test.ts
+++ b/frontend/src/scenes/inbox/logics/inboxUsageLogic.test.ts
@@ -105,4 +105,34 @@ describe('inboxUsageLogic', () => {
expect(logic.values.usedPrs).toBe(4)
})
+
+ // The org-keyed refunds flag resolves late on the client, so the client can fire the summary
+ // request while the server (re-checking the same flag) still returns 404. That mismatch must
+ // degrade to a null summary — falling back to billing's own usage — not bubble up as an
+ // uncaught error into error tracking.
+ it('degrades to null when the server returns 404 for the refund summary', async () => {
+ useMocks({
+ get: {
+ '/api/billing': () => [
+ 200,
+ { products: [{ type: 'inbox', display_divisor: CREDITS_PER_PR, current_usage: 1500 }] },
+ ],
+ '/api/projects/:team_id/signals/reports/refund-summary/': () => [
+ 404,
+ { detail: 'PR refunds are not enabled for this organization.' },
+ ],
+ },
+ })
+ featureFlagLogic.mount()
+ setRefundsFlag()
+ logic = inboxUsageLogic()
+ logic.mount()
+
+ await expectLogic(logic).toDispatchActions(['loadRefundSummarySuccess']).toFinishAllListeners()
+ expect(logic.values.refundSummary).toBeNull()
+ // Widget still renders from billing's recorded usage rather than tearing down. Billing loads
+ // via afterMount independently of the refund summary, so wait for all loaders above before
+ // reading usedPrs, which depends on both.
+ expect(logic.values.usedPrs).toBe(1)
+ })
})
diff --git a/frontend/src/scenes/inbox/logics/inboxUsageLogic.ts b/frontend/src/scenes/inbox/logics/inboxUsageLogic.ts
index 2cfd1fb7a260..f03021f7a421 100644
--- a/frontend/src/scenes/inbox/logics/inboxUsageLogic.ts
+++ b/frontend/src/scenes/inbox/logics/inboxUsageLogic.ts
@@ -3,6 +3,7 @@ import { forms } from 'kea-forms'
import { loaders } from 'kea-loaders'
import { subscriptions } from 'kea-subscriptions'
+import { ApiError } from 'lib/api-error'
import { FEATURE_FLAGS } from 'lib/constants'
import { Dayjs } from 'lib/dayjs'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
@@ -75,7 +76,18 @@ export const inboxUsageLogic = kea<inboxUsageLogicType>([
if (!values.featureFlags[FEATURE_FLAGS.SIGNALS_PR_REFUNDS] || values.currentTeamId == null) {
return null
}
- return await signalsReportsRefundSummaryRetrieve(String(values.currentTeamId))
+ try {
+ return await signalsReportsRefundSummaryRetrieve(String(values.currentTeamId))
+ } catch (error) {
+ // The refunds flag is org-keyed and resolves late on the client, so the client can
+ // believe refunds are on while the server (re-checking the same flag) disagrees and
+ // returns 404. Degrade to the same null the client-flag guard returns when refunds
+ // are off, rather than surfacing a transient mismatch as an error.
+ if (error instanceof ApiError && error.status === 404) {
+ return null
+ }
+ throw error
+ }
},
},
],