Skip to content

fix(billing): detect FK violations from error messages#173

Merged
g1331 merged 1 commit into
masterfrom
fix-billing-fk-message-detect
May 23, 2026
Merged

fix(billing): detect FK violations from error messages#173
g1331 merged 1 commit into
masterfrom
fix-billing-fk-message-detect

Conversation

@g1331
Copy link
Copy Markdown
Owner

@g1331 g1331 commented May 23, 2026

Summary

Fix billing snapshot FK retry detection when the deployed Postgres/Drizzle error only exposes the violated constraint in the error message text.

Related Issue

Follow-up to deploy smoke failure observed in run 26326869522.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (code improvement without changing functionality)
  • Tests (adding or updating tests)
  • Build/CI (changes to build system or CI configuration)

Changes

  • Parse violates foreign key constraint "..." from top-level and cause error messages when Postgres FK metadata fields are unavailable.
  • Keep the existing exact FK column mapping so only known api_key_id and upstream_id billing snapshot constraints are retried with NULL.
  • Add a regression test for the production-shaped wrapped error that only exposes the upstream FK constraint in message text.

Test Plan

  • Local tests pass (pnpm test:run tests/unit/services/billing-cost-service.test.ts)
  • Type check passes (pnpm exec tsc --noEmit)
  • Lint passes (eslint via commit hook)
  • Manual testing completed

Checklist

  • Code follows the project's coding standards
  • Tests have been added where necessary
  • Documentation has been updated (if applicable)
  • Changes do not introduce security vulnerabilities
  • Commit messages follow conventions

Screenshots

N/A

Additional Notes

The previous fix handled constraint_name and constraint fields, but the deployed error in run 26326869522 did not expose those fields to the application-level detector. The constraint name was still present in the error message text, so this patch uses that text as the final FK detection source.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 23, 2026

Codecov Report

❌ Patch coverage is 82.35294% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.66%. Comparing base (67c5607) to head (03a03f9).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #173   +/-   ##
=======================================
  Coverage   78.65%   78.66%           
=======================================
  Files         145      145           
  Lines       11521    11538   +17     
  Branches     3985     3992    +7     
=======================================
+ Hits         9062     9076   +14     
  Misses       1631     1631           
- Partials      828      831    +3     
Flag Coverage Δ *Carryforward flag
typescript 76.02% <ø> (ø) Carriedforward from 67c5607
verify 74.19% <82.35%> (+<0.01%) ⬆️

*This pull request uses carry forward flags. Click here to find out more.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@g1331 g1331 merged commit 9c3b6ef into master May 23, 2026
12 checks passed
@g1331 g1331 deleted the fix-billing-fk-message-detect branch May 23, 2026 07:47
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