Skip to content

fix(sentry): stop reporting D1 network connection lost blips - #952

Merged
kody-bot merged 2 commits into
mainfrom
cursor/sentry-triage-7633338189-10bb
Jul 26, 2026
Merged

kody-bot merged 2 commits into
mainfrom
cursor/sentry-triage-7633338189-10bb

Conversation

@kentcdodds

@kentcdodds kentcdodds commented Jul 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Filters Sentry noise from issue 7633338189 (Error: D1_ERROR: Network connection lost.).

One production event on admin_user_usage (mcp.failure_phase=handler) failed inside readEntitlementResourceUsage → countRunningPackageServices → countRows when the D1 binding dropped mid-query (D1DatabaseSessionAlwaysPrimary._sendOrThrow). This is transient Cloudflare D1 transport unavailability, not an application bug — the same class already handled for SQLITE_BUSY and long-running export blocks (#930).

This PR extends the existing retryable-D1 matcher so:

  1. runD1WithRetry / cron lane skip / module-artifact transient detection treat "Network connection lost" like lock contention
  2. beforeSend (filterRetryableD1LockSentryEvent) drops matching events so binding blips do not open or regress Sentry issues

The matcher accepts only the exact D1 phrase with optional Error: / D1_ERROR: prefixes, so unrelated "Network connection lost while …" messages stay retryable/Sentry-visible.

MCP requests can still fail for the caller when D1 drops the session before a retry wrapper covers that path. We stop treating that as a platform defect in Sentry.

Siblings (client updateCurrentEntry, sandbox timeout, search validation) do not share this root cause and are left alone.

Test plan

  • d1-retry.node.test.ts matches exact D1 network-loss forms; rejects "Network connection lost while uploading..."; retries exact network errors; still rethrows syntax errors immediately
  • sentry-options.node.test.ts drops both exact message forms, keeps unrelated network-loss wording and other D1 errors
  • Local npm run validate green
  • CI npm run validate green
System recap — composes existing primitives (low risk)

Mode: recap · Base: main @ 7f6f85c2 · Head: c70a5d88

Classification: composes — narrow extension of the existing D1 transient matcher + Sentry beforeSend filter; no D1 schema, auth, or backup export contract changes.

Primitives touched

Primitive Group Impact
(unmatched) d1-retry.ts / sentry-options.ts observability composes — treat exact D1 "Network connection lost" like SQLITE_BUSY for retry + Sentry drop

System map

Transient D1 binding drops still fail uncovered queries; Sentry and retry paths no longer treat that blip as a novel platform failure.

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
	d1Retry["d1-retry<br/>Transient D1 matcher"]:::touched
	sentryOpts["sentry-options<br/>beforeSend filters"]:::touched
	d1AppDb["d1-app-db<br/>D1 app database"]:::untouched
	d1AppDb -->|"Network connection lost"| d1Retry
	d1Retry -->|"isRetryableD1LockSentryEvent"| 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
Open in Web Open in Cursor 

Summary by CodeRabbit

  • Bug Fixes

    • Improved resilience to transient database transport drops by automatically retrying operations when the error indicates a “Network connection lost”.
    • Ensured expected transient connection-loss messages don’t surface as reported application errors.
  • Tests

    • Expanded retry coverage for “Network connection lost” variants and added assertions that retries occur exactly once when the first attempt fails.
  • Documentation

    • Updated guidance to include transport “Network connection lost” scenarios and the resulting app/session loss behavior during mid-query drops.

Treat Cloudflare D1 "Network connection lost" like SQLITE_BUSY / long-running
export: retry via runD1WithRetry and drop matching beforeSend events so
transient binding drops do not open or regress Sentry issues.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@coderabbitai

coderabbitai Bot commented Jul 26, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds “Network connection lost” as a retryable D1 error, verifies one retry succeeds, and tests that matching Sentry events are filtered. Related retry documentation and comments are updated.

Changes

D1 network retry handling

Layer / File(s) Summary
Retryable network error support
packages/worker/src/d1-retry.ts, packages/worker/src/d1-retry.node.test.ts
Adds the exported network-loss message, recognizes D1-prefixed and plain forms, documents the behavior, and verifies retry success after one failure.
Sentry network-error coverage
packages/worker/src/sentry-options.ts, packages/worker/src/sentry-options.node.test.ts
Tests filtering for plain and D1-prefixed network-loss events, preserves unrelated network errors, and rewraps the related explanatory comment.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: suppressing D1 network-connection-lost blips in Sentry and related retry handling.
✨ Finishing Touches
📝 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-7633338189-10bb

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.

@kody-bot
kody-bot marked this pull request as ready for review July 26, 2026 00:00
@github-actions

github-actions Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

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

Worker: kody-pr-952
D1: kody-pr-952-db
KV: kody-pr-952-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/d1-retry.ts`:
- Around line 28-34: Update isRetryableD1LockMessage to recognize only the exact
Cloudflare network-loss forms: “Network connection lost.” with an optional
“D1_ERROR:” prefix, while preserving the existing lock and export-message
matches. Add a regression test covering “Network connection lost while
uploading...” and verify it remains non-retryable and unsuppressed.
🪄 Autofix (Beta)

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: 3e5b1c33-9212-4cdf-a471-34b98c0974d0

📥 Commits

Reviewing files that changed from the base of the PR and between 7f6f85c and f7e7149.

📒 Files selected for processing (4)
  • packages/worker/src/d1-retry.node.test.ts
  • packages/worker/src/d1-retry.ts
  • packages/worker/src/sentry-options.node.test.ts
  • packages/worker/src/sentry-options.ts

Comment thread packages/worker/src/d1-retry.ts Resolved
Avoid retrying or dropping unrelated "Network connection lost while …"
messages; only accept the bare D1 phrase with optional Error:/D1_ERROR:
prefixes. Format the retry unit test for CI format:check.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
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.

3 participants