RECONCILIATION · NO. 004
The mechanisms and decisions of the reconciliation engine
The machine matches a bank line to the books only when ten gates pass, and records a resident's deposit only on the resident's own word. Everything else waits for a person.
> everything else waits for a person on the review page # exact_gate.py, module docstring
Reconciliation is the monthly proof that the books and the bank agree, line by line. Software can make it look easy by guessing.
A bank line for $482.17 arrives. The books might hold an entry for exactly $482.17, or one for $482.71, the same digits typed in a different order, or two smaller entries that together make $482.17. A matcher that guesses picks one of them and calls the line matched. When it picks wrong, the treasurer finds out at year end, or the auditor does.
I reconcile an association's books on CommunityPay every month. This post is the mechanism that decides what the machine may match, the iterations that produced it, and what changed in November: a month that closes two business days after it ends once every line is decided, residents' deposits recorded on the resident's own word, and a tenth gate, which reads who a bank line says it is from.
Earlier posts in the series covered a ledger that records its refusals (NO. 001) and the law underneath it (NO. 002). Panels marked ITERATION are abstracted from the production system. Panels with a wax rule are copied from the tree.
PART I
What the machine is allowed to match
# iteration 0 — the suggested match
for line in bank_lines:
entry = nearest(entries, amount=line.amount, tolerance=0.02, days=5)
if entry:
suggest(line, entry, confidence='exact') # the treasurer presses Accept All Exact
Within two cents counted as exact, any entry within five days was a candidate, and the nearest won. One button, Accept All Exact, took every such match at once. It was right most of the time, and the times it was wrong looked exactly like the times it was right.
# iteration 1 — one writer
# The exact gate is the only code that writes a machine match.
# Hints are computed when the review page renders, and stored nowhere.
def match_statement_account(bank_account, *, today):
decisions = exact_gate.evaluate(exact_gate.build_context(bank_account, today=today))
return exact_gate.persist(decisions, today=today)
The page still shows a treasurer the near amounts, the vendor payment a line most likely is, and two or three entries that add up to it. None of that is stored. A stored match is a decision, a person's or the gate's, and a test fails if any other module writes a machine match.
# iteration 2 — only the middle step decides, and it reads nothing else
ctx = build_context(bank_account, today=today) # reads the database
decisions = evaluate(ctx) # pure: same context, same decisions
persist(decisions, today=today) # writes, under the account's lock
Because the decision reads only its context, the same inputs always give the same decisions. The review page relies on that: when a person opens it, the gates run again, and each line says why it is waiting.
# window_closed
closes = lf.bank_date + timedelta(days=lf.window_days)
if not today > closes:
return failed(
'window_closed', COMPUTED, 'waiting_for_window',
days=(closes - today).days + 1, date=day(closes), amount=money(lf.amount),
)
passed('window_closed', window_days=lf.window_days)
...
# mutual: one line wants it, and no other line's applied match cleared it
holder = ctx.held_by.get(entry.entry_id)
if holders[entry.entry_id] != 1 or holder not in (None, lf.line_id):
return failed('mutual', COMPUTED, 'contested', entry=entry.entry_number)
passed('mutual')
return done(PASS, matched=entry)
accounting/services/bank_statement/exact_gate.py · _ready, _decide
Every line runs ten gates in order: the statement is open, the line is open, no person has answered it, its date window has passed, the bank's balance ties past it, one entry equals it to the cent, that entry is not dated after the month ends, it is not half of a voided pair, nothing on the line points at another unit or vendor, and no other line wants it. A match the gate accepts keeps the record of every gate it passed and the day it was decided. The ninth was added on November 13. Part IV is that gate and the two rules that came with it.
models.CheckConstraint(
condition=(
models.Q(auto_rule='')
| (
models.Q(match_type='journal_entry')
& models.Q(amount_difference=0)
& models.Q(created_journal_entry__isnull=True)
)
),
name='machine_match_is_exact_entry',
),
accounting/models/bank_statement.py · BankStatementLineMatch.Meta
The gate is code, and code changes. The rule underneath it is a constraint in the database: a machine match is one existing entry at no recorded difference, with nothing created, or it cannot be stored. A bank fee or interest, which would post an entry, can never be the machine's, whatever the code above believed. A group of entries, or a near amount the code took for exact, is beyond what a row's constraint can see. The gate refuses both, and it is the only code that writes a machine match.
in_s = [line for line in lines if rec.statement_end_date < line.post_date <= d_prime]
s_total = sum((line.amount for line in in_s), ZERO)
anchor_ending = rec.statement_ending_balance
# The date-only block of the day the balance was struck is all in or all
# out: whichever ties is the one recorded ('out' when both do).
variants = (
('out', feed.balance_current - cut.timed_in),
('in', feed.balance_current - cut.timed_in - cut.block),
)
chosen = next(
((name, c) for name, c in variants if c - s_total == anchor_ending),
None,
)
accounting/services/bank_feed/proof.py · compute_proof
The fifth gate reads a proof, and the proof is a subtraction. The bank reports a balance. Take away every transaction the feed holds since the last month a person reconciled, and what is left must equal that month's ending balance, to the cent. Transactions dated the day the balance was struck may or may not be in it, so both readings are tried and the one that ties is recorded. If the feed missed a transaction, or holds one twice, neither ties, and nothing more is matched until one does. No reading of the lines the feed has can find one it does not have.
# iteration 5 — withheld is not evidence
if outcome == WITHHELD: # the month not yet proven, the feed not connected or switched off
keep() # nothing accepted, nothing demoted
elif outcome == COMPUTED: # two candidates now, another line took it, the month failed
demote(match) # back to a person, and never recorded as a person's "no"
A line inside its date window waits, and the page names the day it waits for. A month the bank has not yet proven holds: nothing in it is accepted and nothing is demoted, because not yet proven is not evidence that a match is wrong. A month whose balances fail to tie is evidence, and its machine matches go back to a person.
kind, code = stmt_proof
if code != COLLECTING_CODE:
return kind, code, {}
closes = bank_day + timedelta(days=window)
tie = feed_statements.tied_through(stmt)
if tie is not None and tie.anchor_id == anchor_id and tie.balance_date >= closes:
return PASS, '', {}
return WITHHELD, 'tie_pending', {'date': day(closes)}
accounting/services/bank_statement/exact_gate.py · line_proof
Until November a bank feed month was proven as one unit, five days after it ended, so nothing in it was matched before then. Measured on a live bank feed from May to November, the machine took between 25 and 57 percent of a month's lines, and every line it left had a mechanical cause. Now the feed keeps the latest balance date at which its completeness proof tied, and a line is proven once its own window has closed by that date. Matches land six days behind the bank, all month long.
# iteration 7 — the machine recomputes from people's decisions alone
release(every machine claim)
eligible = entries - cleared - claimed_by_people
for line in lines_no_person_has_answered:
decide(line, eligible)
On every run the machine lets go of its own matches and assigns again from what people decided, so the result does not depend on which line arrived first. A person's "no" is never erased. After an Undo the machine stands down on that line for good. And the gate never posts an entry: it matches lines to entries that already exist. The one path that posts without a person is in Part III, behind the association's own switches.
PART II
The month closes when it can
A line's date window exists so that an entry the books record late can still meet it. When every line in a month is decided, the windows protect nothing. Waiting for them anyway is what kept a month from closing until the sixth of the next one.
def closes_early(stmt: BankStatementImport, proof, *, today: date) -> bool:
"""The month has ended, every one of its transactions is decided, and the
proof's balance date is at or after ``settle_date``. The proof itself is
then read as it is after the windows (``_proven``)."""
end = stmt.statement_end_date
if end is None or today <= end or proof is None or proof.balance_date is None:
return False
if proof.balance_date < settle_date(end):
return False
return not undecided_lines(stmt).exists()
def settle_date(end: date) -> date:
"""The earliest bank balance date at which a month ending ``end`` may
close before its windows: the end of the ``EARLY_CLOSE_BUSINESS_DAYS``-th
business day after it. A weekend day or a federal holiday, on which the
bank posts nothing, is not counted."""
from payments.domains.resident_payment.late_fees import is_federal_holiday
moment = end
remaining = EARLY_CLOSE_BUSINESS_DAYS
while remaining:
moment += timedelta(days=1)
if moment.weekday() < 5 and not is_federal_holiday(moment):
remaining -= 1
return moment
accounting/services/bank_feed/statements.py · closes_early, settle_date
A month whose every line is decided is established once the bank's balance at the end of the second business day after it ends ties to the last reconciled month. A weekend or a federal holiday is not a business day, because the bank posts nothing on one. October ended on a Saturday; decided, it can close on Wednesday, November 4, where it used to wait until Friday, November 6.
The early path only ever establishes a month. A proof that does not tie leaves it collecting, as before, so nothing is reported failed before the windows would have said so. If the bank later reports another line in that month, the month's lines have changed, and until that line is decided the month is collecting again.
When a month is ready to complete, the treasurer's seat is told once, by email and in the notification center. A notice that something may be wrong with the feed itself, such as a balance that does not tie or a connection that lapsed, also goes to whoever holds financial authority. When someone completes the reconciliation, the board is told who did. A month completed long after it ended, from a backlog, shows in the app and sends no email.
PART III
The resident's own word
Most of an association's deposits are residents paying dues. The Deposits page proposes which unit each one is from, and a name on a bank line never decides: two owners share a surname, a tenant pays for a landlord, a spouse pays from a joint account. Two things do decide, because the resident said them: the unit's payment code, printed on every statement, and a payment the resident declared in the portal. A declaration is only an amount and a week, so it decides only a Zelle deposit against a payment declared as Zelle. A Zelle line carries its sender's name, which can stop the match if it points at another unit but never makes one. A check carries no name at all.
#: The proposal kinds a rule records, and the rule each one is.
RULES: dict[str, str] = {
proposer.KIND_CODE: DepositApplication.RULE_CODE,
proposer.KIND_DECLARED: DepositApplication.RULE_DECLARED,
}
def rule_for(proposal: proposer.Proposal | None, line: BankStatementLine) -> str:
"""The rule that records ``proposal`` of ``line`` on its own, or ''."""
if proposal is None or not proposal.one_click or proposal.waiting:
return ''
if proposal.unit_id is None or proposal.is_group or not proposal.applicable:
return ''
rule = RULES.get(proposal.kind, '')
if rule == DepositApplication.RULE_DECLARED and not declared_by_zelle(line, proposal.unit_id):
return ''
return rule
def declared_by_zelle(line: BankStatementLine, unit_id: int) -> bool:
"""The line is a Zelle deposit, and a payment the resident of ``unit_id``
declared as Zelle fits it: the same amount, inside the account's window."""
if keys.method(line.description, line.check_number) != keys.METHOD_ZELLE:
return False
stmt = line.statement_import
fitting = declarations.declared_units(
declarations.pending_facts(stmt.hoa),
amount=line.amount,
bank_day=exact_gate.bank_date(line, stmt.source_type),
window_days=exact_gate.window_days(stmt.bank_account),
)
return any(fact.unit_id == unit_id and fact.method == PaymentDeclaration.ZELLE for fact in fitting)
# Only a known rule records a deposit with no person.
models.CheckConstraint(
condition=models.Q(recorded_by_rule__in=('', 'deposit_code_v1', 'deposit_declared_v1')),
name='deposit_application_known_rule',
),
# A rule applies a line to one unit, never to several.
models.CheckConstraint(
condition=models.Q(recorded_by_rule='') | models.Q(group__isnull=True),
name='deposit_application_rule_is_single',
),
accounting/services/deposit_inbox/auto.py · RULES, rule_for, declared_by_zelle; then accounting/models/deposit_inbox.py · DepositApplication.Meta
For an association that offers bank payments and asks for them to be recorded, the bank feed now records such a deposit when it arrives, through the same Apply a person uses: the same receipt dated the bank's day, the same dues settled, the same email to the owner, the same Undo. Only when the proposer calls it one click, with nothing on the line pointing at another unit, and only if the evidence still holds when Apply proposes the line again under the account's lock, so a declaration one deposit has used never records a second. A payer a person taught stays a person's to apply. A line a person has answered is never asked about again. The rule teaches nothing, and its name is kept on the deposit's application and on the line's match.
The database knows the only rules there are, and holds a rule to one unit. A deposit split across several units is always a person's decision. Four switches stand in front of the rule: the platform's, the bank feed's, and two of the association's own, both off until the association turns them on.
PART IV
What a line says
Dues are the same amount for every unit. One owner's check, recorded and waiting to be deposited, and another owner's bank transfer of the same dues are equal to the cent, and they can arrive in the same week. The amount, the date, and whether anything else wants the entry are the same for both. Only the line itself says which it is: the bank prints who sent a transfer, and prints nothing for a deposited check.
# not_elsewhere: what the line says can stop the pair, never make it
clause = elsewhere(ctx.says.get(lf.line_id, NOTHING), ctx.parties.get(entry.entry_id), lf.line_id)
if clause:
return failed(
'not_elsewhere', COMPUTED, 'points_elsewhere',
entry=entry.entry_number, whose=ctx.parties[entry.entry_id].whose, says=clause,
)
passed('not_elsewhere')
accounting/services/bank_statement/exact_gate.py · _decide
The tenth gate reads what the line says: a payment code, a name, a unit number, a payer someone taught it, a check number, the bank's own words for its fee. If any of that points at another unit or vendor than the entry's own, the pair is refused, and the page says whose the entry is and what the line names. A payment a resident has declared, of that amount and that week, is read the same way: until a person applies it, a deposit that names no one, and so could be it, is not matched to another unit's receipt. A person who knows it is the same money can still match it.
It only refuses. A line that names unit 101, with two receipts at its amount and one of them unit 101's, is still two candidates. Removing the other receipt on the name's word would be the name making the match. And if the reading itself fails, nothing is matched until it reads again. The gate never falls back to the amount alone.
same = [
net for net in eligible[lf.line_id]
if net.entry_id in ctx.parties and ctx.parties[net.entry_id].reference == reference
]
if len(same) == 1 and not elsewhere(said, ctx.parties[same[0].entry_id], lf.line_id):
named[lf.line_id] = same[0]
numbers[lf.line_id] = reference
wanted = Counter(net.entry_id for net in named.values())
fixed = {line_id: net for line_id, net in named.items() if wanted[net.entry_id] == 1}
reserved = {net.entry_id for net in fixed.values()}
accounting/services/bank_statement/exact_gate.py · _named_by_number
One thing a line says does decide: a number the bank and the books both carry for the same piece of paper. A withdrawal the bank printed as check 1041 and the one payment recorded as check 1041, equal to the cent, are each other's, and that entry is no other line's. Two $250 checks used to be two candidates each. With three recorded and two paid, the number says which one is still outstanding. The same number on two lines names nothing, a number the rest of the line contradicts names nothing, and a number that differs from the entry's only refuses.
# iteration 12 — as many entries as lines
entries = candidates(line) # equal to the cent, inside the window
lines = [l for l in open_lines if candidates(l) & entries]
if len(lines) == len(entries) and all(candidates(l) == entries for l in lines):
pair(lines, entries) # every pairing clears the same entries
Eight $350 checks deposited one at a time against eight $350 receipts were eight lines with eight candidates each, and the machine took none of them. But whichever way they are paired, the same eight entries clear, into the same month. The reconciliation is identical under every pairing, so the machine makes one: the bank's dates against the books', and a pair made yesterday is the pair kept today. Seven deposits against eight receipts is not a set. One receipt is outstanding and nothing says which. Each row is still one line to one entry at no difference, so the database's rule holds for every member.
The gate is now also run against months nobody wrote: 3,000 of them, 65,108 bank lines, generated from fixed seeds on every test run. Each line is made from an event and so is each entry, so the right answer is a fact of the fixture. They are built to be hostile. More than half the payments share one of three amounts, and about one entry in seven never reaches the books. For every line, the gate's outcome is the one a second statement of the rule gives, written separately: matched, held, or left for a person. Its answer does not change with the order things are read in. A match re-proved is the match that was made.
In the thousand months where every line names its payer, every entry is a recorded receipt or payment, and no payer pays the same amount twice, 9,654 lines were matched and no wrong entry was cleared. Where a line names no one, the amount is all there is, and nothing on the line can tell an unrecorded payment from a different payment of the same amount. The run counts those cases too. The figure is in the provenance below.
PART V
What the machine is not allowed to do
Machines have become very good at syntax and at the rote work that offices used to brand their experts for. They look things up quickly. What they cannot do is hold a system in their head. This one is more than a million lines of Python plus hundreds of thousands of lines of templates, and no model window today holds more than a fraction of it at once. Close the session and what it learned is gone, unless a person wrote it down.
Where the books use a language model, it proposes and code decides. An emailed invoice is read in one call into a fixed schema, choosing only from the association's own vendors and accounts, and code checks every choice before anything reads it. Nothing in the reconciliation gate has a model in it.
The gate decides a month of 300 bank lines against 424 entries in under two milliseconds. It is a function of its inputs, so it runs again on every reading of the bank, on every decision a person makes, and when the review page opens. Each run is the whole proof again, and it comes out the same.
A language model asked the same question reads the month again each time: about 18,000 tokens in and 11,000 out, estimated from the length of the text. At the list prices of one current model family, from its smallest model to its largest, that is $0.007 to $0.57 a pass. The largest model of each of three vendors is $0.14 to $0.71. Sixty passes, one for each day's reading of the bank and thirty for a person's decisions, are $0.42 to $34 a month for one association. The gate's sixty take about a tenth of a second of computing, the reads from the database aside.
Engineers call the power a machine draws to run itself, and not to do its work, a parasitic load. A model set on top of a ledger to decide what a rule already determines is one. It derives the month again on every pass and is paid for every pass, and the answer it returns is one the books already had. The figure counts the draw: one pass, and a year of a book.
IN THE TIME THE MODEL WRITES IT
62,352
PASSES BY THE RULE
106 seconds against 1.7 milliseconds.
FOR THE PRICE OF IT
24,952,941
PASSES BY THE RULE
$0.57 against about two millionths of a cent.
AS OF NOVEMBER 13, 2026
Claude Fable 5.2 lists $8.00 per million tokens read and $40.00 written. A pass is the month written out and decided: about 17,700 tokens read and 10,600 written, estimated from the length of the text.
Assumed: the model writes 100 tokens a second, and its thinking before it writes is not counted. Measured: the rule's 1.7 milliseconds, priced on one processor at $0.048 an hour. A year is twelve passes for each association: one a month, when the month is reconciled.
The model: $678.72 and 35 hours of writing. The rule: less than one cent and 2 seconds.
A language model that is wrong once in a thousand lines, and cannot say which line, puts a wrong match into a 300-line month about one time in four, and into a year of them 97 times in a hundred. Finding it means reading every match again. The gate does not guess: it matches only what it can prove and holds the rest for a person, and where the lines name their payer it cleared no wrong entry in 9,654 matches.
So the model types, and I decide what the system is forbidden to do. Taste, judgment, and system design are not tasks to hand over. Hand them over and the bill arrives later, as cleanup and maintenance.
TEN GATES.
ONE WAY THROUGH.