Repository navigation
Pips buy their own food, and no workplace conjures it - #10
Merged
Merged
Conversation
ADR 0006 says the core is authoritative for the moment of purchase and the bank for history and solvency, but the implementation had both gating a purchase: the bank committed the transfer, then the core decided whether to apply it. When they disagreed — which happens whenever a wage credit has not reached the core yet — the pip was charged and received nothing, and the replica ended up believing a pip was richer than the ledger did. That is the unsafe direction of error, and it was reachable through the ordinary best-effort intent path. Now exactly one side gates each movement, and it is the side that can see what the other cannot: - A purchase is gated by sim-core, settled against the pip's replica balance inside a tick, which is the only place that decision can be made without a network call. The core emits PurchaseMade and the bank books it off pipsim.economy.purchases.v1. The bank no longer publishes that event — two producers on one fact makes "who decided this" unanswerable from the log. - Payroll stays gated by the bank, because "can this workplace afford its wage bill" is a solvency question and solvency is the ledger's. Four invariants from the ADR follow from that shape or are enforced directly: - Buying is physical (invariant 5). A pip must be inside the seller, checked in the core against `inside`. ADR 0004 made buildings places rather than addresses; money would have quietly reintroduced the model it replaced. - Idempotency keys are per movement (invariant 3). A booked purchase is keyed by the event's own id, so two buys from one seller in a single tick are two bookings rather than one. - A rejection is not a result (invariant 4). Refusals are no longer stored under the idempotency key, so a payer funded later in the same tick is answered from its balance rather than from a memory of being broke. - Minting is a privilege carried by the transfer (invariant 6). The treasury's licence to go negative now requires TransferKind::Issuance rather than being inferred from the payer's identity. Also: nothing issued money, so every account sat at zero and payroll rejected for insufficient funds forever — the economy could not start. The gateway now endows each workplace once, idempotent by balance. `Pip.balance` is exposed on the snapshot so the gateway can answer "can this pip afford it" before submitting an intent, and so a client can draw it.
This is ADR 0006 step 7, and the point the whole ADR was written for. Until now a shift handed the worker food out of nothing: `farm.go` gave +5 a tick, the tavern +3, and both files said in a comment that it was conjured. The economy ran alongside that, decorative — money moved but nothing depended on it. Now the loop closes. Work pays a wage, the farm sells meals, and a hungry pip walks to a shop and buys one. A pip that cannot afford food starves, which is the first death in this simulation caused by economics rather than by a missing building. The behaviour lives in the core because every rule about how pips behave does: the browser predicts with this same code, so a decision taken anywhere else would make the client and the server disagree about what happens next. Concretely a pip gains an *errand* — somewhere it is going of its own accord, which outranks the commute. That is the first thing in this simulation a pip decides for itself; everything else about it was decided by a service or by the world. Deliberately not a plan or a queue of goals. A pip is hungry or it is not, and it re-decides every tick, so a shop that raises its price or a wage that arrives late changes its mind with nothing to invalidate. Prices reach the core the way capacity already does (ADR 0004): the workplace owns the number, the gateway carries it on the registration intent, the core enforces it. A pip deciding inside a tick whether it can afford lunch cannot make a network call to ask. `need_deltas` is deprecated rather than reserved. Step 7 asked for reserved and that turns out to be impossible: `buf breaking` refuses the deletion, and that rule is load-bearing, so the field stays on the wire and dies by disuse. Nothing populates it. The farm and the tavern no longer have any opinion about hunger — which is what makes the tavern's old food_per_tick = -1 bug unrepresentable rather than merely fixed. Covered by a test that runs 4,000 ticks of the full loop: a pip is hired, paid in batches the way the gateway pays it, decides for itself when to stop working and eat, and is still alive at the end with money in the bank and the supply still closed.
4 of 5 tasks
teceer
added a commit
that referenced
this pull request
Aug 7, 2026
#15) Formatting has landed on main and turned the lint job red three times now (twice around #5, again in #14). The pattern never changes: rustfmt is enforced in CI and run nowhere else, so it is found after landing, by whoever pushes next. `make hooks` points core.hooksPath at .githooks/, so the hooks are versioned and change with the repo rather than being copied into .git once and forgotten. The hook checks formatting and nothing else. `make lint` runs clippy, golangci-lint and credo across nine services; a hook people wait thirty seconds for is a hook people pass --no-verify to, and then it protects nothing. Each language is checked only when a file of that language is staged, because the two slow starts are the BEAM and cargo and neither should be paid for a change that did not touch them. `make fmt` is the other half: whatever the hook rejects, it fixes. Two deliberate omissions: - No `buf format`. It reflows .proto comments onto a single space before the slashes, which destroys the column alignment several of those files use to keep a field's meaning readable next to its number. That is the author's style choice and a hook is the wrong place to overrule it — `make proto-lint` already covers the checks that catch real mistakes. - No `mix format` for a service without a .formatter.exs, since broadcast is still an empty shell (ADR 0010). Also fixes what gofmt immediately found: a stray blank line in driver.go, from #10. golangci-lint does not have gofmt enabled here, so CI never saw it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ADR 0006 step 7 — the point the whole ADR was written for.
Replaces #9, which GitHub auto-closed when its base branch (#8) was deleted on merge; a closed PR cannot be retargeted. Same branch, same commit, now based on
mainwithmainmerged in.What changes
Until now a shift handed the worker food out of nothing.
farm.gogave+5a tick, the tavern+3, and both files said in a comment that it was conjured. The economy from #4 and #8 ran alongside that, decorative: money moved, but nothing depended on it.Now the loop closes:
A pip that cannot afford food starves. That is the first death in this simulation caused by economics rather than by a missing building.
The interesting part: a pip decides something
A pip gains an errand — somewhere it is going of its own accord, which outranks the commute. It is the first thing in this simulation a pip decides for itself; everything else about it was decided by a service or by the world.
Two choices worth reviewing:
It lives in the core. Same reason
wanderdoes: the browser predicts with this identical code, so a decision taken in a driver or a client would make prediction and truth disagree about what happens next.It is not a plan. No goal queue, no stored intention. A pip is hungry or it is not, and it re-decides every tick — so a shop that raises its price, or a wage that arrives late, changes its mind with nothing to invalidate. A plan would need cancelling; a standing preference does not.
An errand is also physical, per invariant 5: the pip walks there, goes inside (taking a place, briefly), buys, and leaves in the same tick.
Prices reach the core the way capacity already does (ADR 0004) — the workplace owns the number, the gateway carries it on the registration intent, the core enforces it. A pip deciding inside a tick whether it can afford lunch cannot make a network call to ask.
The proof
One test runs 4,000 ticks of the whole loop: a pip is hired, paid in batches the way the gateway pays it, decides for itself when to stop working and eat, and is alive at the end with money left and
total_money == 0throughout. Two more pin the other side — a penniless pip starves standing next to food it cannot afford, and hunger outranks the commute while employment survives the errand.need_deltasis deprecated, not reservedStep 7 asked for
reserved. That turns out to be impossible, and the ADR is wrong about it:make proto-lintrunsbuf breaking, and that rule is load-bearing — a topic with a week's retention holds messages that must still decode. So the field stays on the wire, marked deprecated, and dies by disuse. Nothing populates it.The farm and the tavern no longer have any opinion about hunger. That is what makes the tavern's old
food_per_tick = -1— the number that starved everyone it employed — unrepresentable rather than merely fixed.Test plan
cargo test -p sim— 32 pass, 3 new (survival over 4,000 ticks, starving next to unaffordable food, errand outranks commute)mix testintavern— 32 pass; its shift test now asserts a shift reports only what it produced and paidgo test ./...infarm,conformance,bank,world-gateway— pass; farm and conformance re-pinned onto wage and producecargo clippy --all-targets -- -D warningsclean,cargo fmt --checkcleanbuf lint/buf breakingclean —WorkplaceOffer,RegisterWorkplaceIntent.sells,Workplace.sellsall additivemake genregenerated for Go, TS and Elixirmain: all of the above still greenBalance, and what to watch
A meal restores 200 food; a working pip burns 2 a tick, so one meal buys ~100 ticks of work — 600 in wages against 50 at the till. Employment is comfortably survivable on purpose: if it were marginal, the only failure anyone would ever see is "everyone dies", and the interesting ones (a wage that cannot cover food, a shop nobody can reach) would be invisible underneath it.
Unemployment is now fatal, since nothing else feeds a pip. That is the intended scarcity, but it makes hiring throughput a survival mechanism rather than an optimisation — worth watching on the first live run.
🤖 Generated with Claude Code