2.15 Reconciliation (Internal, External, Offline): Exit Evidence
Evidence · Step: 2.15 Reconciliation (Internal, External, Offline)
| Step | 2.15 Reconciliation (Internal, External, Offline) |
| Date | 2026-11-17 |
| Database | PostgreSQL 18.6 (postgres:18-alpine) in Docker Desktop on Windows 11 |
| Decision | ADR-0020 |
| Result | Passed. Every planted break is detected and classified, with zero false matches, in the tests, the property test and at a million items. The daily process is a runbook |
Deliverables
Section titled “Deliverables”| Deliverable | Where |
|---|---|
| The reconciliation module | crates/engine/src/recon/: the statement reader (statement.rs), the matcher (matching.rs, pure), import, the external run and the breaks (store.rs), the cache comparison (cache.rs), the offline checks (offline.rs) |
recon_runs, recon_items, recon_breaks |
Migration 0014, with append-only guards, one open break per subject, and vouchers.reported_last_counter (db-schema.md) |
| Statement import | Mezgeb’s CSV layout and a TOML mapping per bank (statement-format.md); mezgeb-cli recon import |
| Matching engine | Exact by bank_ref, then the rule (amount, payment_ref, date within 3 days, one candidate on each side); mezgeb-cli recon run |
| Cache reconciliation endpoint | POST /v1/reconciliation/balances, each balance compared at the posting sequence the cache reflects |
| Resolution through suspense templates only | bank_debit_unmatched.v1 and bank_debit_resolve.v1 into the new 9040 (E32–E35), with deposit_unmatched.v1 and suspense_resolve.v1; POST /v1/reconciliation/breaks/{id}/resolve checks the entry |
| Operator tools | mezgeb-cli recon offline, recon breaks; GET /v1/reconciliation/breaks, …/runs; POST …/explain |
| Runbook (exit gate) | docs/runbooks/reconciliation.md |
Decisions made in this step
Section titled “Decisions made in this step”- The statement format. The partner bank’s format was still an open research item. With the maintainer, Mezgeb reads one generic CSV layout, and each bank’s export through a mapping file: it works with any bank and keeps Mezgeb independent of one. ISO 20022 camt.053 can be added as a second reader without changing the matching.
- Money breaks are resolved through suspense, both ways. The bank can have more than the ledger (9010, as in step 2.02) or less: for the second there was no account, so 9040 Suspense: unexplained bank debits is new. 5020 Bank charges becomes active, as the cause a 9040 item most often closes to.
- A line repeated with the same bank ID is not a break. It is the same
bank transaction printed twice and is skipped, as a re-import is.
duplicate_statement_lineis a line with its own ID that repeats another’s date, amount and reference, which can be real money.
Testing requirements
Section titled “Testing requirements”| Requirement | Test | Result |
|---|---|---|
| Planted mismatches (missing statement line, amount mismatch, duplicate statement line, stale cache) are each detected and classified | every_planted_break_is_found_and_resolved_by_suspense_entries and a_stale_cache_is_a_break_until_it_agrees (crates/engine/tests/reconciliation.rs); the property test every_planted_break_is_found_and_nothing_is_falsely_matched (recon/matching.rs) |
Each found, of its kind; the property test passed 5,000 cases |
| Resolution posts entries; it never edits | The same test resolves each money break with a suspense entry and reconciles clean afterwards; reconciliation_history_cannot_change shows no role, not even the owner, can change a run, a statement line or a closed break (MZ001), and the service cannot delete one |
Passed |
| Reconciling 1M items completes and its runtime is recorded | mezgeb-bench --recon 1000000 (below) |
1,000,100 items in 96.5 s; every run records its runtime in recon_runs.runtime_micros |
Also tested:
- The offline reconciliation (
crates/engine/tests/reconciliation_offline.rs): a clean voucher life has no break; counters a device reported but nobody uploaded become amissing_receiptsbreak only once the voucher has ended, and the break clears when the receipt arrives, even refused; a device that reports less than it signed is acounter_behindbreak. - Against the offline simulator. Every simulation lane against
PostgreSQL now ends with the offline reconciliation, and fails on any
receipt_entry_mismatchorescrow_mismatch: a 20,000-operation run with 593 injected faults (seed 20261117), 1,567 settled receipts including late ones and disputes, found none. - Late lines clear their breaks; conflicts are explained
(
late_lines_clear_their_breaks_and_conflicts_are_explained). - The API (
crates/api/tests/contract/reconciliation.rs): every operation called and every response checked against the contract, including a money break resolved and a stale cache cleared; the authorization matrix (63 operations × every role) and the audit test cover the six new operations. - The CLI parses each command and prints each break on one line.
- The worked entries E32–E35 balance, use only chart accounts, and are
each booked line for line by their template (
crates/ops/tests/reconciliation.rs).
Acceptance criteria
Section titled “Acceptance criteria”| Criterion | Result |
|---|---|
| 100% of planted breaks are detected | Met: in the engine test (4 money kinds plus stale cache, conflict and both offline kinds), in 5,000 random cases, and at a million items (400 of 400) |
| 0 false matches on the test dataset | Met: at a million items, every match was checked against the movement each line came from (0 false); the property test checks every match of every case |
Exit gate: the daily reconciliation process is documented as a runbook
Section titled “Exit gate: the daily reconciliation process is documented as a runbook”docs/runbooks/reconciliation.md: import, run, the breaks of each kind and what to do with them, the suspense entries and how their items close, ageing and escalation, scheduling and alerting on exit status, and SQL checks.
Measurements
Section titled “Measurements”mezgeb-bench --recon 1000000, on the laptop above (release build):
| Phase | Items | Time |
|---|---|---|
| Ledger written through the engine (not reconciliation) | 500,000 lines in 19,800 entries | 1,731.8 s |
| Statement parsed | 500,100 lines | 1.8 s |
| Statement imported | 500,100 lines | 106.2 s |
| Reconciled: matched, breaks recorded, committed | 1,000,100 items | 96.5 s (10,363 items/s); recorded runtime 63.7 s |
ledger: 500000 lines in 1010, 19800 entries, written in 1731.8 sstatement: 500100 lines parsed in 1.8 s, imported in 106.2 srun: 1000100 items (500100 statement lines, 500000 ledger lines) reconciled in 96.5 s (10363 items/s); recorded runtime 63.7 smatched 499800 · breaks: missing in statement 100, missing in ledger 100, amount mismatch 100, duplicate 100 (each 100 planted) · other breaks 0 · false matches 0PASS: every planted break found and classified, no other break, zero false matchesThe recorded runtime ends before the commit; the commit checks the deferred foreign keys of half a million matched lines, which is most of the difference. A day of a real platform is a few thousand lines, which reconcile in well under a second.
What it does not cover
Section titled “What it does not cover”- A real partner bank’s export. The mapping is tested on an invented bank layout; the first real bank needs its mapping written and tried on a sample export (statement-format.md, “Adding a bank”).
- Returning unidentified money to its sender (Dr 9010 / Cr 1010) still has no template (step 2.02’s open question).
- Statement balances. A bank’s opening and closing balance lines are not read; agreement is checked line by line. A balance check is a small addition if a bank’s export carries them.