Skip to content

fix(email): lengthen outbox claim timeout, log aborted claims, and harden prod DB detection (#273) - #305

Merged
JOY (JOY) merged 1 commit into
devfrom
antigravity/give-273-outbox-followups
Nov 22, 2026
Merged

JOY (JOY) merged 1 commit into
devfrom
antigravity/give-273-outbox-followups

Conversation

@JOY

@JOY JOY (JOY) commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

App portion (Phase 2) of email outbox follow-ups from the #254 second reviews (Phase 1 DB migration merged in DOS/DOS.Me#1870 at 0223503c0195725ef56c6618bd229a5af8707468).

Refs #273

Changes

  1. Item 5 — Aborted claim timeout & logging (apps/web/src/server/email/outbox.ts, outbox.test.ts):
    • Lengthens CLAIM_TIMEOUT_MS from 10_000 ms to 15_000 ms (safely above PostgREST's 8 s statement_timeout plus pooler/network jitter so a committing claim_outbox call is not aborted in flight, while remaining well under RUN_BUDGET_MS = 30 s).
    • Inspects both claimSignal.aborted and isAbortError(error) (excluding Postgres server-side rollback 57014) to emit an explicit error log noting that the DB transaction may still have committed and leased rows for 5 minutes — on both first and subsequent claim calls.
  2. Item 6 — Production Supabase host/environment guard (apps/web/src/server/email/provider.ts, provider.test.ts):
    • Hardens usesProductionDatabase(env) to inspect the JWT ref claim of SUPABASE_SERVICE_ROLE_KEY and NEXT_PUBLIC_SUPABASE_ANON_KEY in addition to PRODUCTION_SUPABASE_HOSTS / PRODUCTION_SUPABASE_REF, so an unlisted custom domain is still caught whenever legacy JWT keys are used (while cleanly ignoring opaque sb_secret_* keys and malformed tokens).
    • Decision against an in-DB environment marker: Production, Beta, and Supabase Preview branches replay the same committed DOS/DOS.Me migrations (and Preview inherits migrated rows), so an in-DB marker cannot safely distinguish Production from Preview/Beta without violating migration-only state.

Verification

  • pnpm format:check — PASS
  • pnpm lint — PASS
  • pnpm typecheck — PASS
  • pnpm test — PASS (180/180 files, 2622/2622 tests)
  • pnpm build — PASS

📌 TL;DR

This PR hardens the email outbox system by increasing the claim timeout to prevent race conditions with PostgREST and adding specific logging for aborted transactions. It also enhances production environment detection to identify the production database via JWT project references, preventing non-production deployments from accidentally connecting to production data.

🎯 Type of Change

  • 🚀 New feature
  • 🐛 Bugfix
  • 🧹 Refactor
  • ⚡ Performance
  • 📚 Documentation
  • ⚙️ CI / Configuration

🔍 Changes Walkthrough

File Summary of Changes
apps/web/src/server/email/outbox.ts Increased CLAIM_TIMEOUT_MS from 10s to 15s to exceed PostgREST's 8s statement timeout. Added isAbortError helper to distinguish client-side aborts (where DB may have committed) from server-side rollbacks. Updated error handling in sendDueEmails to log specific warnings for aborted claims.
apps/web/src/server/email/outbox.test.ts Added tests verifying the new 15s timeout constant, ensuring aborted claims log the "may have committed" warning, and confirming that server-side Postgres timeouts (57014) are logged as ordinary failures.
apps/web/src/server/email/provider.ts Added jwtProjectRef helper to extract the Supabase project reference from JWT keys. Updated usesProductionDatabase to check both the URL host and the JWT ref claim, ensuring production detection works even if a custom domain is used that isn't in the static host list.
apps/web/src/server/email/provider.test.ts Added tests for usesProductionDatabase to verify it correctly identifies production environments via JWT refs (service role and anon keys) and correctly ignores non-production or opaque keys.

📊 Architectural Flow

flowchart TD
    subgraph "Email Outbox Execution"
        A[sendDueEmails] --> B{Claim Timeout?}
        B -- Yes --> C[AbortSignal.timeout 15s]
        B -- No --> D[Normal RPC]
        C --> E{Error Occurred?}
        E -- Yes --> F{isAbortError?}
        F -- Yes --> G[Log: 'May have committed']
        F -- No --> H[Log: 'Claim failed']
        E -- No --> I[Process Rows]
    end

    subgraph "Environment Detection"
        J[usesProductionDatabase] --> K{Check URL Host}
        K -- Match --> L[Return True]
        K -- No Match --> M{Check JWT Refs}
        M --> N[jwtProjectRef Service Key]
        M --> O[jwtProjectRef Anon Key]
        N -- Match Prod Ref --> L
        O -- Match Prod Ref --> L
        N -- No Match --> P[Return False]
        O -- No Match --> P
    end
Loading

@claude claude 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.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@vercel

vercel Bot commented Nov 22, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
give Ready Ready Preview Nov 22, 2026 9:10am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c84c5c14-6962-4734-92e8-815a934a6118

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • 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

dos[bot]
dos Bot approved these changes Nov 22, 2026

@dos dos 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.

⏱️ Code Review completed (4 eligible files · 11,082 chars · 2 model call(s) · 1 PR unit(s))

Whole diff with bounded context at base c0202ef / head 02f03f1.

✅ CLEAN_PASS: Complete diff reviewed

Context investigation was bounded to the explicitly requested snapshot paths.

@JOY JOY (JOY) added line:platform Product line: platform po:agy Owned by Antigravity PO (mutual-exclusion parallel PO label) labels Nov 22, 2026
@JOY

Copy link
Copy Markdown
Contributor Author

PO acceptance: merge at 02f03f1

Verified on GitHub:

  • Required checks green: Verify build/Lint, Verify build/Build all apps (plus Vercel preview & DOScout green)
  • mergeStateStatus: CLEAN, 0 unresolved review threads; dos[bot] APPROVED
  • Two independent fresh-context reviews approved at 02f03f111ac989f4913476dfdbb33cfe18736bdf (zero blocking findings; 15s CLAIM_TIMEOUT_MS + abort logging without PII and safe base64url JWT ref detection verified).

@JOY
JOY (JOY) merged commit 6c69036 into dev Nov 22, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

line:platform Product line: platform po:agy Owned by Antigravity PO (mutual-exclusion parallel PO label)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant