From 53f61bc24a398c7ff60564f247df3b67adc5c0f9 Mon Sep 17 00:00:00 2001 From: repo-worker-code-k Date: Sun, 8 Nov 2026 02:15:22 -0600 Subject: [PATCH] =?UTF-8?q?design(id):=20#5829=20currency=20load=20&=20cor?= =?UTF-8?q?rectness=20verification=20programme=20=E2=80=94=20property=20te?= =?UTF-8?q?sts,=20crash=20injection,=20per-stage=20envelopes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/2026-11-01_design_id2043.md | 2 +- doc/2026-11-08_design_id5829.md | 363 ++++++++++++++++++++++++++++++++ 2 files changed, 364 insertions(+), 1 deletion(-) create mode 100644 doc/2026-11-08_design_id5829.md diff --git a/doc/2026-11-01_design_id2043.md b/doc/2026-11-01_design_id2043.md index 071eb46a24..7db93114ab 100644 --- a/doc/2026-11-01_design_id2043.md +++ b/doc/2026-11-01_design_id2043.md @@ -15,7 +15,7 @@ Choose one v1 model that reconciles graph-native tokens, real-service grants, an 4. Real-service purchases use the #2042 pending-hold lifecycle and only anchored currencies. A payment receipt records an effect; it is never itself a balance movement. 5. Anchored conversions use one signed, directional `currency.rate_authorisation`, a short-lived event-pinned quote, and one atomically linked TigerBeetle batch. A posted conversion is corrected by a new compensating conversion, never edited. -This follows #2043’s requested synthesis of #2040–#2042 and its four explicit topics (token model, ledger boundary, conversion authorization, and open-source boundary). It also carries forward later decisions rather than treating the earlier graph-token wire format as the newest word: #2741 is the merged snapshot/fold spec, while the newer #2290 record recommends the canonical `currency.rate_authorisation` event and #2063’s latest summary adopts that direction. Their PRs #3831 and #3844 merged on 2026-11-02, so the two vocabularies are settled for implementation. The staged extension of these contracts across the #5676 backends (Redis, multi-Turso, TigerBeetle) is recorded in `doc/2026-11-05_design_id5828.md` (#5828). +This follows #2043’s requested synthesis of #2040–#2042 and its four explicit topics (token model, ledger boundary, conversion authorization, and open-source boundary). It also carries forward later decisions rather than treating the earlier graph-token wire format as the newest word: #2741 is the merged snapshot/fold spec, while the newer #2290 record recommends the canonical `currency.rate_authorisation` event and #2063’s latest summary adopts that direction. Their PRs #3831 and #3844 merged on 2026-11-02, so the two vocabularies are settled for implementation. The staged extension of these contracts across the #5676 backends (Redis, multi-Turso, TigerBeetle) is recorded in `doc/2026-11-05_design_id5828.md` (#5828). The load & correctness verification programme those stages must pass — property tests, crash injection, and per-stage performance envelopes — is recorded in `doc/2026-11-08_design_id5829.md` (#5829). ## Context and current footing diff --git a/doc/2026-11-08_design_id5829.md b/doc/2026-11-08_design_id5829.md new file mode 100644 index 0000000000..636f4b3f00 --- /dev/null +++ b/doc/2026-11-08_design_id5829.md @@ -0,0 +1,363 @@ +# Design: currency load & correctness verification programme + +- Date: 2026-11-08 +- Status: **decision record** — docs only, no implementation code. +- Issue: [#5829](https://github.com/developing-today/code/issues/5829), follow-on + of [#5676](https://github.com/developing-today/code/issues/5676) (currency + scaling: Redis → multi-Turso → TigerBeetle), programme epic #2056. +- Decomposition item: #5676 item 7 — "Load/correctness verification program: + property tests, crash-injection, per-stage performance envelopes." This + record settles that item. It consumes, and does not re-decide, #5676's + staged path and invariants, the backend port and invariant test-suite + contract owned by [#5823](https://github.com/developing-today/code/issues/5823), + and the conversion/RateAuthorisation stage record + (`doc/2026-11-05_design_id5828.md`, #5828). + +## The decision + +1. **One verification programme, three legs, every stage.** The programme + has exactly three legs — (a) property/model-based correctness tests, + (b) crash injection, (c) per-stage performance envelopes — and all + three run against *every* stage adapter (Stage A Redis, Stage B + multi-Turso, Stage C TigerBeetle) through the #5676 backend port. + A stage is not "done" when its adapter compiles; it is done when the + programme passes against it. Per-stage bespoke test suites are + rejected (§7): the whole point of the port is that verification is + stage-independent, so a stage swap is a re-run of the same programme, + not a new verification design. +2. **Oracle-first, pre-registered verdicts.** Every leg names its oracle + before it runs: the in-memory reference ledger (§3) for correctness, + the reconciliation checker (§4) for recovery, and pre-registered + envelope thresholds (§5) for performance. A result that can only be + judged by eyeballing output is not a programme result. Envelope + numbers are fixed *before* a measurement campaign and are revised + only by the amendment rule in §5.4 — never fitted after a run. +3. **The #5823 invariant suite is an input, not a rival.** #5823 owns + the backend port and the invariant test-suite *contract*: the + conformance gate a backend must pass to be called a currency + backend. This programme owns everything around that gate — the + generative testing beyond the contract's cases, the crash-injection + campaigns, the load envelopes, the cadence, and the published + evidence. The contract suite runs inside this programme as the + first correctness leg (§2); this record does not restate, extend, + or fork its cases. +4. **Programme evidence drives stage transitions; it does not make + them.** #5825 (autoscaling design) owns the scaling triggers and + the stage-transition decisions. This programme's job is to make + those triggers *evidence-based*, as #5676 requires: it publishes + envelope measurements and correctness results per stage, in the + form §5.5 specifies, and #5825's triggers consume them. A breached + envelope is published evidence for a transition review — it is not + a silent failure and not an automatic transition. +5. **No parent decision is changed.** #5676's stages, invariants, + interfaces, and open questions are untouched by this record; §8 + lists the consumed decisions explicitly. Where a programme answer + *would* have changed one (none did), the change would have been + recorded here as an explicit amendment proposal to #5676, not + folded in silently. + +## 1. Boundary with the sibling designs + +| Sibling | It owns | This programme takes from it | This programme gives back | +|---|---|---|---| +| #5823 port + invariant suite contract | The port interface; the conformance cases a backend must pass | The suite, run unmodified as correctness leg 0 (§3.1); the port as the only surface under test | Generative, crash, and load evidence about each adapter claiming conformance | +| #5824 Stage A design | Redis write-through, crash recovery, reconciliation mechanisms | Its declared fault points (§4.2) and recovery claims as test obligations | Crash-injection verdicts on those claims; Stage A envelope measurements | +| #5825 autoscaling design | Scaling triggers, hot-account mitigations, transition decisions | The trigger metrics it needs measured (§5.5) | Published envelope + soak evidence in trigger-ready form | +| #5826 Stage B design | Sharding, cross-DB saga, rebalancing mechanisms | Saga fault points and the pending-settlement semantics (§4.2) as test obligations | Saga crash verdicts; per-shard and cross-DB envelope measurements | +| #5827 Stage C design | TigerBeetle adapter mapping, B→C cutover plan | Its dual-run/ledger-comparison cutover claims as test obligations | Cutover rehearsal verdicts (dual-run divergence = 0) and Stage C envelope measurements | +| #5828 conversion record | Per-stage atomicity of conversions | Its outcome vocabulary (`POSTED`, `FAILED_ATOMIC`, saga outcomes) as oracle states | Conversion-shaped workloads inside all three legs | + +Rule of thumb: a sibling design *claims* a behaviour; this programme +*tests the claim* and publishes the result. A claim with no programme +leg is an untested claim and is called out as such in the campaign +report (§6). + +## 2. Programme shape + +- **System under test:** one stage adapter behind the port, plus the + shared layers above the port (admission, intent, reconciliation + reporting) exactly as deployed. The in-memory adapter is the control: + it must pass every correctness leg trivially, and a leg that fails + against the control has a broken oracle, not a broken backend. +- **Determinism:** every generative or injected run records its seed, + its fault schedule, and the adapter build. Any failure must be + replayable from those three alone before it counts as a finding. +- **Environments:** correctness and crash legs run in CI-grade + ephemeral environments (no shared state between runs). Load legs run + against a dedicated staging twin sized like the production target of + the stage under test; load results from shared or undersized + environments are not publishable evidence. + +## 3. Leg 1 — property / model-based correctness + +### 3.1 Structure + +- **Leg 0 (contract):** the #5823 invariant test suite, unmodified. +- **Leg 1 (generative):** a property-based generator produces random + operation sequences against the port; a model-based oracle — the + reference ledger — computes the expected outcome of every operation; + the adapter's observable state must match the oracle after every + step, not only at the end. + +### 3.2 The oracle: an in-memory reference ledger + +A deliberately simple, obviously-correct implementation of #5676's +semantics: named accounts per currency, double-entry postings, +idempotency-key deduplication, hold/capture/release, and conversion as +the #2063/#5828 outcome state machine (including Stage B's +pending-settlement states — the oracle models the *stage's declared +semantics*, so a saga stage is judged against saga outcomes, never +against atomicity it does not claim). The oracle is single-threaded, +in-memory, and kept small enough to audit in one reading; its own +correctness is established by the #5823 contract examples run against +it as a backend. + +### 3.3 Generators + +Operation mix, weighted toward the dangerous cases: plain transfers, +duplicate submissions of the same idempotency key (before and after +commit), concurrent transfers on one hot account, transfers racing a +hold/capture/release on the same funds, conversions at quote expiry +boundaries, cross-currency transfers (Stage B/C shapes), and +zero/edge amounts at currency precision limits. Contention profiles +are explicit generator parameters (uniform, Zipf-hot-account, +single-account hammer), because invariant violations hide under +contention, not under uniform load. Shrinking is mandatory: a failing +sequence is only a finding once shrunk to its minimal repro, which is +checked into the regression corpus (§3.5). + +### 3.4 Invariants under generation + +The implementation must hold, at every step, for every stage: + +- **I1 Conservation:** per currency, the sum of all balances changes + only by explicit issuance/retirement operations — never by a + transfer, conversion, crash, or retry. +- **I2 Balance rule:** no account goes negative beyond its currency's + stated overdraft/hold rules. +- **I3 Atomicity as declared:** an operation reaches exactly one of + its stage's declared outcomes; no partial legs are ever observable + outside the stage's declared pending states. +- **I4 Idempotency:** re-submitting a committed idempotency key is a + no-op returning the original outcome, indefinitely. +- **I5 Auditability:** the observable history replays to the current + balances under the oracle's semantics — the ledger is its own proof. +- **I6 Hold integrity:** held funds are neither spendable twice nor + stranded: every hold eventually captures, releases, or expires by + its stated rule, under crashes and retries alike. +- **I7 Conversion integrity:** a conversion's legs, rate authorisation + record, and cap reservation agree at every observable point (per + #5828 §2); a failed conversion leaves no leg posted without its + compensating path existing. +- **I8 Event fidelity:** the events emitted on posting (§5676 + interfaces) match the oracle's postings one-for-one, in order per + account — other subsystems react to events, so event drift is + ledger drift. + +### 3.5 Corpus and cadence for Leg 1 + +Every shrunk failure joins a permanent regression corpus that runs on +every PR (§6). Generative runs rotate seeds on the nightly cadence +and record the seed ledger; a seed that found a failure is pinned +until the fix lands. + +## 4. Leg 2 — crash injection + +### 4.1 Method + +Faults are injected at *declared fault points* — deterministic hooks +in the harness at the exact boundaries where a stage design claims +recovery — not by random production-style chaos. Each campaign is: +arm a fault point → run a workload (§3 generators at low volume, or a +scripted scenario) → inject → recover by the stage's own procedure → +judge with the recovery oracle (§4.3). Random chaos tooling in a +staging twin is permitted *in addition* once the declared points pass; +it never substitutes for them. + +### 4.2 Fault-point catalogue (minimum, per stage) + +Shared points (all stages): client crash between intent and posting; +duplicate delivery of any internal message; front-end instance kill +mid-request; clock skew across the quote-expiry boundary; process +restart during reconciliation. + +- **Stage A (§5824's claims):** Redis kill before/after the Lua posting + and before the regular-store write-through; total Redis loss + (rebuild from the system of record); regular-store unavailability + during write-through; reconciliation running against a half-rebuilt + hot store. +- **Stage B (§5826's claims):** coordinator crash after each saga step + (intent durable, hold placed, first leg posted, second leg posted, + completion recorded); one shard DB unavailable mid-saga; directory + service returning a stale currency→DB mapping during rebalancing; + compensating leg itself crashing. +- **Stage C (§5827's claims):** TigerBeetle pending-transfer timeout + and void path; adapter crash between TigerBeetle commit and local + recording; dual-run divergence injected during B→C shadow posting + (the comparison must catch a one-leg difference); cutover aborted + mid-currency. + +Each stage design ticket may add fault points; it may not remove one +of these without amending this record — the catalogue is the floor +the parent's "atomicity under injected crashes" requirement +(#5676, Correctness & verification) is cashed out against. + +### 4.3 Recovery oracle + +After recovery, three checks, all decidable: (i) **no lost committed +work** — every operation the client was told committed is present +with its original outcome (I4/I5); (ii) **no invented work** — every +present posting traces to an admitted intent; (iii) **convergence** — +the reconciliation checker (§5676) reaches agreement between hot +store and system of record within the stage's stated bound, or has +filed its stated discrepancy alert. A campaign that "recovers" by +operator intervention beyond the stage's documented procedure is a +failed campaign with the intervention recorded as the finding. + +## 5. Leg 3 — per-stage performance envelopes + +### 5.1 Load model + +Open-loop load generation (offered load does not wait for the +system), with three named profiles: **steady** (the stage's sustained +mix), **hot account** (Zipf-skewed transfers concentrating on 1% of +accounts, per #5676's hot-spot requirement), and **burst** (10× +steady for 60 s, then back — queue-smoothing headroom is measured, +not assumed). The operation mix is fixed per campaign: 80% plain +transfers, 10% balance reads, 5% conversions, 5% hold lifecycle — +conversion share is deliberate: conversions are the most expensive +declared operation at every stage (#5828). + +### 5.2 Envelope semantics + +An envelope is a set of pre-registered floors/ceilings a stage must +meet under a named profile on the staging twin: sustained throughput +floor, posting latency p99 ceiling, balance-read p99 ceiling (with +its staleness bound where reads are cached, per #5676's open +question — the *bound* is the contract, staleness inside it is +legal), and recovery-time ceiling (from fault injection §4 to full +service). Meeting the envelope is a pass/fail verdict, not a +benchmarketing number: the campaign report publishes the whole +distribution, and the verdict cites the worst profile. + +### 5.3 Initial envelopes (design targets, not measurements) + +These are the starting targets the first campaigns measure against. +They are deliberately conservative floors for a single-region +deployment; §5.4 governs how measurement replaces them. + +| Stage | Sustained floor | Burst floor | Posting p99 | Read p99 (staleness) | Recovery ceiling | +|---|---|---|---|---|---| +| A — Redis + regular store | 2,000 tps | 6,000 tps / 60 s | ≤ 50 ms | ≤ 10 ms (≤ 1 s cached) | ≤ 5 min from Redis loss to rebuilt hot store | +| B — multi-Turso | 8,000 tps aggregate; 1,500 tps per currency shard | 24,000 tps aggregate / 60 s | ≤ 80 ms intra-shard; saga reaches pending ≤ 800 ms, settles p99 ≤ 5 s | ≤ 15 ms (≤ 1 s cached) | ≤ 15 min per-shard restore; saga drain ≤ 10 min | +| C — TigerBeetle | 20,000 tps | 60,000 tps / 60 s | ≤ 20 ms | ≤ 10 ms (≤ 1 s cached) | ≤ 15 min replica failover; dual-run divergence = 0 | + +### 5.4 Amendment rule + +An envelope number changes only by: a published campaign measurement +(§5.5), a written amendment to this record citing that measurement, +and a note on #5829's programme successors (the campaign report). +Numbers never change inside the PR that also changes the code being +measured. Expectation, stated now so later readers can check it: +Stage A and B numbers should be *raised* by first measurement +(they are floors set blind); a proposal to *lower* one is a design +event that reopens this record, not a tuning tweak. + +### 5.5 Publication + +Every campaign publishes an envelope record: stage, adapter build, +environment size, profile, offered vs achieved load, latency +distributions, verdict per envelope line, and the seed/fault ledger +for correctness legs run in the same campaign. Records are kept with +the stage's design documents, so #5825's trigger reviews cite a +record, not a recollection. + +## 6. Cadence and gates + +| Cadence | Legs | Bar | +|---|---|---| +| Every PR touching a currency adapter or the shared layers | #5823 contract suite; regression corpus (§3.5); smoke generative run (fixed seed set) | All pass; no exceptions | +| Nightly | Full generative rotation (fresh seeds), declared fault-point matrix at low volume | Failures file findings against the stage's ticket the same night | +| Stage gate (before a stage may serve production traffic, and before any stage transition) | Full campaign: all three legs, all profiles, full fault catalogue | All legs pass; envelope record published (§5.5); untested sibling claims (§1) listed and either tested or explicitly waived on the stage's ticket | +| Quarterly / on envelope amendment | Soak: 24 h steady profile + hot-account profile, reconciliation convergence sampled hourly | No invariant drift; convergence inside bound throughout | + +## 7. Alternatives rejected + +- **Example-based tests only.** The failure space is interleavings + and crash points; hand-written cases demonstrably under-cover both + (the repo testing doctrine says the same: examples are smoke, not + proof). Rejected as the programme's core; examples remain as the + contract suite's form, under #5823. +- **A separate verification design per stage.** Forks the oracle per + backend, so stages stop being comparable and a swap reopens + verification design instead of re-running it. Rejected; this is + the fork §1's boundary exists to prevent. +- **Load testing only at stage transitions.** Envelopes measured once + are archaeology by the next quarter; regressions arrive with + ordinary changes. Rejected in favour of nightly/stage-gate cadence + with PR smoke legs. +- **Production chaos first (chaos tooling against live traffic).** + The declared-fault-point method (§4.1) finds the recovery bugs + deterministically and replayably; production chaos before the + staging campaigns pass would risk real funds' invariants for + strictly worse evidence. Rejected as the primary method; staging + chaos is allowed as a supplement. +- **Vendor APM/benchmark numbers as envelope evidence.** Not + reproducible from seed + build, and not run against this port. + Rejected; envelopes are measured on our staging twin or not + published at all. + +## 8. Parent decisions consumed, unchanged + +From #5676, taken as given: the three stages and their order; the +double-entry invariants (restated operationally as I1–I8, §3.4 — +a restatement for testability, not a change); the interfaces that +must not change across stages (they are the port surface under +test); single-region strong consistency as the v-next promise, with +multi-region explicitly deferred (envelopes in §5.3 are +single-region numbers); and #5676's own verification requirements, +which this record cashes out rather than replaces. From #5828: the +conversion outcome vocabulary and per-stage atomicity claims, used +as oracle states (§3.2) and fault obligations (§4.2). **Changes to +#5676 decisions proposed by this record: none.** + +## 9. Invariants for implementation (programme level) + +Beyond I1–I8 (which bind the currency implementation), the +programme's own implementation must hold: **P1** every finding is +replayable from (seed, fault schedule, build) alone; **P2** the +oracle is never edited to match a backend — a disagreement is a +finding against the backend or an amendment proposal to this +record, decided in the open; **P3** envelope thresholds are changed +only by §5.4; **P4** a stage's campaign report lists every sibling +claim it did not test (§1) — silence is not coverage. + +## 10. Follow-ons (named next actions) + +Filed as implementation work when the corresponding stage's +implementation is scheduled — not before, so the tickets land +against real adapters: + +1. **Programme harness** (with Stage A implementation, #5824): + reference-ledger oracle, generators, regression corpus, CI legs + per §6. +2. **Crash-injection harness + Stage A fault catalogue** (with + #5824): the §4.2 Stage A points as declared hooks. +3. **Load twin + envelope campaign tooling** (with #5825's first + trigger review): profiles of §5.1, publication per §5.5. +4. **Stage B and Stage C campaign extensions** (with #5826 / #5827 + respectively): fault catalogues and envelope lines of §4.2/§5.3 + as those adapters land. + +Each follow-on, when filed, links this record and #5829; the stage +gate row of §6 is what makes them non-optional. + +## 11. Open questions (deferred, with owners) + +- Whether the generative oracle should also model *fee and rounding* + edge semantics from #2063 at full fidelity from day one, or from + the first conversion-bearing campaign. Owner: programme harness + follow-on (§10.1); default until decided: full fidelity for + amounts, fee paths modelled at Stage B (first saga stage). +- Cross-region envelopes are out of scope until #5676's deferred + multi-region question is reopened; no owner until then.