Skip to content

fix(mcp): keep OAuth token-refresh caller state out of Sentry (KODY-CLOUDFLARE-4J) - #1390

Merged
kentcdodds merged 2 commits into
mainfrom
cursor/sentry-triage-kody-cloudflare-kody-cloudflare-4j-04a3
Aug 11, 2026
Merged

kentcdodds merged 2 commits into
mainfrom
cursor/sentry-triage-kody-cloudflare-kody-cloudflare-4j-04a3

Conversation

@kentcdodds

@kentcdodds kentcdodds commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

Summary

Sentry KODY-CLOUDFLARE-4J grouped reconnectable OAuth refresh failures as platform bugs:

  • Google refresh rejected with HTTP 400 (invalid_grant / expired or revoked consent)
  • Connections without a refresh token (e.g. GitHub, LinkedIn) when something still calls integration_token_refresh

These 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 as McpCallerError from integration_token_refresh, matches the marker in isCallerFailure, and adds a beforeSend backstop. Messages include truncated provider error / error_description and 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 error
  • observability.node.test.ts — refresh rejection message stays off Sentry
  • sentry-options.node.test.ts — beforeSend drops marker messages (incl. missing integration / invalid URL / missing client-secret-name); keeps 5xx and unmarked Integration-not-found
  • npm run validate (local) + CI ✅ Validate / Node / Workers / MCP / E2E / Static
System recap — extends existing primitives (medium risk)

Mode: recap · Base: main @ 328a45d7 · Head: a30f5e7e

Classification: 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

Primitive Group Impact
integrations assistant extends — IntegrationTokenRefreshCallerError + shared marker for preconditions and provider 4xx; reconnect guidance in messages
mcp-server surfaces extends — isCallerFailure matches the token-refresh caller marker
(unmatched) sentry-options — composes — beforeSend backstop for the same marker

System 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).

flowchart LR
	integrations["integrations<br/>OAuth integrations"]:::extended
	mcpServer["mcp-server<br/>MCP endpoint"]:::extended
	sentryOpts["sentry-options<br/>beforeSend filters"]:::touched
	integrations -->|"caller 4xx / missing refresh token"| mcpServer
	mcpServer -->|"isCallerFailure skip"| sentryOpts
	integrations -->|"marker phrase backstop"| sentryOpts
	classDef touched fill:#1a7f37,color:#fff
	classDef extended fill:#9a6700,color:#fff
	classDef added fill:#cf222e,color:#fff
	classDef untouched fill:#57606a,color:#fff
Loading

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.

Open in Web Open in Cursor 

Summary by CodeRabbit

  • Bug Fixes
    • Improved OAuth token refresh error handling with clearer reconnect guidance.
    • Provider 4xx responses now include actionable error details.
    • Malformed token responses are reported as caller-resolvable errors.
    • Provider 5xx failures continue to be surfaced for monitoring and investigation.
    • Caller-resolvable refresh failures are excluded from Sentry while remaining available in application event logs.

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>
@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

OAuth 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.

Changes

OAuth token refresh error flow

Layer / File(s) Summary
Token refresh error classification
packages/worker/src/integrations/token-refresh.ts, packages/worker/src/integrations/token-refresh.node.test.ts
Adds IntegrationTokenRefreshCallerError, stable message matching, reconnect URLs, provider error details, and tests for HTTP 4xx caller errors and HTTP 5xx errors.
MCP caller-error mapping and observability
packages/worker/src/mcp/capabilities/integrations/integration-token-refresh.ts, packages/worker/src/mcp/observability.ts, packages/worker/src/mcp/observability.node.test.ts
Maps caller-resolvable refresh failures to McpCallerError and records them without Sentry reporting.
Sentry filtering
packages/worker/src/sentry-options.ts, packages/worker/src/sentry-options.node.test.ts
Filters OAuth token-refresh caller errors while retaining provider HTTP 5xx events. Tests cover the filtering behavior.

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
Loading

Possibly related PRs

  • kentcdodds/kody#1303: Directly overlaps with the token refresh implementation and tests.
  • kentcdodds/kody#1302: Modifies MCP observability and Sentry filtering for expected caller failures.
  • kentcdodds/kody#1203: Uses McpCallerError classification to keep agent-fixable integration errors out of Sentry.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the main change: excluding OAuth token-refresh caller state from Sentry.
Description check ✅ Passed The description provides the intent, change summary, testing details, risk, and system impact in sufficient detail.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/sentry-triage-kody-cloudflare-kody-cloudflare-4j-04a3

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kentcdodds
kentcdodds marked this pull request as ready for review August 11, 2026 16:06
@github-actions

github-actions Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

🔎 Preview deployed: https://kody-pr-1390.kody-a99.workers.dev

Worker: kody-pr-1390
D1: kody-pr-1390-db
KV: kody-pr-1390-oauth-kv

Mocks:

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 328a45d and b4c39db.

📒 Files selected for processing (7)
  • packages/worker/src/integrations/token-refresh.node.test.ts
  • packages/worker/src/integrations/token-refresh.ts
  • packages/worker/src/mcp/capabilities/integrations/integration-token-refresh.ts
  • packages/worker/src/mcp/observability.node.test.ts
  • packages/worker/src/mcp/observability.ts
  • packages/worker/src/sentry-options.node.test.ts
  • packages/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>
@kentcdodds
kentcdodds merged commit 43275c5 into main Aug 11, 2026
10 checks passed
@kentcdodds
kentcdodds deleted the cursor/sentry-triage-kody-cloudflare-kody-cloudflare-4j-04a3 branch August 11, 2026 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants