Skip to content

fix(auth): retry initial OAuth resource connection - #597

Merged
imshashank merged 2 commits into
mainfrom
codex/fix-oauth-startup-timeouts
Nov 17, 2026
Merged

imshashank merged 2 commits into
mainfrom
codex/fix-oauth-startup-timeouts

Conversation

@imshashank

Copy link
Copy Markdown
Contributor

The initial OAuth resource SELECT can fail with CONNECT_TIMEOUT before the connection is established. Retry that exact resource-identifier lookup once outside a transaction, so a cold connection failure can recover during auth startup.

The retry requires matching CONNECT_TIMEOUT code and errno values and preserves the existing adapter behavior for other reads and transaction phases.

Validation:

  • 47 focused connection and resource-adapter controls passed.
  • The original 67 actual Node24 auth journeys passed on commit44494251. Their executed bundle is byte-identical after current-main integration; no new Node67 execution is claimed for this head.
  • Canonical local verification at 72e67e2: 7,478 passed, 0 failed, 0 skipped, actual exit0. Final Bun/Node checks verified all eight owned database identities, 42 migrations, canonical catalog and idle connections.
  • Fresh public CI and ordinary preview are pending.

No schema migration is required.

@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds a guarded, single retry for initial database connection timeouts. It applies the retry only to exact OAuth resource lookups outside adapter transactions and wraps the Drizzle adapter during Better Auth setup.

Changes: OAuth Resource Connection Retry

Layer / File(s) Summary
Recognize and retry initial connection timeouts
packages/db/src/connection-retry.ts, packages/db/src/index.ts, packages/db/tests/connection-retry.test.ts
Adds and exports a helper that recognizes eligible connection timeouts and retries an operation once when the retry phase is active. Tests cover error inspection, retry conditions, and separate retry budgets for concurrent calls.
Scope retries to OAuth resource lookups
apps/web/src/lib/auth/resource-adapter.ts, apps/web/tests/lib/auth/resource-adapter.test.ts
Adds an adapter wrapper that retries only matching resource reads outside transactions. Tests cover excluded query shapes, mutations, transactions, and concurrent reads.
Apply the wrapper during Better Auth setup
apps/web/src/lib/auth/server.ts, apps/web/tests/lib/auth/resource-adapter.test.ts
Wraps the Drizzle adapter with the resource URL. Tests cover initialization with a configured resource model, adapter schema checks, and behavior without an OAuth provider.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant BetterAuth
  participant withOAuthResourceConnectionRetry
  participant retryInitialDatabaseConnection
  participant DBAdapter
  BetterAuth->>withOAuthResourceConnectionRetry: findOne with the configured resource query
  withOAuthResourceConnectionRetry->>retryInitialDatabaseConnection: run matching read outside a transaction
  retryInitialDatabaseConnection->>DBAdapter: findOne
  DBAdapter-->>retryInitialDatabaseConnection: timeout or result
  retryInitialDatabaseConnection->>DBAdapter: retry once if retry conditions still hold
  DBAdapter-->>retryInitialDatabaseConnection: result
  retryInitialDatabaseConnection-->>withOAuthResourceConnectionRetry: return result
  withOAuthResourceConnectionRetry-->>BetterAuth: return result
Loading
Merge Risk: Minimal · up to 72e67

The change adds a narrow, single retry for the initial OAuth resource lookup when the database connection times out. Other reads, writes and transactions keep their existing behavior. No actionable merge-blocking risk was found. Confirm that public CI passes before merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix and its scope: retrying the initial OAuth resource connection in auth. The changeset adds a retry wrapper for the OAuth resource lookup and a connection-retry helper, so the ti…
Description check Passed The description states the purpose: the initial OAuth resource SELECT can fail with CONNECT_TIMEOUT, and the change retries that exact lookup once outside a transaction. It also names the matching cod…
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: Title check

Explanation

The title names the fix and its scope: retrying the initial OAuth resource connection in auth. The changeset adds a retry wrapper for the OAuth resource lookup and a connection-retry helper, so the title matches the main change. It uses the conventional commit prefix and is specific.

Full details: Description check

Explanation

The description states the purpose: the initial OAuth resource SELECT can fail with CONNECT_TIMEOUT, and the change retries that exact lookup once outside a transaction. It also names the matching code and errno checks, which the changeset implements. It includes validation notes. The description is specific to this changeset.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Noveum/orbit
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: d1b1545
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e1861466-d50b-4c14-aaa1-b27c08b7bbea
Commits

Reviewing files that changed from the base of the PR and between d1b1545 and 72e67e2.

Files selected for processing: 6

  • apps/web/src/lib/auth/resource-adapter.ts
  • apps/web/src/lib/auth/server.ts
  • apps/web/tests/lib/auth/resource-adapter.test.ts
  • packages/db/src/connection-retry.ts
  • packages/db/src/index.ts
  • packages/db/tests/connection-retry.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@github-actions github-actions Bot added tests Test coverage and test infrastructure area: web The Next.js app and its UI area: database Schema, migrations, queries, seed area: auth Sign-in, sessions, passkeys, OAuth labels Nov 17, 2026
@imshashank
imshashank marked this pull request as ready for review November 17, 2026 15:01
@imshashank
imshashank requested a review from pulkitxm as a code owner November 17, 2026 15:01
@vercel

vercel Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
orbit Canceled Canceled Nov 17, 2026 3:16pm UTC

Request Review

@imshashank
imshashank merged commit 5bb2b44 into main Nov 17, 2026
16 of 17 checks passed
@imshashank
imshashank deleted the codex/fix-oauth-startup-timeouts branch November 17, 2026 15:16

This branch was previously deployed

1 inactive deployment
Preview — 72e67e26 Deployed Nov 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: auth Sign-in, sessions, passkeys, OAuth area: database Schema, migrations, queries, seed area: web The Next.js app and its UI tests Test coverage and test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant