Debugging
AuraScore 81/100

Double-Entry Ledger Reconciliation Drift and Race Condition Resolver

Automate database anomaly detection and journal audit scripts to isolate floating-point drift, idempotency collisions, and ledger imbalances.

Use this template when core banking systems or payment ledgers show balance discrepancies, out-of-order journal postings, or race conditions during multi-currency settlements. It generates a Python and SQL debugging script that audits transactions without locking production tables.

Template

Role: Staff FinTech Reliability Engineer specializing in distributed double-entry financial ledgers.

Context

  • Core Banking Engine: {{core_banking_engine}}
  • Discrepancy Timeframe: {{discrepancy_timeframe}}
  • Ledger Table Schema: {{ledger_table_schema}}
  • Settlement Currency Pairs: {{settlement_currency_pairs}}
  • Idempotency Store: {{idempotency_store_type}}
  • Maximum Permissible Drift: {{maximum_drift_tolerance}}

Task

Author an automated Python and SQL diagnostic script to isolate transaction race conditions, rounding drifts, and out-of-order event replay anomalies across distributed double-entry ledger partitions in {{core_banking_engine}}.

Method

  1. Query journal postings from {{ledger_table_schema}} over {{discrepancy_timeframe}} using read-committed non-blocking isolation.
  2. Calculate absolute debit-credit summation invariants per transaction across all currencies in {{settlement_currency_pairs}}.
  3. Detect rounding discrepancies exceeding {{maximum_drift_tolerance}} caused by floating-point arithmetic or foreign exchange conversions.
  4. Correlate ledger write timestamps with state transition records in {{idempotency_store_type}} to flag duplicate idempotency keys.
  5. Identify concurrent transaction interleaving where parent balance locks failed during high-concurrency payment ingestion.
  6. Trace unposted or pending settlement entries that caused dangling balance commitments.
  7. Generate deterministic SHA-256 state validation hashes for each audited account ledger branch.
  8. Emit parameterized, safe SQL compensating transaction scripts to balance isolated anomalous accounts.

Constraints

  • The script MUST operate in strictly read-only mode against database replicas and MUST NOT modify existing journal entries.
  • All balance computations in the Python script MUST use decimal fixed-point arithmetic instead of binary floating-point.
  • The script MUST handle pagination in batches to avoid high memory pressure or lock contention on database replicas.
  • Output SQL fixes MUST be formatted as atomic transactions with explicit balance pre-condition assertions.

Output format

  • Section 1: Execution Prerequisites and Database Permission Checklist.
  • Section 2: Complete Python Ledger Triage Script with embedded parameterized SQL queries (100-160 lines).
  • Section 3: Ledger Anomaly Report Structure detailing Account ID, Debit Sum, Credit Sum, Net Drift, and Culprit Transaction ID.
  • Section 4: Safe SQL Compensating Script Template with integrity assertions.

Self-review

  • Verify that {{core_banking_engine}}, {{discrepancy_timeframe}}, {{ledger_table_schema}}, {{settlement_currency_pairs}}, {{idempotency_store_type}}, and {{maximum_drift_tolerance}} are properly utilized.
  • Ensure no IEEE-754 float types are used in financial calculation paths.
  • Confirm that database queries avoid full table scans without index hints.
AuraScore breakdown
81/100Provisional
Instruction clarity15/15 · Strong

Explicit role, a named task, and discrete steps the model can follow.

Context architecture12/12 · Strong

Background, inputs and variables the model needs before it starts.

Constraint engineering12/12 · Strong

Hard boundaries — what the model must and must not do.

Output specification6/14 · Thin

A named, field-level shape for the response.

Reasoning structure10/10 · Strong

Ordered work items that force analysis before an answer.

Model compatibility10/10 · Strong

Length and structure that travel across frontier models.

Token efficiency5/10 · Thin

Signal density — instruction weight without padding.

Reusability7/7 · Strong

Documented variables so the scaffold adapts to new inputs.

Robustness3/5 · Adequate

Quality bar, assumptions and behaviour when inputs are thin.

Observed performance1/5 · Thin

How much real usage the template has behind it.

developers
developers-debugging
financial-services
ledger-reconciliation
fintech
database-debugging