fix: harden Sentry/PostHog overload-error filters (closes TONALCOACH-1C)#343
Draft
fix: harden Sentry/PostHog overload-error filters (closes TONALCOACH-1C)#343
Conversation
Three gaps let "This model is currently experiencing high demand" and
similar Gemini 503 transient errors slip through the beforeSend filters
even though they are fully handled backend-side.
1. `errorMessages` in `sentryBeforeSend.ts` did not walk the Error.cause
chain. The Vercel AI SDK wraps provider errors: the outer Error carries
a generic message ("Error reading UI message stream") while the
provider-specific text lives on `Error.cause`. The filter matched the
generic message and failed to drop the event.
Fix: walk the full cause chain and push every ancestor message into the
candidate set.
2. Non-Error, non-string objects with a `.message` property (SDK types
that implement the Error interface structurally without extending Error)
were not inspected. Duck-type the check so those objects' messages are
also included.
3. Gemini has a second 503 phrasing — "The model is currently overloaded."
— that maps to `provider_overload` on the backend but had no matching
suppression entry. Add "model is currently overloaded" to both
`sentryBeforeSend` and `posthogBeforeSend` to cover it.
Additionally, `finalizePendingMessages` in `resilience.ts` now wraps each
`finalizeMessage` mutation call in a try/catch. If `@convex-dev/agent`'s
internal stream-error handler finalizes a message before our retry loop
runs, the subsequent call would throw and abort the loop, leaving other
pending messages in the thread unprocessed. The catch is intentionally
silent — this is a best-effort cleanup pass on an already-failed turn.
Tests added: cause-chain suppression (one and two levels deep), non-Error
object suppression, new overloaded pattern, kept-real-error guard, and
sanitized-code exhaustive table in resilienceFinalize.test.ts.
Fixes TONALCOACH-1C
https://claude.ai/code/session_018xtWrKbmTQswzitpVKoLij
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Reviewed open Sentry issues and found TONALCOACH-1C — 807 occurrences of "This model is currently experiencing high demand" still reaching Sentry despite
sentryBeforeSendhaving a suppression entry for that substring. Three root-cause gaps identified and fixed:1.
sentryBeforeSend.ts— cause chain not inspected (src/lib/sentryBeforeSend.ts)The Vercel AI SDK wraps provider errors: the outer
Errorcarries a generic message (e.g."Error reading UI message stream") while the Gemini-specific text lives onError.cause. TheerrorMessageshelper only checked the outer.message, so the suppression filter matched the generic wrapper and let the event through.Fix: Walk the full
Error.causechain and add every ancestor's message to the candidate set.2.
sentryBeforeSend.ts— non-Error objects not handledSDK error types that implement the Error interface structurally (without
extends Error) weren't inspected, sohint.originalException instanceof Errorreturned false and the message was silently skipped.Fix: Duck-type the check — if
originalExceptionis a plain object with astring.message, include that message.3. Missing Gemini 503 variant:
"model is currently overloaded"Gemini has a second 503 overload phrasing ("The model is currently overloaded. Please try again later.") that maps to
provider_overloadon the backend but had no suppression entry in eithersentryBeforeSendorposthogBeforeSend.Fix: Add
"model is currently overloaded"to both filter lists.4.
finalizePendingMessagesnow idempotent (convex/ai/resilience.ts)When
@convex-dev/agent's internal stream-error handler finalizes a message before our retry loop reaches it, the subsequentfinalizeMessagecall throws, aborting the loop and leaving other pending messages unprocessed.Fix: Wrap each per-message
finalizeMessagecall intry/catch— the catch is intentionally silent since this is a best-effort cleanup pass on an already-failed turn. The outersafeFinalizePendingstill catches any remaining errors.Test plan
"model is currently overloaded"pattern, kept-real-error guardposthogBeforeSendgains matching"model is currently overloaded"testresilienceFinalize.test.tsadds: new overloaded →provider_overloadmapping, exhaustive sanitized-code table for all transient kindshttps://claude.ai/code/session_018xtWrKbmTQswzitpVKoLij
Generated by Claude Code