fix: PR A — concurrency + money bugs (round 4, bugs 1-4)#78
Merged
Conversation
Bug 1 (CRITICAL): payment capture/refund/void race - Conditional UPDATE-by-status claims the row atomically - Stripe idempotency keys (cap_/ref_/void_) prevent gateway double-charge - Two-phase pattern: short tx claims state, network call outside, tx finalizes Bug 2 (HIGH): folio.transferCharge non-atomic - Wrapped in db.transaction, both folios locked FOR UPDATE in id-order - Helpers accept optional tx; recalculateBalance uses decimal.js (no parseFloat) Bug 3 (HIGH): transferToCityLedger non-atomic - All 4 steps wrapped in db.transaction - Monetary comparisons use decimal.js on string representations Bug 4 (HIGH): night audit concurrent execution - Unique index on (property_id, business_date) - onConflictDoNothing + re-select: completed → ConflictException, running → return as active audit All financial math now uses decimal.js on Drizzle's string numerics. No parseFloat on monetary values. 552/552 tests passing, build + typecheck clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
First of 4 PRs from round-4 codex review. Covers the concurrency + money class of bugs.
Monetary math policy
All financial arithmetic now uses `decimal.js` on Drizzle's string numeric representations. No `parseFloat` on money values. `recalculateBalance` is the first method migrated — the rest follow in PR D.
Test plan
Still pending from round 4
🤖 Generated with Claude Code