fix: settlement & reconciliation engine — eliminate in-memory state, add middleware integration#50
Merged
devin-ai-integration[bot] merged 1 commit intoJul 6, 2026
Conversation
Contributor
Author
Original prompt from Patrick
|
Contributor
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:
|
Contributor
Author
Test Results — Settlement & Reconciliation Engine (PR #50)All 14 tests passed. Testing approval: User clicked "Test the app" Persistence Elimination
Middleware Integration
TypeScript Settlement Fixes
Infrastructure
Regression
EscalationRuntime PostgreSQL read/write not tested (no DATABASE_URL in session). All validation is structural. |
…add middleware integration 12 gaps fixed across Go, Rust, Python, and TypeScript: Go settlement-batch-processor: - Replaced map[string]*SettlementBatch with PostgreSQL (settlement_batches table) - Query real agent data from DB instead of hardcoded 10-agent loop - Added Mojaloop interbank settlement notifications - Middleware: Kafka, Dapr, Fluvio, Lakehouse, TigerBeetle, OpenSearch, Mojaloop (all async, fail-open) Go revenue-reconciler: - Replaced []ReconciliationReport and []DiscrepancyAlert with PostgreSQL - Query actual metrics from transactions table instead of hardcoded stubs - Query projected metrics from billing_projections instead of stubs - Middleware: Kafka, Dapr, Lakehouse, OpenSearch (all async, fail-open) Rust fund-flow-settlement: - Replaced RwLock<HashMap> (fx_rates + schedules) with PgPool + sqlx - All FX rates, schedules, reconciliation results persisted to PostgreSQL - Settlement batches persisted to settlement_batches_rust table TypeScript posBatchSettlement: - Added FOR UPDATE locking on processBatch + failBatch queries - Wired publishPosMiddleware into createBatch, processBatch, failBatch, reconcileBatch TypeScript transactionReconciliation: - Added 3 mutation handlers: updateStatus, markDisputed, markResolved - Each uses enforceTransition for valid status flow - Publishes to Kafka (transaction.reconciliation topic) TypeScript temporalSagaOrchestrator: - Added startSettlementSaga (4-step: create → process → settle → reconcile) - Each step has compensating action for rollback Python OpenSearch indexer: - Added settlement/reconciliation indexing pipeline (4 new endpoints) - SETTLEMENT_MAPPING + RECONCILIATION_MAPPING with proper field types Migration: 0046_settlement_reconciliation.sql (10 tables) Kafka: 8 new settlement/reconciliation topics 0 new server TS errors, 4,247 tests pass, 0 new test failures. Co-Authored-By: Patrick Munis <pmunis@gmail.com>
feffe3a to
57603ae
Compare
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 12 gaps in the settlement and reconciliation engine across all 4 polyglot services. Core issue: Go, Rust, and TypeScript services stored settlement/reconciliation state in-memory (maps, slices,
RwLock<HashMap>) — all lost on restart. Now 100% PostgreSQL-persisted with full middleware integration.Go settlement-batch-processor (port 9211)
Also: queries real agent data from
agentstable instead of hardcoded 10-agent loop; Mojaloop/settlementsnotifications on batch completion.Go revenue-reconciler (port 9101)
Rust fund-flow-settlement (port 8251)
All FX rate lookups, schedule storage, and reconciliation results now go through PostgreSQL queries.
TypeScript posBatchSettlement
FOR UPDATElocking onprocessBatchandfailBatchqueries (race condition prevention)publishPosMiddleware()intocreateBatch,processBatch,failBatch,reconcileBatch(was dead code)TypeScript transactionReconciliation
updateStatus,markDisputed,markResolvedenforceTransition()for valid status flow + publishes to Kafkatransaction.reconciliationtopicTypeScript temporalSagaOrchestrator
startSettlementSaga— 4-step saga: create_batch → process_transactions → settle_batch → reconcile_batchPython OpenSearch indexer
POST /index/settlements,POST /index/reconciliations,POST /create-settlement-index,POST /create-reconciliation-indexSETTLEMENT_MAPPINGandRECONCILIATION_MAPPINGwith proper field typesMigration & Kafka
0046_settlement_reconciliation.sql: 10 tables with indexessettlement.batch.{created,settled,failed,reconciled},settlement.saga,reconciliation.{completed,discrepancy},transaction.reconciliationVerification: 0 new server TS errors, 4,247 tests pass, 0 new failures.
Link to Devin session: https://app.devin.ai/sessions/3ebd42bf0430422a9a2bd85ed9f9cd4c
Requested by: @munisp