Repository navigation
fix(mcp): keep OAuth token-refresh caller state out of Sentry (KODY-CLOUDFLARE-4J) - #1390
Conversation
Classify missing refresh tokens and provider HTTP 4xx rejections (invalid_grant / revoked consent) as IntegrationTokenRefreshCallerError, re-wrap as McpCallerError from integration_token_refresh, and drop the stable messages in isCallerFailure plus beforeSend. Agents get reconnect guidance; provider 5xx stays visible (KODY-CLOUDFLARE-4J). Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
📝 WalkthroughWalkthroughOAuth token refresh now classifies caller-resolvable failures, adds reconnect guidance, maps them to MCP caller errors, logs them as MCP failures, and filters them from Sentry. Provider HTTP 5xx failures remain ordinary errors and remain visible in Sentry. ChangesOAuth token refresh error flow
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant MCP as MCP integration capability
participant Refresh as refreshIntegrationTokens
participant Provider as OAuth provider
participant Observability as MCP observability
participant Sentry as Sentry filter
MCP->>Refresh: Request token refresh
Refresh->>Provider: Send refresh-token request
Provider-->>Refresh: Return success or HTTP error
Refresh-->>MCP: Return tokens or caller/server error
MCP->>Observability: Report refresh failure
Observability->>Sentry: Classify event
Sentry-->>Observability: Suppress caller error or retain server error
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 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 |
|
🔎 Preview deployed: https://kody-pr-1390.kody-a99.workers.dev Worker: Mocks:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/worker/src/integrations/token-refresh.ts`:
- Around line 33-41: The integrationTokenRefreshCallerPhrases list is missing
patterns for caller errors produced by the missing-integration,
invalid-token-URL, and missing-client-secret-name constructors. Add stable
phrases covering every IntegrationTokenRefreshCallerError message so
isIntegrationTokenRefreshCallerMessage and
filterIntegrationTokenRefreshCallerSentryEvent classify them correctly, then add
Sentry tests for those three missing cases.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 31e087d4-ead2-4fdc-a05c-0e0ca66ba650
📒 Files selected for processing (7)
packages/worker/src/integrations/token-refresh.node.test.tspackages/worker/src/integrations/token-refresh.tspackages/worker/src/mcp/capabilities/integrations/integration-token-refresh.tspackages/worker/src/mcp/observability.node.test.tspackages/worker/src/mcp/observability.tspackages/worker/src/sentry-options.node.test.tspackages/worker/src/sentry-options.ts
Address CodeRabbit: every IntegrationTokenRefreshCallerError now ends with a shared marker so isCallerFailure / beforeSend cover missing-integration, invalid token URL, and missing client-secret-name without over-matching unrelated Integration strings. Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Summary
Sentry KODY-CLOUDFLARE-4J grouped reconnectable OAuth refresh failures as platform bugs:
invalid_grant/ expired or revoked consent)integration_token_refreshThese are caller-clearable account/connection state, not Worker defects. This PR classifies them as
IntegrationTokenRefreshCallerError(every message ends with a shared(integration_token_refresh caller state)marker), re-wraps asMcpCallerErrorfromintegration_token_refresh, matches the marker inisCallerFailure, and adds abeforeSendbackstop. Messages include truncated providererror/error_descriptionand a/connect/oauth?provider=…reconnect path. Provider HTTP 5xx keeps the old "failed" wording (no marker) and still reports to Sentry.Merge note: CI green; left open for Kent — medium risk / OAuth auth surface. After squash-merge + deploy, resolve the Sentry issue in the merge commit.
Test plan
token-refresh.node.test.ts— missing refresh token → caller error; HTTP 400 → caller error with reconnect + marker; HTTP 503 → plain Error; host-approval → caller errorobservability.node.test.ts— refresh rejection message stays off Sentrysentry-options.node.test.ts— beforeSend drops marker messages (incl. missing integration / invalid URL / missing client-secret-name); keeps 5xx and unmarked Integration-not-foundnpm run validate(local) + CI ✅ Validate / Node / Workers / MCP / E2E / StaticSystem recap — extends existing primitives (medium risk)
Mode: recap · Base:
main@328a45d7· Head:a30f5e7eClassification: extends — changes how OAuth token-refresh failures are classified for MCP observability and Sentry; reconnectable 4xx / missing refresh-token state leaves issue reporting, while provider 5xx stays visible.
Primitives touched
integrationsIntegrationTokenRefreshCallerError+ shared marker for preconditions and provider 4xx; reconnect guidance in messagesmcp-serverisCallerFailurematches the token-refresh caller markersentry-optionsbeforeSendbackstop for the same markerSystem map
Token refresh failures flow from the integrations capability through MCP observability; this PR stops reconnectable cases from opening Sentry issues while keeping provider outages visible.
Legend: green = composes (wiring only) · amber = extended by this PR · red = new primitive · gray = context (unchanged, included only when an edge crosses it).
Invariants
Touches OAuth token refresh (auth/credentials path). No change to how tokens are materialized, exchanged, or persisted — only error classification and agent-facing guidance.
Summary by CodeRabbit