Skip to content

feat(database): add an infrastructure-error classifier and read-retry helper - #4863

Open
d-cs wants to merge 1 commit into
mainfrom
tri-13553-infra-retry-util
Open

feat(database): add an infrastructure-error classifier and read-retry helper#4863
d-cs wants to merge 1 commit into
mainfrom
tri-13553-infra-retry-util

Conversation

@d-cs

@d-cs d-cs commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds two shared primitives to @internal/database for surviving brief database connection blips: a classifier that recognises connectivity/infrastructure failures (as opposed to real query errors), and withInfraRetry, a helper that retries an operation on those failures.

Details

isInfrastructureError / looksLikeConnectivityError recognise connection-level failures (unreachable server, closed connection, connection reset, connect timeouts) and deliberately do not match query or validation errors, so retries never mask a real bug.

withInfraRetry(run, config) retries run on a classified infrastructure error with jittered backoff, gated by a shared token-bucket budget so a mass freeze cannot amplify into a retry storm. It has an enabled kill-switch (off by default) and reuses the existing retry-budget primitive.

It must only wrap operations that are safe to run more than once (reads, or writes made idempotent); it deliberately provides no path that silently retries a non-idempotent write.

@changeset-bot

changeset-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 8dbc68b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@d-cs d-cs self-assigned this Sep 1, 2026
@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

The database package adds Prisma and connectivity-error classification. It adds withInfraRetry with configurable attempts, jittered backoff, retry budgets, injected timing, and callbacks. Tests cover classification, retry behavior, budget limits, default classification, attempt limits, and delay calculation. The package index re-exports both new modules.

Merge Risk: 🔵 Low · up to e77d8

The PR adds an opt-in database retry helper and classifier, with retries disabled by default. It is mergeable with explicit owner awareness: non-finite randomness should be normalized, and callers must use only repeat-safe operations with a shared retry budget to avoid duplicated effects or increased database load during outages.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description accurately explains the implementation and intended use, but it does not follow the repository template. It omits the issue reference, checklist, testing section, changelog, and screen… Add the required template sections. Include the issue reference, completed checklist items, specific testing steps and results, a short changelog entry, and the screenshots section or an explicit indication that screenshots are not applicab…
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main changes: an infrastructure-error classifier and a database retry helper. It is concise and follows the stated convention.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 5 files.
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.
Full details: Description check

Explanation

The description accurately explains the implementation and intended use, but it does not follow the repository template. It omits the issue reference, checklist, testing section, changelog, and screenshots section.

Resolution

Add the required template sections. Include the issue reference, completed checklist items, specific testing steps and results, a short changelog entry, and the screenshots section or an explicit indication that screenshots are not applicable.

✨ 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 tri-13553-infra-retry-util

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.

coderabbitai[bot]

This comment was marked as resolved.

@d-cs
d-cs force-pushed the tri-13553-infra-retry-util branch 2 times, most recently from e35afcf to f4f22da Compare September 2, 2026 08:34
coderabbitai[bot]

This comment was marked as resolved.

@d-cs
d-cs force-pushed the tri-13553-infra-retry-util branch from f4f22da to 0436e22 Compare September 2, 2026 11:10
coderabbitai[bot]

This comment was marked as resolved.

@d-cs
d-cs force-pushed the tri-13553-infra-retry-util branch from 0436e22 to e77d850 Compare September 2, 2026 12:21
coderabbitai[bot]

This comment was marked as resolved.

Adds a shared classifier (isInfrastructureError / looksLikeConnectivityError)
recognising connection-blip failures (P1001/P1002/P1008/P1017, ECONNRESET,
"connection terminated", "server has closed the connection"), and
withInfraRetry — a retry helper gated by an enabled kill-switch (default off)
and the existing TokenBucketRetryBudget.

Only for operations safe to run more than once (reads, or writes made
idempotent); it never authorises retrying a bare non-idempotent write.

TRI-13553
@d-cs
d-cs force-pushed the tri-13553-infra-retry-util branch from e77d850 to 8dbc68b Compare September 2, 2026 12:49
@d-cs
d-cs marked this pull request as ready for review September 2, 2026 13:01

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

Devin Review

Comment on lines +35 to +39
error instanceof Prisma.PrismaClientInitializationError ||
error instanceof Prisma.PrismaClientRustPanicError ||
error instanceof Prisma.PrismaClientUnknownRequestError
) {
return true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Permanent failures consume retry budget

Invalid configuration and unknown query failures pass isInfrastructureError unconditionally. withInfraRetry repeats them, delaying errors and draining retries needed for connection blips.

Prompt for agents
Narrow the default retry classification in internal-packages/database/src/infraError.ts. PrismaClientInitializationError can represent persistent configuration, authentication, or database-selection failures, and PrismaClientUnknownRequestError can represent non-connectivity query-engine failures. Do not classify these classes unconditionally for retry. Inspect available error codes/messages for known transient connectivity cases, or split the broad infrastructure classifier from a narrower transient/retryable classifier and make withInfraRetry use the latter. Add negative tests for persistent initialization and unknown request errors.
Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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.

1 participant