Dalteno← Back to the proof section

Engineering case study · October 2026

docrecon: a reconciliation engine built to be judged

A small, open-source component we built so a prospective partner can evaluate our engineering without an NDA, a sales call or a reference check. Everything below is measured on the published code; nothing is a client figure.

What it is. A library that reconciles the three documents behind a sea shipment — commercial invoice, packing list, bill of lading — against 22 rules, and explains every finding.

Why this problem. It is the shape of work we have done for a customs-document comparison system for an Egyptian broker (figures and material not disclosed). We chose a problem we understand rather than a generic to-do app.

Where. github.com/dalteno/docrecon (MIT) · live demo on dalteno.com.

The brief we gave ourselves

Measured

MetricValueHow measured
Rules22, each with a stable id, severity and one-line contractRULES in web/docrecon.js; RuleCatalogue in C#; both counted by a test
Shared cases59 (22 adversarial)cases/generate.mjs; expectations hand-written as RULE|key sets
JS tests72 passing (183 across the three JS suites)node --test web/tests/cases.test.mjs
.NET tests181 passing, 0 faileddotnet test, xUnit; 59 expectation + 59 golden-parity + 63 unit, including the null-line case C53 and the blank-field sweep; measured on GitHub Actions run #9 (23 Oct, 320 ms, net10.0; runs #7 and #8 measured the same 181). Earlier runs: #3 measured 145, #5 measured 152, each before the cases that followed. Run #3 (18 Oct) measured 145 before C53 and its unit tests were added; parity compares every field of every finding to the JS golden report
Mutation checks3 of 3 caughtDisabling R05, flipping the rounding mode, and changing the tolerance comparison each turned the suite red
Throughput38 µs per bundle1,000 bundles in 38 ms, Node 22, after warm-up, mixed cases
Engine size303 lines JS · 415 lines C# corewc -l on docrecon.js, Reconciler.cs + Numeric.cs
Floating-point operations0All arithmetic in integer minor units (BigInt / BigInteger) — ADR-0002
Runtime dependencies0Neither implementation imports anything outside the platform
Effortone engineering day, AI-assistedDesign, both implementations, cases, CI, this page. We use AI tooling the same way we would on your project: it drafts, the tests decide.

Three decisions worth reading

1. No floats, no division

Money is parsed to cents, quantities and weights to thousandths, counts to integers. 3 × 0.10 is 0.30, not 0.30000000000000004. Tolerances are basis points, tested as |a − b| × 10000 > bp × max(|a|, |b|) — no division, so the C# and JS results cannot drift by a rounding step. Case C15_float_trap exists to keep it that way.

2. The cases are the specification

One consistent synthetic bundle plus a named mutation per case, with the expected finding set written by hand. The generator never calls the engine. Separately, the JS engine's full reports are frozen as golden files the .NET engine must reproduce field by field. A rule change therefore shows up three times in review: the generator diff, the golden diff, and both engines.

3. Fail loud, never guess

A quantity of "ten" is a finding (R21), not an exception and not a silent zero. A missing document is reported once and every rule that needs it steps aside. Nothing is inferred from free text; a consignee name is compared only after a documented normalisation (case, punctuation, one trailing legal suffix).

What went wrong, and what it taught us

The first mutation check exposed a gap: flipping the rounding mode from half-away-from-zero to truncation did not fail any shared case, because the ±0.01 amount tolerance absorbed the one-cent difference. Only a unit test caught it. We added C17b_half_cent_zero_tolerance — the same half-cent input with tolerance set to zero — so the behaviour is pinned at the integration level too. The lesson generalises: a tolerance that makes a rule forgiving also makes its tests forgiving; test the boundary with the tolerance off.

Day two: docflow — the workflow around the reconciliation

The same discipline applied to the process the documents live in: a dossier of seven customs documents routed to six roles, with SLAs, a reconciliation gate that reuses docrecon unchanged, an ERP outbox with idempotency keys, notifications on every hand-off, and closure only when every required document is approved and integrated. Built as an event-sourced pure function — every command carries its date, there is no clock — so a visitor can drive it in any order and replay is byte-identical. Try it at dalteno.com/lab/docflow/.

MetricValueHow measured
Rules18 (F01–F18)RULES in web/docflow.js; FlowRules in C#; counted by a test
Document types / roles7 / 6DEFAULT_DEFINITION — data, not code; the roles are the real roles of the process
Shared cases45 (12 adversarial)cases-docflow/generate.mjs; expectations hand-written as status + document states + rule hits
JS tests50 passingnode --test web/tests/docflow.test.mjs — includes the F13 invariant (one notification per hand-off) on every case, and the F18 test that a REVIEW reconciliation stops the customs-entry approval until a reasoned acceptance is recorded
.NET tests96 passing, 0 faileddotnet test on GitHub Actions run #9 (docflow 1.1.0, 23 Oct, 320 ms, net10.0; runs #3–#8 measured 89 before F18); 45 expectation + 45 golden-parity + 6 unit, including the F18 stop-the-flow test; parity compares the whole report, key-order-insensitive
Mutation checks5 of 5 caughtDisabled F08, flipped SLA boundary, removed integration cancel on rejection, froze reconciliation re-run, disabled F02 — each turned the suite red
Throughput73 µs per dossier replay1,000 replays in 73 ms, ~20 events each, Node 22
Engine size247 lines JSwc -l web/docflow.js
Red lineno writes to operational ERP tablesIntegration is an outbox to DOCFLOW_STG.STG_<TYPE> staging tables; the ERP team's job/procedure moves data in. ADR-0004.

Two things the second day taught us. First, a rule that is tested through a tolerance is only half tested — the same lesson as day one, now on dates: the SLA boundary (exactly N days = no breach) needed its own case. Second, hand-writing expectations for a stateful engine forces you to think about every date in a scenario: two of our first drafts accidentally crossed an SLA boundary and would have "expected" a breach we did not intend. The generator caught the author, not the engine — which is the point.

Day three: what an outside review found

On 18 October an independent reviewer went through the live site and both engines. Three real defects, all fixed the same day and each now pinned by a test:

Day five (23 October): the one that mattered most. A second review blanked every field of a clean bundle one at a time. Fourteen fields that rules read — the three document dates, buyer and consignee, weights, package counts, units — could be emptied and the report still said PASS with no findings, because R09, R11, R12, R17, R19 and R20 skipped a comparison when a side was absent and R21 only covered the structurally required fields. Our own README claimed absent data was "reported once"; it was not. Fix in both engines: rule R22 FIELD_ABSENT — a field a rule reads but which is absent is reported once (WARNING, so the status is REVIEW, never PASS) and the rule is skipped; a non-number where a number is expected is R21, never a silent skip. Cases C54–C56 pin it, and a sweep test now blanks every rule-read field on C00_clean in both JS and .NET, so a future rule that reads a new field without declaring it fails the suite. Decision record: ADR-0005.

Two smaller points were also right: a document whose lines is not a list now yields R21 instead of an exception (case C52), and the approvals playground was rebuilt inside the site template so its 4-language text and its validation message behave like the rest of the site. We publish this because it is the point of the lab: the code can be wrong, the tests say so, and the fix is visible.

What this does not prove

If this were your project

We would start exactly here: one page of scope with acceptance criteria, a fixed-price pilot of two to four weeks, the shared-cases approach from day one so you can read our tests before our code, and the right to stop after week one. Write to hello@dalteno.com.

© 2026 Dalteno, Cairo · All sample data in docrecon is synthetic. Client names and figures are withheld under NDA.