bug: atomic compensation + consistent settlement rounding in RFQ execution saga (COG-GTM Execution Saga)#22
Open
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Root cause: on credit-check failure the saga deducts bond notional but never compensates the in-flight bond.deductNotional() mutation, leaving the bond's available notional understated whenever the saga's @transactional joins an outer/shared persistence context (the production scenario). Settlement amounts were also persisted without a consistent rounding policy, producing off-by-a-cent values. Fix: explicitly compensate (bond.addNotional) when deductCredit throws InsufficientCreditException, and normalize the settlement amount to currency scale (2dp, HALF_EVEN) before deducting credit and persisting. Adds JUnit 5 coverage: credit-fail rollback, notional-fail no-op, successful debit, and HALF_EVEN rounding boundary cases. Co-Authored-By: Achal Channarasappa <achal.channarasappa@cognition.ai>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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
Fixes a bug where a counterparty credit-check failure mid-saga left the bond's available notional understated, and a separate inconsistent-rounding bug in settlement math.
Root cause (compensation).
RFQExecutionSaga.executeRfqdeducts bond notional, then deducts counterparty credit. WhendeductCreditthrowsInsufficientCreditException, the saga relied solely on@Transactionalrollback and never reversed the in-flightbond.deductNotional(...)mutation. When the saga's@Transactionaljoins an outer/shared persistence context (the production path), the managedBondis left dirty with the deduction, so the bond'savailableNotionalstays reduced and subsequent quotes are wrongly rejected. The old code comment ("No need for saga compensation…") was incorrect.Root cause (rounding).
executionPricewas persisted and debited verbatim, with no currency-scale normalization → off-by-a-cent settlement values.Fix:
Change is scoped to
RFQExecutionSaga; no unrelated refactors.Reproduction & verification
Added a failing repro first (
creditCheckFailure_rollsBackBondNotionalDeduction): before the fix it observedavailableNotionalunderstated by the trade notional (50000000.00 → 49000000.00) after the credit check failed. It now passes.New JUnit 5 tests in
RFQExecutionSagaTest:.005→.00,.015→.02,.025→.02)Test output
(
mvn test, Java 11)Link to Devin session: https://app.devin.ai/sessions/78af6ddcdc804c8088d3d9a1e22b213a
Requested by: @achalc
Devin Review