feat(db): concurrency and race safety in src/db/ - #1297
Merged
Baskarayelu merged 1 commit intoAug 30, 2026
Merged
Conversation
Serialization/conflict behavior, retry contracts, deterministic test coverage, and operational signals. Changes: - retry.ts: add PG 55P03 (lock_timeout) to isRetryableError() so the retry loop exhausts attempts before surfacing ConflictError with conflictCode='lock_timeout', matching the same contract as serialization failures and deadlocks. - retry.ts: ConflictError (with retryAfterSeconds, attempts, conflictCode) thrown after retry exhaustion for all concurrency conflicts; MaxRetriesExhaustedError only for non-conflict exhaustion. - transaction.ts: TransactionManager with configurable LockTimeoutPolicy, post-commit hooks (cache invalidation, metrics), rollback hooks (compensating actions), AsyncLocalStorage context propagation, transaction budget (duration + savepoints), and RLS tenant_id injection. - settlementsRepository.ts: atomic xmax-based upsert (eliminates TOCTOU SELECT+INSERT race), TransactionManager.withTransaction for upsertBatch atomicity. - concurrency.test.ts: 26 deterministic unit tests covering parallel writes, contention, retry-after-conflict, partial-state invariants, post/rollback hook isolation, and cache invalidation deferral. - docs/DB_CONCURRENCY.md: design, invariants, failure behavior, compatibility impact, migration/rollback, operational limitations, and security assumptions. Closes #<issue>
|
@samuel22x Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Closed
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Serialization/conflict behavior, retry contracts, deterministic test coverage, and operational signals.
Changes:
Closes #1275