Commits
2026-09-12
2026-09-11
2026-08-05
💰 fix: bound the payments walk and settle the statement's arithmeticAhmet Kaan Gümüş · 39821ef
💰 fix: bound the payments walk and settle the statement's arithmetic The statement folded its per-charge rollup from one read of the ledger and balance_minor from a second, later one, so a credit landing in the three-round-trip gap produced a self-inconsistent money document. It now folds both from the lines already in hand. applied_to walked a subtree one query per node under the process-global PAYMENT_LOCK with nothing bounding it, so N one-minor-unit payments made payment N+1 cost N+2 serialized queries while every other money write queued. Capped at MAX_LEDGER_APPLIED_LINES subtree nodes — the node count, not a credit count, because refunds under one credit are equally unbounded. assign_plan could issue 200 × 60 sequential writes in one request; now bounded by MAX_FEE_PLAN_ASSIGN_WRITES, refused up front so nothing partial is billed. due_at declared minimum = 0 in its schema and enforced nothing, so due_at: -1 was a 201 and overdue stayed true forever. A PATCH racing a DELETE of an unassigned plan answered 409 "an assigned plan cannot be edited" about a plan that was gone and never assigned; FeePlan::update now disambiguates the way FeePlan::delete already did. balance_of stops decoding the whole ledger to produce one integer.
2026-07-30
fix: 🧊 freeze a fee plan the moment it is assignedAhmet Kaan Gümüş · ac70cc0
fix: 🧊 freeze a fee plan the moment it is assigned The 409 that stops an assigned plan being edited or deleted was a scan followed, some microseconds later, by the write it licensed. An assign landing in that gap left a plan edited and assigned, or deleted with a live assignment still naming it. The comment called it an accepted race and blamed the other replica; there was never another replica, and two concurrent requests in one process were always enough. A plan now carries an assignment refcount. The assign claims it in the same transaction that writes the row, and the edit and the delete are conditional writes that refuse while it stands. The plan freezes at the instant of the claim, so the assign re-reads it afterwards and bills the copy that froze — the refcount alone still let an edit slip in front and bill the snapshot the handler had read. Existing plans are seeded from the assignments they already carry. An absent counter reads as zero, which is the value that licenses an edit, so a plan assigned before this would otherwise have come unfrozen. Two things this uncovered. A cap claim that lost a write conflict was answered as a 500 five times in six: the retryable conflict shared the error batch with the sibling statements it aborted, and an arbitrary one of those was returned. And a guarded write had no retry at all, so a raced PATCH or DELETE failed outright rather than trying again. The race tests run against a real server. On the embedded engine they watched a 45-in-50 failure rate and passed.
chore: 🧹 drop the coordination for replicas we never runAhmet Kaan Gümüş · a9cfe7b
chore: 🧹 drop the coordination for replicas we never run The backend runs as one process against one database, deployed stop-the-world. The machinery that let several of them agree was built ahead of a multi-replica rollout that stayed parked, so none of it was ever load-bearing: the boot lease elected a leader out of a field of one, the ai_worker table announced a worker to nobody, and the chat claim queue only ever claimed its own writes. Boot now migrates and seeds straight-line; a chat turn is dispatched by the handler that accepted it; the 503 gate reads the in-process registry. The retired columns and tables are unset and removed in separate batches, repair before REMOVE. What stays, with its reason corrected rather than removed: cap.rs, field_update.rs, the refcounts, the CAS retry loops and the in-process locks. Those close write skew between concurrent requests inside one process, which two replicas made worse but never caused. A turn orphaned by a restart or a panic is no longer reclaimed. It settles as timed_out within CHATBOT_PENDING_STALE_SECS. The design survives in the ledger if a second process is ever wanted.
2026-07-29
feat: 💰 track school fees in an append-only ledger of fee plansAhmet Kaan Gümüş · 740e96a
feat: 💰 track school fees in an append-only ledger of fee plans
Fee plans (name + 1..60 installments of {amount_minor, due_at}) are
assigned directly to students; assignment appends every installment as
a charge at once, keyed <plan>_<student>_c<n> so a replay bills nobody.
Payments target one charge, refunds target one credit, and a reversal
undoes only the negative-fold kinds — a mistaken credit is corrected by
a refund, never edited. Balance is never stored; the over-payment cap
folds the target's source subtree under PAYMENT_LOCK and stays advisory
across replicas, which the module doc states outright.
Meal money is untouched: two ledgers, two balances, one shared amount
vocabulary.