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(max): don't report handled quota errors to error tracking (#70957)

posthog[bot]c6ed58684e96
diff --git a/frontend/src/scenes/max/maxThreadLogic.test.ts b/frontend/src/scenes/max/maxThreadLogic.test.ts
index 678f23ff66b0..be88d7db9b31 100644
--- a/frontend/src/scenes/max/maxThreadLogic.test.ts
+++ b/frontend/src/scenes/max/maxThreadLogic.test.ts
@@ -1352,6 +1352,36 @@ describe('maxThreadLogic', () => {
})
})
+ describe('error tracking capture gating', () => {
+ // 402 (out of AI credits) and 429 (rate limited) are expected business conditions shown
+ // to the user, so they must not be reported to error tracking; genuine failures (500) must.
+ it.each([
+ [402, false],
+ [429, false],
+ [500, true],
+ ])('status %s reports exception: %s', async (status, shouldCapture) => {
+ const captureExceptionSpy = jest
+ .spyOn(posthog, 'captureException')
+ .mockImplementation(() => undefined as any)
+ jest.spyOn(api.conversations, 'stream').mockRejectedValue(new ApiError('error', status, undefined, {}))
+
+ logic.unmount()
+ maxLogicInstance.actions.setConversationId(MOCK_TEMP_CONVERSATION_ID)
+ logic = maxThreadLogic({ conversationId: MOCK_TEMP_CONVERSATION_ID, panelId: 'test' })
+ logic.mount()
+
+ await expectLogic(logic, () => {
+ logic.actions.askMax('hello')
+ }).toDispatchActions(['askMax', 'addMessage', 'completeThreadGeneration'])
+
+ if (shouldCapture) {
+ expect(captureExceptionSpy).toHaveBeenCalledTimes(1)
+ } else {
+ expect(captureExceptionSpy).not.toHaveBeenCalled()
+ }
+ })
+ })
+
describe('processNotebookUpdate', () => {
it('navigates to notebook when not already on notebook page', async () => {
router.actions.push(urls.ai())
diff --git a/frontend/src/scenes/max/maxThreadLogic.tsx b/frontend/src/scenes/max/maxThreadLogic.tsx
index de1b7c55a136..54776d4831bf 100644
--- a/frontend/src/scenes/max/maxThreadLogic.tsx
+++ b/frontend/src/scenes/max/maxThreadLogic.tsx
@@ -861,8 +861,11 @@ export const maxThreadLogic = kea<maxThreadLogicType>([
}
if (!(e instanceof DOMException) || e.name !== 'AbortError') {
- posthog.captureException(e)
let releaseException = true
+ // Some statuses are expected business conditions the UI already handles
+ // gracefully (out of AI credits, rate limited). Don't report those to error
+ // tracking as exceptions; only genuine failures should be captured.
+ let reportException = true
// Generic message by default
const relevantErrorMessage = { ...FAILURE_MESSAGE, id: uuid() }
const offlineMessage = 'You appear to be offline. Please check your internet connection.'
@@ -931,11 +934,13 @@ export const maxThreadLogic = kea<maxThreadLogicType>([
relevantErrorMessage.content =
e.detail ||
`You've reached PostHog AI's usage limit for the moment. Please try again ${e.formattedRetryAfter}.`
+ reportException = false
}
if (e.status === 402) {
relevantErrorMessage.content =
'Your organization reached its AI credit usage limit. Increase the limits in [Billing](/organization/billing), or ask an org admin to do so.'
+ reportException = false
}
if (e.status && e.status >= 500) {
@@ -946,6 +951,10 @@ export const maxThreadLogic = kea<maxThreadLogicType>([
console.error(e)
}
+ if (reportException) {
+ posthog.captureException(e)
+ }
+
if (releaseException) {
posthog.capture('max conversation turn completed', {
status: 'failure',