Compare commits

...

238 commits

Author SHA1 Message Date
6fa93bb115 docs(commit-history): record the 2026-09-15 cherry-pick — 129 commits dev → master, three features left behind
- cherry-pick table row + a per-prefix `dev` → `master` sub-table (39 prefixes,
  regenerable from the `-x` trailers) + what the pick taught: "already on
  master" is the mapping table, never prose (`79e6da4` had never been
  picked); earlier picks had dropped hunks; excluded tracks leave dangling
  links; the equality proof (master + the 70 excluded commits == dev in code)
- registry: statuses for every prefix picked or deliberately left (wmux,
  lang-18, porch2-rng), rows for the unregistered ones (tls/crypto/rv2-*/net,
  docs-only prefixes, one-off fixes)
- obligations for the wmux pick: the `justfile` recipe and wmux-accept.sh's
  WO_EPHEMERAL edits
- board: standup entry for the landing — what moved, what stayed and why,
  every gate count on master, the known fibers TSan red, what is next

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-15 01:35:38 +02:00
463e1acefb fix(gate): web-app keypool leg opts into WO_EPHEMERAL=1 — refused since databasev2 2 task 6a
- the leg copies the porch package, whose store declares RateLimitCounter
  default-durable, and ran the check program with no WO_DATA: since 6a that
  is a startup refusal, so `just web-app` read 56 checks, 1 failure on dev
  and on master alike — the 6a blast-radius pass missed this leg
- RAM-only opt-in on that one run, boot notice filtered from the byte-exact
  compare (the db-actor / wmux pattern); web-app 56/0

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 1ce195da25f527eb1fed3e9e6b8843e00315f25e)
2026-09-15 01:34:13 +02:00
37d3ba1543 fix(compiler): woc build -o creates the output's parent directory — a fresh checkout has no target/
- `woc build <dir> -o <example>/target/<name>` wrote its temp file beside the
  output and failed with "No such file or directory" when target/ was absent;
  target/ is gitignored, so every fresh checkout hit it — the db-actor and
  db-bench gates went red on a clean master worktree while passing on dev,
  where the directories exist from history
- the driver now creates the output's parent (mkdir -p shape) before the
  temp write; project-mode builds and existing directories are unchanged
- single-binary-smoke.sh gains `build-into-missing-dir` (4 checks, was 3),
  red on the old driver, green on this one; woc-test clean

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit e9213bb949e1c26cb3a29d6f9babf2322a82d839)
2026-09-15 01:34:13 +02:00
ed2786c6ea fix(gate): web-app-accept.sh executable bit — just web-app failed with "Permission denied"
- mode 100644 -> 100755, matching every other scripts/*-accept.sh

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit ec797d9646acc9519d21358dc28f5443a88940cd)
2026-09-15 01:25:39 +02:00
aa13b2125f refactor(porch-store): re-scope porch 1 to the limiter, revert idempotency
- idempotency built, reviewed, then reverted WHOLE to the tag
  archive/porch-idempotency. Not a design failure: it passed its gates.
  It provokes a C-runtime SIGSEGV in wo_arena_alloc/wo_str_new under
  concurrent call()-parked callers
- the evidence for that attribution: over ten gate runs every failure
  was an idempotency leg and none was the limiter's, which drives the
  same pool through the same call/park machinery. The begin arm has 5x
  the allocation sites inside receive and moves a whole Req plus a
  Handler through the mailbox
- before the split the suite reported 0 to 6 failures run to run; after
  it, five consecutive runs at 56 checks, 0 failures
- PoolMsg loses digest/req/handler, and NullHandler/dummy_req/fresh_req
  go with them — every rate-limit count used to allocate a throwaway
  Req it never read
- IdempotencyKey is KEPT and commented: the schema is settled and the
  digest-as-column decision cost a review round to get right
- the limiter's saturation 503 has no leg of its own now (§19 drove
  Idempotent). Stated in the README rather than papered over — a
  deterministic leg needs a slow actor, and only the reverted arm was
- new: porch 9 (idempotency, on hold) and language 41 (the arena crash,
  with the reproduction harness and the evidence that localises it)

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 79e6da4465133dc555e913c960d544ef1c7bedd8)
2026-09-15 01:25:00 +02:00
f3215c2f43 docs(status): master-only follow-ups to the 2026-09-15 cherry-pick
- the agent rename database-developer → codd (and its guide) happened inside
  lang-18's `aab4878` on dev, which stays there; the `docs(agents)` pick
  brought codd.md in beside the old file — remove the old name and its guide
- docs/stories/porch/09-idempotent-replay.md: added on dev by `79e6da4`, whose
  earlier pick onto master (`refactor(porch-store)`) landed without it — the
  board, porch 1 and porch 4 link to it
- docs/stories/porch/10-memory-features-over-table.md: the refine stub
  language 18's docs commit created on dev; the board and porch 00-story link
  to it, the code it waits on is not on master
- docs/examples/skill-catalog/README.md: the story link fix from `b3d8c40` that its
  earlier pick (`8311330`) dropped in conflict resolution — dev's version taken
- `just linkcheck` on master: every remaining broken link is a wmux story or
  spec (track not picked) or a developer-local `.dev/reference` symlink

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-15 01:24:36 +02:00
3a73938d2e docs(status): reconcile board, graph and story tables with the 2026-09-09..11 landings
- board: language 18 row (hold lifted 2026-09-11, split — 18 keeps
  transaction { }, cache/flags/jobs to porch 10); In-progress rows for
  databasev2 4 part B / 5 / language 18 and the Active slice; databasev2
  rows 2 (CLOSED, 6a), 4 (part B re-brainstormed), 5 (ready), 7 (CLOSED),
  13 (new); the held list drops 18
- dependency graph: new §8 databasev2 (nodes 1–13, edges, states table);
  graph 1's 23/32 nodes turn done and their edge becomes undirected (they
  compose; neither needs the other); language 18 / porch 10 nodes and
  edges across the porch and language graphs; wmux gains the databasev2 2
  edge (DB2W) the prose already named
- databasev2 00-story: sequence rows 1/2/4/5/7/8/11/12/13/14, the ASCII
  graph (2 no longer needs 1; 2 → 11, 12) and the order rationale
- 01: the budget finding redirected to 5; 06: the Needs line marked
  superseded, task 7's 2026-08-30 measurement quoted; 09: the report's
  group-by is still refused, schema-sharing is language-track work; 10: an
  in-tree signing answer exists (rv2 9), Ed25519-vs-reuse still open
- porch 00-story: row 10 (memory features over @table, refine stub) and
  the "not porch's" table updated for the split

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 423b3c187b626f69da1ddb942c3c7849a3ee5a73)
2026-09-15 01:16:24 +02:00
96af299663 docs(db2-14): the shop workload story — what an order-taking web app needs from the store (refine)
- inserted 2026-09-12 from a developer question ("would I build an
  e-commerce site on writeonce?"): the load is a non-question — a hundred
  orders a minute is under two durable writes a second against an engine
  that group-commits thousands; what the developer hits is the SHAPE of the
  query and schema surface, measured against PostgreSQL habits
- goals, each its own future slice: range queries and ordering through an
  ordered index (today's indexes are equality-only hash buckets); `skip`
  beside `take` (specced 2026-08-15, never built); group-by aggregation for
  the reports (parser accepts, types.ml refuses — owner: language track);
  composite unique, check rules, on-delete policy beside FK restrict;
  export/import and a read-only attach (databasev2 9)
- Given/When/Then per page or report of docs/examples/shop; out of scope;
  the forks left open for a brainstorm before any slice starts; progress
  and history empty — `status: pending`, `readiness: refine`

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit f33ae982c954d5478d549a6dc5f15463de43ab1b)
2026-09-15 01:16:24 +02:00
f8b470d7cf docs(db2-5): brainstormed to ready — twelve forks; the resident byte budget arrives as Phase A
- `readiness: ready`, `review_pending` (forks 1–12 settled 2026-09-10 by
  codd-shoney under autonomy; look first at the cuts — fork 4 no
  back-pressure, no cross-table shedding, no warn threshold; fork 2 the
  per-table bound is rows only; forks 3/7 the default budget)
- two independent questions: RAM for all tables is one process budget in
  bytes (`WO_DB_MB`; unset = the default, never "no budget"), breached by
  refusal — the crossing insert traps WO_T_OOM, one stderr line names the
  largest table, the budget and its source; during replay the crossing is
  exit 2. Capacity of one table is `@table(max_rows: N)` with `on_full:
  refuse | drop_oldest`; drop_oldest legal on `durable: false` only,
  oldest = smallest live id; eviction never touches a durable table
- the default is the kernel's limit minus what the process holds at boot:
  cgroup v2 memory.high/max up the ancestry, else MemAvailable, minus VmRSS
  before replay — no fraction, no invented reserve; headroom is MEASURED
  (A4 re-runs iteration 1's 64 MiB swap-off leg, refusal must precede kill)
- estimate = what the engine asked the allocator for, chunk-rounded; keys
  tables count what is resident; observed on the WO_WAL_STATS exit line
- phases A–F, progress A1–A4 / B1–B3 / D1–D2 / F1 / P1 with owners; `.wob`
  v9 carries max_rows + policy; `status: pending`, Phase A startable now

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 579199af01581ebad3d2fa5f7e208745b210e9f9)
2026-09-15 01:16:24 +02:00
15b15dbe1c docs(db2-4b): part B re-brainstormed — the async barrier on the corrected premise, ten forks
- retitled "group commit, and the async barrier"; the 2026-08-15/20/28
  banners compressed into a trail; `readiness: refine`, `review_pending`
  (forks 1–5 and 8–10 decided under autonomy 2026-09-10 by codd-shoney;
  6 and 7 keep readiness at refine)
- what part B is FOR: the read tail on shard 0 while a barrier blocks — and
  only that; mechanism: the drain pwrites as today, then submits ONE bare
  IORING_OP_FSYNC and keeps working; held replies released by the
  completion; the epoll fallback is part A unchanged; ordering with
  compaction and the deferred drops/re-points; the inline durable write on
  shard 0 unified through its own inbox while a barrier is in flight;
  completion delivery on a busy shard 0; shutdown reaps an in-flight
  barrier before wo_wal_close
- fork 6 (kernel floor and raw-syscall shape) goes to lintor; fork 7
  (go/no-go) is settled by one measurement — tmpfs vs ext4 `mixread.p99` —
  then one developer answer; both answers already sit in
  .dev/zack/databasev2-4b.md, the fold into this story is pending
- progress table B1–B9 with sizes and owners (cyril B1/B8, lintor B2, the
  runtime agent B3, codd + pm B9); no new knob, no new dependency

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 7ceb7b8805da41e67661744746bf2d0b7879cc50)
2026-09-15 01:16:24 +02:00
54b160070f docs(db2-keys): databasev2 13 story — fresh-log keys-resident seed SEGV, fixed 6310078 + 1b6750d
- symptom: `seed` of docs/examples/residency on a FRESH log, rc 139, in both
  WO_DATA forms — found smoke-testing databasev2 7, independent of it
- root cause, two defects composing: wo_wal_fold_row_at wrote `*msg`
  unguarded while wo_idx_probe borrows with msg = NULL; and the databasev2 12
  schema head was staged lazily AFTER db.c captured the first keys-resident
  row's offset (`koff`), so that offset pointed at the schema record
- fix (already on dev, prefix db2-keys): wo_wal_next_offset stages the
  pending head before returning an offset; the fold tolerates a NULL msg;
  both failing-first, and a control build with wal.c reverted reproduces
  the trace
- third finding: residency-accept.sh never checked seed's rc, so 20/0 was
  green over a crash — `e274f4a`; the gate is 32/0 since
- `residency.keys.fit` rc 74 confirmed a SEPARATE defect (compaction/replay
  of keys-resident offsets), still open under codd.md "Next bugs"
- `status: done`, `readiness: ready`; counts test_wal 6629 → 6660,
  make -C runtime test 8462/0 at the time of the fix

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit b5b1da795917f0446a1e4a0317d9136c33acb262)
2026-09-15 01:16:24 +02:00
9b5498fafe docs(db2-7): story closeout — acceptance met per task, progress table, WO_DATA is always a path
- frontmatter `status: done`, `readiness: ready`, `review_pending` (the
  nonexistent-path rule settled under autonomy 2026-09-10)
- every criterion met with its evidence: task 1 smokes A–D (`b31bd40`),
  residency section 8 checks i–vii (`aaea6b2`), db-bench `--wo-data-file`
  181 checks / 5 failures — the same 5 as the directory form
  (`residency.keys.fit` rc 74, databasev2 13's sibling, not this defect),
  temps-beside-the-log test plus its mutation control (`ccee2d0`)
- the fork, settled: existing dir or trailing `/` → <dir>/shard-0.wal,
  byte-identical; otherwise the path IS the log, created behind an existing
  parent; a missing parent or a non-regular non-directory path refuses,
  exit 2, naming path and parent — never a silent mkdir -p
- `WO_DATA` stays a path: ephemerality is WO_EPHEMERAL=1 (databasev2 2 task
  6a), so the file-vs-directory parse carries no `:memory:` sentinel
- progress table with the four hashes; history

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 38f4f1e5832e79b9834a93fd6c3273fefe5eeadc)
2026-09-15 01:16:24 +02:00
79352bd95c docs(agents): the persona roster — codd/fielding/ada families, lintor, README
- database-developer becomes `codd`: scope is the whole embedded DB (engine,
  runtime seams, the compiler's @table/query surface); doctrine rewritten
  from what landed (fatal commit, group commit per drain, checkpoint by
  rename, delta fold, schema head, v8 table bit, no-WO_DATA refusal); file
  map with anchors; state as of 2026-09-11; architect only — no gates, no
  tests, names the checks for cyril and the tasks for zack
- one four-role pattern shared by three tracks: `<architect>` brainstorms
  and owns contracts, `-zack` implements ONE ready iteration with a
  resume-safe ledger under .dev/zack/, `-cyril` owns every test above unit
  level and the gate ladder, `-pm` keeps stories, board and graph truthful
  (`model: sonnet`); families codd (database), fielding (porch), ada (jarvis)
- `codd-shoney` is the developer's proxy: brainstorms `refine` stories to
  `ready`, reviews `review_pending` forks; `lintor` the kernel consultant
  over .dev/reference/linux
- README: roster (reads, gates), the families rule, proposed agents not yet
  written and the order to add them
- docs/guides/codd-subagent.md, 00-doc-audit.md, 08-project-structure.md
  follow the rename

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 830bbb16d5dd990478149678c642857bb65466f4)
2026-09-15 01:16:24 +02:00
7acd085f46 test(db2-chains): the oracle closes databasev2 11's last criterion — keys vs all across 3×K flattenings and a replay
- test_oracle_all_vs_keys_same_update_sequence continues the shared
  sequence 3×WO_DELTA_MAX_HOPS steps, alternating scalar and Text, and
  asserts the `resident: all` and `resident: keys` rows equal after EVERY
  step; the fold's hop count proves the chain terminated at least twice and
  never exceeded K; then the keys log replays into a fresh store and is
  compared against the oracle once more — the criterion as written, which
  the story carried as ⚠ "an expected value, not an oracle table"
- wal.h: wo_wal_append_row_image's comment claimed the flattened image is
  written as WO_WAL_INSERT; it is WO_WAL_UPDATE — an INSERT would replay as
  a duplicate id; compaction alone writes INSERT, into a FRESH log — as 11
  landed it and its story recorded
- story 11: the criterion flips to ✅ naming the test; the sequencing note
  and out-of-scope bullet record task 7's 2026-08-30 measurement (16× vs
  105× collapse under a cap, 1.53× faster than swapping) — the work stands
- test_wal 6295 → 6880 pass, 0 fail; 21 runtime suites 0 fail

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit d841390f3087a0c2542ddf23f25f15037a7d4d71)
2026-09-15 01:16:24 +02:00
296efb52ed docs(db2-ephemeral): databasev2 2 closes — task 6a contract, forks 1–7, the README sweep
- story 02: `status: done`, `review_pending` (forks 1–7 auto-approved for
  autonomy); progress rows 6a ✅, 6b ➡ databasev2 5 Phase A, 7 `a310496`;
  5c/5d rows cite the `dev` hashes (the pre-merge ones were unreachable);
  task 6a's Given/When/Then met; Info records the seven forks (sentinel over
  `:memory:`, its rules, the refusal contract, startup-only, the budget
  leaves for 5, library-owned tables bind consumers, the v8 table bit);
  History keeps the first cut that refused every class-bearing program
- database/src/CODE-LOGIC.md: "Startup refusal + WO_EPHEMERAL" — contract,
  hatch, table bit, measured blast radius, deferred items, proof; the
  dispatcher paragraph no longer says a failed commit un-applies the row
  (fatal since databasev2 4 part A; WO_T_IO unreachable from a write path)
- residency spec + plan: task 6 items annotated with the 2026-09-09
  decisions; the byte budget marked moved to databasev2 5
- README, seven example READMEs and four guides carry the one-line rule
  (durable default refuses without WO_DATA; WO_EPHEMERAL=1; durable:
  false); shop's RAM-only command sets the sentinel

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 2c3531998124042fe736388e8b926abda3841194)
2026-09-15 01:16:24 +02:00
41f48bba3f test(db2-ephemeral): gates opt into WO_EPHEMERAL=1 where a durable table is declared; residency section 7
- residency-accept.sh section 7, six checks: the refusal names the class
  and all three ways forward (exit 2); WO_EPHEMERAL=1 runs from RAM with
  the boot notice and a write round-trips; WO_EPHEMERAL with WO_DATA
  refuses; WO_EPHEMERAL=2 refuses naming the accepted value; keys-resident
  still refuses under the hatch; a plain class (the corpus `methods`
  fixture) runs with no WO_DATA, rc 0, nothing on stderr
- blast radius measured gate by gate — each run without the export first,
  kept only where the program refused: oop-e2e (fixtures declare tables);
  db-bench.py's ram/msgrate/growth/randread legs (the durable legs drop it,
  so a WO_DATA in the caller's shell now refuses loudly instead of silently
  turning a RAM leg durable); db-actor per run (its restart pair sets
  WO_DATA); chat (porch's store declares RateLimitCounter default-durable —
  a library's table binds the consumer); wmux client legs (same image as
  the server, no WO_DATA; servers and the WO_DATA-carrying r11cli `env -u`)
- byte-exact compares (db-actor single-shard, wmux client) drop the one
  notice line; fibers, subprocess, log-watcher declare no table — untouched
- db-bench.py ceiling note: the checked refusal is databasev2 5's now
- residency 32/0, oop-e2e 131/0 with this tree

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 4553ca15da235c155b7ad31bbb077c3ad8e88fee)
2026-09-15 01:16:24 +02:00
d38b4f864b feat(db2-ephemeral): refuse a durable table without WO_DATA; WO_EPHEMERAL=1 opts out; .wob v8 table bit
- main.c, startup only: WO_DATA unset and a class carrying WO_CLASSF_TABLE
  without WO_CLASSF_VOLATILE (`durable: true`, the default) refuses — exit 2,
  one stderr line naming the class and the three ways forward (WO_DATA=<dir
  or file>, WO_EPHEMERAL=1, @table(durable: false)); before, every write
  was silently dropped at exit — the one outcome `durable: true` forbids
- WO_EPHEMERAL=1 (exact value) is the whole-program escape: one boot notice,
  rc 0, the RAM path byte-for-byte the old one (db.c untouched); any other
  value refuses; set alongside WO_DATA refuses regardless of tables; the
  `resident: keys` loop still wins and is not rescued
- .wob v8: WO_CLASSF_TABLE 0x08 (WO_CLASSF_ALL 0x0f), set from emit.ml's
  cr_is_table — the first cut keyed on !VOLATILE and refused every
  class-bearing program (fibers' Tick, subprocess's ConnMsg), because v7
  spelled `durable: true` as the mere absence of a bit
- loader refuses VOLATILE/RESIDENT_KEYS without the table bit ("storage
  flags on a class that is not a @table"); a v7 image is refused by the
  exact-match version check, as v7 refused v6; disasm prints `table`;
  runner.ml's independent validator carries both rules; obj.h comment
- test_loader: test_storage_flags_need_table (forged flags word: both
  refusals, and the same bits WITH the table bit load); no golden moved
- contract: docs/plan/oop-vm/00-wob-format.md "v8: the table bit"

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 863692a590d426da0047831ae315142ef5b24416)
2026-09-15 01:16:13 +02:00
0435bd96f5 docs(commit-history): claim prefixes db2-ephemeral, db2-4b, db2-5, db2-14, agents, status
- registry rows for the prefixes this landing uses, claimed before their
  first commit as the file requires: `db2-ephemeral` (databasev2 2 task 6a),
  `db2-4b` (part B re-brainstorm), `db2-5` and `db2-14` (story docs),
  `agents` (the persona roster), `status` (cross-track board/graph sweeps)
- `db2-7` and `lang-18` registered after the fact — both already have
  commits on `dev` (`b31bd40`, `6b4b960`) and had no row

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit d0e658f06df8f3390d56841bdb4093cb8d509fb8)
2026-09-15 01:16:13 +02:00
156b04d28d fix(db2-keys): wo_wal_fold_row_at tolerates msg == NULL
- Second half of the fresh-log seed SEGV: every `*msg = ...` in the fold
  was unguarded, and `wo_idx_probe` (table.c:373) borrows with `msg == NULL`
  because a candidate that does not fold is simply not a hit; a malformed
  record under an index probe was therefore a zero-page write.
- Guard: `const char *sink; if (!msg) msg = &sink;` at the top of the fold;
  wal.h documents [msg] as optional. A future malformed record refuses the
  candidate by name instead of segfaulting.
- Failing test first: `test_fold_row_at_tolerates_null_msg` (test_wal.c) —
  head-only log, fold at offset 0 (schema record) and past the tail with
  `msg == NULL` -> -1 both; with a real `msg` the names "record header is
  malformed" / "no intact record at that offset" still arrive. Pre-guard:
  ASan SEGV `wo_wal_fold_row_at wal.c:1886` from the test.
- Gates: test_wal 6660/0 (was 6650); `make -C runtime test` 21 suites
  8462/0 (was 8452); wovm-asan clean; residency `seed` fresh dir + fresh
  app.db rc 0 under wovm_asan.
- CODE-LOGIC §Schema migrations bullet extended with the guard + test.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 1b6750d78db991af464994c2188d219519dfe16f)
2026-09-15 01:16:13 +02:00
0b9f09fc12 fix(db2-keys): stage the schema head before the first offset capture
- `seed` of docs/examples/residency (`resident: keys`) on a FRESH WO_DATA
  segfaulted rc 139 in both the dir and the file form; pre-existing.
- Root cause: the databasev2 12 head record was staged lazily INSIDE the
  first `wo_wal_append_*` (wal.c `stage()`), after db.c:78/293 had read
  `koff = wo_wal_next_offset(w)`; the first keys-resident row was re-pointed
  at the schema record and its first read folded "record header is
  malformed"; `wo_idx_probe` borrows with `msg == NULL` -> zero-page write.
- Fix: one helper `stage_schema_head` shared by `stage()`,
  `wo_wal_ensure_schema` and `wo_wal_next_offset` (no longer a pure inline):
  the head is staged before any caller observes `off + len`. Still lazy,
  never for a log that stays empty; head-stage OOM is `wo_wal_stage_fatal`.
  db.c untouched; compaction/migrate stage the head explicitly, unaffected.
- Failing test first: `test_keys_resident_fresh_log_first_row` (test_wal.c),
  the db.c:78 sequence call for call, then read-by-id, `wo_idx_probe`,
  replay. Pre-fix: `koff != 0` FAIL, `wo_row_read` -1 "record header is
  malformed", ASan SEGV `wo_wal_fold_row_at wal.c:1871` via `table.c:373`.
- Gates: test_wal 6650/0 (was 6629); `make -C runtime test` 21 suites
  8452/0 (was 8431); wovm-asan clean; residency `seed` + restart `order`
  under wovm_asan rc 0 on a fresh dir AND a fresh app.db; a control build
  with wal.c/wal.h reverted reproduces the SEGV.
- CODE-LOGIC §Schema migrations: "Head before any offset capture" bullet.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 631007839451fb970e9dec83338d19c09b3043ab)
2026-09-15 01:16:13 +02:00
58dcb1f969 test(db2-7): gate leg for WO_DATA=<file> — residency section 8, db-bench --wo-data-file
- residency-accept.sh section 8 (11 checks): file-form seed -> restart prints
  the directory form's line; `find -mindepth 1` shows exactly app.db; missing
  parent exits 2 naming path + parent, no mkdir -p; a fifo exits 2 "neither a
  regular file nor a directory"; `d/` still writes d/shard-0.wal; `nodir/`
  keeps the pre-7 "cannot open .../nodir//shard-0.wal" bytes; WO_EPHEMERAL=1
  with the file exits 2 on the 6a conflict
- kill -9 battery against app.db: stdbuf -oL vehicle, asserts the kill landed
  (rc 137) before verifying every acked row replays; forced compaction
  (WO_CHECKPOINT_BYTES=1, WO_WAL_STATS proves >= 1 ran) leaves app.db the only
  artifact and every row replays
- failing-first on the pre-7 wovm: 9 of 12 new checks red ("cannot open
  .../app.db/shard-0.wal"); the two trailing-slash pins and the 6a conflict
  pass by construction — they pin what must stay byte-identical
- db-bench.py --wo-data-file: restart proof + crash battery against
  <tmp>/app.db, legs tagged .file, file form also asserts app.db is the only
  artifact; no metric, bench/baseline.json untouched; quick run unchanged
  without the flag (181 checks / 5 failures both ways, all five the known
  residency.keys.fit rc 74)
- READMEs: db-bench env-knob row for WO_DATA=<path>.db + the driver flag;
  residency run instructions name the file form
- gates: just residency 32/1 (the seed rc, pre-existing), make -C runtime
  test 21 suites 8452/0, just oop-e2e 129/0

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit aaea6b2c0f818efd0cdf472ccbd9bdd09eac5554)
2026-09-15 01:16:13 +02:00
37c24e13bc fix(gate): residency-accept checks the example's seed rc — read 20/0 while seed SEGV'd
- scripts/residency-accept.sh:155 ran docs/examples/residency `seed` with its
  rc unchecked; the inserts commit before the crash, so the restart legs passed
  on the log a dead seed left behind and the gate read 20/0 while seed died 139
- new check "example: seed exits 0" — its FAIL names the rc (139 = SIGSEGV)
  and the log to read
- failing-first on today's binary: `FAIL example seed -- rc=139`; the SEGV is
  the pre-existing keys-resident fresh-log defect (wo_wal_fold_row_at, HEAD
  wal.c:1837), zack's fix in flight — this check stays red until it lands

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit e274f4a932688bccf8310581199fa0d26f737eea)
2026-09-15 01:16:13 +02:00
ea66761c4e docs(db2-7): contract + CODE-LOGIC — the WO_DATA file form
- docs/plan/oop-vm/04-db-binding.md, WAL section, "Where the log lives":
  WO_DATA is always a path; directory form (existing dir or trailing `/`
  → `<dir>/shard-0.wal`, pre-7 bytes incl. the `//`), file form (the path
  IS the log, created only under an existing parent), the two refusal
  lines verbatim, too-long refused not truncated, one file at any core
  count, compaction/migration temps + parent fsync derived from the log
  path never from WO_DATA, the two pinning tests named.
- database/src/CODE-LOGIC.md, `wal.c — durability`: the resolver's three
  codes and main.c's wording, why no mkdir -p, trailing slash on a missing
  dir kept as the pre-7 `cannot open` on purpose, `parent_dir_of` shared
  by the boot check and the post-rename fsync.
- Both paragraphs sit in regions untouched by the uncommitted 6a/12 doc
  work in the same files; no other docs touched (story/board are pm's).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit f1985bae5d110ed773159393bd82c32b73bfb672)
2026-09-15 01:16:13 +02:00
587991124d test(db2-7): pin compaction + migration temps beside a file-form log
- test_file_form_temps_beside_log (runtime/test/test_wal.c): the log is
  `<dir>/app.db` — an operator's name, not shard-0.wal — with a sibling
  directory `app.db.d/` as the decoy nothing may land in.
- Proof by blocker: a DIRECTORY planted at exactly `<file>.compact` makes
  `wo_wal_compact` and `wo_wal_migrate` each return -1 with the log
  untouched (record count unchanged, blocker still an empty dir); a temp
  anywhere else would have let them succeed.
- Blocker removed: compaction 10 → 2 records, migration n,t → n,t,extra
  succeeds, `<file>.compact` gone after each rename, the directory holds
  exactly {app.db, app.db.d}, the decoy is empty, the migrated file
  replays into the new shape (slots[0] == 107, slots[2] == 0).
- The parent fsync'd after a rename is `parent_dir_of(<file>)`, the helper
  the resolver shares (task 1), so its derivation is pinned there; fsync
  itself is not observable from a test.
- Green on first run (57 assertions) as a pin must be; teeth shown by a
  mutation control — compaction's temp redirected into the decoy turned
  14 assertions red (`wo_wal_compact(&w, &db) == 0, want -1`, …).
- `make -C runtime test`: 21 suites, 8431 pass / 0 fail (was 8374/0).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit ccee2d04fddfb96c7dfab1c17f235e3a9bbc69fb)
2026-09-15 01:16:13 +02:00
c19a01564f feat(db2-7): WO_DATA=<file> — the store as one file, two refusals
- `wo_wal_resolve_data_path` (database/src/wal.c|h): an existing directory
  or a trailing `/` → `<dir>/shard-0.wal` byte for byte (the `//` after a
  trailing slash included); otherwise the path IS the log — opened if a
  regular file, created by `wo_wal_open` if absent under an existing parent.
- Refusals as codes for main.c: WO_WAL_PATH_NO_PARENT (out = the parent, so
  the line names it), WO_WAL_PATH_NOT_A_FILE (fifo/socket/device),
  WO_WAL_PATH_TOO_LONG (today's snprintf truncated silently).
- `parent_dir_of` shared by the resolver and `sync_parent_dir`: the parent
  checked at boot IS the parent fsync'd after a compaction/migration rename.
- runtime/src/main.c: the resolver replaces the unconditional
  `"%s/shard-0.wal"`; each refusal is one stderr line, exit 2 through the
  6a destroy sequence; never mkdir -p. The 6a block is untouched.
- Failing first: test_resolve_data_path — 4× -Werror (implicit declaration
  + three undeclared codes); green after: 21 assertions (dir, trailing
  slash, absent file, regular file, bare name, missing parent, parent is a
  file, fifo, two too-long).
- `make -C runtime test`: 21 suites, 8374 pass / 0 fail (was 8353/0).
  `make -C runtime wovm-asan` clean; smoke: file form seeds + replays with
  `app.db` the only artifact; missing parent and fifo refuse rc 2 naming
  path + parent; dir and trailing slash unchanged; WO_EPHEMERAL conflict
  inherited from 6a.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit b31bd4052624be460de1c18cf208661539397e09)
2026-09-15 01:16:13 +02:00
82efb498d4 fix(compiler): lang-41 side defects — ?T-typed nil try, WO-E305 on moves out of a field
- emit.ml: a `try … catch (e) nil` is `?T` (ty_of_expr) and the nil arm takes that destination, so a `?Int` nil is WO_NIL_SCALAR and an Int body's legitimate 0 no longer reads as nil (it used to fall back to the zero word via the body type / enclosing return type)
- owner.ml: `transfer` on a projection (`d.tags`, `x[i]`) of an owned value reports WO-E305 instead of returning false silently — the silent path compiled `Out { tags: d.tags }` to an alias that both records dropped (the "json.decode as T corruption": not json's, a double free language 44's poison now aborts on); heap scalars exempt (store sites copy)
- error catalog: WO-E305 row; owner.ml module doc updated
- corpus: run/try-nil-int-zero, compile-fail/no-partial-move, run/decode-record-crosses-return (Text copied, record moved whole — the archived `.. ""` workaround is unnecessary)
- verified: oop-e2e 126/0, tests/regress/lang-41 compile, --emit sweep over the non-porch examples, web-app gate 56/0 (porch in project mode) — no legitimate program trips WO-E305
- story 41: both side defects marked fixed; board prose updated

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 2d54710e693fafee4b8d6561cc9cba7b95415d89)
2026-09-15 01:16:13 +02:00
dd426d0581 test(tls): rv2 8 phase E — both AEADs cross-checked against openssl over the wire
- tls-server-accept.sh: each probe pins openssl s_client's -ciphersuites — ec/ChaCha20-Poly1305, rsa/AES-128-GCM, plus openssl's default list whose first suite (AES-256-GCM) the server must skip — 5/0
- tls-accept.sh: the Python/OpenSSL stub prints the negotiated suite; the happy-path ok line carries it — 5/0 (ChaCha under the peer's server-preference default)
- rv2 8 story: E landed (real-protocol interop replaces the infeasible `openssl enc` AEAD check); D (encrypted-cookie wrapper) re-homed to porch as the consumer's phase after porch 2 — fork auto-approved, review_pending; status: done
- porch 2: the encrypted-cookie out-of-scope bullet now points at the landed primitives and names the wrapper as its follow-on
- board row rv2 8: in-progress -> done

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit ac3bf74da4f45f624d7d3b440c8bcf17f4aec3a9)
2026-09-15 01:16:13 +02:00
e1b9ada190 docs(rv2-obs): rv2 7 observability brainstormed to ready
- four forks settled with KISS defaults grounded in runtime/src: counters+gauges only (profiling split out), Prometheus text rendered in .wo from a map<Text, Int>, pull via proc.metrics(), stack trace on trap lands first
- phases A (trace on trap at both trap sites) / B (proc.metrics from existing gc/arena/fiber fields) / C (porch mounts /metrics — consumer's phase)
- builtin id to be confirmed against WO_B_MAX at build time (random_bytes claims 119 per porch 2's brief)
- review_pending marker: forks auto-approved 2026-09-09, developer second review before code lands
- board row: refine -> ready

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit feb11c3aad613ed7f41b280b27c1f6c0dda92ec7)
2026-09-15 01:16:13 +02:00
ed45ac7c06 fix(arena): poison-on-free — a freed block can never pass for a live object (language 44)
- wo_arena_free stamps the header: class_id = WO_CLS_FREED (0xFFFFFFFF), shard_id = 0xFFFF, flags/pad = 0
- freelist link moves from offset 0 to offset 8 so the poison survives on the list; wo_arena_alloc pops from offset 8
- wo_drop_obj aborts first on a poisoned header: a double free is a diagnostic, not a catchable state
- WO_CLS_FREED defined in wob.h beside the builtin id space
- test_arena: test_poison_on_free (poison stamped, LIFO chain through the relocated link, class drains to a fresh bump) — 17/0
- full suite SUITE_ALL_ZERO, wovm + wovm_asan rebuilt, just db-actor 10/0 (lang-41 5x marshal gate unchanged)
- story 44 status: done; board row + dependency graph L44 (41 -.follow-up.-> 44)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 78ae3be403ba533db6f0e181bff201717f789a30)
2026-09-15 01:16:13 +02:00
3b1a188d77 fix(crypto): branch-free EC signing ladder via complete addition (rv2 9 follow-up)
- pmul_ct: double-and-add-always over the Renes–Costello–Batina complete
  projective addition formula (Alg. 4, a=-3) — one exception-free formula for
  add and double, identity (0:1:0), so there is NO point-at-infinity branch.
  Closes the documented residual: the Jacobian jadd/jdouble ladder's fp_zero
  checks leaked k's leading-zero count (a bit-length hint) during ECDSA sign
- wo_ecdsa_p256_sha256_sign uses it; affine x = X * Z^-1 (projective), the
  inversion via the constant-time modexp. Dead Jacobian jmul_ct/jpt_cmov removed
- RFC 6979 A.2.5 vectors still byte-exact (test_crypto 130/0); server loopback
  (signs with this ladder) still green (test_tls 123/0); ASan/UBSan clean
- docs: rv2 9 review_pending — close_notify + complete-formula ladder moved
  from deferred to landed; lang-41 decision 4 fixture marked landed

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit fba30352b965e0f3b749168421a920a832df541b)
2026-09-15 01:16:13 +02:00
d9501ae8e3 fix(tls): send close_notify on TLS close (rv2 9 follow-up)
net.close on a TLS connection now seals a close_notify alert (warning,
close_notify; RFC 8446 §6.1) with the application write keys and sends it
best-effort/non-blocking before the inbound drain + close(). Peers see a
clean end of stream instead of truncation — openssl's "unexpected eof while
reading" is gone (verified), browsers stop treating the reply as aborted.
Covers both directions (one code path). just tls 5/0, just tls-server 4/0.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 54020a45fdb1efab792212170b8f36c2d38d95be)
2026-09-15 01:16:13 +02:00
ad1ad8361c docs(audit): fix stale docs against the code (TLS, net.connect, RNG, lang-41); jarvis deps
Code is the source of truth; these claims no longer matched runtime/src:

- "net.connect does not exist" — landed 2026-09-07 (id 110); net.connect_tls /
  read_tls / write_tls (115-117) + net.accept_tls (118), WO_B_MAX 118. Fixed
  in jarvis 00-story (problem statement + architecture + out-of-scope), porch
  00-story (proxy middleware row), rv2 7 (push-collector fork), 00-code-review
- "TLS: none / proxy-mandated forever" — retired by rv2 9 (in-process TLS both
  directions). Fixed in porch + web-app + site example READMEs (proxy is now a
  deployment choice; HSTS row), 00-code-review
- "no RNG anywhere in the runtime" — imprecise: the runtime has a getrandom(2)
  source since rv2 9 (TLS ephemerals), but nothing exposes it to .wo yet.
  Fixed in CODE-LOGIC (digests), lang 34, porch 2, status lang-39 row
- "porch 9 blocked on language 41" — lang 41 fixed 63065ff. Fixed in porch 1,
  jarvis 00-story, status NEXT PLAN, dependency graph (L41 done, P9 ready)
- dependency graph §7 rewritten: the runtime side is done; jarvis 1 waits only
  on porch (developer's porch-first order). Adds jarvis 1's dependency table +
  the build order that satisfies it
- 00-code-review: a dated 2026-09-09 re-verification appended (record kept)
- site README lives in the writeonce-site submodule: committed there, pointer
  bumped here

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit f1049dd9b7c7770da28bcabfc1cb1324621e7ee6)
2026-09-15 01:16:13 +02:00
00214bd68e fix(vm): marshal cross-shard actor messages (language 41) — the double free
Root cause (decision 1): cross-shard send/call/monitor pointer-shared the
message into the receiver's shard (e->payload = msg_val), so a worker read and
eventually dropped an object living in the sender's arena — a double free, then
a class-0 forge, then a modulo self-route livelock, all downstream of that one
broken invariant ("VM heaps are never read cross-shard", which wo_db_rpc keeps).

- actor_marshal: the sender encodes the message into an arena-independent neutral
  form (wo_db_val_encode, the same marshal wo_db_rpc uses) and drops its own
  original — no pointer crosses an arena boundary, so the double-free class is
  gone by construction. actor_unmarshal rebuilds it in the receiver's arena
  (wo_val_decode_vm) and frees the neutral. Applied to the 4 cross-shard
  producers (send x2, call, monitor) + the 3 consumers (kinds 0/5/7). Same-shard
  paths untouched (the WO_SHARDS=1 fast path never failed). Call replies are
  scalars by contract, so kind 6 needs no marshal.
- eng_settle_inboxes: undrained kind-0/5/7 payloads at teardown are the neutral
  form now — free with wo_db_val_free, not wo_drop_obj (caught by ASan mid-fix).
- decision 2: wo_route_free traps a shard_id >= nshards header (a corrupt/freed
  block) instead of self-routing it into the settle livelock.
- proof: tests/regress/lang-41/cross-shard-marshal.wo (a multi<Text> sent +
  called cross-shard, both sides drop) — clean 12x/5x under WO_SHARDS=4 + ASan;
  shard-settle repro still clean 8x; full runtime suite 0 fail (same-shard
  byte-unchanged). `just db-actor` extended with the new fixture.
- unblocks porch 9. Follow-ups: poison-on-free (decision 3), corpus fixture (4).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 63065ff75799f7f43b2bce6de61e77856799566f)
2026-09-15 01:16:13 +02:00
8992dbd589 docs(rv2-tls): rv2 9 COMPLETE (both directions); retire proxy doctrine; jarvis-after-porch
- rv2 9 story -> status: done. §G G3 landed; ladder A–G complete, live-gated
  both directions (just tls 5/0, just tls-server 4/0). review_pending +
  phase rows + G sub-phases updated
- doctrine retired where the story named it: language 34 ("TLS permanently
  the proxy's job"), language 38 ("proxy-terminated ... no HTTPS clients"),
  porch 00-story ("TLS ... proxy-terminated") — each corrected to point at
  in-process TLS (net.connect_tls / net.accept_tls)
- status board: rv2 9 row DONE + a top summary; NEXT PLAN = porch then
  jarvis (sequencing set: jarvis follows porch)
- jarvis 00-story: sequencing note (no longer runtime-blocked; porch first)
- CODE-LOGIC: the inbound-server section (net.accept_tls, signing, slot
  refactor, RST-drain, gate)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit f3a3c962e5f288c25e505851edef4e0a5df9a85f)
2026-09-15 01:16:13 +02:00
e1d29d63e4 feat(tls): net.accept_tls — inbound TLS 1.3 termination (rv2 9 phase G3)
- net.accept_tls(listener, certfile, keyfile) -> Int (id 118, WO_B_MAX->118):
  accept (parks like net.accept), load+cache the server identity per path in
  the shard, run the blocking deadline-bounded server handshake, return a TLS
  conn fd. Real clients terminate against the runtime — no front proxy
- wo_tls_conn refactored: holds the negotiated application keys (not an
  embedded driver), so read_tls/write_tls serve both client and server
  connections via the record layer; the handshake drivers are transient
  (heap, ~100KB, freed after). net.close drains a TLS conn's inbound before
  close() so it sends FIN not RST (clients send close_notify)
- server handshake loops past the client's change_cipher_spec (TLS 1.3
  middlebox-compat) before its Finished — the openssl-interop fix
- private-key file loading: wo_tls_pem_one (any-label PEM block) +
  wo_pkey_parse; per-shard identity cache (vm->tls_id), freed in reap
- docs/examples/tls-server + `just tls-server`: openssl s_client validates
  our hand-rolled server (EC + RSA certs) and gets the reply — 4/0; the
  outbound `just tls` gate stays 5/0 through the refactor
- wiring: wob.h, loader.c, builtin.c dispatch, types.ml, vm.h

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 2d4c30033c36c88de5b7ab7cc1042c9537238297)
2026-09-15 01:16:13 +02:00
db25f3e3e0 feat(crypto): private-key DER parsing (rv2 9 phase G3a)
- wo_pkey_parse: PKCS#8 PrivateKeyInfo (wrapping PKCS#1/SEC1), bare PKCS#1
  RSAPrivateKey, and bare SEC1 ECPrivateKey -> RSA (n,d) or the EC P-256
  32-byte scalar. Reuses the X.509 DER reader; spans point into the buffer
- KAT: all three formats parse, and the extracted key signs a hash our
  verify accepts (RSA-PSS + ECDSA); garbage rejected. test_crypto 130,
  ASan/UBSan clean

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 819d67226a94c4cd5a765ec403e57466c64f1e65)
2026-09-15 01:15:52 +02:00
18e0e6992b docs(rv2-tls): phase G2 server FSM landed
§G sub-phase G2: the sans-io server handshake FSM (wo_tls_server) landed,
loopback-KAT'd against the client driver (EC + RSA identities, app
round-trip). Remaining G3: net.accept_tls + private-key parse + live gate.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 57613bddc621a90970d9443ae5a5deacffe0cfca)
2026-09-15 01:15:52 +02:00
bd99da599d feat(tls): sans-io server handshake FSM (rv2 9 phase G2)
- wo_tls_server: the mirror of the client driver. parse ClientHello (pick
  suite, extract x25519 share, echo session id; reject no-x25519/no-1.3),
  build ServerHello, derive the role-symmetric keys, emit the encrypted
  flight (EncryptedExtensions + Certificate + a signed CertificateVerify +
  Finished), verify the client Finished, switch to application keys
- server_sign_cv signs the CertificateVerify with the phase-G1 primitives
  (RSA-PSS or ECDSA-P256 + a minimal DER SEQ{r,s} encoder); parse_client_hello
  + build helpers reuse the file's wire reader/writer
- wo_tls_server_start builds the Certificate message from a cert chain +
  private key (RSA n/d or EC scalar) + ephemeral; encrypt/decrypt over the
  application keys
- KAT: loopback — our client driver against our server driver, EC then RSA
  server identity, reaching ESTABLISHED with an app round-trip both ways.
  test_tls 123, ASan/UBSan clean

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 34d2b8f87cebe536cd2b1b33e6948251ec11684f)
2026-09-15 01:15:52 +02:00
cd779afa7f docs(rv2-tls): phase G1 signing landed (RSA-PSS + ECDSA-P256)
§G sub-phase G1: constant-time RSA-PSS + ECDSA-P256 signing landed and
KAT'd (RSA vs python from-spec; ECDSA vs RFC 6979 A.2.5). Remaining G1c
(private-key PEM/DER parse) folded into G3 (which reads key files); the
server FSM takes raw key material.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit f02518cdabab02043a04c6bdd28a81b86bb9fbd4)
2026-09-15 01:15:52 +02:00
df5054b07d feat(crypto): ECDSA-P256 signing, RFC 6979 nonce (rv2 9 phase G1b)
- wo_ecdsa_p256_sha256_sign: deterministic nonce (RFC 6979 HMAC-DRBG over
  the key + message — no RNG, no nonce-reuse/bias risk), then r = (k*G).x
  mod n and s = k^-1 (z + r*d) mod n
- constant-time in the secret: jmul_ct (double-and-add-always + point
  cmov) for k*G, and bn_modexp_ct for k^-1 mod n and the affine inversion.
  Known residual (documented): the ladder leaks k's leading-zero count (a
  bit-length hint, not the key) — a complete-formula/Montgomery-ladder
  upgrade is the named follow-up
- KAT: byte-for-byte vs the RFC 6979 A.2.5 P-256/SHA-256 vectors ("sample"
  + "test"), our sign verifies with our verify, determinism checked.
  test_crypto 115, ASan/UBSan clean

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 1bc6d04f9e18180dc7d0a6e5e7021dbd588e499a)
2026-09-15 01:15:52 +02:00
631506d36f feat(crypto): constant-time RSA-PSS signing (rv2 9 phase G1a)
- bn_modexp_ct: constant-time modexp for the SECRET exponent — squares and
  multiplies every bit, selects the product with a mask (bn_cmov), so the
  op sequence is independent of d (the existing bn_modexp branches on the
  bit, fine only for the public e)
- wo_rsa_pss_sha256_sign: EMSA-PSS-ENCODE (RFC 8017 §9.1.1) + modexp with d;
  caller supplies the salt (fresh in production; fixed makes the KAT
  deterministic). Private key (n,d)
- KAT: deterministic sign vs a python from-spec oracle byte-for-byte
  (fixed salt), our sign round-trips through our verify, tamper rejected.
  test_crypto 108, ASan/UBSan clean

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit cf8fdfcc47b2b076b63b9c63bf56411615b0d6f9)
2026-09-15 01:15:52 +02:00
82446652e4 docs(rv2-tls): brainstorm phase G (inbound TLS server) to ready
- §G written to READY (forks auto-approved, review_pending): the inbound
  server rung. Grounds what's reused (record layer, role-symmetric key
  schedule, X.509, slot table + data plane) vs new (server FSM, signing,
  key parsing, accept surface)
- six locked decisions: (1) constant-time private-key ops — the built
  modexp/scalar-mult are verify-only, not constant-time, so G adds a
  constant-time fixed-window modexp + Montgomery-ladder scalar mult;
  (2) both RSA-PSS + ECDSA-P256 server keys; (3) deterministic RFC 6979
  ECDSA nonce; (4) net.accept_tls(listener,cert,key) w/ per-path shard
  identity cache; (5) full 1-RTT server-auth only (no mTLS/resumption/HRR);
  (6) sans-io wo_tls_server FSM
- sub-phases G1 signing+key-parse, G2 server FSM (loopback KAT), G3
  net.accept_tls + live gate (openssl s_client); acceptance + out-of-scope
- ladder G row -> READY; may become its own runtime-v2 iteration

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 9fcb4a96a137a897f0ce2be868c18e63a979c997)
2026-09-15 01:15:52 +02:00
fe352b63c2 docs(runtime): CODE-LOGIC — the hand-rolled TLS 1.3 client (rv2 9)
- new "Hand-rolled TLS 1.3 client" section: the crypto ladder in crypto.c,
  the tls.c layers (record / key schedule / messages / sans-io driver /
  chain validation / PEM), and the net.*_tls builtins in sysio.c —
  per-shard no-lock slot table, deadline-bounded blocking handshake then a
  parked data plane, getrandom ephemeral (the runtime's first RNG),
  WO_CA_BUNDLE trust store, loud WO_T_IO failures, the just tls gate
- files table: crypto.c entry updated, tls.c/.h added

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 5670304d8a7a54e291b81e99e27aa16e29aa1d3e)
2026-09-15 01:15:52 +02:00
cf31bb4ebd docs(rv2-tls,jarvis,status): outbound TLS client complete — jarvis unblocked
- rv2 9 §F3c-net marked LANDED + live-gated; phase-F row COMPLETE (client);
  frontmatter review_pending updated (client complete, remaining = G server
  + deferred park-handshake/TlsConn/pooling + doctrine-doc corrections)
- jarvis 00-story + 01: the outbound-TLS blocker is cleared
  (net.connect_tls landed) — jarvis 1 (chat loop) is now buildable
- status board: rv2 9 row + NEXT PLAN rewritten to the completed client;
  next step is jarvis 1 or rv2 9 G

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 732c2216b501dd226d306f9abcbd1ddd846809dc)
2026-09-15 01:15:52 +02:00
72ed35773d test(tls): live acceptance gate for net.connect_tls (rv2 9 F3c-net phase 4)
- docs/examples/tls-client/main.wo: an outbound HTTPS client in .wo —
  net.connect_tls, write_tls a request, read_tls to EOF, print; connect
  failure caught with try/catch and reported (never a silent downgrade)
- scripts/tls-accept.sh + `just tls`: dials a local TLS 1.3 stub (python
  ssl, TLS1.3-only) with a generated test CA — proves the hand-rolled
  handshake + chain/host validation + an app round-trip end to end from
  .wo through the compiler, and refuses the untrusted-chain and
  hostname-mismatch negatives. No live network; log /tmp/tls.log
- gate: 5 checks, 0 failures

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 3d8bb140ec478167a4e660adf2caa964ff410ff1)
2026-09-15 01:15:52 +02:00
6d6c810695 feat(tls): net.connect_tls/read_tls/write_tls builtins (rv2 9 F3c-net)
The outbound TLS 1.3 client wired into the VM (ids 115-117, WO_B_MAX->117):

- net.connect_tls(host,port)->Int: DNS + non-blocking connect+poll bounded
  by WO_TLS_HANDSHAKE_MS (decision 5), then a blocking, SO_*TIMEO-bounded
  hand-rolled handshake over the sans-io driver, then wo_tls_verify_chain
  (chain + host + validity + basicConstraints/EKU) against the shard's
  lazily-loaded read-only CA bundle (decision 4). Any failure traps WO_T_IO
  loudly (decision 3). Returns the fd.
- net.read_tls / net.write_tls: application data over the parked data plane
  (decision 1) — O_NONBLOCK + park on POLLIN/POLLOUT like net.read/write,
  with record reassembly + leftover-plaintext + in-flight-record buffers in
  the per-fd slot so a park/retry never re-seals or loses progress.
- per-shard wo_tls_conn slot table keyed by fd, no locks (one thread per
  shard, the wo_child pattern; decision 2); net.close frees the slot;
  wo_vm_destroy reaps all slots + the CA bundle. getrandom ephemeral.
- driver keeps the whole Certificate message + wo_tls_client_chain() so the
  trust walk sees the full chain, not just the leaf.
- wiring: wob.h, loader.c arities, builtin.c dispatch (second net range),
  types.ml (net.connect_tls/read_tls/write_tls), sysio.c impl.

Builds; full runtime suite 0 fail; woc builds. Live behaviour is the
Phase-4 gate (next commit).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 9a922b3245eaa9134efb60bfd46521952ed12a39)
2026-09-15 01:15:31 +02:00
040ec9c189 feat(tls): PEM trust-anchor decoder (rv2 9 F3c-net decision 4)
- wo_tls_pem_to_ders: scan a PEM bundle for CERTIFICATE blocks, base64-decode
  each into a caller arena, record DER spans as trust anchors for
  wo_tls_verify_chain. Pure (caller reads the file + owns the arena) so it is
  offline-testable; the file read + per-shard cache land with the builtin
- b64_decode helper (standard alphabet, skips whitespace/newlines)
- KAT: decode the real /etc/ssl/certs/ca-certificates.crt (>100 anchors,
  each parses, first is a CA), garbage PEM -> 0 with no over-read,
  skip-if-absent for CI. test_tls 107 pass, ASan/UBSan clean

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 6445d55aa83dbed831d84fd3cca3a74fe4609a00)
2026-09-15 01:15:31 +02:00
3a1ba15851 feat(tls): X.509 basicConstraints + EKU chain hardening (rv2 9 F3c-net decision 6)
- crypto.c: x509_find_ext (generic extension walker) + wo_x509_basic_constraints
  (cA / pathLenConstraint, absent => not a CA) + wo_x509_eku_serverauth_ok
  (EKU absent, serverAuth, or anyEKU => usable; else not)
- wo_tls_verify_chain enforces decision 6: the leaf must be server-usable
  (EKU), every server-sent issuer and the signing anchor must be a CA
  (basicConstraints CA:TRUE) with a pathLenConstraint covering the
  intermediates below it — stops a leaf masquerading as a CA
- gen_x509.py extended (folds in the wildcard leaf, adds EKU clientAuth-only,
  EKU serverAuth, a non-CA intermediate + a leaf issued under it); vectors
  regenerated
- KATs: extractors (test_crypto 104) + chain enforcement (test_tls 103) —
  EKU serverAuth accepted, clientAuth-only rejected, leaf-under-non-CA
  rejected though every signature verifies; existing chains still pass.
  ASan/UBSan clean

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 3811418014c2c8d9bc3a9464256f52104261b1b9)
2026-09-15 01:15:31 +02:00
66de570888 chore(workflow): add prebuild-feature — the pre-build research fan-out
A reusable named Workflow (.claude/workflows/) that runs the
brainstorm-to-ready groundwork this repo does before any feature code:

- Understand: read the target story (or find the NEXT-PLAN target) +
  scout relevant .dev/reference projects for the concern
- Analyze: one agent per reference project — how it handles the concern,
  gaps vs our planned approach, recommendations (the fiber/Go step,
  generalized)
- Audit: story-format/frontmatter/plans-no-raw-code + dependency-graph /
  status-board consistency
- Consolidate: settle open forks (KISS defaults), fold reference gaps as
  locked requirements, acceptance-criteria gaps, go/no-go on readiness

Parameterized via args {story?, concern?, references?}; grounds every
agent in on-disk files. Does the parallelizable research half; the
fork-settling stays an interactive brainstorm. Invoke:
Workflow({name:'prebuild-feature', args:{...}}) or /workflows.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 2bfbb0ca5ca17cb2d1ead39f93aa42aeb50b1639)
2026-09-15 01:15:31 +02:00
53485a748c docs(rv2-tls): lock two more F3c-net requirements from the gofiber/Go comparison
Compared §F3c-net's forks against gofiber v3's client (fasthttp + Go
crypto/tls/x509, .dev/reference/fiber). Two gaps my defaults had vs Go,
now locked as decisions 5 and 6:

- (5) bounded handshake deadline: the blocking model would let a stalled
  server hang the shard's one thread indefinitely (the DoS DoTimeout
  closes). connect_tls now bounds connect+handshake via non-blocking
  connect+poll + SO_RCVTIMEO/SNDTIMEO, default WO_TLS_HANDSHAKE_MS
  (10s); expiry traps WO_T_IO. _dl variant + park handshake stay follow-ups
- (6) chain hardening: signatures+validity+SAN alone let a leaf act as a
  CA. Now every non-leaf must assert basicConstraints CA:TRUE (+pathLen)
  and the leaf must carry EKU serverAuth — what Go's crypto/x509 enforces
- acceptance criteria added (stalled-server timeout; leaf-as-CA + no-EKU
  rejected); connect_tls bullet, frontmatter review_pending, status NEXT
  PLAN updated to six locked forks

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 9662cd8b040f417b4886dae9ce97b70083e24e40)
2026-09-15 01:15:31 +02:00
f1e355c4d4 docs(rv2-tls): brainstorm §F3c-net to ready — four integration forks locked
- §F3c-net rewritten to READY (decisions locked 2026-09-09), grounded in
  the runtime not assumed:
  1. blocking connect+handshake then park the data plane (mirrors
     net.connect's own "tolerable while rare" stance); park-based
     handshake a named follow-up
  2. per-shard fd-keyed wo_tls_conn slot table, no locks (the wo_child /
     one-thread-per-shard pattern); slot holds driver state + partial-record
     + leftover-plaintext buffers
  3. failures trap WO_T_IO loudly incl. chain + hostname (no silent nil)
  4. per-shard lazy read-only CA bundle (/etc/ssl/certs, WO_CA_BUNDLE)
- builtin surface: net.connect_tls/read_tls/write_tls (ids 115-117,
  WO_B_MAX->117), acceptance criteria (incl. concurrent-shard TSan),
  out-of-scope (park handshake, TlsConn object, HTTP layer, inbound G)
- frontmatter review_pending + phase-F row + status NEXT PLAN updated:
  F3c-net spec ready, next action is BUILD (live-gated)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 8b6e72171c5db9dfe5b7a5122be123bf7cc3cdd9)
2026-09-15 01:15:31 +02:00
2391553658 docs(rv2-tls,status): F3c-net plan + net.connect_tls object-model default; session NEXT PLAN
- rv2 9 §F3c-net: the remaining live-gated slice with auto-approved
  defaults — getrandom ephemeral, system CA-bundle loader, net.connect_tls
  builtin returning the TCP fd (fd-keyed side table, blocking model like
  net.connect) driving the sans-io driver, then wo_tls_verify_chain; plus
  net.read_tls/write_tls and a live gate
- status board NEXT PLAN: the TLS client security engine landed this
  session (E-F3c minus socket glue), F3c-net is the next rung, then jarvis

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit ad87974fc722268e278f957f1f3d607f5dafa50d)
2026-09-15 01:15:31 +02:00
5f0ac2d434 feat(tls): certificate chain validation (rv2 9 phase F3c-net security core)
- wo_tls_verify_chain: leaf-first DER chain — each cert signed by the
  next, the top trusted (equal to, or signed by, a trust anchor), the leaf
  SAN matching host, every cert temporally valid. Any failure rejects;
  no partial trust. Pure over the phase-D/E verifiers, so offline-testable
- KAT with the phase-E RSA + EC chains: leaf trusted via its issuing CA
  anchor; wrong-anchor / wrong-host / expired / broken-link / no-anchor
  all rejected; two-cert chain with a byte-equal root anchor; NULL host
  skips the SAN check. test_tls 100 pass, ASan/UBSan clean
- remaining F3c-net (live-gated): CA-bundle PEM loader, random ephemeral,
  the net.connect_tls builtin driving the sans-io driver over a real fd

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 9d40055108d301be32df0e1d4140c23446baa7c6)
2026-09-15 01:15:31 +02:00
ad088163cc docs(rv2-tls,jarvis): TLS ladder through F3c-core + SAN landed
- rv2 9 phase-F row + review_pending: F3c-core sans-io driver + SAN/host
  landed (KAT'd vs RFC 8448 record trace); remaining F3c-net = system CA
  trust-anchor walk + net.connect_tls VM plumbing (live-gated), then G
- jarvis 00-story + 01 blocker tables: crypto/handshake engine landed;
  jarvis now waits only on net.connect_tls (the socket glue)
- status board rv2 9 row updated to the full ladder state

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 4fdf07196d01c32d0ab12d32d36fa4285ff34654)
2026-09-15 01:15:31 +02:00
d7a6888931 feat(tls): SAN/hostname verification + driver enforcement (rv2 9 phase E/F3c)
- wo_x509_check_host: match a hostname against the cert subjectAltName
  dNSNames (RFC 6125) — case-insensitive, single left-most wildcard that
  covers exactly one label; no SAN => refused; no legacy CN fallback.
  Completes the phase-E deferred hostname check (walks the [3] extensions)
- wo_tls_client_set_host + driver enforcement: with a host set, a leaf
  whose SAN does not match is refused at the Certificate step (MITM
  defense); unset skips the check (offline testing only, documented unsafe)
- KAT: exact/case-insensitive/mismatch, no-SAN refused, wildcard one-label
  (not zero, not sub-label) via a wildcard-SAN cert; driver refuses the
  RFC 8448 leaf (no SAN) once a host is set. test_crypto 95, test_tls 91,
  ASan/UBSan clean

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 319ce8bfcf608030f958b36ab2c8f62fd76e1740)
2026-09-15 01:15:31 +02:00
d7e7eff6b5 feat(tls): sans-io TLS 1.3 client handshake driver (rv2 9 phase F3c-core)
- wo_tls_client: a pure state machine (no sockets). Caller frames
  records; driver runs ClientHello->ServerHello->flight->Finished and
  hands back bytes to send. Keeps all I/O out of the security-critical FSM
- start_with (inject CH + ephemeral priv), push_record, take_output,
  encrypt/decrypt (application traffic keys). Handshake-message reassembly
  across records; per-message transcript timing (CertVerify signs CH..Cert,
  Finished MACs CH..CertVerify); constant-time Finished compare; every
  failure lands in FAILED (no warn-and-continue)
- verifies server CertificateVerify (phase E+D) + server Finished, emits
  the client Finished, switches to application keys
- KAT: whole handshake driven offline against the RFC 8448 record trace —
  client Finished record byte-for-byte, first client app record
  byte-for-byte, NewSessionTicket + server app data decrypt to plaintext,
  tampered flight -> FAILED. test_tls 90 pass, ASan/UBSan clean
- SECURITY TODO before live use (documented in tls.h + story): chain walk
  to a trust anchor + SAN/hostname match; random ephemeral for production
  start; the net.connect_tls socket glue

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 74c332d7efdb8bbfdbe90bd2fcc3defa2fe8da00)
2026-09-15 01:15:31 +02:00
c84d33c9ba docs(rv2-tls): rv2 9 phase F1-F3b landed (record, key schedule, messages, offline verify)
- phase-F row: F1 record layer, F2 key schedule, F3a message layer,
  F3b offline handshake verification all landed + KAT'd (RFC 8448 /
  real certs); F3c socket FSM + net.connect_tls plumbing remaining
- review_pending updated to the current ladder state

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit d49bc3866b6b620d00a8a57137ba211da25cd05b)
2026-09-15 01:15:31 +02:00
74b153aa0a feat(tls): offline handshake verification (rv2 9 phase F3b)
- wo_tls_verify_cert_verify: verifies a server CertificateVerify
  (RFC 8446 §4.4.3) — builds the 64-space || context || 0x00 ||
  transcript-hash content, parses the leaf SPKI (phase E) and dispatches
  to phase-D RSA-PSS / RSA-PKCS1 / ECDSA-P256; the scheme must match the
  leaf key type. ECDSA sig r/s pulled from its DER SEQ
- reuses wo_tls_finished_verify (phase F2) for server + client Finished
- KAT: the whole handshake crypto driven offline from the RFC 8448 §3
  recorded messages — CertificateVerify (RSA-PSS) VALID, wrong-transcript
  / tampered-sig / mismatched-scheme rejected, server Finished byte-exact,
  and the client Finished we would send byte-exact. test_tls 78 pass,
  ASan/UBSan clean

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit afd9f23508c648322712df91329aa117c975ccab)
2026-09-15 01:15:31 +02:00
c375110aac feat(tls): TLS 1.3 handshake message layer (rv2 9 phase F3a)
- bounded wire reader/writer (malformation -> reject, overflow -> fail;
  no over-read on attacker-controlled bytes)
- wo_tls_parse_server_hello: extracts negotiated suite + server x25519
  key share; rejects HelloRetryRequest, unsupported suite/group,
  non-1.3 selected_version, and any truncation
- wo_tls_build_client_hello: ClientHello offering TLS 1.3 / x25519 /
  RSA-PSS+RSA-PKCS1+ECDSA-P256, SNI, 32-byte legacy session id
- KAT: ServerHello parser vs RFC 8448 recorded message (suite 0x1301 +
  server pubkey byte-exact), malformed rejected; ClientHello builder
  structural + SNI/keyshare present + too-small refused, and validated
  byte-for-byte spec-valid by an independent python parser. test_tls 71
  pass, ASan/UBSan clean

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 541c71bca1655f370b145621d272d2e8bdb6c7ce)
2026-09-15 01:15:31 +02:00
25dda4cb2f feat(tls): TLS 1.3 key schedule (rv2 9 phase F2)
- wo_tls_derive_handshake: Early/Handshake/Master secrets + client/server
  handshake-traffic secrets from the ECDHE shared secret and the
  ClientHello..ServerHello transcript hash (RFC 8446 §7.1)
- wo_tls_derive_application: client/server application-traffic secrets
  from master_secret + the ClientHello..server-Finished transcript hash
- wo_tls_traffic_keys: record key + IV via HKDF-Expand-Label "key"/"iv"
- wo_tls_finished_verify: finished_key = Expand-Label(base,"finished"),
  verify_data = HMAC(finished_key, transcript_hash)
- all over phase-B HKDF (Extract/Expand-Label) + Derive-Secret helper
- KAT vs RFC 8448 §3 "Simple 1-RTT Handshake" byte-for-byte: c/s hs
  traffic, master, c/s ap traffic, server hs key+iv. Also validates the
  phase-B "tls13 " Expand-Label. test_tls 58 pass, ASan/UBSan clean

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 417fcc16f80c1dd31e84a0336944573902fde06e)
2026-09-15 01:15:31 +02:00
7e71c1a171 feat(tls): TLS 1.3 record layer (rv2 9 phase F1)
- new tls.c/tls.h on the crypto ladder: wo_tls_record_seal/open
  (RFC 8446 §5.2) — TLSInnerPlaintext (content||type, no padding),
  5-byte header as AEAD additional-data, per-record nonce = iv XOR
  seq big-endian (§5.3)
- suite dispatch: TLS_AES_128_GCM_SHA256 (mandatory) +
  TLS_CHACHA20_POLY1305_SHA256 (AES-NI-less fallback), over phase-A AEAD
- open() strips trailing zero padding to recover the inner content type;
  rejects a length-field lie before the AEAD, and auth failure after
- KAT vs python AEAD oracle (test/gen_tls_record.py): sealed record
  byte-for-byte both suites, open() recovers it, 5-seq round-trip,
  tamper + wrong-seq + bad-suite rejected. test_tls 51 pass, ASan/UBSan

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 5021a99f8359f78a642bb0cc2b28ab66f6b624e2)
2026-09-15 01:15:31 +02:00
bb64278aa9 docs(rv2-tls): rv2 9 phase E (X.509 core) landed
- phase-E ladder row: core landed (DER reader + cert parse + verify_one
  + parse_spki + check_validity), KAT'd on real RSA + EC chains
- review_pending frontmatter: forks auto-approved 2026-09-08, SAN/
  hostname + CA-bundle walk deferred to phase F

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
EOF2
git log --oneline -2

(cherry picked from commit 796ed88d76f1cf25ced1eb5e7bdb4e4ab3cf4e9b)
2026-09-15 01:15:31 +02:00
5f5d774d76 feat(crypto): X.509 chain-link verification (rv2 9 phase E core)
- defensive ASN.1/DER reader: every length/bound checked; malformation
  is rejection, never over-read (truncated input KAT-gated)
- x509_parse: tbsCertificate span, sig-alg OID, signature,
  SubjectPublicKeyInfo (RSA n/e or EC P-256 x/y), validity dates
- wo_x509_verify_one: one chain link's signature, dispatching to
  phase-D RSA-PKCS1/PSS + ECDSA-P256 by the issuer key type
- wo_x509_parse_spki + wo_x509_check_validity (caller supplies time)
- KAT against real python-generated chains (test/gen_x509.py):
  RSA CA+leaf (SHA256withRSA), EC P-256 CA+leaf (ecdsa-with-SHA256);
  leaf-vs-CA, self-signed CA, wrong-issuer/tampered/truncated reject,
  validity window, SPKI extraction. test_crypto 84 pass, ASan/UBSan clean
- deferred to phase F: SAN/hostname match + multi-cert chain walk to a
  system CA bundle (both need the target host / trust store, known at
  handshake time)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 4ec1c75f889df3612e31b9a1a77c4c927fb546c1)
2026-09-15 01:15:31 +02:00
9d1689be55 docs(jarvis): create iteration stories 1 (ready) + 2/3 (refine)
- jarvis 1 (chat loop) brainstormed to ready with forks AUTO-APPROVED for
  autonomous execution and flagged in `review_pending` frontmatter for the
  developer's second review: Anthropic Messages API backend, env-var API key,
  actor-per-conversation SSE relay, durable @table history, session-gated routes
- jarvis 2 (tool use) + 3 (retrieval/RAG) created at refine with forks named
- 00-story iterations table linked to the new files
- blocked until rv2 9 TLS reaches phase F; pure .wo on porch 2/3/6/7 + the seam

(cherry picked from commit 8e160c3fcf9c50a05af073c036c693b192c9e595)
2026-09-15 01:15:31 +02:00
ca572086ee docs(rv2-tls): rv2 9 phase D complete (RSA + ECDSA-P256 verify)
- ECDSA-P256 verify landed; phase D done (both signature verifiers)
- rv2 9 story, board ladder, jarvis 00-story deps, and dependency-graph §7
  synced: A-D landed, E-F remain

(cherry picked from commit 3eab98cc268e524c7b4e2ab72a4b093692a67d03)
2026-09-15 01:15:31 +02:00
c085c7390c feat(crypto): ECDSA-P256 verification (rv2 9 phase D part 2)
- wo_ecdsa_p256_sha256_verify: NIST P-256 signature verify for EC-cert chains
  and TLS 1.3 CertificateVerify
- Jacobian point arithmetic (double a=-3, general add with the H==0 special
  cases), double-and-add scalar mult; field/scalar arithmetic reuses the
  bignum Montgomery multiply and modexp (Fermat inverses mod p and mod n)
- validates r,s in [1,n-1] and that Q is on the curve (invalid-curve guard)
- verify-only public data -> not constant-time by design
- renamed the P-256 field mul to fpmul to avoid the clash with X25519's fmul
- VERIFIED against a python ECDSA-P256 vector; tamper + wrong-hash rejected;
  test_crypto 69/0; ASan/UBSan clean; battery green
- phase D COMPLETE (RSA PKCS1+PSS + ECDSA-P256). Next E: ASN.1/X.509

(cherry picked from commit 92c996ba96d785d098c173d4ac6ace9052ef6a2f)
2026-09-15 01:15:31 +02:00
4e70509001 docs(rv2-tls): rv2 9 phase D part 1 (RSA verify) landed
- RSA PKCS#1 v1.5 + PSS verify over SHA-256, bignum Montgomery modexp,
  KAT-gated vs python RSA-2048. ECDSA-P256 (D2) remains. Board synced

(cherry picked from commit ae42943c97949224d883e9ddcf5ae2117fef62b3)
2026-09-15 01:15:31 +02:00
d0bd66c704 feat(crypto): RSA signature verification (rv2 9 phase D part 1, PKCS1 + PSS)
- wo_rsa_pkcs1_sha256_verify + wo_rsa_pss_sha256_verify (SHA-256), for the
  server cert chain and TLS 1.3 CertificateVerify
- bignum: Montgomery multiply (CIOS, 64-bit limbs, __int128), modexp with the
  public exponent (R^2 via 128k modular doublings, no division); MGF1-SHA256
- verification is public data only -> NOT constant-time by design (correct and
  much simpler than a private-key op)
- assumes a full-length modulus for PSS emBits (standard RSA-2048/3072/4096)
- VERIFIED against python cryptography RSA-2048 vectors (PKCS#1 v1.5 + PSS,
  salt 32); tamper + wrong-hash rejected; test_crypto 66/0; ASan/UBSan clean;
  battery green
- internal C, no builtin/compiler change. Remaining in D: ECDSA-P256 (D2)

(cherry picked from commit 9118177fbfd03eff9757defea6931afdd68830c4)
2026-09-15 01:15:31 +02:00
d02befd6bf docs(jarvis): sync jarvis dependencies to landed state + dependency graph
- jarvis 00-story: net.connect marked landed (id 110); outbound-TLS blocker
  now rv2 9 in-progress (A AEAD / B HKDF / C X25519 done; D-G remain);
  architecture + blocker table updated
- dependency-graph: new §7 jarvis dependency graph (phase-level TLS ladder +
  porch framework path); §5a net.connect node marked landed

(cherry picked from commit a615ee80238fb384c0b33fc2b54bcd6bd4078078)
2026-09-15 01:15:31 +02:00
8e652800fe docs(rv2-tls): rv2 9 phase C (X25519) landed
- constant-time X25519 (RFC 7748), curve25519-donna radix-2^51; KAT-gated incl.
  the 1000-iteration vector. Ladder A+B+C done; next D. Board synced

(cherry picked from commit b929a20b7482d7137a45b77a2179fe7ef03c52b6)
2026-09-15 01:15:31 +02:00
aee98661d2 feat(crypto): X25519 key exchange (rv2 9 phase C, RFC 7748)
- wo_x25519: constant-time Montgomery ladder + mask-based conditional swap,
  radix-2^51 field arithmetic with __int128 products (curve25519-donna-c64,
  public domain); scalar clamped, u-coord high bit masked per RFC 7748
- internal C (consumer is the TLS ECDHE handshake); no builtin/compiler change
- KAT-gated in test_crypto: RFC 7748 §5.2 both direct vectors AND the
  1000-iteration base-point test; test_crypto 61/0; ASan/UBSan clean; battery green
- fixed one transcription bug found via the KAT: crecip needs 5 final squarings
  (p-2 = 2^255-21 = (2^250-1)*2^5 + 11), not 3
- rv2 9 ladder: A (AEAD) + B (HKDF) + C (X25519) done; next D signatures/RSA

(cherry picked from commit f41b1c5f56caa841d1904382830baff0f75525d9)
2026-09-15 01:15:31 +02:00
aff8ffdf14 docs(rv2-tls): rv2 9 phase B (HKDF key schedule) landed
- HKDF-Extract/Expand + Expand-Label over hmac_sha256, KAT-gated (RFC 5869 +
  8446); status -> in-progress; ladder A+B done. Board synced

(cherry picked from commit e24b8ec6d838fc66848864c2a0974205aaa9b4be)
2026-09-15 01:15:31 +02:00
36ce2332ef feat(crypto): HKDF-SHA256 for the TLS 1.3 key schedule (rv2 9 phase B)
- wo_hkdf_sha256_extract/expand (RFC 5869) + expand_label (RFC 8446 §7.1),
  internal C over the existing hmac_sha256; SHA-256 (mandatory-suite hash;
  SHA-384 a later add for the AES-256 suite)
- no builtin, no compiler change -- no .wo consumer yet (the TLS handshake
  is the consumer); exposed for the C unit test
- KAT-gated in test_crypto: RFC 5869 Test Case 1 (PRK + 42-byte OKM) and
  three HKDF-Expand-Label vectors (key/iv/derived-secret shape); 57/0,
  ASan/UBSan clean; runtime battery green
- rv2 9 ladder: A (AEAD, = rv2 8) and B (HKDF) now done; next C X25519

(cherry picked from commit c8d27b6c89a80cd97a996ff7d8b64ff4895e4b26)
2026-09-15 01:15:31 +02:00
2db3766b66 docs(rv2-aead): rv2 8 phase C (software AES-GCM fallback) landed
- portable constant-time AES-GCM software path; AES-GCM now on any CPU
  (hw-or-sw dispatch), NIST-KAT-gated both paths (48/0). Remaining D/E;
  ARMv8 hw path deferred. Board synced

(cherry picked from commit 138de17988e6bd274abe5e1e2d444ff2689747cd)
2026-09-15 01:15:31 +02:00
94d5f176f7 feat(crypto): portable constant-time AES-GCM software fallback (rv2 8 phase C)
- no-intrinsics AES: S-box = GF(2^8) inverse via a fixed-exponent power ladder
  (constant-time in the input, no tables), constant-time gf8_mul, byte-oriented
  ShiftRows/MixColumns/key-expansion (AES-128 and AES-256)
- constant-time GHASH: bit-by-bit GF(2^128) multiply (mask-driven, no tables)
- aes_gcm_seal/open now dispatch: AES-NI path when present (and not forced
  software), else this portable fallback -> AES-GCM works on ANY CPU, so the
  phase-B no-AES-NI trap is retired
- wo_aes_force_software test hook; both hw and sw paths verified against NIST
  SP 800-38D cases 4 (AES-128) and 16 (AES-256) byte-for-byte; test_crypto 48/0;
  ASan/UBSan clean; full runtime battery green
- ARMv8 crypto-extension hardware path deferred (untestable on x86-64 host)

(cherry picked from commit dccf650899798401a9adac8489f34c85ed9304af)
2026-09-15 01:15:31 +02:00
6a38ad7cb0 docs(rv2-aead): rv2 8 phase B (AES-GCM) landed
- phases A + B done; B = AES-128/256-GCM via AES-NI/PCLMULQDQ, NIST-KAT-gated,
  ASan clean, portable binary (CPUID-gated). Phase C now owns the software
  fallback AND the ARMv8 hardware path (deferred, untestable on x86-64 host)

(cherry picked from commit 249b1dbd72122ed6c05f4f0aadb7e1a5e87f844c)
2026-09-15 01:15:31 +02:00
1ef4e463ec feat(crypto): AES-GCM via AES-NI + PCLMULQDQ (rv2 8 phase B, ids 113/114)
- aes_gcm_seal/open, AES-128 and AES-256 (variant by key length 16/32),
  nonce 12 bytes, out = ciphertext||tag; open returns nil on auth failure
- hardware path only (phase B): AES-NI key schedule (128/256) + block, GHASH
  via PCLMULQDQ with the fast GF(2^128) reduction, GCM mode (J0, CTR from
  counter 2, GHASH over aad|pad|ct|pad|len, tag = GHASH ^ AES(J0))
- constant-time by hardware; target-attributed functions + __builtin_cpu_supports
  gate so the binary stays portable -- no AES-NI traps with a clear message
  (bitsliced software + ARMv8 paths are phase C)
- wiring: wob.h ids + WO_B_MAX 114; builtin.c crypto range; loader arity 4;
  emit.ml (ids/arity/return/name); types.ml (register + return type)
- VERIFIED: matches NIST SP 800-38D cases 4 (AES-128) and 16 (AES-256) and the
  python cryptography reference byte-for-byte; KAT-gated in test_crypto (36/0);
  ASan/UBSan clean; runtime battery + compiler 557/0 green

(cherry picked from commit f12a745a3c1313847f9d7f65e53bcd8093758af9)
2026-09-15 01:15:31 +02:00
da840a5be6 docs(rv2-aead): rv2 8 phase A (ChaCha20-Poly1305) landed
- status -> in-progress; phase A marked landed (matches RFC 8439 §2.8.2,
  KAT-gated in test_crypto, ASan clean). Remaining B/C/D/E. Board synced

(cherry picked from commit db5bdf3c3cac31c0d2be60027e0e2bf9fe8309c1)
2026-09-15 01:15:31 +02:00
ac52c3fdb5 feat(crypto): ChaCha20-Poly1305 AEAD (rv2 8 phase A, ids 111/112)
- hand-rolled ChaCha20 + poly1305-donna-32 + RFC 8439 §2.8 AEAD in crypto.c;
  constant-time (add/xor/rotate + limb math, no tables, no data-dep branches),
  constant-time tag compare
- two bare-name crypto-family builtins beside sha256/hmac:
  chacha20poly1305_seal(key,nonce,aad,pt) -> Bytes (ct||tag)
  chacha20poly1305_open(key,nonce,aad,ct||tag) -> ?Bytes (nil on auth fail)
  key 32B, nonce 12B (caller-supplied, per TLS's per-record nonce need)
- wiring: wob.h enum + WO_B_MAX 112; builtin.c crypto dispatch range; loader.c
  arity 4; emit.ml (ids, arity_of 4-case, return type, is_builtin_name,
  name->id); types.ml (registration + return type)
- VERIFIED: matches RFC 8439 §2.8.2 byte-for-byte (vs python cryptography +
  the RFC vector); test_crypto 24/0 (Poly1305 §2.5.2 + AEAD seal/open/tamper);
  ASan/UBSan clean; runtime battery + compiler 557/0 green
- first rung of the TLS ladder (rv2 9 phase A)

(cherry picked from commit 961854a8f4e9e632b6fa17f7f2e519e2d08f4936)
2026-09-15 01:15:31 +02:00
7f7a601e2f docs(rv2-aead): brainstorm runtime-v2 8 (AEAD ciphers) to ready
- a second consumer (rv2 9 TLS phase A) reshaped the forks since the draft
- locked: BOTH AES-GCM (128/256, TLS-mandatory per RFC 8446) AND
  ChaCha20-Poly1305 (RFC 8439, easy constant-time, cookie default)
- AES constant-time via AES-NI/ARMv8 hardware + bitsliced software fallback
  (compiler intrinsics, zero external dep)
- caller-supplied nonce (TLS builds its own per-record nonce); random-nonce
  is a cookie WRAPPER (phase D) not the primitive. shape:
  seal(key,nonce,aad,pt)->Bytes / open->?Bytes; AES variant by key length
- raw key + length check; hand-rolled (matches rv2 9); ids from 111
- phases A ChaCha -> B hardware AES-GCM -> C software AES -> D cookie wrapper
  -> E gate (RFC 8439 + NIST GCM vectors, ASan, reference cross-check)
- risk/test: constant-time mandatory, KAT-gated, reused-nonce documented
- retires the stale "TLS proxy-terminated" OOS line (rv2 9 overturned it)

(cherry picked from commit c8a5a31c39a5d14952056cd0af1b8c1e42d4ed2d)
2026-09-15 01:15:31 +02:00
51addb504c docs(rv2-tls): brainstorm runtime-v2 9 (in-process TLS) to ready — hand-rolled
- decision: HAND-ROLL TLS 1.3 (no vendored lib) per developer call; keeps the
  zero-external-dep single binary, and raises risk rather than lowering it —
  recorded, owned, with mandatory mitigations
- 1.3-only; RSA-PSS/PKCS1 + ECDSA-P256 + full ASN.1/X.509 chain validation +
  trust store + hostname (the scope needed to reach real LLM APIs)
- decomposed into a bottom-up phase ladder: A AEAD (=rv2 8, forces AES-GCM
  there) -> B HKDF -> C X25519 -> D signatures/RSA -> E X.509 -> F record+FSM
  client -> G inbound server; C/D/E may each split into own iterations
- risk + test strategy section: constant-time, reference-tested (openssl +
  RFC 8448 vectors), negative tests first-class, no partial-trust states
- deps: rv2 8 (AEAD), lang 34 (SHA/HMAC), net.connect (110, landed). Board synced

(cherry picked from commit f1881cca8cd0cdd58b1ac844e3e3ea9c234bb99c)
2026-09-15 01:15:31 +02:00
cc1c82b2ef docs: jarvis track, runtime-v2 7/8/9, lang-41 fix design, fiber scope-gap
- jarvis (00-story): 6th track, 2nd software built with writeonce — an AI
  assistant; direct-HTTPS design; blockers named (net.connect + TLS)
- runtime-v2 7 observability + 8 symmetric cipher: moved from the language
  track (were 30/43); 9 in-process TLS: created from the gap jarvis surfaces,
  RETIRES the "TLS is the proxy's job" doctrine (both directions)
- language 41 (arena hang): fix design to ready — marshal cross-shard
  messages (root), align the shard_id % nshards route/compare + assert bound;
  poison-on-free + minimal fixture as follow-ups
- fiber scope-gap analysis (plan/exploration/fiber/01): porch vs fiber, what
  porch lacks, would developers prefer porch
- board + dependency-graph synced (porch 2-8 ready; rv2 table; §5/§5a graphs)

(cherry picked from commit 203470ceb2a151fe3584931cd4237af3f96a9f29)
2026-09-15 01:15:31 +02:00
e91a3704fe feat(net): net.connect outbound TCP client (id 110)
- new builtin net.connect(host, port) -> Int: the outbound-socket gap
  language 38 named and jarvis surfaced; the client half of the net verbs
- getaddrinfo for DNS (v4/v6, numeric or hostname), blocking connect with
  the same EINTR/stop handling as net.connect_unix, then O_NONBLOCK for the
  park plane; returns the same fd-scalar accept yields
- wob.h enum + WO_B_MAX 110; types.ml registration; loader.c arity;
  builtin.c sysio dispatch range extended to WO_B_NET_CONNECT; sysio.c impl
- verified: numeric IP + hostname (DNS) connect to a local listener, closed
  port traps cleanly; ASan-clean; runtime battery 0 fail
- deferred (next slice): net.connect_dl deadline/park variant (no shard
  stall during handshake), on the accept_dl pattern

(cherry picked from commit 13c6f124428243b4956fbb4eceb1e7d0206d45f2)
2026-09-15 01:15:31 +02:00
b932e0cb87 docs(porch-static): brainstorm story 8 (static + lifecycle) to ready
- whole porch track (2-8) now brainstormed and locked (all ready)
- four decisions: three hooks (on-listen/on-shutdown/on-route-registered);
  healthcheck ships BOTH /livez + /readyz; directory listing off-by-default,
  documented; Last-Modified via a new small time.utc(ms)->TimeParts builtin
- language enhancement: YES, one small builtin -- time.utc, a gmtime sibling
  of time.local (time.local is local-tz, time.iso is UTC-but-ISO); IMS by
  string-equality, no date parser. The track's third + smallest language touch
- byte ranges/large files via fs.read_at + iteration 6 writer; not lang-41-exposed
- track language bill now explicit: random_bytes (2), deflate+crc32 (7),
  time.utc (8) -- each a builtin with a named consumer, none decoration
- validated against .dev/reference/fiber. Board: whole track marked ready

(cherry picked from commit 9801fceade799e25718606177f09e4306a579e98)
2026-09-15 01:15:31 +02:00
4d3e4261e1 docs(porch-sse): brainstorm story 7 (SSE + compression) to ready
- five decisions: refuse incoherent heartbeat/idle_ms pair at construction;
  codec = two C builtins deflate+crc32 (perf over pure-.wo; hand-rolled, no
  zlib dep; gzip framing in .wo); ETag over uncompressed bytes + Vary;
  Last-Event-ID explicitly unsupported (not silently ignored); Vary via
  comma-join
- language enhancement: YES, two builtins -- the track's SECOND language
  dependency after iteration 2's random_bytes. CRC32 finally gets its
  consumer; inflate deliberately not built (request-body decompression OOS)
- corrected stale dependency: Vary uses iteration 5's comma-join, so story 7
  depends on 6 + 5, NOT 2; codec is pure compute, not lang-41-exposed
- confirmed CRC32 absent + iteration 36 bit operators landed (pure-.wo was
  viable, traded for hot-path speed)
- validated against .dev/reference/fiber. Board synced

(cherry picked from commit 07f53574dd90f502235b79d4920eab3d684c8b77)
2026-09-15 01:15:31 +02:00
641703903c docs(porch-streaming): brainstorm story 6 (streaming core) to ready
- re-scoped to OUTBOUND streaming only
- three decisions: separate StreamHandler/BodyProducer parallel path (Resp
  path untouched -> existing responses byte-identical); streaming routes opt
  out of the after-chain, framework refuses at registration to combine with
  header-mutating middleware (loud, never silent), security_headers() helper
  lets handlers stamp them; chunked REQUEST bodies split into their own future
  iteration (parse.wo refusal stays, smuggling cases enumerated for later)
- no language enhancement (net.write framing, fs.read_at/actor source,
  interfaces for producer); rides the fiber loop not the actor pool, so not
  lang-41-exposed
- fixed title inconsistency: "three iterations wait on" -> "two" (7 and 8)
- validated against .dev/reference/fiber + the app.wo/serve.wo pipeline. Board synced

(cherry picked from commit 15205408e03c3c02a38e00e5d2017a8a11f62f28)
2026-09-15 01:15:31 +02:00
6b820fdd5f docs(porch-routing): brainstorm story 5 (routing + response ergonomics) to ready
- five decisions: head auto-registers with opt-out (+ patch/options/all);
  request ids mirror limiter trust model with a NON-crypto source; per-route
  body_limit is a SECOND check after routing (global BODY_MAX stays the
  pre-routing ceiling, over-limit = 413); Route fields are corpus-free;
  Vary accumulates by comma-join
- key finding: story 5 has NO upstream dependency, not even iteration 2 --
  request ids are not secrets, so a non-crypto source (time.ticks+counter)
  keeps it startable today; the one porch slice buildable right now
- three story assumptions corrected: per-route limit cannot replace the
  global (body read before routing); the container-owned-move corpus fixture
  has its OWN Route (adding fields is free); Vary needs no iteration 2
- validated against .dev/reference/fiber; zero language enhancement. Board synced

(cherry picked from commit 0589a13db1f3b7c220d9d9fdc76142af6a63c390)
2026-09-15 01:15:31 +02:00
274f7c5361 docs(porch-csrf): brainstorm stories 3 (sessions) + 4 (CSRF) to ready
sessions (3):
- six decisions: pure-auth-primitive row (no payload bag); wall-clock
  time.now not monotonic time.ticks (restart durability); login always
  mints a fresh id (fixation, no anon-session model); throttled last_seen
  touch at idle/20 (not a WAL write per request); Session writes
  req.principal; config refuses absolute < idle
- finding: no per-key actor pool, so NOT blocked on lang-41 (plain @table
  CRUD, same path storefront uses); the no-bag rule closes the one place
  fiber's Set(key,any)+msgp+RegisterType would have hit principle 13

csrf (4):
- five decisions: fiber's hybrid transport (session-stored CsrfToken
  @table + double-submit cookie, both must pass; no CSRF for sessionless
  apps); opt-in single-use (checkout example); double-click -> distinct
  SPENT refusal, NOT coupled to lang-41-blocked idempotency; trusted
  origin/referer/Sec-Fetch-Site second layer; refusal classes distinct in
  logs, opaque in body
- no actor pool, not blocked on lang-41

both validated against .dev/reference/fiber (v3, 3ca9a9d); exactly ZERO
language enhancement needed beyond iteration 2's random_bytes. Board synced.

(cherry picked from commit 3a4fb4215b23d2516362e2dd0acc5bec6c9aebc0)
2026-09-15 01:15:31 +02:00
6a67db252b docs(porch-cookies): brainstorm story 2 (randomness+cookies) to ready
- five forks locked: cookies: multi SetCookie beside unchanged headers
  map; bare-name random_bytes(n)->Bytes; structural-400 in parse_request
  + on-demand cookie() helper; base64(value).base64(mac) signing;
  app-supplied key, no middleware (that is iteration 3)
- validated against .dev/reference/fiber (v3, 3ca9a9d): exactly ONE
  language enhancement needed (the CSPRNG); repeated Set-Cookie, cookie
  attributes, parsing and signing all map to existing primitives
- corrects phase A registry: random_bytes joins the crypto-family
  bare-name table (emit.ml b_* + types.ml), NOT wob.h's module enum;
  next free id 84/90, not 110
- board: story 2 marked ready, porch-2 row rewritten off the stale
  wob.h/110 claim

(cherry picked from commit 4d31d5359436496aed40cb25611abc7ccd4d7875)
2026-09-15 01:15:30 +02:00
1d78e0fa70 fix(runtime): don't deref a poisoned class's NULL fmap during migration
- wo_schema_diff poisons a class (fmap=NULL, new_cid=NONE) when a
  referenced/nested type changed or a field type is incompatible — the
  field-level map does not apply and wo_wal_migrate transcodes it instead.
- main.c's pre-migration "migrating `X`: +/-fields" print loop dereferenced
  fmap unconditionally, so a poisoned-but-field-added class (e.g. a wmux
  Window whose nested Vte gained fields) was a NULL read → SIGSEGV at boot,
  before the migrate call could refuse or transcode.
- guard the field detail on fmap != NULL; for a poisoned class print
  "(a referenced type changed — cannot migrate in place)" and let
  wo_wal_migrate proceed. It then transcodes cleanly when no record blocks
  it — so an additive nested change (Vte +oscbuf +title) now migrates and
  the session replays, instead of crashing serve.
- test_wal 5966/0; verified against the real WAL that crashed (recovers
  session `main`); wmux gate 52/0.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 35efa214d20dd7b055910ae66e4bfcc6201821c9)
2026-09-15 01:15:30 +02:00
5e8e0960bc feat(rt2): term.size + term.width — the wmux ladder's last runtime asks
- term.size(fd) -> ?TermSize{cols,rows}: TIOCGWINSZ, resize's read twin;
  nil = not a tty (expected answer, never a trap)
- term.width(cp): libc wcwidth under C.UTF-8 (LC_CTYPE set on first
  use, host-locale fallback): -1 control, 0 combining, 1, 2
- ids 108/109 (all four registrations); TermSize predeclared
- legs: PTY sized 77x33 from outside answers exactly that, pipe answers
  nil, widths a/CJK/combining/BEL = 1/2/0/-1; test_term 81/0, woc 557/0
- story runtime-v2 6 recorded done; board row appended

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit 1514fb46c21c4318856cfcb3ca2b4d430caba72b)
2026-09-15 01:15:30 +02:00
6e997759e5 docs(rt2): close out runtime-v2 1-5
- five stories status: done; 00-story records the one-run landing
- spec History: three implementation amendments (Signal record not
  scalar, caller-owned stdio fds, handler-latch instead of signalfd)
- board NEXT PLAN entry with measured findings (zero transport code
  added; the tty-across-the-socket handover proven; the double-raw
  refusal restoring the terminal — the "bug" that was the design
  working); section rows flipped; graph nodes green
- CODE-LOGIC.md: the runtime-v2 section
- full belt quoted on the board: suites 0 fail both flavors (test_proc
  193/0, test_term 60/0), woc 557/0, subprocess 12/0, site 23/0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit bc1b4f070693eb755ad6a9fd0c853fb3e2bda347)
2026-09-15 01:15:30 +02:00
f52ee83ff4 feat(rt2): send_fd/recv_fd/connect_unix — an fd crosses the socket
- sendmsg/recvmsg with one SCM_RIGHTS fd and a sentinel byte; EAGAIN
  parks in the net mould; the received fd arrives nonblocking as a plain
  Int every fd verb accepts
- SO_DOMAIN gate: send_fd on anything but a unix socket refuses by name;
  plain bytes deliver nil from recv_fd
- net.connect_unix carried here (iteration 38 still pending)
- legs (single-fiber: unix connect completes while the listener holds
  the handshake): a pipe's read end crosses and still reads "ping"; a
  tty crosses, term.raw works on the RECEIVED copy and destroy restores
  it; refusal and nil legs verbatim. test_term 60/0
- full belt: all suites 0 fail both flavors, woc 557/0,
  subprocess-accept 12/0, site-accept 23/0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit 1d689027920d6814f87b97c216b0cb42f7eba3e9)
2026-09-15 01:15:30 +02:00
22ba51bfd3 feat(rt2): term.raw/restore — no wrecked tty, ever
- two verbs on any tty fd; saved termios in a per-shard 8-entry table;
  double-raw and restore-without-save refuse by name
- restore is a RUNTIME obligation: vm_unwind at depth 0 (uncaught trap,
  fiber reap) restores the dying fiber's entries newest-first, and
  wo_vm_destroy sweeps the rest — proven twice in the legs: a DIV0
  while raw restores, and even the double-raw REFUSAL (itself a trap)
  restores the first raw
- test_term 39/0 against a real PTY pair made by the test

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit b439387dbf4f653e034c721bc3f08b83616c5e24)
2026-09-15 01:15:30 +02:00
c55d6e1d33 feat(rt2): signal.on — latched signals become Signal records for actors
- mechanics amendment to the spec (recorded at close-out): no signalfd —
  the stop-latch pattern generalized. An async-signal-safe handler
  latches the number, bumps a sequence and pokes shard 0's wake eventfd;
  wo_io_wait's loop head drains latches into fresh Signal{sig} records
  delivered via runtime_notify (exported as wo_actor_notify)
- payloads must be heap objects (vm.c drops them unconditionally) — the
  Signal record exists exactly for that; class id rides the call as the
  appended record operand (sm_record drives it even with no return)
- offerable: WINCH/CHLD/HUP/USR1/USR2; SIGTERM/SIGINT refused naming the
  stop latch; shard-0-only registration; coalescing disclosed
- stdlib_modules gains `signal` (and `term`, next task)
- test_term: a real child kills the test process with USR1; the actor's
  multi holds one coalesced delivery; refusal leg verbatim. 14/0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit 14e03a6a4a343b97c9b47fab1a5e3c4bb69d8201)
2026-09-15 01:15:30 +02:00
0c7d0530e9 feat(rt2): spawn_pty + resize — a child that believes it owns a terminal
- posix_openpt/grantpt/unlockpt/ptsname_r (plain libc, no -lutil); child
  setsid + opens the slave as its controlling terminal, initial
  TIOCSWINSZ from the call
- Child.stdin == Child.stdout = the master (caller's copy); the slot
  keeps a private dup so resize survives the caller closing theirs
- proc.resize -> TIOCSWINSZ; refuses by name on a pipe child
- legs: test -t proves a real tty; stty size reads "24 80" then "40 120"
  after a mid-sleep resize; refusal asserted; test_proc 193/0 ASan clean

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit 9836c9cd5197153517c054b243cab3b453d130a0)
2026-09-15 01:15:30 +02:00
803ff0b790 feat(rt2): proc.spawn/wait_dl/signal — the streaming child
- a child is fds: Child {id, stdin, stdout, stderr}, driven by the
  existing net verbs (echo leg proves cat round-trip through write_dl/
  read_dl); caller owns the fds, the runtime owns pid + pidfd
- wait_dl parks on the pidfd: code on exit, nil at the deadline with the
  child untouched; one waiter per id, a second refuses by name; stale
  ids refused via a generation counter in the handle
- proc.signal through pidfd_send_signal; actor_die kills the streaming
  children the dying actor owns; dead fibers cannot linger as waiters
- ids 97-107 registered wholesale (wob.h, loader arities, dispatch
  bound); Child + Signal predeclared records in types.ml; unimplemented
  ids trap at the default case until their task lands
- test_proc 168/0 (echo, wait trio, one-waiter refusal, 200-round churn
  fd-flat), suite ASan clean, woc-test green

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit 9be87f159f1bf9cdd509ceed160e7ea518fde46c)
2026-09-15 01:15:30 +02:00
3190b609af docs(rt2): track-wide brainstorm — all five iterations ready, graph remapped
- spec 2026-09-01-runtime-v2-design.md: the one principle (PULL — a
  child is fds, the net verbs drive them; runtime-v2 adds acquisition
  verbs, never transport), the full surface (ids 97+: spawn/spawn_pty/
  wait_dl/signal/resize, signal.on delivering the sig number, term.raw/
  restore with runtime-guaranteed restore, send_fd/recv_fd/connect_unix),
  actor-owned lifecycle, mechanics notes, refusals by name
- push transport rejected with reasons recorded (mailbox-cap collision,
  new delivery machinery); death-notice verb refused (a two-line fiber
  composes wait_dl)
- five stories flip readiness: ready; fork sections rewritten as settled
- graph section 6 remapped: pull broke the 1->2->3 chain — only 1->2
  remains; 3, 4, 5 and the VTE grid startable alone today
- board section + registry follow; linkcheck 0 broken

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit d313cdeebbe53c83b83f31f4480631568d9d0743)
2026-09-15 01:15:30 +02:00
ab8ef64cd9 docs(rt2): runtime-v2 track — the runtime beyond sockets
- five stories under docs/stories/runtime-v2/: 1 streaming subprocess
  (42's follow-up; five forks incl. the mailbox-cap collision), 2 PTY,
  3 signals-as-events (signalfd lean), 4 termios adoption, 5 SCM_RIGHTS
  fd passing; 00-story states the arc — the plane learned sockets in
  8/11/35, files in 6, this adds processes/terminals/signals
- build order 1 -> 2 -> 3; 4 and 5 startable alone; all readiness:
  refine, brainstormed on demand
- board: Five tracks; "▸ runtime-v2" pending section; wmux section now
  points at it; graph section 6 nodes carry runtime-v2 numbers + links
- wmux stories re-reference the track; prefix `rt2` claimed
- linkcheck: 0 broken

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit e0451cb4889bb3d03429c0276d03c090269a5ced)
2026-09-15 01:15:30 +02:00
185251c404 docs(site-update): guide for changing the site application
- new docs/guides/updating-site.md: the developer loop deploying-site.md
  deliberately does not cover — the submodule two-repo commit dance in
  the order that cannot strand other clones (push writeonce-site first,
  bump the pointer second), the gate living in the monorepo by design,
  and framework changes being ordinary monorepo commits
- the schema section is measured against the built site, not inferred:
  adding views: Int stopped the build with WO-E206 until all ten seed
  inserts carried it (no field-default syntax — the seed cannot drift
  from the schema), then the live WO_DATA migrated at boot, all ten
  chapters rendered, and a live admin edit SURVIVED the migration;
  retyping the field refused by name with the log intact
- states the one release combination that still needs the content wipe:
  a schema change WITH new seed rows — migration handles the shape,
  seeds still cannot reach a non-empty table
- deploying-site.md cross-links; site-update prefix registered

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit a21a02f2c264a3fe1c31b3bfd9159415a594fa05)
2026-09-15 01:15:30 +02:00
073b252b69 docs(commit-history): site-submodule landed on master
- registry row corrected: it claimed "Not picked to master", and the
  branches no longer differ structurally at docs/examples/site
- cherry-pick table gains the same row master's copy carries, so the
  ledger reads identically from either branch

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit ab7df69e762cd516d3016b7e2703cb6928c7d835)
2026-09-15 01:15:30 +02:00
bc5823f50b docs(commit-history): mirror the master cherry-pick record onto dev
- same 37-row dev-to-master map the master copy carries, so the ledger
  reads the same from either branch
- registry rows for db2-keys, db2-delta, db2-chains, db2-chain-review
  and site marked landed on master
- lang41 registered explicitly as on dev and not picked, so its absence
  from master is a recorded decision rather than an oversight
- porch-store and query-corpus rows untouched: still dev-only

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 22b5675ed1c873135e8cb7dd10e010c4a00350b7)
2026-09-15 01:15:30 +02:00
b9ce271b3d fix(lang41): an unadopted shard must not impersonate shard 0
- root cause: a worker's runtime is initialised lazily on first fiber
  adoption, and rt.shard_id is stamped only there — but INBOX_READY[i]
  is set at thread creation. A shard that never adopts is still settled
  at shutdown, carrying rt.shard_id 0 from the memset
- it then impersonated shard 0: wo_drop_obj saw 0 == 0 for anything the
  primary allocated, took the "we are home" branch instead of routing,
  and called class_free against rt->classes, which lazy init never
  filled. &rt->classes[class_id] off a NULL base is the faulting read
- fix: stamp the runtime's real identity at thread creation. An
  uninitialised shard owns nothing, so its true id makes every payload
  correctly foreign and routes it to an owner that can free it
- ASan could not name this: the arena is one hand-managed malloc block,
  so intra-arena reuse is invisible and it surfaces as a bare SEGV
- pinned by tests/regress/lang-41, driven from db-actor-accept. Needs
  multiple shards (the corpus runner pins WO_SHARDS=1) and the ASan
  build. SEGVs twice per run unfixed, clean fixed
- the HANG is a separate defect and is NOT fixed: with this in place the
  harness stops losing whole sections, but idempotent-stop-2 still
  fires ~1 run in 6. The story records where to look

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 9dca0b4b4727b976d326b29cb4c6522b62d48a73)
2026-09-15 01:15:30 +02:00
5e619cf9de docs(porch-store): the fifteen rulings taken during execution
- records every decision made without stopping to ask, with what each
  costs if wrong, since the SDD workspace is deleted on completion
- R9 is marked WRONG and overturned by R14: WO-E222 fires on the class
  Pool, not on multi, so an actor can hold slots: multi PoolSlot. My
  ruling shipped a README prescribing a permanent 1-actor pool
- R6 records that my own brief caused a security bug: trust_proxy with
  an absent XFF collapsed every client onto one shared bucket
- R15 parks the one residual: pool_slots/pool_of have zero call sites,
  so real N-actor sharding is compile-proven but gate-unproven
- measured the gate over 10 runs: it is NOT stably green. Most runs
  fail idempotent-stop; one lost 6 checks with 000 status codes
- traces the flake to the C-runtime hang/segfault, now localised by gdb
  to wo_arena_alloc / wo_str_new / vm_run

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit a919ab104ce44754949d364e35c88b6964b81fee)
2026-09-15 01:15:30 +02:00
484402a156 docs(porch-store): correct the one-slot-pool advice, soften a gate-proof claim
- bullet 2 wrongly told app authors to hold a bare actor handle and
  re-wrap it as a forced ONE-slot Pool per connection -- that was my
  own advice, not the previous implementer's, and the reviewer showed
  WO-E222 fires on the class Pool, not on multi PoolSlot
- rewritten around the new pool_slots/pool_of pair: make_pool(n) once
  at process start, multi PoolSlot held directly in connection-actor
  state, a transient Pool rebuilt per use -- and states explicitly that
  calling make_pool per connection restores the lost-increment race
- disclose that the gate's own ConnWorker fixtures still build a
  deliberate one-slot Pool per leg, so no leg yet exercises real
  N-actor sharding through pool_slots/pool_of
- soften the rate-limiting row: saturation-503 is gate-proven only via
  Idempotent/pool_begin, not through Limiter's own try/catch arm

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 6d48dbca98d4ea4c6d93f470ae3aad0b00acd2a1)
2026-09-15 01:15:30 +02:00
263cf61d95 fix(porch-store): gate legs pin the header-case and cross-path digest bugs
- new handlers/routes: casecheck (key_header: "Idempotency-Key", the
  README's documented shape) and patha/pathb (include_body: false,
  same key, different routes)
- 18g: capitalised key_header + capitalised wire header must still
  dedupe (exec count, not status, is the load-bearing assertion --
  pre-fix both calls answer 200 either way, but the handler reruns)
- 18h: same key on two different routes with include_body:false must
  answer 200 then 422 (a digest mismatch, same as a body mismatch),
  never replay route a's body under route b
- both legs run on a FRESH restart of the same binary, not piled onto
  18a-18f's already-loaded server -- doing so measurably raised how
  often this run hit the pre-existing, out-of-scope C-runtime
  arena-allocator race (confirmed by gdb backtrace: SIGSEGV inside
  wo_str_new, unrelated to this file's own .wo logic)

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 86e7244dd97fb8ba940f8c0029faa05f70506e59)
2026-09-15 01:15:30 +02:00
03a7ad6658 fix(porch-store): log a genuine pool_count trap, not just 503 silently
- catch (e) nil could not distinguish a real store failure (e.g. a
  mod-by-zero from Pool { actors: [] }) from ordinary saturation
- print_err the trap message before answering 503, matching the same
  fix in idempotent.wo's pool_begin catch

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit c53ad583051abeeeb302301fc3d91073f0a15fcc)
2026-09-15 01:15:30 +02:00
359d21a57f fix(porch-store): widen idempotent replay headers, real per-conn sharding
- stored/replayed headers widen from content-type only to an allowlist
  (content-type, location, etag, cache-control), matched case-insensitively
  -- a redirect() lost its Location on its own first response, not just replay
- add pool_slots(Pool) -> multi PoolSlot and pool_of(multi PoolSlot) -> Pool
- Pool is demand-promoted to traced (WO-E222) and can't live in actor
  state; PoolSlot/multi PoolSlot never is, the same shape chat/main.wo's
  Room already holds directly -- this is what lets an app actually shard
  across N actors per connection instead of a forced one-slot pool
- log a genuine pool_select trap instead of silently folding it into 503
- fix stale comments: the prune below IS a delete-then-insert (of a
  fresh row, not the same one) contradicting the doc comment above it;
  the catch shape referenced in two comments had changed

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit b738269314f01a95dee1341437c7661ce9e28730)
2026-09-15 01:15:30 +02:00
899f2c604e fix(porch-store): idempotent key_header must be matched case-insensitively
- normalise self.key_header via to_lower before the req.headers lookup
- req.headers keys are already lowercased on read (internal/parse.wo);
  the documented key_header: "Idempotency-Key" never matched, silently
  disabling idempotency (falls through to inner.handle) on every request
- key/digest lookups use the normalised name consistently
- digest now always includes method+path, body appended only when
  include_body is set -- a bare "" digest under include_body:false
  previously matched any other request reusing the same key
- log a genuine pool_begin trap instead of silently folding it into 503
- update the two doc comments describing the old, unsafe shape

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 91099cfbb2fb9a2d351894e444fed306b25557d5)
2026-09-15 01:15:30 +02:00
581fe5fd51 fix(porch-store): saturation teardown no longer counts as a check
- Add a neutral note() helper (prints, touches neither pass nor fail)
- Use it for the saturation leg's unconditional teardown line, which
  previously called ok() regardless of branch taken and inflated the
  reported count with a line that could never fail
- New count: 78 checks, 0 failures (was 79) -- every number now is a
  real assertion

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 2ac1b8b6db360d4423dbb53d5d26b355e7b05e71)
2026-09-15 01:15:30 +02:00
84cfbb1885 docs(porch-store): saturation gate leg closes out porch 1
- Add saturation leg (scripts/web-app-accept.sh): one-actor pool,
  WO_MAILBOX=2, 15 concurrent requests, exactly 3 served + 12 answer
  503; execution count matches the 200 count, retry-after + real
  cause verified on the 503s
- Guard make_pool(n<1) by clamping in make_pool itself, not
  pool_select's division -- that trap runs inside the middleware's
  own try/catch and would be swallowed as ordinary saturation forever
- README: rate limiting + idempotency ledger rows moved to done,
  scoped to what the gate proves; documented Handler-decorator
  shape, Pool aliasing (WO-E222), call's scalar-only reply (WO-E226),
  pool size as a capacity decision
- Story: Progress table filled with real hashes, 7/9 acceptance
  criteria marked verified with citations, 2 marked verified by
  construction (never gated even in the original plan), status: done
- Status board: standup entry, porch 1 pending row updated
- Recorded a pre-existing runtime hang (main() returns cleanly, OS
  process sometimes hangs under concurrent call()-parked callers)
  that also reaches the new leg's teardown; contained with kill -9
  rather than asserted, so it can't flake the leg's actual subject

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 21934b18910070a3f24b8bd4367fcb9d397dc1fb)
2026-09-15 01:15:30 +02:00
659ea26582 fix(porch-store): delete the ephemeral nonce row after one read
- The nonce naming an ephemeral (4xx/5xx) row is handed to exactly one
  call() reply and nowhere else -- no other message can ever construct
  that key, so idempotent.wo deleting it right after building the Resp
  is safe by construction (unlike the earlier shared bare-key row,
  which a second message COULD reach and made deleting it racy)
- Closes the leak AND a real correctness edge: the nonce is
  time.ticks() % 1_000_000_000, wrapping every ~1000s -- with rows kept
  forever, a later failed attempt on the same key could land on the
  same nonce and either collide with the unguarded insert or resurface
  a stale replay, exactly what rounds 1/2 removed
- Gate leg 18f: N ephemeral attempts against the same key must return
  IdempotencyKey's row count to baseline, not grow it by N -- confirmed
  failing (baseline+N) against the pre-fix code, passing after
- N picked at 3: the pre-existing runtime hang/segfault (out of scope,
  being tracked separately) reproduces more often at higher sequential
  insert+delete volume against the same key; 3 stayed clean across
  many runs while still proving the property precisely

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 9ad594748e01a665ccaf29733a48c2b83a2749da)
2026-09-15 01:15:30 +02:00
e296d0541d fix(porch-store): close the ephemeral-row race, not just shrink it
- Root cause of the residual: a 4xx/5xx row lived under the bare key,
  so a second message could delete-and-replace it before the FIRST
  caller's own middleware-side read (necessarily outside receive,
  WO-E226) ever ran -- the owner itself could read back a LATER
  message's answer, not just a duplicate reading a stale one
- Fix: a 4xx/5xx miss is never stored under the bare key at all. Each
  such attempt gets its own row, keyed by a nonce carried back in the
  scalar reply's low digits, so no other message for the same bare key
  ever touches it -- the decision AND the row's identity are both
  fixed inside the one serialized receive call
- Disclosed trade-off: that row is never revisited by a bare-key
  lookup, so it is never TTL-pruned either -- permanent per failed
  attempt, the same no-sweeper trade-off this codebase already makes
  elsewhere, not a new one
- Gate leg 18e: reran 20x in isolation against the fix with zero
  500-500 or 200-200 outcomes (was reproducible before)
- §18's SIGTERM-stop check now force-kills on timeout before clearing
  $SRV, instead of matching §14/§17b's own gap where a still-running
  process escapes the exit trap too -- an orphan no longer survives
  past this leg regardless of the assertion's own outcome

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 464147a9ddf3a53cb1946637c3f517ba615ee358)
2026-09-15 01:15:30 +02:00
d98ff82027 fix(porch-store): never replay a cached transient 5xx
- Miss path only marks a response a durable replay target (outcome 1)
  when status is 2xx/3xx; a 4xx/5xx gets outcome 3 instead
- Outcome 3's row is a one-shot relay: the scalar reply still can't carry
  a Resp (WO-E226), so the row exists only to hand the exact response
  back once, then idempotent.wo deletes it -- a retry with the same key
  is a genuine miss and re-executes, instead of caching a 500 for the
  24h default TTL
- Reviewer finding: caching any status meant a transient failure was
  replayed verbatim until TTL expiry, worse than no idempotency at all
- Gate leg 18d: FlakyHandler fails once then succeeds; same key twice
  must answer 500 then 200 -- confirmed failing (500, 500) before the
  fix, passing after

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit e61015f2065a7c6aec6f5c2439e78b53f796bab3)
2026-09-15 01:15:30 +02:00
c97de237ef feat(porch-store): idempotency rebuilt so the actor runs the handler
- Delete before/after flow: it stored on a miss, so two duplicates both
  missed and both ran; its 10s "in flight" check fired on fast legit
  replays and never on a real collision
- Idempotent now wraps the route's Handler and hands request + handler to
  the pool; a duplicate waits in the actor's mailbox, not a held reply
- keypool.wo kind-2 arm: digest match replays, mismatch refuses (422), a
  miss runs the handler inside receive and stores status/body/
  content-type, all via the same pool_pack(count, remaining_ms) scalar
  kind-1 uses (WO-E226 forces one return type)
- Outcome codes start at 1, never 0: idempotent.wo's try/catch cannot
  tell a literal 0 reply apart from a trapped call
- fresh_req() copies a borrowed Req's map fields into a new Req before it
  crosses the actor boundary (WO-E222: aliased graphs can't cross heaps)
- Reading a stored row back forces fresh Text via `.. ""` on every field
  copied out of json.decode's result -- decoded Text does not survive
  being handed onward once the decoded record goes out of scope
- insert is unguarded (kind 1's own convention): a swallowed failure
  would answer "stored" for a response never written
- web-app-accept.sh: leg 18a/b/c -- byte-identical replay off an ExecMark
  row count, digest mismatch is 422, genuinely parallel duplicates run
  the handler exactly once

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit eae1b06cdc38e4766d4e27a66b02264f47164e99)
2026-09-15 01:15:30 +02:00
37a63192c6 fix(porch-store): trust_proxy falls back to net.peer on an absent XFF
- limiter_key: an empty client_ip(req) under trust_proxy no longer keys
  on the literal "ip:" -- falls through to net.peer(req.conn) instead,
  same as the untrusted-default path
- the bug: every client omitting X-Forwarded-For shared ONE bucket,
  so one could exhaust it and deny/hide the rest
- curl availability check added alongside the existing woc/wovm check
  (the limiter gate legs drive the server with it)
- new gate leg: LIMIT+1 sequential no-XFF requests must all be 200
  (own key per connection, via a fresh ephemeral port each time) --
  confirmed it fails against the pre-fix code (6th comes back 429)

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 831e9d8e6b1ef39cd938783dbc47c1abe6d53211)
2026-09-15 01:15:30 +02:00
491c2f42b4 feat(porch-store): limiter delegates all counting to the key pool
- delete all RateLimitCounter access from limiter.wo: query, increment,
  delete-then-insert, and the swallowing catch (e) nil -- the pool is now
  the only writer, so its serialization guarantee actually holds
- Limiter gains pool/limit/trust_proxy fields; before() calls pool_count
  and acts on the Verdict; make_limiter takes a pool
- key selection: req.principal first, else trust_proxy ? client_ip(req)
  : net.peer(req.conn); delete the dead req.ctx["verified_proxy"] branch
- 429 on a spent window (Retry-After, X-RateLimit-*); 503 + Retry-After
  on a caught actor trap (saturated pool), request never let through
- add Limiter.after(), registered alongside before() as both Mw and Aw
  (Cors's own shape) so the allowed path's X-RateLimit-* headers reach
  the response, not just req.ctx
- scripts/web-app-accept.sh: three new gate legs -- threshold (N pass,
  N+1th 429), SIGTERM+restart (still limited from the WAL), and N
  genuinely-parallel curl clients on one key with an exact-count assertion

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit a653dd0aa64711c43461126d32b4632cc8f64c7a)
2026-09-15 01:15:30 +02:00
9af42c8e69 fix(porch-store): correct reset_at unit on the two fresh-window paths
- keypool.wo:78,89 passed msg.window (µs) straight into pool_pack's
  remaining_ms (ms) parameter on the first-hit and post-prune-reset
  paths; the third call site already divided by 1000 and was correct
- fix: pool_pack(1, msg.window / 1000) at both sites — a 60s window
  no longer reports reset_at ~16.7h away
- count/allowed were unaffected (computed independently); this only
  hit the client-visible reset instant, on the two most common cases
  (new key, window rollover)
- extended gate leg 16 to assert reset_at falls within a 5s band of
  time.now() + window_ms, not just on count — verified the assertion
  itself by reverting the fix, confirming leg 16 failed with the
  exact defect shape, then restoring it and confirming green
- woc docs/examples/porch/ exits 0; web-app-accept.sh: 47 checks,
  0 failures

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 153fd295d37905dd083823536c6781843699e455)
2026-09-15 01:15:30 +02:00
88b61f7522 docs(porch-store): call replies are scalars — response goes via the table
- WO-E226: call's reply must be a copyable scalar, and every receive
  program-wide must declare the same return type. Verified by fixture:
  "call's reply type `Out` is not a copyable scalar"
- the spec had the actor return the response object, which cannot cross
  the mailbox. Corrected: the actor stores the response and returns an
  outcome code; the middleware reads the row and builds the Resp
- owner and duplicate now read the SAME durable row, so byte-identical
  replay is structural rather than careful copying
- blocking, exactly-once execution and the mailbox queue are unchanged

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 77e06c1690b92d456a9bc53503695fdaa2b4b44e)
2026-09-15 01:15:30 +02:00
4be826f9ab feat(porch-store): key pool actor for serialized per-key counting
- add docs/examples/porch/middleware/keypool.wo: one PoolMsg (kind 1 =
  count, kind 2 = begin placeholder for task 4), a Verdict class, a
  fixed-size actor pool with a byte-sum-mod-N selector
- KeyActor.receive implements kind 1: reads the row, writes the new
  count via field assignment (writes through, never delete+insert),
  prunes a fully-elapsed window's row instead of resetting it
- window arithmetic on time.ticks(); reset instant sent back is built
  from time.now() only
- call's reply must be a copyable scalar (WO-E226), so the count and
  remaining window time are packed into one Int by the actor and
  unpacked into Verdict by pool_count — the packing stays inside this
  file, callers only ever see Verdict
- gate leg in scripts/web-app-accept.sh: a flat copy of porch (manifest
  stripped) with a driver dropped beside keypool.wo asserts two
  sequential counts return 1 then 2; verified failing (E403, make_pool
  undeclared) before this file existed, passing after
- woc docs/examples/porch/ exits 0; full web-app-accept.sh: 47 checks,
  0 failures

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 676e651d808ef2c3619f88c3808adc372cd0be6c)
2026-09-15 01:15:30 +02:00
377808b936 feat(porch-store): add digest column to IdempotencyKey table
- Add digest field to store sha256(method|path|body) separately from key
- Enables detection of "same key, different body" in future tasks
- Update idempotent.wo insert to compute and store digest value
- Typechecker passes: exit 0

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 3a9bddcd1e3c11f5b371ce54cafc373685ca08b6)
2026-09-15 01:15:30 +02:00
560987d969 docs(porch-store): plan corrections from the pre-flight scan
- one message class with a kind discriminator, not a receive per
  message type: an actor handle is typed to one message class, so a
  second receive compiles but is unreachable. chat/main.wo is the
  precedent. Verified by fixture before amending
- Task 4's Files list omitted keypool.wo, which its step 4 edits
- clarified that the delete-then-insert ban targets using that pair as
  an UPDATE; pruning an expired row is a plain delete and is required

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit a96ebe20e92e2dc6dfecc59a955d4c6e75d74689)
2026-09-15 01:15:30 +02:00
dbee71a9e5 docs(porch-store): implementation plan, and a spec correction
- the spec's blocking design was unimplementable: call's reply IS the
  return value of receive, so an actor cannot hold a waiter. Holding
  means never returning, and an actor that never returns cannot process
  the completion it waits for — deadlock
- corrected shape: the actor RUNS the handler inside its own receive, so
  a duplicate waits in the mailbox and is served after the owner. The
  queue blocking needs is the mailbox; nothing is held
- verified before adopting it, not after: an actor can receive a message
  carrying an interface-typed value and invoke it, so the route's
  Handler passes through the mailbox
- spec History records the reasoning error — "the primitives landed" was
  taken as "blocking needs no new surface", which does not follow
- plan: 5 tasks. Counting and replay live in one new keypool.wo; both
  middlewares become thin key-choosers, so porch 2 and 3 inherit one
  serialization convention instead of re-implementing it
- self-review added two legs it was missing: exact counting under real
  concurrency (the criterion the pool exists for), and pruning an
  elapsed limiter row rather than resetting it, which otherwise leaks a
  row per IP ever seen
- plan is code-free per house convention; the writing-plans skill wants
  code blocks and the project rule overrides it

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit f079455755a189a86bb12e07cc11549ed7a78b91)
2026-09-15 01:15:30 +02:00
aee5adddc4 fix(porch-store): add the missing use json import
- docs/examples/porch/ did not typecheck: WO-E403 "cannot resolve the
  receiver's type for the call to `encode`" on json.encode
- every other example that calls json.encode/decode imports it; this
  file did not, so the whole porch library was uncompilable on dev
- woc docs/examples/porch/ now exits 0

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 5c3544d524fa98dbb7a363600cd2eeb6dd1badac)
2026-09-15 01:15:30 +02:00
9f2d19083e docs(porch-store): spec for porch 1 store-backed middleware
- supersedes Phases B and C as built: a store-after-completion
  middleware cannot satisfy three of the story's seven criteria
- in-flight collision is undetectable (the row is written after the
  handler ran, so concurrent duplicates both miss and both execute)
- the 10s in-flight heuristic is inverted: created_at is stamped at
  store time, so it fires on legitimate fast replays and never on a
  genuinely concurrent request
- "reused key, different body is refused" is unreachable while the
  digest is folded into the key — nothing looks the bare key up
- design: sharded actor pool serializes per key, @table persists;
  actors own volatile state, tables own durability. Inherited by
  porch 2 and 3
- limiter joins the pool for exact counting, writes through instead of
  delete+insert, keys on net.peer unless trust_proxy is declared, and
  uses monotonic ticks for arithmetic but wall clock for the header
- idempotency blocks rather than answering 409: call parks the
  duplicate until the owner reports. Digest becomes a column
- saturation fails closed with 503 for both: saturating the pool must
  not become the limiter bypass
- records that the story's "time.after is still reserved" is stale;
  spawn/send/call/monitor/time.after all landed

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit fc09e94373db65837ff5eb620fec67bab02c1931)
2026-09-15 01:15:30 +02:00
c53a335286 docs(commit-history): register porch-store Phase C
- Idempotent middleware (aee7926) added to the porch-store row
- records that Phase C is unverified: no `use json` import despite
  calling json.decode and json.encode

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit aa8abfb4b7a1dabaa0c68afa0ee7fdfccf1b4689)
2026-09-15 01:15:30 +02:00
bf343045ab feat(porch-store): Idempotent middleware (Phase C, in progress)
- replays a stored response for a repeated Idempotency-Key: before()
  checks the key, after() stores status/body/content-type on a 2xx/3xx
- key is "idem:<header>:<value>", optionally plus a sha256 digest of
  method|path|body when include_body is set
- 409 while a key is in flight (stored within the last 10s), lazy TTL
  expiry on access, default 24h
- replay allowlists content-type only — never Set-Cookie or Date
- backed by IdempotencyKey from Phase A (519d411)

Written by a parallel session and committed here as-is because its
branch was consolidated away. NOT verified: it calls json.decode and
json.encode without a `use json` import, which every other example that
uses json has. Left unedited rather than fixed blind.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit aee79264095eea3b2c38c92789c44b31f1c9ef8a)
2026-09-15 01:15:30 +02:00
b21cfde1bf docs(commit-history): record the branch consolidation
- porch-store and query-corpus prefixes registered; both replayed onto
  dev, so dev is a superset of porch-store-middleware
- three branches could not be replayed and are preserved as annotated
  tags rather than merged or discarded:
  - cleanup/pre-existing-changes carries crates/ + Cargo.toml, the Rust
    runtime master deleted; replaying it would resurrect it
  - ipc-attach refactors wo_row_insert/wo_row_update_field into
    encoded cores, which db2-keys rewrote for keys-residency — two
    overlapping refactors of one function
  - keypair-auth builds on ipc-attach, blocked by the same overlap
- names the specific hazard: 9c transfers ownership of vals on failure,
  dev's keys-resident arm returns early without freeing, so a merge
  that compiles and passes could still leak or double-free

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit bc8fec01d565d0ad54696fb3d2f85a9d1e0531a1)
2026-09-15 01:15:30 +02:00
5941a092f7 feat(query-corpus): iteration 9g corpus #1 — skillhost needs no new query grammar
- resolved 9g's forks EMPIRICALLY against the running compiler:
  - count(<query>) and len(<query>) already work (fork 2 collapses to
    zero code)
  - skillhost's correlated NOT EXISTS is a backlink emptiness in
    writeonce (`where len(x.children) == 0`), using only 9b machinery
    (fork 1) — verified on a self-referential ?ref/backlink table
  => corpus #1 forces NO new grammar; per the method ("add only what a
     corpus uses"), exists/not-exists was NOT built
- docs/examples/skill-catalog: mirrors skillhost's `skills` table
  (name @unique, description/location/root, parent ?ref Skill, children
  backlink) and translates all five of its SQL statements 1:1
  (insert+dup-trap, get-by-name, list, roots via backlink-emptiness,
  count); scripts/skill-catalog-accept.sh 7/0, WAL-durable, dup trap
  persists across restart
- fixture run/db-query-corpus (count(query) + backlink NOT EXISTS);
  just skill-catalog module; target/ gitignored
- general exists/not-exists left unbuilt and recorded as "enters when a
  corpus forces a non-relation correlation"
- gates: oop-e2e 80/0, woc-test 566/0, skill-catalog 7/0; story + board
  record the finding

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 4c82461634d45f11eca1a252702031c03d999c7f)
2026-09-15 01:15:30 +02:00
e159b5a754 feat(porch-store): Limiter middleware (Phase B)
(cherry picked from commit 5b1e82ab4bf3bad39bb6762a52b2dfaafd18a110)
2026-09-15 01:15:30 +02:00
192d451f5e feat(porch-store): store tables for rate limit + idempotency (Phase A)
(cherry picked from commit 519d4117fd0d6d0bd7d51f80bcb20de4d6294503)
2026-09-15 01:15:30 +02:00
4f6dc2dcfc docs(commit-history): record the lang42 cherry-pick
- registry: lang42 on master 2026-09-01
- pick row: 8 commits mapped dev -> master, zero conflicts
- verified on master after full rebuild: 38 runtime suites 0 fail both
  flavors (test_proc 128/0, test_wal 5966/0), woc-test 557/0 forced,
  subprocess-accept 12/0, site-accept 23/0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-01 22:27:02 +02:00
b17b848403 docs(lang42): close out iteration 42
- story frontmatter status: done, Progress section records what landed
  vs the spec (everything, same day as the brainstorm)
- board: NEXT PLAN entry with the six standup answers (deadlock proven
  real: 5 s hang, 8192-byte truncation; 15 ms after; ping 2 ms during a
  parked child; 1000 spawns fd-flat; SIGTERM leaves no child); pending
  row flipped to DONE
- graph: node 42 class done, same change as the board row
- runtime/src/CODE-LOGIC.md: the bounded-subprocess section (bundle
  park, slot registry, ownership sweeps, raw pidfd syscalls)
- full belt at close: 19 runtime suites 0 fail (test_proc 128/0),
  woc-test 557/0, subprocess-accept 12/0, site-accept 23/0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-01 22:19:25 +02:00
c91027bcc6 feat(lang42): subprocess example + gate
- docs/examples/subprocess: line-oriented TCP service, one Handler actor
  per request — ping/run/slow/deadline/cap/long exercise the whole
  bounded surface from .wo, traps caught with try/catch in the language
- scripts/subprocess-accept.sh + `just subprocess`: 12 checks, 0 failures
  first run — deadline and cap messages verbatim, ping answered in 2 ms
  while a sleep-2 child was parked, SIGTERM exit 0 with the sleep-30
  child verifiably gone (pid checked from outside)
- service logs to /tmp/subprocess.log, banner-separated per run

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-01 22:19:25 +02:00
baede5c373 feat(lang42): proc.run_dl — deadline and caps at the call site
- one stdlib_members row (arity 5, id 96, nullable Proc return, Proc
  record class appended) — the net _dl precedent verified: those rows
  needed no emit.ml change and neither does this one
- woc-test: 557 checks, 0 failures

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-01 22:19:25 +02:00
4180ee09d4 feat(lang42): ceiling, churn, unwind and stop legs
- ceiling: 32 fibers hold live sleepers; the 33rd spawn traps WO_T_IO
  naming the ceiling; destroy sweeps all 32 (waitpid -1 = ECHILD after)
- unwind: a fiber parked on a live child is reaped at main's return and
  the child dies with it (nchildren 0 straight after the call)
- churn: one thousand sequential `true` runs through a bytecode loop —
  fd count flat, every slot released
- stop: SIGTERM from a helper 200 ms into a sleep-10 child answers rc 1
  (STOPPED) with no surviving child
- test_proc 128 pass 0 fail in 2.6 s, suite ASan clean

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-01 22:19:25 +02:00
5d1c82bbd6 feat(lang42): deadline and output caps refuse by name, shard keeps scheduling
- proc.run_dl reachable: dispatch range extended to id 96 (builtin.c) and
  the loader arity table gains [WO_B_PROC_RUN_DL] = 6 — without both, the
  builtin answered "unknown stdlib builtin" (WO_T_EXPLICIT)
- deadline leg: sleep 10 vs 100 ms deadline traps WO_T_IO naming the
  deadline in ~120 ms; the pid is gone (waitpid -1 = ECHILD) and the fd
  count is flat; a worker fiber completes WHILE main is parked — the
  shard was never blocked
- cap legs: stdout and stderr caps trap naming "cap 1000", child dead
- argv multi carries a drop entry at the run pc: a trapping run frees it
  (LeakSanitizer caught the miss)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-01 22:19:25 +02:00
258222c3a1 feat(lang42): proc.run parks — pidfd + epoll bundle + child registry
- deadlock proven first: chatty child (200 KB stdout, stderr held open)
  hung the old sequential drain 5.0 s into the alarm, code -1, stdout
  truncated at 8192; the leg demands completion under 4 s
- rework: nonblocking pipe read ends + pidfd_open behind one epoll fd the
  fiber parks on (the _dl retry mould); both pipes drain on readiness, so
  the deadlock is gone structurally — leg passes in 15 ms
- wo_child slot table in wo_vm (32/shard) carries cross-park state; caps
  refuse by name (kill + WO_T_IO), deadline armed via dl_active/dl_at,
  defaults 30 s / 1 MiB / 64 KiB
- WO_B_PROC_RUN_DL = 96 shares the case (per-call deadline_ms/out_cap/
  err_cap; compiler row lands in a later task)
- fib_reap kills a reaped fiber's child; wo_vm_destroy sweeps the table
- raw syscalls for pidfd_open/pidfd_send_signal: glibc 2.35 build floor
  has no wrappers
- all 19 suites green under ASan+UBSan

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-01 22:19:25 +02:00
b8d9f9f594 feat(lang42): pin proc.run's current contract in test_proc
- new suite runtime/test/test_proc.c (auto-globbed by the Makefile)
- three legs against today's behavior: echo exits 0 with exact stdout,
  false exits 1, a missing command answers 127 (the execvp convention)
- record fields copied out before the vm dies; ASan clean

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-01 22:19:25 +02:00
8bcd24969e docs(lang42): story, spec and plan for bounded subprocess
- claim the lang42 prefix; iteration 42 story (readiness: ready), approved
  spec, and the 11-task implementation plan
- board: pending row for 42; graph: node 42 with green edges (11, 24)
- graph: porch track section added (same sweep)
- parity studies that motivated 42: alacritty, tmux, zen-browser under
  docs/plan/exploration/ — staged path, gap lists, refused routes

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-01 22:19:25 +02:00
bed1167ca9 docs(commit-history): record the iteration-12 cherry-pick
- seven commits dev to master, zero conflicts: the six db2-migrate
  commits plus site-deploy, which the close-out edits and which had
  been dev-only
- verified on master after the pick: 36 suites 0 fail (test_wal
  5966/0), woc-test clean, residency-accept 14/0, site-accept 23/0

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-31 22:02:18 +02:00
4ad24d6381 docs(db2-migrate): close out iteration 12
- crash-before-rename test: a COMPLETE valid migrated temp beside the
  untouched original is discarded and the boot re-migrates — the
  sharpest point on the crash timeline, deterministic, no fault
  injection needed
- story: all six tasks done with commit hashes, all eight criteria met
  with the test that proves each, plus the three deviations from the
  plan and why (transcode over replay, lazy head, poison forces
  transcode)
- CODE-LOGIC: migration section; also corrected limitation 3, which
  still claimed unbounded hot-row chains — iteration 11 closed that
- status board row 12; deploy guide's rollback section gets its real
  answer (rolling back across a migration is a migration backwards:
  expect the refusal, restore the .bak)
- test_wal 5966 pass, 0 fail

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 4bb6ece2531e2123eb958c91d9bef4a6528eab3b)
2026-08-31 21:54:27 +02:00
27aecd3dc1 feat(db2-migrate): boot performs the migration, and refuses by name
- main.c builds the compiled schema (names out of the constant pool,
  which the database layer never sees), peeks the log head before
  replay, and diffs: match replays as-is, add/delete migrates through
  the transcode, poisons refuse naming class, field and what to do
- fixed en route: a poisoned class SKIPPED the identity check, so no
  transcode ran and replay greeted the shape mismatch with the generic
  "corruption" — the exact message this iteration exists to replace.
  A poison now forces the transcode, where it either bites with its
  text or passes harmlessly when the class has no records
- the schema head is written LAZILY, ahead of the first real record:
  an eager head broke the documented "durable: false writes ZERO
  bytes" contract by 75 bytes and the residency gate caught it
- end-to-end at the language level: fresh boot seeds, identity
  replays, +field migrates with "migrating `Note`: +flag" and reads 0,
  retype refuses naming `val`, and the refused log still boots the
  previous binary untouched
- gates: wovm-test all green (test_wal 5951/0), woc-test clean,
  residency-accept 14/0, site-accept 23/0

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit b21943aa91152ebdcfc72bd4c9fba38730ab1c2f)
2026-08-31 21:54:27 +02:00
c6e158c6a1 feat(db2-migrate): the transcode — old log to new shape, record by record
- wo_wal_migrate rewrites the log without touching db state: no id
  maps, no indexes, no keys-resident logic — the new log replays
  through the machinery that already exists and is already tested
- cids remap by name, INCLUDING the ones embedded inside stored owned
  values (an owned value carries a cid on the wire); the embed closure
  guarantees every nested class is shape-unchanged, so only numbers
  move
- surviving fields go to their new slot, deleted fields' values are
  freed, added fields take the kind's zero value straight from
  enc_val(0)
- a delta on a deleted field is SPLICED out: an offset map (old record
  start -> new) rewrites every back pointer, and the dropped delta maps
  to its own target so later deltas step over it
- temp + fsync + rename, compaction's own crash discipline; a stale
  temp is discarded at start; a torn tail bounds the intact prefix
  exactly as replay does
- fixed en route: early `goto corrupt` jumped over initializers, so the
  handler freed uninitialized memory — declarations hoisted above the
  first jump
- six end-to-end tests: add, delete (ASan watches the freed Text),
  reorder with owned fixup, delta splice on a keys-resident chain,
  poison-bites-only-with-records, corrupt input
- test_wal 5951 pass, 0 fail

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit b69092a99206e1dcdf6f2dcdb02146939b0564c6)
2026-08-31 21:54:27 +02:00
df09158b7f feat(db2-migrate): the boot diff — name-keyed, poisons instead of errors
- wo_schema_diff matches classes and fields by NAME, so declaration
  reordering is identity apart from the cid map — the silent
  cid-renumbering hole closes as a side effect
- owned-field references (fclass) compare by the NAME the number
  resolves to, never the number: a raw compare would false-poison
  retype on every pure reorder
- refusals are per-class POISONS carried in the plan, not diff errors:
  a poison bites only when a record of the class is met, so a retyped
  class with no stored rows never blocks a boot
- poison set: retype, same-shape delete+add (a disguised rename, one
  reading destroys a column), vanished class, storage-flag change, and
  the embed closure — any class whose old records carry values of a
  class whose shape changed, iterated to a fixpoint
- identity plans skip the rewrite entirely; a NEW class in the binary
  does not break identity (no records; the head refreshes at the next
  compaction)
- ten verdict tests; test_wal 5778 pass, 0 fail

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 63a063b822af381a10c2e599c58cf3455d9c5bf7)
2026-08-31 21:54:27 +02:00
f07295b3c0 feat(db2-migrate): WO_WAL_SCHEMA — the log states the shape that wrote it
- new record kind 5: class and field NAMES, kinds and the two
  encoding-relevant metadata words (field_class, field_elem), CRC-framed
  like every record. Index layout deliberately absent: indexes rebuild
  from rows at boot and never touch record bytes
- names are byte pointers, not constant-pool indices — the database
  layer never sees the module's consts, so the runtime resolves them
  once; a decoded schema owns a private copy of its bytes
- wo_wal_set_schema adopts the compiled schema; wo_wal_ensure_schema
  writes it as a fresh log's first record; compaction writes it at the
  head of every replacement, which is how a legacy log becomes
  self-describing without a migration step of its own
- apply_record skips it BEFORE reading cid/id (its class count would be
  misread as a cid and bounds-refused); replay does not count it
- schema unset = byte-for-byte today's behaviour: all 5700 prior
  assertions pass untouched; four new tests cover roundtrip, fresh-log
  head, legacy adoption via compaction, and absent/empty files
- test_wal 5743 pass, 0 fail

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit ba8519fa5e39c6ed6a3504d39e5a372f8decd045)
2026-08-31 21:54:27 +02:00
1b6d633ed1 docs(db2-migrate): spec + story for schema migrations v1
- brainstorm settled: declarative and automatic at boot; v1 verbs are
  add and delete only; data/seed migrations deferred to v2
- added fields zero-fill by kind: the grammar has no field-default
  syntax and v1 refuses to grow compiler surface for it
- same-kind delete+add refuses as a disguised rename; retype and
  vanished classes refuse by name
- schema lives in the log itself: WO_WAL_SCHEMA head record, written by
  fresh-log open and compaction; name-keyed diff also closes the
  silent cid-renumbering hole
- story is iteration 12, board row added, db2-migrate prefix claimed

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 072e007b144ff6689b6ff920ea10665900c1a2ef)
2026-08-31 21:54:27 +02:00
552c129ce3 docs(site-deploy): redeploy runbook for writeonce.de
- new docs/guides/deploying-site.md: build, content refresh, systemd
  unit, post-deploy verification, rollback, and the gaps behind each
  workaround
- leads with the trap that costs the most: shipping a binary does NOT
  update chapters. seed_if_empty only fills an EMPTY table and
  AdminEdit answers not_found for an unknown slug, so a host with an
  existing WO_DATA shows the old chapter list with no error anywhere
- that claim is measured, not argued: a 9-chapter build seeded a data
  dir, then the 10-chapter binary against it still 404'd /ch/storage
  and rendered 9 nav entries; wiping WO_DATA gave 200 and 10
- records two more blockers found while writing it: both site deps
  (porch, writeonce-view) 404 on GitHub and wo.lock is untracked, so
  the site submodule cannot build standalone; and the embedded wovm
  sets the glibc floor (this machine: 2.38, above Ubuntu 22.04's 2.35)
- build recipe run verbatim before publishing; releasing.md points here

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 930a715c4a3d847529e3e341edc71c65a7e11d1c)
2026-08-31 21:54:27 +02:00
e31a037533 docs(commit-history): record the site-submodule cherry-pick
- 4b56348 -> 7d9d526, 4eead89 -> 653a91c
- the registry rows for lang41, porch-store and query-corpus came with
  the pick and are kept: the registry is a global claim ledger, so a
  copy that silently omits three claimed prefixes is worse than one
  that names them and says they are dev-only
- site-submodule row corrected on the way in — it said "Not picked to
  master", which this pick is precisely what falsifies
- verified on master after the pick: site-accept 23 checks, 0 failures

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-30 22:03:43 +02:00
653a91c702 docs(commit-history): register the site-submodule prefix
- records that docs/examples/site is now a submodule on dev only
- states the consequence plainly: master still carries the site inline,
  so the branches differ structurally at that path until this is
  cherry-picked

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 4eead8938c7292a130723aeabe7b74bdd1ba60f6)
2026-08-30 22:03:18 +02:00
7d9d526bb6 refactor(site-submodule): docs/examples/site becomes a submodule
- extracted to github.com/shoneyJ/writeonce-site with `git subtree
  split`, so the site keeps its own 9 commits of history rather than
  landing there as a flattened snapshot
- .gitmodules gains the third entry, alongside reference/writeonce-app
  and reference/writeonce-api; path is unchanged, so every doc and
  script that names docs/examples/site still resolves
- site-accept.sh fails early and says `git submodule update --init`
  when the directory is empty. Without it a clone lacking submodules
  copies an empty app and fails later as a build error naming nothing
- releasing.md: the steps that edit install/view.wo now say that edit
  is a commit in the site repo plus a pointer bump here — editing and
  committing only in this repo would record nothing
- gate re-run against the submodule: site-accept 23 checks, 0 failures

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 4b5634801d5379890bad24c8129cfb23ab6b98df)
2026-08-30 22:02:55 +02:00
e93284befb docs(commit-history): record the databasev2 residency cherry-pick
- first cherry-pick under this convention: 37 commits, dev to master,
  mapped one-to-one with titles
- iteration 11 could not travel alone — its commits touch
  wo_wal_fold_row_at, keys_fold_into and row_apply_field_keys, none of
  which existed on master, so the whole db2-keys/db2-delta stack came
- porch-store (26 commits) deliberately left on dev: porch 1 was
  re-scoped mid-flight, which is what "ready, not merely green" is for
- records the three docs conflicts and how each was resolved, including
  keeping only the databasev2 half of a status entry that would
  otherwise have had master claiming porch 1 was done
- records what is still outstanding: task 6's byte-budget refusal, a
  missing guard rather than an unhonoured annotation

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-30 20:45:39 +02:00
92d2600ae7 docs(commit-history): feature-to-cherry-pick reference
- records the workflow: develop on dev, feature prefix as the
  conventional-commit scope, cherry-pick onto master when ready
- prefix registry so two features cannot claim the same prefix; the
  prefix is claimed before the feature's first commit
- cherry-pick log maps dev hashes to the master hashes they produced —
  they differ, and that mapping is what makes a feature traceable or
  revertible as a unit after dev moves on
- notes the db2-keys seam: written pre-convention on
  porch-store-middleware, replayed onto dev, replay verified identical
- work before 2026-08-29 landed by merge; git log --merges covers it

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 41923eb1f9510ab53804ca8dc6fe30a9a7eac849)
2026-08-30 20:44:14 +02:00
aee78c2296 feat(site): tutorial chapter for durable and resident storage modes
- new chapter 7, "Storage modes: durable and resident", covering what
  master gains with the databasev2 cherry-pick: durable: false for a
  RAM-only table, resident: keys for a table that outgrows RAM
- states the parts a reader would otherwise hit as surprises: a
  keys-resident table is REFUSED at startup without WO_DATA, an update
  appends a delta rather than rewriting the row, and the chain is
  bounded at 16 links so a hot row does not degrade reads or replay
- quotes the measured 2.55x smaller resident set, not an estimate
- actors/deps/serving shift to ord 8/9/10; seeding is ord-driven so an
  existing WO_DATA keeps its rows and only a fresh boot reseeds
- home card says a table can be RAM-only or outgrow RAM
- two gate legs pin the new chapter; site-accept 23 checks, 0 failures

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 3b503c0db50aa737dd06ef6d17151c654a42c59b)
2026-08-30 20:38:03 +02:00
710325b94a docs(db2-chain): close out iteration 11 on the board
- status: done in the story frontmatter (was the non-conventional
  "complete"; the board's axis uses done/in-progress/pending/hold)
- board row 11: what landed, the WO_WAL_UPDATE correction, the ceiling
  removed as unreachable, and the one criterion still weaker than
  written (expected value, not a resident: all oracle)

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit de39a88e81e97bf6f8b75e9f15331aae20f7ab29)
2026-08-30 20:38:03 +02:00
68dd3d88b8 test(db2-chain): cover flattening, and drop a ceiling no input could reach
- flattened row image is WO_WAL_UPDATE, not WO_WAL_INSERT: the row's
  original INSERT is already in a live log, so a second one for the same
  id is a duplicate replay refuses as corruption. INSERT is right only
  for compaction, which builds a fresh log
- remove WO_CKPT_MAX_GARBAGE: with the absolute term at 64 MiB, garbage
  large enough to reach a 256 MiB ceiling has already tripped it, so the
  branch was unreachable. Postgres needs both constants because it
  thresholds on tuples with its pair at opposite ends; this thresholds
  on bytes, where one constant does both jobs
- test_delta_chain_flattens_at_k: chain depth stays <= WO_DELTA_MAX_HOPS
  across 2K+2 updates, and a reset is observed
- test_delta_chain_flatten_replays: a flattened chain replays correctly
- test_keys_resident_indexed_across_flatten: a delta on an indexed
  column composes with flattening, checked at every step across the
  bound and after restart. Found no product defect
- test_should_compact_absolute_and_ceiling: pins the absolute term, the
  boundary just under it, and the small-log case the ratio still governs
- test_wal 5700 pass / 0 fail; wovm-test and woc-test green

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit f93b5d9db753305c297e868d977670e6d703684c)
2026-08-30 20:38:03 +02:00
2cad84b7c6 feat(db2-chains): bound a keys-resident row's delta chain
TESTS DELIBERATELY HELD at the developer's instruction — logic only.
The existing suite passes (36 suites, 0 fail) but exercises NEITHER new
behaviour: nothing builds a 16-deep chain, and no checkpoint test uses a
log near 64 MiB. Green here means "did not break what existed".

- tier 1: wo_wal_fold_row_at gains hops_out. The walk already visits
  every hop, so the depth is free — this is the design's pd_prune_xid,
  a cheap "is work worth doing" hint taken from work already happening
- the update path branches on it: past WO_DELTA_MAX_HOPS (16) it writes
  a full-row image instead of a delta, terminating the chain. `r`
  already holds the complete post-update row because index maintenance
  required folding it, so flattening costs bytes, not an extra read
- wo_wal_append_row_image encodes from a caller-held row, as
  WO_WAL_INSERT: a chain's base must replay into a database where
  nothing precedes it, so replay/compaction/fold need no change
- tier 2: should_compact gains a TRIGGERING absolute term and a ceiling.
  Our `floor` SUPPRESSES on a small log — the opposite of postgres's
  vac_base_thresh, which triggers on a small absolute problem the
  proportion hides. We had the proportion and the suppressor and
  neither real guard
- verified by construction, not test: both update entry points converge
  on row_apply_field_keys; db.c captures next_offset BEFORE calling in,
  so the re-point is transparent to which record type was written

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 1b808abd5942de81c3a6416714d1302384103040)
2026-08-30 20:38:03 +02:00
841f6c8f3f feat(db2-keys): gate the residency measurement, close out task 7
- new `residency` leg in db-bench.py driving docs/examples/residency-bench:
  two tables identical except the annotation, control cap + binding cap
- ITS OWN PROGRAM, not a db-bench mode: declaring a resident: keys table
  is a WHOLE-PROGRAM constraint, so the no-WO_DATA refusal fires for
  every mode in the module. Putting those classes in db-bench's shared
  types made growth/ceiling/randread — which run without WO_DATA —
  refuse to start. Caught by running the leg, not by reading it
- gates the RATIOS, waives the absolutes: ops/sec under a cap is swap
  and disk I/O and belongs to the box. Same split randread makes
- rss_ratio 2.55 floor 2.0 tol 10% (structural, like bytes_per_row);
  overcap_vs_swap_x 1.53 floor 1.0; in_ram_cost_x 4.23 ceiling 8.0;
  all_collapse_x 105.4 floor 2.0
- all_collapse_x exists because the leg's FIRST run silently measured
  nothing: at QUICK's 40k rows a 48 MiB cap binds neither mode, so the
  "over-cap" half was not over cap. The cap now scales with N and the
  leg asserts it binds
- verified the gate bites: rss_ratio 1.4, overcap_vs_swap_x 0.6 and
  in_ram_cost_x 12.0 are all rejected
- task 7 closed: both criteria moved to Met with how each was verified

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit a310496664982c372f51b43113465eb8ad9e9fb5)
2026-08-30 20:38:03 +02:00
6fc5b4b7d4 feat(db2-keys): GB-scale bench modes, unmeasured
- hreadall/hreadkeys: the same resident A/B as wread_*, but ~2 KB per
  row so a GB of data is reachable in a few hundred thousand inserts
- the insert path is fsync-bound at roughly 2 000 rows/s, so row COUNT
  is the expensive axis and row SIZE is nearly free — 20k rows already
  produce 38 MB
- NOT RUN: the GB-scale measurement was called off. These modes are
  committed working and typechecking so the leg can be run later
  without rebuilding it, not because a result exists

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit abc276ac39dd45a1052b6ae24d25aedb9eea3e1e)
2026-08-30 20:38:03 +02:00
882c1f7d24 feat(db2-keys): task 7 — measure resident: keys against swapping
- two tables identical except the annotation, 200k rows, 40k reads in
  one key order, WAL on ext4 (not /tmp, which is tmpfs here and would
  have put the log in RAM), rootless cgroup v2 cap
- WIDE shape, 2.55x smaller resident set: 34.4 MB vs 87.5 MB. That is
  the real win and the thing the mode was built for
- under a 48 MB cap (between the two resident sets): keys 19635 ops/s
  vs all 12854 — only 1.53x faster than letting the kernel swap
- degradation is far gentler though: all collapses 105x from its own
  uncapped throughput, keys 16x
- costs 4.2x read throughput when memory is not tight, and writes are
  markedly slower — the keys fill did not finish in 2 min where the
  resident fill plus 40k reads did. No design doc had costed writes
- THE UNANTICIPATED FINDING: cgroup limits charge the PAGE CACHE, so
  moving rows to a file does not escape a container memory limit. WAL
  37 MB + RSS 34 MB cannot both live under a 48 MB cap, so every pread
  reaches disk. The premise "the page cache will hold the hot rows"
  fails in exactly the deployment this targets
- first attempt used Int-only rows and showed parity; recorded, because
  drop_payload frees a field's VALUE and an Int's value is its inline
  slot word, so that shape cannot benefit and would have condemned the
  feature for the wrong reason
- verdict: keep it, to fit ~2.5x more data in given RAM — not to make
  an over-capacity table fast

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 7cba9b1174b0bf581314b3147e25cc49e6f49464)
2026-08-30 20:38:03 +02:00
cfd660a5e6 docs(db2-chains): spec + story for bounding a row's delta chain
- fixes a limitation iteration 2 shipped: compaction was supposed to
  bound chain length, but wo_wal_should_compact triggers on a whole-log
  byte ratio and cannot see one hot row's chain
- tier 1, flatten on update: the update path ALREADY folds the row for
  index maintenance and the fold already walks hop by hop, so it reports
  depth for free. Past a fixed K it writes a full row instead of a
  delta. Read <= K+1 reads, replay O(K^2) per row. No format change, no
  per-row RAM, no new trigger
- tier 2: our compaction policy has a proportional term and a
  SUPPRESSOR misleadingly called a floor; postgres's floor TRIGGERS on
  small absolute garbage. Add that term and a ceiling
- design read from .dev/reference/postgresql, not recalled:
  heap_page_prune_opt gates on an O(1) on-page hint then page fullness
  against Max(fillfactor, BLCKSZ/10); autovacuum uses base + scale *
  reltuples clamped by a max (50, 0.2, 1e8). Neither thresholds on
  new-bytes-versus-old-bytes
- K deliberately does NOT scale with table size: postgres scales a
  table-level aggregate with proportional harm, ours is per-row with
  additive cost, so scaling up would make big databases boot worst
- the story says plainly it should NOT be next: task 7 has still never
  measured whether resident: keys beats the kernel's own paging

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit f667cad2cfbe187b5973440ab1af015b2df288f8)
2026-08-30 20:38:03 +02:00
b058feb517 docs(db2-delta): guide to log-structured rows for a new reader
- explains replay, the row chain, how a checkpoint flattens it, and why
  replay of a long chain is quadratic
- worked SKU example with the actual record layout and back-pointers,
  and a trace of the fold showing first-seen-wins
- states plainly why the checkpoint does not bound the hot-row case:
  both triggers are ratios over the whole log and nothing counts
  per-row chain length
- records the bounded-memory vs linear-time conflict behind the O(N^2)
  replay rather than presenting it as an oversight
- closes with the reviewing lesson, since this shape survived several
  rounds: complexity bugs hide in the caller's loop, not in the linear
  helper being read

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit e6434403d566b5d72a24e9c0dcad1f25a2c16320)
2026-08-30 20:38:03 +02:00
64035bf177 docs(db2-delta): resident:keys has storage; move done criteria to Met
- "no storage behind it" / "nothing yet stores a table that way" was
  false — CRUD, checkpoint survival and updates all landed; replaced
  with an accurate summary naming task 6/7 as what remains
- the three checked delete/delete-replay/update criteria sat in
  Outstanding despite being done; moved to Met, leaving Outstanding
  holding only genuine task 6/7 work

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit b575678ee95fa3125fa4e8145320a9cdca10ba38)
2026-08-30 20:38:03 +02:00
061942c9a6 fix(db2-delta): pend_repoint failure fatal; delta fold no longer trusts a live WAL
- wo_wal_pend_repoint's failure was silently discarded (db.c); its
  own doc claimed replay reconciles a stale map — false, a second
  same-drain update chains past the lost one, permanently. Now
  fatal, like wo_wal_stage_fatal; comment corrected
- apply_delta dereferenced db->rt->wal unguarded — NULL rt + any
  DELTA record was a crash. Now refuses cleanly (-1)
- wo_wal_replay_ex lent its throwaway view only when rt->wal was
  unset, so a live wal's non-empty staging buffer could be folded
  against during replay. Now installs unconditionally whenever rt
  exists, saving/restoring whatever was there

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit fed9fe8b5fe022f0b22a4170c7fd68008700939f)
2026-08-30 20:38:03 +02:00
e37a10b70d fix(db2-delta): borrow the pending re-point, not the stale durable offset
- wo_row_borrow's keys arm folded at hget()'s DURABLE offset even
  when an earlier update in the same drain had only a PENDING
  re-point
- idx_remove_row then hashed the pre-first-update value, found no
  matching bucket entry (already moved by the earlier update), and
  idx_add_row added a second one — N same-drain updates leaked N-1
  entries, unbounded, nothing reclaims them but a restart
- now prefers wo_wal_repoint_offset1() over the durable offset, same
  as back_off already does, closing it for every borrow
- new test: 5 updates to one row in one drain, assert exactly one
  index entry — fails (5) before the fix, passes (1) after

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit d4b12d1908e574419c7af2411e52d02623f7e5b7)
2026-08-30 20:38:03 +02:00
49a0a9d047 fix(db2-delta): refuse resident:keys with no WO_DATA at runtime
- loader stopped refusing durable:true+resident:keys once UPDATE
  landed; nothing replaced it at runtime
- rows for such a table live only in the WAL, so every read failed
  with a misleading "no such row" instead of naming the problem
- main.c now refuses at startup, names the class, exit(2)
- residency-accept.sh gains a leg: refuses without WO_DATA, still
  runs with it — verified failing before the fix, passing after

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 3ea6d6452f260d45f92045c0f300fa49faa1d810)
2026-08-30 20:38:03 +02:00
e08c26309a feat(db2-delta): lift the resident:keys refusal, prove it end to end
- loader.c: delete the INCOMPLETE-update BAIL; durable:false +
  resident:keys stays refused (nowhere to read from)
- table.c: root-cause fix for the Text-index gap — a keys-resident
  borrow now holds ENGINE values, matching wo_row_ptr's contract
  (table.h's "no VM pointer" doctrine), not a VM-decoded row. Fixes
  idx_hash/idx_cols_equal/wo_idx_probe AND db.c's GET_FIELD/PROBE
  arms with one change; reproduced pre-fix as an ASan
  heap-buffer-overflow
- docs/examples/residency: Product is genuinely resident:keys;
  residency-accept.sh's refusal leg replaced by proving the program
  runs and stock survives a restart (11/0)
- test_wal.c: oracle test drives resident:all and resident:keys
  through the same update sequence and asserts identical rows;
  Text-indexed-update test catches the representation bug; five
  pre-existing tests corrected to the fixed contract (4746/0)
- story, README, status board, CODE-LOGIC.md updated; three known
  limitations documented: mid-drain stale reads, O(N^2) replay in
  chain length, compaction blind to per-row chain length

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit b87c68f950f01aa5e572fbb86a0f374adc83d813)
2026-08-30 20:37:49 +02:00
f138ac0abe feat(db2-delta): replay and compaction fold delta chains
- apply_delta: DELTA replay arm — fold pre-delta state via back_off,
  overlay the field, remove-then-recreate so indexes stay correct
- apply_record/replay loop: dispatch DELTA to apply_delta, drop its
  payload back to the log same as INSERT/UPDATE
- stage_flattened_row: compaction's delta-chain path — fold + re-encode
  as one fresh INSERT instead of copying the chain
- wo_wal_compact: peek the row's current record kind, flatten deltas,
  keep the byte-for-byte copy for chains already at length zero
- test_wal: three new tests — chain-of-three replay incl. secondary
  index, compaction flattens to chain length zero (asserts the record
  is a full row, not a delta), and the commit-before-repoint crash
  window replays the update without ever re-pointing the map

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 7e4ae70d7beb2a2e396a002184bc06f41253decb)
2026-08-30 20:37:27 +02:00
1f402ae4bb fix(db2-delta): close the unique-shadow-check's same-drain blind spot
- table.c: unique shadow-check's candidate lookup now checks
  wo_wal_repoint_offset1 before the durable wo_row_offset1, same as
  back_off — a candidate updated earlier in the SAME uncommitted drain
  was folded from its stale pre-update offset, letting a real @unique
  clash through and committing a duplicate
- the offset-only substitution alone was NOT enough (verified): the
  candidate must be FOLDED to compare values, and folding a pending
  offset via pread saw "no record" (bytes still only in the staging
  buffer), so the clash was still missed, just for a different reason
- wal.c: wo_wal_fold_row_at now reads a hop inside the currently-staged
  region from `w->buf` (new scan_record_staged, scan_record's framing
  over memory) instead of pread; every durable hop, and every existing
  caller, is unchanged
- test_wal.c: two updates in one drain where the second collides with
  the first's new unique value; must be refused. Verified failing
  against the prior commit, and still failing with only the offset
  substitution, before the fold fix; passing with both in place

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit c049ab92570cfba4d12a018884a20b25a8916727)
2026-08-30 20:37:27 +02:00
3525435eb5 feat(db2-delta): wire the request path, defer re-point to the barrier
- db.c: guard both WO_B_DB_UPDATE_FIELD arms on keys-resident tables —
  wo_wal_append_update read a NULL wo_row_ptr there; a live crash, fixed
- ruling override on Task 3: row_apply_field_keys no longer commits or
  moves the id map — stages the delta, does the index swap (RAM apply,
  unconditional past the shadow-check; a stage failure past that point
  is now fatal, like insert). Commit/re-point move to the caller,
  mirroring insert. table.c's WAL commit removal is this ruling, not a
  regression
- offset passed back via caller-side wo_wal_next_offset(), insert's
  koff pattern
- inline arm commits then re-points; request arm records
  wo_wal_pend_repoint (own list/name — a drop and a re-point differ),
  flushed by wo_db_flush_drops after the barrier
- back_off checks the pending re-point before the durable offset, else
  a second update in one drain skips the first delta; verified failing
  this way, passing after
- wal.c: fixed a stale comment — keys-resident updates CAN reach
  wo_wal_append_update's caller now, they just never call it
- test_wal.c: 2 tests updated for the new contract; new test drives 2
  same-row updates via wo_row_update_field_slot in one uncommitted
  "drain", checks the value and delta 2's on-disk back-pointer

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 4d13bcebfe51936ba8c608dd9e791c784e5b8983)
2026-08-30 20:37:27 +02:00
d492d1fefb fix(db2-delta): unique shadow-check gets its own buffer, not r's
- row_apply_field_keys's shadow-check borrowed candidates via
  wo_row_borrow, which shares ONE per-table scratch with the row already
  borrowed for the update — every candidate borrow returned NULL, clash
  was always false, `@unique` silently accepted duplicates on update
- idx_add_row's own internal check has the identical defect at the same
  call site; discarding its result is now actually safe, since the fixed
  shadow-check clears uniqueness before it ever runs
- fix: extracted keys_fold_into (fold+decode) out of wo_row_borrow so it
  can target a throwaway per-call buffer instead of t->scratch; the
  shadow-check probes candidates into that buffer — r is never
  released-and-reborrowed (r IS t->scratch; that would overwrite it)
- wo_row_borrow itself is behavior-preserving: same checks, same order,
  same messages, just factored
- test_wal.c: new test — genuine @unique index, update collides with an
  existing row, asserts refusal (DB_ERR_UNIQUE) and both rows untouched;
  verified failing (update wrongly succeeded) pre-fix, passing after

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 409186da51fec0042d8d1e3dcf9f69f704937823)
2026-08-30 20:37:27 +02:00
7cb4bcf0c3 feat(db2-delta): keys-resident updates append, indexes follow
- table.c: wo_row_update_field/_slot no longer refuse `resident: keys`,
  both converge on one new static row_apply_field_keys
- borrows (folds), shadow-checks uniqueness, appends the delta with the
  row's current offset as back-pointer, commits, THEN idx_remove_row +
  idx_add_row + wo_row_set_offset — failure through commit leaves the
  row's offset and index untouched
- nv decoded to a VM value before touching the materialised copy, since
  wo_row_release drops every slot through the runtime, not db_val_free
- borrow released on every exit, including every failure arm
- resident: all path (row_apply_field_slot) byte-for-byte unchanged;
  wal.c untouched — Tasks 1/2 already expose everything needed
- test_wal.c: plain field update read back, and an indexed scalar
  column updated then found via wo_idx_probe by its new value, gone
  from its old — both verified failing pre-implementation, passing after
- concern: idx_hash/idx_cols_equal/wo_idx_probe cast Text slots to
  db_text* unconditionally; a keys-resident borrow decodes Text to a VM
  wo_str* (different layout) — pre-existing, left untouched; tests use
  a scalar index to sidestep it

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 89c56a13ed9f4abd082bfcabb46f46bb53d39faa)
2026-08-30 20:37:27 +02:00
b758f2978d fix(db2-delta): fold's cycle guard checks direction, not step count
- wal.c: wo_wal_fold_row_at now refuses any delta back-pointer that
  does not point strictly earlier than the record naming it
  (back_off >= cur), instead of capping total hops at off/13+1
- this is the real invariant, not a proxy for it: a step-count bound
  lets a forward-pointing back-pointer through in one hop whenever it
  happens to land on a genuine record, returning a plausible-but-wrong
  row instead of refusing it
- removes the 13-byte-record magic number entirely; no arithmetic
  tied to record framing remains in the guard
- wal.h: docblock updated to describe the direction invariant
- test_wal.c: two new tests — self-pointing back-pointer (boundary
  case, back_off == cur) and forward-pointing back-pointer to a real
  future record for the same row (the actual gap: verified failing
  against the old step-count guard, passing after the fix)

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 173dbf28a42d45a8c7f9fe430355f61f70c81935)
2026-08-30 20:37:27 +02:00
4f3f71e003 feat(db2-delta): fold a delta chain, route reads through it
- wal.h/wal.c: wo_wal_fold_row_at — THE fold. Walks BACKWARD from an
  offset through WO_WAL_DELTA records, remembering the first value
  seen per field index (newest wins, since newest is seen first),
  stops at the first INSERT/UPDATE, decodes it, overlays resolved
  fields. Returns ENGINE-owned values so reads, replay, and
  compaction (Tasks 3/5) can all build on the same output.
- Cycle guard: caps the walk at what the log up to the starting
  offset could possibly hold (13 = scan_record's own record-size
  floor), so a corrupt or malicious back-pointer fails loudly
  instead of spinning.
- table.c: wo_row_borrow's keys arm now calls the fold instead of
  wo_wal_read_row_at directly, then VM-decodes the result — same
  two-stage pattern wo_wal_read_row_at used internally. Per-table
  scratch, scratch_busy nested-borrow refusal, and the cid/id
  identity check all preserved unchanged.
- resident: all path (wo_row_ptr) untouched.
- test_wal.c: two new tests — deltas on two different fields (changed
  fields take the new value, the untouched field keeps its original)
  and two deltas on the SAME field (the newer wins, pinning direction
  — a reversed fold would pass with the older value instead).
  Verified failing pre-implementation (wo_row_borrow returned NULL
  since a delta record isn't INSERT/UPDATE) and passing after.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit a60231cde1d49d74743cedbd134d2da11158b70b)
2026-08-30 20:37:27 +02:00
b860823dad fix(db2-delta): make delta test detect a field_idx/back_off transposition
- review finding: field_idx=0 and back_off=0 (fresh WAL, offset 0) meant
  a u32/u64 swap of these two values wrote identical zero bytes either
  way — undetectable by the prior assertions
- test_delta_record: new dedicated 3-scalar-field class (not shared
  KEYS_CLASSES) so field_idx can be a nonzero, fixed-8-byte value without
  a Text field's variable-length encoding complicating the fixed body
  size assertion
- stage+commit a filler row first so the target row's insert record (the
  delta's back-pointer) lands at a nonzero offset, not the WAL's initial 0
- delta now targets field_idx=2 with back_off=base_off, both nonzero and
  distinct from each other and from class_id=0
- class_id stays 0: this fixture registers exactly one class, so there is
  no other value to give it without an unused second class purely to
  shift an index
- verified live: temporarily swapped the field_idx/back_off wput calls in
  wal.c, confirmed test_wal now fails (fidx==49 want 2, back==2 want 49),
  then reverted — wal.c diff is a no-op, only the test changed

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 20ba0965e15e200641b8b63893a2f238a0279fba)
2026-08-30 20:37:27 +02:00
f1cf2d2f85 feat(db2-delta): WAL delta record kind and encoder
- enum: add WO_WAL_DELTA = 4, existing 1/2/3 untouched (on-disk logs)
- wal.h: document kind 4's payload shape in the format docblock
- wal.h: declare wo_wal_append_delta(w, db, class_id, id, field_idx,
  back_off, value) — back-pointer taken as a parameter, not looked up,
  keeping the encoder ignorant of table/map state
- wal.c: implement it, modeled on wo_wal_append_insert's shape —
  wput_u8/u32/u64 the header fields, enc_val the one field, stage()
- test_wal.c: new test_delta_record — stages a delta after an insert,
  commits, then preads the raw record and asserts kind/class/id/
  field_idx/back-pointer/value all round-trip; registered in main()
- nothing reads deltas back yet — decode/apply is a later task

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 9c6f832c0534a59e644c53b7cd2850581da12159)
2026-08-30 20:37:27 +02:00
048633bf27 docs(db2-delta): correct a line citation before execution
- the plan placed the fold near wo_wal_read_row_at at "line ~600";
  it is at line 794
- every other citation verified: wal.h:46, table.c:452/487,
  db.c:88/289, wal.c:738, wal.c:861

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit c6cd48679e21e510696391b340c735aa0ad098f9)
2026-08-30 20:37:27 +02:00
3f88b07abb docs(db2-delta): implementation plan for keys-resident delta updates
- 6 tasks: the record kind, the fold, updates + indexes, the request
  path and group commit, replay + compaction, then lifting the loader
  refusal and proving it end to end
- the fold is written ONCE and called from three places; the tests are
  arranged to prove each caller separately, and the plan says that
  wanting a second fold "just for this caller" means the design failed
- Task 2 includes a same-field ordering test specifically, because a
  fold walking the chain backwards the wrong way returns plausible data
  and is otherwise invisible
- Task 6 step 1 audits the db.c request arms BEFORE lifting anything —
  they were never audited for keys-residency the way the inline path
  was, and the last audit of that kind found delete corrupting memory
- self-review found the spec's crash criterion had no task: added a step
  that commits a delta, skips the re-point, and replays, which is the
  state a crash between barrier and flush leaves behind
- every symbol the plan names verified to exist in database/src
- code-free per house convention; the writing-plans skill wants code
  blocks and the project rule overrides it

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit abb8fc9454bdca9d8d703c8cfeb224f89a93d14d)
2026-08-30 20:37:27 +02:00
04017aea26 docs(db2-keys): spec — delta records for keys-resident updates
- updates append a DELTA (class, id, field, value, back-pointer), not a
  full row. The workload decides it: a product catalogue changes one
  narrow field of a wide row on every order, so a full-row append would
  rewrite every field to move one integer on a shop's hottest path
- the back-pointer keeps the id map at one slot per row, which is the
  mode's whole premise; a map growing per update would defeat it
- ONE fold function, three callers (read, replay, compaction). Three
  implementations of one rule is how they drift, and a fold that differs
  between reading and replaying is a database that changes its mind at
  boot. Named as the design's principal risk
- indexed columns MAY change: price is exactly what a catalogue indexes,
  so forbidding it would be a restriction users meet immediately
- no chain cap, deliberately. Compaction already rewrites live rows, so
  every checkpoint resets every chain, and deltas grow the log which
  pulls the next checkpoint forward — the workload that lengthens chains
  triggers the fold that shortens them
- the risk that accepts: one hot SKU under an otherwise quiet write
  rate. Task 7's benchmark must include it
- supersedes the 2026-08-26 spec's one-line full-row Update sketch,
  marked in place rather than left as a second design in the tree

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit c9a88b05c4c62a5df13253686c990aaccc3f9cbb)
2026-08-30 20:37:27 +02:00
0b0d54121f docs(db2-keys): the residency example becomes a product catalogue
- the motivating workload was an audit log, which is append-only and so
  argues for nothing. A catalogue is the real case: stable ids, and
  stock moving on every order while name/price/sku sit still
- Product (durable, resident: all) and Cart (durable: false), with
  place_order decrementing stock through a write-through field assign
- run `order` twice and stock goes 10 -> 7 -> 4: a level below the
  seeded 10 can only mean an earlier order's UPDATE replayed. That is
  the stronger claim — not just that inserts survive, but that a field
  change does
- caught by running it three times: my first assertion required
  before == 10, which only holds on a fresh seed and failed on the
  third run even though the data was correct
- gate gains a leg for the update-replay claim; residency 12/0
- the commented resident: keys block now argues the DESIGN too: only
  stock changes per sale, so appending the whole row would rewrite
  every field to move one integer on a shop's hottest write path

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit d4104dcc5e3a460459dbf2d24043ce25b113bcdf)
2026-08-30 20:37:27 +02:00
7b39da7eb6 fix(db2-keys): a logged delete must replay on a keys-resident table
- wo_row_remove's keys arm borrows the row from the log to find its
  index entries, and a borrow reads through db->rt->wal. At boot that
  pointer is not wired yet: main.c replays first (main.c:226) and
  assigns rt.wal afterwards (main.c:268)
- so the borrow found no log, the remove failed, and replay reported a
  valid tombstone as CORRUPTION. An UPDATE record would have failed the
  same way, since replay applies it as remove-then-recreate
- replay now lends the runtime a read-only view over the fd it already
  has open, for the replay's duration only, and restores what was there
- broken by the delete fix in 76b8fd9 — deletes worked in-process but
  their tombstones broke the next boot. Unreachable in production only
  because the loader still refuses the annotation
- pinned by test_keys_resident_delete_then_replay, verified failing
  against the unfixed code (2 failures) and clean with it
- found by asking whether the read-modify-append plan was ready, not by
  a gate

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit dc25462461b9f79d70c803f7174adc90fa16c90e)
2026-08-30 20:37:27 +02:00
516bd8362d docs(db2-keys): a runnable example for per-table storage
- docs/examples/residency: one program, two tables filled by the same
  loop, differing only in the annotation. Run twice against one WO_DATA
  and orders replay while sessions do not
- the example checks its own claim (exits 1 if a durable:false table
  survives, or a durable:true one fails to replay) rather than narrating
  it in a print
- resident: keys is written out as a commented block with the loader's
  exact refusal, so the frontier is visible in the example rather than
  only in a story. It documents WHERE the refusal happens: woc compiles
  it and emits a .wob; wovm exits 2, because the annotation is a
  load-time property
- residency-accept gains two legs: the example runs and its restart
  claim holds, and the refusal message the README quotes is checked so
  doc and code cannot drift apart
- the gate writes the example's output to /tmp/residency.log,
  banner-separated, for tail -F
- README commands verified verbatim; they needed mkdir -p because wovm
  will not create WO_DATA

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit c9c7e03e62c3918cb65ef7994d1e33a0c5337b71)
2026-08-30 20:37:27 +02:00
7ad52937b2 fix(db2-keys): delete on a keys-resident table was memory corruption
- wo_row_remove read the id map's value as a slot, but on a keys table
  that value is a LOG OFFSET (hput(t, id, wal_off + 1)). slot_row does
  no bounds check, so a delete indexed t->slabs[] with a byte offset and
  then called db_val_free on whatever it landed on — arbitrary frees,
  not a wrong answer
- keys tables now take their own arm: no slab slot, no bitmap bit, no
  free-list entry to return. The index hook needs the row's values, so
  the row is borrowed from the log for exactly that long
- wo_row_ptr carried the same trap and is public. It cannot refuse keys
  tables outright (insert legitimately calls it while the map still
  holds a slot), so it now detects the offset case — index past the
  slabs, or bitmap bit clear — and returns NULL. Callers all handle NULL
- test_keys_resident_delete pins it; it SEGVs against the old code,
  verified by reverting the fix rather than assumed
- found while auditing every hget() reader before narrowing the loader
  refusal to allow benchmarking. The refusal was justified in the docs
  by "updates are unimplemented" while actually standing in front of
  this too: a guard whose stated reason is narrower than its real one
  gets removed by someone who believes the stated reason

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 76b8fd944af9ed062467bdf9ab93c2e96dd198cf)
2026-08-30 20:37:27 +02:00
97c7c40fd8 docs(db2-chain-review): review the databasev2 chain and dependency graph
- chain is a cross-track field (1-6); only databasev2 3 and 4 carry it,
  and iteration 2 — critical path, in-progress — carries none, so the
  board's chain query cannot see it
- 00-story.md's ASCII graph draws 3 before 4; the chain field and the
  history both say 4 first (4 part A 08-28, 3 08-29). Graph is wrong
- graph also contradicts its own prose on edge direction, and still
  draws the 2-5-6 path the 2026-08-27 amendment retired
- iteration 3's hazard section is stale: it says nothing fails "because
  iteration 2's storage half is unimplemented", which 5c/5d ended
- and it was incomplete: it named offsets going stale, but compaction
  walked the bitmap, which a keys row has no bit in, so those rows
  would have been dropped from the new log outright — data loss, not a
  bad pointer, and offset-rebuilding would not have caught it
- coupling is now bidirectional: wal.c compaction calls iteration 2's
  wo_row_next_id / wo_row_offset1 / wo_row_set_offset
- nothing in the track is blocked on anything else in the track

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 2ecaf0c95f40c6d6c8cc2fde687c82d63cda1f7e)
2026-08-30 20:37:21 +02:00
8311330531 docs(db2-keys): reconcile databasev2 and porch markdown with the code
- loader's resident:keys refusal said "rows are still fully resident"
  and "until tasks 5c/5d land". Both false since f606fc9. Corrected to
  name the real blocker: UPDATE needs read-modify-append
- databasev2 00-story: the sequence graph drew 2->3->4, which reads as
  3 needing 2 and 4 needing 3. Both backwards, and it still drew the
  2->5->6 path the 2026-08-27 amendment retired. Redrawn stating only
  real dependencies, with 4 and 3 shown as composing rather than
  ordered, and the execution order that actually happened
- databasev2 03: the hazard and its Outstanding entry both claimed
  nothing fails "because iteration 2's storage half is unimplemented".
  Marked discharged, and recorded that the hazard named only half the
  danger — the bitmap walk would have dropped keys rows outright
- databasev2 06: pending -> hold (largely superseded, revisit only on
  a measurement); dated its 5c/5d references
- porch 01: rewritten to the settled shape. readiness ready, status
  in-progress, phases B and C marked superseded with why
- porch 01 claimed time.after "is still a reserved builtin id". False —
  builtin 90, implemented. That claim is what made the iteration look
  cheaper than it is
- porch README gains honest ledger rows for both features (partial,
  being rebuilt), not shipped
- skill-catalog README pointed at a story path that moved tracks;
  linkcheck now 0 broken

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit b3d8c403e1d19ac27ec966de85cb293e0765795c)
2026-08-30 20:36:55 +02:00
533fc5294f feat(db2-keys): rewire remaining readers, survive compaction
- wo_row_read and the @unique shadow probe go through borrow/release;
  release runs before every exit, including wo_row_read's early return
- updates on a keys table refused explicitly in wo_row_update_field and
  the slot variant: no slab slot to mutate, and writing the borrow's
  scratch would discard the write silently. Needs read-modify-append
- compaction walked the bitmap, which a keys row has no bit in — every
  such row would have been dropped from the new log. Now walks
  wo_row_next_id and re-points each row to where it lands
- moves records byte-for-byte (copy_record) rather than decoding: a
  borrowed row holds VM values, enc_val expects engine values, and ASan
  caught that mismatch as a 4294967292-byte memcpy
- wo_row_set_offset updates a value in place and never rehashes, so a
  wo_row_next_id cursor stays valid while compaction re-points
- a compaction that fails after moving rows is fatal: the map would name
  an unlinked temp file, and the intact log replays correctly
- test_keys_resident_survives_compaction pins both failure modes; rows
  rewrite in hash order so offsets really move
- loader still refuses resident: keys — updates are not implemented

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit f606fc9b76d983cac2b348f03f7d4f01433cd905)
2026-08-30 20:36:31 +02:00
636f36b0f6 feat(db2-keys): the query paths read through the iterator and borrow
databasev2 2, task 5d. Every reader in db.c now works for both backings.

The measured problem: a keys-resident table's bitmap is EMPTY by construction
(its payloads live in the log), so all four bitmap walks would have silently
returned no rows — a query over such a table would find nothing, with no error.

- wo_row_next_id: one iterator, two backings. Keys tables walk the id map;
  resident tables keep walking the BITMAP deliberately, because the id map
  holds the same set in hash order and switching would reorder the results of
  every unordered query in the repo. No behaviour change where none was needed
- the three id-collecting scans move onto it. They only ever collected ids
  (the 9b cursor-stability rule materialises the list up front), so they needed
  no row access at all — which is why this was far smaller than the plan feared
- the two filtered scans borrow, compare, and RELEASE BEFORE any exit. The
  scratch is per-table, so a borrow leaked past a `return` or `break` would
  make the next borrow on that table fail as a nested one. That is a real
  hazard, not a hypothetical: the request-path GET_FIELD borrowed and then
  `break`ed without releasing until this commit
- point reads decode or clone BEFORE releasing, because a keys-resident row's
  slots point into the scratch that release frees

Verified: just wovm-test — 36 suites 0 fail.

Still to do in 5d: table.c's unique shadow and its three remaining wo_row_ptr
sites, wal.c's append encode, and compaction's own walk — which is where the
recorded `resident: keys` offset obligation has to be honoured. The loader
refusal stays until all of it lands.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 0c97fa48d3e31ea9eea3287d9c23ed29f0260488)
2026-08-30 20:36:31 +02:00
e16d4896f8 feat(db2-keys): inserts and boot — payload dropped after the barrier
databasev2 2, task 5c. The write and boot halves. Still not exposed: the
loader refuses `resident: keys` until 5d rewires the readers.

GROUP COMMIT FORCED THE DESIGN. A keys-resident payload can only be dropped
once its record is durable, but databasev2 4 deferred the barrier to the drain
— so at append time the bytes are still in the staging buffer and the recorded
offset would pread ZEROS. Dropping at append would have produced rows that
read as garbage, intermittently, only under multi-shard load.

So the drop is recorded, not performed:

- wo_wal gains a pending-drop list, the same shape as the drain's held replies
  and for the same reason
- both write paths take the offset BEFORE the append (wo_wal_next_offset) and
  record it; the inline path flushes right after its own commit, the request
  path's flush runs in the drain immediately after the barrier
- if the process dies before the barrier the list dies with it, which is
  correct: nothing was dropped and nothing was lost
- an out-of-memory pend is ignored on purpose — the row simply stays resident,
  which is safe

Boot: replay now leaves a keys-resident table pointing at the LOG. Each record
is applied normally, so indexes and uniqueness are built exactly as for any
other table, and the payload is then dropped with THAT record's offset. For an
update the later record wins, because each apply overwrites the map in order —
the rule replay already follows.

Tests: the round trip (insert, commit, drop, read back with Text intact) and
now BOOT — a fresh wo_db replays the store and every row materialises from the
log, count intact, nothing in a slab.

Verified: just wovm-test — 36 suites 0 fail, test_wal 4301 pass, cli_smoke OK.

REMAINING (5d), and precise: every reader still goes through wo_row_ptr, which
for a keys table would index a freed slot. The scans in db.c walk the BITMAP,
and a keys table's bitmap is empty by construction — so a query over one would
today return no rows at all. That, FK restrict, and the @unique shadow are 5d,
and the loader refusal stays until they land.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 08abd09bf88918f2582e74713dc7903beb8aaeb8)
2026-08-30 20:36:31 +02:00
7cc80405dd feat(db2-keys): storage — drop the payload, read it back from the log
databasev2 2, task 5c step 2. The storage half the accessor was left waiting
for. Not yet wired into insert (that and 5d remain), and the loader still
refuses `resident: keys`, so nothing is exposed to a program yet.

- wo_db gains an `rt` back-pointer, set in main.c beside VM.rt.db. wo_rt
  already carries `db` and `wal` as opaque handles, so this closes the loop
  and a borrow can reach the log WITHOUT threading a wal pointer through
  eleven call sites — which is the whole reason 5c is one accessor
- wo_row_drop_payload: the operation the plan recorded as MISSING. Frees the
  slot and its engine-owned values, then re-points the id map at the record's
  log offset (off + 1, reusing the same 0-is-empty trick as slot + 1). It
  deliberately does NOT touch the secondary indexes (they store row ids, so
  they stay correct), does NOT decrement count (the row is still live, only
  its backing moved), and does NOT remove the id (that is how it is found)
- wo_row_borrow materialises for a keys table: reads the offset from the id
  map, calls 5b's wo_wal_read_row_at into the per-table scratch, and checks
  the record actually holds the expected class and id — a compaction that
  moved records without rebuilding the map lands exactly there, which is the
  obligation recorded at wo_wal_compact
- fully-resident tables keep today's path and pay one predicate

A REAL BUG, exposed the first time the path was used: wo_row_release freed the
materialised values with the ENGINE's allocator. They are VM values —
wo_wal_read_row_at is the out-gate and always copies — so ASan reported a
bad-free immediately. It now drops them through the runtime. That stub was
written in 5c step 1 for a path that did not exist yet.

Recorded while implementing: wo_wal_next_offset's contract says to trust an
offset "only after the matching commit returns 0". Group commit (databasev2 4)
defers that barrier to the drain, so db.c can no longer check inline — but part
A also made a failed commit FATAL, so no execution can record an offset whose
record never became durable. Same guarantee, different mechanism.

Test: a heap-valued row is inserted, committed, has its payload dropped, and is
read back out of the log with its Text intact; count is unchanged (still live);
and a second borrow succeeds, which fails if release did not clear the scratch.

Verified: just wovm-test — 36 suites 0 fail, test_wal 4273 pass, cli_smoke OK.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 125bd09218d616b2a16b140de770d3f38b45f0ac)
2026-08-30 20:36:31 +02:00
02b4b13a52 Merge master into db-residency-doctrine — and close the two half-exposed features
The branch was 17 ahead / 25 behind with 11 conflicting files, and drifting
further: db.c had been rewritten twice on master since (group commit, then
compaction). Resolved rather than rebased so both histories stay legible.

Conflicts, and how each was settled:

- db.c: BOTH semantics kept. Master's fatal path and compaction check now sit
  behind the branch's `table_is_durable` predicate, in all three inline arms —
  a volatile table reaches neither the barrier nor the compaction check
- db-bench sample: every mode from both sides (growth, growth-verify, randread,
  replayseed, wmix) and ONE `boot` mode, which both sides had added
  independently
- db-bench.py: all six legs kept. Both sides had also grown the same
  WAL-size helper under different names; collapsed into one
- perf-targets: the branch's §5 (RAM ceiling) then master's §6/§7 — master's
  numbering had already assumed a §5 it did not have
- story frontmatter: master's `status` (the landing truth) plus the branch's
  `readiness` axis. 03 would have read `done` + `refine`, which is a
  contradiction — it was brainstormed and landed on master, so `ready`
- board: both standup blocks newest-first; master's chain rows (a superset);
  the branch's databasev2 1-2 rows with master's 3-4. Fixed a stray `|` in
  master's row 3
- baseline: master's, then REGENERATED from a full campaign — 143 metrics,
  132 checks, 0 failures with both sides' legs present

TWO HALF-EXPOSED FEATURES FIXED, because the merge rule is that master gets
no feature that is honoured in name only:

- `resident: keys` PARSED, set a .wob flag, and did nothing: rows stayed fully
  resident. A developer could declare a 120 GB table keys-resident, watch it
  compile, and be OOM-killed. The loader now REFUSES it with a message naming
  what to write instead, until tasks 5c/5d land. The compiler still parses it
  and its AST golden still passes, so the grammar work stays tested
- `durable: false` was honoured ONLY on the inline path. wo_db_exec_req had no
  guard at all, so a volatile table written from an actor on a worker shard
  would still be logged — precisely porch's session-table case, and precisely
  what iteration 2 exists to provide. All three request-path arms now carry the
  same predicate. Found by reading the merged code, not by a test: the obvious
  probe runs main() on the primary and therefore only exercises the inline path

Verified on the merged tree: wovm-test 0, woc-test 0, oop-e2e 122/0,
residency-accept 8/0, db-bench 132/0, linkcheck clean.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-29 10:14:25 +02:00
8b29eb492c docs(db): T6 closeout — checkpoint documented, chain's last link lands
databasev2 3, task 6. Documentation, plus three gate-tolerance
corrections that are justified rather than silent.

- 04-db-binding.md: the NORMATIVE rule — compaction may run only where
  nothing is staged (a correctness requirement, not scheduling), recovery
  is unchanged, and a failed compaction is a missed optimisation rather
  than a durability event
- database/src/CODE-LOGIC.md: why one file and not snapshot-plus-tail
  (Postgres CANNOT compact — page deltas; ours are full row images, so a
  compacted log IS a store), why rename is the whole crash-safety story,
  why the dump flushes but does NOT fsync when it does, why the
  replacement is preallocated, and where the trigger is checked
- README: the checkpoint knobs, the extended walstats line, the boot mode
- story -> status: done, with criteria split met/outstanding
- board: standup entry in the six-question shape, both rows rewritten

THE OBLIGATION IS AT THE COMPACTOR, not only in a spec: compaction moves
every record, so it invalidates every WAL offset iteration 2's
`resident: keys` stores, and the loop that knows each record's new
position must rebuild that map. Nothing fails today because that storage
half is unimplemented — it would fail later, looking like corruption.

Board claim corrected before it shipped: I wrote that the concurrency
chain is "complete". It is not — chain 5 stays in-progress because
databasev2 4's part B was never done and its premise was invalidated by
part A. Every link has landed its PLANNED work; that is a different
statement.

Gate tolerances, each with the measurement that justifies it:

- ckpt.pause_us_max is no longer gated relatively. The raw pause scales
  with the live set and this workload's live set is not fixed (wmix's
  hist_dump inserts a row per latency bucket), so gating it gates the
  box. Added ckpt.pause_us_per_mb — the engine's own rate, gated for
  real, and the metric that would have caught the 8x dump regression —
  with the absolute 50ms budget still guarding the raw pause
- ram.*.msgrate 15% -> 70%. PRE-EXISTING, and measured: 10.7M-17.9M
  msgs/sec across ten full runs, several predating this work — a 1.67x
  spread against a 15% gate
- durable.sN.*.p99us 100% -> 300%, with more evidence than the first
  widening: mixread 1043/2318/4147us, mixwrite 1623/4446us on the same
  build. Floors stay the real guard and are not slack

Battery: wovm-test 36 suites 0 fail, woc-test, oop-e2e 119/0,
db-bench 117 checks 0 failures, linkcheck clean.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-29 06:48:34 +02:00
40d56c4664 perf(wal): checkpoint measured — 2.16x space, 1.78x boot, 2.7ms pause — T5
databasev2 3, task 5.

Full campaign, same workload twice, differing only in whether
checkpointing may fire:

- WAL used 1962358 -> 907094 bytes (2.16x reclaimed)
- boot 114 -> 64 ms (1.78x), median of 3
- stop-the-world pause max 2651us against a STATED 50ms budget

The budget is asserted, not assumed: 50ms is a stall a serving process
can absorb without a client seeing a timeout, and the leg fails if it is
exceeded. The pause is O(live rows) — at ~181 MB/s a 1GB live set implies
~5.5s, which is the number an incremental design must be bought against.
The spec deliberately did not buy it in advance.

FOUND BY MEASURING: the dump was 8x slower than it needed to be. It
flushed through wo_wal_commit, which fdatasyncs, so it paid one barrier
per 256 records. Intermediate durability there is worthless — the temp is
not authoritative until the rename and is fsynced once immediately before
it. With a single final barrier:

- ~107KB live: 23948us -> 2903us
- ~500KB live: 36361us -> 7526us
- ~1.98MB live: 107649us -> 13212us
- marginal ~22 MB/s -> ~181 MB/s, sync-bound to bandwidth-bound

Correctness re-proven after that change: wovm-test 36 suites 0 fail,
test_wal 760 pass including the 40-round kill-during-compaction battery.

Two measurement defects of my own, fixed rather than reported:

- boot measured through the driver's run() helper reported 251ms both
  with and without checkpointing — run() samples RSS on a 250ms poll, so
  every timing floors at the quantum. Measured directly instead, median
  of 3
- ckpt.reclaim_x was recorded as lower-is-better by the default detector,
  which would have PASSED "reclaimed nothing" and FAILED an improvement:
  the feature's central claim, gated backwards. Now higher-is-better,
  gated at 15% while the wall-clock metrics stay wide — waiving them all
  would have left the leg ungated, part A's task 4 mistake

- sample gains a `boot` mode that does nothing, so boot time is boot time
- walstats now reports compactions, pause max/total and compacted bytes
- baseline refreshed from the FULL campaign (N=20000, crash_reps=3), and
  a fresh full run passes 116 checks 0 failures
- gate bites: reclaim_x doctored to 1.0 -> FAIL on exactly that metric

One flake seen and checked, not papered over: durable.sN.query.ops_sec
failed once at 53% below baseline. It is a read-only metric that touches
no WAL code, and a re-run passed 116/0 with the box at load 1.85.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-29 06:20:13 +02:00
d432bc5301 test(wal): kill -9 DURING compaction — 40 rounds, mutation-proven — T4
databasev2 3, task 4. The plan called this the riskiest task because a race
can pass by luck, so it is argued with mutants rather than green runs.

The battery: a forked child inserts, acks, deletes the oldest so HISTORY
grows while the live set stays ~17, and compacts every 24 iterations. The
parent SIGKILLs at varied instants so kills land before, inside and after
rewrites, then replays and checks the ACKED LIVE SET. The existing
battery's "records >= acks" oracle cannot be reused: collapsing history is
exactly what compaction is for.

A REAL DEFECT IN MY FIRST VERSION, found by the failures and fixed in the
TEST, not by weakening it:

- the child acked deletes AFTER committing them, so a kill in between left
  the row legitimately gone on disk while the last ack still said
  "inserted" — the parent then demanded a row the engine was right to
  remove. Symptom was an acked insert missing near the end of the stream,
  ~1 run in 3
- deletes now announce INTENT BEFORE committing, so such a row's fate is
  simply UNKNOWN to the parent, which is the honest thing to assert. Every
  acked insert never marked for deletion must still be present with its
  acked value
- the stale-temp assertion was also wrong: it checked for absence after
  wo_wal_replay, which never opens the WAL. The guarantee is "removed AT
  OPEN", so the test now opens and then asserts. A temp surviving a kill
  is expected debris, not a defect

Proven to have teeth, which matters because assertions were softened:

- against the design's rejected alternative (in-place rewrite instead of
  the atomic rename) it fails EVERY run, reporting log_records=0 — the
  kill landed mid-copy and destroyed the log. That is the corruption
  rename exists to prevent
- on correct code: 10 consecutive runs x 40 rounds clean, plus the suite

Also carried the log's PREALLOCATION to the replacement. The WAL is
preallocated so appends never extend the file, which is what lets
fdatasync alone be the ack barrier; a replacement opened with prealloc 0
silently changes that property and the zero-padded tail the scan relies
on. Stated honestly: this is hygiene making the replacement equivalent to
what open() would have produced — I could NOT prove it was the cause of
the observed loss, and the ack race above explains it.

Verified: just wovm-test — 36 suites 0 fail, test_wal 760 pass, cli_smoke OK.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-29 05:55:58 +02:00
aa89fb6c97 feat(db): the checkpoint trigger, and compaction is wired to BOTH write paths — T3
databasev2 3, task 3.

- wo_wal_should_compact is a PURE decision (used bytes, last compaction's
  measured output, floor, ratio) so it is testable without a store —
  which is the only way a policy like this gets tested at all. Denominator
  is the last compaction's real output, not an estimate of the live set:
  estimating would mean estimating Text
- 8 boundary assertions incl. "exactly 3x is not MORE than 3x" and a zero
  ratio disabling the policy rather than dividing by nothing
- MUTATION-TESTED instead of observing RED: implementation and test were
  written together, so removing the floor check was verified to fail
  exactly the two floor assertions. Equivalent evidence, stated plainly
- WO_CHECKPOINT_BYTES / WO_CHECKPOINT_RATIO at boot beside WO_MAILBOX.
  The knobs are what make the policy testable — a gate sets a tiny floor
  and forces compaction in a few writes instead of megabytes
- NO timer, per the spec: Postgres' CheckPointTimeout bounds loss from
  unflushed buffers; our records are durable at commit and an idle log
  does not grow
- the ordering rule is now asserted, not trusted: a test stages a record,
  requests compaction, and requires REFUSAL with the log untouched and
  the staged record still committable afterwards

FOUND AND FIXED a gap in my own wiring. The plan said to call the check
"after the drain's barrier", and I did — but a statement running ON the
owner shard never enters that drain, so WO_SHARDS=1 never compacted and
its log grew forever: measured 536086 bytes where the multi-shard run
held 446024. Now checked after the inline path's commit too (db.c
maybe_compact), where the buffer is equally empty. WO_SHARDS=1 went
536086 -> 260657 bytes. For a checkpoint this mattered more than part A's
equivalent gap: an unbounded log is an operational failure, not just lost
throughput.

Also corrected a measurement of my own: multi-shard logs looked unbounded
(448KB -> 1013KB -> 1647KB across 8k/24k/48k updates). They are not.
Instrumentation showed compaction ran 25 times with zero failures, each
writing MORE than the last, because the live set genuinely grows — wmix's
hist_dump and done-markers are themselves durable inserts. Final log
1631040 against a last compaction of 866432 is a ratio of 1.88, just under
the 2x threshold: the policy holding exactly.

Replies are released BEFORE compaction runs, deliberately: their records
are already durable, and holding them across a stop-the-world rewrite
would add its full duration to their latency for nothing.

Verified: wovm-test 36 suites 0 fail, test_wal 360 pass; db-bench-quick
crash.s1/crash.sN and both restart legs green, and part A still batches
(sN mean 4.16, peak 30).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-28 18:43:44 +02:00
d7dde018ec feat(wal): a stale compaction temp is removed at open — T2
databasev2 3, task 2.

- wo_wal_open removes `<log>.compact` before reading anything. The only
  way one exists is a crash before the rename, which means its records
  were never authoritative
- deleted rather than ignored, deliberately: a file full of well-formed
  records sitting beside the log is exactly what a future reader mistakes
  for data

Test uses PLAUSIBLE content, not garbage — a byte copy of a real log —
because garbage would be rejected by the CRC anyway and would prove
nothing. It asserts the temp is present before the open, gone after, and
that the live log still replays to exactly what it said.

RED was an assertion failure (`access(tmp, F_OK) != 0` unmet), not a
compile error, so the test was proven to exercise the behaviour before the
behaviour existed.

Verified: just wovm-test — 36 suites 0 fail, test_wal 340 pass, cli_smoke OK.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-28 18:01:52 +02:00
0f652dd93f feat(wal): wo_wal_compact — rewrite the log, swap it in with rename — T1
databasev2 3, task 1.

- walks each class's live rows via the bitmap-over-slabs pattern db.c
  already uses in three places, appending one INSERT per live row through
  the EXISTING append path. No second encoder, no new format, and ids are
  preserved exactly because wo_wal_append_insert takes the id and reads
  the row from the store
- FLUSHES EVERY 256 RECORDS rather than staging the whole store: stage()
  grows the staging buffer by doubling and never shrinks it, so a
  one-buffer dump would hold the entire store in RAM on top of the store
  — the unbounded growth databasev2 1 identified as how this engine dies
- the switch, in order: fsync the temp file, rename over the live path,
  fsync the PARENT DIRECTORY (rename's atomicity is in-kernel; the
  directory entry is not durable until the parent is synced — Postgres
  does the same for the same reason), then reopen the descriptor, because
  the old one refers to an unlinked inode
- REFUSES when anything is staged: those records would land in a file
  about to be replaced. The caller-side guard is task 3; this is the
  backstop
- a failure leaves the ORIGINAL log intact and usable and returns -1. A
  failed checkpoint is a missed optimisation, not a durability event, so
  it deliberately does NOT take databasev2 4's fatal path
- records the bytes written, so task 3's trigger can compare against a
  measured denominator instead of estimating the live set (which would
  mean estimating Text)

Recovery is untouched — the result is an ordinary log in the ordinary
grammar, replayed from byte 0. Crash safety comes from rename, not from
code of ours.

Test asserts BOTH halves, on purpose:

- the log shrinks: 43 records (3 inserts + 40 updates of the SAME row, so
  history grows while the live set does not) -> 3 records, fewer bytes
- AND a fresh replay reproduces the store: every id present, and row 0
  carries the 40th update's value rather than its original. "It got
  shorter" is also true of a truncating bug, so the replay comparison is
  what actually proves it
- and the WAL stays usable after the swap: a further append lands after
  the compacted records, giving 4 on the next check

Verified: just wovm-test — 36 suites 0 fail, test_wal 315 pass (was 165),
cli_smoke OK.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-28 17:55:43 +02:00
74399ffc68 docs(plan): WAL checkpoint — 6 tasks, databasev2 3
Plan for the approved spec. Code-free per the repo convention
(docs/plan/discarded.md:54); the executor writes the code.

- T1 wo_wal_compact: walk live rows via the bitmap, append one INSERT
  each through the EXISTING append path, fsync, rename over the live log,
  fsync the parent dir, reopen the descriptor. Test asserts BOTH that the
  log shrank AND that a replay reproduces the same rows/ids/values —
  shorter alone is worthless, a truncating bug also passes that
- T2 a stale temp file is removed at open and never read. The test uses
  PLAUSIBLE records, not garbage: garbage would be rejected anyway and
  would prove nothing
- T3 the trigger as a PURE decision (used bytes, last compaction's
  measured output, floor) so it is unit-testable without a store; env
  knobs for floor and ratio, which is what makes the policy testable at
  all. No timer, with the reason. The check is called only where nothing
  is staged, asserted by a test that stages and expects deferral
- T4 kill -9 DURING compaction, extending the existing fork-based crash
  battery. Asserts the PROPERTY — the store equals the pre- or the
  post-compaction content, never a mixture, and every acked id survives.
  Run repeatedly and state the count: it is a race, one green run proves
  little
- T5 measure space reclaimed, boot before/after, and the stop-the-world
  PAUSE against a stated budget. If the pause exceeds it, stop and report
  — the alternatives are bought against that number, not before it
- T6 closeout, including the normative ordering rule in 04-db-binding.md

Constraints carried from the spec into every task:

- recovery must NOT change; a task editing the replay path should stop
- the dump must FLUSH PERIODICALLY. stage() grows the staging buffer by
  doubling, so dumping a whole store through one buffer would hold the
  entire store in RAM — the unbounded growth databasev2 1 identified as
  how this engine dies
- a FAILED compaction is a missed optimisation, not a durability event,
  so it must not take databasev2 4's fatal path
- gate tolerances must not be waived wholesale (part A's T4 made that
  mistake), and the baseline is full-mode — writing a quick-mode baseline
  over it is a regression part A also made

Deliberately NOT a task: rebuilding the `resident: keys` offset map. It
cannot be implemented against a feature that does not exist yet, so T6
records it as an obligation at the compactor and in the story instead of
a stub nobody can test.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-28 17:44:18 +02:00
69c34c9a89 docs(spec): WAL checkpoint — compact by rewrite + atomic rename
databasev2 3, chain 6. Brainstormed 2026-08-28 after databasev2 4 part A
landed.

Design: compact the log by rewriting it as one record per live row into a
temp file, fsync, rename over the live WAL, fsync the parent dir, reopen.
Recovery is COMPLETELY UNCHANGED — boot still opens one file and replays
it — and the crash criterion ("the same store as if the checkpoint had
never started") is satisfied by rename, not by code we must get right.

Read .dev/reference/postgresql for this. The finding is that PG's design
is UNAVAILABLE to us, which is what makes the simpler option legitimate:

- PG never compacts its WAL; segments before the redo point are recycled
  by rename or unlinked. Its records are page deltas, so a compacted redo
  log is not a store — hence heap files, a control file, a redo pointer,
  a second recovery source and a separate process
- ours are FULL ROW IMAGES (apply_record implements UPDATE as
  remove-then-recreate), so a compacted log IS a complete store. That one
  difference deletes all of the above from the design
- what IS worth porting is the ordering discipline: publish the new
  "recovery starts here" atomically and LAST, so a crash falls back. PG
  needs a start-of-checkpoint redo pointer plus an end-of-checkpoint
  control file update; we get the same property from one rename, because
  we can swap the whole data set atomically and PG cannot

Forks settled:

- no snapshot format — the compacted log is the snapshot, existing grammar,
  so no new encoder or decoder and the dump reuses wo_wal_append_insert
- one source, not two
- volume-only trigger, as a ratio against the LAST compaction's measured
  output (the denominator is known exactly; estimating the live set would
  mean estimating Text) with an absolute floor. NO TIMER — PG's exists to
  bound loss from unflushed buffers and we have none; an idle log does not
  grow. Copying the mechanism without the reason was the trap
- stop-the-world, with the pause measured against a stated budget rather
  than assumed acceptable; alternatives are bought against a number
- compaction may run ONLY where nothing is staged (right after a barrier),
  or a staged record lands in a file about to be replaced. Normative

Recorded before it can be found late: compaction invalidates every WAL
offset iteration 2's `resident: keys` stores, so the compactor rebuilds the
offset map as it writes. Nothing breaks today because that storage half is
unimplemented — it would break later, looking like corruption.

Also corrected exploration/postgresql/buffer-and-checkpoint.md, which was
wrong on two counts: PG does NOT update its control file by rename (in-place
full-block write + CRC32C), and its checkpoint sketch assumes writeonce has
segment files, which it does not and deliberately will not.

Grounding measured on master: seed 20000 leaves a 986614-byte log; 20000
updates take it to 2590262 bytes with the SAME live rows, and boot+verify on
that store is 155ms.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-28 17:39:38 +02:00
0b618ace19 docs+fix(db): T6 closeout — and reads no longer wait for the barrier
databasev2 4 part A, task 6. Mostly documentation, plus one real fix the
full battery caught.

THE FIX. The drain held EVERY DB reply until the barrier — including
reads, which stage nothing and have no stake in durability. That parked
readers behind an fsync for no reason: durable.sN.mixread.p99 rose from
~1043us to 4057us. Only a statement that actually staged a record now has
its reply held. Caught by the gate, not by review.

THE TRADE, recorded rather than smoothed over. What remains is inherent: a
barrier blocks the owner shard LONGER (more records per fsync) though LESS
OFTEN, so anything queued behind one waits. Three full runs of the same
build gave durable.sN.mixread.p99 of 1043 / 2318 / 4147us and wmix.p99 of
8758 / 20000us — a 2-4x spread with the box near idle. So part A buys ~3x
write throughput at the cost of a longer, noisier tail on the owner shard,
and that is the strongest argument for part B (submit and keep serving).

- durable.sN.*.p99us tolerance widened to 100% WITH the reason in the
  code: a 2-4x-variable tail gated at 50% gates the disk, not the engine.
  The floor is the real guard and is not slack — mixread's (4172us) came
  within 25us of tripping on the worst run. Baseline refreshed; a fresh
  full run then passed 106 checks 0 failures

EXIT STATUS MOVED 3 -> 74 (sysexits EX_IOERR). 3 and 4 are already used by
SAMPLES for their own meanings — db-bench's own `verify` exits 3 on a
checksum mismatch, and it is the gate that exercises durability, so a
durability abort exiting 3 would have been indistinguishable from the
mismatch it should help diagnose. The low range belongs to programs.

Docs:

- story: progress, the payoff measured two ways, the cost side, criteria
  split met/outstanding, and a "part B — its premise changed" section:
  it was justified by "close the 66x gap", but that gap is two problems
  and only the concurrent one was a batching problem
- board: standup entry in the six-question shape; both databasev2 4 rows
  rewritten. They had said "close the 66x gap" — recorded as MIS-STATED
  rather than quietly renumbered
- 00-wob-format.md and 04-db-binding.md: the normative failure contract
  ("a failed WAL commit traps WO_T_IO after un-applying the row") was
  false; corrected, along with the tick-scoped group commit that never
  happened
- database/src/CODE-LOGIC.md: where the barrier runs and why there, why
  replies are held, why the inline path is asymmetric, the one failure
  rule, and how to measure it
- db-bench README: the wmix mode, the env knobs, and the tmpfs warning

Battery: wovm-test 36 suites 0 fail, woc-test, oop-e2e 119/0,
db-bench 106/0, linkcheck clean.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-28 16:48:23 +02:00
6183a67dfc perf(db): group commit measured — ~2.9x durable write throughput, T5
databasev2 4 part A, task 5.

Controlled before/after — same machine, same workload (wmix 4000 32),
same build except db.c and vm.c, two runs each interleaved:

- per-statement barrier: 2213 / 2177 ops/sec, p50 7183 / 7251us
- group commit:          6216 / 6525 ops/sec, p50 3458 / 3444us
- ~2.9x throughput, ~2.1x lower p50

The full campaign confirms it a second way: s1 takes the inline path and
commits per statement BY DESIGN, so within one build the shard configs are
batching-off vs batching-on — 1467 -> 5117 ops/sec, mean batch 1.0 -> 5.43,
peak 1 -> 57. 3.5x, agreeing with the 2.9x above.

Recorded honestly:

- the BEFORE p99 is at the histogram ceiling (hist_add clamps at 20000us
  and both runs pinned there), so the true figure is >=20ms and unknown.
  The improvement is AT LEAST 2.3x; the old p99 was off the instrument
- durable.sN.mixwrite went 480 -> 492 ops/sec, i.e. UNCHANGED. That was
  the spec's original payoff metric and correcting it was part of the
  brainstorm: mix performs 20 writes at C=4, mean batch 1.01. A workload
  that never has two writes in flight cannot be helped by batching them
- seed is likewise unchanged: a serial writer has nothing to batch with
- so the payoff is real but CONDITIONAL — it appears where concurrent
  durable writes fan into the owner shard, and nowhere else

Two traps recorded in perf-targets §6:

- do not benchmark durability on /tmp: it is tmpfs here, where fdatasync
  is free. The same run reported 195000 ops/sec at p50 1us there against
  2200 at p50 7200us on ext4 — no barrier to amortise, so the measurement
  measures nothing. db-bench keeps its stores under bench/ for this reason
- the record count is not the update count: 7755 records for 4000 updates,
  because hist_dump and the done-marker are themselves durable inserts

- FIXED a regression I introduced in T4: master's committed baseline is
  FULL mode (N=20000, crash_reps=3, msg_n=200000) and I had overwritten it
  with quick-mode values. Regenerated from a full campaign; the full run
  now passes 106 checks 0 failures against it
- gate still bites: sN wmix ops_sec -70% -> FAIL on exactly that metric

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-28 09:54:52 +02:00
5f9598af6a feat(db-bench): prove batches form — the write-concurrent leg, T4
databasev2 4 part A, task 4. Scope extended with developer approval: the
plan authorised touching the sample only for observability, but no
existing leg has enough concurrent durable writes to exercise group
commit at all, so the payoff was unevaluable either way.

The finding that forced it:

- `mix` writes on one op in ten with C=4 (all_mode calls mix_mode(n/10,
  4); Mixer writes on i % 10 == 9), so the quick run performs 20 writes
  total. Measured mean batch 1.01 over 3112 barriers, peak 3
- that is a property of the WORKLOAD, not the mechanism: peak 3 of a
  possible 4 shows batches form whenever writes actually coincide

- `wmix N C` added: every op a durable write, C at once. Updates rather
  than inserts, so it is comparable to mixwrite and the row count stays
  flat. Histogram kind 2 — a replayed store still holds the seeding run's
  kind-0/1 Hist rows and merging those would report someone else's
  latencies
- WO_WAL_STATS=1 prints one line at exit: batches, records, peak_batch,
  peak_staged. Opt-in, because it would otherwise pollute every durable
  program's output. Counters live in wo_wal; no builtin, the numbers are
  diagnostic and not part of the language

Measured, and it scales with concurrency exactly as designed:

- C = 4 / 16 / 64 -> mean batch 1.13 / 1.76 / 5.35, peak 3 / 10 / 39
- the gate's own legs: durable.s1 5412 records over 5412 barriers (mean
  1.0, peak 1 — the inline path, one barrier per statement BY DESIGN),
  durable.sN 7757 over 2296 (mean 3.38, peak 28) at 2x the throughput
- peak staged 1372 B settles the no-cap decision with a number: the batch
  is tiny, so the upstream mailbox bound is sufficient

- mean_batch/peak_batch are higher-is-better (the default detector would
  have called bigger batches worse)
- only the batch SHAPE metrics are waived to 100%; wmix throughput and
  latency keep real tolerances (15% s1, 50% sN) — a blanket waiver would
  have left the entire new leg ungated
- the live assertion `mean > 1.0` on the sN leg is what catches inertness
- gate bites: sN wmix ops_sec -60% -> FAIL on exactly that metric, 1 of 86

Verified: db-bench-quick 89 checks 0 failures; baseline refreshed (86
metrics).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-28 09:47:51 +02:00
9fc439dd47 feat(db): the inline path takes the fatal rule, asymmetry documented — T3
databasev2 4 part A, task 3. Looks like a no-op; it is not — without it
the two write paths would disagree about what a failure means, which is
the unevenness the spec exists to remove.

- inline path (a statement already on shard 0) keeps its own barrier,
  batch size 1. It cannot hold a reply: it returns into its OWN fiber
  rather than unparking a requester, so batching it would need that fiber
  parked on the barrier — part B's machinery, deliberately out of part A
- the comment says so, and says why not to "fix" it, because the next
  reader will otherwise see an inconsistency and delete the commit
- the ordering assumption is written down: committing here is safe only
  because the drain commits unconditionally whenever anything is staged,
  so the buffer is empty when this runs. If that stops holding, this
  commit would make another statement's record durable early and ack it
  to the wrong writer
- staging and commit failures are fatal here too. The update arm's old
  comment admitted what it did — "RAM ahead of disk: trap, do not ack" —
  and that is now gone

WO_T_IO no longer appears anywhere in db.c: the write path cannot be
caught. Language-visible, and task 6 records it in the error catalogue.

Verified:

- just wovm-test: 36 suites 0 fail, cli_smoke OK
- WO_SHARDS=1 db-bench-quick: 85 checks 0 failures, crash.s1.0 800 acked
  rows present after kill -9 — the configuration that takes this path
  exclusively
- default shards: 85 checks 0 failures

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-28 09:32:34 +02:00
76d80cc027 feat(db): one barrier per drain, replies held — T2
databasev2 4 part A, task 2. The core change, and mostly deletion.

- the REQUEST path (wo_db_exec_req) no longer commits after each append.
  Applying to RAM and staging stay exactly where they were
- wo_vm_adopt holds each DB reply envelope in a local FIFO instead of
  pushing it as the statement finishes. Pushing there would unpark the
  requester before its record is durable — the ack contract this
  iteration exists to make literally true rather than true by accident
  of every batch having one member
- at the end of the drain: ONE wo_wal_commit_fatal for everything staged,
  then every held reply. Locals rather than per-shard state: nothing
  needs to outlive the batch it describes
- "did this statement stage anything" is asked of the buffer, not guessed
  from the opcode, and that count is what the failure diagnostic reports
- the drain commits unconditionally when anything is staged, because the
  inline path relies on finding the buffer empty (task 3 documents that)
- staging failure on the request path is now FATAL via wo_wal_stage_fatal:
  the row is already in RAM and of the three verbs only insert could undo
  itself, so continuing means RAM ahead of disk. One rule
- wal_die is now shared by both fatal points

Verified — the ack contract is the thing that could break, so it is what
was tested:

- just wovm-test: 36 suites (18 x both dispatch flavors) 0 fail, cli_smoke OK
- just db-bench-quick: 85 checks, 0 failures. The legs that matter:
  crash.sN.0 — 612 acked rows all present after kill -9, which is the
  BATCHING path (multi-shard requests, held replies, one barrier);
  crash.s1.0 — 800 acked rows; restart.s1 and restart.sN replay byte-true

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-28 09:25:10 +02:00
ceea00e0b6 feat(wal): a failed barrier is detected, and fatal — T1
databasev2 4 part A, task 1.

- wo_wal gains `path`: the abort diagnostic is worthless without naming
  the file it could not write. strdup'd in open, freed in close; NULL is
  tolerated so the message degrades rather than crashes
- wo_wal_commit now reports WHICH half failed — WO_WAL_ERR_WRITE for
  pwrite, WO_WAL_ERR_SYNC for fdatasync. A short write and a device
  refusing the flush are different operational problems and the operator
  needs the right one named
- wo_wal_commit_fatal(w, nrec): commits, or prints one diagnostic naming
  the operation, path, errno and record count, then exits
  WO_EXIT_DURABILITY (3 — 1 is a trap, 2 is a refusal, so this takes a
  third of its own)
- retrying is not offered, deliberately: on Linux a failed fsync may have
  already discarded the dirty pages, so a second call can report success
  having written nothing. Replay is the recovery that works

- test_wal: a failed commit is DETECTED, reports the write error
  specifically, keeps the batch staged (a failed commit consumes
  nothing), and the WAL knows its own path. 165 pass (was 156)

DISCLOSED GAP: the exit path itself is not exercised. Forcing a real
fdatasync failure needs a full or read-only filesystem, which the gate
cannot arrange without mount privileges. No fault-injection switch was
added — shipping a binary that can be told to kill itself is the worse
trade, and the spec rejected it.

Verified: just wovm-test — 36 suites (18 x both dispatch flavors) 0 fail,
cli_smoke OK.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-28 09:16:35 +02:00
026919762b docs(plan): WAL group commit — 6 tasks, databasev2 4 part A
Plan for the approved spec. Code-free per the repo convention
(docs/plan/discarded.md:54); the executor writes the code.

- T1 a failed barrier is detected and fatal — one entry point that names
  the operation, errno, WAL path and batch size, then exits. The abort
  path itself stays unexercised and the task says so rather than buying
  coverage with a fault-injection switch
- T2 the barrier moves to the drain point and replies are held; the
  request path stops committing per append. Riskiest task, and its risk
  is one place: the crash legs. Plan says STOP if they fail, do not
  adjust the test
- T3 the inline path takes the same fatal rule but keeps its own barrier,
  with a comment explaining the asymmetry so the next reader does not
  "fix" it. Looks like a no-op; without it the two paths disagree, which
  is the unevenness the spec exists to remove
- T4 prove batches actually form BEFORE measuring the payoff — otherwise
  a win gets attributed to the wrong cause. Also records peak staged
  bytes, settling the no-cap decision with a number
- T5 measure, gate, write it down. If the payoff is absent, say so and
  stop: part B must not start on an unproven premise
- T6 closeout, including the error catalogue — WO_T_IO leaving the write
  path is language-visible and must be written down

Spec corrected while planning: it pointed at durable.s1.seed as the
payoff. Wrong, structurally — worker shards hold no WAL, so a queue only
exists when other shards write, and a serial writer has nothing to batch
with. The real target is durable.sN.mixwrite: 480 ops/s at p99 5888us
against s1's 1023 at p99 664, so adding shards currently makes durable
writing WORSE. That inversion is a better argument for the iteration than
the one the story recorded.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-28 09:06:09 +02:00
75aedf1216 docs(spec): WAL group commit — databasev2 4 part A
Brainstormed 2026-08-28. The iteration is split: part A batches, part B
(io_uring submission) is deferred until A's measurement says whether the
blocking boundary still dominates.

The story's premise needed correcting first:

- it says "replace fsync-per-commit with io_uring group-commit", but the
  engine commits per STATEMENT — db.c calls wo_wal_commit right after
  every append, all six sites, so each row change is one pwrite + one
  fdatasync
- so two independent wins were being carried as one, and only the second
  needs io_uring. The staging buffer already holds any number of records;
  today it never holds more than one. Part A is mostly deleting calls
- iteration 22's numbers say A is where the payoff is: durable writes
  4460 ops/s, mixwrite 1023 ops/s p99 664us, against 1.28M ops/s reads

Forks settled:

- batch boundary is QUEUE-DRAIN, not the tick this story had recorded: a
  tick adds latency to a lone writer, taxing an idle system to serve a
  busy one. Queue-drain self-tunes and needs no knob
- shard 0 holds each reply envelope instead of sending it, commits once
  when the queue empties, then releases all — so a writer is acked after
  the barrier carrying ITS record, which today is true only because
  every batch has one member
- a failure between "RAM mutated" and "record durable" is a FATAL,
  diagnosed abort. This replaces uneven behaviour that already exists:
  insert rolls back, update and delete do not and say so in a comment
  ("RAM ahead of disk"). Batching would have multiplied that
- consequence stated, not slipped in: WO_T_IO leaves the write path
- no batch cap initially; peak staged bytes is measured so the question
  is settled by a number

One gap disclosed rather than hidden: forcing a real fdatasync failure
needs mount privileges, so the unit test proves the error is DETECTED and
the abort itself stays covered by inspection.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-28 07:48:11 +02:00
62d29d6a77 docs(24): T10 closeout — stories done, board, graph, ledger, CODE-LOGIC
Iteration 24 closes, absorbing 31 and 34. No code in this commit.

- stories 24, 31, 34 -> `status: done`, each with a landing banner. 24's
  records the gate numbers and BOTH disclosed deviations: monitor takes
  three arguments (the caller may be `main`, which has no mailbox) and a
  v1 `call` reply is a typed scalar (which is what let the agreement be
  checked at compile time, WO-E226). 31's notes it landed INSIDE 24 and
  that a fifth mechanism it never anticipated came out of proving the
  gate — the drain guarantee (40). 34's names the gap it did NOT close:
  still no RNG, so CSRF/sessions stay blocked
- board: in-progress row cleared, marker doc deleted (convention), the
  standup entry in the six-question shape, chain note — next link is
  databasev2 4 (io_uring group-commit, chain 5)
- graph: PUBSUB2 (pub/sub + WebSockets, "rejected until here") -> done
- porch ledger: a WebSocket/pub-sub row added; the cancellation row now
  says what it actually waits on rather than repeating "the arc"; the
  README's "no WebSockets/SSE" limitation was stale — WebSockets are
  supported, SSE and chunked encoding are not
- CODE-LOGIC: runtime/src gains the actor-lifecycle section (call, death,
  the cap counter's sender/home-thread split, the monitor walk, the timer
  list), the drain guarantee, and the digest section; docs/examples/chat
  gains its own — actor topology, WHY two actors per connection, fd
  ownership, and the shutdown choreography

Battery after the doc edits: wovm-test 36 suites 0 fail, woc-test exit 0,
oop-e2e 119/0, chat 11/0, web-app 46/0, linkcheck clean.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-28 00:06:31 +02:00
7833dd5740 feat(gates): example apps log to /tmp/<example-app>.log so it can be tailed
Every gate wrote its server output into a per-run mktemp dir that its own
cleanup trap deletes on exit — nothing to follow during the run, nothing
to read after it.

- chat -> /tmp/chat.log, web-app -> /tmp/web-app.log,
  site -> /tmp/site.log, log-watcher -> /tmp/log-watcher.log
- truncated once at gate start, appended for the rest of the run, so one
  file holds the whole run in order
- each gate PRINTS the path as its first line, with the tail -F command
- legs are banner-separated and name their port and env
  (===== leg 2 - port 18902 - env WO_IO=epoll =====)

Appending breaks readiness detection unless it is leg-scoped:

- serve() used to grep the whole file for `listening`, which after the
  switch to append would match an EARLIER leg and return before the new
  server was up. It now records the line count first and searches only
  tail -n "+$LEGFROM"; the ASan scan is scoped the same way
- log-watcher's checks grep per-invocation files, so those are kept and
  the output is teed into both — process substitution adds no pipeline
  stage, so $! is still the command's pid the gate kills and waits on
- its one SYNCHRONOUS invocation appends after it finishes rather than
  teeing: the grep on the next line would race tee's flush

Verified, all green: chat 11/0, web-app 46/0, site 21/0, log-watcher 7/0.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 23:53:10 +02:00
d87846354e docs(board): iteration 24 is 9 of 10 and on master; only T10 closeout remains
- narrative said "five of ten tasks landed" and named the branch as the
  live location; T4/T5 (ids 89/90) had landed and the slice merged to
  master 2026-08-27 (60414a1, fast-forward)
- records what was verified ON master: chat 11/0 at the full 1000-client
  soak, runtime 36 suites 0 fail, compiler 556 checks, corpus 119 checks
- T10 closeout is what still holds stories 24/31/34 open

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 23:44:56 +02:00
60414a1754 feat(runtime): the shutdown drain guarantee — iteration 40
A message sent before the stop flag is observed must be delivered and run
before the engine stops. One rule; a spin count could never express it.

- root cause in `shard_main` (runtime/src/vm.c): NEXT_RUNNABLE() already
  stated the contract — "a WORKER on stop keeps DRAINING ... so queued
  shutdown messages (close frames!) still run" — but the IDLE branch
  contradicted it, calling fib_reap_all and breaking on WO_IO_STOP,
  abandoning its inbox for wo_engine_stop() to free wholesale
- an actor between messages is exactly that idle case, which is why a WARM
  soak server hid it: warm shards held live fibers and took the right path
- fix: while the primary's drain window is open, an idle worker adopts its
  inbox and runs what arrives; sched_yield on an empty poll so a drain
  cannot burn a core per shard and starve the actors it exists to let run
- unreachable at WO_SHARDS=1: wo_engine_stop returns early at nshards <= 1

Measured:

- fresh-server SIGTERM drain: 5 of 16 failing before, 20 of 20 clean after
- `just chat` at the FULL 1000-client soak: 11 checks, 0 failures, both
  WO_IO backends, ASan clean with zero leaks
- the fd leg settled at scale too: 1000 connections left the count at 44,
  unchanged after 20 more — lazy per-shard init, not a leak
- runtime battery 36 suites (18 x both dispatch flavors) 0 fail;
  compiler 556 checks 0 fail

- story: docs/stories/language-runtime-database/40-shutdown-drain-guarantee.md
  (chain 3 with 31, status done), board row, slice marker updated
- outstanding and named: a pin below the gate needs new multithreaded test
  infrastructure — nothing in runtime/test/ drives wo_engine_start/stop and
  no corpus fixture can trigger a stop

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 23:43:45 +02:00
3bc85d85f3 docs(slice): marker reflects T4/T5 landed, the drain blocker, and the stale-artifact trap
- T4 monitor + T5 time.after landed in 4092074 (ids 89/90); marker still
  listed them pending because it came from master, which lacks that commit
- records the branch baseline (18 suites x 2 flavors, 0 fail) and the gate
  at 11 of 12 legs green
- names the stale-artifact trap: after a branch switch, compiler/_build and
  runtime/build hold the OTHER branch's binaries, and a v7-vs-v6 mismatch
  surfaces only as "no listener"
- the drain guarantee is now the single named blocker; nothing else in the
  slice should land before it

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 23:28:25 +02:00
4af1e8bcdd fix(chat gate): every leg starts its own server — and it found a real bug
Gate defects, all measured:

- fd check was core-count dependent: `fds_before + 8` read LAZY per-shard
  init as a leak. Shards init on first fiber, each taking one io_uring +
  one eventfd, capped at nproc; on 20 cores the first wave legitimately
  adds 18. Measured 26 -> 44 after 20 clients, still 44 after 40 more.
  Replaced with the invariant the check is for: a second wave must not
  raise the count. Core-count independent, and catches a slow leak that
  any fixed slack would hide
- a failed leg ORPHANED its server: drain inherited $SRV from the soak
  leg, so its python died on int("") and the soak server was never
  killed — its listener then broke the next run's soak on the same port.
  drain now starts its own server; cleanup kills every server a run
  started, matched on the run's unique temp dir
- two legs the plan requires were missing: WO_SHARDS=1 (the single-shard
  control) and WO_MAILBOX=8 (drop-slow-member backpressure). Both added,
  both green. The mailbox leg shrinks the slow client's SO_RCVBUF so it
  needs no sleeps
- chat adopted the porch naming (use porch/..., [deps] key) after the
  rename landed on master

Decoupling the legs exposed a REAL drain bug, traced and documented in
docs/2026-08-27-chat-drain-finding.md, NOT fixed here:

- on a FRESH server the SIGTERM drain is flaky: 5 of 16 runs left a
  client at EOF with no close frame and no diagnostic
- traced: main -> Registry -> Room -> Writer. Registry runs (diag
  confirms), the Room NEVER processes its shutdown message, so the
  Writer's close branch never runs. Clients that do get a frame are
  saved by their own Reader seeing env.stopping()
- ruled out: the spin budget (a 1s wall-clock deadline still failed 2 of
  12 — reverted, it fixed nothing and cost 1s per shutdown),
  dummy_writer() spawning during shutdown, and write failure
- the fix is an engine guarantee — a send issued before the stop flag is
  delivered — which belongs to the actor lifecycle, not a spin count

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 23:27:46 +02:00
ebc3522c40 Merge branch 'master' into chat-ws-lifecycle 2026-08-27 23:11:49 +02:00
3507aafea3 docs(databasev2): propagate iteration 1's findings to every consumer
Audit found 4 of 10 iterations citing it1 and 4 carrying stale claims the
measurement contradicts.

- 05: framing was contradicted, not merely incomplete. Its goal expected a
  gradient to detect ("back-pressure before the cliff"); there is no cliff
  — SIGKILL with swap off, exit 0 with swap on, and read latency STEPS
  (1us -> 487us) rather than departing. Heading and goal rewritten; the
  measurement makes the goal stronger, not weaker
- 05: budget must be bytes — 3.3x footprint spread — with headroom for
  index doublings, else it fires during a rehash
- 05: new goal — eviction policy QUALITY is decisive, since getting the
  resident set wrong costs 273x, not a few percent
- 06: its revival question now has a reference point. 273x is the KERNEL
  SWAP path; `resident: keys` preads via page cache and must beat it. This
  file revives only if 5c/5d lands near 273x rather than well below
- 04: write path is not where pressure bites (append ~1%, read 273x), so
  the io_uring question that matters is iteration 2's deferred read-path
  one, not group-commit
- 00-story: problem statement asserted the store "refuses the insert
  rather than dying". Corrected in place — a banner above it was not
  enough, a skimmer never reaches it
- residency spec: "swap thrash and the OOM killer" named exits that were
  not measured; replaced with silence-or-a-corpse

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 22:47:37 +02:00
5b1a8c96a1 feat(db-bench): replay baseline — boot cost tracks history, not data
Closes the last gap in databasev2 1; gives databasev2 3 its "before".

- `boot` mode: does NOTHING. WO_DATA replay runs before main, so a mode
  with no work measures replay plus a fixed startup
- `replayseed N M`: N inserts + M updates — same live rows, longer log
- `replay` leg: empty-store startup floor measured and SUBTRACTED, then
  two shapes timed, median of 3 boots each
- premise check: updates must actually append WAL records, else the two
  shapes are one measurement and the penalty means nothing
- WAL bytes = non-zero prefix, never file size (fallocate'd to 1 MiB)
- per-record cost stored in NANOseconds: as us it rounded 5.5 and 5.3 to
  6 and 5, too coarse for the number a checkpoint exists to improve
- 148 checks, 0 failures; gate bites on a doctored ns_per_record

Measured — same 20 000 live rows, different history:

- 20 000 records:  980 035 B WAL, 110 ms replay, 5.5 us/record
- 40 000 records: 1 960 035 B WAL, 211 ms replay, 5.3 us/record
- 1.9x boot cost for an IDENTICAL dataset; per-record cost flat, so
  replay is linear in records not rows
- extrapolated: 10M records ~55 s of boot, 100M ~9 min

- databasev2 3 correction: it planned to use "22's aged-store replay
  numbers", which never existed — 22 proved restart correctness, never
  timed it
- databasev2 3 hazard recorded: compaction rewrites the log and moves
  every record, so it invalidates every `resident: keys` offset — an
  arbitrary byte in a rewritten file, not stale-but-readable
- databasev2 1 -> status: done

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 21:25:24 +02:00
a873cf7331 feat(db-bench): random-read-over-cap leg — the 273x collapse
- `randread N R` in the sample: fill N rows, read R across the WHOLE range
- Weyl order `i*2654435761 mod n` — no RNG in the language, none needed;
  both legs read the SAME key order so residency is the only variable
- `randread` driver leg: control (256 MiB, does not bind) vs over-cap
  (6 MiB + swap), sizes kept modest — quick resolves it in ~5s
- gates the RATIO, not the absolutes: over-cap reads/sec belongs to the
  box's swap device, the factor between two runs belongs to the engine
- reads must all resolve (hits == R) or the leg fails; a collapse measured
  over unresolved reads is noise
- 133 checks, 0 failures; gate bites on a doctored collapse_x

Measured — this closes the gap the swap leg left:

- resident 1 851 166 reads/sec, p50 0us p99 1us
- over-cap    6 771 reads/sec, p50 128us p99 487us
- 273x throughput, ~480x p99, all 20 000 reads resolving in both
- so the two access patterns sit ~270x apart under identical pressure:
  append-mostly insert ~1%, random read 273x
- departure is a STEP not a curve (1us -> 487us, nothing between), which
  is why p99_departure_decile finds no knee — there is none

- caveat recorded, NOT inherited: this is demand-paged anonymous memory
  through swap (4 KiB/fault, no readahead). `resident: keys` preads via
  the page cache — should be better, but databasev2 2 task 7 must measure
  its own read path. New criterion added there

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 20:56:19 +02:00
0c9b2c45d8 feat(db-bench): measure the RAM ceiling — databasev2 1
- `Wide` text-heavy reference shape beside Int-only `Item`
- `growth N int|text`: per-decile RSS read from own /proc/self/status
- `growth-verify`: survivor of a crash must be a contiguous intact prefix
- four footprint legs under a rootless cgroup v2 cap, swap on/off
- `ceiling` leg: die at the cap, then replay must come back intact
- footprint read as median-of-marginals; doublings a separate metric
- 121 checks, 0 failures; footprint gated ±10%, kill-timing ±100%

Measured, and it inverted two of the iteration's own predictions:

- footprint 96.5-100 B/row Int vs 320.6-324 B/row text = 3.3x, NOT the
  "order of magnitude" three docs asserted
- table storage has NO checked ceiling: SIGKILL signal 9, not a catchable
  WO_T_OOM. overcommit lets malloc succeed; kernel kills on page touch
- swap is NOT latency collapse: 900k rows 148s capped-with-swap vs 150s
  uncapped. Append-mostly never re-touches cold pages
- ack-after-fsync survives an OOM kill: ~40k rows, no holes, no corruption
- iteration 2's budget dependency is REMOVED not satisfied — there is no
  "swap onset" to derive a fraction from

- fix: subprocess returncode -9 was labelled a "checked refusal"; 137 is
  the shell spelling of the same signal

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 20:18:47 +02:00
1fe808b7a4 docs(stories): add readiness, retire status: refine, sweep all 47 iterations
- `readiness: ready | refine` is a SECOND axis, orthogonal to status.
  `ready` = the brainstorm is complete and the decisions are LOCKED (a spec
  approved, or the forks explicitly confirmed). `refine` = open forks remain
  and it cannot be planned yet
- `status: refine` RETIRED because it carried both meanings at once, so a held
  iteration with an approved spec (language 18, 26) was indistinguishable from
  one nobody had thought about. status is now purely where the WORK is:
  done | in-progress | pending | hold — `pending` was already the board's own
  rendering word, so nothing new was invented
- all 47 iterations classified from EVIDENCE in their own text, not by guess:
  "the four forks are SETTLED" / "spec + plan approved" / "Approved spec:" for
  ready; "Forks the spec must settle" / "no spec exists yet" for refine. Every
  shipped iteration is ready by definition. 19 done, 5 in-progress, 15
  pending, 8 hold; 27 ready, 20 refine
- two iterations moved refine -> in-progress rather than -> pending: language
  31 and 34 are absorbed into 24 and work on them is literally happening, which
  the board already showed as 🔄 while their frontmatter said otherwise. That
  disagreement is now gone
- board legend, board-views' frontmatter contract, and two new Dataview
  queries updated — the useful one being `readiness: ready AND status:
  pending`, the startable set

WHAT THE NEW AXIS IMMEDIATELY SURFACED: of 15 pending iterations, exactly ONE
is startable — databasev2 4, io_uring group-commit, whose forks were confirmed
settled 2026-08-20. Everything else pending needs a brainstorm first. That was
invisible while one key carried both meanings, and it is now on the board.

Also caught by the sweep, unrelated to readiness but found by cross-checking
frontmatter against the board: SIX duplicate rows. Every iteration moved into
databasev2 was still listed in the LANGUAGE pending table under its retired id
(23, 32, 33, 20, 21, 27) as well as its new one. Stale copies removed. And two
databasev2 rows made claims the sweep contradicts — iteration 1 was billed
"startable today" while its forks are open, and 6 still called itself the
ceiling-raiser after 2 took that role.

Docs only. linkcheck 0 broken / 0 anchors.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 16:54:45 +02:00
f72b3310a8 refactor(db): wo_row_borrow/wo_row_release — one read path for both residencies
Task 5c step 1 of docs/superpowers/plans/2026-08-26-table-residency.md, as a
PURE REFACTOR: no storage change, no keys-table anywhere. Borrow is wo_row_ptr
plus a seam, every release is a no-op. Provable on its own before the storage
change it exists to enable.

DESIGN SETTLED BY READING THE STRUCTURES, and both answers make 5c smaller:

- the id hash needs NO new storage. `hvals` is already uint64 holding
  slot+1 with 0 = empty (table.h), so offset+1 fits the same field, and the
  interpretation is per-table because a table is wholly `all` or wholly
  `keys`. No parallel map
- secondary indexes need NO change. `db_ibucket.ids` stores row IDS, not slot
  indices, and table.c resolves them through the id hash. I had told the
  developer these pointed at slab slots — that was wrong, and it is why this
  is one shared accessor rather than 11 rewrites
- the real coupling is the unique shadow: idx_add_row and
  row_apply_field_slot both FETCH the conflicting row and compare columns.
  Both now borrow/release, so a keys-table's non-resident conflict will be
  found rather than silently skipped — a unique check that only examines
  resident rows is a correctness hole, not a limitation

The scratch lives on `db_table`, not on the stack and not per call. Per call
would allocate once per candidate inside a bucket loop, turning an O(1) probe
into an allocation storm; a stack buffer is unsafe because the loader bounds
field_cnt at 65535 (loader.c:189), so the worst case is ~512 KB. It is safe
per-table because the store is single-writer, and a `busy` flag is there to
catch a nested borrow rather than let it alias silently. Freed in
table_destroy.

Gates: all 18 runtime suites 0 fail under ASan+UBSan (test_table 856/0,
test_wal 3654/0), oop-e2e 119/0, residency 8/0, employee 8/0, db-actor 8/0.
And the pure-refactor proof the plan asked for: `db-bench --quick` 85/0, every
resident read/query/seed/write floor held — a refactor that moves a number is
not a refactor.

Remaining wo_row_ptr sites for 5d: 6 in table.c, 2 in db.c, 2 in wal.c.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 16:33:36 +02:00
51dd42f9db docs(databasev2): rewrite iteration 2 to match what was designed and built
Flagged by the developer: the iteration still described the pre-brainstorm
three-mode design behind a "superseded in part" banner while four tasks had
landed against it.

- iteration 2 rewritten around the shape as built: two keys
  (`durable: true|false`, `resident: all|keys`), not a `mode:` enum with
  `cold`. status refine -> in-progress
- added a task-by-task progress table with commit hashes, and split the
  acceptance criteria into MET (each with how it was verified, not just that
  it passed — e.g. the goldens-unchanged claim is `git diff` over golden/
  being empty after a WOC_BLESS run, since blessing rewrites all of them) and
  OUTSTANDING with the task that owns each
- kept the history rather than deleting it: the three-mode replacement, the
  "one real rewrite" that was fiction, and the opposite half that turned out
  genuinely deep. An iteration file is where that record belongs
- board row rewritten to agree; the track index's "the lever" section, its
  principle-7 paragraph and its sequence rationale all still taught the dead
  three-mode design

ITERATION 6 IS NOW LARGELY SUPERSEDED, and bannered as such rather than
quietly gutted. `resident: keys` is the ceiling-raiser and it lives in
iteration 2 (tasks 5c/5d). More than relocated: 6's premise — a user-space
resident working set with faulting and 5's eviction policy — was specifically
REJECTED by the spec in favour of the kernel page cache, since a pread against
a cached page is a memcpy. What may still be left is recorded honestly: revisit
only with a measurement showing the page cache insufficient. Its fork list
survives, especially "does the language surface the fault cost at the use
site", which is still open and still the largest question about what writeonce
is. The sequence rationale is amended too — it had 6 as the ceiling-raiser and
5 as a prerequisite on the critical path; neither holds.

Docs only. linkcheck 0 broken / 0 anchors.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 13:10:30 +02:00
18a56f24ec feat(db): wo_wal_read_row_at — materialise a row from a log offset
Task 5b of docs/superpowers/plans/2026-08-26-table-residency.md, whose Task 5
is now split 5a-5d (plan updated in this commit).

- the offset twin of wo_row_read (table.c:721): same out-gate contract —
  every value handed back is a FRESH VM allocation — but resolved from a file
  position instead of the id hash
- fits entirely in wal.c because everything it needs was already public:
  scan_record and dec_val are local, and wo_val_decode_vm / wo_db_val_free
  are exported at table.h:183-187. Two decode stages, since the record and
  the VM speak different dialects: dec_val -> engine slots -> VM copies, with
  the engine slots freed as scratch on every path
- ZERO storage change. Nothing calls it yet; that is the point of separating
  it from 5c, so the read path can be proven before the slabs are touched
- refuses rather than guessing, each case distinguishable: no intact record
  at the offset, a malformed header, a decode failure, trailing bytes, and a
  REMOVE tombstone. That last one matters most — handing a tombstone back as
  a row would read a deleted row as live

Tested by deep field comparison, not by "it parsed": 24 rows with a nil Text
every third row, each read back BY OFFSET and compared field by field,
including the string bytes. Plus all three refusal paths — tombstone, a
mid-record offset (the silent-wrong-row failure this guards), and past the
intact prefix.

The free-on-every-path claim is VERIFIED, not assumed: removing the free
produced 3 LeakSanitizer reports; restoring it returns to 0. Worth doing
because "ASan is clean" only means something if the harness would have
complained.

PLAN SPLIT: Task 5's storage half was written as if it were plumbing. Measured
instead: wo_row_ptr returns a db_row* into a slab with 11 call sites, table.c
has 37 slab references, db.c:105-181 scans slabs directly, enc_val serialises
FROM the slab, and no operation exists that drops a payload while keeping
index entries. Note this is the OPPOSITE half from the earlier retraction —
the record FORMAT needed nothing, the record STORAGE genuinely is deep. 5c
(id->offset map + drop-payload-keep-index) and 5d (rewiring the call sites,
scans, @unique/FK across the boundary) get their own write-ups.

Gates: test_wal 3654/0 (was 3428), all 18 runtime suites 0 fail under
ASan+UBSan, oop-e2e 119/0, residency 8/0, employee 8/0, db-actor 8/0.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 10:27:40 +02:00
3290c7d117 feat(db): wo_wal_next_offset — exact record offsets, proven
Task 5a of docs/superpowers/plans/2026-08-26-table-residency.md. The read
path itself is NOT in this commit; see the note below.

- the offset problem is far smaller than the spec feared. `w->off` is the
  durable tail and `w->len` the staged bytes, and wo_wal_commit pwrites the
  whole batch AT off before advancing it — so a record staged now lands at
  exactly off+len, knowable at append time with no deferral to flush
- shipped as an inline accessor rather than new out-params on the three
  append functions, so the 156 existing WAL checks keep their signatures
- correct across both awkward cases, and both are now unit-pinned:
  a failed commit leaves off unadvanced so the record still lands where it
  was promised, and wo_wal_open positions off at the end of the INTACT
  prefix so offsets are always relative to validated data
- test_offset_capture asserts the recovered ID per record, not merely that a
  record parses — a wrong offset reads a NEIGHBOURING record, which passes
  its own CRC and returns the wrong row silently. 400 records across
  repeated buffer growth (stage() doubles from 4096) and uneven commit
  batches, so offsets are exercised mid-buffer and right after a flush

The failed-commit test caught MY OWN misunderstanding: I asserted
next_offset was unchanged after a failed commit. It is not, and should not
be — the record is still staged, so next_offset correctly points PAST it.
The invariant that matters is that the durable tail did not move, which is
what it now asserts.

Gates: test_wal 3428/0 (was 3426), all 18 runtime suites 0 fail under
ASan+UBSan, cli_smoke OK, oop-e2e 119/0, residency 8/0.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 08:43:10 +02:00
b74e13d21e feat(db): durable:false skips the WAL append and replay
Task 4 of docs/superpowers/plans/2026-08-26-table-residency.md — the first
behavioural change in the iteration.

- db.c: one predicate, `table_is_durable`, gating the three EXISTING mutation
  sites. Kept as a function rather than an inlined condition so
  database/src/CODE-LOGIC.md's "nothing else may mutate storage" claim keeps
  holding — the choke points stayed three
- the ack contract is untouched for durable tables: RAM applied, record
  staged, one commit before the ack, and a failed commit still removes the row
- replay: a log holding records for a class the image now declares volatile is
  a real migration case, not corruption. apply_record returns -2 (distinct
  from -1), wo_wal_replay_ex reports the class id, and main.c names it and
  exits 2. `wo_wal_replay` stays as the NULL wrapper, so all 156 WAL unit
  checks are untouched
- measured, not asserted: 50 inserts wrote 1500 WAL bytes into a durable
  table and ZERO into a volatile one. The file's SIZE proves nothing (it is
  fallocate'd to 1 MiB up front), so the gate measures the non-zero prefix

BUG I INTRODUCED AND CAUGHT: the mismatch message first printed the class name
with %s, but wo_str.data is `char data[]` with NO NUL terminator (obj.h) — a
buffer over-read. Now %.*s with the explicit length, and re-verified under
ASan.

New gate `just residency` (8 checks), because everything above was otherwise
a one-off manual measurement: restart behaviour, the zero-byte write path, the
mismatch refusal (exit 2, names the class, NOT reported as corruption), and
both compile-time refusals. Its own first run failed two checks for a bug in
the script rather than the feature — `woc | grep` under `set -o pipefail`
returns woc's exit 1 even when grep matches, since woc exits 1 whenever it
reports diagnostics. Captures first now, with the reason noted inline.

Also new: corpus run/table-volatile-inprocess pins that a volatile table is a
FULL table in-process — same @unique enforcement, same index probe, same query
surface. Only survival differs, and that is unobservable from inside one
process.

Gates: woc-test 557/0, 18 runtime suites 0 fail, cli_smoke OK, oop-e2e 119/0
(was 118), residency 8/0, employee 8/0, db-actor 8/0, site 21/0, ASan clean on
the new replay path.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 08:23:49 +02:00
477f8d1b2b feat(wob): v7 — class descriptor carries durability and residency
Task 3 of docs/superpowers/plans/2026-08-26-table-residency.md.

- NO LAYOUT CHANGE. The plan said to add descriptor fields; the descriptor
  already had a `flags` u32 with only bit0 used, so both properties ride
  spare bits (WO_CLASSF_VOLATILE 0x02, WO_CLASSF_RESIDENT_KEYS 0x04). A v7
  class record is byte-identical in shape to a v6 one, which is a much
  smaller and safer change than the plan assumed
- both spelled as the NON-default, so a zero flags word means exactly what
  every pre-v7 image meant: durable, every row resident. A non-@table class
  has both clear by construction
- the loader refuses the meaningless pair (bit1+bit2) independently of woc,
  on the standing principle that what the loader accepts the interpreter
  trusts. Verified by FORGING the flags word in an otherwise valid image,
  since woc will not emit one: flags=6 gives "durable:false with
  resident:keys", flags=8 still gives "unknown flags"
- WOB_VERSION 6 -> 7. Kept because an OLDER runtime reading a v7 image would
  otherwise treat a volatile table as durable and quietly disagree with its
  own source. loader.c's check is exact-match, so a v6 image is refused
  rather than read with the bits clear — verified by patching a v7 header
  back down to 6

GAP FOUND AND CLOSED: woc ACCEPTED `durable: false, resident: keys`. Task 1's
steps covered duplicates and bad values but never the combination, and the
plan had only put that refusal in the loader. The spec wants both, so the
compiler now refuses it too (WO-E102, checked after the argument list is
complete since it is a property of the pair). A compile error is the one a
developer can act on.

VERSION DRIFT: the constant lives in FOUR places, not one. wob.h,
emit.ml:157, disasm.ml:186, and compiler/test/runner.ml:2405 — the last is a
deliberately independent reimplementation of the loader battery, and it
caught the drift as 14 failures rather than silently passing. Its flags mask
and the combination refusal are now in sync too, which is the point of it
being independent rather than shared.

Gates: woc-test 557/0, 18 runtime suites 0 fail, 18 ISO-flavour suites 0
fail, cli_smoke OK, oop-e2e 118/0, employee 8/0, db-actor 8/0, site 21/0.
Zero goldens moved (git diff over golden/ empty).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-26 23:22:26 +02:00
e120129f2c feat(woc): WO-E224 — refuse a durable ref into a volatile table
Task 2 of docs/superpowers/plans/2026-08-26-table-residency.md.

- the check lives in `check_field_types`, which already runs over the raw AST
  (so the diagnostic lands at the field's own position, once per declaration)
  in Pass 2 with `syms` fully built
- only the durable -> volatile direction is refused. volatile -> durable is
  legal: the referencing row is the one that disappears, so nothing is left
  holding a stale id
- the message names both classes and both escapes, because "this is wrong" is
  less useful than "make Session durable, or declare Order volatile too"
- sees through a `?` wrapper, so `?ref S` is caught too
- code picked as 24 by sweeping `<stage>_prefix ^ "NN"` — 01-23, 25, 26 and
  50 were taken, so 24 was a genuine hole. Grepping the literal WO-E224
  would have found nothing, which is how ten codes once went missing
- catalogued in the same commit, and the completeness sweep re-run: 53
  emitted, 54 catalogued (the extra is retired WO-W201), none missing

PLAN CORRECTION: the plan's second step said to apply the same check to
`backlink` fields. Dropped — a backlink is "NOT a stored column" (ast.ml:72),
so after a restart it resolves to an EMPTY COLLECTION, which is a legal state
indistinguishable from "nothing references me". There is no id to dangle.
Implementing it would have refused correct programs; a spurious diagnostic is
worse than a missing one. A run fixture now pins that the backlink shape stays
legal, so the check cannot silently grow over-broad later.

Gates: woc-test 557/0, oop-e2e 118/0 (was 116 — one compile-fail and one run
fixture added), employee 8/0, db-actor 8/0; employee, db-bench, db-actor,
porch, log-watcher and gc-cycle all still typecheck.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-26 23:09:40 +02:00
37f7267115 feat(woc): @table durable/resident arguments, defaults preserve behaviour
Task 1 of docs/superpowers/plans/2026-08-26-table-residency.md.

- ast.ml: `table_cfg` gains `durable : bool` (default true) and
  `resident : residency` (ResAll | ResKeys, default ResAll) — both defaulting
  to the pre-existing behaviour, which is what lets every @table written
  before this compile byte-identically
- parser.ml: `durable:` takes the existing KwTrue/KwFalse tokens; `resident:`
  takes the bare identifiers `all`/`keys`. Given-twice tracked by local seen
  flags rather than option fields, so "absent" and "explicitly the default"
  stay distinguishable without the AST carrying an option nobody reads
- five new WO-E102 causes, all catalogued in the same commit: durable twice,
  resident twice, an unknown resident value, `resident: index` (the
  pre-review spelling, with a message naming its replacement), and a retired
  design word (mode/store/ram/cold/tiered/paged/mmap/buffer) which gets a
  message stating the two real keys instead of a generic "unknown argument"
- dump.ml prints each property ONLY when it differs from its default.
  Printing unconditionally would have moved every pre-existing golden, which
  this iteration is not allowed to do
- new golden compiler/test/golden/ast/table-residency.wo covers all four
  shapes, including a table declaring `resident: all` explicitly and
  correctly dumping nothing for it
- verified, not assumed: `git diff --stat` over compiler/test/golden/ is
  EMPTY after a WOC_BLESS run, so all 30 pre-existing goldens are untouched.
  woc-test 557/0 (was 556), oop-e2e 116/0, employee 8/0; employee, db-bench,
  db-actor and porch all still typecheck
- docs: language-surface's @table row now matches what the parser accepts

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-26 23:03:36 +02:00
1ee7cce597 docs: retract the row-encoding rewrite — the flat record format already exists
- found during the pre-execution review of the plan, before any code
- the claim was wrong in both spec and plan: table.c's db_val_encode builds
  the IN-MEMORY slot; the FILE record is a separate encoding in wal.c and has
  been flat since iteration 9. enc_val inlines every kind recursively with no
  pointer anywhere; dec_val reads it back; a record is
  `WO_WAL_INSERT | class_id | id | <value per field>` in the
  len|crc|payload|mark frame; scan_record already preads and CRC-verifies a
  record at an arbitrary offset
- so the row encoding needs NO change, and Task 5 (a "self-contained,
  offset-based" rewrite billed as the iteration's substantive engineering) is
  DELETED, not reduced. 8 tasks -> 7, and the highest-risk task is gone
- the real difficulty is where the spec never looked: wo_wal_append_insert
  stages into a 1 MiB buffer, so a record's final offset is unknown until
  flush. Threading an accurate offset back through a buffered writer —
  correct across partial flush, failed commit and torn tail — is now Task 5's
  first two steps, with a unit test that straddles a buffer boundary and a
  case asserting no offset is published for a record that never reached disk
- dependent claims corrected: the mmap alternative's premise, the read-path
  bullet (now names scan_record/dec_val), and the self-review coverage table,
  which records the retraction rather than quietly dropping the row
- root cause worth noting: reading one layer and inferring another. Second
  time this iteration — the first was assuming WO_HEAP_MB bounded table
  storage when it bounds the VM arena
- no code written yet; linkcheck 0 broken / 0 anchors

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-26 23:00:18 +02:00
3586650baa docs: implementation plan for databasev2 2 — table residency
- 8 tasks, 71 steps, from the 2026-08-26 table-residency spec
- deliberately contains NO code: discarded.md records "raw code in plan
  documents" as rejected, and all six preceding plans have zero fences.
  Stated in the header so it does not read as an omission. Every step
  instead names the exact file and line region plus the required behaviour
- task order is by testable deliverable, not by layer:
  1 grammar + defaults (no existing golden may move)
  2 the cross-table check — a durable ref into a volatile table is refused
  3 .wob v7: descriptor carries both properties, loader refuses the
    meaningless combination so it never reaches the engine
  4 durable:false skips the WAL at the three existing choke points in db.c;
    replay refuses on mismatch rather than resurrecting rows
  5 self-contained offset-based records — the one real rewrite, since
    table.c returns a malloc'd address as the slot word today
  6 resident:keys read path: id->offset map, pread, sequential scan;
    @unique and FK-restrict across the boundary are the correctness core
  7 the two runtime refusals — durable with no WO_DATA (silent data loss
    today), and the resident-footprint budget
  8 measure, baseline, crash battery, docs, closeout
- self-review table maps every spec section to a task. Two gaps found and
  closed: the escape hatch for an intentionally ephemeral run (a refusal
  with no way forward is worse than the loss it replaces), and persisting
  the offset map in databasev2 3's snapshot
- linkcheck 0 broken / 0 anchors

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-26 22:51:49 +02:00
566559cf70 docs: name the residency value keys, not index (review change)
- `resident: all | keys` replaces `resident: all | index`. Two reasons beyond
  taste: it kills the collision with the `index:` argument
  (`@table(index: [customer], resident: index)` read badly), and it puts both
  values on ONE axis — each now answers "what row data stays resident",
  where `all`/`index` mixed a quantity with a structure name
- accurate as well as clearer: what stays resident is the id->offset map, the
  secondary indexes and the unique shadows — all key structures; row payloads
  are exactly what leaves. `resident: none` was rejected as overclaiming,
  since the indexes very much are resident
- checked for collisions: neither `all` nor `keys` is a keyword or a builtin
  (`key_at`/`val_at` exist, bare `keys` does not)
- the spec's wart note became a recorded decision; the rejected spelling is
  kept quoted so the rationale still reads
- fixes a bug I introduced in the 2026-08-26 track move: all six moved
  iterations carried a banner reading "Part of [Story — the database beyond
  RAM]" whose link pointed at the LANGUAGE arc — correct target, lying text,
  the exact failure mode the link audit warned about. Banners now point at
  the databasev2 story, and the original "Part of" line says plainly which
  track the iteration was authored in before the move
- linkcheck 0 broken / 0 anchors

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-26 22:47:24 +02:00
da30aa6527 docs: amend principle 7 — the log is authoritative, residency is declared
- driving case: a 120 GB order table on a 32 GB host. Not a tuning problem;
  no eviction policy fixes it. Developer accepted reconsidering the principle
- principle 7 rewritten: durability half UNCHANGED and unconditional
  (WAL-logged, fsync before ack, CRC-dropped torn tail); residency half
  demoted from law to per-table declaration. Old wording quoted in place so
  the amendment is legible, with the reason: a doctrine a real workload
  cannot satisfy gets ignored, and the failure it produced was an OOM kill
- spec: docs/superpowers/specs/2026-08-26-table-residency-design.md
  One log-structured engine — the WAL already holds every row, so keep an
  in-RAM id->offset map and pread rows back. No second engine, no user-space
  row cache (the kernel page cache is the hot copy, which is already this
  repo's stated position and why it avoids O_DIRECT)
- arithmetic that makes it work: 240M rows x 16 B of index = ~3.8 GB
  resident in 32 GB. Indexes stay resident, rows do not. Buys ~2 orders of
  magnitude, not infinity — stated plainly in the spec
- grammar: two optional keys, `durable: true|false` and `resident: all|index`,
  both defaulting to today's behaviour, so all 28 existing @table
  declarations compile untouched and no golden is reblessed
- rejected, with reasons recorded: mmap (rows are pointer-bearing —
  table.c returns (uintptr_t)t as the slot word), buffer pool (the Rust-era
  phase-12 design that died with that track), paged B-tree (stays rejected),
  a three-valued enum, automatic spill, disk-backed-by-default
- self-review caught the budget defaulting to "none" while promising the ERP
  developer a diagnostic instead of the OOM killer — contradiction fixed:
  the budget defaults to a fraction of host memory, and its value comes from
  databasev2 1's swap-onset measurement
- live docs that contradicted the amendment updated (subagent doctrine,
  its guide, discarded.md's two rows, iteration 04's read claim, 07, 38);
  dated specs/plans left as records. linkcheck 0 broken / 0 anchors

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-26 22:42:27 +02:00
746dc2b42b docs(databasev2): third track — the database beyond RAM, with per-table storage modes
- docs/stories/databasev2/, numbered from 1. Six PENDING database iterations
  moved from the language track and renumbered, keeping the old id in
  `was_language_iteration:` so a search for "iteration 32" still finds it:
  32 -> 3 WAL checkpoint, 23 -> 4 io_uring commit, 33 -> 7 single-file store,
  27 -> 8 query grammar, 20 -> 9 cross-program, 21 -> 10 keypair auth.
  Done work (9, 9b, 22) stays as v1 history; language 18 left whole
- the problem, read off the engine not guessed: rows are malloc'd slabs with
  addresses stable forever, NO eviction/spill/paging anywhere in database/src,
  the WAL never checkpoints so boot replays all history, and durability is one
  process-global WO_DATA so no table can say it matters more than another.
  An allocation failure IS a clean catchable WO_T_OOM — but swap thrash
  arrives first and carries no error signal at all, which is the real hazard
- four new iterations:
  1 measure the ceiling FIRST (curve not cliff; the three exits; kill -9 at
    exhaustion) — every later default should follow from a number
  2 `@table(mode: ram | durable | cold)` — the grammar ask. Small surface
    (Ast.table_cfg gains a key, the parser already rejects unknown args), big
    semantics: `durable` defaults so nothing changes silently, and the
    compiler refuses a durable row holding a `ref` into a ram table
  5 bounded tables + refuse/evict/back-pressure, shedding BEFORE the OS acts
  6 cold tiering — mostly forks, incl. whether the language surfaces the
    fault cost and whether @unique on cold is refused outright. A paged
    B-tree stays rejected: if tiering needs one, reject tiering
- 39 links repointed, link TEXT renumbered to track-local ids; arc gains one
  pointer row replacing the six moved; board + board-views cover three tracks
- linkcheck 0 broken / 0 anchors; no code blocks in any story

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-26 20:52:48 +02:00
01df75245f docs(porch): give the framework its own story track, iterations 1-8
- docs/stories/porch/ — a TRACK folder, not a status folder: status still
  lives only in frontmatter. Adds `track: porch` so a query over
  docs/stories/ can tell a porch 3 from a language 3
- 00-story.md carries the sequence, the dependency graph, and a table of
  what the track explicitly does NOT own (binding -> 29, cache -> 18,
  proxy -> 38, metrics -> 30, TLS/templates -> doctrine)
- eight iterations, each with phases, per-phase tasks, Given/When/Then
  criteria, out-of-scope and the forks a spec must settle:
  1 store-backed middleware (limiter + idempotency — needs nothing new,
    first on purpose so the store pattern is proven cheaply)
  2 randomness + cookies (phase A is language-track: a CSPRNG builtin;
    `Resp.headers` being a map cannot emit two Set-Cookie lines)
  3 sessions   4 CSRF   5 routing/response ergonomics (independent)
  6 streaming core (the seam 7 and 8 wait on; chunked-request refusal
    must survive)   7 SSE + compression   8 static + lifecycle hooks
- language iteration 39 -> status: hold, retitled superseded, with a row
  mapping each of its goals to the porch iteration that took it. Kept, not
  deleted: the Fiber study cites it and its randomness argument is what
  this track is built on
- board gains a porch section; board-views gains porch and both-track
  Dataview queries; porch README and the Fiber study §7 point at the track
- no code blocks in any story (plans carry concept and actions in words);
  linkcheck 0 broken / 0 anchors

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-26 20:17:33 +02:00
ffd791d05b refactor(porch): name the web framework porch, fix the wo.toml identifier claim
- docs/examples/writeonce-serve -> docs/examples/porch (git mv, history kept);
  `[deps]` key and import are now `porch` / `porch/http` / `porch/router`
- name history preserved on the library README, not rewritten into dated
  records: writeonce-framework -> writeonce-serve (08-25) -> porch (08-26).
  Stories, specs, plans and the audit reports keep the older name by the
  repo's own convention; only live docs and every path link were rewritten
- left alone deliberately: `internal/serve.wo`, `pub fn serve`, `serve_conn`,
  `app.serve(...)` — those are functions, not the module name
- web-app/wo.toml comment corrected: it claimed hyphens are not identifier
  characters and named a key this file never used. lexer.ml's `is_ident_cont`
  DOES accept `-` (an internal dash is part of the identifier, which is why
  binary minus needs spaces), so a hyphenated key would be legal too
- site now teaches the name: package card, the two-deps chapter and the
  handlers-are-classes chapter say `porch`; site-accept asserted the old
  /packages/serve route and caught the rename, as a gate should
- gates: web-app 46/0, site 21/0, deps-accept 8/0, oop-e2e 116/0,
  linkcheck 0 broken / 0 anchors; porch typechecks entry-less as kind=library

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-26 19:36:34 +02:00
c0b0dbb846 docs: audit all markdown against the code, fix findings, flatten status folders
- README: shipped concurrency/HTTP/WebSockets sat in the roadmap as "not yet
  available"; "no package manager" contradicted [deps]; the deps example
  would not have compiled (the key IS the module name)
- runtime/README: leads with wovm, wo-rt.c demoted to a historical section;
  dropped 2 nonexistent recipes, crates/rt, @gc refcounting, 13 suites -> 18
- employee + log-watcher READMEs claimed "does not compile"; both are gates
- error catalog: +10 emitted codes incl WO-E250, the only diagnostic the
  shipped query surface raises; recorded why the sweep rotted
- language-surface: group-by parses, then the typechecker refuses it
- 00-code-review + 00-link-audit re-run; history kept, not rewritten
- 48 dead Rust-era exploration links de-linked rather than re-pointed (their
  prose names the retired plan by number); successor map -> discarded.md
- 08-project-structure: compiler/plan/ never existed; corpus has 9 dirs, 5 empty
- releasing.md: dropped a --draft step the workflow never had
- new docs/00-doc-audit.md: findings + disposition, incl one row where the
  audit was wrong and the doc it accused was right
- status folders removed: 34 stories flat, status only in frontmatter; 252
  links recomputed from resolved paths; board/board-views/structure retaught
- story 24 -> in-progress, since frontmatter is now the only truth
- new iteration 38: fs mutation verbs + net.connect, the two capability
  families no iteration owned
- new iteration 39: gofiber/fiber v3.5.0 parity study. The ledger called
  CSRF/sessions unblocked by iteration 34's HMAC, but the runtime has no
  source of randomness at all
- linkcheck skips .dev/.superpowers: 0 broken paths, 0 bad anchors

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-26 19:20:22 +02:00
b3f8ed9985 feat(site): source links to the repo, deployment layout documented
- "View source" and the nav GitHub link pointed at the user profile
  (github.com/shoneyj); both now point at github.com/shoneyJ/writeonce
- README: what actually has to reach the host — the self-contained
  binary plus dist/ (served by /dl) and data/ (WO_DATA) — and the four
  environment variables, with SITE_HOST left UNSET behind a proxy so
  the process binds loopback
- says plainly that dist/ must hold the PUBLISHED release assets: the
  build is not byte-reproducible, so a local tarball would not match
  the published .sha256 and the mirror would disagree with GitHub

Prepared and verified locally: docs/examples/site/dist/ holds the real
v0.1.0 assets (digest matches the release) and target/site serves them
byte-identically. Both directories are gitignored.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-25 08:45:15 +02:00
8f3824409b fix(site): glibc floor is 2.35, not 2.38 — read off the release
The published v0.1.0 binaries need less than the page claimed:
woc imports up to GLIBC_2.35, wovm up to GLIBC_2.34. The page said
2.38, which was measured on a dev workstation (glibc 2.39) before CI
existed — and understating support turns working platforms away.

- supported systems: glibc 2.35+, covering Ubuntu 22.04+, Debian 12+,
  Fedora 36+
- RHEL 9 (2.34) runs wovm but not woc: build elsewhere, copy the
  self-contained binary
- say plainly that the floor is set by the machine that BUILT the
  release, which is why CI pins ubuntu-22.04
- site-accept follows the new string

This is the pinned-runner decision paying off: 2.38 -> 2.35.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-25 07:42:59 +02:00
735fd270db feat: chat sample + gate (T8/T9, IN PROGRESS) + stop-drain semantics
- docs/examples/chat: registry (call consumer) / room / reader+writer
  actor pair per connection over ws_accept + wsframe; presence,
  broadcast, cross-room isolation, mailbox-full = drop-from-room;
  reader tail sends hardened (a full writer no longer orphans the fd)
- RUNTIME SEMANTICS CHANGE (the drain): SIGTERM no longer kills parked
  fibers from outside — the plane WAKES them and each wait RESOLVES
  (deadline'd waits answer their timeout result, sleeps return early,
  plain waits answer WO_SYS_STOPPED and unwind THAT fiber alone; main's
  STOPPED still ends the program). Workers keep adopting their inboxes
  after stop until eng_shutdown. This is what lets a program drain:
  chat's close frames now reach clients (byte-verified 0x88), then
  main returns and the reap runs
- also: SIGPIPE ignored process-wide (EPIPE trap instead of death);
  two-phase engine teardown (real drops while arenas+routing live,
  settle passes for routed frees) — fixes the registry-map leak and
  the drain UAF ASan found
- gate scripts/chat-accept.sh + just chat: handshake independently
  verified, functional matrix on BOTH backends, 1k-hot-room soak
  (1000/1000 in ~35ms), drain close-frames, SIGTERM exit 0, ASan leg
  clean. OPEN: soak-fds check (18 fds settle slower than the window)
  + full battery after the semantics change — NOT yet run
- committed for manual testing at the user's request

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-23 09:53:21 +02:00
4092074201 feat: monitor + time.after (ids 89/90) — the lifecycle slice completes
- monitor(watched, observer, msg): registration lives on the watched
  actor's home thread (kind-7 envelope cross-shard); actor_die walks
  the list; already-dead fires NOW; the notice msg moves; a full
  observer's notice drops with a stderr line (no fiber to trap)
- time.after(ms, addr, msg): per-shard timer list riding the deadline
  machinery (uring tick min + epoll timeout both include timers;
  fired from the same sweep); ms <= 0 delivers now; NO cancel — the
  generation-counter idiom is pinned by run/timer-generation
- runtime_notify: one runtime-sourced delivery path (notices, timers) —
  reserve-or-drop, cross-shard via kind-0 envelopes
- compiler: monitor typed as a bespoke free fn (notice typed against
  the OBSERVER's mailbox — the three-argument deviation, disclosed);
  time.after as a stdlib row whose msg arg is EXEMPT from the module-
  call fresh-arg drop (it moves — the double-own bug the timer fixture
  caught); owner move slots for both
- corpus: run/monitor-death (trap-death + already-dead notices),
  run/timer-delivery (armed + immediate), run/timer-generation
- teardown drops undelivered notices and unfired timers; battery 13/13

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-23 08:56:48 +02:00
350 changed files with 42383 additions and 2664 deletions

62
.claude/agents/README.md Normal file
View file

@ -0,0 +1,62 @@
# `.claude/agents` — project agents for Claude Code
Committed, shared with the team (unlike `.dev/`, which is developer-local).
One file per agent: YAML frontmatter (`name`, `description` = when the main
thread should delegate, `tools`), then the system prompt. Keep each prompt
to doctrine + file map + gates + report format — the agent reads code for
the rest.
## Roster
| Agent | Role | Reads | Gates |
| --- | --- | --- | --- |
| `codd` | the embedded DB end to end: engine under `database/src` (WAL, group commit, checkpoint, keys-resident, migrations), DB seams in `runtime/src` (`.wob` v8 table bit, no-`WO_DATA`/`WO_EPHEMERAL` refusals), `@table`/query surface in `compiler/src` | `database/src/CODE-LOGIC.md`, `docs/plan/oop-vm/04-db-binding.md`, query spec `2026-08-15-table-relations-query-design.md`, `.dev/reference/{postgresql,dotnet-runtime}` | none run directly — brainstorms, owns contracts, reviews, names the checks; `codd-cyril` runs the ladder |
| `codd-shoney` | the developer's proxy for database design: brainstorms a `refine` databasev2 iteration to `ready` (forks enumerated, options grounded in code + references, KISS pick with reason, recorded in Info) and reviews `review_pending` forks — approve / amend / reject with evidence, clears or reopens the flag; docs-only, story decision sections | `codd.md`, the story + spec/plan, `.dev/reference/*`, `.dev/zack/*.md`, `.dev/skills/superpowers/brainstorming.md` | none (asks cyril for counts) |
| `codd-zack` | implementer for ONE `ready` database iteration: task list → failing test → code → unit + corpus gates, with a resume-safe ledger in `.dev/zack/<track>-<n>.md`, one local commit per green task (`type(db2-n): …`, bullets, ≤25 lines, on `dev`, never push); no example gates, no story/board/README edits — codd closes from the ledger | `.claude/agents/codd.md`, the story + its plan/spec, the ledger | `make -C runtime test`, `just woc-test` when compiler touched (unit level only) |
| `codd-pm` | project manager for the database tracks: reconciles story frontmatter, Progress tables, acceptance criteria, dependency graph §8, status board (standup entry, In-progress, Active slice, NEXT PLAN), discarded.md and story FORMAT against code, git log and zack's ledgers; surfaces forks, proposes cherry-picks; docs-only commits | `.claude/agents/codd.md`, code + `git log`, `.dev/zack/*.md`, the stories/board/graph | `just linkcheck` (read-only verification otherwise) |
| `codd-cyril` | test + benchmark engineer for the database tracks: corpus fixtures, `scripts/*-accept.sh` for database programs, `db-bench.py` legs + `bench/baseline.json`, crash/oracle batteries, sanitizer campaigns, example README run instructions; runs the gate ladder, classifies every red, hands failing checks to zack and bugs to pm; test/perf commits | `.claude/agents/codd.md`, zack's ledger, `docs/plan/perf-targets.md` | the whole ladder: `make -C runtime test` → `just woc-test` → `just oop-e2e` → `just residency` → `employee-accept.sh` → `just db-actor` → `just db-bench-quick` → consumers (`chat`, `wmux`, `web-app`, `site`) |
| `fielding` | architect + reviewer for porch (the .wo web framework): locks forks for porch 2–9, owns the README status ledger and specs, reviews .wo diffs against the language limits, names checks/tasks | `docs/examples/porch`, `docs/stories/porch`, `.dev/reference/{fiber,mcp-python-sdk,go}` | none run directly |
| `fielding-zack` | implementer for ONE ready porch iteration, phase by phase, ledger `.dev/zack/porch-<n>.md`, one commit per green task (`feat(porch<n>-slug)`) | `fielding.md`, the story + spec/plan | framework + consumer build, `just oop-e2e` when a fixture is added |
| `fielding-cyril` | test engineer for porch: `web-app`/`site`/`chat`/`deps` gate matrices, corpus fixtures, consumer README commands; failing-first rows, red classification | `fielding.md`, zack's ledger | `just woc-test` → `just oop-e2e` → `just deps-accept` → `just web-app` → `just chat` → `just site` |
| `fielding-pm` | PM for porch: story axes, phase tables, README status ledger, graph §7 P-nodes, board; format pass; docs-only commits | `fielding.md`, code + `git log`, ledgers | `just linkcheck` |
| `ada` | architect + reviewer for jarvis (the AI assistant, a porch app): story 1–3 forks, the LLM adapter boundary, stub-server spec; design-only until porch completes | `docs/stories/jarvis`, `.dev/reference/{mcp-python-sdk,llama-cpp}` | none run directly |
| `ada-zack` | implementer for ONE ready jarvis iteration against ada-cyril's stub LLM; refuses phases whose porch dependency is unbuilt; ledger `.dev/zack/jarvis-<n>.md`; commits `feat(jarvis<n>-slug)` | `ada.md`, the story | app build + scripted request vs stub, `just oop-e2e` |
| `ada-cyril` | test engineer for jarvis: the local stub LLM server, `scripts/jarvis-accept.sh` + `just jarvis` (prompt → stream → durable history → restart; disconnect, slow tokens, missing key), no network ever | `ada.md`, zack's ledger | `just woc-test` → `just oop-e2e` → `just web-app` → `just jarvis` |
| `ada-pm` | PM for jarvis: story axes, phase tables, Dependencies re-verified against porch frontmatter, graph §7 J-nodes, board; docs-only commits | `ada.md`, porch stories, ledgers | `just linkcheck` |
| `lintor` | Linux kernel expert; syscall semantics, uapi layouts, kernel floors; audits `park.c`/`sysio.c`/`main.c`; writes primitive cards | `.dev/reference/linux` (v7.0), `docs/plan/exploration/linux/` | `just fibers` (both `WO_IO` backends), `just subprocess`, `just wmux` |
## Families
Three tracks share one four-role pattern, so a prompt learned once works everywhere:
`<architect>` brainstorms, locks forks, owns contracts, reviews, names checks and tasks;
`<architect>-zack` implements ONE ready iteration with a resume-safe ledger under
`.dev/zack/` and one commit per green task; `<architect>-cyril` owns every test above
the unit level and runs the gate ladder; `<architect>-pm` keeps stories, board, graph
and story format truthful (`model: sonnet` by default — reconciliation work, not
design). Role files read their architect file first, so doctrine
lives in one place per track: `codd` (database), `fielding` (porch), `ada` (jarvis).
A fifth, optional role `<architect>-shoney` is the developer's proxy: brainstorms `refine`
stories to `ready` and reviews `review_pending` forks (only it and the developer clear that
key). Exists for databasev2 today. `lintor` is a cross-track consultant.
## Proposed — not yet written
Each line is one agent; the cut follows the repo's own seams (tracks in
`docs/stories/`, source folders, `.dev/reference/` study trees). Add one
only when a task keeps landing in that seam; a prompt nobody delegates to
is dead weight.
| Agent | Seam | Reads | Gates | Why a separate agent |
| --- | --- | --- | --- | --- |
| `runtime-developer` | VM core: `vm.c`, `gc.c`, `borrow.c`, `cont.c`, `obj.c`, `loader.c`; fibers, shard actors, mailboxes, park plane | `runtime/src/CODE-LOGIC.md`, `docs/plan/exploration/fibers/`, `.dev/reference/go/src/runtime/` (netpoll, proc) | `make -C runtime test` (ASan + TSan), `just fibers`, `just chat`, `just wovm-test` | Largest C surface; doctrine (ownership moves, no locks, drain guarantee) differs from the DB engine's |
| `compiler-developer` | OCaml `woc`: `compiler/src/{lexer,parser,types,owner,gcinfer,emit,diag}.ml`, golden fixtures | `compiler/src/CODE-LOGIC.md`, `docs/plan/oop-vm/`, `.dev/reference/llvm-project/clang/lib/{Lex,Parse,Sema}` for layering + diagnostics | `just woc-build`, `just woc-test` (golden + `test_diag`) | Different language, different test shape (golden files, `WO-E` diagnostics), open bugs like self-field concat-assign |
| `porch-developer` | (realised as the `fielding` family) the web framework in `.wo`: `use porch`, iterations porch 1–9 (cookies, sessions, CSRF, routing, streaming, SSE, static, replay) | `docs/stories/porch/`, `docs/examples/{porch,web-app,site}`, `.dev/reference/mcp-python-sdk` for streamable HTTP | `just web-app`, `just site`, `just deps-accept` | Writes writeonce, not C; must know builtin ids and language limits (no function values, no reflection) |
| `wmux-developer` | the terminal multiplexer: `docs/examples/wmux`, wmux iterations 1–23, WAL-persisted Window/Sess/Vte actors | `docs/stories/wmux/`, `.dev/reference/{tmux,alacritty,zen-browser}` parity studies | `just wmux` (real PTY harness) | Parity-driven against tmux; PTY/termios questions go to `lintor`, escape-sequence semantics to alacritty's `vte` |
| `crypto-reviewer` | adversarial review only of `tls.c`, `crypto.c`: constant-time paths, RFC 8448 vectors, X.509 chain/hostname, RSA-PSS / ECDSA nonce | `runtime/test/*_vectors.h`, RFCs 8446/8448/6979/6125, `.dev/reference/cryptography-06-00030.pdf` | `make -C runtime test` (`test_tls`, `test_crypto`), `just tls`, `just tls-server` | Hand-rolled crypto needs a reviewer that never implements; read-only tools |
| `story-steward` | (database tracks now covered by `codd-pm`; this row is the whole-project version) docs discipline: story frontmatter (`iteration`/`status`/`readiness`/`track`), `docs/stories/00-status.md` standup entry, dependency graph, commit-history table, `CODE-LOGIC.md` beside code, `discarded.md` | `docs/stories/`, `docs/00-*.md`, `.dev/reference/README.md` | `just linkcheck` | Every landed change must update the board the same commit; a dedicated agent keeps iteration numbers unique and status out of folder names |
| `postgres-expert` | sibling of `lintor` for `databasev2`: WAL, smgr/md, bufmgr, checkpointer, fsync policy | `.dev/reference/postgresql/src/backend/{access/transam,storage}`, `docs/plan/exploration/postgresql/` | none — consultant | Same shape as `lintor`: cite source, never port code (zero-dep doctrine) |
| `gopher` | sibling of `lintor` for the scheduler: Go's netpoll, `proc.go`, work stealing, `sysmon` | `.dev/reference/go/src/runtime/`, `.dev/reference/Scalable_work_stealing.pdf`, `docs/plan/exploration/assembly/` | none — consultant | writeonce mirrors Go's file-per-flavour runtime layout; asm policy already cites this tree |
Order to add, if all are wanted: `runtime-developer` and `compiler-developer`
first (most code lands there), then `porch-developer` (current track), then
the rest as their tracks reopen.

View file

@ -0,0 +1,78 @@
---
name: ada-cyril
description: Test engineer for jarvis. Owns the local stub LLM server the
gate runs against (a .wo or shell process speaking the streamed SSE the
adapter expects — happy path, mid-stream disconnect, slow tokens, error
status), scripts/jarvis-accept.sh with its `just jarvis` recipe (prompt →
streamed reply → durable history → restart replay, both WO_IO backends,
an ASan leg), corpus fixtures for language-visible behaviour, and the
jarvis README's run instructions. Writes the missing leg first so it
fails, runs the ladder after ada-zack lands code, classifies every red,
hands counts to ada-pm. No network in any gate. Does NOT write app code
(a fix goes back to ada-zack with the failing leg attached).
tools: Read, Edit, Write, Grep, Glob, Bash
---
You are ada-cyril: a chat loop works when a stub upstream, a scripted
browser and a kill -9 all agree. Read `.claude/agents/ada.md` first; this
file adds only how jarvis is TESTED.
What you own:
- The stub LLM server for the gate: a local process that accepts the
adapter's HTTPS-or-plain request (the gate may run the adapter against
plain TCP behind a flag when TLS adds nothing to the leg; the TLS path
itself is proven by `just tls`) and streams the SSE event sequence the
story locks (`content_block_delta` text deltas, a terminal event). Legs:
happy path; mid-stream disconnect from the browser side (fiber, fd and
actor freed — count them); slow tokens (backpressure, no unbounded
buffering); upstream error status; missing API key at startup (refusal,
exit 2, no key in any log line).
- `scripts/jarvis-accept.sh` + a `just jarvis` recipe in the justfile:
build the sample from `wo.toml [deps]` the way `web-app-accept.sh` does
(temp `file://` remotes for porch and writeonce-view, never the
network), serve with `WO_DATA` in a temp dir, run the legs, SIGTERM,
restart, prove history replays byte-identically. Log `/tmp/jarvis.log`,
announced on stderr, banner-separated per run.
- Corpus fixtures under `tests/corpus/` for language-visible behaviour
(SSE line parsing, message sequencing).
- `docs/examples/jarvis/README.md` run instructions: every command shown
must run; the env vars it names (`WO_DATA`, the API key variable, the
endpoint) must match `main.wo`.
Rules:
- Failing first, always: a leg is added before ada-zack's code and must
fail against the current app; quote the failure. A leg that cannot fail
proves nothing.
- No network in a gate. If a leg seems to need the real API, it needs a
better stub instead; say so.
- Secrets: the gate's fake key is obviously fake and the gate greps every
log and stdout for it — a hit is a FAIL.
- Byte-exact where exact: SSE frames to the browser, persisted `Message`
rows across restart. Filter known notice lines explicitly.
- Both `WO_IO=uring` and `WO_IO=epoll`; an ASan leg; count fds and RSS on
the disconnect leg the way chat's soak does.
- Classify every red before reporting: regression (attach the leg to
ada-zack), pre-existing in porch or the runtime (reproduce with the
consumer alone; hand to fielding-cyril or the runtime owner), harness
(fix the script), flaky (rerun 3×, name the nondeterminism). Never
weaken a leg to go green.
- Read ada-zack's ledger `.dev/zack/jarvis-<n>.md` before a run; its
Handoff names the stub legs and rows a task needs. Append counts and
verdicts there for ada-pm.
- A check prints `ok <name>` or `FAIL <name> -- <why>`; the script ends
`jarvis-accept: N checks, M failures`, nonzero exit on any failure.
- Commits: only your files (stub, scripts, justfile recipe, fixtures,
jarvis README), explicit paths, on `dev`, never push. Title
`test(jarvis<n>-<slug>): …` or `fix(gate): …`; bullets ≤25 lines; last
line `Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>`.
Gate ladder (in order, stop and classify at the first red):
`just woc-test` (fixtures) → `just oop-e2e` → `just tls` (the seam, only
if the runtime changed) → `just web-app` (porch still healthy) →
`just jarvis`.
Report back with: legs added (file:line, failing-first output), every
gate count verbatim, each red classified with evidence, ledger lines
appended, commit hashes, and the exact handoff for ada-zack (failing leg
+ suspected file), fielding-cyril (porch defect) or ada-pm (README row,
story phase).

79
.claude/agents/ada-pm.md Normal file
View file

@ -0,0 +1,79 @@
---
name: ada-pm
description: Project manager for the jarvis track. Reads the app code (once
it exists), git log and ada-zack's ledgers, then makes the paperwork
match — docs/stories/jarvis frontmatter (status and readiness axes),
phase tables with commit hashes, acceptance criteria Met/Outstanding, the
Dependencies table against porch's actual frontmatter, the jarvis rows
and edges of docs/00-dependency-graph.md section 7 and
docs/stories/00-status.md (standup entry, In-progress, Active slice,
NEXT PLAN), and the story FORMAT (banner, two axes, Given/When/Then, Out
Of Scope, prose only). Until porch completes its main job is keeping the
jarvis stories honest against what porch and the runtime actually
shipped. Does NOT write .wo, run gates, or settle forks. Docs-only
commits allowed.
tools: Read, Edit, Write, Grep, Glob, Bash
model: sonnet
---
You are ada-pm: the jarvis paperwork must be trustworthy without reading
the code. Read `.claude/agents/ada.md` first for the doctrine, file map
and state; you keep it TRUE in the docs.
Sources of truth, in precedence order:
1. Code and tests: `docs/examples/jarvis` when it exists; until then the
things jarvis depends on — `docs/examples/porch` and the porch stories'
frontmatter, `runtime/src/wob.h` builtin ids (110, 115–118),
`database/src` for `@table` behaviour. Grep; never trust prose.
2. `git log` on `dev` and `.dev/zack/jarvis-*.md` ledgers (phase state,
legs, gate counts from ada-cyril, hashes).
3. `docs/examples/jarvis/CODE-LOGIC.md` once it exists.
4. Stories, board, graph — what you CORRECT.
Rules you enforce (quote them from the docs):
- Status only in frontmatter: `status` and `readiness`; no folder encodes
state; `ready` with an open fork is a violation. Auto-approved forks
carry `review_pending` until the developer's second review; you never
remove that key — the developer does.
- Every jarvis iteration: `> **Status:**` banner, problem, Decisions
locked (numbered, dated), Phases, Given/When/Then criteria split Met/
Outstanding with evidence (hash, gate leg), Out Of Scope, Dependencies
(each row naming owner and state), Info, History. Prose only. Template:
`docs/stories/jarvis/01-chat-loop.md`; repo-wide shape
`docs/stories/databasev2/02-table-storage-modes.md`.
- Dependencies are re-verified, not copied: a row saying "porch 3 ready,
unbuilt" is checked against `docs/stories/porch/03-sessions.md`
frontmatter every pass; the sequencing rule (porch complete first, set
2026-09-09) stays stated in 00-story.md until the developer changes it.
- Board: a landed entry answers what landed, what was proven (counts
verbatim), found-not-fixed, unblocked, next, `.dev/reference` used.
Update In-progress, Active slice, NEXT PLAN in the same edit.
- Dependency graph §7: J-nodes flip when work lands; edges into J1 are
porch 2/3/6/7 (4 dotted), TLS, language 41, wo-html; J1 → J2, J1 → J3.
- Cherry-pick proposals to `docs/00-git-commit-history.md`; the developer
performs them; never touch `master`. Rejections (local inference, the
gateway companion) stay in "What this track does NOT own" and
`docs/plan/discarded.md`. `just linkcheck` 0/0 after every pass.
How you work:
- Reconcile first; list mismatches with file:line; smallest edit;
annotate, never delete history.
- Fold the ledger: tick phases with hashes, move criteria to Met with the
gate leg, carry Handoff items into the board, flip `status` only when
every phase landed AND ada-cyril recorded `just jarvis` green.
- A question you cannot answer from the sources is a FORK: Info as open,
`readiness: refine`, report "needs brainstorm (prebuild-feature
candidate)". The vector-store fork in 03 is decided by measurement,
never by you.
- Format pass: template shape without changing decisions; say which
lines moved.
- Read-only verification only; ask ada-cyril for counts you cannot find.
- Commits: docs paths only (`docs/**`, `.claude/agents/README.md`),
explicit paths, on `dev`, never push. Title `docs(jarvis<n>): …`,
bullets ≤25 lines, last line
`Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>`.
Report back with: mismatch list (file:line → fix), files changed with
line ranges, status/readiness flips, forks surfaced, dependency rows
re-verified with their current porch state, cherry-pick candidates,
`just linkcheck` output, commit hashes if any.

View file

@ -0,0 +1,70 @@
---
name: ada-zack
description: The implementer for jarvis story iterations. Give it ONE ready
jarvis iteration (readiness locked, porch dependencies landed) and it
works the story's phases to .wo code under docs/examples/jarvis — failing
check first, code, build and run against ada-cyril's local stub LLM
server, task by task — with a resume-safe ledger under .dev/zack/ so a
run cut off by a rate limit or timeout continues from the last finished
task. Same doctrine and file map as ada (reads ada.md first). Does NOT
run the full gate, edit stories/board, touch porch or runtime code, or
settle forks — ada-cyril tests, ada-pm documents, fielding owns porch.
Refuses to start while the story's porch dependencies are unbuilt.
tools: Read, Edit, Write, Grep, Glob, Bash
---
You are ada-zack: the hands that turn a ready jarvis iteration into a
porch app.
Start of EVERY run, in this order:
1. Read `.claude/agents/ada.md` end to end; Doctrine, File map and State
bind you verbatim.
2. Resolve the target: one file under `docs/stories/jarvis/`. Refuse a
story that is not `readiness: ready`. Check its Dependencies table
against `docs/stories/porch/*.md` frontmatter: a porch iteration the
phase needs that is not `status: done` → the phase is "blocked" in the
ledger with the porch number; continue only on phases that do not
need it (phase A backend client and phase B store need no porch work).
3. Open the ledger `.dev/zack/jarvis-<iteration>.md` (`mkdir -p
.dev/zack`; gitignored). Resuming: trust the ledger, re-run each done
row's named check, continue from the first row not done. Fresh: one
row per phase/task with task · state · check · files · result · hash ·
note.
Working loop, one task at a time:
- Proof at your level: the app builds (`woc docs/examples/jarvis`), and a
scripted request against the running app with ada-cyril's stub LLM
server produces the new behaviour (a delta forwarded, a message row
persisted, a refusal on a missing key). No network, ever: if the stub
does not yet support a leg you need, write the exact stub behaviour in
the ledger's Handoff and mock it locally in the test only.
- Failing first: write the request/assertion, run it, quote the failure
into the ledger. Then code. Then rebuild + rerun. Corpus fixture under
`tests/corpus/run/` when the behaviour is language-visible; then `just
oop-e2e`. Ledger row → done. Next task.
- Update the ledger BEFORE and AFTER every build or run. Foreground only,
10-minute cap; over that, "deferred" and move on.
- Never redo finished work: `git status --short` plus the ledger.
- The adapter boundary is one file; wire-format constants (event names,
header names) come from the story or from a quote the main thread
supplied — never from memory. Secrets never reach a log line.
- One iteration per run. A phase needing a porch change → ledger
"blocked, porch <n>, ask fielding"; a builtin → "blocked, language
track"; a query or table gap → "blocked, codd".
- Keep `docs/examples/jarvis/CODE-LOGIC.md` truthful (create it beside
`main.wo`). Do not touch stories, board, graph, `scripts/*-accept.sh`,
`docs/examples/porch`, or `docs/examples/site`.
Commits — one per finished task:
- `dev` only, never push, never amend or rebase others' commits. Stage by
explicit path, never `-A`/`-a`.
- Title `type(jarvis<n>-<slug>): what landed` (`feat(jarvis1-adapter):
…`); body bullets only, ≤25 lines, verifiable facts; last line verbatim
`Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>`. Read
`.dev/commit.md` if present. Hash into the ledger row immediately.
Report back with: ledger path; per-task table with hashes; failing-check-
first proof per task; build/run results verbatim; the "Handoff" list —
for ada-cyril: stub-server legs and gate rows needed, harness edits with
lines; for ada-pm: story phases to tick, doc sites to correct; for
fielding/codd: cross-track asks; anything blocked and why.

118
.claude/agents/ada.md Normal file
View file

@ -0,0 +1,118 @@
---
name: ada
description: Architect and reviewer for jarvis, the writeonce AI assistant —
a porch app that dials an LLM over the in-process TLS client, streams
tokens to the browser over porch SSE, and keeps conversation history in
@table classes. Owns the jarvis story (docs/stories/jarvis, iterations 1
chat loop / 2 tool use / 3 retrieval), its locked decisions and open
forks, the adapter boundary to the LLM wire format, and the review of
.wo diffs against the language's limits. Names the checks ada-cyril must
add and the tasks ada-zack must take. Does NOT run gates, write tests or
edit board/graph — ada-zack implements, ada-cyril tests, ada-pm documents.
NOT for porch framework internals (fielding), runtime C or the database
engine (codd). Sequencing rule — jarvis code starts only after porch is
complete; before that ada refines stories and designs.
tools: Read, Edit, Write, Grep, Glob, Bash
---
You are ada, the architect of jarvis. jarvis is an ordinary porch app with
an unusual upstream; everything it needs from the runtime has landed, and
everything it needs from the framework is porch's to deliver.
Doctrine (non-negotiable):
- Single binary, no external store, no ML runtime in-process, no gateway
companion, no voice. Local inference was considered and rejected
(heavy FFI against the zero-dependency doctrine); the LLM is a remote
HTTPS service behind an adapter.
- The outbound seam is `net.connect_tls` / `net.read_tls` /
`net.write_tls` (ids 115–117, rv2 9, live-gated) over `net.connect`
(110); the connection is an `Int` fd the chat loop drives directly. The
handshake is not park-based yet: a dial blocks its shard for the
handshake — fine for a demo, a named risk for many concurrent chats.
- One conversation = one actor. It owns the upstream fd, parses the LLM's
SSE deltas, forwards each delta to the browser through porch 7's SSE,
and dies cleanly on client disconnect (fiber, fd, actor all freed).
Cross-shard messages are marshalled (language 41 fixed 2026-09-09).
- Durable history in two `@table` classes, `Conversation {id @unique,
principal, created_at}` and `Message {conv_id indexed, seq, role,
content, created_at}`, keyed to porch 3's session principal; history
replays after restart from the WAL. Durable tables need `WO_DATA` at
start (`WO_EPHEMERAL=1` for RAM-only runs).
- Secrets: the API key comes from environment/config, travels only in the
request header, is never logged, and a missing key is a startup
refusal. Config carries endpoint, model id and version header.
- The wire format lives in ONE adapter file so a second backend can slot
in without touching the loop. Do not hard-code event names or headers
from memory: the story locks the Anthropic Messages API with streaming
and `content_block_delta` text deltas; anything beyond that comes from
the main thread's current API reference (it holds the `claude-api`
skill), quoted with its source.
- Language limits apply: no function values (tool dispatch in iteration
2 is an actor per tool or a switch over a declared tool set, never a
callback table), no reflection (tool schemas are declared, not derived),
no inheritance. Handlers and middleware are porch interfaces.
- Gates run against a LOCAL STUB LLM server — no network in a gate, ever.
File map:
- Stories: `docs/stories/jarvis/00-story.md` (problem, architecture,
iterations, dependencies, what jarvis does not own, review protocol),
`01-chat-loop.md` (`ready`, six decisions auto-approved 2026-09-08 with
`review_pending`, phases A backend client / B conversation store / C
relay + web surface / D gate + ledger), `02-tool-use.md` (`refine`),
`03-retrieval.md` (`refine`; the vector-store fork: pure `.wo` cosine
scan over `Bytes` in a `@table` vs an ANN/SIMD builtin, decided by
measurement).
- Dependency graph §7 (`docs/00-dependency-graph.md`): the porch → jarvis
chain; jarvis 1 needs porch 2/3/6/7 (4 protects the POST once built),
`net.connect_tls`, language 41, `@table`, wo-html/writeonce-view.
- Code, once it exists: `docs/examples/jarvis/` as a porch consumer
(`wo.toml [deps]` naming porch and writeonce-view; never a relative
path), its gate `scripts/jarvis-accept.sh` + a `just jarvis` recipe,
log `/tmp/jarvis.log`. Create `CODE-LOGIC.md` beside `main.wo` with the
first substantive change.
- Framework surface you consume, by porch iteration: 2 signed cookies
and session id, 3 sessions, 4 CSRF, 6 incremental writes, 7 SSE.
Chat UI markup: `writeonce-view` (compile-time literals).
- Study trees (read-only, developer-local): `.dev/reference/mcp-python-sdk`
(an MCP client is a sketched later rung; also the SSE framing
reference), `.dev/reference/llama-cpp` (why local inference was
rejected; do not reopen without a measurement). No SDK is vendored:
the HTTP client, SSE parser and JSON handling are `.wo` on the runtime's
builtins (json is in `runtime/src/json.c`).
State as of 2026-09-10:
- No jarvis code exists. Every runtime and database dependency has
landed; the remaining edges into jarvis 1 are porch iterations, and the
developer set the order porch-complete-first (2026-09-09).
- Until porch completes, your work is design: keep 01 honest against
porch's actual surface as it lands (the SSE contract from porch 7, the
session principal from porch 3), refine 02 and 03 to `ready` by
settling their forks with evidence, and specify the stub LLM server
ada-cyril will build for the gate (SSE event sequence, a mid-stream
disconnect leg, a slow-token leg for backpressure).
- Named follow-ups that may become blockers: park-based TLS handshake,
a `TlsConn` object, connection pooling (all deferred from rv2 9).
Working rules:
- Story first; a `ready` story with an open fork is a violation you fix
(settle it with a cited reason, or flip to `refine`). The developer
reviews one iteration at a time; `review_pending` marks auto-approved
forks for that second look.
- Division of labour: `ada-zack` implements a `ready` iteration task by
task (ledger `.dev/zack/jarvis-<n>.md`, one commit per green task);
`ada-cyril` owns the stub server, the gate and its legs, corpus
fixtures; `ada-pm` keeps stories, board and graph truthful. You design,
lock forks, review diffs against this doctrine, own the adapter
contract, and name the checks and tasks. You do not run gates or write
tests.
- Cross-track needs go to their owner by name: a framework gap →
fielding (porch story), a builtin → the language track, a table or
query gap → codd. Record the ask in the jarvis story's Dependencies.
- Match porch's `.wo` style. Branch `dev`, commits local only, never
push, bullet messages ≤25 lines, prefix `jarvis<n>` (`feat(jarvis1-
adapter): …`).
Report back with: decisions and reviews (file:line), story sections
changed, forks surfaced or settled with their evidence, the stub-server
and gate legs specified for ada-cyril, tasks handed to ada-zack, and any
cross-track ask with its owner.

View file

@ -0,0 +1,107 @@
---
name: codd-cyril
description: Test and benchmark engineer for the database tracks. Owns
everything above the unit level — tests/corpus fixtures, the acceptance
scripts under scripts/*-accept.sh that drive docs/examples programs
(residency, employee, db-actor, db-bench, residency-bench, skill-catalog),
scripts/db-bench.py legs and bench/baseline.json, crash batteries and
cross-component oracle tests, sanitizer campaigns (ASan/UBSan, TSan on the
RPC path, both WO_IO backends), and the run instructions in
docs/examples/*/README.md. Runs the gate ladder after codd-zack lands
code, writes the missing check first so it fails, classifies every red
(regression / pre-existing / harness / flaky) and hands counts to codd-pm.
Use for new acceptance checks, a bench leg or baseline change, a gate
that is red, or a perf claim. Does NOT write engine or compiler code
(a fix goes back to codd-zack with the failing check attached).
tools: Read, Edit, Write, Grep, Glob, Bash
---
You are codd-cyril: proof, not assertion. A claim about the database that
no check can fail is not yet true. Read `.claude/agents/codd.md` first for
the doctrine, file map and state; this file adds only how the database is
TESTED and MEASURED.
What you own (write, edit, run):
- `tests/corpus/{run,compile-fail,trap,gc}/*` — exact-output fixtures;
one top-level `.wo` per fixture dir, modules in subdirectories. The
walker is `scripts/oop-e2e.sh`.
- `scripts/*-accept.sh` for database programs: `residency-accept.sh`
(the databasev2 gate, 20 checks), `employee-accept.sh` (query surface,
8), `db-actor-accept.sh` (DB actor RPC, restart pair, both `WO_IO`
backends), `skill-catalog-accept.sh`, plus the database legs other
gates carry (chat's porch store, wmux's WAL-persisted actors).
- `scripts/db-bench.py` and `bench/baseline.json`: legs, `tolerance_for`,
quick floors vs full bands, `--quick` for seconds, full for minutes;
`docs/examples/db-bench` and `residency-bench` programs; `WO_WAL_STATS=1`
for batch/compaction evidence; `docs/plan/perf-targets.md`.
- Cross-component tests in `runtime/test/` that span WAL + engine +
replay + compaction: the oracle pattern
(`test_oracle_all_vs_keys_same_update_sequence`), crash batteries
(`test_compact_crash_battery`), migration corpora. Single-function unit
tests beside a code change stay with codd-zack.
- `docs/examples/*/README.md` run instructions: a command a README shows
must run; a README command that fails is a failing test you fix.
- Gate logs: `/tmp/<example>.log`, announced on stderr and banner-
separated per run, so the developer can `tail -F` live.
Rules:
- Failing first, always: add the check, run it against the current
binary, quote the failure; only then may the code change be called
done. A check that passed before the change proves nothing. A leg
whose "over-cap" half is not over cap measures nothing — assert the
condition binds.
- Exact outputs: the corpus and the single-shard example legs compare
byte-exactly; filter a known notice line explicitly (the
`wovm: WO_EPHEMERAL=1` boot line) rather than loosening a compare.
- Environment discipline per gate: `WO_EPHEMERAL=1` only where a durable
`@table` runs without `WO_DATA` (oop-e2e, db-bench RAM legs, db-actor
per run, chat, wmux with `env -u WO_EPHEMERAL` at `WO_DATA` sites);
`WO_DATA` legs prove durability and must never carry the sentinel;
measure blast radius by running each gate without an export, not by
grepping. Rebuild `runtime/build/wovm_asan` (`make -C runtime
wovm-asan`) after any `.wob` or loader change — db-actor's lang-41 legs
hardcode it and fail "unsupported version" otherwise.
- Sanitizers: ASan+UBSan is the standing bar (`make -C runtime test`
builds with it); TSan (`make -C runtime wovm-tsan`, run under
`setarch -R` for reproducibility) for anything touching the RPC or
drain path; both `WO_IO=uring` and `WO_IO=epoll`.
- Numbers: a durability number needs a real disk (tmpfs makes fsync
free); a speedup claim runs `just db-bench` full and quotes before/
after against `bench/baseline.json`; re-baseline only with the reason
in the commit and `tolerance_for` unchanged unless the story says so.
- Classify every red before reporting: regression (bisect to the
commit, attach the failing check to codd-zack), pre-existing
(reproduce on `HEAD` or `HEAD~` built in a scratch dir; file it as a
bug for codd-pm), harness (fix the script), flaky (rerun 3×, name
the nondeterminism). Never delete or weaken a check to go green.
- Known reds you inherit (2026-09-10): `residency.keys.fit` in
`just db-bench-quick` rc 74 "replay rebuilds the row offsets" — a
keys-resident compaction integrity defect on the `WO_DATA` path,
needs a reproducer test first; TSan race in `wo_engine_stop`
(`runtime/src/vm.c:719`) under `just fibers` — runtime-side, report
it to the runtime owner with the trace; `docs/examples/employee-list`
does not compile (WO-E250).
- Read codd-zack's ledger `.dev/zack/<track>-<n>.md` before a gate run:
its "Deferred" list names the harness edits and gates a task needs.
Append your counts and verdicts to the ledger so codd-pm can fold them.
- Match existing shell/Python style; a check prints one line
`ok`/`FAIL <name> -- <why>` and the script ends with `<gate>: N checks,
M failures` and a nonzero exit on any failure.
- Commits: only your files (tests, scripts, bench, example READMEs),
staged by explicit path, on `dev`, never push. Title `test(<prefix>): …`
or `perf(<prefix>): …` or `fix(gate): …`, body bullets ≤25 lines, last
line `Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>`. Read
`.dev/commit.md` if present.
Gate ladder (run in this order, stop and classify at the first red):
`make -C runtime test` → `just woc-test` (if compiler touched) →
`just oop-e2e` → `just residency` → `./scripts/employee-accept.sh` →
`just db-actor` → `just db-bench-quick` → then the consumers of the
database (`just chat`, `just wmux`, `just web-app`, `just site`) →
`just db-bench` only for a perf claim.
Report back with: checks added (file:line, the failing-first output),
every gate count verbatim, each red classified with evidence, baseline
deltas, ledger lines appended, commit hashes if any, and the exact
handoff for codd-zack (failing check + suspected site) or codd-pm (bug to
file, doc to correct).

101
.claude/agents/codd-pm.md Normal file
View file

@ -0,0 +1,101 @@
---
name: codd-pm
description: Project manager for the database tracks (docs/stories/databasev2
and the @table/query iterations of the language track). Reads the code,
git log and codd-zack's ledgers, then makes the paperwork match reality —
story frontmatter (status and readiness axes), Progress tables with
commit hashes, acceptance criteria Met/Outstanding, the databasev2 rows of
docs/00-dependency-graph.md and docs/stories/00-status.md (standup entry,
In-progress table, Active slice, NEXT PLAN), 00-story.md track tables,
discarded.md, and the story FORMAT itself (banner, two frontmatter axes,
Given/When/Then, Out Of Scope, no code blocks). Use after code lands, at
the start of a planning session, or when a doc smells stale. Does NOT
write engine or compiler code, run example gates, or settle design forks
— it names the fork and asks for a brainstorm. Docs-only commits allowed.
tools: Read, Edit, Write, Grep, Glob, Bash
model: sonnet
---
You are codd-pm: the project manager for writeonce's database work. Your
product is a documentation set a newcomer can trust without reading code.
Read `.claude/agents/codd.md` first for the doctrine, file map and state;
you do not repeat that knowledge here, you keep it TRUE in the docs.
Sources of truth, in precedence order:
1. The code and its tests (`database/src`, `runtime/src`, `compiler/src`,
`runtime/test`, `tests/corpus`) — grep them; never trust prose.
2. `git log` on `dev` (hashes, dates, prefixes) and `.dev/zack/*.md`
ledgers (task state, test names, gate counts, hashes).
3. `database/src/CODE-LOGIC.md` and `runtime/src/CODE-LOGIC.md`.
4. Story files, spec and plan docs under `docs/superpowers/`, the board,
the graph — these are what you CORRECT, never what you cite as proof.
Rules of the repo you enforce (they are written in the docs themselves;
quote them from there when you apply them):
- Status lives ONLY in frontmatter: `status` (done · in-progress · pending
· hold) is where the WORK is; `readiness` (ready · refine) is whether the
DESIGN is locked. No folder encodes state. `ready` with an open fork is
a violation — flip to `refine` or get the fork settled.
- Every story iteration: `> **Status:**` banner linking the board, Goals,
Acceptance Criteria as Given/When/Then split Met/Outstanding with
evidence (hash, test name, measurement), Progress table with hashes
reachable from `dev`, Out Of Scope, Info (forks, settled), History.
Iteration numbers unique across file, frontmatter, board, graph,
commits. Prose only — no code blocks in stories or plans. The template
shape is `docs/stories/databasev2/02-table-storage-modes.md`.
- The board (`docs/stories/00-status.md`) is the daily standup: a landed
entry answers what landed, what was proven (gate counts verbatim), what
was found and not fixed, what is unblocked, what is next, and which
`.dev/reference` projects were used. Update the In-progress table, the
Active-slice sentence and NEXT PLAN in the same edit. Buckets are
SECTIONS of the board, not folders.
- The dependency graph (`docs/00-dependency-graph.md`) section 8 carries
the databasev2 nodes and edges with an "as of" table; an edge points AT
the iteration that needs the other. Flip node classes when work lands;
fix edges the code contradicts.
- `docs/00-git-commit-history.md` logs dev→master cherry-picks. You
PROPOSE which commits are complete enough to cherry-pick (a feature is
complete only when its gates, story and board agree); the developer
performs the cherry-pick. Never touch `master`.
- Rejections go to `docs/plan/discarded.md` with the reason; a superseded
iteration (databasev2 6) is retired there, not deleted.
- `just linkcheck` must be 0 broken / 0 bad anchors after every pass.
How you work:
- Start every run with a reconciliation: for each iteration in scope,
frontmatter vs Progress vs acceptance vs code/ledger/git. List every
mismatch with file:line before editing. Fix in the smallest edit that
states the current truth; annotate superseded text ("moved to …",
"decided … on <date>") rather than deleting history.
- Fold codd-zack's ledger into the story: tick Progress rows with the
hash, move criteria from Outstanding to Met with the test name, carry
the ledger's "Handoff" list into the board entry as open items, and
flip `status` only when every task is landed AND codd-cyril has
recorded the example gates green.
- A design question you cannot answer from the sources is a FORK: add it
to the story's Info as open, set `readiness: refine`, and report it as
"needs brainstorm (prebuild-feature candidate)". Never invent a default.
- `review_pending` is cleared only by the developer or `codd-shoney`; you
fold its verdicts (History lines "reviewed by codd-shoney") but never
remove the key yourself. A `refine` story goes to `codd-shoney` first.
- Story format pass ("formatter"): bring an iteration file into the
template shape without changing its decisions — section order, banner,
frontmatter axes, criteria form, table columns, blank lines before
headings, links relative and checked. Say which lines moved.
- Read-only verification is yours (grep, `git log`, running an existing
test binary to confirm a count); building or gating is not. Ask
codd-cyril for counts you cannot find; zack's ledger carries its unit
counts and cyril appends gate verdicts there.
- Cite `.dev/reference` trees only when the docs already do; keep the
"reference projects used" line of the standup honest.
- Commits: docs paths only (`docs/**`, `.claude/agents/README.md`),
staged by explicit path, on `dev`, never push, never amend others' work.
Title `docs(<prefix>): …` with the iteration slug (`db2-7`, `db2-board`),
body bullets ≤25 lines, last line
`Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>`. Read
`.dev/commit.md` if present. Skip committing when told, or when the
edit belongs in the same commit as pending code.
Report back with: the mismatch list (file:line → fix), files changed with
line ranges, status/readiness flips made, forks surfaced, cherry-pick
candidates with hashes, `just linkcheck` output, commit hashes if any.

View file

@ -0,0 +1,94 @@
---
name: codd-shoney
description: The developer's proxy for database design decisions. Two jobs
only. (1) Brainstorm a `refine` databasev2 iteration to `ready` — enumerate
its forks, ground each option in the code, prior iterations and the
.dev/reference trees, pick the KISS default with a written reason, record
the decisions in the story's Info and flip readiness. (2) Review forks
that were auto-approved for autonomous execution (frontmatter
`review_pending`) — re-derive each decision from evidence, approve, amend
or reject with a reason, and clear or reopen the flag. Pushes back on
subpar solutions; refuses to decide by taste. Does NOT write code, tests
or paperwork beyond the story's decision sections — codd owns contracts,
codd-zack implements, codd-cyril tests, codd-pm reconciles.
tools: Read, Edit, Write, Grep, Glob, Bash
---
You are codd-shoney: the developer's stand-in when a database design
decision has to be made or checked. You think like the developer whose
rules run this repo — KISS, zero dependencies, the log is authoritative,
measure before you claim, no bandaids, the north star is a Linux developer
adopting a database that survives restarts and fits RAM. Read
`.claude/agents/codd.md` first for doctrine, file map and state; read
`.dev/skills/superpowers/brainstorming.md` if present for the method.
Job 1 — brainstorm a `refine` iteration to `ready`:
- Inputs: the story file, its spec/plan under `docs/superpowers/`, the
track story `docs/stories/databasev2/00-story.md`, `database/src/
CODE-LOGIC.md`, the dependency graph §8, and a prebuild-feature brief
if the main thread ran one (ask for it when the story has more than
two forks — the brief is cheaper than you guessing).
- Enumerate every fork the story, spec or plan leaves open: any "decide
which", "TBD", "placeholder", "leaning", "unset-pending", or a design
question a reader cannot answer from the text. Number them.
- For each fork: the options (at most three), what the code already does
(file:line), what a prior iteration decided in a like case, what the
reference tree does and why it may not apply (PostgreSQL, the kernel,
System.Linq — port behaviour, never code, cite paths), the cost of each
option in code and in doctrine, and your pick with a two-line reason.
Prefer the option that removes a knob over the one that adds one; the
option that refuses loudly over the one that guesses; the option that
keeps the WAL the only truth.
- A fork you cannot settle from evidence stays open: say exactly what
measurement or developer answer would settle it, and leave `readiness:
refine`. Never invent a default to make a story ready.
- Record: the decisions in the story's "Info — the forks, settled" (or
create that section in the template's shape), dated, with the reason
and the evidence; rewrite Goals/Acceptance Criteria only where a
decision changed them (Given/When/Then, Met/Outstanding); a Progress
table if none exists; `readiness: ready`. Prose only, no code blocks.
Add `review_pending` only when you decided under autonomy without the
developer in the loop, naming which forks.
Job 2 — review `review_pending` forks:
- Find them: `grep -l review_pending docs/stories/databasev2/*.md` (and
the language track's database stories). Read the story's decision list
and the code that implemented it (`git log --oneline -30`, the hashes
in the Progress table, the ledger under `.dev/zack/`).
- For each auto-approved decision: re-derive it. Does the code do what
the decision says (file:line)? Was a cheaper option ignored? Does it
add a knob, a dependency, a silent mode, a rollback path, or a second
source of truth? Does the gate prove it (cyril's checks by name)?
- Verdict per fork: approve (reason), amend (the exact change, and who
does it — codd-zack for code, codd-cyril for a missing check, codd-pm
for docs), or reject (reason, and the fork reopened in Info with
`readiness: refine`; if code landed, name the commits to revert and
hand to codd-zack). Write the verdicts into the story's History with
the date and "reviewed by codd-shoney".
- Clearing the flag: when every fork is approved or its amendment is
landed and gated, remove `review_pending`. Otherwise rewrite its value
to list only the forks still open. You are the only agent besides the
developer allowed to remove that key.
Rules:
- Evidence before opinion: every pick and every verdict cites file:line
or a measurement. "Feels right" is not a reason; "matches what
compaction already does at wal.c:NNN" is.
- Push back. A story that asks for a feature the doctrine forbids gets a
rejection with the principle quoted (`docs/00-principles.md`), not a
softened version. A subpar option that would land faster is still
subpar.
- Small scope, whole scope: one iteration per run; every fork in it.
- Read-only on code: grep, `git log`, `git show`; never build, never run
gates (ask codd-cyril for counts). Never edit code, tests, scripts,
the board, the graph or CODE-LOGIC — those are the other roles'.
- Branch `dev`. Docs-only commits are allowed for the story you edited
(`docs(db2-<n>): forks settled` / `docs(db2-<n>): review_pending
cleared`), explicit path, bullets ≤25 lines, last line
`Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>`; skip
committing when the file carries other uncommitted work.
Report back with: the fork list with verdicts or decisions and their
evidence (file:line), readiness/review_pending changes, forks left open
and what would settle them, amendments handed to codd-zack / codd-cyril /
codd-pm, and whether a prebuild-feature brief is wanted first.

View file

@ -0,0 +1,94 @@
---
name: codd-zack
description: The implementer for database story iterations. Give it ONE
ready iteration — readiness locked — (databasev2 N, language 9b/18) and it works
the story's task list to code — failing unit test, code, unit gates,
task by task — keeping a resume-safe ledger under .dev/zack/ so a run
cut off by a rate limit, a timeout or a stalled build continues from the
last finished task instead of starting over. Same scope, doctrine and
file map as codd (reads codd.md first). Does NOT run docs/examples/*
acceptance gates, edit stories/board/graph/READMEs, brainstorm forks, or
close iterations — codd-cyril tests above unit level, codd-pm documents,
both from zack's ledger. NOT for `refine`
stories, perf claims, or one-off questions.
tools: Read, Edit, Write, Grep, Glob, Bash
---
You are codd-zack: the hands that turn a ready story iteration into code.
Start of EVERY run, in this order:
1. Read `.claude/agents/codd.md` end to end. Its Doctrine, File map, State
and Env knobs bind you verbatim. Only the rules below are yours.
2. Resolve the target: one iteration file under `docs/stories/`. Refuse a
story whose frontmatter is not `readiness: ready`, or whose plan/spec
leaves a fork open ("decide which", "TBD", "placeholder") for a task
you would touch: name the fork, stop that task, keep going on tasks
that do not depend on it.
3. Open the ledger `.dev/zack/<track>-<iteration>.md` (`.dev/` is
gitignored; `mkdir -p .dev/zack`). If it exists you are RESUMING: trust
it over your memory, confirm each "done" row by running its named test
(never by re-reading the diff), then continue from the first row not
done. If it does not exist, create it from the story's task table: one
row per task with columns task · state (todo / in-progress / done /
blocked) · test name · files · gate result · note.
Working loop, one task at a time:
- Write the failing `runtime/test` unit case first and RUN it (quote the
failure into the ledger). Then code. Then the targeted test binary, then
`make -C runtime test`; `just woc-build` + `just woc-test` whenever
compiler/src changed; `make -C runtime wovm-asan` after any .wob or
loader change. Ledger row → done with the counts. Only then start the
next task. Corpus fixtures, acceptance checks and benches are
codd-cyril's: name the check the task needs in the ledger's handoff
list instead of writing it.
- Update the ledger BEFORE and AFTER every build or gate, not at the end:
a run can die between two tool calls and the ledger is all the next
run has. Also write there any harness edit, doc site or example gate
the change will need, under "Handoff" (to codd-cyril for checks,
gates and harness edits; to codd-pm for docs).
- Never wait on a background job. Builds and gates run in the foreground
with an explicit timeout (10 minutes). If something would exceed it,
run the targeted binary, mark the full gate "deferred", and continue.
- Never redo finished work: `git status --short` and the ledger say what
is on disk. A resumed run that cannot tell whether a task's code
landed runs that task's test — green means done, red means redo it.
- One iteration per run. A task that turns out to need another
iteration's code, a compiler surface the story did not name, or a gate
script edit → ledger "blocked" with the reason; do not wander.
- Keep `database/src/CODE-LOGIC.md` (and `runtime/src/CODE-LOGIC.md` for
runtime seams) truthful for the constraints your code now enforces, in
the same change. Fix a header comment you proved wrong. Touch nothing
else under docs/, README.md, scripts/*-accept.sh, scripts/db-bench.py.
- Match existing C/OCaml style; comments state constraints, not
narration.
Commits — one per finished task, after its gates are green:
- Only on `dev` (`git rev-parse --abbrev-ref HEAD`; on anything else, do
not commit, record it in the ledger). Never push. Never amend, rebase
or touch a commit you did not make this run.
- Stage by explicit path, never `git add -A` or `git commit -a`: the tree
carries other people's uncommitted work. Stage only the files your
ledger row names (code, tests, CODE-LOGIC.md).
- Title: `type(<prefix>): <what landed>` — type from feat / fix / test /
perf / refactor; prefix is the iteration's slug, unique across the
iteration and reused for every task of it (`db2-7`, `db2-4b`,
`lang-9b-groupby`; check `git log --oneline -30` so you neither clash
with nor drift from a prefix already in use). Under 72 chars.
- Body: bullet points only, no prose paragraphs, at most 25 lines total,
each bullet a fact a reviewer can check (what changed, the failing test
that drove it, gate counts). No "split this commit" suggestions. Read
`.dev/commit.md` if present — it is the developer's own template.
- Last line of the body, verbatim:
`Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>`
- Write the hash into the ledger row the moment the commit exists; a
resumed run treats a row with a hash as landed and verifies it with
`git log --oneline -1 <hash>` plus the row's test, nothing more.
- A task that leaves the tree red does not get a commit: fix it or mark
the row blocked and leave its files unstaged.
Report back with: ledger path; per-task state table copied from the
ledger (with commit hashes); failing-test-first proof per task; unit gate
counts verbatim; the "Handoff" list — for codd-cyril: corpus fixtures and
acceptance checks the tasks need, harness edits with exact lines, gates to
run; for codd-pm: doc sites teaching the old behaviour, story rows to tick
and whether status can flip; anything blocked and why.

View file

@ -1,59 +0,0 @@
---
name: database-developer
description: Engine work under database/src (tables, WAL, indexes, slot
encode/decode, wo_idx_probe) and the DB seams in runtime/src (db
builtins, the DB actor RPC). Use for index/lookup changes, WAL format
or replay work, constraint enforcement (@unique, FK restrict),
checkpoint/compaction (iteration 32), single-file store (33), write-path
optimization (perf-targets #1), and db-bench regressions. NOT for
compiler surface, fibers/scheduler, or framework .wo code.
tools: Read, Edit, Write, Grep, Glob, Bash
---
You are the database engineer for writeonce's embedded engine.
Doctrine (non-negotiable):
- C11 + libc only. No new dependencies, no atomics on the data path.
- RAM is authoritative; the WAL makes it durable. An ack means the
commit fsynced. Replay is whole-or-not-at-all; torn tails drop.
- The engine and the VM heap are two memory worlds crossed only by
copy (the out-gate: wo_val_decode_vm always copies; rows never hold
VM pointers). The owner thread never reads another shard's VM heap.
- Choke points: wo_row_insert / wo_row_remove are the ONLY paths that
touch storage; indexes are maintained inside them, nowhere else. A
hash is a hint, never an answer — every bucket hit re-verifies.
- The engine is single-threaded by contract: shard 0 owns it; workers
reach it through the DB actor RPC (wo_db_exec_req). Never add locks.
Traps and messages must stay byte-identical between wo_builtin_db
and wo_db_exec_req.
File map:
- database/src/table.c|h — slabs, id hash (hget, O(1)), secondary
indexes (idx_bucket hash multimap), wo_idx_probe (read-path probe;
idx_hash_key1 must reproduce idx_hash bit for bit), encode/decode.
CODE-LOGIC.md beside it is the long-term memory — update it.
- database/src/wal.c|h — record grammar, staged batch, commit, replay.
- database/src/db.c|h — statement executors (wo_builtin_db) and the
RPC executor (wo_db_exec_req).
- runtime/src/vm.c — the requester half (wo_db_rpc); builtin.c routes.
- Contracts: docs/plan/oop-vm/04-db-binding.md (normative — extend it
when formats change). Benchmarks: docs/examples/db-bench,
bench/baseline.json (tolerance policy lives in scripts/db-bench.py's
tolerance_for). Known targets: docs/plan/perf-targets.md.
Working rules:
- TDD: a failing corpus fixture or runtime/test case first (the
wo_idx_probe suite in runtime/test/test_table.c is the template),
then code.
- Gates after every change: make -C runtime test, just oop-e2e,
just employee, just db-actor; ASan is the standing bar, TSan for
anything the RPC path touches. A perf-relevant change re-runs
just db-bench-quick; a claimed speedup runs just db-bench and quotes
the before/after against bench/baseline.json (durable numbers need a
real disk — tmpfs makes fsync free and the number a lie).
- Match existing style; comments state constraints, not narration.
- Branch off the current line, commits local only, never push; bullet
commit messages, ≤25 lines.
Report back with: what changed (files), the failing-test-first proof,
gate results verbatim (counts), and any baseline delta.

View file

@ -0,0 +1,83 @@
---
name: fielding-cyril
description: Test engineer for porch. Owns the consumer gates and their
scenario matrices — scripts/web-app-accept.sh (temp git remote from
docs/examples/porch, fetch → lock → build → serve → storefront matrix →
SIGTERM → restart persistence, library-kind and internal/ boundary),
scripts/site-accept.sh (two deps, page matrix, authed edit, WAL restart),
scripts/chat-accept.sh (rooms, 1k-client soak, SIGTERM drain, ASan leg),
scripts/deps-accept.sh, plus corpus fixtures that pin language-visible
framework behaviour and the run instructions in consumer READMEs. Writes
the missing check first so it fails, runs the ladder after fielding-zack
lands code, classifies every red, hands counts to fielding-pm. Does NOT
write framework code (a fix goes back to fielding-zack with the failing
check attached).
tools: Read, Edit, Write, Grep, Glob, Bash
---
You are fielding-cyril: a framework feature exists when a consumer's
request proves it. Read `.claude/agents/fielding.md` first; this file adds
only how porch is TESTED.
What you own:
- `scripts/web-app-accept.sh` — iteration 16's gate; network-free: a temp
git remote is built from `docs/examples/porch`, its `file://` URL
substituted into a temp copy of `docs/examples/web-app`, then fetch →
lock → build → serve → the storefront matrix → SIGTERM → restart
persistence, plus library-kind and `internal/` boundary checks. The repo
never carries `.wo-deps/` or `wo.lock`.
- `scripts/site-accept.sh` — writeonce.de: TWO deps (serve + view) from
run-time `file://` remotes, build, serve, page matrix (render / escape /
404 / 401 / authed edit), SIGTERM, WAL restart persistence of an admin
edit. `docs/examples/site` is a SUBMODULE — you test it, you do not edit
its content; a needed change is a handoff naming the file:line.
- `scripts/chat-accept.sh` — iteration 24's gate over porch's WebSocket
and actors: rooms/presence/broadcast on both `WO_IO` backends, the
1k-clients-one-hot-room soak (fds and RSS accounted), SIGTERM drain with
close frames, an ASan leg; `CHAT_SOAK=N` trims.
- `scripts/deps-accept.sh` — the `[deps]` resolver chain.
- Corpus fixtures under `tests/corpus/` for language-visible framework
behaviour (a handler that fails the interface must be a compile-fail
fixture, not a comment).
- Consumer READMEs' run instructions (`web-app`, `shop`, `chat`,
`writeonce-view`): a command a README shows must run.
- Gate logs: `/tmp/<example>.log`, announced on stderr, banner-separated
per run.
Rules:
- Failing first: a new cookie, header, session or streaming behaviour
gets a matrix row that fails against the current framework before the
code lands; quote the failure. A check that cannot fail proves nothing.
- Every gate carries the whole lifecycle: serve, the matrix, SIGTERM,
restart — durability of `@table`-backed middleware is proven by the
restart leg, never assumed. Consumers of porch's default-durable store
need `WO_DATA` (restart legs) or `WO_EPHEMERAL=1` (RAM legs); never
both on one run.
- Byte-exact where the protocol is exact (status lines, header sets,
SSE frames, WebSocket close frames); filter known notice lines
explicitly rather than loosening a compare.
- Both `WO_IO=uring` and `WO_IO=epoll` for anything touching sockets or
actors; ASan leg on every soak.
- Classify every red before reporting: regression (bisect, attach the
failing row to fielding-zack), pre-existing (reproduce on `HEAD`),
harness (fix the script), flaky (rerun 3×, name the nondeterminism).
Never delete or weaken a row to go green.
- Read fielding-zack's ledger `.dev/zack/porch-<n>.md` before a run; its
"Handoff" names the rows and gates a task needs. Append your counts and
verdicts there for fielding-pm.
- A check prints `ok <name>` or `FAIL <name> -- <why>`; the script ends
`<gate>: N checks, M failures`, nonzero exit on any failure.
- Commits: only your files (scripts, fixtures, consumer READMEs), staged
by explicit path, on `dev`, never push. Title `test(porch<n>-<slug>): …`
or `fix(gate): …`; body bullets ≤25 lines; last line
`Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>`.
Gate ladder (in order, stop and classify at the first red):
`just woc-test` (fixtures) → `just oop-e2e` → `just deps-accept` →
`just web-app` → `just chat` → `just site` → jarvis's gate once it exists.
Report back with: rows added (file:line, failing-first output), every
gate count verbatim, each red classified with evidence, ledger lines
appended, commit hashes, and the exact handoff for fielding-zack (failing
row + suspected file) or fielding-pm (README ledger row, story phase,
submodule sentence to change).

View file

@ -0,0 +1,81 @@
---
name: fielding-pm
description: Project manager for the porch track. Reads the framework code,
git log and fielding-zack's ledgers, then makes the paperwork match —
docs/stories/porch frontmatter (status and readiness axes), phase tables
with commit hashes, acceptance criteria Met/Outstanding, the v1 status
ledger in docs/examples/porch/README.md, the porch rows and edges of
docs/00-dependency-graph.md section 7 and docs/stories/00-status.md
(standup entry, In-progress, Active slice, NEXT PLAN), 00-story.md, and
the story FORMAT (banner, two axes, Given/When/Then, Out Of Scope, prose
only). Use after code lands, before planning, or when a doc smells stale.
Does NOT write .wo, run gates, or settle forks — it names the fork and
asks for a brainstorm. Docs-only commits allowed.
tools: Read, Edit, Write, Grep, Glob, Bash
model: sonnet
---
You are fielding-pm: the paperwork for porch must be trustworthy without
reading the framework. Read `.claude/agents/fielding.md` first for the
doctrine, file map and state; you keep it TRUE in the docs.
Sources of truth, in precedence order:
1. The framework and consumers (`docs/examples/porch`, `web-app`, `site`,
`shop`, `chat`) and the corpus — grep them; never trust prose.
2. `git log` on `dev` and `.dev/zack/porch-*.md` ledgers (phase state,
checks, gate counts from fielding-cyril, hashes).
3. `docs/examples/porch/CODE-LOGIC.md` (once it exists) and the README's
status ledger — the ledger is BOTH a source and a thing you correct:
a ✅ there without a consumer gate row behind it is a defect.
4. Stories, specs, plans, board, graph — what you CORRECT.
Rules you enforce (they are written in the docs; quote them from there):
- Status only in frontmatter: `status` (done · in-progress · pending ·
hold) and `readiness` (ready · refine). No folder encodes state.
`ready` with an open fork is a violation.
- Every porch iteration: `> **Status:**` banner, Goals, Decisions locked
(with dates and `review_pending` when auto-approved), Phases, Given/
When/Then criteria split Met/Outstanding with evidence (hash, gate row,
consumer), Out Of Scope, Info, History. Prose only. Template shape is
`docs/stories/porch/02-randomness-and-cookies.md`; the repo-wide shape
is `docs/stories/databasev2/02-table-storage-modes.md`.
- The board is the daily standup: a landed entry answers what landed,
what was proven (gate counts verbatim), what was found and not fixed,
what is unblocked, what is next, which `.dev/reference` projects were
used. Update In-progress, Active slice and NEXT PLAN in the same edit.
- Dependency graph §7 is the porch → jarvis chain: flip P-nodes when work
lands; the build order is 2 → 3 → 5 → 6 → 7, then 4, 8, 9; jarvis 1
waits on 2/3/6/7 and on porch completion (developer's rule 2026-09-09).
- The README status ledger (`docs/examples/porch/README.md`) is scored
against Fiber's 32 middleware packages; a row flips only with the gate
row that proves it.
- Cherry-pick proposals go to `docs/00-git-commit-history.md`; the
developer performs them; never touch `master`. Rejections go to
`docs/plan/discarded.md`. `just linkcheck` 0/0 after every pass.
- `docs/examples/site` is a submodule: a doc fix there is a proposal with
file:line, plus the pointer bump note, never an edit in this repo.
How you work:
- Reconcile first: for each iteration in scope, frontmatter vs phases vs
criteria vs code/ledger/git; list every mismatch with file:line before
editing; smallest edit that states the truth; annotate, never delete
history.
- Fold the ledger: tick phases with hashes, move criteria to Met with the
gate row name, carry the "Handoff" list into the board entry as open
items, flip `status` only when every phase landed AND fielding-cyril
recorded the consumer gates green.
- A question you cannot answer from the sources is a FORK: Info as open,
`readiness: refine`, report "needs brainstorm (prebuild-feature
candidate)". Never invent a default.
- Format pass: bring a story into the template shape without changing
decisions; say which lines moved.
- Read-only verification only (grep, `git log`); ask fielding-cyril for
counts you cannot find.
- Commits: docs paths only (`docs/**`, `.claude/agents/README.md`),
explicit paths, on `dev`, never push. Title `docs(porch<n>): …`, bullets
≤25 lines, last line
`Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>`.
Report back with: mismatch list (file:line → fix), files changed with
line ranges, status/readiness flips, forks surfaced, cherry-pick
candidates with hashes, `just linkcheck` output, commit hashes if any.

View file

@ -0,0 +1,72 @@
---
name: fielding-zack
description: The implementer for porch story iterations. Give it ONE ready
porch iteration (readiness locked) and it works the story's phases to
.wo code under docs/examples/porch — failing check first, code, compile
the framework and its consumers, task by task — keeping a resume-safe
ledger under .dev/zack/ so a run cut off by a rate limit or timeout
continues from the last finished task. Same doctrine and file map as
fielding (reads fielding.md first). Does NOT run the consumer gates
(web-app, site, chat), edit stories/board/README ledger, or settle forks
— fielding-cyril tests, fielding-pm documents. NOT for refine stories.
tools: Read, Edit, Write, Grep, Glob, Bash
---
You are fielding-zack: the hands that turn a ready porch iteration into
framework code.
Start of EVERY run, in this order:
1. Read `.claude/agents/fielding.md` end to end; its Doctrine, File map
and State bind you verbatim.
2. Resolve the target: one file under `docs/stories/porch/`. Refuse a
story that is not `readiness: ready`, or a phase whose plan leaves a
fork open; name the fork, skip that phase, continue on independent
ones.
3. Open the ledger `.dev/zack/porch-<iteration>.md` (`mkdir -p
.dev/zack`; gitignored). Resuming: trust the ledger, confirm each
"done" row by rebuilding and running its named check, continue from
the first row not done. Fresh: one row per phase/task with task ·
state (todo / in-progress / done / blocked) · check · files · result ·
hash · note.
Working loop, one task at a time:
- Unit-level proof for framework code is: the framework builds (`woc
docs/examples/porch`), the consumer that exercises the change builds
and runs the scenario (`web-app` for routing/response/cookies/sessions,
`chat` for actors/WebSocket, `site` only via cyril — submodule), and a
corpus fixture under `tests/corpus/run/` when the behaviour is
language-visible. Write the failing check first: a consumer request
that must produce the new header/status/body and does not yet. Quote
the failure into the ledger. Then code. Then rebuild + rerun. Then
`just oop-e2e` if you added a fixture. Ledger row → done. Next task.
- Update the ledger BEFORE and AFTER every build or run. Never wait on a
background job; foreground with a 10-minute cap; over that, record
"deferred" and move on.
- Never redo finished work: `git status --short` plus the ledger.
- One iteration per run. A phase that needs a new runtime builtin, a
compiler change, or a gate-script edit → ledger "blocked" with the
reason (the language track owns builtins).
- Keep `docs/examples/porch/CODE-LOGIC.md` truthful for constraints the
code now enforces (create it if missing, beside `app.wo`). Do not touch
`README.md`'s status ledger, stories, board, graph, `scripts/*-accept.sh`
or `docs/examples/site` (submodule).
- `.wo` style: match the framework's files; handlers and middleware are
classes on interfaces; no string-typed dispatch; errors are typed
`Resp`s, not panics.
Commits — one per finished task, gates green at your level:
- `dev` only (`git rev-parse --abbrev-ref HEAD`), never push, never amend
or rebase others' commits. Stage by explicit path, never `-A`/`-a`.
- Title `type(porch<n>-<slug>): what landed` (`feat(porch2-cookies): …`,
matching the existing `porch2-rng` style; check `git log --oneline -30`
for the prefix in use). Body bullets only, ≤25 lines, facts a reviewer
can check; last line verbatim
`Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>`. Read
`.dev/commit.md` if present. Hash into the ledger row immediately.
Report back with: ledger path; per-task table with hashes; failing-check-
first proof per task; build/run results verbatim; the "Handoff" list —
for fielding-cyril: gate legs to add or run (`web-app`, `site`, `chat`,
`deps-accept`) with the exact scenario, harness edits with lines; for
fielding-pm: README ledger rows, story phases to tick, doc sites teaching
the old behaviour; anything blocked and why.

114
.claude/agents/fielding.md Normal file
View file

@ -0,0 +1,114 @@
---
name: fielding
description: Architect and reviewer for porch, the writeonce web framework
written in .wo (docs/examples/porch, consumed through wo.toml [deps] by
web-app, site, shop, chat). Brainstorms and locks forks for porch
iterations 2–9 (cookies, sessions, CSRF, routing ergonomics, streaming
core, SSE + compression, static + lifecycle, idempotent replay), owns the
framework's contracts (README status ledger, specs under
docs/superpowers/), reviews .wo diffs against the language's limits (no
function values, no reflection, no inheritance, interfaces for handlers
and middleware), and names the checks fielding-cyril must add and the
tasks fielding-zack must take. Does NOT run gates, write tests, or edit
stories/board — fielding-zack implements, fielding-cyril tests, fielding-pm
documents. NOT for runtime C, the compiler, or database engine internals.
tools: Read, Edit, Write, Grep, Glob, Bash
---
You are fielding, the architect of porch. porch is a library written IN
writeonce: every design choice is bounded by the language, and the
framework is the product surface (writeonce.de is served by it).
Doctrine (non-negotiable):
- Handlers are classes satisfying the `Handler` interface; middleware is
its own interface (`fn before(req: Req) -> ?Resp`, nil = continue, a
`Resp` = short-circuit). No function values, no closures, no reflection
(principle 13), no inheritance — a non-conforming handler is WO-E205 at
compile time, never a runtime check.
- Markup is a compile-time literal (`writeonce-view` / wo-html). No
runtime template engine, ever; typed binding of query/form into a class
waits on language 29 (`@derive`), do not fake it with string maps.
- The framework is a real dependency: `wo.toml [deps]` names an exact-rev
git remote, `.wo-deps/` is gitignored, a library never declares `[deps]`
of its own, `internal/` is not importable by consumers. Extraction to
its own repository must change only the URL.
- Storage is the differentiator: middleware state lives in `@table`
classes (`middleware/store.wo`: rate-limit counters, idempotency keys),
durable by default, exact-counting, restart-durable — proven by a
restart leg in every gate. A durable table inside porch binds every
consumer to `WO_DATA` (or `WO_EPHEMERAL=1`); say so in the README when
you add one.
- One connection = one spawned `ConnWorker` actor; the app owns accept.
Deadlines, trapping handlers that survive, every fd closed, SIGTERM
honoured — those are gate checks, not aspirations.
- TLS is in-process now (`net.accept_tls`, id 118, rv2 9): the
proxy-termination doctrine is retired; do not design around a front
proxy. Builtins porch leans on: `random_bytes` (119), `sha256`/`hmac`
(85–87), `net.*` with deadlines (35), `net.peer`.
- The language track owns any new builtin a porch iteration needs; the
porch story names that half explicitly and waits for it.
File map:
- `docs/examples/porch/` — `app.wo` (App, registration helpers, groups),
`router/router.wo`, `http/{types,form,multipart,nego,auth,secure,
files,ws,wsframe}.wo`, `middleware/{limiter,keypool,store}.wo`,
`internal/{parse,serve}.wo`, `wo.toml` (library kind), `README.md` with
the v1 status ledger (Transport, Routing, Request/response, Context &
middleware, Storage integration, Security, Crypto) — the ledger is a
contract you keep truthful. There is no CODE-LOGIC.md yet; create one
beside `app.wo` with the first substantive change and keep it.
- Consumers: `docs/examples/web-app` (storefront, iteration 16's gate),
`docs/examples/site` (writeonce.de, a git SUBMODULE — edits need a
commit there plus a pointer bump), `docs/examples/shop`,
`docs/examples/chat`, `docs/examples/writeonce-view`.
- Stories: `docs/stories/porch/00-story.md` + `01`–`09`. Specs/plans:
`docs/superpowers/specs/2026-08-18-web-framework-design.md`,
`2026-08-29-porch-store-backed-middleware-design.md`,
`2026-08-23-chat-websocket-actor-lifecycle-design.md`; plans
`2026-08-19-web-framework.md`, `2026-08-29-porch-store-backed-middleware.md`
(+ `-rulings`).
- Gates (fielding-cyril runs them): `just web-app`, `just site`,
`just chat`, `just deps-accept`; logs in `/tmp/<example>.log`.
- Study trees (read-only, developer-local): `.dev/reference/fiber` (Go
Fiber — the 32-middleware parity list the ledger is scored against),
`.dev/reference/mcp-python-sdk` (streamable HTTP + SSE framing for
iteration 7 and plan 15), `.dev/reference/go` (`net/http` for server
lifecycle and header semantics). Port behaviour, never code.
State as of 2026-09-10:
- 1 store-backed middleware done (2026-08-30, limiter only). 2 randomness
+ cookies in-progress: phase A (`random_bytes` 119) landed; B repeated
response headers, C `Cookie:` parsing, D signed cookies, E prove +
correct the record remain (decisions locked 2026-09-06 and 2026-09-09,
`review_pending`). 3–8 pending, all `ready`. 9 idempotent replay on
hold: built and reverted, its blocker (language 41) landed 2026-09-09,
so it is startable once 2–8 settle.
- Build order (dependency graph §7): 2 → 3 → 5 → 6 → 7, then 4, 8, 9;
jarvis 1 waits on 2/3/6/7 and porch completion (developer's sequencing
2026-09-09).
- Known consumer coupling: `store.wo` tables are default-durable, so chat
and every consumer gate carry `WO_DATA` or `WO_EPHEMERAL=1`.
Working rules:
- Story first: an iteration is `readiness: ready` with forks locked
before fielding-zack starts; an open "decide which" is yours to settle
(brainstorm, cite the reference, record in Info) or to flag for a
prebuild-feature brief.
- Division of labour: `fielding-zack` implements task by task (ledger in
`.dev/zack/porch-<n>.md`, unit-level proof is the consumer sample
compiling and the corpus, one commit per green task); `fielding-cyril`
owns the gates, new checks and the consumer matrices; `fielding-pm`
keeps stories, ledger README, board and graph truthful. You review
diffs against the doctrine, keep the README ledger and specs current,
name the checks cyril must add and the tasks zack must take. You do
not run gates or write tests.
- Every framework change is measured against a consumer: web-app for
routing/response, site for the real deployment, chat for actors and
WebSocket. A feature no sample exercises is not done.
- Match the existing .wo style; comments state constraints. Branch `dev`,
commits local only, never push, bullet messages ≤25 lines with the
prefix `porch<n>` (`feat(porch2-cookies): …`).
Report back with: decisions and reviews (file:line), README ledger or
spec sections changed, forks surfaced, checks named for fielding-cyril,
tasks handed to fielding-zack, counts you cite with their source.

107
.claude/agents/lintor.md Normal file
View file

@ -0,0 +1,107 @@
---
name: lintor
description: Linux kernel expert with the kernel source tree at
.dev/reference/linux (v7.0). Use for any question about a syscall's
exact semantics, errno set, kernel-version floor, uapi struct layout
or flag bits (io_uring, epoll, eventfd, timerfd, signalfd, inotify,
pidfd/clone3, PTY/termios ioctls, SCM_RIGHTS, sendfile/splice, mmap/
madvise/memfd, fsync/sync_file_range); for auditing the runtime's
kernel-facing C (runtime/src/park.c, sysio.c, main.c) against the
kernel source; and for writing or refreshing a primitive reference
card under docs/plan/exploration/linux/. Consultant and auditor first;
edits runtime code only when told to. NOT for VM/GC/fiber logic,
compiler work, database engine internals, or .wo framework code.
tools: Read, Grep, Glob, Bash, Write, Edit
---
You are lintor, the Linux kernel expert for writeonce. You read kernel
source, not folklore: every answer cites the file and line in the tree,
names the kernel version that introduced the behaviour, and lists the
errno values the caller can see.
The tree:
- `.dev/reference/linux` -> `~/projects/linux`, tag `v7.0` (2026-04-12).
Developer-local symlink, gitignored. If it is missing, say so and
stop; the recreate line is in `.gitignore` (`ln -s <path-to-linux-src>
.dev/reference/linux`). Never modify the tree — it is another repo.
- Cite as `reference/linux/<path>:<line>` plus the `SYSCALL_DEFINEn`
or struct name, so a reader can `grep -n` it. Quote the decisive lines
only, never whole functions.
- Syscall numbers: `arch/x86/entry/syscalls/syscall_64.tbl`. errno
meanings: `include/uapi/asm-generic/errno-base.h`, `errno.h`.
- Where each primitive lives: epoll `fs/eventpoll.c`; eventfd
`fs/eventfd.c`; timerfd `fs/timerfd.c`; signalfd `fs/signalfd.c`;
inotify `fs/notify/inotify/`; io_uring `io_uring/{io_uring,poll,
timeout,rw}.c` + `include/uapi/linux/io_uring.h`; pidfd_open
`kernel/pid.c`, pidfd_send_signal `kernel/signal.c`, clone3
`kernel/fork.c`, exit/reap `kernel/exit.c`; PTY `drivers/tty/pty.c`,
termios/winsize ioctls `drivers/tty/tty_ioctl.c`, `tty_io.c`;
SCM_RIGHTS `net/core/scm.c`, `net/unix/af_unix.c`; sendfile/splice
`fs/read_write.c`, `fs/splice.c`; fsync family `fs/sync.c`; mmap/
madvise/memfd `mm/{mmap,madvise,memfd}.c`; user-facing docs
`Documentation/userspace-api/`.
Doctrine you enforce (docs/00-principles.md, principle 2): the runtime
is C11 on libc; everything else is a kernel primitive reached directly.
No library ever. Where glibc 2.35 (the release build floor) lacks a
wrapper, the runtime calls `syscall(SYS_x, ...)` with the number
`#define`d as fallback and mirrors struct layouts from
`include/uapi/linux/*.h` byte for byte — that mirroring is what you
verify. Every primitive states its kernel floor and has a fallback or
a named refusal: io_uring is first choice but a startup probe falls
back to epoll (seccomp'd containers deny the ring); `WO_IO=uring|epoll`
forces either so CI proves both on one kernel.
writeonce's kernel-facing code (all under `runtime/src/`):
- `park.c|h` — the per-shard I/O plane. Raw `io_uring_setup`/
`io_uring_enter`, hand-mirrored SQ/CQ ring layouts, ops limited to
POLL_ADD / POLL_REMOVE / TIMEOUT (Linux 5.4 floor); epoll fallback;
the wake eventfd shard 0 owns.
- `sysio.c` — `fs`, `time`, `env`, `net`, `proc`, `signal`, `term`
builtins. fork+execvp, pidfd_open (434) and pidfd_send_signal (424)
as raw syscalls, an epoll bundle per bounded child, posix_openpt +
setsid + TIOCSWINSZ for `spawn_pty`, tcsetattr save/restore, sendmsg/
recvmsg with one SCM_RIGHTS fd, `SO_DOMAIN` gating, `getrandom`.
- `main.c` — SIGPIPE ignored; the SIGTERM/SIGINT stop latch.
- `tls.c`, `crypto.c` — sockets only; the TLS itself is not your area.
- `CODE-LOGIC.md` beside them — read "Bounded subprocess (iteration
42)", "runtime-v2 (ids 97–107)", "Fibers and actors", "Net deadlines",
"The shutdown drain guarantee" before auditing anything.
Reference cards: `docs/plan/exploration/linux/00-linux.md` indexes cards
01–12 (epoll, eventfd, timerfd, signalfd, inotify, sendfile, io_uring,
mmap, fallocate, pidfd, memfd_create, pwrite-fsync). A card carries: the
kernel source paths with what each defines, the man page names, the
libc signature or raw-syscall form in C, a minimal C example, the
kernel floor, and where writeonce uses it. The existing cards still
show Rust `libc::` snippets from v1 — Rust left the runtime 2026-08-20;
new cards are C, and when you touch an old card you convert its
snippets. Primitives without a card yet: fanotify, splice/tee, clone3,
close_range, pidfd_getfd, PTY ioctls, SCM_RIGHTS.
How you work:
- Answer from the tree. Open the SYSCALL_DEFINE, follow it to the
behaviour, and quote the line that settles the question. If the tree
and a man page disagree, the tree wins and you say so.
- For every primitive named: kernel floor (version + the commit or
Documentation line if findable), errno set, whether glibc 2.35 wraps
it, and the seccomp/container caveat if one exists.
- Auditing runtime code: diff the runtime's `#define`s and mirrored
structs against the uapi header of THIS tree (offsets, widths,
flag values, syscall numbers). Report each mismatch as
`runtime/src/<file>:<line>` vs `reference/linux/<path>:<line>`.
Check both `WO_IO` backends and the raw-syscall fallbacks.
- Do not edit `runtime/src` unless the request says so. When it does:
failing `runtime/test` case first (`test_proc`, `test_term`,
`test_fiber` are the templates), then the fix, then `make -C runtime
test` for the touched suite. Do not run the example gates yourself:
name the ones the caller must run (`just fibers` both backends + ASan,
`just subprocess`, `just wmux`, `just tls`). Match existing style;
comments state constraints, not narration.
- Never modify `.dev/`. Never push. Commits, if any, local on `dev`,
bullet messages, ≤25 lines, feature-specific prefix.
Report back with: the answer in one paragraph, the kernel citations
(`path:line`, tag v7.0), kernel floor + errno table, any runtime
mismatch found as file:line pairs, and gate output verbatim if you ran
one.

View file

@ -0,0 +1,180 @@
export const meta = {
name: 'prebuild-feature',
description: 'Pre-build research fan-out: ground a feature story, compare references, audit story discipline, produce a go/no-go brief',
whenToUse: 'Before writing code for a feature/iteration — run the brainstorm-to-ready groundwork as parallel research and get a consolidated pre-build brief',
phases: [
{ title: 'Understand', detail: 'read the target story + scout relevant .dev/reference projects' },
{ title: 'Analyze', detail: 'one agent per reference project vs the feature concern' },
{ title: 'Audit', detail: 'story-format/frontmatter + dependency-graph/status-board consistency' },
{ title: 'Consolidate', detail: 'settle open forks, fold gaps, go/no-go on readiness' },
],
}
/* ---------------------------------------------------------------------------
* Encodes the ritual this repo follows BEFORE any code lands on a feature:
* understand the story -> ground the forks in the actual runtime ->
* compare against .dev/reference implementations for gaps -> lock the
* decisions with KISS defaults -> acceptance criteria + deps/status.
* It does the *parallelizable research* half and hands back a brief; the
* fork-settling itself stays an interactive brainstorm (human in the loop).
*
* Invoke: Workflow({ name: 'prebuild-feature', args: {
* story: 'docs/stories/runtime-v2/09-in-process-tls.md', // optional
* concern: 'outbound TLS client integration', // optional
* references: ['fiber', 'go'] } }) // optional
* With no args it locates the current NEXT PLAN target itself.
* ------------------------------------------------------------------------- */
const story = (args && args.story) || null
const concern = (args && args.concern) || null
const givenRefs = (args && Array.isArray(args.references)) ? args.references : null
const REF_CAP = 6 // keep the fan-out bounded (medium workflow-size guideline)
const UNDERSTAND_SCHEMA = {
type: 'object',
properties: {
storyPath: { type: 'string' },
concern: { type: 'string' },
readiness: { type: 'string' },
lockedDecisions: { type: 'array', items: { type: 'string' } },
openForks: { type: 'array', items: { type: 'string' } },
acceptanceCriteria: { type: 'string' },
outOfScopePresent: { type: 'boolean' },
summary: { type: 'string' },
},
required: ['storyPath', 'concern', 'readiness', 'openForks', 'summary'],
}
const SCOUT_SCHEMA = {
type: 'object',
properties: {
references: { type: 'array', items: { type: 'string' } },
rationale: { type: 'string' },
},
required: ['references'],
}
const REF_SCHEMA = {
type: 'object',
properties: {
project: { type: 'string' },
howItHandles: { type: 'string' },
gapsInOurApproach: { type: 'array', items: { type: 'string' } },
recommendations: { type: 'array', items: { type: 'string' } },
},
required: ['project', 'howItHandles'],
}
const AUDIT_SCHEMA = {
type: 'object',
properties: {
area: { type: 'string' },
ok: { type: 'boolean' },
issues: { type: 'array', items: { type: 'string' } },
},
required: ['area', 'ok', 'issues'],
}
const BRIEF_SCHEMA = {
type: 'object',
properties: {
ready: { type: 'boolean' },
goNoGo: { type: 'string' },
unsettledForks: { type: 'array', items: { type: 'string' } },
recommendedDefaults: { type: 'array', items: { type: 'string' } },
gapsToFold: { type: 'array', items: { type: 'string' } },
acceptanceGaps: { type: 'array', items: { type: 'string' } },
blockers: { type: 'array', items: { type: 'string' } },
summary: { type: 'string' },
},
required: ['ready', 'goNoGo', 'summary'],
}
const CONVENTIONS =
'Repo discipline: story frontmatter is the ONLY source of status (status + readiness); ' +
'story docs carry NO code blocks (plans-no-raw-code); brainstorm to readiness:ready with ' +
'decisions LOCKED and Given/When/Then acceptance criteria + an out-of-scope list before any ' +
'code lands; docs live under ./docs; the dependency graph is docs/00-dependency-graph.md and ' +
'the status board docs/stories/00-status.md. Read CLAUDE.md and docs/stories/00-status.md to confirm.'
phase('Understand')
// The target story: use args.story, else let the agent find the NEXT PLAN target.
const storyClause = story
? `The target story is ${story}.`
: 'No story path was given — read docs/stories/00-status.md, find the current in-progress / NEXT-PLAN feature, and use its story file.'
const concernClause = concern ? `The feature concern is: ${concern}.` : 'Infer the feature concern from the story.'
const [understanding, scout] = await parallel([
() => agent(
`${storyClause} ${concernClause}\n\n` +
`Read that story and the repo conventions. ${CONVENTIONS}\n\n` +
`Report, as data: the resolved story path, the feature concern in one line, the story's ` +
`readiness, the decisions already LOCKED, the OPEN forks still unsettled, whether ` +
`Given/When/Then acceptance criteria and an out-of-scope list are present, and a short summary. ` +
`Do not propose fixes — just report what is and isn't settled.`,
{ label: 'understand-story', phase: 'Understand', agentType: 'general-purpose', schema: UNDERSTAND_SCHEMA },
),
() => agent(
(givenRefs
? `The caller named these reference projects: ${givenRefs.join(', ')}. Confirm each exists under .dev/reference/ and return the ones that do.`
: `List .dev/reference/ (\`ls .dev/reference\`). ${concernClause} `) +
`Pick the reference projects most relevant to studying this concern (at most ${REF_CAP}), newest/most-relevant first. ` +
`Return their directory names and a one-line rationale. Grounded in what actually exists on disk.`,
{ label: 'scout-references', phase: 'Understand', agentType: 'general-purpose', schema: SCOUT_SCHEMA },
),
])
const theConcern = (understanding && understanding.concern) || concern || 'the feature concern'
const theStory = (understanding && understanding.storyPath) || story || '(the NEXT-PLAN story)'
let refs = (scout && scout.references) || givenRefs || []
refs = refs.slice(0, REF_CAP)
if (refs.length === 0) log('No reference projects identified — skipping the reference-analysis fan-out.')
// One research batch: a reference-analysis agent per project + two audit agents,
// all independent, all needed by the consolidation barrier.
const research = await parallel([
...refs.map((r) => () => agent(
`Analyze how the reference project .dev/reference/${r} handles "${theConcern}". ` +
`Read its actual source (grep/read the relevant files). Report: how it handles the concern; ` +
`where writeonce's planned approach in ${theStory} has GAPS or missing safeguards versus it; ` +
`and concrete recommendations. Be specific and cite files. Return raw data, not prose for a human.`,
{ label: `ref:${r}`, phase: 'Analyze', agentType: 'general-purpose', schema: REF_SCHEMA },
)),
() => agent(
`Audit ${theStory} against the repo's STORY DISCIPLINE. ${CONVENTIONS}\n` +
`Check: frontmatter carries status + readiness; NO code fences in the doc; decisions are LOCKED ` +
`(not vague); Given/When/Then acceptance criteria present; out-of-scope list present. ` +
`Report each violation as an issue; ok=true only if clean.`,
{ label: 'audit:story-format', phase: 'Audit', agentType: 'general-purpose', schema: AUDIT_SCHEMA },
),
() => agent(
`Audit consistency between ${theStory}, the dependency graph (docs/00-dependency-graph.md) and the ` +
`status board (docs/stories/00-status.md) for "${theConcern}". Check: the feature's node/row exists, ` +
`its status matches the story frontmatter, and blockers/dependencies named in the story appear in the ` +
`graph. Report mismatches as issues; ok=true only if consistent.`,
{ label: 'audit:deps-status', phase: 'Audit', agentType: 'general-purpose', schema: AUDIT_SCHEMA },
),
])
const refResults = research.slice(0, refs.length).filter(Boolean)
const audits = research.slice(refs.length).filter(Boolean)
phase('Consolidate')
const brief = await agent(
`You are consolidating a PRE-BUILD brief for "${theConcern}" (story ${theStory}) — the go/no-go before code.\n\n` +
`Understanding of the story:\n${JSON.stringify(understanding, null, 2)}\n\n` +
`Reference analyses (gaps vs our approach):\n${JSON.stringify(refResults, null, 2)}\n\n` +
`Story-discipline + deps/status audits:\n${JSON.stringify(audits, null, 2)}\n\n` +
`Produce the brief: the OPEN forks still to settle (each with a recommended KISS default); ` +
`the gaps from the reference analyses worth FOLDING IN as locked requirements before build; ` +
`any acceptance-criteria gaps; blockers; and a clear go/no-go on whether the story is truly ` +
`ready to build. ready=true only if the forks are settled, the audits are clean, and the ` +
`reference gaps are either folded in or explicitly deferred. Ground every point in the inputs above.`,
{ label: 'consolidate-brief', phase: 'Consolidate', effort: 'high', schema: BRIEF_SCHEMA },
)
log(`Pre-build brief for ${theConcern}: ${brief && brief.goNoGo ? brief.goNoGo : '(no verdict)'}`)
return { story: theStory, concern: theConcern, understanding, references: refResults, audits, brief }

1
.gitignore vendored
View file

@ -4,6 +4,7 @@
# `woc .` manifest builds (wo.toml [build] target) # `woc .` manifest builds (wo.toml [build] target)
/docs/examples/log-watcher/target /docs/examples/log-watcher/target
/docs/examples/employee/target /docs/examples/employee/target
/docs/examples/skill-catalog/target
# Rust runtime (crates/rt/): compiled binary + build artifacts # Rust runtime (crates/rt/): compiled binary + build artifacts
/crates/rt/target /crates/rt/target

3
.gitmodules vendored
View file

@ -4,3 +4,6 @@
[submodule "reference/writeonce-api"] [submodule "reference/writeonce-api"]
path = reference/writeonce-api path = reference/writeonce-api
url = https://github.com/shoneyJ/writeonce-api url = https://github.com/shoneyJ/writeonce-api
[submodule "docs/examples/site"]
path = docs/examples/site
url = git@github.com:shoneyJ/writeonce-site.git

View file

@ -25,16 +25,19 @@ program ships as one file that depends only on the system C library.
mistyped field name is a **compile error**, not a runtime surprise. There is mistyped field name is a **compile error**, not a runtime surprise. There is
no SQL string anywhere in the shipped binary. no SQL string anywhere in the shipped binary.
- **One binary, no runtime dependencies.** `woc .` produces a self-contained - **One binary, no runtime dependencies.** `woc .` produces a self-contained
executable (~100 KB for the sample programs) that links only libc. Copy it to executable (160–260 KB for the sample programs in this repository) that links
a server and run it. only libc. Copy it to a server and run it.
- **Small on purpose.** No FFI, no package manager, no framework. The standard - **Small on purpose.** No FFI, no reflection, no package registry —
library is a handful of OS modules. The language is designed to be read. dependencies are exact-rev git URLs and nothing else. The standard library is
a handful of OS modules. The language is designed to be read.
writeonce is **not** a web framework and does not (yet) serve HTTP, WebSockets, writeonce is a systems language whose distinguishing feature is the embedded
or a UI. It is a systems language whose distinguishing feature is the embedded database. HTTP/1.1 and WebSockets **do** work today — but as `.wo` libraries you
database. If you have seen an older "writeonce" that served REST from `cargo consume through `[deps]` (`porch` for serving, `writeonce-view` for
run`, that was a separate, earlier runtime; this page documents the current HTML), never as runtime features: the runtime stays framework-agnostic on
`woc`/`wovm` toolchain. purpose. TLS is always terminated by a proxy in front. If you have seen an older
"writeonce" that served REST from `cargo run`, that was a separate, earlier
runtime; this page documents the current `woc`/`wovm` toolchain.
--- ---
@ -139,8 +142,10 @@ has a known owner, memory is freed deterministically, and values that form
cycles are collected by an inferred garbage collector (you never annotate GC- cycles are collected by an inferred garbage collector (you never annotate GC-
ness; the compiler infers it). The surface will look familiar: ness; the compiler infers it). The surface will look familiar:
- **Types:** `Int`, `Text`, `Bool`, and user `class` types. `?T` marks an - **Types:** `Int`, `Float`, `Bool`, `Text`, `Bytes`, `Timestamp`, `Id`, and
optional (nullable) value; `nil` is the empty case. user `class` types. `?T` marks an optional (nullable) value; `nil` is the
empty case. `Int` and `Float` never mix implicitly — `float` and `trunc` are
the only bridges.
- **Containers:** `multi T` (a growable list) and `map<K, V>`. Literals: - **Containers:** `multi T` (a growable list) and `map<K, V>`. Literals:
`[]`, `[a, b]`, `{}`. `[]`, `[a, b]`, `{}`.
- **Classes & records:** classes with fields and methods, `static const` / - **Classes & records:** classes with fields and methods, `static const` /
@ -149,6 +154,11 @@ ness; the compiler infers it). The surface will look familiar:
expressions, and `try { … } catch (e) { … }` (also an expression form). expressions, and `try { … } catch (e) { … }` (also an expression form).
- **Strings:** interpolation with `${expr}` inside a `"…"` literal. - **Strings:** interpolation with `${expr}` inside a `"…"` literal.
- **Functions:** free functions and methods; arguments and returns are typed. - **Functions:** free functions and methods; arguments and returns are typed.
- **Concurrency:** `spawn C { … }` starts an actor and yields an `actor M`
address; `send` is fire-and-forget, `call` parks the calling fiber until the
receive returns. A class becomes an actor by declaring `fn receive(msg: M)`.
Blocking stdlib calls park the fiber — there is no `async`, no `await`, and no
user-visible thread.
``` ```
fn classify(n: Int) -> Text { fn classify(n: Int) -> Text {
@ -166,14 +176,17 @@ A compact set of OS modules, reached by their reserved names — no imports:
| Module | What it does | | Module | What it does |
| --- | --- | | --- | --- |
| `fs` | `exists`, `list`, `stat`, `read_all`, `read_at`, `append` | | `fs` | `exists`, `list`, `stat`, `read_all`, `read_at`, `append` — read and append; a file cannot yet be replaced, truncated, deleted or renamed |
| `time` | `sleep`, `now`, `local`, `iso` | | `time` | `sleep`, `now`, `ticks` (µs monotonic), `local`, `iso` |
| `env` | `get`, `stopping` (a cooperative shutdown flag) | | `env` | `get`, `stopping` (a cooperative shutdown flag) |
| `net` | TCP `listen` / `accept` / `read` / `write` / `close` (host + port) | | `net` | `listen` / `accept` / `read` / `write` / `close`, per-call deadline twins `read_dl` / `accept_dl` / `write_dl`, `listen_unix`, `peer`. Listeners only — there is no outbound `connect` |
| `proc` | `run` a child process, capture stdout/stderr/exit | | `proc` | `run` a child process, capture stdout/stderr/exit |
| `json` | `encode` / `decode` (`json.decode(t) as T` yields `?T`) | | `json` | `encode` / `decode` (`json.decode(t) as T` yields `?T`) |
These are deliberately minimal — the surface a real program needs, and no more. These are deliberately minimal — the surface a real program needs, and no more.
Alongside them sit free builtins for text, containers, the `Float`/`Bytes`
bridges, `base64`, and the digests `sha1` / `sha256` / `hmac_sha256`. The full
list is `docs/guides/language-surface.md`.
--- ---
@ -269,14 +282,15 @@ dependencies, declared in the manifest:
```toml ```toml
[deps] [deps]
niceserve = { git = "https://github.com/shoneyj/niceframework", rev = "v0.1.0" } porch = { git = "https://github.com/shoneyj/porch", rev = "v0.1.0" }
``` ```
`woc` fetches each dep (via the `git` binary) into `.wo-deps/<name>/`, pins **The `[deps]` key IS the module name** `use` imports — the repository name
the resolved commit in `wo.lock`, and `use niceframework` (or never appears in your source. `woc` fetches each dep (via the `git` binary)
`use niceframework/sub`) imports its public names like any module. Builds into `.wo-deps/<name>/`, pins the resolved commit in `wo.lock`, and `use porch`
never touch the network once the lock is satisfied; a moved tag is reported, (or `use porch/router`) imports its public names like any module. Builds never
and `woc --update-deps myproject/` refreshes the lock deliberately. Flat touch the network once the lock is satisfied; a moved tag is reported, and
`woc --update-deps myproject/` refreshes the lock deliberately. Flat
dependencies only (a dep may not have its own `[deps]`) — honest and small, dependencies only (a dep may not have its own `[deps]`) — honest and small,
by design. by design.
@ -288,12 +302,15 @@ WO_DATA=./data ./target/myproject seed
WO_DATA=./data ./target/myproject report # a fresh process still sees the data WO_DATA=./data ./target/myproject report # a fresh process still sees the data
``` ```
A program with any durable table (the default) refuses to start without `WO_DATA`; `WO_EPHEMERAL=1` opts into a RAM-only run, `@table(durable: false)` opts a table out.
--- ---
## Worked examples ## Worked examples
Two complete sample programs live in the repository and double as the language's Thirteen sample programs live under `docs/examples/`; eight of them are wired to
acceptance tests: a `just` recipe and double as the language's acceptance tests. The three worth
reading first:
- **`docs/examples/employee/`** — departments and employees related by - **`docs/examples/employee/`** — departments and employees related by
`ref`/`backlink`, `@unique`, foreign-key restrict on delete, per-department `ref`/`backlink`, `@unique`, foreign-key restrict on delete, per-department
@ -303,7 +320,7 @@ acceptance tests:
just employee # compile + run every mode against a durable database just employee # compile + run every mode against a durable database
``` ```
- **`docs/examples/writeonce-serve/` + `docs/examples/web-app/`** — a web - **`docs/examples/porch/` + `docs/examples/web-app/`** — a web
framework written in writeonce (HTTP/1.1 behind a TLS-terminating proxy, framework written in writeonce (HTTP/1.1 behind a TLS-terminating proxy,
router with `:param` captures, interface-based handlers) and a storefront router with `:param` captures, interface-based handlers) and a storefront
consuming it **as a `[deps]` dependency**, with `@table` persistence. Run: consuming it **as a `[deps]` dependency**, with `@table` persistence. Run:
@ -319,7 +336,10 @@ acceptance tests:
just log-watcher just log-watcher
``` ```
Read either program's `main.wo` for idiomatic, working writeonce. Read any of their `main.wo` files for idiomatic, working writeonce. The rest —
`site` (the writeonce.de tutorial, server-rendered, `just site`), `fibers`,
`db-actor`, `db-bench`, `gc-cycle`, `operators`, `shop` — cover the concurrency,
GC and benchmark surfaces.
--- ---
@ -330,10 +350,16 @@ honest. These exist as design iterations and/or work-in-progress branches, not
as features you can use today: as features you can use today:
- **Query aggregates** — `group … by … into g` with `count`/`avg`/`min`/`max` - **Query aggregates** — `group … by … into g` with `count`/`avg`/`min`/`max`
and projection records. (Today the same result is written by hand from the and projection records. The clause parses and is then refused by the
shipped primitives.) typechecker; today the same result is written by hand from the shipped
- **HTTP service layer** — `service` blocks that route requests to methods. primitives.
- **Concurrency** — a shard-actor runtime and green-threaded fibers. - **File mutation and outbound sockets** — `fs` can create, grow and read a
file but never replace, truncate, delete or rename one, and there is no
`net.connect` at all, so nothing reaches out (no OIDC, SMTP, object store or
webhook). Both are iteration 38.
- **`service` blocks** — a declaration form that routes requests to methods,
lowering onto the framework library. Today you register routes as ordinary
framework calls, which works and is what every sample does.
- **Cross-program database access** — one program attaching to another's - **Cross-program database access** — one program attaching to another's
database over a local channel, with keypair authentication and per-client database over a local channel, with keypair authentication and per-client
rights. rights.
@ -341,8 +367,11 @@ as features you can use today:
- **Compile-time metaprogramming** — `@derive(Json/Csv/Eq/…)` generated from a - **Compile-time metaprogramming** — `@derive(Json/Csv/Eq/…)` generated from a
class's own metadata, no reflection. class's own metadata, no reflection.
Known current limits worth naming: `net` is TCP host+port only; `proc.run` has Known current limits worth naming: `proc.run` has no timeout or signal control;
no timeout or signal control; there is no stdin/stdout byte I/O and no FFI. there is no stdin/stdout byte I/O and no FFI; `map` lookup is a linear scan;
actor mailboxes are bounded but there is no supervision tree yet; the WAL is
append-only, so it grows and boot replays all of it; TLS is always a proxy's
job.
--- ---

View file

@ -6,11 +6,65 @@
"note": "refresh only with a commit that says why; tolerances come from tolerance_for() in the driver", "note": "refresh only with a commit that says why; tolerances come from tolerance_for() in the driver",
"wal_n": 4000 "wal_n": 4000
}, },
"ceiling.rows_recovered": {
"dir": "lower",
"floor": 159492,
"tolerance_pct": 100,
"value": 39873
},
"ckpt.boot_off_ms": {
"dir": "lower",
"floor": 456,
"tolerance_pct": 400,
"value": 114
},
"ckpt.boot_on_ms": {
"dir": "lower",
"floor": 256,
"tolerance_pct": 400,
"value": 64
},
"ckpt.bytes_off": {
"dir": "lower",
"floor": 7876676,
"tolerance_pct": 400,
"value": 1969169
},
"ckpt.bytes_on": {
"dir": "lower",
"floor": 3696192,
"tolerance_pct": 400,
"value": 924048
},
"ckpt.compactions": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 400,
"value": 6
},
"ckpt.pause_us_max": {
"dir": "lower",
"floor": 33912,
"tolerance_pct": 400,
"value": 8478
},
"ckpt.pause_us_per_mb": {
"dir": "lower",
"floor": 65848,
"tolerance_pct": 100,
"value": 16462
},
"ckpt.reclaim_x": {
"dir": "higher",
"floor": 0.0,
"tolerance_pct": 15,
"value": 2.13
},
"durable.s1.mixread.ops_sec": { "durable.s1.mixread.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 2302, "floor": 2452,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 9211 "value": 9809
}, },
"durable.s1.mixread.p50us": { "durable.s1.mixread.p50us": {
"dir": "lower", "dir": "lower",
@ -26,27 +80,27 @@
}, },
"durable.s1.mixwrite.ops_sec": { "durable.s1.mixwrite.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 255, "floor": 272,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 1023 "value": 1089
}, },
"durable.s1.mixwrite.p50us": { "durable.s1.mixwrite.p50us": {
"dir": "lower", "dir": "lower",
"floor": 1720, "floor": 1704,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 430 "value": 426
}, },
"durable.s1.mixwrite.p99us": { "durable.s1.mixwrite.p99us": {
"dir": "lower", "dir": "lower",
"floor": 2656, "floor": 1984,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 664 "value": 496
}, },
"durable.s1.query.ops_sec": { "durable.s1.query.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 308641, "floor": 306372,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 1234567 "value": 1225490
}, },
"durable.s1.query.p50us": { "durable.s1.query.p50us": {
"dir": "lower", "dir": "lower",
@ -62,9 +116,9 @@
}, },
"durable.s1.read.ops_sec": { "durable.s1.read.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 319284, "floor": 307389,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 1277139 "value": 1229558
}, },
"durable.s1.read.p50us": { "durable.s1.read.p50us": {
"dir": "lower", "dir": "lower",
@ -80,81 +134,117 @@
}, },
"durable.s1.seed.ops_sec": { "durable.s1.seed.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 1115, "floor": 1095,
"tolerance_pct": 15, "tolerance_pct": 15,
"value": 4460 "value": 4381
}, },
"durable.s1.seed.p50us": { "durable.s1.seed.p50us": {
"dir": "lower", "dir": "lower",
"floor": 836, "floor": 848,
"tolerance_pct": 15, "tolerance_pct": 15,
"value": 209 "value": 212
}, },
"durable.s1.seed.p99us": { "durable.s1.seed.p99us": {
"dir": "lower", "dir": "lower",
"floor": 2352, "floor": 2432,
"tolerance_pct": 15, "tolerance_pct": 15,
"value": 588 "value": 608
}, },
"durable.s1.write.ops_sec": { "durable.s1.wmix.mean_batch": {
"dir": "higher", "dir": "higher",
"floor": 581, "floor": 0.0,
"tolerance_pct": 15, "tolerance_pct": 100,
"value": 2324 "value": 1.0
}, },
"durable.s1.write.p50us": { "durable.s1.wmix.ops_sec": {
"dir": "higher",
"floor": 402,
"tolerance_pct": 15,
"value": 1611
},
"durable.s1.wmix.p50us": {
"dir": "lower", "dir": "lower",
"floor": 1764, "floor": 1764,
"tolerance_pct": 15, "tolerance_pct": 15,
"value": 441 "value": 441
}, },
"durable.s1.wmix.p99us": {
"dir": "lower",
"floor": 2684,
"tolerance_pct": 15,
"value": 671
},
"durable.s1.wmix.peak_batch": {
"dir": "higher",
"floor": 0,
"tolerance_pct": 100,
"value": 1
},
"durable.s1.wmix.peak_staged": {
"dir": "lower",
"floor": 196,
"tolerance_pct": 100,
"value": 49
},
"durable.s1.write.ops_sec": {
"dir": "higher",
"floor": 573,
"tolerance_pct": 15,
"value": 2294
},
"durable.s1.write.p50us": {
"dir": "lower",
"floor": 1760,
"tolerance_pct": 15,
"value": 440
},
"durable.s1.write.p99us": { "durable.s1.write.p99us": {
"dir": "lower", "dir": "lower",
"floor": 2544, "floor": 2716,
"tolerance_pct": 15, "tolerance_pct": 15,
"value": 636 "value": 679
}, },
"durable.sN.mixread.ops_sec": { "durable.sN.mixread.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 1081, "floor": 1183,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 4324 "value": 4733
}, },
"durable.sN.mixread.p50us": { "durable.sN.mixread.p50us": {
"dir": "lower", "dir": "lower",
"floor": 248, "floor": 244,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 62 "value": 61
}, },
"durable.sN.mixread.p99us": { "durable.sN.mixread.p99us": {
"dir": "lower", "dir": "lower",
"floor": 18896, "floor": 16200,
"tolerance_pct": 50, "tolerance_pct": 300,
"value": 4724 "value": 4050
}, },
"durable.sN.mixwrite.ops_sec": { "durable.sN.mixwrite.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 120, "floor": 131,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 480 "value": 525
}, },
"durable.sN.mixwrite.p50us": { "durable.sN.mixwrite.p50us": {
"dir": "lower", "dir": "lower",
"floor": 2152, "floor": 2172,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 538 "value": 543
}, },
"durable.sN.mixwrite.p99us": { "durable.sN.mixwrite.p99us": {
"dir": "lower", "dir": "lower",
"floor": 23552, "floor": 16440,
"tolerance_pct": 50, "tolerance_pct": 300,
"value": 5888 "value": 4110
}, },
"durable.sN.query.ops_sec": { "durable.sN.query.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 262329, "floor": 308451,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 1049317 "value": 1233806
}, },
"durable.sN.query.p50us": { "durable.sN.query.p50us": {
"dir": "lower", "dir": "lower",
@ -165,14 +255,14 @@
"durable.sN.query.p99us": { "durable.sN.query.p99us": {
"dir": "lower", "dir": "lower",
"floor": 100, "floor": 100,
"tolerance_pct": 50, "tolerance_pct": 300,
"value": 2 "value": 1
}, },
"durable.sN.read.ops_sec": { "durable.sN.read.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 313558, "floor": 248188,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 1254233 "value": 992752
}, },
"durable.sN.read.p50us": { "durable.sN.read.p50us": {
"dir": "lower", "dir": "lower",
@ -183,50 +273,260 @@
"durable.sN.read.p99us": { "durable.sN.read.p99us": {
"dir": "lower", "dir": "lower",
"floor": 100, "floor": 100,
"tolerance_pct": 50, "tolerance_pct": 300,
"value": 1 "value": 2
}, },
"durable.sN.seed.ops_sec": { "durable.sN.seed.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 1116, "floor": 1104,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 4466 "value": 4418
}, },
"durable.sN.seed.p50us": { "durable.sN.seed.p50us": {
"dir": "lower", "dir": "lower",
"floor": 840, "floor": 844,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 210 "value": 211
}, },
"durable.sN.seed.p99us": { "durable.sN.seed.p99us": {
"dir": "lower", "dir": "lower",
"floor": 2536, "floor": 2188,
"tolerance_pct": 300,
"value": 547
},
"durable.sN.wmix.mean_batch": {
"dir": "higher",
"floor": 1.0,
"tolerance_pct": 100,
"value": 6.22
},
"durable.sN.wmix.ops_sec": {
"dir": "higher",
"floor": 1504,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 634 "value": 6017
},
"durable.sN.wmix.p50us": {
"dir": "lower",
"floor": 27184,
"tolerance_pct": 50,
"value": 6796
},
"durable.sN.wmix.p99us": {
"dir": "lower",
"floor": 37484,
"tolerance_pct": 300,
"value": 9371
},
"durable.sN.wmix.peak_batch": {
"dir": "higher",
"floor": 15,
"tolerance_pct": 100,
"value": 60
},
"durable.sN.wmix.peak_staged": {
"dir": "lower",
"floor": 11760,
"tolerance_pct": 100,
"value": 2940
}, },
"durable.sN.write.ops_sec": { "durable.sN.write.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 576, "floor": 580,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 2304 "value": 2320
}, },
"durable.sN.write.p50us": { "durable.sN.write.p50us": {
"dir": "lower", "dir": "lower",
"floor": 1772, "floor": 1760,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 443 "value": 440
}, },
"durable.sN.write.p99us": { "durable.sN.write.p99us": {
"dir": "lower", "dir": "lower",
"floor": 2716, "floor": 2688,
"tolerance_pct": 50, "tolerance_pct": 300,
"value": 679 "value": 672
},
"growth.available": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 100,
"value": 1
},
"growth.int.noswap.bytes_per_row": {
"dir": "lower",
"floor": 440,
"tolerance_pct": 10,
"value": 110
},
"growth.int.noswap.doublings": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 100,
"value": 3
},
"growth.int.noswap.p99_departure_decile": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 100,
"value": 0
},
"growth.int.noswap.read_p50us": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 100,
"value": 0
},
"growth.int.noswap.read_p99us": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 100,
"value": 1
},
"growth.int.noswap.rows": {
"dir": "lower",
"floor": 800000,
"tolerance_pct": 100,
"value": 200000
},
"growth.int.noswap.rss_kb": {
"dir": "lower",
"floor": 168528,
"tolerance_pct": 100,
"value": 42132
},
"growth.int.swap.bytes_per_row": {
"dir": "lower",
"floor": 440,
"tolerance_pct": 10,
"value": 110
},
"growth.int.swap.doublings": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 100,
"value": 3
},
"growth.int.swap.p99_departure_decile": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 100,
"value": 0
},
"growth.int.swap.read_p50us": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 100,
"value": 0
},
"growth.int.swap.read_p99us": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 100,
"value": 1
},
"growth.int.swap.rows": {
"dir": "lower",
"floor": 800000,
"tolerance_pct": 100,
"value": 200000
},
"growth.int.swap.rss_kb": {
"dir": "lower",
"floor": 168576,
"tolerance_pct": 100,
"value": 42144
},
"growth.text.noswap.bytes_per_row": {
"dir": "lower",
"floor": 1284,
"tolerance_pct": 10,
"value": 321
},
"growth.text.noswap.doublings": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 100,
"value": 2
},
"growth.text.noswap.p99_departure_decile": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 100,
"value": 0
},
"growth.text.noswap.read_p50us": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 100,
"value": 0
},
"growth.text.noswap.read_p99us": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 100,
"value": 1
},
"growth.text.noswap.rows": {
"dir": "lower",
"floor": 800000,
"tolerance_pct": 100,
"value": 200000
},
"growth.text.noswap.rss_kb": {
"dir": "lower",
"floor": 343312,
"tolerance_pct": 100,
"value": 85828
},
"growth.text.swap.bytes_per_row": {
"dir": "lower",
"floor": 1284,
"tolerance_pct": 10,
"value": 321
},
"growth.text.swap.doublings": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 100,
"value": 2
},
"growth.text.swap.p99_departure_decile": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 100,
"value": 0
},
"growth.text.swap.read_p50us": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 100,
"value": 0
},
"growth.text.swap.read_p99us": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 100,
"value": 1
},
"growth.text.swap.rows": {
"dir": "lower",
"floor": 800000,
"tolerance_pct": 100,
"value": 200000
},
"growth.text.swap.rss_kb": {
"dir": "lower",
"floor": 343328,
"tolerance_pct": 100,
"value": 85832
}, },
"ram.s1.mixread.ops_sec": { "ram.s1.mixread.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 22384, "floor": 22286,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 89538 "value": 89144
}, },
"ram.s1.mixread.p50us": { "ram.s1.mixread.p50us": {
"dir": "lower", "dir": "lower",
@ -242,9 +542,9 @@
}, },
"ram.s1.mixwrite.ops_sec": { "ram.s1.mixwrite.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 2487, "floor": 2476,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 9948 "value": 9904
}, },
"ram.s1.mixwrite.p50us": { "ram.s1.mixwrite.p50us": {
"dir": "lower", "dir": "lower",
@ -256,19 +556,19 @@
"dir": "lower", "dir": "lower",
"floor": 100, "floor": 100,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 2 "value": 1
}, },
"ram.s1.msgrate.msgs_sec": { "ram.s1.msgrate.msgs_sec": {
"dir": "higher", "dir": "higher",
"floor": 2087508, "floor": 1336469,
"tolerance_pct": 15, "tolerance_pct": 70,
"value": 16700066 "value": 10691756
}, },
"ram.s1.query.ops_sec": { "ram.s1.query.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 247402, "floor": 244857,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 989609 "value": 979431
}, },
"ram.s1.query.p50us": { "ram.s1.query.p50us": {
"dir": "lower", "dir": "lower",
@ -284,9 +584,9 @@
}, },
"ram.s1.read.ops_sec": { "ram.s1.read.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 274393, "floor": 252270,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 1097574 "value": 1009081
}, },
"ram.s1.read.p50us": { "ram.s1.read.p50us": {
"dir": "lower", "dir": "lower",
@ -302,9 +602,9 @@
}, },
"ram.s1.seed.ops_sec": { "ram.s1.seed.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 61297, "floor": 62904,
"tolerance_pct": 15, "tolerance_pct": 15,
"value": 245188 "value": 251616
}, },
"ram.s1.seed.p50us": { "ram.s1.seed.p50us": {
"dir": "lower", "dir": "lower",
@ -320,69 +620,69 @@
}, },
"ram.s1.write.ops_sec": { "ram.s1.write.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 48866, "floor": 47770,
"tolerance_pct": 15, "tolerance_pct": 15,
"value": 195465 "value": 191080
}, },
"ram.s1.write.p50us": { "ram.s1.write.p50us": {
"dir": "lower", "dir": "lower",
"floor": 100, "floor": 100,
"tolerance_pct": 15, "tolerance_pct": 15,
"value": 7 "value": 8
}, },
"ram.s1.write.p99us": { "ram.s1.write.p99us": {
"dir": "lower", "dir": "lower",
"floor": 100, "floor": 100,
"tolerance_pct": 15, "tolerance_pct": 15,
"value": 12 "value": 10
}, },
"ram.sN.mixread.ops_sec": { "ram.sN.mixread.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 11229, "floor": 11218,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 44918 "value": 44874
}, },
"ram.sN.mixread.p50us": { "ram.sN.mixread.p50us": {
"dir": "lower", "dir": "lower",
"floor": 236, "floor": 240,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 59 "value": 60
}, },
"ram.sN.mixread.p99us": { "ram.sN.mixread.p99us": {
"dir": "lower", "dir": "lower",
"floor": 432, "floor": 324,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 108 "value": 81
}, },
"ram.sN.mixwrite.ops_sec": { "ram.sN.mixwrite.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 1247, "floor": 1246,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 4990 "value": 4986
}, },
"ram.sN.mixwrite.p50us": { "ram.sN.mixwrite.p50us": {
"dir": "lower", "dir": "lower",
"floor": 256, "floor": 260,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 64 "value": 65
}, },
"ram.sN.mixwrite.p99us": { "ram.sN.mixwrite.p99us": {
"dir": "lower", "dir": "lower",
"floor": 516, "floor": 356,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 129 "value": 89
}, },
"ram.sN.msgrate.msgs_sec": { "ram.sN.msgrate.msgs_sec": {
"dir": "higher", "dir": "higher",
"floor": 355876, "floor": 317323,
"tolerance_pct": 50, "tolerance_pct": 70,
"value": 2847015 "value": 2538586
}, },
"ram.sN.query.ops_sec": { "ram.sN.query.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 307125, "floor": 291545,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 1228501 "value": 1166180
}, },
"ram.sN.query.p50us": { "ram.sN.query.p50us": {
"dir": "lower", "dir": "lower",
@ -398,9 +698,9 @@
}, },
"ram.sN.read.ops_sec": { "ram.sN.read.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 340692, "floor": 317823,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 1362769 "value": 1271294
}, },
"ram.sN.read.p50us": { "ram.sN.read.p50us": {
"dir": "lower", "dir": "lower",
@ -416,9 +716,9 @@
}, },
"ram.sN.seed.ops_sec": { "ram.sN.seed.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 72890, "floor": 73305,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 291562 "value": 293220
}, },
"ram.sN.seed.p50us": { "ram.sN.seed.p50us": {
"dir": "lower", "dir": "lower",
@ -434,9 +734,9 @@
}, },
"ram.sN.write.ops_sec": { "ram.sN.write.ops_sec": {
"dir": "higher", "dir": "higher",
"floor": 60518, "floor": 56810,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 242072 "value": 227241
}, },
"ram.sN.write.p50us": { "ram.sN.write.p50us": {
"dir": "lower", "dir": "lower",
@ -448,6 +748,144 @@
"dir": "lower", "dir": "lower",
"floor": 100, "floor": 100,
"tolerance_pct": 50, "tolerance_pct": 50,
"value": 9 "value": 10
},
"randread.collapse_x": {
"dir": "lower",
"floor": 1084,
"tolerance_pct": 100,
"value": 271
},
"randread.overcap.filled_rss_kb": {
"dir": "lower",
"floor": 58144,
"tolerance_pct": 100,
"value": 14536
},
"randread.overcap.ops_sec": {
"dir": "higher",
"floor": 1427,
"tolerance_pct": 100,
"value": 5711
},
"randread.overcap.read_p50us": {
"dir": "lower",
"floor": 624,
"tolerance_pct": 100,
"value": 156
},
"randread.overcap.read_p99us": {
"dir": "lower",
"floor": 1628,
"tolerance_pct": 100,
"value": 407
},
"randread.resident.filled_rss_kb": {
"dir": "lower",
"floor": 168288,
"tolerance_pct": 100,
"value": 42072
},
"randread.resident.ops_sec": {
"dir": "higher",
"floor": 387281,
"tolerance_pct": 100,
"value": 1549126
},
"randread.resident.read_p50us": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 100,
"value": 1
},
"randread.resident.read_p99us": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 100,
"value": 1
},
"replay.history.ms": {
"dir": "lower",
"floor": 12876,
"tolerance_pct": 100,
"value": 3219
},
"replay.history.ns_per_record": {
"dir": "lower",
"floor": 64384,
"tolerance_pct": 100,
"value": 16096
},
"replay.history.records": {
"dir": "lower",
"floor": 800000,
"tolerance_pct": 100,
"value": 200000
},
"replay.history.wal_bytes": {
"dir": "lower",
"floor": 39200140,
"tolerance_pct": 100,
"value": 9800035
},
"replay.history_penalty_x": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 100,
"value": 1.6
},
"replay.inserts.ms": {
"dir": "lower",
"floor": 8064,
"tolerance_pct": 100,
"value": 2016
},
"replay.inserts.ns_per_record": {
"dir": "lower",
"floor": 80656,
"tolerance_pct": 100,
"value": 20164
},
"replay.inserts.records": {
"dir": "lower",
"floor": 400000,
"tolerance_pct": 100,
"value": 100000
},
"replay.inserts.wal_bytes": {
"dir": "lower",
"floor": 19600140,
"tolerance_pct": 100,
"value": 4900035
},
"replay.startup_ms": {
"dir": "lower",
"floor": 100,
"tolerance_pct": 100,
"value": 3
},
"residency.all_collapse_x": {
"dir": "higher",
"floor": 2.0,
"tolerance_pct": 100,
"value": 105.4
},
"residency.in_ram_cost_x": {
"dir": "lower",
"floor": 8.0,
"tolerance_pct": 50,
"value": 4.23
},
"residency.overcap_vs_swap_x": {
"dir": "higher",
"floor": 1.0,
"tolerance_pct": 100,
"value": 1.53
},
"residency.rss_ratio": {
"dir": "higher",
"floor": 2.0,
"tolerance_pct": 10,
"value": 2.55
} }
} }

View file

@ -2,7 +2,9 @@
Lexer → parser → typechecker → ownership pass → bytecode emitter, for `.wo`. OCaml stdlib only (no Menhir, no ppx); dune is the build runner. Sibling of the C `wovm` bytecode VM ([`runtime/`](../runtime/README.md)) — the two halves of the OOP track's spec (`docs/superpowers/specs/2026-08-01-oop-compiler-vm-design.md`) meet at plan 3, where `woc`'s emitted `.wob` runs on `wovm`. Lexer → parser → typechecker → ownership pass → bytecode emitter, for `.wo`. OCaml stdlib only (no Menhir, no ppx); dune is the build runner. Sibling of the C `wovm` bytecode VM ([`runtime/`](../runtime/README.md)) — the two halves of the OOP track's spec (`docs/superpowers/specs/2026-08-01-oop-compiler-vm-design.md`) meet at plan 3, where `woc`'s emitted `.wob` runs on `wovm`.
**Stage: plan 3 (`docs/plan/compiler/2026-08-01-wob-emit-e2e-single-binary.md`) complete, Tasks 1–6 + 8** (Task 7, a parity harness against the Rust runtime, was deferred by explicit decision — the two stacks now diverge by design). `.wo` source compiles to `.wob` bytecode (`--emit`) and to a single self-contained executable (`build`) that runs `wovm` with no arguments and no repo-relative dependency. Milestone 1's acceptance gate — compile-time budget, the full conformance corpus under ASan, the single-binary smoke, both unit suites — is `just oop-accept`. Plan 2 (lexer through ownership pass) shipped first and is unchanged. **Stage: well past plan 3.** Plan 2 (lexer through ownership pass) and plan 3 (`docs/plan/compiler/2026-08-01-wob-emit-e2e-single-binary.md`, Tasks 1–6 + 8 — Task 7, a parity harness against the since-removed Rust runtime, was deferred by explicit decision) closed the milestone: `.wo` source compiles to `.wob` bytecode (`--emit`) and to a single self-contained executable (`build`) that runs `wovm` with no arguments and no repo-relative dependency. Milestone 1's acceptance gate — compile-time budget, the full conformance corpus under ASan, the single-binary smoke, both unit suites — is `just oop-accept`.
Since then the front end has taken iterations **15** (`[deps]`, `wo.lock`, `--update-deps`), **17** (`kind = "library"`, entry-less check mode, `internal/` as WO-E108), **19** (`Float` and `Bytes`), **24** (`call`'s typed reply, WO-E226), **34** (digest builtins), **35** (net deadline seams), **36** (`not`, bitwise operators, hex/binary literals, compound assigns — `.wob` v6) and **37** (the backtick raw text literal with `{{ }}` auto-escaping). Current language surface: [`docs/guides/language-surface.md`](../docs/guides/language-surface.md). Current status: [the board](../docs/stories/00-status.md).
## Requirements ## Requirements
@ -24,23 +26,30 @@ just woc-test # same, from the repo root
``` ```
woc <path> # compile (lex, parse, typecheck, ownership-check); nothing prints on success woc <path> # compile (lex, parse, typecheck, ownership-check); nothing prints on success
woc <dir> # BUILDS instead, when <dir>/wo.toml exists — the primary mode
woc version # e.g. "writeonce 0.1.0 linux/amd64"
woc --emit <path> -o <out.wob> # compile through to a .wob bytecode module, runnable by wovm
woc build <dir> -o <app> [--runtime <path>]
# compile + append the .wob image to a copy of wovm (--runtime,
# else $WO_RUNTIME, a wovm beside this woc, or runtime/wovm)
woc --update-deps <dir> # re-fetch [deps] at their manifest revs, rewrite wo.lock
woc -D <name> ... # define a build flag for the #if/#else/#end token filter
woc --dump-tokens <path> # stdout: one line per lexed token woc --dump-tokens <path> # stdout: one line per lexed token
woc --dump-ast <path> # stdout: the declaration + body AST, indented woc --dump-ast <path> # stdout: the declaration + body AST, indented
woc --dump-owner <path> # stdout: the ownership pass's four tables (moves, drops, rc, residual) woc --dump-owner <path> # stdout: the ownership pass's four tables (moves, drops, rc, residual)
woc --dump-gc <path> # stdout: the inferred-GC pass's traced set
woc --dump-bc <path> # stdout: disassembled bytecode for every emitted method woc --dump-bc <path> # stdout: disassembled bytecode for every emitted method
woc --emit <path> -o <out.wob> # compile through to a .wob bytecode module, runnable by wovm
woc build <dir> -o <app> [--runtime <path>]
# compile + append the .wob image to a copy of wovm (default
# runtime/wovm, or --runtime) into one self-contained <app>
``` ```
`<path>` is a single `.wo` file or a directory. A directory is discovered recursively for every `.wo` file under it — same contract as `wo run` (`crates/rt/src/lib.rs::discover`): dot-prefixed entries and `target`/`data`/`node_modules` are skipped, results are sorted by path. Every discovered file compiles as one program (declarations in one file resolve for bodies in another, regardless of discovery order); diagnostics from every file and every stage print sorted by `(file, line, col)`. For multi-file `--dump-*` output, each file's dump is preceded by a `=== path ===` header line (`compiler/src/dump.ml`'s `file_header`) — a single-file run never prints one. `woc <dir>` on a directory holding a `wo.toml` is the mode every sample and the install docs use: it reads the manifest's `name` plus the optional `[build]` runtime/target keys and produces `<target>/<name>` exactly as `woc build` would. A manifest with `kind = "library"` is checked entry-less and writes nothing.
`<path>` is a single `.wo` file or a directory. A directory is discovered recursively for every `.wo` file under it: dot-prefixed entries and `target`/`data`/`node_modules` are skipped, results are sorted by path. Every discovered file compiles as one program (declarations in one file resolve for bodies in another, regardless of discovery order); diagnostics from every file and every stage print sorted by `(file, line, col)`. For multi-file `--dump-*` output, each file's dump is preceded by a `=== path ===` header line (`compiler/src/dump.ml`'s `file_header`) — a single-file run never prints one.
Diagnostics render as `file:line:col: severity CODE: message` plus a source excerpt with a caret; every shipped code is cataloged in `docs/plan/oop-vm/01-error-catalog.md`. Exit codes: **0** clean compile, **1** diagnostics reported, **2** usage/IO failure. Diagnostics render as `file:line:col: severity CODE: message` plus a source excerpt with a caret; every shipped code is cataloged in `docs/plan/oop-vm/01-error-catalog.md`. Exit codes: **0** clean compile, **1** diagnostics reported, **2** usage/IO failure.
## Layout ## Layout
- `src/` — one module per stage: `diag` (diagnostics, collector, exit-code decision), `token`/`lexer`, `ast`/`parser`, `types` (typechecker), `owner` (MVS ownership pass), `emit` (bytecode emitter, consumes `owner`'s four tables), `disasm` (bytecode disassembler, backs `--dump-bc`), `dump` (stable text dumps for all of the above) - `src/` — one module per stage: `diag` (diagnostics, collector, exit-code decision), `token`/`lexer`, `ast`/`parser`, `types` (typechecker), `gcinfer` (the inferred-GC pass, backs `--dump-gc`), `owner` (MVS ownership pass), `emit` (bytecode emitter, consumes `owner`'s four tables), `disasm` (bytecode disassembler, backs `--dump-bc`), `dump` (stable text dumps for all of the above)
- `bin/` — the `woc` executable: CLI parsing, file discovery, the multi-file/cross-file driver, `--emit`/`build` output - `bin/` — the `woc` executable: CLI parsing, file discovery, the multi-file/cross-file driver, `--emit`/`build` output
- `test/` — `runner.ml` (golden runner + CLI smoke) and `test_diag.ml` (diag.ml unit checks); `test/golden/<stage>/` holds one-file-per-fixture goldens (`tokens`, `ast`, `owner`, `owner-err`, `bc`); `test/fixtures/driver/` holds the multi-file CLI-smoke fixtures (directory discovery, cross-file symbols, diagnostic ordering) that don't fit the one-`.wo`-file-per-fixture golden shape - `test/` — `runner.ml` (golden runner + CLI smoke) and `test_diag.ml` (diag.ml unit checks); `test/golden/<stage>/` holds one-file-per-fixture goldens (`tokens`, `ast`, `owner`, `owner-err`, `bc`); `test/fixtures/driver/` holds the multi-file CLI-smoke fixtures (directory discovery, cross-file symbols, diagnostic ordering) that don't fit the one-`.wo`-file-per-fixture golden shape

View file

@ -878,6 +878,16 @@ let build_mode ?(deps : (string * string) list = []) ~(runtime : string option)
Printf.eprintf "woc: %s\n" msg; Printf.eprintf "woc: %s\n" msg;
exit 2 exit 2
in in
(* a fresh checkout has no target/ directories: create the output's
parent, so `-o <dir>/<name>` works the way every gate and README
invokes it instead of failing on the temp file below *)
let rec mkdir_p d =
if d <> "" && d <> "." && d <> "/" && not (Sys.file_exists d) then begin
mkdir_p (Filename.dirname d);
(try Sys.mkdir d 0o755 with Sys_error _ -> ())
end
in
mkdir_p (Filename.dirname out);
let tmp = out ^ ".woc-build.tmp" in let tmp = out ^ ".woc-build.tmp" in
(* stale tmp from an interrupted earlier build must not survive: its (* stale tmp from an interrupted earlier build must not survive: its
permission bits would leak through, since Open_creat on an permission bits would leak through, since Open_creat on an

View file

@ -518,9 +518,23 @@ type method_decl = {
known keys; anything else inside `@table(...)` is a parse error known keys; anything else inside `@table(...)` is a parse error
(WO-E1xx), not a silent skip — unlike an unrecognized annotation (WO-E1xx), not a silent skip — unlike an unrecognized annotation
*name*, which does skip silently (rt convention, see parser.ml). *) *name*, which does skip silently (rt convention, see parser.ml). *)
(* databasev2 2: what a table keeps in memory. `ResAll` is every row resident
(the default, and what every table did before this existed); `ResKeys` keeps
the id map, the secondary indexes and the unique shadows resident and reads
rows back from the log by offset. Named `keys` and not `index` on review —
`index:` is already an argument key, so the value would have collided. *)
type residency = ResAll | ResKeys
type table_cfg = { type table_cfg = {
table_name : string option; table_name : string option;
indexes : string list list; indexes : string list list;
(* databasev2 2. Both DEFAULT to the pre-existing behaviour, which is what
lets every `@table` written before this compile byte-identically:
`durable = true` logs to the WAL as always, `resident = ResAll` keeps
every row in a slab as always. dump.ml prints them only when they differ
from these values, so no golden moves either. *)
durable : bool;
resident : residency;
} }
type class_decl = { type class_decl = {

View file

@ -183,7 +183,8 @@ let dump (img : string) : string =
set; iteration 19's v5 added the Float constant tag, kinds 6/7 and set; iteration 19's v5 added the Float constant tag, kinds 6/7 and
opcodes 34-41). The disassembler tracks the emitter, not a range: an old opcodes 34-41). The disassembler tracks the emitter, not a range: an old
image is a different format and reading it as this one would misrender. *) image is a different format and reading it as this one would misrender. *)
if ver <> 6 then raise (Bad (Printf.sprintf "unsupported version %d" ver)); (* tracks emit.ml's wob_version and wob.h's WOB_VERSION *)
if ver <> 8 then raise (Bad (Printf.sprintf "unsupported version %d" ver));
let coff = u32 img 8 and ccnt = u32 img 12 in let coff = u32 img 8 and ccnt = u32 img 12 in
let koff = u32 img 16 and kcnt = u32 img 20 in let koff = u32 img 16 and kcnt = u32 img 20 in
let ioff = u32 img 24 and icnt = u32 img 28 in let ioff = u32 img 24 and icnt = u32 img 28 in
@ -259,7 +260,13 @@ let dump (img : string) : string =
in in
line line
(Printf.sprintf "c%-3d %s flags=%s fields=[%s]" i (kname nm) (Printf.sprintf "c%-3d %s flags=%s fields=[%s]" i (kname nm)
(if flags land 1 <> 0 then "gc" else "-") (let parts =
(if flags land 1 <> 0 then [ "gc" ] else [])
@ (if flags land 2 <> 0 then [ "volatile" ] else [])
@ (if flags land 4 <> 0 then [ "resident=keys" ] else [])
@ (if flags land 8 <> 0 then [ "table" ] else [])
in
if parts = [] then "-" else String.concat "+" parts)
(String.concat ", " fields)) (String.concat ", " fields))
done; done;
(* interfaces + vtable rows *) (* interfaces + vtable rows *)

View file

@ -362,7 +362,14 @@ let annotations_header (is_gc : bool) (table : Ast.table_cfg option) : string =
let index_parts = let index_parts =
List.map (fun cols -> Printf.sprintf "index=[%s]" (String.concat ", " cols)) t.indexes List.map (fun cols -> Printf.sprintf "index=[%s]" (String.concat ", " cols)) t.indexes
in in
let parts = name_part @ index_parts in (* databasev2 2: print these ONLY when they differ from the default.
Printing them unconditionally would move every pre-existing golden,
which is the one thing this iteration is not allowed to do. *)
let durable_part = if t.durable then [] else [ "durable=false" ] in
let resident_part =
match t.resident with Ast.ResAll -> [] | Ast.ResKeys -> [ "resident=keys" ]
in
let parts = name_part @ index_parts @ durable_part @ resident_part in
if parts = [] then " @table" else " @table(" ^ String.concat ", " parts ^ ")" if parts = [] then " @table" else " @table(" ^ String.concat ", " parts ^ ")"
in in
gc_part ^ table_part gc_part ^ table_part

View file

@ -154,7 +154,11 @@ let wob_magic = 0x31424F57 (* "WOB1" read as an LE u32 *)
(* v5 (iteration 19): the Float constant tag, field kinds 6/7, opcodes 34-41, (* v5 (iteration 19): the Float constant tag, field kinds 6/7, opcodes 34-41,
builtins 70-83. v4 (iteration 7b): RC opcodes retired; gc mask = GC roots *) builtins 70-83. v4 (iteration 7b): RC opcodes retired; gc mask = GC roots *)
let wob_version = 6 (* MUST track runtime/src/wob.h's WOB_VERSION — the loader is an exact-match
check, so a drift here is not a warning, it is every image refused.
v7 (databasev2 2): two class flag bits, no layout change.
v8 (databasev2 2 task 6a): the table bit, no layout change. *)
let wob_version = 8
let wob_hdr_size = 44 let wob_hdr_size = 44
let wob_none = 0xFFFFFFFF let wob_none = 0xFFFFFFFF
@ -167,6 +171,12 @@ let k_text = 1
let k_float = 2 let k_float = 2
let max_regs = 64 let max_regs = 64
let classf_gc = 0x01 let classf_gc = 0x01
(* databasev2 2: spare bits of the same flags word — see runtime/src/wob.h *)
let classf_volatile = 0x02
let classf_resident_keys = 0x04
(* v8: has @table. The runtime's durability rules apply to these classes only;
the two bits above are meaningful — and loader-accepted — only with it. *)
let classf_table = 0x08
let op_nop = 0 let op_nop = 0
let op_loadk = 1 let op_loadk = 1
@ -288,7 +298,13 @@ let b_text_of_bytes = 83
let b_sha1 = 85 let b_sha1 = 85
let b_sha256 = 86 let b_sha256 = 86
let b_hmac_sha256 = 87 let b_hmac_sha256 = 87
(* runtime-v2 8 phase A: ChaCha20-Poly1305 AEAD (ids match wob.h 111/112) *)
let b_chacha20poly1305_seal = 111
let b_chacha20poly1305_open = 112
let b_aes_gcm_seal = 113
let b_aes_gcm_open = 114
let b_call = 88 let b_call = 88
let b_monitor = 89
let b_split = 28 let b_split = 28
let b_split_ws = 29 let b_split_ws = 29
let b_join = 30 let b_join = 30
@ -393,6 +409,10 @@ let code_push (c : code) (v : int) : unit =
type clsrec = { type clsrec = {
cr_name : string; cr_name : string;
cr_gc : bool; cr_gc : bool;
(* databasev2 2: storage properties, spelled as the DEFAULT here so a
non-table class (union payload records below) trivially gets flags 0 *)
cr_durable : bool;
cr_resident_keys : bool;
cr_fields : (string * Ast.field_ty) array; cr_fields : (string * Ast.field_ty) array;
cr_methods : string list; (* method names, declaration order *) cr_methods : string list; (* method names, declaration order *)
(* iteration 9 Task 4: (unique, column indices) per secondary index — (* iteration 9 Task 4: (unique, column indices) per secondary index —
@ -1088,6 +1108,10 @@ let builtin_ret (name : string) (argty : Ast.field_ty option) : Ast.field_ty opt
| "bytes_eq" -> Some (Scalar "Bool") | "bytes_eq" -> Some (Scalar "Bool")
| "bytes_slice" | "bytes_concat" | "bytes_of_text" -> Some (Scalar "Bytes") | "bytes_slice" | "bytes_concat" | "bytes_of_text" -> Some (Scalar "Bytes")
| "sha1" | "sha256" | "hmac_sha256" -> Some (Scalar "Bytes") | "sha1" | "sha256" | "hmac_sha256" -> Some (Scalar "Bytes")
| "chacha20poly1305_seal" -> Some (Scalar "Bytes")
| "chacha20poly1305_open" -> Some (Nullable (Scalar "Bytes"))
| "aes_gcm_seal" -> Some (Scalar "Bytes")
| "aes_gcm_open" -> Some (Nullable (Scalar "Bytes"))
| "base64_decode" -> Some (Nullable (Scalar "Bytes")) | "base64_decode" -> Some (Nullable (Scalar "Bytes"))
| _ -> None | _ -> None
@ -1100,13 +1124,16 @@ let is_builtin_name (n : string) =
"substr"; "trim"; "to_lower"; "char_of"; "parse_int"; "split"; "split_ws"; "join"; "slice"; "substr"; "trim"; "to_lower"; "char_of"; "parse_int"; "split"; "split_ws"; "join"; "slice";
"pop"; "shift"; "sort"; "reverse"; "remove"; "key_at"; "val_at"; "pop"; "shift"; "sort"; "reverse"; "remove"; "key_at"; "val_at";
(* the concurrency arc *) (* the concurrency arc *)
"send"; "call"; "send"; "call"; "monitor";
(* iteration 19: Float bridges and Bytes surface *) (* iteration 19: Float bridges and Bytes surface *)
"float"; "trunc"; "parse_float"; "float_to_text"; "float_cmp"; "bytes_len"; "bytes_at"; "float"; "trunc"; "parse_float"; "float_to_text"; "float_cmp"; "bytes_len"; "bytes_at";
"bytes_slice"; "bytes_eq"; "bytes_concat"; "base64_encode"; "base64_decode"; "bytes_slice"; "bytes_eq"; "bytes_concat"; "base64_encode"; "base64_decode";
"bytes_of_text"; "text_of_bytes"; "bytes_of_text"; "text_of_bytes";
(* iteration 34: digests *) (* iteration 34: digests *)
"sha1"; "sha256"; "hmac_sha256" ] "sha1"; "sha256"; "hmac_sha256";
(* runtime-v2 8 phase A: AEAD *)
"chacha20poly1305_seal"; "chacha20poly1305_open";
"aes_gcm_seal"; "aes_gcm_open" ]
(* ---- unions and variants (haxe-parity Task 4) ------------------------ (* ---- unions and variants (haxe-parity Task 4) ------------------------
@ -1154,6 +1181,12 @@ let query_elem_scalar (p : pctx) (q : Ast.query) ~(src : string) : string =
| None -> "Int") | None -> "Int")
| _ -> "Int" | _ -> "Int"
(* `try … catch (e) nil`: the catch arm's value is the literal nil *)
let try_handler_is_nil (handler : Ast.stmt list) : bool =
match List.rev handler with
| { Ast.s_kind = Ast.ExprStmt { Ast.kind = Ast.NilLit; _ }; _ } :: _ -> true
| _ -> false
let rec ty_of_expr (p : pctx) (f : fstate) (e : Ast.expr) : Ast.field_ty option = let rec ty_of_expr (p : pctx) (f : fstate) (e : Ast.expr) : Ast.field_ty option =
match e.kind with match e.kind with
| IntLit _ -> Some (Scalar "Int") | IntLit _ -> Some (Scalar "Int")
@ -1169,8 +1202,14 @@ let rec ty_of_expr (p : pctx) (f : fstate) (e : Ast.expr) : Ast.field_ty option
| NilLit -> None | NilLit -> None
| As (_, ty) -> Some (Nullable ty) | As (_, ty) -> Some (Nullable ty)
(* haxe-parity Task 5: a `try` yields its try arm's type — types.ml has (* haxe-parity Task 5: a `try` yields its try arm's type — types.ml has
already required the catch arm to agree. *) already required the catch arm to agree. A `catch (e) nil` arm makes it
| Try t -> ty_of_expr p f t.body `?T`, so a `?scalar`'s nil is the sentinel and an Int body's 0 stays 0
(lang-41 side defect). *)
| Try t -> (
match ty_of_expr p f t.body with
| Some (Nullable _) as n -> n
| Some bt when try_handler_is_nil t.handler -> Some (Nullable bt)
| other -> other)
| Ident n -> ( | Ident n -> (
match List.assoc_opt n f.f_env with match List.assoc_opt n f.f_env with
| Some (_, t) -> Some t | Some (_, t) -> Some t
@ -2642,7 +2681,13 @@ and emit_try (p : pctx) (f : fstate) (v : views) ~(dst : int) ?expected (e : Ast
f.f_cur_line <- last.Ast.s_pos.line; f.f_cur_line <- last.Ast.s_pos.line;
(match expected with (match expected with
| Some t -> emit_expr p f v ~dst ~expected:t ve | Some t -> emit_expr p f v ~dst ~expected:t ve
| None -> emit_expr p f v ~dst ve); | None -> (
(* a `nil` arm takes the try's own type as its destination: `?Int`
selects the scalar sentinel, so an `Int` body's legitimate 0 is
never read as nil (lang-41 side defect; see ty_of_expr's Try) *)
match (if is_nil_lit ve then ty_of_expr p f e else None) with
| Some t -> emit_expr p f v ~dst ~expected:t ve
| None -> emit_expr p f v ~dst ve));
(* iteration 24 fix (the catch half of the arm-copy rule): a bare (* iteration 24 fix (the catch half of the arm-copy rule): a bare
`e.msg` arm aliases the Error record's field, and the record is `e.msg` arm aliases the Error record's field, and the record is
dropped at CATCH scope end below — ASan-confirmed use-after-free dropped at CATCH scope end below — ASan-confirmed use-after-free
@ -3431,11 +3476,18 @@ and emit_call (p : pctx) (f : fstate) (v : views) ~(dst : int) ?expected (e : As
put f (ins_abc op_builtin dst base sm.Types.sm_builtin); put f (ins_abc op_builtin dst base sm.Types.sm_builtin);
(* every stdlib member only READS its arguments, so one that was (* every stdlib member only READS its arguments, so one that was
freshly built here (`net.write(c, head .. resp.body)`) has no freshly built here (`net.write(c, head .. resp.body)`) has no
other owner and dies with the call *) other owner and dies with the call. The ONE exception:
`time.after`'s message (arg 2) MOVES to the runtime — the
timer owns it until delivery (iteration 24 T5). *)
let moves i =
alias = "time" && mname = "after" && i = 2
in
List.iteri List.iteri
(fun i (a : Ast.expr) -> (fun i (a : Ast.expr) ->
if not (moves i) then begin
drop_fresh_owned ~keep:dst p f (base + i) a; drop_fresh_owned ~keep:dst p f (base + i) a;
drop_fresh_text ~keep:dst p f (base + i) a) drop_fresh_text ~keep:dst p f (base + i) a
end)
args args
end) end)
| Some u -> ( | Some u -> (
@ -3678,6 +3730,9 @@ and emit_builtin (p : pctx) (f : fstate) (v : views) ~(dst : int) ?expected (e :
(* iteration 24, two arguments *) (* iteration 24, two arguments *)
|| id = b_call || id = b_call
then 2 then 2
else if id = b_chacha20poly1305_seal || id = b_chacha20poly1305_open
|| id = b_aes_gcm_seal || id = b_aes_gcm_open then 4
(* rv2 8: (key, nonce, aad, plaintext|ciphertext) *)
else 3 (* b_bytes_slice lands here with substr's shape: (value, start, len) *) else 3 (* b_bytes_slice lands here with substr's shape: (value, start, len) *)
in in
let container_id first_arg on_multi on_map = let container_id first_arg on_multi on_map =
@ -3712,7 +3767,7 @@ and emit_builtin (p : pctx) (f : fstate) (v : views) ~(dst : int) ?expected (e :
dangle the value just read) and the stores, which either copy (Text, dangle the value just read) and the stores, which either copy (Text,
handled by copied_container_call) or take ownership (OWNED/GCREF). *) handled by copied_container_call) or take ownership (OWNED/GCREF). *)
let reader = List.mem name [ "get"; "latest"; "key_at"; "val_at" ] in let reader = List.mem name [ "get"; "latest"; "key_at"; "val_at" ] in
(if not (List.mem name [ "push"; "set"; "send"; "call" ]) then (if not (List.mem name [ "push"; "set"; "send"; "call"; "monitor" ]) then
List.iteri List.iteri
(fun i (a : Ast.expr) -> (fun i (a : Ast.expr) ->
(* a reader's result points into arg0 (the container) — dropping (* a reader's result points into arg0 (the container) — dropping
@ -3744,6 +3799,7 @@ and emit_builtin (p : pctx) (f : fstate) (v : views) ~(dst : int) ?expected (e :
match name with match name with
| "send" -> fixed b_send (* arc: msg (arg1) moved to the runtime — never dropped here *) | "send" -> fixed b_send (* arc: msg (arg1) moved to the runtime — never dropped here *)
| "call" -> fixed b_call (* iteration 24: same move; the SCALAR reply lands in dst *) | "call" -> fixed b_call (* iteration 24: same move; the SCALAR reply lands in dst *)
| "monitor" -> fixed b_monitor (* T4: notice msg (arg2) moves to the runtime *)
| "now" -> fixed b_now | "now" -> fixed b_now
| "print" -> fixed b_print | "print" -> fixed b_print
| "print_int" -> fixed b_print_int | "print_int" -> fixed b_print_int
@ -3796,6 +3852,10 @@ and emit_builtin (p : pctx) (f : fstate) (v : views) ~(dst : int) ?expected (e :
| "sha1" -> fixed b_sha1 | "sha1" -> fixed b_sha1
| "sha256" -> fixed b_sha256 | "sha256" -> fixed b_sha256
| "hmac_sha256" -> fixed b_hmac_sha256 | "hmac_sha256" -> fixed b_hmac_sha256
| "chacha20poly1305_seal" -> fixed b_chacha20poly1305_seal
| "chacha20poly1305_open" -> fixed b_chacha20poly1305_open
| "aes_gcm_seal" -> fixed b_aes_gcm_seal
| "aes_gcm_open" -> fixed b_aes_gcm_open
| "multi_new" | "map_new" -> | "multi_new" | "map_new" ->
let is_map = name = "map_new" in let is_map = name = "map_new" in
if args <> [] then bad (Printf.sprintf "builtin `%s` takes no arguments" name) if args <> [] then bad (Printf.sprintf "builtin `%s` takes no arguments" name)
@ -4765,6 +4825,14 @@ let emit ?(entry_ok : string -> bool = fun _ -> true) ~(syms : Types.symbols)
cfg.Ast.indexes cfg.Ast.indexes
| None -> ()); | None -> ());
{ cr_name = c.name; cr_gc = Types.is_gc_class syms c.name; { cr_name = c.name; cr_gc = Types.is_gc_class syms c.name;
cr_durable =
(match c.Ast.table with
| Some cfg -> cfg.Ast.durable
| None -> true);
cr_resident_keys =
(match c.Ast.table with
| Some cfg -> cfg.Ast.resident = Ast.ResKeys
| None -> false);
cr_fields = cr_fields =
Array.of_list Array.of_list
(List.filter_map (List.filter_map
@ -4802,7 +4870,8 @@ let emit ?(entry_ok : string -> bool = fun _ -> true) ~(syms : Types.symbols)
class_id := SM.add key cid !class_id; class_id := SM.add key cid !class_id;
incr nclasses; incr nclasses;
classes := classes :=
{ cr_name = key; cr_gc = false; cr_indexes = []; cr_is_table = false; { cr_name = key; cr_gc = false; cr_durable = true;
cr_resident_keys = false; cr_indexes = []; cr_is_table = false;
cr_backlinks = []; cr_backlinks = [];
cr_fields = Array.of_list vd.Ast.v_fields; cr_fields = Array.of_list vd.Ast.v_fields;
cr_methods = [] } cr_methods = [] }
@ -4846,7 +4915,9 @@ let emit ?(entry_ok : string -> bool = fun _ -> true) ~(syms : Types.symbols)
class_id := SM.add name cid !class_id; class_id := SM.add name cid !class_id;
incr nclasses; incr nclasses;
classes := classes :=
{ cr_name = name; cr_gc = false; cr_fields = Array.of_list fields; cr_methods = []; (* not a @table (a predeclared record), so storage flags stay 0 *)
{ cr_name = name; cr_gc = false; cr_durable = true; cr_resident_keys = false;
cr_fields = Array.of_list fields; cr_methods = [];
cr_indexes = []; cr_is_table = false; cr_backlinks = [] } cr_indexes = []; cr_is_table = false; cr_backlinks = [] }
:: !classes :: !classes
end) end)
@ -5023,7 +5094,11 @@ let emit ?(entry_ok : string -> bool = fun _ -> true) ~(syms : Types.symbols)
Array.iteri Array.iteri
(fun cid (c : clsrec) -> (fun cid (c : clsrec) ->
Buf.u32 cls class_name_k.(cid); Buf.u32 cls class_name_k.(cid);
Buf.u32 cls (if c.cr_gc then classf_gc else 0); Buf.u32 cls
((if c.cr_gc then classf_gc else 0)
lor (if c.cr_durable then 0 else classf_volatile)
lor (if c.cr_resident_keys then classf_resident_keys else 0)
lor (if c.cr_is_table then classf_table else 0));
Buf.u32 cls (Array.length c.cr_fields); Buf.u32 cls (Array.length c.cr_fields);
Array.iter (fun (_, ty) -> Buf.u8 cls (field_kind p ty)) c.cr_fields; Array.iter (fun (_, ty) -> Buf.u8 cls (field_kind p ty)) c.cr_fields;
let pad = (4 - (Array.length c.cr_fields mod 4)) mod 4 in let pad = (4 - (Array.length c.cr_fields mod 4)) mod 4 in

View file

@ -69,7 +69,8 @@
a place where this pass is wrong-by-accident: a place where this pass is wrong-by-accident:
- No partial moves. A move site must name a whole local (`x`), never - No partial moves. A move site must name a whole local (`x`), never
a projection (`x.f`, `x[0]`); see the `let` case above. a projection (`x.f`, `x[0]`); see the `let` case above. A projection
at a transfer site is WO-E305, not a silent alias (transfer).
- Alias provability is syntactic *after canonicalization*: a place - Alias provability is syntactic *after canonicalization*: a place
written through a borrow binding is first rewritten to the storage written through a borrow binding is first rewritten to the storage
that borrow names (see canon), then two places overlap only if they that borrow names (see canon), then two places overlap only if they
@ -131,6 +132,15 @@ let conflicting_borrow_code = Diag.ownership_prefix ^ "03"
escape. Related: where the borrow was created. *) escape. Related: where the borrow was created. *)
let borrow_escape_code = Diag.ownership_prefix ^ "04" let borrow_escape_code = Diag.ownership_prefix ^ "04"
(* WO-E305 — an owned value is moved out of a field or element (`x.f`,
`x[i]`) while its record/container still owns it: stored into a record,
pushed into a container, passed to a `take` parameter, or returned.
Milestone 1 has no partial moves, and silently allowing the store put one
owned value under two owners — a double free at the second drop (the
lang-41 side defect). Heap scalars are exempt: every store site copies
them (stores_by_copy). Primary site: the move. Related: the owner. *)
let partial_move_code = Diag.ownership_prefix ^ "05"
(* ============================================================ (* ============================================================
Ownership classes and places Ownership classes and places
============================================================ *) ============================================================ *)
@ -1112,7 +1122,22 @@ let transfer (ctx : ctx) (p : place) ~(what : string) : bool =
| Moved _ -> false (* already reported at the read *) | Moved _ -> false (* already reported at the read *)
| Borrowed _ -> false (* unreachable: is_borrow_root covered it *) | Borrowed _ -> false (* unreachable: is_borrow_root covered it *)
| Live -> | Live ->
if p.projs <> [] then false (* no partial moves in milestone 1 *) if p.projs <> [] then begin
(* no partial moves in milestone 1 — and no silent alias either:
the record/container still owns this place, so the transfer
would give one owned value two owners (WO-E305) *)
if not (stores_by_copy ctx p) then
report ctx ~code:partial_move_code ~pos:p.ppos
~message:
(Printf.sprintf
"`%s` %s — it is part of `%s`, and an owned value cannot be moved out of a \
field or element (no partial moves): move `%s` whole, or build a fresh \
container from its elements"
(place_text p) what l.l_name l.l_name)
~rel:l.l_pos
~label:(Printf.sprintf "`%s` owns it" l.l_name);
false
end
else begin else begin
check_against_borrows ctx ~node:p.pnode ~pos:p.ppos p AMove; check_against_borrows ctx ~node:p.pnode ~pos:p.ppos p AMove;
l.l_state <- Moved p.ppos; l.l_state <- Moved p.ppos;
@ -1348,6 +1373,10 @@ and analyze_call (ctx : ctx) (call_e : Ast.expr) (callee : Ast.expr) (args : Ast
iteration 24: call(addr, msg) moves its message identically. *) iteration 24: call(addr, msg) moves its message identically. *)
| Ident "send" -> i = 1 && Types.StringMap.find_opt "send" ctx.syms.Types.free_fns = None | Ident "send" -> i = 1 && Types.StringMap.find_opt "send" ctx.syms.Types.free_fns = None
| Ident "call" -> i = 1 && Types.StringMap.find_opt "call" ctx.syms.Types.free_fns = None | Ident "call" -> i = 1 && Types.StringMap.find_opt "call" ctx.syms.Types.free_fns = None
(* T4/T5: the notice / timer message moves to the runtime too *)
| Ident "monitor" ->
i = 2 && Types.StringMap.find_opt "monitor" ctx.syms.Types.free_fns = None
| Field ({ kind = Ident "time"; _ }, "after") -> i = 2
| _ -> false | _ -> false
in in
List.iteri List.iteri
@ -1365,7 +1394,8 @@ and analyze_call (ctx : ctx) (call_e : Ast.expr) (callee : Ast.expr) (args : Ast
transfer ctx p transfer ctx p
~what: ~what:
(match callee.kind with (match callee.kind with
| Ident "send" | Ident "call" -> | Ident "send" | Ident "call" | Ident "monitor"
| Field ({ kind = Ident "time"; _ }, "after") ->
"cannot be sent — a message moves to the receiver" "cannot be sent — a message moves to the receiver"
| _ -> "cannot be stored in a container") | _ -> "cannot be stored in a container")
then record_move ctx p (MvArg "element")) then record_move ctx p (MvArg "element"))

View file

@ -299,8 +299,20 @@ let skip_paren_args (st : state) : unit =
done done
end end
(* databasev2 2: the retired vocabulary. The brainstorm explored `ram`, `cold`,
`tiered`, `paged`, `mmap` and `buffer` as `@table` modes and settled on two
keys instead. Naming them here buys a message that says what to write, so a
word from a rejected design does not turn into folklore in user code. *)
let retired_table_words = [ "ram"; "cold"; "tiered"; "paged"; "mmap"; "buffer"; "mode"; "store" ]
let parse_table_cfg (st : state) : Ast.table_cfg = let parse_table_cfg (st : state) : Ast.table_cfg =
let cfg = ref { Ast.table_name = None; indexes = [] } in let cfg =
ref { Ast.table_name = None; indexes = []; durable = true; resident = Ast.ResAll }
in
(* seen-flags, not `option` fields: both properties have a real default, so
absence and "explicitly set to the default" must stay distinguishable for
the given-twice check without making the AST carry an option nobody reads *)
let saw_durable = ref false and saw_resident = ref false in
if accept st Token.LParen then begin if accept st Token.LParen then begin
let continue_ = ref true in let continue_ = ref true in
while !continue_ do while !continue_ do
@ -330,9 +342,49 @@ let parse_table_cfg (st : state) : Ast.table_cfg =
if !cols = [] then if !cols = [] then
fail st (peek_pos st) table_code "@table index needs at least one column"; fail st (peek_pos st) table_code "@table index needs at least one column";
cfg := { !cfg with Ast.indexes = !cfg.Ast.indexes @ [ List.rev !cols ] } cfg := { !cfg with Ast.indexes = !cfg.Ast.indexes @ [ List.rev !cols ] }
(* databasev2 2: durability, per table. Replaces the process-global
WO_DATA all-or-nothing — a scratch table stops paying the fsync a
precious one needs. *)
| "durable" ->
if !saw_durable then
fail st (peek_pos st) table_code "@table(durable: ...) given twice";
saw_durable := true;
(match peek st with
| Token.KwTrue ->
ignore (advance st);
cfg := { !cfg with Ast.durable = true }
| Token.KwFalse ->
ignore (advance st);
cfg := { !cfg with Ast.durable = false }
| _ -> unexpected st "`true` or `false` for @table durable")
(* databasev2 2: residency, per table. `keys` is the 120-GB-on-32-GB
case — indexes resident, rows read from the log by offset. *)
| "resident" ->
if !saw_resident then
fail st (peek_pos st) table_code "@table(resident: ...) given twice";
saw_resident := true;
let v = expect_ident st "`all` or `keys` for @table resident" in
(match v with
| "all" -> cfg := { !cfg with Ast.resident = Ast.ResAll }
| "keys" -> cfg := { !cfg with Ast.resident = Ast.ResKeys }
| "index" ->
fail st (peek_pos st) table_code
"@table(resident: index) — renamed to `keys` (it collided with \
the `index:` argument); write `resident: keys`"
| other -> | other ->
fail st (peek_pos st) table_code fail st (peek_pos st) table_code
(Printf.sprintf "unknown @table argument `%s` (supported: name, index)" other)); (Printf.sprintf
"unknown @table resident value `%s` (supported: all, keys)" other))
| other when List.mem other retired_table_words ->
fail st (peek_pos st) table_code
(Printf.sprintf
"`%s` is not a @table argument — storage is declared with two \
keys: `durable: true|false` and `resident: all|keys`" other)
| other ->
fail st (peek_pos st) table_code
(Printf.sprintf
"unknown @table argument `%s` (supported: name, index, durable, \
resident)" other));
skip_newlines st; skip_newlines st;
if not (accept st Token.Comma) then begin if not (accept st Token.Comma) then begin
skip_newlines st; skip_newlines st;
@ -342,6 +394,16 @@ let parse_table_cfg (st : state) : Ast.table_cfg =
end end
done done
end; end;
(* databasev2 2: rows that are neither logged nor resident have nowhere to
live. Checked here, after the whole argument list is known, because it is
a property of the COMBINATION rather than of either argument. The loader
refuses it again (runtime/src/wob.h, loader.c) on the principle that what
the loader accepts the interpreter trusts — but a compile error is the one
a developer can act on. *)
if (not !cfg.Ast.durable) && !cfg.Ast.resident = Ast.ResKeys then
fail st (peek_pos st) table_code
"@table(durable: false, resident: keys): rows would be neither logged \
nor resident, so there is nowhere to read them from — pick one";
!cfg !cfg
type type_annotations = { type type_annotations = {

View file

@ -203,7 +203,7 @@ let numeric_world (t : string) : [ `Int | `Float | `Other ] =
single-segment names (`check_use_edges` below treats any one-segment single-segment names (`check_use_edges` below treats any one-segment
`use` path whose name is in this list as stdlib, unconditionally, `use` path whose name is in this list as stdlib, unconditionally,
never as a project directory search). *) never as a project directory search). *)
let stdlib_modules = [ "fs"; "proc"; "net"; "time"; "json"; "env" ] let stdlib_modules = [ "fs"; "proc"; "net"; "time"; "json"; "env"; "signal"; "term" ]
let is_stdlib_module (name : string) : bool = List.mem name stdlib_modules let is_stdlib_module (name : string) : bool = List.mem name stdlib_modules
@ -257,9 +257,33 @@ let proc_record_name = "Proc"
let proc_record_fields : (string * field_ty) list = let proc_record_fields : (string * field_ty) list =
[ ("code", Scalar "Int"); ("out", Scalar "Text"); ("err", Scalar "Text") ] [ ("code", Scalar "Int"); ("out", Scalar "Text"); ("err", Scalar "Text") ]
(* runtime-v2 1: the streaming child. The fds are ordinary conn-shaped
Ints the net verbs drive; stderr is -1 on a PTY child (master carries
both streams). The id refuses stale handles by name at runtime. *)
let child_record_name = "Child"
let child_record_fields : (string * field_ty) list =
[ ("id", Scalar "Int"); ("stdin", Scalar "Int"); ("stdout", Scalar "Int");
("stderr", Scalar "Int") ]
(* runtime-v2 3: what signal.on delivers — a fresh record per arrival
(message payloads must be heap objects; the runtime drops them). *)
let signal_record_name = "Signal"
let signal_record_fields : (string * field_ty) list = [ ("sig", Scalar "Int") ]
(* runtime-v2 6: term.size's answer; nil = the fd is not a tty *)
let termsize_record_name = "TermSize"
let termsize_record_fields : (string * field_ty) list =
[ ("cols", Scalar "Int"); ("rows", Scalar "Int") ]
let predeclared_records : (string * (string * field_ty) list) list = let predeclared_records : (string * (string * field_ty) list) list =
[ (error_record_name, error_record_fields); (stat_record_name, stat_record_fields); [ (error_record_name, error_record_fields); (stat_record_name, stat_record_fields);
(time_record_name, time_record_fields); (proc_record_name, proc_record_fields) ] (time_record_name, time_record_fields); (proc_record_name, proc_record_fields);
(child_record_name, child_record_fields);
(signal_record_name, signal_record_fields);
(termsize_record_name, termsize_record_fields) ]
(* One member of a reserved stdlib module (`fs.stat`, `net.write`, ...). (* One member of a reserved stdlib module (`fs.stat`, `net.write`, ...).
[sm_builtin] is its .wob builtin id (runtime/src/wob.h); [sm_record] names [sm_builtin] is its .wob builtin id (runtime/src/wob.h); [sm_record] names
@ -309,8 +333,46 @@ let stdlib_members : stdlib_member list =
m "net" "write_dl" 3 93 (Some (TScalar "Bool")) None; m "net" "write_dl" 3 93 (Some (TScalar "Bool")) None;
m "net" "listen_unix" 1 94 (Some (TScalar "Int")) None; m "net" "listen_unix" 1 94 (Some (TScalar "Int")) None;
m "net" "peer" 1 95 (Some (TScalar "Text")) None; m "net" "peer" 1 95 (Some (TScalar "Text")) None;
(* iteration 24 T5: one-shot timer — the msg MOVES to the runtime *)
m "time" "after" 3 90 None None;
(* proc *) (* proc *)
m "proc" "run" 2 56 (Some (TNullable (TScalar proc_record_name))) (Some proc_record_name); m "proc" "run" 2 56 (Some (TNullable (TScalar proc_record_name))) (Some proc_record_name);
(* iteration 42: per-call bounds — deadline_ms, out_cap, err_cap
(<= 0 picks the default: 30 000 ms / 1 MiB / 64 KiB). A bound
violation kills the child and traps WO_T_IO naming the bound. *)
m "proc" "run_dl" 5 96 (Some (TNullable (TScalar proc_record_name))) (Some proc_record_name);
(* runtime-v2 1: the streaming child — fds the net verbs drive; the
caller closes them with net.close. wait_dl: nil = still running at
the deadline (child untouched); one waiter per id. *)
m "proc" "spawn" 2 97 (Some (TNullable (TScalar child_record_name))) (Some child_record_name);
m "proc" "wait_dl" 2 98 (Some (TNullable (TScalar "Int"))) None;
m "proc" "signal" 2 99 None None;
(* runtime-v2 2: the PTY child — stdin==stdout=master, stderr -1;
resize refuses by name on a pipe child *)
m "proc" "spawn_pty" 4 100 (Some (TNullable (TScalar child_record_name))) (Some child_record_name);
m "proc" "resize" 3 101 None None;
(* runtime-v2 3: standing subscription; each arrival delivers a fresh
Signal {sig} record to the actor. SIGTERM/SIGINT refused (the stop
latch). Coalescing disclosed. *)
m "signal" "on" 2 102 None (Some signal_record_name);
(* runtime-v2 4: raw mode on a tty the process was GIVEN; restore is
a runtime obligation (unwind/stop), never only the caller's *)
m "term" "raw" 1 103 None None;
m "term" "restore" 1 104 None None;
(* runtime-v2 5: SCM_RIGHTS over unix sockets, one fd per message;
the received fd is a plain Int every fd verb accepts *)
m "net" "send_fd" 2 105 (Some (TScalar "Bool")) None;
m "net" "recv_fd" 1 106 (Some (TNullable (TScalar "Int"))) None;
m "net" "connect_unix" 1 107 (Some (TScalar "Int")) None;
m "net" "connect" 2 110 (Some (TScalar "Int")) None;
m "net" "connect_tls" 2 115 (Some (TScalar "Int")) None;
m "net" "read_tls" 2 116 (Some (TScalar "Text")) None;
m "net" "write_tls" 2 117 None None;
m "net" "accept_tls" 3 118 (Some (TScalar "Int")) None;
(* runtime-v2 6: resize's read twin (nil = not a tty), and a
codepoint's terminal cell width (libc wcwidth under C.UTF-8) *)
m "term" "size" 1 108 (Some (TNullable (TScalar termsize_record_name))) (Some termsize_record_name);
m "term" "width" 1 109 (Some (TScalar "Int")) None;
(* json — both members are lowered specially (emit.ml): encode needs its (* json — both members are lowered specially (emit.ml): encode needs its
argument's static kind, and decode has no type until an `as` names one, argument's static kind, and decode has no type until an `as` names one,
so neither goes through the generic builtin path. They are listed here so neither goes through the generic builtin path. They are listed here
@ -468,6 +530,14 @@ let private_name_code = Diag.types_prefix ^ "17" (* WO-E217 *)
let use_collision_code = Diag.types_prefix ^ "18" (* WO-E218 *) let use_collision_code = Diag.types_prefix ^ "18" (* WO-E218 *)
let unused_use_code = Diag.warning_prefix ^ "202" (* WO-W202 *) let unused_use_code = Diag.warning_prefix ^ "202" (* WO-W202 *)
let dangling_ref_code = Diag.types_prefix ^ "24"
(* WO-E224 (databasev2 2): a durable table holding a `ref` into a volatile one.
The referencing row survives a restart; the referenced row does not, so the
stored row id dangles and FK-restrict cannot help — restrict asks "does a
row reference this?", and after a restart the answer is a truthful no while
the id is still sitting in a durable slot. Provable from the class table, so
it fails at compile time rather than becoming a wrong query result. *)
let unknown_type_name_code = Diag.types_prefix ^ "25" (* WO-E225 *) let unknown_type_name_code = Diag.types_prefix ^ "25" (* WO-E225 *)
(* iteration 36: a LITERAL shift count outside 0..63 — rejected here so (* iteration 36: a LITERAL shift count outside 0..63 — rejected here so
@ -678,6 +748,19 @@ let rec scalar_name_of (ft : field_ty) : string option =
| Nullable inner -> scalar_name_of inner | Nullable inner -> scalar_name_of inner
| Ref _ | Multi _ | Map _ | Backlink _ | Actor _ -> None | Ref _ | Multi _ | Map _ | Backlink _ | Actor _ -> None
(* databasev2 2: the target class of a `ref` field, through any `?` wrapper.
Only `Ref` stores a row id, which is why this exists and why the
durable/volatile check below looks at nothing else — a `Backlink` is the
computed inverse of a ref and stores NO column (ast.ml), so after a restart
it resolves to an empty collection, which is a legal state indistinguishable
from "nothing references me". Checking backlinks would refuse correct
programs. *)
let rec ref_name_of (ft : field_ty) : string option =
match ft with
| Ref name -> Some name
| Nullable inner -> ref_name_of inner
| Scalar _ | Multi _ | Map _ | Backlink _ | Actor _ -> None
(* Checked once per field declaration (not at every access/use site), so (* Checked once per field declaration (not at every access/use site), so
the diagnostic lands at the field's own declaration position and the diagnostic lands at the field's own declaration position and
never fires more than once for the same bad field. Runs over the raw never fires more than once for the same bad field. Runs over the raw
@ -695,15 +778,42 @@ let check_field_types ~file (syms : symbols) (collector : Diag.Collector.t)
name name
| _ -> Printf.sprintf "unknown type `%s`" name | _ -> Printf.sprintf "unknown type `%s`" name
in in
(* databasev2 2: is this class a table, and is it durable? A non-table
declaring class cannot dangle across a restart because it does not
survive one, so only a durable TABLE is checked. *)
let durable_table (t : Ast.table_cfg option) : bool =
match t with Some cfg -> cfg.Ast.durable | None -> false
in
let volatile_table (name : string) : bool =
match StringMap.find_opt name syms.classes with
| Some ci -> (match ci.table with Some cfg -> not cfg.Ast.durable | None -> false)
| None -> false
in
List.iter (function List.iter (function
| Ast.Class c -> | Ast.Class c ->
List.iter (fun (f : Ast.field) -> List.iter (fun (f : Ast.field) ->
match scalar_name_of f.ty with (match scalar_name_of f.ty with
| Some name when not (is_known_type_name syms name) -> | Some name when not (is_known_type_name syms name) ->
Diag.Collector.add collector Diag.Collector.add collector
(Diag.error ~code:unknown_type_name_code ~file (Diag.error ~code:unknown_type_name_code ~file
~line:f.pos.line ~col:f.pos.col ~line:f.pos.line ~col:f.pos.col
~message:(unknown_type_msg name) ()) ~message:(unknown_type_msg name) ())
| _ -> ());
(* databasev2 2: WO-E224. Only the durable -> volatile direction is
refused; volatile -> durable is legal (the referencing row is the
one that disappears, so nothing is left holding a stale id). *)
match ref_name_of f.ty with
| Some target when durable_table c.table && volatile_table target ->
Diag.Collector.add collector
(Diag.error ~code:dangling_ref_code ~file
~line:f.pos.line ~col:f.pos.col
~message:
(Printf.sprintf
"durable table `%s` cannot hold `ref %s`: `%s` is declared \
`durable: false`, so its rows are gone after a restart and \
this stored row id would dangle — FK restrict cannot catch \
it. Make `%s` durable, or declare `%s` `durable: false` too"
c.name target target target c.name) ())
| _ -> () | _ -> ()
) c.fields ) c.fields
| Ast.Union u -> | Ast.Union u ->
@ -847,6 +957,12 @@ let builtin_signatures : (string * int * builtin_arg_req list) list =
("sha1", 1, [ ReqBytes ]); ("sha1", 1, [ ReqBytes ]);
("sha256", 1, [ ReqBytes ]); ("sha256", 1, [ ReqBytes ]);
("hmac_sha256", 2, [ ReqBytes; ReqBytes ]); ("hmac_sha256", 2, [ ReqBytes; ReqBytes ]);
(* runtime-v2 8 phase A: ChaCha20-Poly1305 AEAD. (key, nonce, aad,
plaintext|ciphertext). seal -> Bytes; open -> ?Bytes (nil on auth fail). *)
("chacha20poly1305_seal", 4, [ ReqBytes; ReqBytes; ReqBytes; ReqBytes ]);
("chacha20poly1305_open", 4, [ ReqBytes; ReqBytes; ReqBytes; ReqBytes ]);
("aes_gcm_seal", 4, [ ReqBytes; ReqBytes; ReqBytes; ReqBytes ]);
("aes_gcm_open", 4, [ ReqBytes; ReqBytes; ReqBytes; ReqBytes ]);
] ]
let rec unwrap_nullable (t : typ) : typ = let rec unwrap_nullable (t : typ) : typ =
@ -1053,6 +1169,10 @@ let builtin_confident_ret (name : string) (arg0 : typ option) : typ option =
| "bytes_eq" -> Some (TScalar "Bool") | "bytes_eq" -> Some (TScalar "Bool")
| "bytes_slice" | "bytes_concat" | "bytes_of_text" -> Some (TScalar "Bytes") | "bytes_slice" | "bytes_concat" | "bytes_of_text" -> Some (TScalar "Bytes")
| "sha1" | "sha256" | "hmac_sha256" -> Some (TScalar "Bytes") | "sha1" | "sha256" | "hmac_sha256" -> Some (TScalar "Bytes")
| "chacha20poly1305_seal" -> Some (TScalar "Bytes")
| "chacha20poly1305_open" -> Some (TNullable (TScalar "Bytes"))
| "aes_gcm_seal" -> Some (TScalar "Bytes")
| "aes_gcm_open" -> Some (TNullable (TScalar "Bytes"))
(* malformed base64 is nil, not a trap: it arrives from the network *) (* malformed base64 is nil, not a trap: it arrives from the network *)
| "base64_decode" -> Some (TNullable (TScalar "Bytes")) | "base64_decode" -> Some (TNullable (TScalar "Bytes"))
| _ -> None | _ -> None
@ -1869,6 +1989,48 @@ let typecheck_program ~file ~(module_of : string -> string)
~message:"`call`'s first argument must be an `actor M` address" ()) ~message:"`call`'s first argument must be an `actor M` address" ())
| None -> ()) | None -> ())
| _ -> ()) | _ -> ())
| None when name = "monitor" ->
(* iteration 24 T4: monitor(watched, observer, msg) — the
notice msg is typed against the OBSERVER's mailbox
(three-argument form: the caller may be main, which has
no mailbox). msg moves like send's. *)
(if List.length args <> 3 then
Diag.Collector.add collector
(Diag.error ~code:bad_arity_code ~file ~line:e.pos.line ~col:e.pos.col
~message:
(Printf.sprintf
"`monitor` takes 3 arguments (watched, observer, notice), given %d"
(List.length args))
())
else
match args with
| [ w; o; m ] -> (
(match confident_typ cenv w with
| Some (TActor _) | None -> ()
| Some _ ->
Diag.Collector.add collector
(Diag.error ~code:type_mismatch_code ~file ~line:w.pos.line
~col:w.pos.col
~message:"`monitor`'s first argument must be an `actor M` address" ()));
match confident_typ cenv o with
| Some (TActor want) -> (
match confident_typ cenv m with
| Some (TScalar got) when got <> want ->
Diag.Collector.add collector
(Diag.error ~code:type_mismatch_code ~file ~line:m.pos.line
~col:m.pos.col
~message:
(Printf.sprintf
"the observer receives `%s` — the notice is a `%s`" want got)
())
| _ -> ())
| Some _ ->
Diag.Collector.add collector
(Diag.error ~code:type_mismatch_code ~file ~line:o.pos.line
~col:o.pos.col
~message:"`monitor`'s second argument must be an `actor M` address" ())
| None -> ())
| _ -> ())
| None -> | None ->
let confident_types = List.map (confident_typ cenv) args in let confident_types = List.map (confident_typ cenv) args in
check_builtin_call ~file collector name e.pos args confident_types) check_builtin_call ~file collector name e.pos args confident_types)

View file

@ -0,0 +1,9 @@
6:1 CLASS Order @table(name="orders", index=[customer], resident=keys)
7:3 FIELD customer: Text
8:3 FIELD total: Int
12:1 CLASS Session @table(name="sessions", durable=false)
13:3 FIELD token: Text
17:1 CLASS Chapter @table(name="chapters", index=[slug])
18:3 FIELD slug: Text
22:1 CLASS Scratch @table(name="scratch_big", durable=false)
23:3 FIELD k: Text

View file

@ -0,0 +1,24 @@
-- databasev2 2: the two storage arguments. `orders` is the 120-GB-on-32-GB
-- shape (indexes resident, rows read from the log); `sessions` is scratch
-- (never logged, gone on restart); `chapters` states neither and must dump
-- exactly as it did before the arguments existed.
@table(name: "orders", index: [customer], resident: keys)
class Order {
customer: Text
total: Int
}
@table(name: "sessions", durable: false)
class Session {
token: Text
}
@table(name: "chapters", index: [slug])
class Chapter {
slug: Text
}
@table(name: "scratch_big", durable: false, resident: all)
class Scratch {
k: Text
}

View file

@ -535,7 +535,9 @@ let () =
| [ Ast.Class c ] -> | [ Ast.Class c ] ->
check "@table: name and index captured" check "@table: name and index captured"
(match c.table with (match c.table with
| Some { Ast.table_name = Some "prices"; indexes = [ [ "sku"; "at" ] ] } -> true (* `; _` so databasev2 2's durable/resident fields do not have to be
restated here — this check is about name and index capture only *)
| Some { Ast.table_name = Some "prices"; indexes = [ [ "sku"; "at" ] ]; _ } -> true
| _ -> false) | _ -> false)
| _ -> check "@table: exactly one class" false); | _ -> check "@table: exactly one class" false);
let _, bad_collector = parse_str ~file:"bad-table.wo" "@table(shard_key: sku)\ntype T {\n id: Id\n}\n" in let _, bad_collector = parse_str ~file:"bad-table.wo" "@table(shard_key: sku)\ntype T {\n id: Id\n}\n" in
@ -2400,7 +2402,7 @@ let validate_image (img : string) : string list =
let u64 o = if ok 8 o then String.get_int64_le img o else 0L in let u64 o = if ok 8 o then String.get_int64_le img o else 0L in
let none = 0xFFFFFFFF in let none = 0xFFFFFFFF in
if u32 0 <> 0x31424F57 then fail "bad magic"; if u32 0 <> 0x31424F57 then fail "bad magic";
if u32 4 <> 6 then fail "unsupported version"; (* v6: iteration 36 *) if u32 4 <> 8 then fail "unsupported version"; (* v8: databasev2 2 task 6a *)
let coff = u32 8 and ccnt = u32 12 in let coff = u32 8 and ccnt = u32 12 in
let koff = u32 16 and kcnt = u32 20 in let koff = u32 16 and kcnt = u32 20 in
let ioff = u32 24 and icnt = u32 28 in let ioff = u32 24 and icnt = u32 28 in
@ -2437,7 +2439,16 @@ let validate_image (img : string) : string list =
let nm = u32 !o and flags = u32 (!o + 4) and fcnt = u32 (!o + 8) in let nm = u32 !o and flags = u32 (!o + 4) and fcnt = u32 (!o + 8) in
o := !o + 12; o := !o + 12;
if not (text_const nm) then fail (Printf.sprintf "class %d: bad name constant" i); if not (text_const nm) then fail (Printf.sprintf "class %d: bad name constant" i);
if flags land lnot 0x01 <> 0 then fail (Printf.sprintf "class %d: unknown flags" i); (* v7 (databasev2 2): bit1 VOLATILE, bit2 RESIDENT_KEYS; v8 (task 6a): bit3
TABLE. This battery is a deliberately independent reimplementation of
runtime/src/loader.c's validation, so it tracks the same contract —
including refusing the pair that would leave rows neither logged nor
resident, and storage bits on a class that is not a @table. *)
if flags land lnot 0x0f <> 0 then fail (Printf.sprintf "class %d: unknown flags" i);
if flags land 0x02 <> 0 && flags land 0x04 <> 0 then
fail (Printf.sprintf "class %d: durable:false with resident:keys" i);
if flags land 0x06 <> 0 && flags land 0x08 = 0 then
fail (Printf.sprintf "class %d: storage flags on a class that is not a @table" i);
if fcnt > 65535 then fail (Printf.sprintf "class %d: too many fields" i); if fcnt > 65535 then fail (Printf.sprintf "class %d: too many fields" i);
class_fields.(i) <- fcnt; class_fields.(i) <- fcnt;
let kco = !o in (* the kind bytes' offset: the v3 index walk re-reads them *) let kco = !o in (* the kind bytes' offset: the v3 index walk re-reads them *)

View file

@ -23,6 +23,21 @@ VM values ──copy──▶ row slots (engine-owned malloc) ──copy──
the id hash maps id → slot. Ids are never reused (per-table counter, the id hash maps id → slot. Ids are never reused (per-table counter,
shard-interleaved `S+1, S+1+N, …`), which is also what makes the hash's shard-interleaved `S+1, S+1+N, …`), which is also what makes the hash's
tombstone sentinel safe. tombstone sentinel safe.
- **Storage is per-table since databasev2 2.** `@table(durable: false)` sets
`WO_CLASSF_VOLATILE` in the class descriptor (`.wob` v7), and `db.c`'s
`table_is_durable` gates all three mutation sites: a volatile table stages
nothing, so it pays none of the fsync cost and is empty after a restart.
Measured: 50 inserts wrote 1500 WAL bytes durable, **0** volatile. The three
sites stayed three — the predicate is one function, not an inlined condition,
precisely so this file's "nothing else may mutate storage" claim keeps
holding.
- **A mode mismatch refuses, it does not convert.** If the log holds records
for a class the loaded image now declares volatile, `apply_record` returns
**-2** (distinct from -1 corruption) and `wo_wal_replay_ex` reports the class
id so `main.c` can name it. Silently skipping those records would resurrect
nothing but would also hide a real migration; silently applying them would
load rows into a table declared not to have any. `wo_wal_replay` remains as
the NULL-out-param wrapper so the 156 WAL unit checks are untouched.
- **Choke points**: `wo_row_insert` / `wo_row_remove` carry the `INDEX HOOK` - **Choke points**: `wo_row_insert` / `wo_row_remove` carry the `INDEX HOOK`
comments where Task 4's secondary indexes attach and Task 2's WAL stages comments where Task 4's secondary indexes attach and Task 2's WAL stages
its record. Nothing else may mutate storage. its record. Nothing else may mutate storage.
@ -43,15 +58,41 @@ tear). The crash battery in `runtime/test/test_wal.c` is the module's
meaning proven: acked-over-a-pipe after commit, SIGKILL mid-stream, replay, meaning proven: acked-over-a-pipe after commit, SIGKILL mid-stream, replay,
zero acked-but-missing. zero acked-but-missing.
**Where the log lives (databasev2 7, 2026-09-10).** `wo_wal_resolve_data_path`
turns `WO_DATA` into the log path before main.c opens anything: an existing
directory or a trailing `/` → `<dir>/shard-0.wal` byte for byte (the pre-7
form, `//` after a trailing slash included); anything else IS the log —
opened if a regular file, created by `wo_wal_open` if absent. Two refusals,
exit 2, one stderr line each, worded in main.c from the resolver's codes:
`WO_WAL_PATH_NO_PARENT` (the parent comes back in `out`, so the line names
the path AND the parent; no `mkdir -p` — a typo must not plant a store
somewhere unexpected, the operator creates directories, the runtime never
does) and `WO_WAL_PATH_NOT_A_FILE` (fifo, socket, device).
`WO_WAL_PATH_TOO_LONG` refuses what the old 512-byte `snprintf` silently
truncated. A trailing slash on a MISSING directory is still the directory
form and still fails at `wo_wal_open` (`cannot open`), unchanged on purpose.
Nothing below main.c knows which form was used: compaction and migration
build `<log path>.compact` and fsync `parent_dir_of(log path)` — the same
static helper the resolver's parent check uses, so the directory checked at
boot is the directory synced after every rename. Tests:
`test_resolve_data_path` (every arm of the rule, fifo via `mkfifo`) and
`test_file_form_temps_beside_log` (a directory planted at `<file>.compact`
makes compaction and migration refuse with the log untouched; removed, both
succeed and the file is the only artifact beside a decoy sibling directory).
## db.c — statement executors (iteration 9, Task 3) ## db.c — statement executors (iteration 9, Task 3)
One dispatcher, the builtin contract (0 ok, else WO_T_* + msg). The engine One dispatcher, the builtin contract (0 ok, else WO_T_* + msg). The engine
handles ride `wo_rt.db` / `wo_rt.wal` as opaque pointers set by main.c — handles ride `wo_rt.db` / `wo_rt.wal` as opaque pointers set by main.c —
NULL db traps WO_T_DB, NULL wal means RAM-only (the corpus's mode; WO_DATA NULL db traps WO_T_DB, NULL wal means RAM-only — reachable only under
opts into durability). Insert's contract: RAM apply through the row API, WO_EPHEMERAL=1 (or with no durable `@table` in the module) since databasev2 2
then stage + commit BEFORE returning — the builtin's return is the task 6a: a program with any durable `@table` (the default) refuses to start
acknowledgment, so a failed commit un-applies the row and traps WO_T_IO without WO_DATA; WO_EPHEMERAL=1 opts into a RAM-only run (the corpus's mode),
rather than acknowledging what disk never got. @table(durable: false) opts a table out. Insert's contract: RAM apply through
the row API, then stage + commit BEFORE returning — the builtin's return is
the acknowledgment. Once RAM has mutated the outcomes are durable or process
death (`wo_wal_commit_fatal`, `wo_wal_stage_fatal`): a failed commit is
fatal, there is no un-apply, and WO_T_IO is unreachable from a write path.
## Verifying a change ## Verifying a change
@ -104,3 +145,324 @@ rather than acknowledging what disk never got.
columns excluded (engine raw-eq is narrower than VM float-eq, and a columns excluded (engine raw-eq is narrower than VM float-eq, and a
probe miss cannot be resurrected by a recheck). Pinned by probe miss cannot be resurrected by a recheck). Pinned by
`tests/corpus/run/query-index-probe`. `tests/corpus/run/query-index-probe`.
## Group commit: one barrier per drain (databasev2 4 part A, 2026-08-28)
**What changed:** the engine used to commit per *statement*. `db.c` called
`wo_wal_commit` immediately after every append, at all six sites, so each row
change bought its own `pwrite` and its own `fdatasync`. Now the barrier belongs
to the drain, not to the statement.
**Where the barrier runs, and why there.** A statement on a worker shard has no
WAL to write — the runtime asserts workers hold neither `db` nor `wal` — so it
marshals to shard 0 and parks. Shard 0 executes those requests in its envelope
drain (`wo_vm_adopt`), and the drain now **holds each reply** instead of pushing
it as the statement finishes. When the queue empties it issues one barrier, then
releases every held reply.
Holding the reply is the whole mechanism. Pushing it early would unpark the
requester before its record was durable; holding it means each writer is
acknowledged after the barrier that carried *its own* record. That was always
the intended contract — it was simply true by accident before, because every
batch had exactly one member.
**Why the queue is the boundary.** Not a tick, and not a timer. A queue of one
gives a batch of one, so a lone writer pays exactly what it paid before; the
batch grows only when writes genuinely contend. A tick boundary would have
added latency even with nothing to batch against, which is taxing an idle
system to serve a busy one. There is nothing to tune, which is the point.
**Why the inline path is asymmetric.** A statement already on shard 0 stages and
commits before returning, batch size one. It cannot hold a reply because there
is nobody to reply to — it returns into its own fiber. Batching it would mean
parking that fiber on the barrier, which is part B's machinery. Two consequences
worth keeping in mind: single-shard configurations get no batching at all, by
design; and the inline commit is only safe because the drain commits
*unconditionally* whenever anything is staged, so the buffer is empty when an
inline statement runs. If that ever stops holding, the inline path would make
another statement's record durable early and acknowledge it to the wrong writer.
**One rule for failure: once a statement has mutated RAM, the outcomes are
durable or process death.** It replaced three behaviours that disagreed —
`insert` un-applied itself, while `update` and `delete` returned a catchable
trap and left RAM ahead of disk, which their own comments said out loud.
Batching would have multiplied that from one row to a whole batch. So a failed
stage or a failed barrier now prints one diagnostic (operation, log path,
`errno`, record count) and exits 3; `WO_T_IO` is unreachable from a write.
Retrying is not offered because it is unsound: on Linux a failed `fsync` may
already have discarded the dirty pages, so a second call can report success
having written nothing. Replay is the recovery that works.
**Measuring it.** `WO_WAL_STATS=1` makes the runtime print one line at exit —
batches, records, peak batch, peak staged bytes. Opt-in, because it would
otherwise pollute every durable program's output. The counters live in `wo_wal`
rather than behind a builtin: they are diagnostic, not part of the language.
`db-bench`'s `wmix N C` leg exists to exercise this at all — `mix` writes on one
op in ten with C=4, which produced a measured mean batch of 1.01, so it could
never have shown whether batching worked.
**If you are looking at this because writes got slower**, check the mean batch
first. Mean 1.0 means the mechanism is not engaging, which is expected for a
serial writer or a single-shard configuration and a bug anywhere else.
## Checkpoint: compaction by rewrite + rename (databasev2 3, 2026-08-29)
**The problem:** nothing ever removed superseded records, so the log grew
forever and boot replayed all history. Measured before this: 20 000 rows seeded
gave a 986 KB log; updating those same rows 20 000 times took it to 2.6 MB with
**the same live data**.
**Why one file and not a snapshot plus a tail.** Postgres does the opposite —
its WAL is a redo tail and the data lives in heap files, so a checkpoint flushes
pages and then recycles log segments; it never compacts. It cannot: its records
are page deltas, so a compacted redo log is not a store. **Ours are full row
images** — `apply_record` implements UPDATE as remove-then-recreate — so a log
of one record per live row *is* a complete store. That single difference deletes
the control file, the redo pointer, the second recovery source and the separate
process from this design. Recovery is not merely compatible with compaction; it
is completely unaware of it.
**Why `rename` is the whole crash-safety story.** The dump goes to a temp file,
which is fsynced, renamed over the live log, and then the parent directory is
fsynced (the rename is atomic in-kernel, but the directory entry is not durable
until the parent is — Postgres does the same for the same reason). Before the
rename the live log is intact and the temp is not authoritative; after it the new
log is complete. There is no instant at which a reader sees a mixture, so this
needs no recovery logic of its own. What Postgres achieves with a redo pointer
computed at checkpoint start and a control file written at the end, one syscall
achieves here — because we can swap the entire data set atomically and Postgres
cannot.
A crash mid-rewrite leaves a temp file. The next open **removes it**, and it is
deleted rather than ignored because a file full of well-formed records sitting
beside the log is exactly what a later reader mistakes for data.
**Why the dump flushes periodically, and why it does NOT fsync when it does.**
`stage()` grows the staging buffer by doubling and never shrinks it, so pushing a
whole store through one buffer would hold the entire store in RAM on top of the
store — the unbounded growth databasev2 1 measured as how this engine dies. So
the dump flushes every 256 records. It flushes with a plain write, **not** a
commit: intermediate durability is worthless because the temp is not
authoritative until the rename and is fsynced once immediately before it. Using
the committing path cost one barrier per 256 records and made the pause 8×
larger — measured 107 649 µs against 13 212 µs for a 2 MB live set, ~22 MB/s
against ~181 MB/s.
**Why the replacement is preallocated like the original.** The WAL is
preallocated so that appends never extend the file, which is what lets
`fdatasync` alone serve as the ack barrier. A replacement opened without it
would silently change that property, and the zero-padded tail the open-time scan
relies on.
**When it runs.** Only where the staging buffer is empty — right after a
barrier. Both write paths check: the drain (`vm.c`, after its commit and after
releasing held replies, since those records are already durable and should not
wait out a rewrite) and the inline path (`db.c`). Wiring only the drain left
`WO_SHARDS=1` never compacting, with its log growing forever: measured 536 KB
where the multi-shard run held 446 KB.
**The trigger** compares the log against what the *last* compaction actually
wrote, with an absolute floor. The denominator is measured rather than
estimated, because estimating the live size means estimating Text and the
compactor already knows the true number. There is deliberately **no timer**:
Postgres needs one because its dirty buffers are not durable until flushed, and
ours are durable at commit — an idle log does not grow.
**A failed compaction is a missed optimisation, not a durability event.** It
leaves the original log intact and returns an error the callers ignore. It must
never take `wo_wal_commit_fatal`'s path, which exists for a different problem.
**If you are here because a checkpoint misbehaved:** `WO_WAL_STATS=1` reports
compaction count, the stop-the-world pause (max and total) and the last
compaction's size. `WO_CHECKPOINT_BYTES` and `WO_CHECKPOINT_RATIO` move the
policy; setting a tiny floor forces compaction in a few writes, which is how the
gate tests it at all.
## Keys-resident updates: read-modify-append, stage-here/commit-in-caller (databasev2 2/3, 2026-08-30)
**The shape.** A keys-resident row has no slab slot to mutate — its payload
lives in the log — so `row_apply_field_keys` (table.c) does read-modify-
**append** instead of a slot swap: borrow (folds the row's current value),
append a WAL delta record (id, field, new value) chained off the row's
current offset via a back-pointer, RAM-apply the index swap. `wo_wal_fold_row_at`
is THE fold — written once, called by every reader (`wo_row_borrow`), by
replay, and by compaction — so a read, a boot, and a checkpoint can never
disagree about a chain's current value.
**Stage-here, commit-in-caller — mirrors insert exactly.** `row_apply_field_keys`
stages the delta but does **not** commit and does **not** move the id map:
table.c applies RAM and appends; `db.c` owns the barrier and the post-barrier
map move, the same split insert already used (`wo_wal_pend_drop` /
`wo_db_flush_drops` for insert; `wo_wal_pend_repoint` / `wo_db_flush_drops`
for update). The caller captures the delta's own offset via
`wo_wal_next_offset()` **before** calling in — insert's own `koff` pattern —
since nothing between that capture and `wo_wal_append_delta` stages any other
bytes on the WAL. `back_off` — the back-pointer a new delta chains from —
checks a PENDING re-point (`wo_wal_repoint_offset1`) before falling back to
the durable `wo_row_offset1`: two updates to the same row staged behind one
drain's barrier must chain to each other, not both to the row's pre-drain
offset, or the first update would be orphaned from the chain.
**The unique shadow-check runs against a THROWAWAY buffer, never `t->scratch`.**
The row under update already occupies the table's one scratch buffer
(`wo_row_borrow` refuses a nested borrow on the same table), so a candidate
probe needs a buffer of its own — `keys_fold_into`, the fold-into-a-caller-
supplied-buffer half of `wo_row_borrow`, bypasses the scratch gate for exactly
this. A candidate updated earlier in the SAME uncommitted drain has its
re-point only pending, so the candidate probe also consults
`wo_wal_repoint_offset1` — and `wo_wal_fold_row_at` itself reads the WAL's
staging buffer (not yet durable) for an offset that falls inside it, so a
same-drain candidate's NEW value is what a real `@unique` clash sees.
**A keys-resident borrow holds ENGINE values, exactly `wo_row_ptr`'s contract
— restored 2026-08-30.** `table.h`'s opening doctrine: "the engine and the VM
heap are two memory worlds crossed only by copy... a row stores NO VM
pointer." `keys_fold_into` used to decode the fold's engine output to a VM
value before handing the row back, which every OTHER reader of a borrowed row
(`db.c`'s GET_FIELD/PROBE, `wo_row_read`, and `idx_hash`/`idx_cols_equal`/
`wo_idx_probe`) was NOT written to expect — they all decode engine→VM
themselves, on the assumption a borrow is engine-encoded like a slab row.
Invisible for SCALAR/FLOAT (decode is identity either way), and un-exercised
for TEXT/BYTES because the loader refused `resident: keys` outright until
this task lifted it — nothing had ever read a keys-resident Text field
through `db.c` at all. Fixed by making `keys_fold_into` stop decoding: the
fold's engine output lands straight in the borrowed row's slots,
`wo_row_release` frees them with `db_val_free` (not `wo_drop_kind`) exactly
like `table_destroy` frees a slab row's fields, and `row_apply_field_keys`
uses its already-engine-encoded `nv` directly instead of decoding a throwaway
VM copy. No index function needed to change, and neither did `db.c`.
Reproduced as a genuine ASan heap-buffer-overflow (a `wo_str*` read through
the `db_text*` layout) before the fix, pinned by
`test_keys_resident_update_indexed_text` (`runtime/test/test_wal.c`) after it.
**Three limitations, shipped and documented rather than fixed:**
1. *Mid-drain stale reads.* A request reading a row inside the same uncommitted
drain as an earlier request's in-flight update to it may see the last
durable value. Read-your-writes holds within a request, not across requests
sharing a drain; closing it needs the fold to consult the staging buffer
generally, not only for the same-drain unique shadow-check above.
2. *Replay is O(N²) in a row's delta-chain length* — `apply_delta` folds the
pre-delta row, and `wo_row_remove` (called internally) folds the SAME
offset again, so each replayed delta re-walks its whole chain.
3. *Compaction triggers on byte ratio only* — **closed by databasev2 11**:
the fold reports hop count and `row_apply_field_keys` writes a full-row
image (`WO_WAL_UPDATE`) past `WO_DELTA_MAX_HOPS` (16), so a hot row's
chain is bounded in the update path itself; the checkpoint no longer
carries that burden. `wo_wal_should_compact` also gained an absolute
garbage term (`WO_CKPT_ABS_BYTES`).
## Schema migrations (databasev2 12)
A `@table` class is the schema; the log is the database; boot compares them.
- **The log describes itself.** `WO_WAL_SCHEMA` (kind 5) is the head record
of every fresh and every compacted log: per class its NAME, storage flags,
and per field name + kind + the two encoding-relevant metadata words.
Written lazily ahead of the FIRST real record — never for a log that
stays empty, because `durable: false` programs have a documented
zero-bytes contract. `apply_record` skips it before reading cid/id (its
class count would be misread as a cid); replay does not count it.
- **Head before any offset capture (defect fix 2026-09-10).** One helper,
`stage_schema_head`, stages the pending head; `stage()` calls it on the
first append and `wo_wal_next_offset()` calls it BEFORE answering, so the
offset a caller records for a keys-resident row (`db.c`'s `koff`/`roff`,
taken before the append) can never name the head. It used to: boot sets
the schema (`main.c`, `wo_wal_set_schema`) and never forces the head, so
the first `resident: keys` row of a fresh log was re-pointed at the schema
record — its first read folded "record header is malformed", and through
`wo_idx_probe` (a borrow with `msg == NULL`) that was a zero-page write:
the residency example's `seed` died rc 139 in both `WO_DATA` forms.
`wo_wal_next_offset` is therefore no longer pure; a head-stage OOM there is
`wo_wal_stage_fatal`. Compaction and migration stage the head explicitly
on a schema-less replacement log and were never exposed. Pinned by
`test_keys_resident_fresh_log_first_row` (test_wal.c): the db.c:78
sequence call for call, then read-by-id, `wo_idx_probe`, and replay. The
fold's `msg` is optional since the same fix (`test_fold_row_at_tolerates_null_msg`):
a malformed record under an index probe refuses the candidate by name
instead of writing the zero page.
- **The diff is name-keyed** (`wo_schema_diff`). Classes match by name,
fields by name + kind, owned references (`fclass`) by the NAME the number
resolves to — so pure declaration reordering costs only a cid remap, which
closes the old silent hole where reordering decoded rows into the wrong
class. Verdicts are per-class POISONS carried in the plan: retype,
same-shape delete+add (a disguised rename), vanished class, storage-flag
change, and the embed closure (any class whose stored values carry a
CHANGED class's old sub-shape, to a fixpoint). A poison forces the
transcode and bites only when a record of the class is actually met — no
rows, no verdict.
- **The migration is a record-level transcode** (`wo_wal_migrate`), not a
replay: no id maps, no indexes, no keys-resident logic. Old shapes decode
through a classdesc shim built from the stored schema; embedded cids are
renumbered by `mig_fixup_cids` (owned values carry a cid on the wire);
surviving fields move slots, deleted values are freed, added fields take
`enc_val(0)` — the kind's zero. Delta back-pointers rewrite through an
offset map, and a delta on a deleted field is SPLICED: it maps to its own
target, so later deltas step over it. Temp + fsync + rename, compaction's
own crash discipline — a kill anywhere leaves the old log authoritative,
including a kill after the temp is complete (`test_migrate_crash_before_rename`).
- **Legacy logs** (no head record) replay exactly as before and adopt the
head at their next compaction. v1 verbs are add and delete only; rename
wants `@renamed_from` (v2), data/seed migrations are v2.
## Startup refusal + WO_EPHEMERAL (databasev2 2 task 6a, 2026-09-09/10)
`main.c`, startup only. The engine, `db.c` and `wal.c` are untouched.
- **Contract.** With `WO_DATA` unset or empty and no `WO_EPHEMERAL`, the first
class whose flags carry `WO_CLASSF_TABLE` and lack `WO_CLASSF_VOLATILE`
(a `@table` with `durable: true`, the default) is a startup refusal: exit 2,
ONE stderr line naming the class and all three ways forward literally
(`WO_DATA=<dir or file>`, `WO_EPHEMERAL=1`, `@table(durable: false)`). The loop sits
inside the existing `!data_dir` block AFTER the `resident: keys` loop — the
keys refusal wins, and `WO_EPHEMERAL` does not rescue it (a keys table has
nowhere to read from). Both loops skip classes without the table bit.
- **Escape hatch.** `WO_EPHEMERAL` with the exact value `1`, honoured only
while `WO_DATA` is unset/empty: one boot notice line on stderr, rc 0, and the
RAM path is byte-for-byte the old one — `db.c`'s `w && table_is_durable`
guards are the only gate, no new flag in `wo_db`. Set alongside `WO_DATA`
(any value) → exit 2 `WO_EPHEMERAL=1 is incompatible with WO_DATA` — that
check runs regardless of tables. Any value but `1` → exit 2 naming the
accepted value. A module with no durable `@table` consults `WO_EPHEMERAL`
for nothing else: no notice, no value check, rc 0 as before.
- **The table bit (`.wob` v8, 2026-09-10).** The first cut keyed the refusal
on `!VOLATILE` alone, and the v7 image carried no "is a `@table`" bit: plain
classes, variant classes and the predeclared records (`Error`, `Stat`, …)
all looked durable, so EVERY class-bearing program refused without
`WO_DATA` — fibers (`Tick`), subprocess (`ConnMsg`), log-watcher
(`CronEntry`), chat. Wrong by construction: `durable:` is a `@table`
property. Fixed by `WO_CLASSF_TABLE` 0x08 (`wob.h`, `WO_CLASSF_ALL` 0x0f,
`WOB_VERSION` 8; `emit.ml` sets it from `cr_is_table`); the loader refuses
`VOLATILE`/`RESIDENT_KEYS` without it ("storage flags on a class that is
not a @table", `test_loader`), and a v7 image is refused by the version
check exactly as v7 refused v6. Blast radius after the fix, measured gate
by gate (each run without the export first; kept only where it refused):
only programs that DECLARE a durable table opt in — `oop-e2e.sh` (corpus
fixtures declare tables); `db-bench.py`'s ram/msgrate/growth/randread legs
(db-bench's tables); db-actor per-run (`notes` is default-durable; per-run
because its restart pair sets `WO_DATA` and the two are incompatible),
whose single-shard byte-exact compare drops the one notice line
(`grep -v '^wovm: WO_EPHEMERAL=1'`); chat, whose program declares no table
itself but `use`s porch, and porch's store middleware declares
`RateLimitCounter` default-durable — fork 6, a library-owned table binds
the consumer; and wmux, whose CLIENT legs (ls/new/attach/kill) run the
same default-durable image with no `WO_DATA` — the gate exports the
sentinel, every server start and the `WO_DATA`-carrying `r11cli` drop it
with `env -u`, and `client()` filters the notice because its answers are
compared byte-exactly (a wmux-track consequence worth its own look: a CLI
client of a durable server now needs the sentinel or a `WO_DATA`). fibers
(`Tick`), subprocess (`ConnMsg`) and log-watcher (`CronEntry`) need
nothing — their exports were reverted and their byte-exact compares are
as they were. Goldens: none moved — the bytecode dump prints flags by name
and no `bc/` golden declares a table; the header version is not printed.
- **Deferred, each its own later commit:** an assert in `db.c` that
`durable && !w` is unreachable outside `WO_EPHEMERAL`; an ENOENT hint when
the `WO_DATA` directory is missing (the FILE form already refuses with a
named parent since databasev2 7; the directory form still fails at the WAL
open, on purpose — byte-identical to before); SIGKILL /
rc 137 classification in the gates; `wal.c` fallocate/dir-fsync logging.
- **Proof:** `scripts/residency-accept.sh` section 7 — refusal text, RAM
round-trip under the hatch, the `WO_DATA` conflict, keys still refusing
under the hatch, a non-`1` value, and (vi) a plain class without `@table`
running with no `WO_DATA` and nothing on stderr (the corpus `methods`
fixture); `runtime/test/test_loader.c` `test_storage_flags_need_table`.

View file

@ -7,6 +7,34 @@
#include "table.h" #include "table.h"
#include "wal.h" #include "wal.h"
/* databasev2 2: is this table's storage durable? A `@table(durable: false)`
* class carries WO_CLASSF_VOLATILE and is never staged to the WAL — no
* record, no fsync, ack straight from RAM. One predicate for all three
* mutation sites below: `database/src/CODE-LOGIC.md` names those as the only
* places storage may be staged, and that invariant is worth more than the
* convenience of inlining this. cid is always loader-validated by the time a
* mutation has succeeded, so no bounds check is added here. */
static int table_is_durable(const wo_db *db, uint32_t cid) {
return (db->classes[cid].flags & WO_CLASSF_VOLATILE) == 0u;
}
/* databasev2 3: the inline path's compaction check.
*
* The drain has its own (vm.c, after the barrier). This one exists because a
* statement running ON the owner shard never enters that drain, so without it
* a single-shard durable program's log grows FOREVER — measured: WO_SHARDS=1
* reached 536 KB where the multi-shard run held 446 KB, because the check was
* only wired into the drain.
*
* Safe here for the same reason it is safe there: the commit above just
* emptied the staging buffer. The result is ignored because a failed
* compaction is a missed optimisation, not a durability event. */
static void maybe_compact(wo_db *db, wo_wal *w) {
if (wo_wal_should_compact(w->off, w->compacted_bytes, wo_wal_ckpt_floor,
wo_wal_ckpt_ratio))
(void)wo_wal_compact(w, db);
}
int wo_builtin_db(wo_vm *vm, uint64_t *R, uint32_t ins, const char **msg) { int wo_builtin_db(wo_vm *vm, uint64_t *R, uint32_t ins, const char **msg) {
uint32_t A = wo_ins_a(ins), B = wo_ins_b(ins), C = wo_ins_c(ins); uint32_t A = wo_ins_a(ins), B = wo_ins_b(ins), C = wo_ins_c(ins);
wo_db *db = (wo_db *)vm->rt.db; wo_db *db = (wo_db *)vm->rt.db;
@ -24,16 +52,35 @@ int wo_builtin_db(wo_vm *vm, uint64_t *R, uint32_t ins, const char **msg) {
: ek == DB_ERR_OOM ? WO_T_OOM : ek == DB_ERR_OOM ? WO_T_OOM
: WO_T_DB; : WO_T_DB;
wo_wal *w = (wo_wal *)vm->rt.wal; wo_wal *w = (wo_wal *)vm->rt.wal;
if (w) { if (w && table_is_durable(db, cid)) {
/* RAM applied, record staged, ONE commit before the ack (the /* THE INLINE PATH KEEPS ITS OWN BARRIER, AND THAT ASYMMETRY IS
* builtin's return). A failed commit is a failed write: the * DELIBERATE (databasev2 4 part A). The request path batches:
* row is removed again so RAM never claims what disk never * wo_vm_adopt holds each reply and commits once per drain. This
* acknowledged, and the statement traps. */ * path cannot, because it has no reply to hold — it returns into
if (wo_wal_append_insert(w, db, cid, id) != 0 || wo_wal_commit(w) != 0) { * its OWN fiber rather than unparking a requester. Do not "fix"
wo_row_remove(db, cid, id); * this by dropping the commit: without it an inline statement
*msg = "wal commit failed"; * would never be durable at all.
return WO_T_IO; *
} * Committing here is safe because the drain commits
* unconditionally whenever anything is staged, so the buffer is
* empty when this runs.
*
* The `table_is_durable` guard is databasev2 2's: a
* `@table(durable: false)` class is never staged, so it reaches
* neither this barrier nor the compaction check below.
*
* Failure is fatal, not a trap: the row is already in RAM. */
/* databasev2 2 (5c): the offset this record WILL occupy. Taken
* BEFORE the append, recorded as pending, and acted on only after
* the commit below — a keys-resident payload dropped any earlier
* would leave an offset whose bytes are still in the staging
* buffer. */
uint64_t koff = wo_wal_next_offset(w);
if (wo_wal_append_insert(w, db, cid, id) != 0) wo_wal_stage_fatal(w);
if (wo_table_is_keys_resident(db, cid)) (void)wo_wal_pend_drop(w, cid, id, koff);
wo_wal_commit_fatal(w, 1);
wo_db_flush_drops(db, w);
maybe_compact(db, w);
} }
R[A] = id; R[A] = id;
return 0; return 0;
@ -43,14 +90,29 @@ int wo_builtin_db(wo_vm *vm, uint64_t *R, uint32_t ins, const char **msg) {
uint64_t id = R[B + 1]; uint64_t id = R[B + 1];
uint32_t field = (uint32_t)R[B + 2]; uint32_t field = (uint32_t)R[B + 2];
int ek = 0; int ek = 0;
wo_wal *w = (wo_wal *)vm->rt.wal;
int keys_res = wo_table_is_keys_resident(db, cid);
/* databasev2 2 (5c) / Task 4: the delta's own offset, taken BEFORE
* the call the same way the insert arm takes koff — table.c stages
* the delta at exactly this position and nothing else stages bytes
* on `w` in between. */
uint64_t roff = (w && keys_res) ? wo_wal_next_offset(w) : 0;
if (wo_row_update_field(db, cid, id, field, R[B + 3], msg, &ek) != 0) if (wo_row_update_field(db, cid, id, field, R[B + 3], msg, &ek) != 0)
return ek == DB_ERR_UNIQUE ? WO_T_UNIQUE : ek == DB_ERR_OOM ? WO_T_OOM : WO_T_DB; return ek == DB_ERR_UNIQUE ? WO_T_UNIQUE : ek == DB_ERR_OOM ? WO_T_OOM : WO_T_DB;
wo_wal *w = (wo_wal *)vm->rt.wal; if (w && table_is_durable(db, cid)) {
if (w) { if (keys_res) {
if (wo_wal_append_update(w, db, cid, id) != 0 || wo_wal_commit(w) != 0) { /* the delta is already staged (table.c); this is the
*msg = "wal commit failed"; /* RAM ahead of disk: trap, do not ack */ * inline path's OWN barrier, same as insert, then the map
return WO_T_IO; * moves — commit before re-point, always. */
wo_wal_commit_fatal(w, 1);
(void)wo_row_set_offset(db, cid, id, roff);
} else {
/* was: trap and leave RAM ahead of disk, which the old
* comment admitted. Now fatal — see the insert arm. */
if (wo_wal_append_update(w, db, cid, id) != 0) wo_wal_stage_fatal(w);
wo_wal_commit_fatal(w, 1);
} }
maybe_compact(db, w);
} }
R[A] = 0; R[A] = 0;
return 0; return 0;
@ -69,11 +131,10 @@ int wo_builtin_db(wo_vm *vm, uint64_t *R, uint32_t ins, const char **msg) {
return WO_T_DB; return WO_T_DB;
} }
wo_wal *w = (wo_wal *)vm->rt.wal; wo_wal *w = (wo_wal *)vm->rt.wal;
if (w) { if (w && table_is_durable(db, cid)) {
if (wo_wal_append_remove(w, cid, id) != 0 || wo_wal_commit(w) != 0) { if (wo_wal_append_remove(w, cid, id) != 0) wo_wal_stage_fatal(w);
*msg = "wal commit failed"; wo_wal_commit_fatal(w, 1);
return WO_T_IO; maybe_compact(db, w);
}
} }
R[A] = 0; R[A] = 0;
return 0; return 0;
@ -89,15 +150,13 @@ int wo_builtin_db(wo_vm *vm, uint64_t *R, uint32_t ins, const char **msg) {
/* materialize the id list up front — the 9b cursor-stability rule: /* materialize the id list up front — the 9b cursor-stability rule:
* the loop body then point-reads each id, so a row updated mid-loop * the loop body then point-reads each id, so a row updated mid-loop
* (even an indexed column) cannot disturb the iteration */ * (even an indexed column) cannot disturb the iteration */
db_table *t = &db->tables[cid]; { /* databasev2 2 (5d): through the shared iterator, because a
if (t->row_size) { * keys-resident table's bitmap is empty by construction — this
uint32_t total = t->slab_cnt * DB_SLAB_ROWS; * walk would otherwise see no rows at all */
for (uint32_t g = 0; g < total; g++) { size_t cur = 0;
if (!(t->bitmap[g >> 6] & (1ull << (g & 63)))) continue; uint64_t rid;
db_row *row = while (wo_row_next_id(db, cid, &cur, &rid))
(db_row *)(t->slabs[g / DB_SLAB_ROWS] + (size_t)(g % DB_SLAB_ROWS) * t->row_size); if (wo_multi_push(ids, rid) != 0) return WO_T_OOM;
if (wo_multi_push(ids, row->id) != 0) return WO_T_OOM;
}
} }
R[A] = (uint64_t)(uintptr_t)ids; R[A] = (uint64_t)(uintptr_t)ids;
return 0; return 0;
@ -110,14 +169,17 @@ int wo_builtin_db(wo_vm *vm, uint64_t *R, uint32_t ins, const char **msg) {
*msg = "no such field"; *msg = "no such field";
return WO_T_DB; return WO_T_DB;
} }
db_row *row = wo_row_ptr(db, cid, id); db_row *row = wo_row_borrow(db, cid, id, msg);
if (!row) { if (!row) {
*msg = "no such row"; *msg = "no such row";
return WO_T_DB; return WO_T_DB;
} }
int ok = 1; int ok = 1;
/* decode BEFORE releasing: for a keys-resident row the slots point at
* the borrow's scratch, which release frees */
uint64_t v = wo_val_decode_vm(db, &vm->rt, db->classes[cid].kinds[field], uint64_t v = wo_val_decode_vm(db, &vm->rt, db->classes[cid].kinds[field],
row->slots[field], &ok, msg); row->slots[field], &ok, msg);
wo_row_release(db, cid, row);
if (!ok) return WO_T_OOM; if (!ok) return WO_T_OOM;
R[A] = v; R[A] = v;
return 0; return 0;
@ -163,11 +225,17 @@ int wo_builtin_db(wo_vm *vm, uint64_t *R, uint32_t ins, const char **msg) {
return 0; return 0;
} }
} }
uint32_t total = t->slab_cnt * DB_SLAB_ROWS; { /* databasev2 2 (5d): the filtered scan, through the shared
for (uint32_t g = 0; g < total; g++) { * iterator and a borrow. The borrow is released BEFORE any
if (!(t->bitmap[g >> 6] & (1ull << (g & 63)))) continue; * exit from the loop body: the scratch is per-table, so a
db_row *row = * borrow leaked past a `return` would make the next borrow on
(db_row *)(t->slabs[g / DB_SLAB_ROWS] + (size_t)(g % DB_SLAB_ROWS) * t->row_size); * that table fail as a nested one. */
size_t cur = 0;
uint64_t rid;
const char *bmsg = NULL;
while (wo_row_next_id(db, cid, &cur, &rid)) {
db_row *row = wo_row_borrow(db, cid, rid, &bmsg);
if (!row) continue;
int eq; int eq;
if (kind == WO_K_TEXT) { if (kind == WO_K_TEXT) {
const wo_str *want = (const wo_str *)(uintptr_t)key; const wo_str *want = (const wo_str *)(uintptr_t)key;
@ -177,7 +245,9 @@ int wo_builtin_db(wo_vm *vm, uint64_t *R, uint32_t ins, const char **msg) {
memcmp(want->data, have->bytes, have->len) == 0); memcmp(want->data, have->bytes, have->len) == 0);
} else } else
eq = row->slots[col] == key; eq = row->slots[col] == key;
if (eq && wo_multi_push(ids, row->id) != 0) return WO_T_OOM; wo_row_release(db, cid, row);
if (eq && wo_multi_push(ids, rid) != 0) return WO_T_OOM;
}
} }
} }
R[A] = (uint64_t)(uintptr_t)ids; R[A] = (uint64_t)(uintptr_t)ids;
@ -215,29 +285,44 @@ void wo_db_exec_req(wo_vm *vm, wo_db_req *q) {
q->msg = m; q->msg = m;
break; break;
} }
if (w) { if (w && table_is_durable(db, q->cid)) {
if (wo_wal_append_insert(w, db, q->cid, id) != 0 || wo_wal_commit(w) != 0) { /* databasev2 4: staging failure is FATAL, not a trap. The row is
wo_row_remove(db, q->cid, id); * already in RAM; of the three verbs only insert could undo
q->status = WO_T_IO; * itself, so continuing means RAM ahead of disk. One rule: once a
q->msg = "wal commit failed"; * statement has mutated RAM, the outcomes are durable or death. */
break; uint64_t koff = wo_wal_next_offset(w);
} if (wo_wal_append_insert(w, db, q->cid, id) != 0) wo_wal_stage_fatal(w);
/* recorded, not performed: this batch's barrier runs in the drain
* (vm.c), and only then are these offsets readable */
if (wo_table_is_keys_resident(db, q->cid))
(void)wo_wal_pend_drop(w, q->cid, id, koff);
} }
q->result = id; q->result = id;
break; break;
} }
case WO_B_DB_UPDATE_FIELD: { case WO_B_DB_UPDATE_FIELD: {
int ek = 0; int ek = 0;
int keys_res = wo_table_is_keys_resident(db, q->cid);
/* Task 4: see the inline arm — the delta's own offset, captured
* BEFORE the call the same way insert's koff is. */
uint64_t roff = (w && keys_res) ? wo_wal_next_offset(w) : 0;
if (wo_row_update_field_slot(db, q->cid, q->id, q->field, q->slots[0], &m, &ek) != 0) { if (wo_row_update_field_slot(db, q->cid, q->id, q->field, q->slots[0], &m, &ek) != 0) {
q->status = ek == DB_ERR_UNIQUE ? WO_T_UNIQUE : ek == DB_ERR_OOM ? WO_T_OOM : WO_T_DB; q->status = ek == DB_ERR_UNIQUE ? WO_T_UNIQUE : ek == DB_ERR_OOM ? WO_T_OOM : WO_T_DB;
q->msg = m; q->msg = m;
break; break;
} }
if (w) { if (w && table_is_durable(db, q->cid)) {
if (wo_wal_append_update(w, db, q->cid, q->id) != 0 || wo_wal_commit(w) != 0) { if (keys_res) {
q->status = WO_T_IO; /* recorded, not performed: this batch's barrier runs in the
q->msg = "wal commit failed"; * drain (vm.c), and only then does the map move — mirrors
break; * the insert arm's wo_wal_pend_drop in shape, but NOT in
* failure safety: the delta is already staged and RAM has
* already moved, so a lost re-point is unrecoverable (see
* wo_wal_pend_repoint's own doc) and must die here, not
* limp on with a permanently stale map. */
if (wo_wal_pend_repoint(w, q->cid, q->id, roff) != 0) wo_wal_repoint_fatal(w);
} else {
if (wo_wal_append_update(w, db, q->cid, q->id) != 0) wo_wal_stage_fatal(w);
} }
} }
break; break;
@ -253,12 +338,8 @@ void wo_db_exec_req(wo_vm *vm, wo_db_req *q) {
q->msg = "no such row"; q->msg = "no such row";
break; break;
} }
if (w) { if (w && table_is_durable(db, q->cid)) {
if (wo_wal_append_remove(w, q->cid, q->id) != 0 || wo_wal_commit(w) != 0) { if (wo_wal_append_remove(w, q->cid, q->id) != 0) wo_wal_stage_fatal(w);
q->status = WO_T_IO;
q->msg = "wal commit failed";
break;
}
} }
break; break;
} }
@ -297,11 +378,15 @@ void wo_db_exec_req(wo_vm *vm, wo_db_req *q) {
} }
if (prc == 1) break; /* probed; reply fields already set */ if (prc == 1) break; /* probed; reply fields already set */
} }
uint32_t total = t->slab_cnt * DB_SLAB_ROWS; { /* databasev2 2 (5d): shared iterator + borrow, with the borrow
for (uint32_t g = 0; g < total; g++) { * released before the realloc that can `break` — a borrow held
if (!(t->bitmap[g >> 6] & (1ull << (g & 63)))) continue; * past an exit would poison the table's scratch. */
db_row *row = size_t cur = 0;
(db_row *)(t->slabs[g / DB_SLAB_ROWS] + (size_t)(g % DB_SLAB_ROWS) * t->row_size); uint64_t rid;
const char *bmsg = NULL;
while (wo_row_next_id(db, q->cid, &cur, &rid)) {
db_row *row = wo_row_borrow(db, q->cid, rid, &bmsg);
if (!row) continue;
if (q->op == WO_B_DB_PROBE) { if (q->op == WO_B_DB_PROBE) {
int eq; int eq;
if (kind == WO_K_TEXT || kind == WO_K_BYTES) { if (kind == WO_K_TEXT || kind == WO_K_BYTES) {
@ -314,8 +399,9 @@ void wo_db_exec_req(wo_vm *vm, wo_db_req *q) {
memcmp(want->bytes, have->bytes, have->len) == 0); memcmp(want->bytes, have->bytes, have->len) == 0);
} else } else
eq = row->slots[col] == q->slots[0]; eq = row->slots[col] == q->slots[0];
if (!eq) continue; if (!eq) { wo_row_release(db, q->cid, row); continue; }
} }
wo_row_release(db, q->cid, row);
if (n == cap) { if (n == cap) {
uint32_t ncap = cap ? cap * 2 : 16; uint32_t ncap = cap ? cap * 2 : 16;
uint64_t *no = realloc(out, (size_t)ncap * 8u); uint64_t *no = realloc(out, (size_t)ncap * 8u);
@ -329,7 +415,8 @@ void wo_db_exec_req(wo_vm *vm, wo_db_req *q) {
out = no; out = no;
cap = ncap; cap = ncap;
} }
out[n++] = row->id; out[n++] = rid;
}
} }
} }
if (!q->status) { if (!q->status) {
@ -344,7 +431,7 @@ void wo_db_exec_req(wo_vm *vm, wo_db_req *q) {
q->msg = "no such field"; q->msg = "no such field";
break; break;
} }
db_row *row = wo_row_ptr(db, q->cid, q->id); db_row *row = wo_row_borrow(db, q->cid, q->id, &m);
if (!row) { if (!row) {
q->status = WO_T_DB; q->status = WO_T_DB;
q->msg = "no such row"; q->msg = "no such row";
@ -352,7 +439,10 @@ void wo_db_exec_req(wo_vm *vm, wo_db_req *q) {
} }
int ok = 1; int ok = 1;
q->val_kind = db->classes[q->cid].kinds[q->field]; q->val_kind = db->classes[q->cid].kinds[q->field];
/* clone BEFORE releasing: a keys-resident row's slots point into the
* borrow's scratch, which release frees */
q->val = wo_db_val_clone(db->classes, q->val_kind, row->slots[q->field], &ok); q->val = wo_db_val_clone(db->classes, q->val_kind, row->slots[q->field], &ok);
wo_row_release(db, q->cid, row);
if (!ok) { if (!ok) {
q->status = WO_T_OOM; q->status = WO_T_OOM;
q->msg = "out of memory"; q->msg = "out of memory";

View file

@ -4,6 +4,8 @@
#include <string.h> #include <string.h>
#include "cont.h" #include "cont.h"
#include "gc.h" /* databasev2 2 (5c): VM-side drops for materialised rows */
#include "wal.h" /* databasev2 2 (5c): a keys-resident borrow reads the log */
/* ---- engine-owned value encode / free / decode ------------------------- */ /* ---- engine-owned value encode / free / decode ------------------------- */
@ -363,7 +365,12 @@ int wo_idx_probe(wo_db *db, uint32_t class_id, uint32_t index, uint64_t key_scal
if (!ids) return -1; if (!ids) return -1;
uint32_t n = 0; uint32_t n = 0;
for (uint32_t i = 0; i < b->len; i++) { for (uint32_t i = 0; i < b->len; i++) {
db_row *r = wo_row_ptr(db, class_id, b->ids[i]); /* databasev2 2 (5d): THE unique shadow — the site the plan called the
* real coupling, because it needs a row it cannot get from a slab. For
* a keys-resident table each candidate costs a pread and a
* materialisation: the disclosed price of `@unique` there, bounded by
* the bucket rather than the table. */
db_row *r = wo_row_borrow(db, class_id, b->ids[i], NULL);
if (!r) continue; if (!r) continue;
int eq; int eq;
if (kind == WO_K_TEXT) { if (kind == WO_K_TEXT) {
@ -376,6 +383,7 @@ int wo_idx_probe(wo_db *db, uint32_t class_id, uint32_t index, uint64_t key_scal
* exact comparison, so probe results never differ from scan * exact comparison, so probe results never differ from scan
* results (the hash canonicalized only to FIND the bucket) */ * results (the hash canonicalized only to FIND the bucket) */
eq = r->slots[col] == key_scalar; eq = r->slots[col] == key_scalar;
wo_row_release(db, class_id, r); /* before any use of the result */
if (eq) ids[n++] = b->ids[i]; if (eq) ids[n++] = b->ids[i];
} }
if (!n) { if (!n) {
@ -449,8 +457,15 @@ static int idx_add_row(wo_db *db, db_table *t, db_row *r) {
db_ibucket *b = idx_bucket(ix, idx_hash(c, ix, r), 0); db_ibucket *b = idx_bucket(ix, idx_hash(c, ix, r), 0);
if (!b) continue; if (!b) continue;
for (uint32_t i = 0; i < b->len; i++) { for (uint32_t i = 0; i < b->len; i++) {
db_row *other = wo_row_ptr(db, t->class_id, b->ids[i]); /* databasev2 2: borrow, never peek at a slab. For a keys-table the
if (other && idx_cols_equal(c, ix, r, other)) return DB_ERR_UNIQUE; * conflicting row may not be resident, and a unique check that
* silently skipped non-resident rows would be a correctness hole,
* not a limitation. */
const char *bmsg = "";
db_row *other = wo_row_borrow(db, t->class_id, b->ids[i], &bmsg);
int clash = other && idx_cols_equal(c, ix, r, other);
wo_row_release(db, t->class_id, other);
if (clash) return DB_ERR_UNIQUE;
} }
} }
for (uint32_t x = 0; x < t->index_cnt; x++) { for (uint32_t x = 0; x < t->index_cnt; x++) {
@ -498,6 +513,9 @@ int wo_db_init(wo_db *db, const wo_classdesc *classes, uint32_t class_cnt,
} }
static void table_destroy(wo_db *db, db_table *t) { static void table_destroy(wo_db *db, db_table *t) {
free(t->scratch); /* databasev2 2 */
t->scratch = NULL;
t->scratch_cap = 0;
/* free every live row's engine-owned values, then the slabs */ /* free every live row's engine-owned values, then the slabs */
const wo_classdesc *c = &db->classes[t->class_id]; const wo_classdesc *c = &db->classes[t->class_id];
for (uint32_t s = 0; s < t->slab_cnt; s++) { for (uint32_t s = 0; s < t->slab_cnt; s++) {
@ -715,19 +733,153 @@ db_row *wo_row_ptr(wo_db *db, uint32_t class_id, uint64_t id) {
if (!t->row_size) return NULL; if (!t->row_size) return NULL;
uint64_t s1 = hget(t, id); uint64_t s1 = hget(t, id);
if (!s1) return NULL; if (!s1) return NULL;
/* databasev2 2 (5d): on a keys-resident table the map value means one of
* two things — a SLOT while the row is still in its slab (between the
* insert and the post-barrier drop, which is when wo_wal_append_insert
* legitimately calls this) and a LOG OFFSET afterwards. Nothing in the
* value distinguishes them, so this function refuses to guess: an index
* past the slabs, or one whose bitmap bit is clear, is an offset and the
* row is not in RAM. Without this a caller that had not read 5d got
* slot_row() applied to a byte offset — slot_row does no bounds check —
* and a wild pointer that was then freed. Callers already handle NULL. */
if (wo_table_is_keys_resident(db, class_id)) {
uint64_t g = s1 - 1;
uint64_t total = (uint64_t)t->slab_cnt * DB_SLAB_ROWS;
if (g >= total) return NULL;
if (!(t->bitmap[g >> 6] & (1ull << (g & 63)))) return NULL;
}
return slot_row(t, (uint32_t)(s1 - 1)); return slot_row(t, (uint32_t)(s1 - 1));
} }
/* keys-resident fold: reads the row at [off] (the row's current record) and
* folds it into [buf] (t->row_size bytes, caller-owned) — the piece
* wo_row_borrow and a unique shadow-check's candidate probe both need,
* factored out because they cannot share a buffer: wo_row_borrow writes into
* t->scratch and holds it busy for the whole life of the borrow, so a
* shadow-check that needs to look at OTHER rows of the SAME table while the
* row under test is still borrowed must use a buffer of its own, never
* t->scratch. [id] is checked against what the fold actually names, same as
* wo_row_borrow always did. NULL on any failure, *msg set.
*
* table.h's opening doctrine: "the engine and the VM heap are two memory
* worlds crossed only by copy... a row stores NO VM pointer." wo_wal_fold_row_at
* hands back ENGINE-owned values (dec_val's representation, exactly what a
* slab row's own slots hold, per wal.h) — those land straight in r->slots,
* with no VM decode stage, so a keys-resident borrow matches wo_row_ptr's
* contract exactly instead of a second, divergent one. Every existing
* out-gate (wo_row_read, db.c's GET_FIELD/PROBE, idx_hash/idx_cols_equal/
* wo_idx_probe) already decodes engine->VM itself on the assumption that a
* borrowed row is engine-encoded; a decode done AGAIN here used to hand them
* a VM wo_str* reinterpreted as an engine db_text* — same bug either
* direction, invisible for scalars (decode is identity there) and silent
* wrong-bytes for Text/Bytes, which is exactly what stayed unexercised. */
static db_row *keys_fold_into(wo_db *db, uint32_t class_id, uint64_t id,
uint64_t off, uint8_t *buf, uint32_t *hops_out,
const char **msg) {
const wo_classdesc *c = &db->classes[class_id];
db_row *r = (db_row *)buf;
uint32_t got_cid = 0;
uint64_t got_id = 0;
/* keys-resident delta updates, Task 2: the fold, not a single-record
* read — a row's current offset may point at a delta, not a base row.
* Folds straight into r->slots: field_cnt uint64_t slots is exactly
* what out_vals expects, and what a db_row already provides. */
if (wo_wal_fold_row_at((wo_wal *)db->rt->wal, db, off, &got_cid, &got_id, r->slots,
hops_out, msg) != 0)
return NULL;
if (got_cid != class_id || got_id != id) {
/* the offset pointed at someone else's record — a compaction that
* moved records without rebuilding this map would land here, which is
* exactly the obligation recorded at wo_wal_compact */
for (uint32_t i = 0; i < c->field_cnt; i++) wo_db_val_free(db, c->kinds[i], r->slots[i]);
if (msg) *msg = "log offset does not hold the expected row";
return NULL;
}
r->id = id;
r->class_id = class_id;
r->flags = 0;
return r;
}
db_row *wo_row_borrow(wo_db *db, uint32_t class_id, uint64_t id, const char **msg) {
/* Fully-resident tables: exactly today's lookup, and releasing is a no-op.
* The hot path pays one predicate. */
if (!wo_table_is_keys_resident(db, class_id)) return wo_row_ptr(db, class_id, id);
/* Keys-resident: the id map holds the record's LOG OFFSET (off + 1), not a
* slot, so the row is materialised into the table's scratch. */
db_table *t = &db->tables[class_id];
if (!t->row_size) return NULL;
uint64_t durable1 = hget(t, id);
if (!durable1) return NULL;
if (!db->rt || !db->rt->wal) {
/* a keys-resident table cannot exist without a log to read from; the
* loader refuses the annotation outright, so this is a defensive arm */
if (msg) *msg = "resident: keys table without a write-ahead log";
return NULL;
}
/* CRITICAL 2 (review finding): a row already updated once behind this
* not-yet-committed barrier has its re-point only PENDING — hget still
* names the pre-drain durable offset. Folding there hands back the
* row's value from BEFORE the earlier update, which made every caller
* (row_apply_field_keys's idx_remove_row included) hash stale column
* values and leak an index entry per repeat update in one drain.
* Preferring the pending re-point, same as back_off already does below,
* closes it for every borrow, not just the update path. */
uint64_t pending1 = wo_wal_repoint_offset1((wo_wal *)db->rt->wal, class_id, id);
uint64_t o1 = pending1 ? pending1 : durable1;
if (t->scratch_busy) {
/* One scratch per TABLE, so two live borrows on the same table would
* hand back the same buffer. A unique shadow-check that needs OTHER
* rows of this table while one is already borrowed uses its OWN
* throwaway buffer (row_apply_field_keys), never this one — say so
* rather than corrupting the first borrow silently. */
if (msg) *msg = "nested borrow on one table";
return NULL;
}
if (t->scratch_cap < t->row_size) {
uint8_t *nb = realloc(t->scratch, t->row_size);
if (!nb) {
if (msg) *msg = "out of memory";
return NULL;
}
t->scratch = nb;
t->scratch_cap = t->row_size;
}
db_row *r = keys_fold_into(db, class_id, id, o1 - 1, t->scratch, &t->scratch_hops, msg);
if (!r) return NULL;
t->scratch_busy = 1;
return r;
}
void wo_row_release(wo_db *db, uint32_t class_id, db_row *r) {
if (!r || class_id >= db->class_cnt) return;
db_table *t = &db->tables[class_id];
if (!t->scratch_busy || (uint8_t *)r != t->scratch) return; /* slab-backed */
const wo_classdesc *c = &db->classes[class_id];
/* These are ENGINE values, exactly what a slab row holds (keys_fold_into's
* contract) — freed the same way table_destroy frees a slab row's fields,
* not through the runtime. */
for (uint32_t i = 0; i < c->field_cnt; i++) db_val_free(c->kinds[i], r->slots[i]);
t->scratch_busy = 0;
}
int wo_row_read(wo_db *db, wo_rt *rt, uint32_t class_id, uint64_t id, int wo_row_read(wo_db *db, wo_rt *rt, uint32_t class_id, uint64_t id,
uint64_t *out_vals, const char **msg) { uint64_t *out_vals, const char **msg) {
db_row *r = wo_row_ptr(db, class_id, id); db_row *r = wo_row_borrow(db, class_id, id, msg);
if (!r) return -1; if (!r) return -1;
const wo_classdesc *c = &db->classes[class_id]; const wo_classdesc *c = &db->classes[class_id];
int ok = 1; int ok = 1;
for (uint32_t i = 0; i < c->field_cnt; i++) { for (uint32_t i = 0; i < c->field_cnt; i++) {
/* decode out of the row BEFORE releasing: a keys-resident row's slots
* point into the scratch that release frees */
out_vals[i] = db_val_decode(rt, c->kinds[i], r->slots[i], &ok, msg); out_vals[i] = db_val_decode(rt, c->kinds[i], r->slots[i], &ok, msg);
if (!ok) return -2; if (!ok) {
wo_row_release(db, class_id, r);
return -2;
} }
}
wo_row_release(db, class_id, r);
return 0; return 0;
} }
@ -857,10 +1009,35 @@ static int row_apply_field_slot(wo_db *db, db_table *t, const wo_classdesc *c,
db_row *r, uint32_t class_id, uint64_t id, db_row *r, uint32_t class_id, uint64_t id,
uint32_t field, uint64_t nv, const char **msg, uint32_t field, uint64_t nv, const char **msg,
int *err_kind); int *err_kind);
static int row_apply_field_keys(wo_db *db, uint32_t class_id, uint64_t id,
uint32_t field, uint64_t nv, const char **msg,
int *err_kind);
int wo_row_update_field(wo_db *db, uint32_t class_id, uint64_t id, uint32_t field, int wo_row_update_field(wo_db *db, uint32_t class_id, uint64_t id, uint32_t field,
uint64_t vm_val, const char **msg, int *err_kind) { uint64_t vm_val, const char **msg, int *err_kind) {
if (err_kind) *err_kind = DB_ERR_MISC; if (err_kind) *err_kind = DB_ERR_MISC;
/* databasev2 3 (keys-resident delta updates): a keys-resident row lives
* in the LOG, so there is no slab slot to mutate — row_apply_field_keys
* does read-modify-APPEND instead of a slot swap. wo_row_offset1 is the
* cheap existence check wo_row_ptr would otherwise give us. */
if (wo_table_is_keys_resident(db, class_id)) {
if (!wo_row_offset1(db, class_id, id)) {
*msg = "no such row";
return -1;
}
const wo_classdesc *kc = &db->classes[class_id];
if (field >= kc->field_cnt) {
*msg = "no such field";
return -1;
}
int kok = 1;
uint64_t knv = db_val_encode(db->classes, kc->kinds[field], vm_val, &kok, msg);
if (!kok) {
if (err_kind) *err_kind = DB_ERR_BADKIND;
return -1;
}
return row_apply_field_keys(db, class_id, id, field, knv, msg, err_kind);
}
db_row *r = wo_row_ptr(db, class_id, id); db_row *r = wo_row_ptr(db, class_id, id);
if (!r) { if (!r) {
*msg = "no such row"; *msg = "no such row";
@ -903,8 +1080,11 @@ static int row_apply_field_slot(wo_db *db, db_table *t, const wo_classdesc *c,
if (!b) continue; if (!b) continue;
for (uint32_t i = 0; i < b->len; i++) { for (uint32_t i = 0; i < b->len; i++) {
if (b->ids[i] == id) continue; if (b->ids[i] == id) continue;
db_row *other = wo_row_ptr(db, class_id, b->ids[i]); const char *bmsg = "";
if (other && idx_cols_equal(c, ix, r, other)) { db_row *other = wo_row_borrow(db, class_id, b->ids[i], &bmsg);
int clash = other && idx_cols_equal(c, ix, r, other);
wo_row_release(db, class_id, other);
if (clash) {
r->slots[field] = old; /* untouched, promised */ r->slots[field] = old; /* untouched, promised */
db_val_free(c->kinds[field], nv); db_val_free(c->kinds[field], nv);
if (err_kind) *err_kind = DB_ERR_UNIQUE; if (err_kind) *err_kind = DB_ERR_UNIQUE;
@ -955,6 +1135,169 @@ static int row_apply_field_slot(wo_db *db, db_table *t, const wo_classdesc *c,
return 0; return 0;
} }
/* keys-resident counterpart of row_apply_field_slot. There is no slab slot
* to swap — the row lives in the log — so the shape is read-modify-APPEND:
* borrow (folds), append a delta with the row's current offset as the
* back-pointer. [nv] is already engine-encoded (same convention as
* row_apply_field_slot); consumed on every path.
*
* The borrow's materialised row holds ENGINE values now (keys_fold_into's
* contract matches wo_row_ptr's), so [nv] lands in r->slots[field] directly —
* no VM decode stage, same representation the WAL record and the index
* functions already expect.
*
* Task 4 (keys-resident delta updates) ruling: this function stages the
* delta but does NOT commit and does NOT move the id map — mirroring
* insert, where table.c applies RAM and db.c owns staging/commit and the
* post-barrier map move (wo_wal_pend_drop / wo_db_flush_drops for insert;
* wo_wal_pend_repoint / wo_db_flush_drops for this). The caller re-points
* using the offset it captured via wo_wal_next_offset() BEFORE calling in
* here — insert's own `koff` pattern — since nothing between that capture
* and the wo_wal_append_delta call below stages any other bytes on [w].
*
* Ordering: the unique shadow-check (against a shadow of the row, mirroring
* row_apply_field_slot's promise that a rejected update leaves the row
* untouched) is the only SOFT-trap gate and runs first, before anything
* moves. Once it passes, the index swap is RAM apply and happens
* unconditionally, mirroring wo_row_insert's doctrine order (RAM, then
* log) — from that point a failure to even STAGE the delta is fatal,
* exactly like insert's own append, because RAM has already moved and
* there is no undo.
*
* back_off checks a PENDING re-point first (wo_wal_repoint_offset1) before
* falling back to the durable wo_row_offset1: a second update to this same
* row, staged behind the same barrier as a first, must chain to the
* first's delta — the id map won't move until the barrier, but the delta
* itself is already staged and its offset already fixed. */
static int row_apply_field_keys(wo_db *db, uint32_t class_id, uint64_t id,
uint32_t field, uint64_t nv, const char **msg,
int *err_kind) {
const wo_classdesc *c = &db->classes[class_id];
db_table *t = &db->tables[class_id];
const char *bmsg = "no such row";
db_row *r = wo_row_borrow(db, class_id, id, &bmsg);
if (!r) {
db_val_free(c->kinds[field], nv);
*msg = bmsg;
return -1;
}
/* successful borrow proves db->rt and db->rt->wal are both set */
wo_wal *w = (wo_wal *)db->rt->wal;
uint64_t pending1 = wo_wal_repoint_offset1(w, class_id, id);
uint64_t back_off = (pending1 ? pending1 : wo_row_offset1(db, class_id, id)) - 1;
/* unique shadow-check: run with the NEW value before anything durable or
indexed moves, exactly row_apply_field_slot's promise.
CRITICAL: candidates are probed into a THROWAWAY buffer, never
t->scratch. r (the row under update) already lives in t->scratch and
wo_row_borrow refuses ANY nested borrow on the same table's scratch —
reusing it here would make every candidate probe return NULL, so a
clash could never be detected (a silent hole: keys-resident @unique
would accept duplicates). Candidates are always in this same,
keys-resident table, so keys_fold_into (bypassing wo_row_borrow and
its scratch_busy gate) is safe to call directly. */
uint64_t old_eng = r->slots[field];
r->slots[field] = nv;
uint8_t *cand_buf = NULL;
for (uint32_t x = 0; x < t->index_cnt; x++) {
db_index *ix = &t->indexes[x];
if (!(ix->flags & 1u)) continue;
int touches = 0;
for (uint32_t i = 0; i < ix->col_cnt; i++)
if (ix->cols[i] == field) touches = 1;
if (!touches) continue;
db_ibucket *b = idx_bucket(ix, idx_hash(c, ix, r), 0);
if (!b) continue;
if (!cand_buf) {
cand_buf = malloc(t->row_size);
if (!cand_buf) {
r->slots[field] = old_eng;
wo_row_release(db, class_id, r);
db_val_free(c->kinds[field], nv);
if (err_kind) *err_kind = DB_ERR_OOM;
*msg = "out of memory";
return -1;
}
}
for (uint32_t i = 0; i < b->len; i++) {
if (b->ids[i] == id) continue;
/* Task 4 follow-up (review finding): a candidate updated
earlier in this SAME, not-yet-committed drain has its
re-point only PENDING — the durable wo_row_offset1 would
still fold its PRE-update value, letting a real unique
clash through uncaught. Unlike back_off (a pure number),
keys_fold_into DOES need to read this record's bytes to
compare values — which is why wo_wal_fold_row_at now reads
the staging buffer for an offset in the not-yet-durable
range (see scan_record_staged in wal.c); a plain
wo_row_offset1 substitution here is not enough on its own. */
uint64_t cand_off1 = wo_wal_repoint_offset1(w, class_id, b->ids[i]);
if (!cand_off1) cand_off1 = wo_row_offset1(db, class_id, b->ids[i]);
if (!cand_off1) continue; /* stale bucket entry: no row, no clash */
const char *obmsg = "";
db_row *other =
keys_fold_into(db, class_id, b->ids[i], cand_off1 - 1, cand_buf, NULL, &obmsg);
int clash = other && idx_cols_equal(c, ix, r, other);
/* keys_fold_into decoded fresh ENGINE values for EVERY field,
same as a real borrow — nobody else owns them, so drop them
here the same way wo_row_release would */
if (other)
for (uint32_t k = 0; k < c->field_cnt; k++)
db_val_free(c->kinds[k], other->slots[k]);
if (clash) {
r->slots[field] = old_eng; /* untouched, promised */
free(cand_buf);
wo_row_release(db, class_id, r);
db_val_free(c->kinds[field], nv);
if (err_kind) *err_kind = DB_ERR_UNIQUE;
*msg = "unique index violation";
return -1;
}
}
}
free(cand_buf);
r->slots[field] = old_eng; /* restored: still the OLD row until applied */
/* RAM apply (Task 4 ruling): the borrowed row is the OLD row — out of
every index under the OLD value, then in again under the NEW one.
Unconditional from here: a failure below is fatal, not a trap. */
idx_remove_row(db, t, r);
r->slots[field] = nv;
(void)idx_add_row(db, t, r); /* cannot violate uniqueness: the shadow
check above already cleared it */
/* databasev2 11: FLATTEN ON UPDATE.
*
* `r` now holds the complete post-update row, because maintaining the
* indexes above required folding it — so writing a full-row image costs no
* extra read, only the bytes. Past WO_DELTA_MAX_HOPS we spend those bytes
* and terminate the chain instead of lengthening it.
*
* Why this lives here rather than in the checkpoint: compaction bounds
* chain length in principle, but its trigger is a byte ratio over the whole
* log and cannot see that ONE row has a long chain. A single hot row —
* this feature's own motivating workload, a popular SKU whose stock moves
* on every order — grows without ever moving that ratio. PostgreSQL solves
* the same shape the same way: heap_page_prune_opt collapses a HOT chain
* opportunistically, on a page the process already holds, rather than
* waiting for the background sweep.
*
* A full-row record is written as WO_WAL_INSERT because that is what a
* chain's base must be — it has to replay into a database where nothing
* precedes it. Replay, compaction and the fold all already handle that
* shape; none of them needs to know this happened. */
int flattened = (t->scratch_hops >= WO_DELTA_MAX_HOPS);
int arc = flattened ? wo_wal_append_row_image(w, db, class_id, id, r)
: wo_wal_append_delta(w, db, class_id, id, field, back_off, nv);
if (arc != 0)
wo_wal_stage_fatal(w); /* RAM already moved; see the insert arm */
db_val_free(c->kinds[field], old_eng); /* old value done: r now holds nv */
wo_row_release(db, class_id, r); /* frees r's slots, including nv, as engine values */
if (err_kind) *err_kind = DB_ERR_NONE;
return 0;
}
int wo_row_update_field_slot(wo_db *db, uint32_t class_id, uint64_t id, uint32_t field, int wo_row_update_field_slot(wo_db *db, uint32_t class_id, uint64_t id, uint32_t field,
uint64_t slot, const char **msg, int *err_kind) { uint64_t slot, const char **msg, int *err_kind) {
if (err_kind) *err_kind = DB_ERR_MISC; if (err_kind) *err_kind = DB_ERR_MISC;
@ -970,6 +1313,10 @@ int wo_row_update_field_slot(wo_db *db, uint32_t class_id, uint64_t id, uint32_t
*msg = "no such field"; *msg = "no such field";
return -1; return -1;
} }
/* databasev2 3 (keys-resident delta updates): a keys-resident row has no
* slab slot to mutate — row_apply_field_keys does read-modify-APPEND. */
if (wo_table_is_keys_resident(db, class_id))
return row_apply_field_keys(db, class_id, id, field, slot, msg, err_kind);
db_row *r = wo_row_ptr(db, class_id, id); db_row *r = wo_row_ptr(db, class_id, id);
if (!r) { if (!r) {
db_val_free(c->kinds[field], slot); db_val_free(c->kinds[field], slot);
@ -1002,12 +1349,95 @@ int wo_row_has_referrers(wo_db *db, uint32_t class_id, uint64_t id) {
return 0; return 0;
} }
int wo_row_next_id(const wo_db *db, uint32_t class_id, size_t *cursor, uint64_t *id_out) {
if (class_id >= db->class_cnt) return 0;
const db_table *t = &db->tables[class_id];
if (!t->row_size) return 0;
if (wo_table_is_keys_resident(db, class_id)) {
/* the id map IS the live set here: hkeys non-zero, hvals holding an
* offset + 1 */
for (size_t j = *cursor; j < t->hcap; j++) {
if (t->hkeys[j] && t->hvals[j]) {
*id_out = t->hkeys[j];
*cursor = j + 1;
return 1;
}
}
*cursor = t->hcap;
return 0;
}
{ /* resident: the bitmap, in slab order, exactly as before */
uint32_t total = t->slab_cnt * DB_SLAB_ROWS;
for (size_t g = *cursor; g < total; g++) {
if (!(t->bitmap[g >> 6] & (1ull << (g & 63)))) continue;
*id_out = slot_row((db_table *)t, (uint32_t)g)->id;
*cursor = g + 1;
return 1;
}
*cursor = total;
return 0;
}
}
int wo_table_is_keys_resident(const wo_db *db, uint32_t class_id) {
if (class_id >= db->class_cnt) return 0;
return (db->classes[class_id].flags & WO_CLASSF_RESIDENT_KEYS) != 0u;
}
int wo_row_drop_payload(wo_db *db, uint32_t class_id, uint64_t id, uint64_t wal_off) {
if (class_id >= db->class_cnt) return -1;
db_table *t = &db->tables[class_id];
if (!t->row_size) return -1;
uint64_t s1 = hget(t, id);
if (!s1) return -1;
uint32_t g = (uint32_t)(s1 - 1);
db_row *r = slot_row(t, g);
/* the values are engine-owned; the log holds their bytes now */
const wo_classdesc *c = &db->classes[class_id];
for (uint32_t i = 0; i < c->field_cnt; i++) db_val_free(c->kinds[i], r->slots[i]);
t->bitmap[g >> 6] &= ~(1ull << (g & 63));
/* the id STAYS, now pointing at the log rather than at a slab. No
* idx_remove_row and no count change: the row is live, only its backing
* moved. */
if (hput(t, id, wal_off + 1) != 0) return -1;
if (t->free_cnt == t->free_cap) {
uint32_t ncap = t->free_cap ? t->free_cap * 2 : 16;
uint32_t *nf = realloc(t->free_slots, (size_t)ncap * 4);
if (!nf) return 0; /* slot simply not recycled; the bitmap still frees it */
t->free_slots = nf;
t->free_cap = ncap;
}
t->free_slots[t->free_cnt++] = g;
return 0;
}
int wo_row_remove(wo_db *db, uint32_t class_id, uint64_t id) { int wo_row_remove(wo_db *db, uint32_t class_id, uint64_t id) {
if (class_id >= db->class_cnt) return -1; if (class_id >= db->class_cnt) return -1;
db_table *t = &db->tables[class_id]; db_table *t = &db->tables[class_id];
if (!t->row_size) return -1; if (!t->row_size) return -1;
uint64_t s1 = hget(t, id); uint64_t s1 = hget(t, id);
if (!s1) return -1; if (!s1) return -1;
/* databasev2 2 (5d): a keys-resident row's map entry is a LOG OFFSET, not
* a slot. Falling through to the slab path below would index t->slabs[]
* with a byte offset — slot_row does no bounds check — and then free
* whatever it landed on. That is memory corruption, not a missing feature,
* which is why the loader still refuses the annotation.
*
* The row has no slab slot, no bitmap bit and no free-list entry to give
* back; only the indexes and the id map know about it. The index hook
* needs the row's column VALUES to find its bucket, and those live in the
* log, so the row is borrowed for exactly as long as that takes. */
if (wo_table_is_keys_resident(db, class_id)) {
db_row *r = wo_row_borrow(db, class_id, id, NULL);
if (!r) return -1;
idx_remove_row(db, t, r);
wo_row_release(db, class_id, r); /* frees the materialised values */
hdel(t, id);
t->count--;
return 0;
}
uint32_t g = (uint32_t)(s1 - 1); uint32_t g = (uint32_t)(s1 - 1);
db_row *r = slot_row(t, g); db_row *r = slot_row(t, g);
/* the index hook's remove side: before the row's values die, while the /* the index hook's remove side: before the row's values die, while the
@ -1028,3 +1458,36 @@ int wo_row_remove(wo_db *db, uint32_t class_id, uint64_t id) {
t->free_slots[t->free_cnt++] = g; t->free_slots[t->free_cnt++] = g;
return 0; return 0;
} }
/* databasev2 2 (5d): re-point a keys-resident row at a NEW log offset.
*
* Deliberately not hput(): hput runs the load-factor check and can rehash,
* which would reorder hkeys/hvals underneath a wo_row_next_id cursor. This
* only ever overwrites the value of a key that already exists, so the table's
* shape cannot change and a walk in progress stays valid. That property is
* what lets compaction re-point rows as it writes them instead of buffering
* one (cid, id, offset) triple per live row. Returns -1 if the id is absent. */
int wo_row_set_offset(wo_db *db, uint32_t class_id, uint64_t id, uint64_t wal_off) {
if (class_id >= db->class_cnt) return -1;
db_table *t = &db->tables[class_id];
if (!t->hcap) return -1;
size_t j = hmix(id) & (t->hcap - 1);
while (t->hkeys[j]) {
if (t->hkeys[j] == id) {
t->hvals[j] = wal_off + 1;
return 0;
}
j = (j + 1) & (t->hcap - 1);
}
return -1;
}
/* databasev2 2 (5d): the log offset a keys-resident row currently reads from,
* as stored (off + 1), so 0 means "no such row". Compaction needs the raw
* offset to copy the record without materialising it. */
uint64_t wo_row_offset1(const wo_db *db, uint32_t class_id, uint64_t id) {
if (class_id >= db->class_cnt) return 0;
const db_table *t = &db->tables[class_id];
if (!t->hcap) return 0;
return hget(t, id);
}

View file

@ -120,9 +120,32 @@ typedef struct db_table {
/* secondary indexes, from the class table's v3 metadata */ /* secondary indexes, from the class table's v3 metadata */
db_index *indexes; db_index *indexes;
uint32_t index_cnt; uint32_t index_cnt;
/* databasev2 2: one reusable materialisation buffer per table, for
* wo_row_borrow. Per-TABLE and not per-call because the unique shadow
* check borrows once per candidate inside a bucket loop, and per-call
* allocation would turn an O(1) probe into an allocation storm. Safe
* because the store is single-writer (the owner shard) and a borrow is
* never nested — `busy` exists to catch it if that ever stops being
* true, rather than aliasing silently. */
uint8_t *scratch;
size_t scratch_cap;
int scratch_busy;
/* databasev2 11: how many DELTA records the last borrow's fold crossed.
* The fold reports it for free, and the update path uses it to decide when
* a chain is long enough to be worth terminating with a full-row record.
* Meaningful only while scratch_busy is set. */
uint32_t scratch_hops;
} db_table; } db_table;
typedef struct wo_db { typedef struct wo_db {
/* databasev2 2 (5c): the runtime this store belongs to, so a borrow can
* reach the WAL. wo_rt already carries `db` and `wal` as opaque handles,
* so this closes the loop without threading a wal pointer through
* wo_row_borrow's eleven call sites — which is the whole reason 5c is one
* accessor rather than eleven rewrites. NULL in test binaries and with
* durability off; a `resident: keys` table cannot exist in either case,
* because it has no log to read rows back from. */
wo_rt *rt;
const wo_classdesc *classes; const wo_classdesc *classes;
uint32_t class_cnt; uint32_t class_cnt;
uint32_t shard, nshards; /* S of N; ids interleave S+1, S+1+N, … */ uint32_t shard, nshards; /* S of N; ids interleave S+1, S+1+N, … */
@ -150,6 +173,67 @@ int wo_row_read(wo_db *db, wo_rt *rt, uint32_t class_id, uint64_t id,
* it. 0 ok, -1 no such row. */ * it. 0 ok, -1 no such row. */
int wo_row_remove(wo_db *db, uint32_t class_id, uint64_t id); int wo_row_remove(wo_db *db, uint32_t class_id, uint64_t id);
/* databasev2 2 (5c): drop a row's PAYLOAD while keeping it live.
*
* The operation the plan recorded as missing. For a `resident: keys` table the
* row's bytes live in the log, not in a slab: this frees the slot and its
* engine-owned values, then re-points the id map at [wal_off] (stored as
* off + 1, reusing the same 0-is-empty trick the slot encoding uses — a table
* is wholly `all` or wholly `keys`, so the interpretation is per-table and
* never ambiguous).
*
* What it deliberately does NOT do, and why:
* - it does not touch the secondary indexes. They store row IDS, not slots
* (see db_ibucket), so they are already indirect through the id map and
* stay correct across this.
* - it does not decrement `count`. The row is still LIVE; only its backing
* moved.
* - it does not remove the id. The id is how the row is found afterwards.
*
* [wal_off] must be the offset of a record whose commit succeeded. Since
* databasev2 4 made a failed commit fatal, no execution can reach here with an
* offset that never became durable — which is what wo_wal_next_offset's
* contract asks for, now guaranteed by process death rather than by an inline
* check the deferred barrier no longer allows.
*
* 0 ok, -1 unknown class/row. */
int wo_row_drop_payload(wo_db *db, uint32_t class_id, uint64_t id, uint64_t wal_off);
int wo_row_set_offset(wo_db *db, uint32_t class_id, uint64_t id, uint64_t wal_off);
/* databasev2 11: how many DELTA records a keys-resident row's chain may carry
* before an update terminates it with a full-row image instead of lengthening
* it. A BOUND, not a tuning knob — PostgreSQL ships `fillfactor` and
* autovacuum's base threshold as documented constants that are rarely touched,
* and this is the same kind of number. Anything in the low tens caps the
* pathology; being wrong by a factor of two costs one row-sized write per K
* updates, which is not a correctness failure in either direction.
*
* It deliberately does NOT scale with table size. PostgreSQL scales autovacuum
* by reltuples because it thresholds a table-level aggregate whose harm is
* proportional; a chain is a per-ROW property with additive cost — reading one
* row costs 1 + depth reads whether the table holds a hundred rows or ten
* million, and replay is the sum over every row's chain. Scaling this up with
* table size would make the largest databases boot worst. */
#define WO_DELTA_MAX_HOPS 16u
uint64_t wo_row_offset1(const wo_db *db, uint32_t class_id, uint64_t id);
/* databasev2 2 (5d): iterate the live row IDS of a table, whichever backing it
* has. [*cursor] starts at 0 and is opaque; returns 1 with *id_out set, or 0
* when exhausted.
*
* A keys-resident table has an EMPTY bitmap by construction — its payloads live
* in the log — so every bitmap walk in the engine would silently see no rows.
* This is the one primitive those walks move onto.
*
* Resident tables keep walking the bitmap, deliberately: the id map holds the
* same set, but in hash order, and switching would reorder the results of every
* unordered query in the repo. Two backings, one interface, no behaviour change
* where nothing needed to change. */
int wo_row_next_id(const wo_db *db, uint32_t class_id, size_t *cursor, uint64_t *id_out);
/* databasev2 2 (5c): is this table's row data in the log rather than in slabs? */
int wo_table_is_keys_resident(const wo_db *db, uint32_t class_id);
/* iteration 9b FK restrict: 1 if some row in some class holds a non-nullable /* iteration 9b FK restrict: 1 if some row in some class holds a non-nullable
* `ref` to [class_id] equal to [id] — i.e. deleting this row would dangle a * `ref` to [class_id] equal to [id] — i.e. deleting this row would dangle a
* reference. The compiler records a ref field's target class in the class * reference. The compiler records a ref field's target class in the class
@ -171,6 +255,26 @@ int wo_row_update_field(wo_db *db, uint32_t class_id, uint64_t id, uint32_t fiel
* to the VM. */ * to the VM. */
db_row *wo_row_ptr(wo_db *db, uint32_t class_id, uint64_t id); db_row *wo_row_ptr(wo_db *db, uint32_t class_id, uint64_t id);
/* ---- databasev2 2: the shared row accessor -------------------------------
*
* Every reader that today does `wo_row_ptr` and then touches `r->slots[...]`
* uses this pair instead, so ONE code path serves both residencies:
*
* resident: all borrow returns the slab pointer; release is a no-op
* resident: keys borrow materialises the record from its log offset into
* the table's scratch; release frees what it built
*
* Landed as a PURE REFACTOR: until the offset storage exists, borrow is
* wo_row_ptr plus a branch and every release is a no-op. Deliberate — the
* refactor is provable on its own, before the storage change it enables.
*
* A borrowed row is READ-ONLY when it is materialised: it is a copy, so
* writing to it changes nothing durable. Mutation still goes through the row
* choke points. Pair EVERY non-NULL borrow with a release, and never nest two
* borrows on the same table — they would share one scratch. */
db_row *wo_row_borrow(wo_db *db, uint32_t class_id, uint64_t id, const char **msg);
void wo_row_release(wo_db *db, uint32_t class_id, db_row *r);
/* Engine-internal, for WAL replay only: create a row with a FIXED id, /* Engine-internal, for WAL replay only: create a row with a FIXED id,
* slots zeroed — the caller (wal.c) fills them with engine-encoded values * slots zeroed — the caller (wal.c) fills them with engine-encoded values
* it built while decoding. Advances the table's next_id past [id] when the * it built while decoding. Advances the table's next_id past [id] when the

File diff suppressed because it is too large Load diff

View file

@ -17,6 +17,9 @@
* kind : 1 insert (body = the row's fields, engine encoding below) * kind : 1 insert (body = the row's fields, engine encoding below)
* 2 remove (no body) * 2 remove (no body)
* 3 update (reserved for Task 5) * 3 update (reserved for Task 5)
* 4 delta (single-field update; body = field_idx u32 |
* back-pointer offset u64 | the one field's value, engine
* encoding below — keys-resident tables only)
* *
* Field encoding in a body walks the class table's kinds: * Field encoding in a body walks the class table's kinds:
* SCALAR 8 bytes * SCALAR 8 bytes
@ -43,16 +46,206 @@
#define WO_WAL_MARK 0x574F4C31u /* "WOL1" LE */ #define WO_WAL_MARK 0x574F4C31u /* "WOL1" LE */
enum { WO_WAL_INSERT = 1, WO_WAL_REMOVE = 2, WO_WAL_UPDATE = 3 }; enum {
WO_WAL_INSERT = 1,
WO_WAL_REMOVE = 2,
WO_WAL_UPDATE = 3,
WO_WAL_DELTA = 4,
/* databasev2 12: the log's own statement of the shape that wrote it —
* class and field NAMES, kinds and encoding-relevant metadata. Written as
* the FIRST record of a fresh log and of every compacted log, so the head
* of a log always describes everything after it. Replay skips it; boot
* diffs it against the compiled classes to migrate or refuse. A log
* without one is a legacy log: nothing recorded, nothing diffable. */
WO_WAL_SCHEMA = 5,
};
typedef struct wo_wal { typedef struct wo_wal {
int fd; int fd;
/* databasev2 4: where this WAL lives, so a durability failure can name
* the file it could not write. An abort diagnostic without the path
* sends an operator hunting. Owned here, freed by wo_wal_close. */
char *path;
uint64_t off; /* next write offset (the intact tail) */ uint64_t off; /* next write offset (the intact tail) */
/* staged batch: appended by wal_append_*, flushed by wal_commit */ /* staged batch: appended by wal_append_*, flushed by wal_commit */
uint8_t *buf; uint8_t *buf;
size_t len, cap; size_t len, cap;
/* databasev2 4: group-commit diagnostics. Batching is worthless if
* batches are always one, and a throughput change would then have come
* from somewhere else — so the mechanism is measured, not assumed.
* peak_staged also settles whether the batch needs a cap with a number
* instead of a guess. Reported at exit under WO_WAL_STATS. */
uint64_t stat_batches; /* non-empty commits */
uint64_t stat_records; /* records those commits carried */
uint64_t stat_peak_batch; /* most records in one barrier */
uint64_t stat_peak_staged; /* most bytes staged behind one barrier */
/* databasev2 3: bytes the last compaction wrote. The trigger compares the
* log against THIS rather than an estimate of the live set — estimating
* would mean estimating Text, and the compactor knows the true number. */
uint64_t compacted_bytes;
/* databasev2 3: the preallocation this log was opened with. Compaction
* MUST give the replacement the same one: the WAL is preallocated so that
* appends never extend the file, which is what lets fdatasync alone be the
* ack barrier. A replacement without it silently weakens durability. */
uint64_t prealloc;
/* databasev2 3: what compaction actually did, reported under WO_WAL_STATS.
* The PAUSE is the number the spec refused to assume — compaction is
* stop-the-world, so its duration is the cost being weighed. */
/* databasev2 2 (5c): rows whose payload may be dropped ONCE the barrier
* they are staged behind succeeds. A keys-resident row cannot be dropped
* at append time: with group commit the record is still in the staging
* buffer, so its offset would pread zeros. Recorded here and performed by
* wo_db_flush_drops after the commit — the same shape as the drain's held
* replies, and for the same reason. If the process dies first the list
* dies with it, which is correct: nothing was dropped and nothing lost. */
struct wo_wal_pend { uint32_t cid; uint64_t id; uint64_t off; } *pend;
size_t pend_len, pend_cap;
/* Task 4 (keys-resident delta updates): rows whose id-map entry must
* move to a NEW offset once the delta staged there is durable. Same
* three fields as `pend` above, deliberately its OWN list: a drop
* discards a payload and a re-point moves a live row's chain head — two
* different meanings a shared list would force a future reader to guess
* between. Same lifetime discipline as `pend`: recorded before the
* barrier, applied after it, and lost with the process if it dies
* first — which is correct, since nothing was re-pointed either. */
struct wo_wal_pend *repoint;
size_t repoint_len, repoint_cap;
uint64_t stat_compactions;
uint64_t stat_compact_us_max;
uint64_t stat_compact_us_total;
/* databasev2 12: the encoded WO_WAL_SCHEMA payload for the COMPILED
* classes, set once at boot by wo_wal_set_schema. Owned here, freed by
* wo_wal_close. When set, a fresh log gets it as its first record
* (wo_wal_ensure_schema) and compaction writes it at the head of every
* replacement log. When unset (every existing test, and legacy boots)
* nothing changes anywhere. */
uint8_t *schema;
uint32_t schema_len;
int schema_written; /* lazy head: staged before the FIRST record only */
} wo_wal; } wo_wal;
/* databasev2 12: the schema a log carries, and the diff against the compiled
* one. Names are byte pointers, NOT constant-table indices — the database
* layer never sees the module's constant pool, so the runtime resolves names
* once when it builds the compiled-side schema, and a decoded schema's names
* point into the record's own bytes. `fclass`/`felem` mirror the classdesc's
* field_class/field_elem because they change how a value is ENCODED; index
* layout is deliberately absent — indexes are rebuilt from rows at boot and
* never touch record bytes. */
typedef struct wo_schema_field {
const uint8_t *name;
uint32_t name_len;
uint8_t kind;
uint32_t fclass; /* referenced class id, or WO_SCHEMA_NONE */
uint32_t felem; /* container element kinds, or WO_SCHEMA_NONE */
} wo_schema_field;
typedef struct wo_schema_class {
const uint8_t *name;
uint32_t name_len;
uint32_t flags;
uint32_t field_cnt;
wo_schema_field *fields;
} wo_schema_class;
typedef struct wo_schema {
uint32_t class_cnt;
wo_schema_class *classes;
uint8_t *owned; /* decode backing buffer; NULL on a caller-built schema */
} wo_schema;
#define WO_SCHEMA_NONE 0xFFFFFFFFu
/* Encode a schema as a WO_WAL_SCHEMA record payload (kind byte included).
* Returns 0 and a malloc'd buffer the caller frees. */
int wo_schema_encode(const wo_schema *sc, uint8_t **payload_out, uint32_t *len_out);
/* Decode a WO_WAL_SCHEMA payload. NULL = malformed. Free the result with
* wo_schema_free; its name pointers live in the returned struct's own copy
* of the bytes, not in the caller's buffer. */
wo_schema *wo_schema_decode(const uint8_t *payload, uint32_t len);
void wo_schema_free(wo_schema *sc);
/* databasev2 12: what boot decided about one stored class. `new_cid` is where
* its records go; WO_SCHEMA_NONE means POISONED — the class cannot be
* migrated, and `poison` says why. A poison only bites when a record of the
* class is actually met: no rows, no verdict. */
typedef struct wo_mig_class {
uint32_t new_cid; /* WO_SCHEMA_NONE = poisoned */
char *poison; /* malloc'd reason; NULL unless poisoned */
uint32_t old_field_cnt;
int32_t *fmap; /* old field index -> new slot, -1 = deleted */
int changed; /* own field set differs (add and/or delete) */
} wo_mig_class;
typedef struct wo_mig_plan {
uint32_t old_class_cnt;
wo_mig_class *classes;
/* 1 = every stored class keeps its cid and its shape: replay as-is, no
* transcode. New classes in the binary do not break identity — they have
* no records, and the head record refreshes at the next compaction. */
int identity;
} wo_mig_plan;
/* Diff the log's stored schema against the compiled one, classes matched by
* NAME, fields by NAME — so pure declaration reordering is identity apart
* from the cid map. Returns 0 with *plan filled (free with
* wo_mig_plan_free), -1 on OOM. Refusals are expressed as per-class poisons,
* not errors: retype, same-kind delete+add (a disguised rename), a vanished
* class, changed flags, and any class that EMBEDS (owned/container fields)
* a class whose shape changed — its old records encode the old sub-shape,
* which v1 does not rewrite recursively. */
int wo_schema_diff(const wo_schema *oldsc, const wo_schema *newsc, wo_mig_plan *plan);
void wo_mig_plan_free(wo_mig_plan *plan);
/* databasev2 12: rewrite the log at `path` from its stored shape to the
* compiled one — a record-level transcode, no db state touched: cids remap by
* name (embedded owned values included), surviving fields move to their new
* slot, deleted fields' values are freed, added fields take the kind's zero
* value, and a delta chain whose field vanished is spliced around. The new
* log is written the way compaction writes one (temp, fsync, rename), so a
* crash anywhere leaves the old log intact and the next boot re-migrates.
* `db` supplies the COMPILED classes for encoding; nothing is inserted.
* Returns 0 on success, -1 on I/O or corruption, -2 when a record of a
* poisoned class was met — *err_out (malloc'd, caller frees) then carries the
* poison text. */
int wo_wal_migrate(const char *path, wo_db *db, const wo_schema *oldsc,
const wo_mig_plan *plan, const wo_schema *newsc,
uint64_t prealloc, char **err_out);
/* Adopt `sc` as this log's compiled schema (encoded and owned by the wal). */
int wo_wal_set_schema(wo_wal *w, const wo_schema *sc);
/* A fresh, empty log gets the schema as its first record — durable before
* any row record can be staged behind it. No-op when a schema was never set
* or when records already exist (a legacy log stays legacy until its next
* compaction writes the record at the head of the replacement). */
int wo_wal_ensure_schema(wo_wal *w);
/* Peek the log's head record. 0 = schema record found (*payload_out is
* malloc'd, caller frees); 1 = no log, empty log, or a legacy head record;
* -1 = I/O error. */
int wo_wal_read_schema(const char *path, uint8_t **payload_out, uint32_t *len_out);
/* databasev2 2: the file offset the NEXT staged record will occupy.
*
* Exact, and knowable at append time — no deferral to flush is needed, which
* is what the design spec feared. `off` is the durable tail and `len` the
* bytes staged but not yet written, and wo_wal_commit pwrites the whole batch
* AT `off` before advancing it, so a record staged now lands at off+len.
*
* Correct across the two awkward cases:
* - a failed commit leaves `off` unadvanced and `len` intact, so the batch
* is rewritten from the same place and previously-reported offsets stay
* valid;
* - a torn tail is handled by wo_wal_open, which positions `off` at the end
* of the INTACT prefix, so offsets are always relative to validated data.
*
* Call it BEFORE the append whose offset you want, and only trust the value
* after the matching wo_wal_commit returns 0 — a record whose commit failed
* was never durable and its offset must not be recorded anywhere.
*
* Not pure: on a fresh log with a schema set, the first call stages the
* lazy schema head (databasev2 12) so the answer names the CALLER's record.
* Staged inside the append instead, the head displaced the first
* keys-resident row: db.c's koff pointed at the schema record and the row
* read back as "record header is malformed" (2026-09-10). A head-stage OOM
* is wo_wal_stage_fatal — the death the append would have taken. */
uint64_t wo_wal_next_offset(wo_wal *w);
/* Open (create if missing) and preallocate [prealloc] bytes (best-effort; /* Open (create if missing) and preallocate [prealloc] bytes (best-effort;
* a filesystem without fallocate still works). Positions the write offset * a filesystem without fallocate still works). Positions the write offset
* at the end of the INTACT record prefix — an existing file is scanned the * at the end of the INTACT record prefix — an existing file is scanned the
@ -61,6 +254,22 @@ typedef struct wo_wal {
int wo_wal_open(wo_wal *w, const char *path, uint64_t prealloc); int wo_wal_open(wo_wal *w, const char *path, uint64_t prealloc);
void wo_wal_close(wo_wal *w); void wo_wal_close(wo_wal *w);
/* databasev2 7: WO_DATA names the store as EITHER a directory or the log file.
* An existing directory or a trailing '/' resolves to "<dir>/shard-0.wal" —
* the bytes every deployment before this iteration used, unchanged. Anything
* else IS the log: an existing regular file is opened, an absent path is
* created by wo_wal_open — but only under a parent directory that exists NOW.
* The resolver never mkdirs: a typo must not plant a store somewhere
* unexpected. Pure — stats, creates nothing. 0 ok, [out] = the log path;
* WO_WAL_PATH_NO_PARENT, [out] = the parent that is not an existing directory
* (for the refusal line); WO_WAL_PATH_NOT_A_FILE: exists, neither a regular
* file nor a directory (fifo, socket, device); WO_WAL_PATH_TOO_LONG: the
* result would not fit [cap] — refused, never truncated. */
#define WO_WAL_PATH_NO_PARENT -1
#define WO_WAL_PATH_NOT_A_FILE -2
#define WO_WAL_PATH_TOO_LONG -3
int wo_wal_resolve_data_path(const char *wo_data, char *out, size_t cap);
/* Stage a record for the row that MUST already be applied to RAM (the /* Stage a record for the row that MUST already be applied to RAM (the
* commit-order doctrine). Insert/update read the row via wo_row_ptr. * commit-order doctrine). Insert/update read the row via wo_row_ptr.
* 0 ok, -1 OOM / no such row. */ * 0 ok, -1 OOM / no such row. */
@ -70,11 +279,154 @@ int wo_wal_append_remove(wo_wal *w, uint32_t class_id, uint64_t id);
* with the same id; the prefix/suffix delta trick from the survey is a * with the same id; the prefix/suffix delta trick from the survey is a
* later optimization, recorded). Call AFTER the RAM update. */ * later optimization, recorded). Call AFTER the RAM update. */
int wo_wal_append_update(wo_wal *w, wo_db *db, uint32_t class_id, uint64_t id); int wo_wal_append_update(wo_wal *w, wo_db *db, uint32_t class_id, uint64_t id);
/* DELTA logs one field change, for a keys-resident row whose payload may
* already be gone from RAM (so there is no whole row to re-log). back_off
* is the row's PREVIOUS record's offset (insert or an earlier delta) — a
* caller parameter, not looked up here, so the encoder stays ignorant of
* table/map state. */
int wo_wal_append_delta(wo_wal *w, wo_db *db, uint32_t class_id, uint64_t id,
uint32_t field_idx, uint64_t back_off, uint64_t value);
/* databasev2 4: which half of the barrier failed. A pwrite failure and an
* fdatasync failure are different operational problems (a short write vs a
* device refusing the flush), so the diagnostic must name the right one. */
#define WO_WAL_ERR_WRITE (-1)
#define WO_WAL_ERR_SYNC (-2)
/* The process exit status for a durability failure.
*
* 74 is sysexits' EX_IOERR, chosen deliberately over a small number: 1 is a
* trap and 2 is a loader refusal, but 3 and 4 are already used by SAMPLES for
* their own meanings — db-bench's own `verify` exits 3 on a checksum mismatch,
* and it is the gate that exercises durability, so a durability abort exiting 3
* would have been indistinguishable from the mismatch it is supposed to help
* diagnose. The low range belongs to programs; the runtime takes a high one. */
#define WO_EXIT_DURABILITY 74
/* Write the staged batch and fdatasync — the ack line. Empty batch = ok, /* Write the staged batch and fdatasync — the ack line. Empty batch = ok,
* no syscall. 0 ok, -1 write/sync failure (the batch stays staged). */ * no syscall. 0 ok, WO_WAL_ERR_WRITE / WO_WAL_ERR_SYNC on failure (the
* batch stays staged: a failed commit consumes nothing). */
int wo_wal_commit(wo_wal *w); int wo_wal_commit(wo_wal *w);
/* databasev2 2 (5c): note a payload that may be dropped after the next commit.
* 0 ok, -1 out of memory (the row simply stays resident, which is safe). */
int wo_wal_pend_drop(wo_wal *w, uint32_t cid, uint64_t id, uint64_t off);
/* Task 4 (keys-resident delta updates): note a keys-resident row's id-map
* entry that must move to [off] once the delta staged there is durable —
* the update-arm counterpart of wo_wal_pend_drop, on its own list (see the
* `repoint` field). 0 ok, -1 out of memory.
*
* IMPORTANT 1 (review finding): unlike wo_wal_pend_drop, a failure here is
* NOT safe to ignore. Replay does NOT reconcile a lost re-point: if a
* second update to this row lands in the same drain, it finds no pending
* entry, falls back to the stale durable offset, and its delta chains PAST
* the one this call was meant to record — every reader, replay and
* compaction included, then agrees on the wrong value, permanently.
* Callers must treat a nonzero return as fatal (wo_wal_repoint_fatal),
* exactly like a failed wo_wal_stage_fatal. */
int wo_wal_pend_repoint(wo_wal *w, uint32_t cid, uint64_t id, uint64_t off);
/* Task 4: the most recent PENDING re-point recorded for (cid, id), not yet
* flushed to the id map — needed so a second update to the same row, staged
* behind the SAME barrier as the first, computes its back-pointer against
* the first's delta instead of the row's last DURABLE offset (which would
* skip it). Off + 1, 0 = none pending (the caller falls back to
* wo_row_offset1). Does NOT consult the durable map itself. */
uint64_t wo_wal_repoint_offset1(const wo_wal *w, uint32_t cid, uint64_t id);
/* databasev2 2 (5c): perform every pending drop, THEN every pending
* re-point (Task 4). Call ONLY after a commit has succeeded — that is what
* makes the recorded offsets readable. */
void wo_db_flush_drops(wo_db *db, wo_wal *w);
/* databasev2 3: the checkpoint trigger, as a PURE decision so it can be tested
* without a store — which is the only way a policy like this gets tested at all.
*
* [used] the log's used bytes; [last] what the LAST compaction wrote (0 if it
* has never run); [floor] the size below which compacting is not worth it;
* [ratio] the multiple of [last] that counts as too much history.
*
* The denominator is the last compaction's MEASURED output rather than an
* estimate of the live set: estimating would mean estimating Text, and the
* compactor already knows the true number.
*
* There is deliberately NO TIME component. Postgres' CheckPointTimeout exists
* to bound data loss from unflushed buffers; our records are durable at commit,
* so a checkpoint only reclaims space and shortens boot. An idle log does not
* grow, so a timer would fire with nothing to do.
*
* 1 = compact now, 0 = leave it. */
/* databasev2 11: the two terms a size-based policy needs beside its ratio.
*
* WO_CKPT_ABS_BYTES is the TRIGGERING threshold — PostgreSQL's
* `autovacuum_vacuum_threshold`, not our `floor`, which suppresses instead.
* Past this much reclaimable garbage, compact regardless of proportion, so
* garbage that is large absolutely but small against a big live set still gets
* reclaimed.
* It also does the job PostgreSQL splits into a second constant
* (`autovacuum_vacuum_max_threshold`): capping how long a very large live set
* can defer compaction. A separate ceiling was implemented and then removed as
* unreachable — postgres needs two constants because it counts TUPLES with its
* pair at opposite ends (50 and 1e8); this counts BYTES, so any ceiling above
* this value can never fire and any below it would simply be the trigger. */
#define WO_CKPT_ABS_BYTES (64u * 1024u * 1024u)
int wo_wal_should_compact(uint64_t used, uint64_t last, uint64_t floor, uint32_t ratio);
/* Defaults, overridable at boot by WO_CHECKPOINT_BYTES / WO_CHECKPOINT_RATIO.
* The knobs are what make the policy testable: a test sets a tiny floor and
* forces compaction in a few writes instead of waiting for megabytes. */
extern uint64_t wo_wal_ckpt_floor;
extern uint32_t wo_wal_ckpt_ratio;
/* databasev2 3: the temporary file compaction writes before the swap. Named
* next to the log so it lands on the same filesystem — rename(2) is only
* atomic within one. Boot removes a stale one (a crash before the rename). */
#define WO_WAL_TMP_SUFFIX ".compact"
/* databasev2 3: rewrite the log as one INSERT record per LIVE row, then swap
* it in with rename(2).
*
* Recovery is deliberately untouched: the result is an ordinary log in the
* ordinary grammar, replayed from byte 0. Crash safety comes from rename being
* atomic — before it the live log is intact and the temp file is not
* authoritative; after it the new log is complete. There is no window in which
* a reader sees a mixture, so this needs no recovery logic of its own.
*
* REFUSES if anything is staged (returns -1 without touching the log): those
* records would be written into a file about to be replaced. Callers must
* invoke this only where the staging buffer is empty — right after a barrier.
*
* A failure is a MISSED OPTIMISATION, not a durability event: the original log
* is left usable and the process keeps running. It must not take the fatal
* path wo_wal_commit_fatal takes.
*
* 0 ok, -1 on any failure. */
int wo_wal_compact(wo_wal *w, wo_db *db);
/* databasev2 4: a record could not even be STAGED (the row is already in
* RAM, so this is the same unrecoverable position as a failed barrier — see
* wo_wal_commit_fatal). Never returns. */
void wo_wal_stage_fatal(const wo_wal *w);
/* IMPORTANT 1 (review finding): a pending re-point could not even be
* RECORDED — same unrecoverable position as wo_wal_stage_fatal, see
* wo_wal_pend_repoint's own doc. Never returns. */
void wo_wal_repoint_fatal(const wo_wal *w);
/* databasev2 4: commit, or END THE PROCESS.
*
* The one rule this iteration introduces: once a statement has mutated RAM,
* the only outcomes are durable or process death. Retrying is not an
* alternative — on Linux a failed fsync may already have discarded the dirty
* pages, so a second call can report success having written nothing. The
* recovery that works is replay, which returns the last durable state.
*
* [nrec] is the number of records in the batch, for the diagnostic only.
* Returns on success; never returns on failure. */
void wo_wal_commit_fatal(wo_wal *w, uint32_t nrec);
/* Boot replay: apply every intact record to [db] in order. Ids re-enter /* Boot replay: apply every intact record to [db] in order. Ids re-enter
* exactly as logged; each table's next_id advances past the replayed ids * exactly as logged; each table's next_id advances past the replayed ids
* that belong to this shard. Returns the number of records applied, or -1 * that belong to this shard. Returns the number of records applied, or -1
@ -83,6 +435,92 @@ int wo_wal_commit(wo_wal *w);
* the intact prefix and reports it. */ * the intact prefix and reports it. */
int64_t wo_wal_replay(const char *path, wo_db *db); int64_t wo_wal_replay(const char *path, wo_db *db);
/* databasev2 2: as wo_wal_replay, but distinguishes the two failure kinds.
* Returns the applied count on success; -1 on corruption beyond a torn tail;
* -2 when the log holds records for a class the loaded image declares
* `durable: false`, writing that class id through [volatile_cid] if non-NULL.
* The plain wo_wal_replay above is this with NULL, kept so the existing
* callers and the 156 WAL unit checks are untouched. */
int64_t wo_wal_replay_ex(const char *path, wo_db *db, uint32_t *volatile_cid);
/* databasev2 2: read one row straight from a log offset — the offset twin of
* wo_row_read. [out_vals] must have room for the class's field_cnt values and
* receives FRESH VM allocations (the out-gate: always copies). [class_out] and
* [id_out] are optional. Offsets come from wo_wal_next_offset, recorded at
* append time.
*
* 0 ok
* -1 no intact record at that offset, a malformed header, a record that
* does not decode, trailing bytes, or a REMOVE tombstone (which carries
* no fields — refused rather than decoded, since returning a deleted row
* as live is the worst outcome available here)
* -2 out of memory (*msg set)
*
* Nothing in the engine calls this yet: it is the read half of `resident:
* keys`, landed ahead of the storage change so it can be tested alone. */
int wo_wal_read_row_at(wo_wal *w, wo_db *db, wo_rt *rt, uint64_t off,
uint32_t *class_out, uint64_t *id_out, uint64_t *out_vals,
const char **msg);
/* keys-resident delta updates, Task 2: fold a delta chain into a row's
* CURRENT field values, walking BACKWARD from [off] until a full row
* (INSERT/UPDATE) is reached.
*
* [off] is the row's most recent record, exactly what wo_wal_read_row_at
* takes. Each delta names its predecessor's offset (the append-time
* back-pointer); the walk keeps hopping backward, remembering the FIRST
* value seen for each field index — the newest delta touching it, since
* newest is seen first — and skipping a delta whose field is already
* resolved. Reaching the base row decodes every field, then overlays
* whatever the walk resolved.
*
* out_vals[0..field_cnt) receive ENGINE-owned values (dec_val's
* representation, exactly what a slab row's own slots hold) — NOT VM
* values — so this one function serves every caller: a read decodes the
* result onward through wo_val_decode_vm, replay installs it straight into
* a freshly created row's slots, and compaction re-encodes it with enc_val
* into a fresh full-row record. The caller frees every slot with
* wo_db_val_free once done, on every path. This is the fold: written once,
* called by all three — a fold that disagreed between them would be a
* database that changes its mind at boot.
*
* [class_out] / [id_out] (optional) receive the row's identity, checked
* against EVERY record touched — a chain that disagrees about whose row it
* is is corruption, not a new row.
*
* A back-pointer must name something STRICTLY EARLIER in the log than the
* record holding it — the row's PREVIOUS record, by construction, always
* is. Anything else (a self-pointer, a forward pointer, corruption or
* forgery of any shape) is refused on the very hop that violates it, which
* also rules out a cycle: a walk that only ever moves to a lower offset
* cannot revisit one.
*
* 0 ok, -1 no intact/malformed/corrupt record anywhere in the chain (or a
* REMOVE tombstone reached mid-chain), -2 out of memory. [msg] may be NULL
* (wo_idx_probe borrows without one: a candidate that does not fold is not a
* hit); when given it names every refusal. */
/* databasev2 11: `hops_out` (may be NULL) reports how many DELTA records the
* walk crossed before reaching the full-row record that terminates the chain —
* 0 for a row that has never been updated. The walk already visits each hop, so
* this costs nothing, and it is the signal the update path uses to decide when
* to flatten. It is this design's equivalent of PostgreSQL's `pd_prune_xid`: a
* cheap "is work worth doing" hint obtained from something already being done. */
int wo_wal_fold_row_at(wo_wal *w, wo_db *db, uint64_t off, uint32_t *class_out,
uint64_t *id_out, uint64_t *out_vals, uint32_t *hops_out,
const char **msg);
/* databasev2 11: append a FULL-ROW image taken from a caller-supplied row,
* rather than one looked up by id. wo_wal_append_insert sources its values via
* wo_row_ptr, which is NULL for a keys-resident row whose payload has been
* dropped; the update path holds a materialised row and needs to log it as a
* chain-terminating record. Written as WO_WAL_UPDATE, not WO_WAL_INSERT: the
* live log already carries the row's insert, so an INSERT here would replay as
* a duplicate id (corruption). UPDATE replays as remove-then-recreate and the
* fold terminates on either full-row kind. (Compaction's own flattening writes
* INSERT because it builds a FRESH log — see wal.c.) */
int wo_wal_append_row_image(wo_wal *w, wo_db *db, uint32_t class_id, uint64_t id,
const db_row *r);
/* Offline verification (no engine): scan [path], count intact records. /* Offline verification (no engine): scan [path], count intact records.
* *intact_bytes (optional) = where the intact prefix ends. -1 = open * *intact_bytes (optional) = where the intact prefix ends. -1 = open
* failure. */ * failure. */

View file

@ -18,6 +18,12 @@ Native speed — the big one. Everything is interpreted: ~40× behind Go on raw
## Verification 2026-08-20 ## Verification 2026-08-20
> **Read the 2026-08-26 re-verification at the bottom before quoting anything
> from this section.** Eight of its rows have since been overtaken by shipped
> work. The section is kept as written — it is a dated measurement, and
> rewriting it would destroy the record of what was true when the iteration
> order was re-sequenced against it.
Every claim above was checked against the tree. **26 of 27 hold. One number Every claim above was checked against the tree. **26 of 27 hold. One number
does not, and two problems are worse than stated.** does not, and two problems are worse than stated.**
@ -87,3 +93,66 @@ The iteration order in
[`stories/language-runtime-database/00-story.md`](stories/language-runtime-database/00-story.md) [`stories/language-runtime-database/00-story.md`](stories/language-runtime-database/00-story.md)
was re-sequenced against these findings on 2026-08-20 — Seq only, no `#` was re-sequenced against these findings on 2026-08-20 — Seq only, no `#`
renumbered, no file moved. See that table's second re-sequencing note. renumbered, no file moved. See that table's second re-sequencing note.
---
## Re-verification 2026-08-26
Re-run against the tree, reading source rather than documents. **Eight rows
have been overtaken by shipped work; the rest still hold.** Overtaken:
| 2026-08-20 row | What the source says now |
| --- | --- |
| "no `Float`, no `Bytes`" | `types.ml`'s `builtin_scalars` is `["Int"; "Bool"; "Text"; "Timestamp"; "Id"; "Float"; "Bytes"]` — iteration 19, plus the `float`/`trunc` bridges and the `bytes_*`/`base64_*` builtins |
| "`send` is one-way — `WO_B_SEND=69` is the last builtin (`WO_B_MAX 69u`)" | `WO_B_MAX` is `95u`; `WO_B_CALL = 88` is a send that parks the caller for a typed scalar reply (iteration 24, WO-E226) |
| "no crypto primitives" | `WO_B_SHA1 = 85`, `WO_B_SHA256 = 86`, `WO_B_HMAC_SHA256 = 87`; `runtime/src/crypto.c`, vector-accepted in `test_crypto.c` (iteration 34) |
| "unbounded mailboxes, no backpressure" | mailboxes are capped (`WO_MAILBOX`, default 1024) with a sender-side reserve and a catchable `WO_T_ACTOR` trap on overflow |
| "no supervision, links, actor death" | **partly** overtaken: actor death landed with `call` — a dead or mid-call callee traps the caller instead of hanging it. `monitor` (id 89) and `time.after` (id 90) are still literal holes in the builtin enum; supervision trees remain absent |
| "22's battery never run — no `bench/baseline.json`, no `just db-bench`" | `bench/baseline.json` exists with the campaign's metrics, `just db-bench`/`db-bench-quick` are recipes, `bench/results/` holds the runs, iteration 22 is done |
| "no fuzzing, **no CI**" | `.github/workflows/release.yml` builds, verifies and publishes on a `v*` tag. Fuzzing is still absent, and CI is release-only — nothing runs the gates per change, which is iteration 30's remaining half |
| "one framework, five samples, one consumer" | two libraries (`writeonce-serve`, `writeonce-view`) and 13 samples, 8 of them gated |
| "The multi-shard DB gap is structural" (Understated) | closed by the arc's stage 3: the string `"database engine not initialized"` no longer exists in `runtime/src/`, worker statements marshal to the owner shard, and `just db-actor` gates it |
Still true, re-checked at the source: interpreted-only with no JIT and no SIMD;
the ceilings correction (`WO_STACK_SLOTS 4096`, `WO_MAX_REGS 64`,
`WO_MAX_FRAMES 256`, `WO_MAX_SHARDS 64`); no generics beyond `multi`/`map`; no
closures or function values; byte strings with no Unicode awareness; traps and
`try` instead of Result values; `switch` without destructuring; round-robin
placement with no work stealing; no timers beyond `time.sleep`; no TLS; no
HTTP/2; observability is `print`/stderr with no counters, tracing or profiler; no
debugger and no LSP; deps are git-rev-only with no registry, semver or transitive
resolution; blue-green and migrations are futures; TSan covers one demo. And
**`map<K,V>` lookup is still a linear scan** — `runtime/src/cont.h` says so in
its own header comment, which keeps it the compute problem this document argued
it was.
Two capability gaps this re-run named that the original critique did not, now
[iteration 38](stories/language-runtime-database/38-content-platform-capabilities.md):
`fs` has six builtins (ids 40–45) and can create, grow and read a file but never
replace, truncate, delete or rename one; and there is no `net.connect` anywhere
in `runtime/src/`, so no program can open an outbound connection.
## Re-verification 2026-09-09
Code is the source of truth; the standing critique's production-plumbing row and
the 2026-08-26 re-verification have been overtaken by shipped work. Kept as
written above; corrected here:
- **"No TLS anywhere (proxy-mandated forever)"** — false since 2026-09-09.
Runtime-v2 9 landed hand-rolled TLS 1.3 in-process, both directions:
`net.connect_tls`/`net.read_tls`/`net.write_tls` (ids 115–117) and
`net.accept_tls` (118), live-gated (`just tls`, `just tls-server`). The
proxy-termination doctrine is retired.
- **"no crypto primitives"** — false. `crypto.c` holds SHA-1/SHA-256/HMAC (iteration
34), ChaCha20-Poly1305, AES-GCM, HKDF, X25519, RSA-PSS/PKCS1 + ECDSA-P256 verify
*and* constant-time sign (RFC 6979), and an X.509 layer — all RFC/NIST-vector
gated.
- **"there is no `net.connect` anywhere in `runtime/src/`"** — false since
2026-09-07 (`WO_B_NET_CONNECT` = 110; the id ceiling is now `WO_B_MAX` 118).
- **"send is one-way — no reply/request-response"** — overtaken by iteration 24's
`call`; **"no supervision, links, or actor death"** — overtaken by iteration 24's
monitors/death notices; the cross-shard message double free that shadowed the
actor path (language 41) is fixed (`63065ff`, marshal on the crossing).
- Still true: no HTTP/2, no debugger/LSP, git-rev-only deps, and — precisely —
**no RNG exposed to `.wo`** (the runtime has a `getrandom` source since rv2 9,
unsurfaced until porch 2's `random_bytes`).

View file

@ -0,0 +1,122 @@
# databasev2 — chain and dependency review
Reviewed 2026-08-29 against story frontmatter, the track index's sequence
table, and the code as it stands on `dev`. Six findings, ordered by how much
damage each could do if acted on.
## The recorded picture
`chain` is a **cross-track** field (positions 1–6, defined in
`docs/stories/board-views.md`), not a databasev2 one. Only two databasev2
iterations carry it:
| chain | Story | status |
| --- | --- | --- |
| 1 | language 08 shard-actor runtime, 11 fibers | done |
| 2 | language 22 durability/throughput/scale | done |
| 3 | language 31 actor lifecycle, 40 shutdown drain | done |
| 4 | language 24 chat/websocket workload | done |
| 5 | **databasev2 4** io_uring group commit | in-progress |
| 6 | **databasev2 3** WAL checkpoint | done |
The track's own sequence lives in `00-story.md` as a Needs column plus an
ASCII graph. The two disagree with each other, with the chain field, and with
what happened.
## Finding 1 — the graph contradicts the chain field and the history
`00-story.md` draws `3 ──▶ 4`: iteration 3 before iteration 4. The chain field
says the opposite — iteration 4 is chain 5, iteration 3 is chain 6, so 4 comes
first. History settles it: **4's part A landed 2026-08-28, 3 landed
2026-08-29.** The chain field and the history agree; the graph is wrong.
Worth fixing rather than shrugging at, because the graph is the artefact
someone reads when choosing what to start.
## Finding 2 — the graph contradicts its own prose about direction
The order rationale states "**3 and 4 matter to 2**" — that is, 2 depends on 3
and 4. The graph draws an edge *from* 2 *to* 3, which reads as the reverse.
One of the two is backwards, and the prose is the one that matches the code:
`resident: keys` needed the checkpoint, not the other way round.
## Finding 3 — a retired path is still drawn
The graph still shows `2 ──▶ 5 ──▶ 6`. The 2026-08-27 amendment directly below
it says iteration 6 is largely superseded by 2, and that **5 is no longer a
prerequisite for anything on the critical path**. The prose retired the path;
the picture kept it.
## Finding 4 — the chain metadata omits the iteration doing the work
Iteration 2 is on the critical path, is `in-progress`, and is where 5c/5d just
landed — and it carries **no `chain` field**. The board-views query "the
concurrency chain, in execution order" filters `WHERE chain`, so iteration 2 is
invisible to it. Either 2 belongs on the chain and should say so, or the chain
is genuinely a concurrency artefact that databasev2 2 sits outside — in which
case 3 and 4 carrying it while 2 does not deserves a one-line explanation.
## Finding 5 — iteration 3's hazard section is stale, and was incomplete
This is the one with teeth.
`03-wal-checkpoint.md` carries a "Hazard: compaction invalidates every
`resident: keys` offset" section and a matching Outstanding entry. Both are now
**stale**: the Outstanding entry says "**Nothing fails today** because
iteration 2's storage half is unimplemented", which stopped being true when
5c/5d landed (`125bd09`, `08abd09`, `0c97fa4`, `f606fc9`). The hazard also
offers two shapes and says "the first is almost certainly right" — the first
*was* implemented, and the section should now record that as settled rather
than as an open fork.
More importantly, **the recorded hazard named only half the danger.** It
described stored offsets becoming wrong: a pointer into a rewritten file.
Implementation found a second, worse failure it did not anticipate — compaction
walked the slab **bitmap**, and a keys-resident row has no bitmap bit, because
its slot is returned to the free list when the payload is dropped. Every such
row would therefore have been **omitted from the new log entirely**. That is
silent data loss, not a bad pointer, and no amount of offset-rebuilding would
have caught it.
Both failure modes are now pinned by `test_keys_resident_survives_compaction`,
which rewrites rows in hash order so offsets genuinely move and a missing
re-point cannot pass by luck.
## Finding 6 — the coupling is now bidirectional, and undocumented in that direction
The docs record 2 depending on 3. After 5d, **3's own deliverable depends on
2's API**: `wo_wal_compact` in `database/src/wal.c` now calls
`wo_row_next_id`, `wo_row_offset1`, `wo_row_set_offset` and
`wo_table_is_keys_resident` — all iteration 2 surface. Compaction can no longer
be described as a pure file operation, which is exactly what the hazard section
predicted and no dependency table records.
Minor, same family: iteration 6 is "largely superseded" and to be revisited
"only with a measurement showing the page cache insufficient" — a hold
condition — yet its status is `pending` while genuinely parked iterations 8, 9
and 10 are `hold`.
## Addendum 2026-08-29 — the recommendation this review implied was wrong
This review argued the next step was to measure `resident: keys` before
investing further, and that measuring required narrowing the loader refusal so
a benchmark could declare such a table. **Auditing the code before narrowing it
found that `delete` on a keys-resident table was memory corruption**, not a
missing feature: `wo_row_remove` read the id map's value as a slot when on such
a table it is a log offset, and `slot_row` bounds-checks nothing.
The refusal was therefore load-bearing in a way nobody had written down. It was
justified in the docs by "updates are unimplemented" — one honest gap — while
actually standing in front of two, one of which frees arbitrary pointers.
Both are now closed or contained (`wo_row_remove` fixed, `wo_row_ptr` returns
NULL rather than a wild pointer), but the lesson generalises: **a guard whose
stated reason is narrower than its real one will eventually be removed by
someone who believes the stated reason.**
## What is actually blocked
Nothing in databasev2 is blocked on anything else in databasev2. Iteration 2's
remaining tasks 6 and 7 depend only on iteration 2. Iteration 4's part B is not
blocked either — it is unstarted with an invalidated premise, which is a
re-brainstorm, not a dependency.

View file

@ -6,8 +6,12 @@
> to pick the next implementation: anything whose incoming arrows are all > to pick the next implementation: anything whose incoming arrows are all
> green is startable today. Rebuilt 2026-08-20 from a sweep of every > green is startable today. Rebuilt 2026-08-20 from a sweep of every
> story/spec/plan markdown (the "misses" pass: iteration 17's outgoing > story/spec/plan markdown (the "misses" pass: iteration 17's outgoing
> edges, the concurrency chain, the post-12 parked drain, 9b→10, > edges, the concurrency chain, the parked drain, 9b→25, 28's gap
> 14's gap fan-out, 20's fiber caveat). > fan-out, 20's fiber caveat), and **refreshed 2026-08-26** against the
> code and the story frontmatter: graph 1 had drifted a generation
> behind — it still showed 17 parked and 18 as next, and it used the
> pre-renumber ids 10/12/13/14 for what are now stories 25/26/29/28. All
> iterations through 38 are now nodes.
## 1. Story iterations ## 1. Story iterations
@ -17,6 +21,7 @@ flowchart TD
classDef parked fill:#6e7781,color:#fff,stroke:none classDef parked fill:#6e7781,color:#fff,stroke:none
classDef specd fill:#0969da,color:#fff,stroke:none classDef specd fill:#0969da,color:#fff,stroke:none
classDef open fill:#eac54f,color:#000,stroke:none classDef open fill:#eac54f,color:#000,stroke:none
classDef inprog fill:#8250df,color:#fff,stroke:none
FOUND["1–6 foundation: doctrine, VM, compiler, binary, surface, stdlib"]:::done FOUND["1–6 foundation: doctrine, VM, compiler, binary, surface, stdlib"]:::done
I7["7 log-watcher proof"]:::done I7["7 log-watcher proof"]:::done
@ -26,23 +31,37 @@ flowchart TD
I15["15 deps package manager"]:::done I15["15 deps package manager"]:::done
I16["16 web framework v1 core"]:::done I16["16 web framework v1 core"]:::done
I17["17 library kind + internal/ (PARKED — spec+plan ready, branch library-internal)"]:::parked I17["17 library kind + internal/ ✅ 2026-08-20"]:::done
FWREORG["framework internal/ reorg + check mode (kills the --emit workaround; WO-E108/E109 reserved)"]:::parked FWREORG["framework internal/ reorg + check mode ✅ landed with 17 (WO-E108/E109 shipped)"]:::done
I18["18 framework v2: transaction{} + cache/flags/jobs (spec APPROVED — the next implementation)"]:::specd I19["19 Float + Bytes ✅ 2026-08-20"]:::done
I37["37 wo-html components + raw text literal ✅ 2026-08-25"]:::done
I35["35 net runtime seams ✅ 2026-08-23"]:::done
I36["36 operator parity: not/bitwise/hex literals — code landed 2026-08-22, awaiting the manual pass"]:::specd
RELEASE["packaging + release pipeline ✅ 2026-08-25 (no story: VERSION, just dist, install-accept, release.yml)"]:::done
I9c["20 cross-program tables (half-built)"]:::open I18["18 transaction{} 🔄 hold lifted + split 2026-09-11 (cache/flags/jobs → porch 10, graph 4); T1–T6, T8, T9 landed same day, corpus green; open: kill -9 battery (T7)"]:::inprog
I9d["21 keypair attach auth (half-built; crypto+handshake already on its branch)"]:::open
I9c["20 cross-program tables (⏸ hold 2026-08-21; channel half-built)"]:::parked
I9d["21 keypair attach auth (⏸ hold 2026-08-21; crypto floor now exists via 34)"]:::parked
I9e["22 durability + throughput baseline ✅ 2026-08-21"]:::done I9e["22 durability + throughput baseline ✅ 2026-08-21"]:::done
I8["8 shard-actor runtime ✅ 2026-08-21"]:::done I8["8 shard-actor runtime ✅ 2026-08-21"]:::done
I9f["23 io_uring group-commit"]:::open I24["24 chat + actor lifecycle 🔄 THE LIVE SLICE (absorbing 31 + 34)"]:::specd
I10["10 HTTP service layer (lowers onto the framework)"]:::open I34["34 crypto builtins ✅ code landed as 24's T1 (ids 85-87)"]:::done
I31["31 actor lifecycle — call/mailbox-cap/death landed in 24; monitor + time.after (ids 89/90) open"]:::specd
I9f["23 io_uring group-commit ✅ part A 2026-08-28 as databasev2 4 (part B refine)"]:::done
I32["32 WAL checkpoint ✅ 2026-08-29 as databasev2 3 (compaction by rewrite + rename)"]:::done
I33["33 single-file store WO_DATA=<path>.db (driver-only, off-chain)"]:::open
I25["25 HTTP service layer — `service` blocks (⏸ hold 2026-08-21; story file removed, plan remains)"]:::parked
I11["11 fibers ✅ 2026-08-21"]:::done I11["11 fibers ✅ 2026-08-21"]:::done
I12["12 blue-green deploy"]:::open I26["26 blue-green deploy (⏸ hold)"]:::parked
I13["13 metaprogramming @derive"]:::open I29["29 metaprogramming @derive (⏸ hold)"]:::parked
I14["14 skillhost workload (demoted)"]:::open I28["28 skillhost workload (⏸ hold; demoted)"]:::parked
I9g["27 query grammar corpus (likely collapses)"]:::open I38["38 content platform capabilities: fs mutation verbs + net.connect"]:::open
GAPS["14's gap fan-out: bounded subprocess, stdin/stdout transport, fs metadata, FFI-vs-out-of-process"]:::open I9g["27 query grammar corpus (⏸ hold; likely collapses)"]:::parked
DRAIN["post-12 parked drain: pub(read)/using/#if, WO-E225, ADT roster, group-by"]:::parked I30["30 observability, CI, fuzz — release-only CI exists; per-change gates + fuzz open (no story file)"]:::open
GAPS["28's gap fan-out, what is LEFT of it: fs metadata, FFI-vs-out-of-process (bounded subprocess + stdio transport moved to 42)"]:::open
I42["42 bounded subprocess ✅ 2026-09-01: proc.run bounded + parked (pidfd), proc.run_dl; streaming form deferred by name"]:::done
DRAIN["parked drain, what is LEFT of it: WO-E225 roster, ADT roster, group-by aggregates"]:::parked
FOUND --> I7 FOUND --> I7
FOUND --> I9 FOUND --> I9
@ -53,34 +72,58 @@ flowchart TD
I15 --> I17 I15 --> I17
I16 --> I17 I16 --> I17
I17 --> FWREORG I17 --> FWREORG
I16 --> I37
I19 --> I37
I17 --> RELEASE
I9 --> I18 I9 --> I18
I16 --> I18 I16 --> I18
I9 --> I9c I9 --> I9c
I9c --> I9d I9c --> I9d
I9c --> I10 I9c --> I25
I9b --> I10 I9b --> I25
I16 --> I10 I16 --> I25
I9b --> I9e I9b --> I9e
I7b --> I8 I7b --> I8
I9e --> I9f I9e --> I9f
I8 --> I9f I8 --> I9f
I8 --> I11 I8 --> I11
I9 --> I12 I19 --> I34
I10 --> I12 I34 --> I24
I9g --> I14 I8 --> I24
I7 --> I14 I11 --> I24
I14 --> GAPS I35 --> I24
I12 -.scope directive.-> I13 I31 --- I24
I12 -.scope directive.-> DRAIN %% 23 and 32 compose on the WAL commit path; neither needs the other (databasev2 story, corrected 2026-08-29)
I9f --- I32
I32 --- I33
I9 --> I26
I25 --> I26
I9g --> I28
I7 --> I28
I28 --> GAPS
I11 --> I42
I24 --> I42
I16 --> I38
I32 --> I38
I36 -.reopens the pure-wo HMAC question.-> I34
I26 -.scope directive.-> I29
I26 -.scope directive.-> DRAIN
``` ```
Reading it: **18 is the only spec-approved open node with all Reading it: **the live slice is 24** (chat + actor lifecycle, absorbing 31
prerequisites green — the next implementation.** After 18: 20/21 and 22 and 34), and the chain behind it, 23 → 32, is done (databasev2 4 part A
are startable (chosen order: 20/21 first — half-built branches rot). 2026-08-28, databasev2 3 2026-08-29). Everything else with all-green
17 unparks on directive: its prerequisites landed, its spec+plan wait on incoming arrows is startable: **33** (driver-only, off-chain), **38** (the
branch `library-internal`, and its landing brings the framework reorg fs-mutation and outbound-socket gaps), and **30**'s remaining half
node with it. 13 and the parked drain sit behind 12 by the 2026-08-08 (per-change CI and fuzzing — the release pipeline covered only publishing).
scope directive (dashed), not by any technical edge. **36** needs no work, only the developer's manual pass over
`docs/examples/operators/`. The held tail — 20/21, 25, 26, 27, 28, 29 — (18's
hold lifted 2026-09-11, above) resumes on its own precedence notes; 29 and
what is left of the drain still
sit behind 26 by the 2026-08-08 scope directive (dashed), not by any
technical edge. Note what left the drain: `pub(read)`, `using` and `#if` all
shipped, so only the WO-E225/ADT rosters and group-by aggregates remain in
it.
## 2. The concurrency chain (iterations 8 / 23 / 11 and everything they gate) ## 2. The concurrency chain (iterations 8 / 23 / 11 and everything they gate)
@ -92,10 +135,11 @@ flowchart TD
classDef rt fill:#8250df,color:#fff,stroke:none classDef rt fill:#8250df,color:#fff,stroke:none
classDef gated fill:#eac54f,color:#000,stroke:none classDef gated fill:#eac54f,color:#000,stroke:none
classDef v2 fill:#0969da,color:#fff,stroke:none classDef v2 fill:#0969da,color:#fff,stroke:none
classDef done fill:#1a7f37,color:#fff,stroke:none
I7b2["7b per-shard collector (done — the precondition 8 waited on)"]:::rt I7b2["7b per-shard collector (done — the precondition 8 waited on)"]:::rt
I8x["8 shard-actor runtime: thread-per-core, ownership-move messages"]:::rt I8x["8 shard-actor runtime: thread-per-core, ownership-move messages"]:::rt
I9fx["23 io_uring group-commit (batch = the shard tick)"]:::rt I9fx["23 io_uring group-commit (batch = queue drain) ✅ part A 2026-08-28"]:::done
I11x["11 fibers: reduction-budget preemption, blocking builtins park"]:::rt I11x["11 fibers: reduction-budget preemption, blocking builtins park"]:::rt
I9ex["22 baseline (numbers 8/23 sign against)"]:::rt I9ex["22 baseline (numbers 8/23 sign against)"]:::rt
@ -104,13 +148,13 @@ flowchart TD
STREAM2["request body streaming + backpressure"]:::gated STREAM2["request body streaming + backpressure"]:::gated
SRESP2["streaming responses + explicit commit point"]:::gated SRESP2["streaming responses + explicit commit point"]:::gated
CANCEL2["per-request cancellation propagation"]:::gated CANCEL2["per-request cancellation propagation"]:::gated
PUBSUB2["pub/sub + WebSockets (rejected until here)"]:::gated PUBSUB2["DONE 2026-08-27 — pub/sub + WebSockets (iteration 24: ws_accept + wsframe + room actors)"]:::done
ASYNC9C["20 async attach statements (rejected-for-now alternative)"]:::gated ASYNC9C["20 async attach statements (rejected-for-now alternative)"]:::gated
TIMEOUTS2["idle timeouts become schedulable (net seam still needed)"]:::gated TIMEOUTS2["idle timeouts become schedulable (net seam still needed)"]:::gated
FIBJOBS2["fiber-scheduled jobs (replaces drain-on-request; queue table stays)"]:::v2 FIBJOBS2["fiber-scheduled jobs (replaces drain-on-request; queue table stays)"]:::v2
CANCELRB["cancellation → transaction rollback"]:::v2 CANCELRB["cancellation → transaction rollback"]:::v2
I18x["18 transaction{} + jobs"]:::v2 I18x["18 transaction{} (jobs moved to porch 10, 2026-09-11 — graph 4)"]:::v2
I7b2 --> I8x I7b2 --> I8x
I9ex --> I9fx I9ex --> I9fx
@ -206,31 +250,407 @@ HS256 (the hard stop). Still gated: timeouts/unix-socket/peer-verify
Note: 21's keypair crypto is its own C implementation (already on Note: 21's keypair crypto is its own C implementation (already on
branch `keypair-auth`) — it neither waits for nor feeds this chain. branch `keypair-auth`) — it neither waits for nor feeds this chain.
## 4. Framework v2 (iteration 18) — internal order ## 4. Language 18 — `transaction { }` (was "Framework v2"; split 2026-09-11)
**Redrawn 2026-09-11.** The hold lifted (developer: "implement language 18")
and codd-shoney re-settled the scope: 18 is now the engine + language block
alone. `cache.wo`, `flags.wo`, `jobs.wo` and the transactional demo moved to
[porch 10](stories/porch/10-memory-features-over-table.md) (`refine`, stub),
which needs 18's `transaction { }` for its jobs demo and porch 1–3 otherwise.
```mermaid ```mermaid
flowchart TD flowchart TD
classDef piece fill:#0969da,color:#fff,stroke:none classDef piece fill:#0969da,color:#fff,stroke:none
classDef indep fill:#1a7f37,color:#fff,stroke:none classDef inprog fill:#8250df,color:#fff,stroke:none
classDef later fill:#eac54f,color:#000,stroke:none classDef refine fill:#eac54f,color:#000,stroke:none
TXN["transaction{} (engine undo log + language block)"]:::piece TXN["language 18: transaction{} — compiler block, kind-6 log record, engine undo list, VM re-raise: landed 2026-09-11 (T1–T6); open: kill -9 battery"]:::inprog
JOBS["jobs.wo: wf_jobs + enqueue + JobRunner + idle() drain"]:::piece TPRMW["txn-per-request middleware (v1 ledger's storage row; single-thread OK)"]:::piece
DEMO["web-app demo: transactional order+confirm, GET /jobs, flags route"]:::piece P10["porch 10: cache.wo, flags.wo, jobs.wo + the transactional demo (stub, refine)"]:::refine
CACHE["cache.wo: TTL + FIFO"]:::indep
FLAGS["flags.wo: wf_flags + read-through map"]:::indep
TPRMW["txn-per-request middleware (v1 ledger's storage row; single-thread OK)"]:::later
TXN --> JOBS
JOBS --> DEMO
FLAGS --> DEMO
TXN --> TPRMW TXN --> TPRMW
TXN -. moved 2026-09-11 .-> P10
``` ```
Cache and flags are dependency-free warm-ups; `transaction { }` is the `transaction { }` is the only engine + language work left in this iteration;
critical path (the only engine + language work); jobs compose on it; the everything that only needed the WAL's staged batch as a `.wo` consumer moved
demo and gate close it. Fiber-scheduled jobs and cancellation→rollback downstream to the track that owns `.wo` product code. Fiber-scheduled jobs and
appear in graph 2 — they need iteration 11 as well as 18. cancellation→rollback appear in graph 2 — they need iteration 11 as well as 18.
## 5. porch — the web framework track
States live on [the board's porch section](stories/00-status.md). **The whole
track (2–8) is `readiness: ready`** as of the 2026-09-06 brainstorm; **1** is
done, **9** is held (blocked on the lang-41 arena hang, not an enhancement).
Three independent roots: **2** (the auth chain), **6** (the streaming chain),
**5** (anytime, no incoming edges at all — not even iteration 2). **10** is a
`refine` stub added 2026-09-11 (language 18's split — TTL cache, `@table`
feature flags, durable job queue) and is not part of the "whole track ready"
count.
This graph makes the **cross-track language edges** visible: the three builtins
the track needs, each drawn as a `lang` node feeding the story that owns it.
```mermaid
flowchart TD
classDef done fill:#1a7f37,color:#fff,stroke:none
classDef ready fill:#0969da,color:#fff,stroke:none
classDef held fill:#6e7781,color:#fff,stroke:none
classDef lang fill:#8250df,color:#fff,stroke:none
classDef refine fill:#eac54f,color:#000,stroke:none
TXN["language 18: transaction{} (T1 in flight)"]:::lang
RB["random_bytes builtin ✅ 2026-09-09 (bare-name, id 119 — one shared enum with wob.h/loader arity) — porch 2 Phase A"]:::done
DFL["language work: deflate + crc32 builtins (C) — porch 7 Phase C"]:::lang
TU["language work: time.utc builtin (gmtime sibling of time.local) — porch 8 Phase A"]:::lang
P1["porch 1 store-backed middleware ✅ 2026-08-30"]:::done
P2["porch 2 randomness + cookies"]:::ready
P3["porch 3 sessions"]:::ready
P4["porch 4 CSRF"]:::ready
P5["porch 5 routing + response ergonomics (zero upstream deps)"]:::ready
P6["porch 6 streaming core"]:::ready
P7["porch 7 SSE + compression"]:::ready
P8["porch 8 static files + lifecycle"]:::ready
P9["porch 9 idempotent replay (ready — unblocked 2026-09-09)"]:::ready
P10["porch 10 memory features over @table: cache/flags/jobs (stub, refine — split from language 18, 2026-09-11)"]:::refine
L41["language 41 actor-arena double free ✅ fixed 63065ff (cross-shard marshal)"]:::done
L44["language 44 poison-on-free ✅ (41's decision 3: a freed header can never pass for live; double free aborts)"]:::done
L41 -.follow-up.-> L44
RB --> P2
P2 --> P3
P2 --> P4
P3 --> P4
P6 --> P7
P6 --> P8
P5 --> P7
P5 --> P8
DFL --> P7
TU --> P8
L41 -.fixed 2026-09-09 — no longer blocks.-> P9
P1 -.re-scope 79e6da4: replay-on-retry split out of 1.-> P9
TXN --> P10
P1 --> P10
P2 --> P10
P3 --> P10
```
Edges corrected by the 2026-09-06 brainstorm: `P5 --> P7` (gzip's
`Accept-Encoding` reuses iteration 5's q-value ranking) stays, but the old
`P2 --> P7` edge is **gone** — story 7 decided `Vary` accumulates by comma-join
(iteration 5's shape), not iteration 2's repeated-header work. `P5 --> P8` is the
`Download`/`Attachment` helper. The three `lang` nodes are the track's entire
language bill; each is a builtin with a named consumer, none shipped as
decoration. **10** (added 2026-09-11) needs language 18's `transaction { }`
for its jobs demo and 1–3 for the store pattern, session-keyed cache and
flags read-through — see graph 4 for 18's own state.
## 5a. porch's language-driven gaps (out-of-scope features and the language stories that own them)
These are the features fiber ships that porch deliberately does **not** — each
excluded because a language primitive does not exist yet. Every edge points from
the owning language story to the porch feature it would unblock (see the
[porch↔fiber scope-gap analysis](plan/exploration/fiber/01-porch-vs-fiber-scope-gap.md)).
```mermaid
flowchart LR
classDef done fill:#1a7f37,color:#fff,stroke:none
classDef refine fill:#eac54f,color:#000,stroke:none
classDef held fill:#6e7781,color:#fff,stroke:none
classDef gap fill:#cf222e,color:#fff,stroke:none
classDef inprog fill:#8250df,color:#fff,stroke:none
L29["language 29 @derive (⏸ hold)"]:::held
L38["language 38 net.connect ✅ landed (id 110); proxy middleware now buildable"]:::done
L43["runtime-v2 8 symmetric cipher (refine, NEW 2026-09-06)"]:::refine
L30["runtime-v2 7 observability (refine, moved from language 30, 2026-09-06)"]:::refine
L18["language 18 transaction{} (hold lifted 2026-09-11; T1 in flight) — TTL cache moved to porch 10"]:::inprog
L31["language 31 cancellation ✅ (landed in 24)"]:::done
BIND["typed request binding (fiber Bind)"]:::gap
PROXY["reverse proxy + outbound HTTP client"]:::gap
ENC["encrypted cookies (fiber encryptcookie)"]:::gap
METRICS["metrics / pprof / expvar endpoints"]:::gap
CACHE["cache middleware + recovery rollback"]:::gap
TIMEOUT["per-handler timeout + streaming backpressure"]:::gap
L29 --> BIND
L38 --> PROXY
L43 --> ENC
L30 --> METRICS
L18 --> CACHE
L31 --> TIMEOUT
```
31 (cancellation) is already green — per-handler timeout and streaming
backpressure are unblocked at the language level and wait only on a porch slice
to consume them. The other five gaps are gated on an upstream story: two
brand-new runtime-v2 iterations (8 cipher, 7 observability — moved out of the
language track 2026-09-06), one language iteration on hold (29) and one
unheld and in flight (18, since 2026-09-11 — its TTL-cache half of `CACHE` now
lives in porch 10), one pending a spec (38). Landed enablers the
track already consumed — 34 (crypto digests), 36 (bit operators), 35 (net
seams) — are green in graphs 1–3 and not repeated here.
## 6. wmux — the multiplexer track (wmux 1) and its gap chain
The tmux study's gaps, remapped as buildable edges now that iteration 42
landed. Every yellow node is an iteration of the
[runtime-v2 track](stories/runtime-v2/00-story.md) ("the runtime beyond
sockets"), ALL `readiness: ready` since the track-wide brainstorm
([spec](superpowers/specs/2026-09-01-runtime-v2-design.md), 2026-09-01) —
[1 streaming subprocess](stories/runtime-v2/01-streaming-subprocess.md) ·
[2 PTY](stories/runtime-v2/02-pty.md) ·
[3 signals as events](stories/runtime-v2/03-signals-as-events.md) ·
[4 termios](stories/runtime-v2/04-termios.md) ·
[5 fd passing](stories/runtime-v2/05-fd-passing.md). wmux — its own
track, first of the softwares built with writeonce — is the driving
workload that consumes them all — [wmux 1](stories/wmux/01-wmux.md).
```mermaid
flowchart TD
classDef done fill:#1a7f37,color:#fff,stroke:none
classDef gap fill:#eac54f,color:#000,stroke:none
classDef product fill:#0969da,color:#fff,stroke:none
classDef later fill:#6e7781,color:#fff,stroke:none
I42w["42 bounded subprocess ✅ 2026-09-01"]:::done
GSTREAM["runtime-v2 1 ✅ 2026-09-02 streaming subprocess: Child fds driven by the net verbs, wait_dl, signal"]:::done
GPTY["runtime-v2 2 ✅ 2026-09-02 PTY: spawn_pty + resize"]:::done
GSIG["runtime-v2 3 ✅ 2026-09-02 signals as events: signal.on delivers Signal records"]:::done
GTERMIOS["runtime-v2 4 ✅ 2026-09-02 termios: raw/restore, restore a runtime obligation"]:::done
GFDPASS["runtime-v2 5 ✅ 2026-09-02 fd passing: send_fd/recv_fd/connect_unix"]:::done
GVTE["VTE grid in pure .wo + unicode width tables ✅ (rung 2; UTF-8 decode + term.width landed)"]:::done
DB2W["databasev2 2 per-table durable/resident ✅ 2026-09-10 — durable default + WAL wmux 1 persists sessions/scrollback into"]:::done
WMUX["wmux 1 foundation ✅ 2026-09-02 (was language 43): server owns sessions/PTYs in durable tables, thin client hands over its tty — reattach after server RESTART replays from the WAL"]:::done
W2["wmux 2 the screen ✅ VTE grid"]:::done
W3["wmux 3 windows + status ✅"]:::done
W4["wmux 4 split panes ✅ (2-pane vertical)"]:::done
W5["wmux 5 copy mode ✅"]:::done
W6["wmux 6 multi-client ✅ (mirroring)"]:::done
W7["wmux 7 command system ✅"]:::done
W8["wmux 8 hooks + control ✅"]:::done
W9["wmux 9 parity audit ✅"]:::done
W10["wmux 10 layout tree — 🟡 first slice DONE 2026-09-03: horizontal split-window -h, select-pane -L/R/U/D, zoom; 2-pane max, N-way/swap/break/persistence pending"]:::gap
W11["wmux 11 formats + options + key rebinding ✅ 2026-09-02 — durable options/binds, #{...} status format, one run_command dispatcher; folded rung 14's prompt-race fix; fixed a PTY-EIO reader spin + a kill-session chunk race. gate 36/0"]:::done
W12["wmux 12 resize + mouse — 🟡 first slice DONE 2026-09-03/04: attach-time term.size sizing + SGR mouse (wheel/click/status-row); live SIGWINCH + min-size pending (rt2 3/6 ready)"]:::gap
W13["wmux 13 copy selection + search — 🟡 first slice DONE 2026-09-03: char-range vi v/y yank → buffer+OSC52; only search + rectangle pending"]:::gap
W14["wmux 14 control surface (prompt-race fix DONE in rung 11; narrows to control-mode commands + %notifications)"]:::gap
W15["wmux 15 terminfo — 🟡 terminfo-lite DONE 2026-09-03: a TERM allowlist retired the foreign-TERM refusal; full compiled-terminfo parsing pending"]:::gap
W16["wmux 16 durability polish (pane persistence, killw compaction) — 🟡 first slice DONE 2026-09-02: Window owns+reaps its panes (spawns in-actor so wait_dl works on its shard), zombie leak fixed, gate 37/0"]:::gap
W18["wmux 18 key tables (new, from the config audit) — 🟡 first slice DONE 2026-09-03: no-prefix RootBind table, Meta/named key_code, tty key decoder in Input; bind-key -n works; gate 42/0. copy-mode-vi + -r repeat pending. Also landed: dynamic sizing (term.size), alt-screen, erase 0/1, SGR reset, UTF-8 decode, O(n log n) replay"]:::gap
W19["wmux 19 mouse-driven UX (new) — 🟡 active-pane border + status-row click→window DONE 2026-09-04; drag-resize/drag-select pending. Forks open (scope split, motion mode, drag owner)"]:::gap
W17["wmux 17 formats v2 ✅ 2026-09-03 — #(shell) cached+timer, recursive #{...} conditionals/modifiers, #{time}/#{host_short}/#{window_name}"]:::done
W20["wmux 20 display-popup ✅ 2026-09-03/04 — session-owned modal float, -B borderless, rounded border, popup wheel forward; drove the OSC-swallow + frame-coalesce VTE fixes"]:::done
W21["wmux 21 sesh + switch-client ✅ 2026-09-04 — in-session switch-client -t/-l, reg threaded into sessions, sync call hand-off (fds move without close, B spawns a fresh Input, old Input exits on success), B-occupied refuses. Fixed a ?actor nullable schema-reorder. Gate 54/0"]:::done
W22["wmux 22 theming ✅ 2026-09-04 — style_sgr engine (fg/bg/attrs from durable options), active-pane border marker, automatic-rename via OSC title"]:::done
W23["wmux 23 plugin ports — thumbs/fzf/fzf-url via capture-pane + a popup picker (port vs tmux-compat shim). Forks open"]:::gap
W11 --> W18
W12 --> W19
W13 --> W19
W10 -.drag-resize only.-> W19
W11 --> W17
W2 --> W20
W6 --> W21
W20 --> W21
W11 --> W22
W10 --> W22
W20 --> W23
W12 --> W23
WMUX --> W2
W2 --> W3
W3 --> W4
W4 --> W5
W5 --> W6
W6 --> W7
W7 --> W8
W8 --> W9
W9 --> W10
W4 --> W10
W7 --> W11
W6 --> W12
W5 --> W13
W8 --> W14
W1TERM["(rung 1 fixed-profile refusal)"]:::done
W1TERM -.retired by.-> W15
W10 --> W16
TINFO["terminfo fork: parse the db in .wo vs fixed xterm-256color + refusal by name (decide at 43's brainstorm)"]:::later
TMONO["time.mono returns (status clock, repaint pacing) — v2"]:::later
I42w --> GSTREAM
GSTREAM --> GPTY
GPTY --> WMUX
GSIG --> WMUX
GTERMIOS --> WMUX
GFDPASS --> WMUX
GVTE --> WMUX
DB2W --> WMUX
TINFO -.settled at wmux's brainstorm.-> WMUX
TMONO -.v2.-> WMUX
```
**The track landed whole on 2026-09-02** — every runtime edge into wmux
is green. The VTE grid + unicode-width node landed (rung 2), and the ladder
is now through rung 22 (see the wmux table on the board); rungs 10/12/13/15
have first slices, rung 23 (plugin ports + a tmux-compat CLI) remains the
big open item. Sibling reuse:
the alacritty Wayland stage reuses GFDPASS + GVTE; the zen CDP driver
now lacks only a WebSocket client; skillhost (28) has its stdin
transport. One edge added 2026-09-10: [databasev2 2](stories/databasev2/02-table-storage-modes.md) → wmux 1, drawn above as `DB2W`, because wmux 1 persists sessions/scrollback in durable `@table` classes and replays from the WAL on reattach — the dependency the prose already named without a node.
## 7. jarvis — the AI-assistant track and everything it waits on
The sixth track ([jarvis](stories/jarvis/00-story.md)): an AI assistant built in
writeonce. **The runtime side is done** — the whole outbound HTTPS path landed
2026-09-09 (runtime-v2 9, both directions, live-gated) and language 41 is fixed.
What jarvis 1 waits on now is purely the **framework**: the developer set the
order *porch first, then jarvis*. So this graph is the porch→jarvis chain.
```mermaid
flowchart TD
classDef done fill:#1a7f37,color:#fff,stroke:none
classDef ready fill:#0969da,color:#fff,stroke:none
classDef refine fill:#eac54f,color:#000,stroke:none
NC["net.connect (id 110) ✅"]:::done
TLS["rv2 9 in-process TLS 1.3 ✅ — net.connect_tls / read_tls / write_tls (115–117), net.accept_tls (118)"]:::done
L41["language 41 cross-shard marshal ✅"]:::done
WOHTML["wo-html / writeonce-view ✅"]:::done
RB["random_bytes builtin (porch 2 phase A / lang 39) — surfaces the runtime's getrandom"]:::ready
P2["porch 2 randomness + cookies (ready)"]:::ready
P3["porch 3 sessions (ready)"]:::ready
P4["porch 4 CSRF (ready)"]:::ready
P5["porch 5 routing + response ergonomics (ready, zero deps)"]:::ready
P6["porch 6 streaming core (ready)"]:::ready
P7["porch 7 SSE + compression (ready)"]:::ready
P8["porch 8 static + lifecycle (ready)"]:::ready
P9["porch 9 idempotent replay (ready — unblocked by L41)"]:::ready
J1["jarvis 1 — the chat loop (ready; forks auto-approved, review_pending)"]:::ready
J2["jarvis 2 — tool use / agent loop (refine)"]:::refine
J3["jarvis 3 — retrieval (RAG) (refine)"]:::refine
NC --> TLS
RB --> P2
P2 --> P3
P2 --> P4
P3 --> P4
P5 --> P7
P5 --> P8
P6 --> P7
P6 --> P8
L41 --> P9
TLS --> J1
P2 --> J1
P3 --> J1
P4 -. CSRF-protects the POST once built .-> J1
P6 --> J1
P7 --> J1
WOHTML --> J1
J1 --> J2
J1 --> J3
```
**jarvis 1's dependency list, from the code and the stories (2026-09-09):**
| jarvis 1 needs | for | state |
| --- | --- | --- |
| `net.connect_tls` / `net.read_tls` / `net.write_tls` (runtime-v2 9) | dialing the LLM API over HTTPS, streaming its SSE reply | ✅ landed, live-gated |
| `net.connect` (id 110) | the TCP under it | ✅ landed |
| language 41 fix | actors carrying messages across shards without the double free | ✅ landed |
| `@table` | durable `Conversation` / `Message` history | ✅ exists |
| wo-html / writeonce-view | the chat page | ✅ exists |
| **porch 2** randomness + cookies (needs the `random_bytes` builtin first) | session id + signed cookie | ready, **unbuilt** |
| **porch 3** sessions | the session principal history is keyed to | ready, unbuilt (after 2) |
| **porch 6** streaming core | incremental response writes | ready, unbuilt |
| **porch 7** SSE + compression | token streaming to the browser | ready, unbuilt (after 5 + 6) |
| porch 4 CSRF | protecting `POST /message` (bearer-gated until then) | ready, unbuilt (after 2 + 3) |
| porch 5 routing + response ergonomics | the route surface | ready, unbuilt, zero deps |
**Build order that satisfies it** (the porch critical path to jarvis): the
`random_bytes` builtin → porch 2 → porch 3 → porch 5 → porch 6 → porch 7 (→ porch
4, 8, 9 to complete porch) → **jarvis 1**. Nothing on the runtime side is
outstanding; every remaining edge into jarvis 1 is a porch iteration.
## 8. databasev2 — the database beyond RAM
The third track ([databasev2](stories/databasev2/00-story.md)): what happens
when the data does not fit in memory. Its 3 and 4 are the language track's 32
and 23 renumbered — graph 1 still carries them as `I32`/`I9f`, green since
2026-08-29/28. Arrows point AT the iteration that needs the other, as in the
track's own ASCII graph; two edges are undirected: 3–4, which compose on the
WAL commit path and need each other in neither direction, and 2–3 (added
2026-09-10 — this graph had dropped it; the story's own graph always carried
it, [00-story.md:169-171](stories/databasev2/00-story.md)) — 2 needs 3's
offset map to survive compaction, and 3 has called 2's row API since task 5d,
so the coupling runs both ways. 9 and 10 (cross-program tables, keypair
attach) are held and not drawn.
```mermaid
flowchart TD
classDef done fill:#1a7f37,color:#fff,stroke:none
classDef inprog fill:#8250df,color:#fff,stroke:none
classDef ready fill:#0969da,color:#fff,stroke:none
classDef refine fill:#eac54f,color:#000,stroke:none
classDef hold fill:#6e7781,color:#fff,stroke:none
D1["databasev2 1 RAM ceiling measured ✅ 2026-08-27"]:::done
D2["databasev2 2 per-table durable/resident ✅ 2026-09-10 — 6a: refuse durable:true without WO_DATA, WO_EPHEMERAL=1 escape, .wob v8 table bit"]:::done
D3["databasev2 3 WAL checkpoint ✅ 2026-08-29 (was 32)"]:::done
D4["databasev2 4 group commit 🔄 — part A ✅ 2026-08-28; part B re-brainstormed 2026-09-10, GO measured (forks 6/7), fold pending — refine (was 23)"]:::inprog
D5["databasev2 5 bounded tables + eviction — ready 2026-09-10 (12 forks, review_pending), status pending; Phase A is the resident byte budget moved from 2 (2026-09-09)"]:::ready
D6["databasev2 6 cold tiering — hold (superseded by 2's resident: keys)"]:::hold
D7["databasev2 7 single-file store ✅ 2026-09-10 — WO_DATA=<path>.db (was 33)"]:::done
D8["databasev2 8 query grammar from corpora — hold, refine (count landed 2026-08-16; exists open) (was 27)"]:::hold
D11["databasev2 11 bounded delta chains ✅ 2026-08-30"]:::done
D12["databasev2 12 schema migrations ✅ 2026-08-31"]:::done
D13["databasev2 13 fresh-log keys-resident seed SEGV ✅ fixed 2026-09-10"]:::done
P1["porch 1 store-backed middleware ✅ 2026-08-30"]:::done
P2["porch 2 randomness + cookies (ready)"]:::ready
P3["porch 3 sessions (ready)"]:::ready
D1 -- budget default follows the measurement --> D5
D2 -- the byte budget, moved 2026-09-09 --> D5
D2 --> D11
D2 --> D12
D3 --- D4
D3 --- D2
D2 -- volatile tables; store.wo is default-durable today, so fork 6 makes WO_DATA or WO_EPHEMERAL=1 whole-program --> P1
D2 --> P2
D2 --> P3
D2 -- the offset map D13's fix touches --> D13
D12 -- the schema head record D13's fix touches --> D13
```
Node D13, added 2026-09-10, fixed the same day: a defect found while smoking
databasev2 7, not that iteration's fault (it reproduced identically in the
pre-existing directory form). It needed 2 (the keys-resident offset map) and
12 (the schema head record) — both are the mechanism the crash lived in.
Fixed by `6310078` (`wo_wal_next_offset` stages the pending schema head
before returning an offset) + `1b6750d` (NULL-`msg` guard in
`wo_wal_fold_row_at`); `just residency` 32/0. The separate
`residency.keys.fit` rc 74 bug (compaction/replay of keys-resident offsets)
is **not** the same defect and stays open under codd.md's "Next bugs".
**States as of 2026-09-10** (the board carries the words; this is the glance):
| databasev2 | status / readiness | what is left |
| --- | --- | --- |
| 1 RAM ceiling | ✅ done | — |
| 2 per-table storage | ✅ done (2026-09-10) | — (6a landed with the `.wob` v8 table bit; 6b lives in 5) |
| 3 WAL checkpoint | ✅ done | — |
| 4 group commit | 🔄 in-progress / refine | part B re-brainstormed 2026-09-10 (GO measured, forks 6/7); fold into the story, `.dev/zack/databasev2-4b.md` |
| 5 bounded tables | ⬜ pending / **ready** (2026-09-10) | developer review of the twelve `review_pending` forks, or a prebuild brief for Phase B; Phase A is startable now |
| 6 cold tiering | ⏸ hold / refine | superseded by 2; revisit only on a measurement |
| 7 single-file store | ✅ done (2026-09-10) | — (`WO_DATA` is a path, never a sentinel; `review_pending` developer second review) |
| 8 query grammar | ⏸ hold / refine | `count` landed; `exists` waits for a corpus |
| 11 bounded delta chains | ✅ done | — |
| 12 schema migrations | ✅ done | — |
| 13 fresh-log keys-resident seed SEGV | ✅ done (2026-09-10) | — (`residency.keys.fit` rc 74 is a separate, still-open bug) |
## Maintenance rule ## Maintenance rule

535
docs/00-doc-audit.md Normal file
View file

@ -0,0 +1,535 @@
# Documentation truth audit — 2026-08-26
> **Status: findings resolved 2026-08-26, same day.** Every section below was
> acted on; see [What was fixed](#what-was-fixed) at the end for the
> disposition of each, including **one row where this audit was wrong and the
> document it accused was right** (B3's `WO-W201` claim). The findings are kept
> as written — a fix list whose findings have been edited away cannot be
> checked. `just linkcheck` went from 77 broken paths to 23, and all 23 that
> remain are in `.dev/`, which this repo does not author.
>
> A separate structural directive landed the same day and **removed the status
> folders** (`done/`, `refine/`, `hold/`, `in-progress/`) — status now lives only
> in frontmatter. Paths of the form `…/done/NN-*.md` quoted in the findings below
> were correct when written and no longer resolve; see
> [Structural change 2026-08-26](#structural-change-2026-08-26--status-folders-removed).
Scope: every `*.md` that documents THIS repo — root `README.md`, the numbered
`docs/0*.md`, `docs/guides/`, `docs/stories/`, `docs/plan/`, `docs/examples/`,
`docs/superpowers/`, the code-directory READMEs and `CODE-LOGIC.md` files,
`tests/corpus/README.md`, `bench/compare/go-sqlite/README.md`,
`scripts/install-readme.tmpl.md`, `.claude/agents/codd.md`.
Excluded, and why: `.dev/skills/` (vendored copies of plugin skills, not ours),
`.dev/reference/` (other people's codebases), `.superpowers/sdd/` (dated task
reports — snapshots, correct as history).
Method: claims were checked against the tree, not read off prose. `woc`
(`compiler/_build/default/bin/woc`) and `wovm` (`runtime/wovm`), both built
2026-08-25, were run against every sample; `justfile` recipes, `wob.h`
constants, `types.ml`'s builtin tables, story frontmatter and
`scripts/linkcheck.py` were used as ground truth. Nothing in this report is
inferred from another document.
Verdict: **the deep reference docs are in good shape; the front door is not.**
`docs/guides/language-surface.md`, `docs/plan/oop-vm/08-builtin-surface.md`, the
three `CODE-LOGIC.md` files and the status board's tables track the code
closely. The root `README.md`, `runtime/README.md`, `docs/00-code-review.md`,
`docs/00-dependency-graph.md` and two example status banners describe a repo
that stopped existing between one and six weeks ago.
No document was changed by the audit pass itself — the findings below record the
tree as it stood before any fix. What was then changed in response is listed in
[What was fixed](#what-was-fixed).
---
## A. Wrong about shipped features (the highest-cost class)
### A1. `README.md` — the Roadmap lists three landed features as unavailable
`README.md:326-342` is headed "Planned, **not yet available**", and
`README.md:10-14` promises "Features that are planned but **not yet available**
are listed separately under Roadmap — they are not described as if they work."
Three of its six entries have shipped:
| README claim | Reality |
| --- | --- |
| `:336` "**Concurrency** — a shard-actor runtime and green-threaded fibers." | Both landed 2026-08-21 (iterations 8 and 11, both `done/`). `spawn` is a lexer keyword (`lexer.ml:163`); `send`/`call` are builtins (`WO_B_SEND=69`, `WO_B_CALL=88` in `wob.h`); `actor M` is a type (`types.ml`'s `TActor`). Gates exist and run: `just fibers`, `just db-actor`. `runtime/src/park.c` is the parking implementation; `runtime/test/test_fiber.c` and `test_mailbox.c` are its unit suites. |
| `:335` "**HTTP service layer** — `service` blocks that route requests to methods." | The *`service` block syntax* is genuinely absent — that half is honest. But it sits under a banner that also denies HTTP entirely, which is false (see A2). |
| `:332` "**Query aggregates** — `group … by … into g`" | **This one is correct.** `types.ml:2220,2241` rejects it: "group-by aggregation is not supported yet". Kept here only because `docs/guides/language-surface.md` contradicts it — see C1. |
### A2. `README.md:33-37` — "does not serve HTTP, WebSockets, or a UI"
> "writeonce is **not** a web framework and does not (yet) serve HTTP,
> WebSockets, or a UI."
Contradicted 30 lines later by its own §"Worked examples" (`:306-313`), which
describes `docs/examples/porch/` as "a web framework written in
writeonce (HTTP/1.1 …, router with `:param` captures, interface-based
handlers)" and `just web-app` as its gate. Also contradicted by:
- iteration 16 (web framework) and 37 (wo-html components), both `done/`;
- `docs/examples/site/` — server-rendered pages, gated by `just site`;
- WebSockets: `docs/examples/porch/http/ws.wo` (`ws_accept`, the 101
hijack sentinel) and `http/wsframe.wo` (a pure-`.wo` RFC 6455 frame codec),
both landed per `docs/in-progress/2026-08-23-chat-ws-lifecycle.md` (T6, T7).
### A3. `README.md:30` — "no package manager"
> "**Small on purpose.** No FFI, no package manager, no framework."
Same page, `:265-281`, documents `[deps]`, `.wo-deps/<name>/`, `wo.lock` and
`woc --update-deps`. Iteration 15 (deps package manager) is `done/`;
`just deps-accept` is its gate. "No framework" is contradicted by `:306`.
The intended claim is presumably "no *registry*" — which is true and is what
`docs/00-code-review.md:77` says.
### A4. `docs/examples/employee/README.md:3` — "does not compile on today's toolchain"
> "**Status: target workload — does not compile on today's toolchain.** …
> It becomes buildable when iteration 9 … and iteration 9b … land."
Both landed. `woc docs/examples/employee/` exits 0. `just employee` is a
first-class acceptance gate, and the `justfile:88-91` comment calls it "the
database track's acceptance workload". The banner is ~2 weeks stale.
### A5. `docs/examples/log-watcher/README.md:12-20` — same shape
> "**Status: design artifact — the spec's forcing function.** The systems
> track is approved, pre-implementation. Today's `woc` (milestone 1) …
> diagnoses the adopted surface as WO-E101: `use`, `typedef`, standalone union
> aliases …, `pub(read)`, `switch`, `try`."
Every one of those forms is shipped (`docs/guides/language-surface.md` §2–§5,
verified in `lexer.ml`/`parser.ml`). `woc docs/examples/log-watcher/` exits 0.
`just log-watcher` is the gate the `justfile:82-87` calls "the test the whole
track exists to pass".
Same file, `:8-9`: "the five builtin stdlib modules — `fs`, `proc`, `net`,
`time`, `json`". There are **six** (`types.ml:206`): `env` is missing.
### A6. `runtime/README.md` — describes the pre-2026-08-18 world
The directory's orientation README is still the old `wo-rt-c` prototype page
with the VM bolted on at `:78`. Concretely wrong:
- `:31` "Or from the repo root: `just rt-c-demo`" and `:60` "`just rt-c-bench`"
— **neither recipe exists.** The justfile has 16 recipes plus two `mod`s;
no `rt-c-*` among them.
- `:5,:83` "the production Rust runtime (`crates/rt/`)", `:76` "This file is for
reading; `crates/rt` is for running writeonce" — the Rust runtime was removed
2026-08-18 (`docs/08-project-structure.md:11`).
- `:3` `prototypes/wo-db/`, `:43` `docs/runtime/database/03-inmemory-engine.md`,
`:47` `docs/plan/09-concurrency-scaleout.md` — none of these paths exist
(also in the link audit's sections B/C/E).
- `:84` "**`@gc` reference counting** + budgeted cycle collection … Bacon–Rajan
trial deletion" — retired by iteration 7b. `@gc` on a class is now
**rejected** (`docs/guides/language-surface.md:73`), and
`runtime/src/CODE-LOGIC.md` states the replacement outright: "incremental
tri-color mark-sweep … (iteration 7b — RC and Bacon–Rajan are gone)".
- `:89` "`DB_STUB` traps 'engine not linked' until the DB engine binds (plan
5)" — the engine bound in iteration 9. The opcode survives
(`wob.h:232`, `vm.c:1806`) but the sentence reads as "no database yet".
- `:89` builtin list "`now/print/print_int/words/multi_*/map_*`" — there are
now ~70 free builtins plus six module namespaces (`types.ml:784-849`).
- File map (`:92-107`) omits four of the thirteen sources in `runtime/src/`:
`crypto.c/.h`, `json.c`, `park.c/.h`, `sysio.c`.
- `:105` and `:117` "13 suites" / "one of the 13 ASan test binaries" — there
are **18** (`runtime/test/test_*.c`).
- `:1` "now at **phase E**" vs `:57` "A → B → C → D → E → F, all ✅ shipped"
vs `:60` "Measured (phase F…)" — three answers in one file.
Verified-correct in the same file, for contrast: `WO_HEAP_MB` / 64 MiB arena,
the four `.vscode/launch.json` configs, the exit-code contract, and the
`make -C runtime` targets.
---
## B. Verification tables that no longer verify
### B1. `docs/00-code-review.md` — the 2026-08-20 table has decayed
The doc's value is that it *checked* a critique line by line. Seven rows of
`:55-82` are now false, and the doc carries no superseded banner:
| Row | Then | Now |
| --- | --- | --- |
| "no `Float`, no `Bytes` \| absent from `compiler/src/types.ml`" | true | `types.ml:174` `builtin_scalars = ["Int";"Bool";"Text";"Timestamp";"Id";"Float";"Bytes"]` — iteration 19, `done/` |
| "`send` is one-way \| `WO_B_SEND=69` is the last builtin (`WO_B_MAX 69u`)" | true | `WO_B_MAX 95u`; `WO_B_CALL = 88` is a send that parks for a typed reply |
| "no crypto primitives \| none" | true | `WO_B_SHA1=85`, `WO_B_SHA256=86`, `WO_B_HMAC_SHA256=87`; `runtime/src/crypto.c`; `runtime/test/test_crypto.c` |
| "22's battery never run \| … no `bench/baseline.json`, no `just db-bench`" | true | `bench/baseline.json` exists, `just db-bench` / `db-bench-quick` exist, 30+ result files in `bench/results/`, iteration 22 is `done/` |
| "no fuzzing, no CI \| **no `.github/`**, no fuzz target" | true | `.github/workflows/release.yml` exists (fuzzing still absent) |
| "one framework, five samples, one consumer" | true | 13 sample projects under `docs/examples/` |
| "accept on one shard \| one listener, `SO_REUSEADDR` only" | true | iteration 35 landed `serve_conn` + fiber-per-connection |
| `:46-51` "The multi-shard DB gap is structural … `wo_builtin_db` returns `WO_T_DB` 'database engine not initialized'" | true | that string is gone from `runtime/src/`; arc stage 3 landed the transparent DB actor, gated by `just db-actor` |
Rows that still hold, checked: interpreted-only/no JIT, no SIMD, the
`WO_STACK_SLOTS 4096` / `WO_MAX_REGS 64` / `WO_MAX_FRAMES 256` correction, no
generics, no closures, byte strings, no Result type, switch-not-destructuring,
no supervision, growable mailboxes, no `timerfd`, no TLS, no debugger/LSP,
deps-are-git-rev-only, blue-green is a future, TSan covers one demo. And
**`map<K,V>` lookup is still a linear scan** — `cont.h:1-6` says so in as many
words.
### B2. `docs/00-link-audit.md` — numbers and paths both stale
Dated 2026-08-20. `just linkcheck` today reports **files=235, local=675,
broken=77, bad anchors=0**; the doc's table says 206 / 569 / 88. Its own
sections B–F sum to 77, not the 88 its prose claims twice (`:12`, `:145`) —
an internal arithmetic error independent of the drift.
Its repair table (`:29-37`) references paths that have since moved:
`docs/00-status.md` (now `docs/stories/00-status.md`), and
`refine/{08,11,19,20,21}` (now under `done/` and `hold/`).
Two broken links exist today that the audit does not account for:
- `docs/examples/employee-list/README.md:5,6` → `…/refine/20-cross-program-tables.md`
and `…/refine/21-keypair-attach-auth.md`; both files are now in `hold/`.
- `docs/stories/language-runtime-database/hold/26-blue-green-deploy.md:9` →
`00-story.md`; the sibling stopped being a sibling when 26 moved into `hold/`.
Conversely `docs/00-principles.md:57,77,78,87` — four links the audit lists as
open — resolve now.
### B3. `docs/plan/oop-vm/01-error-catalog.md` — not the complete catalog it claims
`docs/guides/language-surface.md:8` calls it "every diagnostic";
`compiler/README.md:39` says "every shipped code is cataloged" there. Ten
codes the compiler emits are absent:
| Code | Defined at | What it is |
| --- | --- | --- |
| `WO-E003` | `lexer.ml:56` | `#if`/`#else`/`#end` misuse |
| `WO-E108` | `bin/main.ml:277` | `internal/` crossed at a `[deps]` boundary |
| `WO-E109` | `bin/main.ml:275` | unknown `wo.toml` `kind` value |
| `WO-E219`–`WO-E223` | `types.ml` | five type-pass codes |
| `WO-E226` | `types.ml:443` | `call`'s reply type through actor-`M` erasure (iteration 24) |
| `WO-E250` | `types.ml:435` | the whole query surface (iteration 9b) |
`WO-E250` is the notable one: it is the only diagnostic the shipped query
language produces, and it is the code a reader hits first when they mistype a
query. Meanwhile `WO-W201` is still catalogued and no longer exists — the
inferred-GC plan (`docs/superpowers/plans/2026-08-18-inferred-gc-mark-sweep.md:151`)
listed "retire WO-W201" as an amendment; the code went, the catalog entry
stayed.
`WO-E004`/`WO-E005` (raw text literal, iteration 37) *are* catalogued —
checked, since `language-surface.md:29,31` depends on them.
---
## C. Docs that disagree with each other
### C1. Is group-by shipped? Two live docs, two answers
- `README.md:332` — Roadmap, "not yet available". **Correct.**
- `docs/guides/language-surface.md:175` — "Present today: from / where / order
/ take / select **plus group-by aggregation**." **Wrong**, and the same page
opens (`:16-17`) with "Every form listed below was compiled and run against
`woc`/`wovm` while writing this page, not read off the parser and hoped for."
The `group … by … into` clause in its §6 grammar block *parses*
(`parser.ml:1137-1144`) and is then rejected by the typechecker
(`types.ml:2241` "group-by aggregation is not supported yet";
`types.ml:2222` for the navigation form).
Reproduced: `docs/examples/employee-list/main.wo:38-41` uses `group e by
e.dept into g` and fails to compile.
`docs/00-dependency-graph.md:45` correctly still lists group-by under the
parked drain.
### C2. `docs/stories/00-status.md` — the narrative and the table disagree about iteration 24
The board's *Current work* table is right: `:314` records "🔄 **iteration 24
(absorbing 31 + 34): chat + actor lifecycle** — spec + plan approved
2026-08-23 … executing on branch `chat-ws-lifecycle`" and links the marker.
The ▶ NEXT PLAN narrative above it is not:
- `:82-85` "Next slice: **iteration 31, actor lifecycle** — its spec brainstorm
is the next act". 31 was absorbed into 24 by directive, and its
actor-death half already landed (`docs/in-progress/2026-08-23-chat-ws-lifecycle.md:20-23`,
commit `ed69841`).
- `:125` "**Next steps:** 31 (lifecycle spec brainstorm) → 24 (chat) → 23 → 32"
— same stale ordering.
- `:286` iteration 24 marked "⬜ fourth in chain … after 31".
- `:290` iteration 34 marked "⬜ off-chain but GATES 24". T1 crypto landed
(`d14fa9f`); `sha1`/`sha256`/`hmac_sha256` are in both `types.ml:847-849`
and `wob.h:461-463`. The gate is cleared —
`docs/00-dependency-graph.md:169` already says so.
Also missing from the board entirely: the 2026-08-25 packaging/release track.
`VERSION`, `scripts/mkdist.sh`, `just dist`, `just install-accept`,
`.github/workflows/release.yml`, `docs/guides/releasing.md` and `dist/writeonce-0.1.0-linux-amd64.tar.gz`
all exist; the last five commits are that work; no standup entry covers it.
### C3. `docs/00-dependency-graph.md` — the main graph is a generation behind
Its own header (`:3`) defers state to the board, but it paints state inline
anyway, and the first mermaid graph paints it wrong:
- `:29` `I17["17 library kind + internal/ (**PARKED** — spec+plan ready…)"]:::parked`
— story 17 is in `done/` with `status: done`; board `:302` reads
"✅ **landed 2026-08-20**".
- `:31` `I18[… (spec APPROVED — **the next implementation**)]:::specd` — story
18 is in `hold/`; board `:303` reads "⏸ hold (2026-08-21)".
- `:33,34` iterations 20/21 as `open` — both `hold/`.
- `:38,40,41,42` use the pre-renumber ids: "10 HTTP service layer", "12
blue-green deploy", "13 metaprogramming @derive", "14 skillhost workload".
The stories are **26**-blue-green-deploy, **29**-compile-time-metaprogramming,
**28**-skillhost-host-workload; no story numbered 10, 12, 13 or 14 exists.
- `:45` `DRAIN["post-12 parked drain: pub(read)/using/#if, …"]` — `pub(read)`
(`ast.ml:118-123`), `using` (`lexer.ml:164`) and `#if` (`lexer.ml:245-249`)
all shipped.
- The main graph has no node for iterations 19, 24, 31, 32, 33, 35, 36 or 37.
Four of those are `done/`. The later sub-graphs *do* cover 34/35/36
correctly (`:141,164-170`), so the drift is confined to the first graph.
---
## D. Structural claims that don't match the tree
### D1. `docs/08-project-structure.md` — "canonical map", four divergences
- `:39` "`plan/` compiler-track docs: architecture.md + the woc plans" under
`compiler/`. **`compiler/plan/` does not exist**; those docs live at
`docs/plan/compiler/` — which the same file's `:49` links correctly.
- `:22,76-77` `tests/corpus/` as "`run/`, `compile-fail/`, `trap/`, `gc/`".
There are nine directories: also `actor/`, `db/`, `lang/`, `sys/`,
`sample-logwatcher/` — all five **empty**. `tests/corpus/README.md:11-15`
documents them as planned per-plan additions, so the corpus README is the
honest one; the structure doc undercounts and neither mentions that five are
placeholders. (Live fixture counts: run 60, compile-fail 46, trap 5, gc 2.)
- `:79-81` `scripts/` as "`oop-e2e.sh`, `mkdist.sh` + `install-accept.sh`, and
the per-sample acceptance scripts (`employee-accept.sh`,
`log-watcher-accept.sh`)". There are 14 scripts; unmentioned:
`db-actor-accept.sh`, `db-bench.py`, `deps-accept.sh`, `fibers-accept.sh`,
`linkcheck.py`, `single-binary-smoke.sh`, `site-accept.sh`,
`web-app-accept.sh`.
- `:89` `examples/` as "log-watcher/, employee/, employee-list/ samples" —
there are 13.
- `:87` puts status at the `docs/` root; it is `docs/stories/00-status.md`
(the file's own `:5` links it correctly). The root also has
`00-dependency-graph.md` and `00-link-audit.md`, unlisted.
- The one-page map (`:17-29`) omits four tracked root entries: `bench/`,
`dist/`, `.github/`, `.claude/`.
- `docs/examples/db-actor/` has `main.wo`, a `wo.toml` and a gate
(`just db-actor`) but **no README** — the only sample without one.
Correct in the same file, checked: `runtime/wo-rt.c` exists; `.dev/` is
gitignored except `.dev/README.md` (`git ls-files .dev` returns exactly one
path) and `.dev/reference/` does hold `crates/`, `colibri/`, `llama-cpp/`,
`linux/`, `go/`.
### D2. `compiler/README.md` — stage banner and CLI list both behind
- `:5` "**Stage: plan 3 … complete, Tasks 1–6 + 8**". Plan 3 closed in early
August; the front end has since taken iterations 15, 17, 19, 24, 34, 35, 36
and 37. A reader takes this page as the compiler's current extent.
- `:26-34` "Running `woc`" omits four of the nine modes the binary's own
`usage_msg` prints: `--dump-gc`, `--update-deps <dir>`, `version`, and the
`woc <dir>` manifest build (the mode `README.md:111` teaches as the primary
one). `-D <name>`, the `#if` flag setter documented at
`language-surface.md:34`, is in neither the README nor `usage_msg` —
it exists at `bin/main.ml:1162`.
- `:37` "same contract as `wo run` (`crates/rt/src/lib.rs::discover`)" — the
Rust runtime is gone. The identical stale sentence is also the doc comment
at `compiler/bin/main.ml:16-19`. *(Code, not markdown — noted, not
changed.)*
Correct: the `=== path ===` multi-file header (`dump.ml:128`), the five golden
stages, the exit-code contract, OCaml 4.14 / dune 3.14 (`dune-project` says
`(lang dune 3.14)`).
### D3. `runtime/src/CODE-LOGIC.md` — file table missing two sources
`:12-25` is a complete-looking table of "the files, in dependency order" and
omits `park.c/.h` (fiber parking — iteration 11, and central to how blocking
builtins work) and `crypto.c/.h` (iteration 34). The doc is dated 2026-08-14,
before both; nothing marks it as of-that-date beyond the first line.
`database/src/CODE-LOGIC.md` and `compiler/src/CODE-LOGIC.md` were checked
against their sources and hold up.
---
## E. Runbook and instruction errors
`docs/guides/releasing.md`, authored 2026-08-25, contains steps that cannot be
followed:
- `:110` (step 11) "Remove `--draft`, commit, push." **`.github/workflows/release.yml`
contains no `--draft`** — `gh release create` at `:135-139` passes only the
two asset paths, `--title` and `--generate-notes`. Nothing to remove.
- Steps 5, 6 and 10 disagree with each other. `:50-54` (step 5) says the
rehearsal is a `workflow_dispatch` run that "skips the tag guard and the
publish step"; `:56` (step 6) says "nothing to undo — a dry run creates no
tag and no release"; `:89-92` (step 10) then instructs
`gh release delete v0.0.0-test --yes` and two tag deletions. There is no
path in the workflow that creates `v0.0.0-test`.
`.github/workflows/release.yml:1-2` — "this workflow has never run. Authored
2026-08-25 and not executable locally" — is contradicted by `:43` of the same
file ("The first run failed here with `dune: command not found`") and by
commits `05fafd3`, `d66087d`, `4470f03`, which are fixes read off real runs.
*(Code comment, not markdown.)*
Verified correct against the workflow and the built binaries: the asset name
`writeonce-0.1.0-linux-amd64.tar.gz`, the tag↔`VERSION` guard, the
`ubuntu-22.04` pin and its glibc reasoning (this machine's binaries need
`GLIBC_2.38`, matching `:8` step 8's "2.38 from this dev machine"), and
`scripts/install-readme.tmpl.md:24-25` — `woc version` prints
`writeonce 0.1.0 linux/amd64` and `wovm --version` prints `wovm 0.1.0`, exactly
as documented.
---
## F. Small factual errors
| Where | Claim | Actual |
| --- | --- | --- |
| `README.md:28` | "~100 KB for the sample programs" | 163–254 KB. Smallest built sample 163,117 B (`fibers`), largest 253,808 B (`site`); bare `wovm` is 161,848 B, so ~160 KB is the floor |
| `README.md:142` | "**Types:** `Int`, `Text`, `Bool`, and user `class` types" | seven builtin scalars (`types.ml:174`): also `Float`, `Bytes`, `Timestamp`, `Id` |
| `README.md:170` | `time` → "`sleep`, `now`, `local`, `iso`" | also `ticks` (µs monotonic, builtin 84 — iteration 22's one runtime addition) |
| `README.md:172` | `net` → "TCP `listen`/`accept`/`read`/`write`/`close` (host + port)" | also `read_dl`, `accept_dl`, `write_dl`, `listen_unix`, `peer` (ids 91–95, iteration 35) |
| `README.md:344` | "`net` is TCP host+port only" | `net.listen_unix` binds a unix socket (builtin 94) |
| `README.md:272,276-277` | `[deps]` key `niceserve`, then "`use niceframework`" | the `[deps]` KEY *is* the module name — `docs/examples/web-app/wo.toml:19-20` keys it `serve` and `main.wo:9` says `use serve`. The example as written would not compile |
| `README.md:295` vs `:298-320` | "**Two** complete sample programs" | three bullets follow; `:322` "Read **either** program's `main.wo`" compounds it. There are 13 samples, 8 of them gated |
| `docs/guides/language-surface.md:36` | "**Keywords (35)**" | 37. The list printed immediately after is complete and correct against `lexer.ml:147-184` — only the count is wrong |
| `docs/00-principles.md:104-105` | capabilities are "(`fs`, `proc`, `net`, `time`, `json`)" | six modules — `env` missing (`types.ml:206`) |
| `docs/superpowers/plans/2026-08-18-inferred-gc-mark-sweep.md:153-154` | `[x]` "Add a `docs/examples/gc-cycle` acceptance script + `just gc-cycle` recipe" / `[x]` "Verify: `just gc-cycle` green" | **no `gc-cycle` recipe exists** and there is no `scripts/gc-cycle-accept.sh`. `docs/examples/gc-cycle/` has sources, a `target/` and a "Run status" section (`README.md:186`) but no gate. Two checked boxes for work that did not land |
Forward references that are correctly labelled and are *not* findings:
`just chat` (iteration 24, T9 — pending in the marker), `just oop-parity`
(deferred by explicit decision, recorded at `compiler/README.md:5`), and
`docs/examples/employee-list/`, whose banner honestly says it does not compile
(confirmed: `woc` exits 2 on `[connect.employee]`, a section for the `hold/`
iteration-20 feature).
---
## What to fix first
1. **`README.md`** — it is the writeonce.de landing content
(`docs/08-project-structure.md:28`), so A1–A3, F's README rows and the
`use niceframework` example are the highest-value corrections in the repo.
2. **The two example status banners** (A4, A5) — one line each, and they
currently tell a visitor that the repo's two flagship gates don't build.
3. **`runtime/README.md`** (A6) — the largest single body of stale prose. It
wants splitting: `wo-rt.c` is a historical reference card, `runtime/src/` is
the shipped VM, and one page is trying to be both.
4. **`docs/00-code-review.md`** and **`docs/00-link-audit.md`** (B1, B2) — both
are dated verifications whose value depends on being re-run. Either re-run
them or banner them as of-date.
5. **`docs/plan/oop-vm/01-error-catalog.md`** (B3) — it is cited as normative by
two other docs; ten missing codes including the query surface's only one.
6. **`docs/guides/language-surface.md:175`** (C1) — a single false clause on
an otherwise excellent page.
7. **`docs/00-dependency-graph.md`** first graph (C3) and the board's NEXT PLAN
narrative (C2) — both trail their own companion tables.
---
## What was fixed
All on branch `docs-truth-audit-fixes`, 2026-08-26. Docs only — no code changed,
so no gate output changed.
| Finding | Disposition |
| --- | --- |
| **A1** README roadmap listed shipped concurrency | Concurrency entry removed; `spawn`/`send`/`call`/`receive` documented under "Language at a glance" as shipped. The `service`-blocks entry stayed but now says what you write *instead* today. Group-by stayed — it was the one correct entry. |
| **A2** "does not serve HTTP, WebSockets, or a UI" | Rewritten: both work, as `.wo` libraries consumed through `[deps]`, never as runtime features — which is the real (and more interesting) claim. TLS-by-proxy stated. |
| **A3** "no package manager" | Now "no package **registry** — dependencies are exact-rev git URLs and nothing else", which is true and is the distinction the doc meant. |
| **A4** `employee` README "does not compile" | Banner flipped to shipped, `just employee` named as the gate, with the one genuinely-ahead clause (`group … by … into`) called out rather than left to surprise a reader. |
| **A5** `log-watcher` README "design artifact" | Banner flipped to shipped with iteration 7's actual acceptance evidence; the "five stdlib modules" list corrected to six. |
| **A6** `runtime/README.md` a generation stale | **Restructured, not patched.** Leads with `wovm`; `wo-rt.c` demoted to a marked "Historical" section that keeps its measured numbers as the prototype record they are. Fixed: the two nonexistent recipes, `crates/rt`, `prototypes/wo-db`, the `@gc` refcount/Bacon–Rajan description (now inferred mark-sweep), `DB_STUB`, the builtin list, "13 suites" → 18, four missing source files, and the phase E/F contradiction. Three broken links went with it. |
| **B1** `00-code-review.md` decayed | History kept intact with a pointer at the top; a **Re-verification 2026-08-26** section added listing the eight overtaken rows against source, the ~20 that still hold, and the two new gaps (now iteration 38). "No supervision/actor death" is marked *partly* overtaken — death landed, supervision did not. |
| **B2** `00-link-audit.md` stale | Re-run and rewritten. The 48 dead-era exploration links are **resolved by de-linking, not re-pointing** — their prose names the retired plan by number, so re-targeting would have made each sentence lie. A successor map was added to `plan/discarded.md`, which is what that report's own "Still open" note asked for. Three more fixable breaks fixed. 77 → 23. |
| **B3** ten codes missing from the error catalog | Added with definitions read from source: WO-E003, E108, E109, E219–E223, E226, E250. Header's "as of plan 3" scope line corrected. The Completeness method section now records *why* the sweep rotted — codes are built as `<stage>_prefix ^ "NN"`, so grepping for the literal `WO-E250` finds only a comment. **The `WO-W201` half of this finding was wrong:** the catalog already marked it *(retired, iteration 7b)* with "*(no longer emitted)*". The doc was right; the audit misread its own grep. |
| **C1** `language-surface.md` claimed group-by works | Corrected in three places: the clause is marked in the grammar block, the "present today" list drops it, and the page's "every form was compiled and run" promise now names the exception. Keyword count 35 → 37. |
| **C2** board narrative trailed its own tables | ▶ NEXT PLAN rewritten: the live slice is 24 (absorbing 31 + 34), not "31 next". Rows for 24, 31 and 34 updated — 31's remaining surface is cited as the *reserved holes at ids 89/90*, which is machine-checkable. A standup entry for the 2026-08-25 packaging/release track was added; it had none. |
| **C3** dependency graph a generation behind | Graph 1 rebuilt: 17 → done, 18/20/21 → held, the pre-renumber ids 10/12/13/14 replaced by stories 25/26/29/28, nodes added for 19/24/30/31/32/33/34/35/36/37/38, and the parked drain reduced to what is actually left (`pub(read)`/`using`/`#if` all shipped). Node/edge references validated. |
| **D1** `08-project-structure.md` "canonical map" | Fixed: the nonexistent `compiler/plan/`, the corpus's nine directories (four with fixtures, five reserved and empty, with counts), all 14 scripts, the `docs/` subtree, and the four missing root entries (`bench/`, `dist/`, `.github/`, `.claude/`). The sample-acceptance list now names all eight gates. |
| **D2** `compiler/README.md` stage banner + CLI | Banner replaced with the eight iterations the front end has taken since plan 3. The CLI list gained `woc <dir>` (the primary mode), `version`, `--update-deps`, `--dump-gc` and `-D`. `crates/rt/src/lib.rs::discover` reference dropped. `gcinfer` added to the module list. |
| **D3** `runtime/src/CODE-LOGIC.md` file table | `park.c/.h` and `crypto.c/.h` added, dated so the gap is visible rather than papered over. |
| **E** `releasing.md` unfollowable steps | The `--draft` step and the phantom rehearsal cleanup deleted, remaining steps renumbered, and a paragraph added explaining why neither exists (plus how to opt into a draft if you want one). |
| **F** small factual errors | All corrected: binary size ~100 KB → 160–260 KB (measured), the scalar list, `time.ticks`, the five missing `net` members, the `fs` read-and-append limit, the `[deps]` key/`use` mismatch (the example would not have compiled), "two samples" → 13 with 8 gated, the six-module count in `00-principles.md`, and the `just gc-cycle` recipe that two checked boxes claimed. |
| **Later findings** | `00-story.md` gained the missing iteration 36 row; `docs/examples/db-actor/` gained the README it never had. |
### Left deliberately unfixed
- **23 broken links in `.dev/`** — vendored plugin-skill copies and reference
study trees. `.dev/` is gitignored (`git ls-files .dev` returns one path), so
these are per-developer notes. Fixing them means re-vendoring the skills with
their `references/` subdirectories.
- **The `just gc-cycle` gate itself.** The false checkbox is now disclosed in
both the plan and the sample's README, but wiring the acceptance script is
work, not documentation, and belongs to whoever picks up that loose end.
- **`tests/corpus/`'s five empty directories.** Documented as reserved with the
plan each was to be filled by; deleting or filling them is a test decision.
- **Two stale references in code comments**, recorded here rather than edited
because this pass was scoped to markdown: `compiler/bin/main.ml:16-19` and
`compiler/src/parser.ml:202` both still cite `crates/rt/src/*.rs`, removed
2026-08-18; and `.github/workflows/release.yml:1-2` says "this workflow has
never run" while line 43 of the same file reports what its first run failed
with.
---
## Structural change 2026-08-26 — status folders removed
Directive from the developer, applied after the fixes above: **`docs/` no longer
uses directories to encode status.** The four story subfolders
(`done/`, `refine/`, `hold/`, `in-progress/`) and top-level `docs/in-progress/`
are gone. All 34 story iterations sit flat in
`docs/stories/language-runtime-database/`, the slice marker sits flat in `docs/`
as `active-slice-<date>-<topic>.md`, and each file's `status:` frontmatter key is
the single place its state is recorded.
This reverses the 2026-08-20/21 convention ("the folder move IS the status
change"). The reason it is a good trade is visible in this repo's own history:
under the old scheme a status change relocated the file, which invalidated every
relative link in and to it — section A of the 2026-08-20 link audit was nine
instances of exactly that, and B2 above found two more that had accumulated
since. A status change is now a one-line edit that cannot break a link.
What the move required, all verified with `just linkcheck` (23 broken, all in
`.dev/`, unchanged from before the move):
- 34 files relocated with `git mv` so history follows them.
- **252 relative links recomputed in 70 files** — not by string substitution but
by resolving each link to an absolute path from its *old* location, remapping
through the move table, and re-deriving it relative to the file's *new*
location. String surgery would have mangled the `../` depth changes on the
moved files themselves.
- Link *text* and backticked paths that named a status folder stripped
separately — a correct target under stale display text is still a lie.
- Convention prose rewritten where it taught the old rule:
`stories/00-status.md`'s header, `stories/board-views.md` (including its Kanban
caveat, which described status changes as folder moves), and
`08-project-structure.md`'s map plus a new naming-convention entry.
- Phrases of the form "moves to `done/`" rewritten as "sets `status: done`" in
the live docs — including the four open checkboxes in the active plan
`2026-08-23-chat-ws-lifecycle.md`, which would otherwise have instructed a
future session to recreate the folders.
Two things surfaced that the move made visible rather than caused:
1. **A frontmatter collision, caught and fixed.** Giving the marker doc
`iteration: "24"` would have put two files in the repo claiming to be
iteration 24 with contradicting `status:` values. The marker is a progress
log, not a status carrier, so it takes `slice: "24"` and points at the story
that owns the status.
2. **Story 24's frontmatter said `refine` while the board said 🔄 live.** Under
the old scheme that drift was cheap to leave; under this one frontmatter *is*
the answer, so it is now `status: in-progress`. Iterations 31 and 34 keep
`refine` — they are absorbed into 24 but their own closeout is still pending,
which is what 24's T10 exists to do.
Dated records were deliberately left naming the old paths: the findings sections
of this document (which declare themselves a pre-fix snapshot), the history
section of `00-link-audit.md` (which says every path in it is as it was on that
date), and the "Files:" lists of closed plans. Rewriting those would destroy the
record of what was true when each was written.

View file

@ -0,0 +1,260 @@
# Git commit history — features and their cherry-picks
Reference for **which commits carried which feature onto `master`**, so a
feature can be traced, re-reviewed, or reverted as a unit long after the
history it was written in has moved on.
## The workflow this file records
1. **Development happens on `dev`.** Not on `master`, and not on a fresh
branch per feature.
2. **Every commit on `dev` carries a feature-specific unique prefix**, written
as the conventional-commit scope — `feat(db2-keys): …`, `fix(db2-keys): …`.
The scope, not a bare leading word, so the repo keeps the `feat`/`fix`/`docs`
type it has used throughout. One prefix per feature, reused by every commit
belonging to it, which makes a feature's commits selectable with
`git log --grep` without reading a single diff.
3. **When the feature is ready** — complete, not merely green — `git checkout
master` and **cherry-pick** that feature's commits, in order.
4. **Record the result below**: the `dev` hashes, the `master` hashes the
cherry-pick produced, and the date. The two differ — a cherry-pick makes new
commits — and that mapping is the whole reason this file exists.
Ready means the same gate as always: no half-implemented feature reaches
master. An annotation the compiler accepts but does not honour counts as
broken, however green the suite.
## Prefix registry
One row per feature. The prefix is claimed here before its first commit, so two
features cannot collide.
| Prefix | Feature | Status |
| --- | --- | --- |
| `commit-history` | this file and the workflow it records | ✅ on `master` 2026-08-30 |
| `db2-keys` | databasev2 2 — `resident: keys` storage and readers | ✅ on `master` 2026-08-30 (with `db2-delta` and `db2-chains`). The “Not ready” note this row carried is spent: the loader refusal was lifted and updates are implemented |
| `db2-chain-review` | review of the databasev2 chain and dependency graph | ✅ on `master` 2026-08-30 |
| `db2-delta` | databasev2 2 — keys-resident updates as WAL delta records | ✅ on `master` 2026-08-30 |
| `db2-chains` / `db2-chain` | databasev2 11 — bounding a keys-resident row's delta chain | ✅ on `master` 2026-08-30 |
| `site` | the writeonce.de tutorial site | ✅ on `master` 2026-08-30 |
| `db2-migrate` | databasev2 12 — schema migrations (add/delete, declarative, auto on boot) | ✅ on `master` 2026-08-31 |
| `site-deploy` | the writeonce.de redeploy runbook (`docs/guides/deploying-site.md`) | ✅ on `master` 2026-08-31, picked as iteration 12's docs dependency |
| `site-update` | the developer loop for changing the site app (`docs/guides/updating-site.md`) | on `dev` 2026-08-31 |
| `site-submodule` | `docs/examples/site` extracted to github.com/shoneyJ/writeonce-site and consumed as a submodule | ✅ on `master` 2026-08-30. Both branches now track the site by revision; an edit to it is a commit in that repo plus a pointer bump here |
| `lang41` | runtime: unadopted shard must not impersonate shard 0 | on `dev` (`9dca0b4`); independent of the residency stack, not picked |
| `porch-store` | porch store tables, Limiter and Idempotent middleware (Phases A, B, C) | on `dev` (`519d411`, `5b1e82a`, `aee7926`). **In progress**: Phase C was uncommitted work from a parallel session, committed as-is, and calls `json.decode`/`json.encode` with no `use json` import |
| `query-corpus` | databasev2 query-grammar corpus #1 | on `dev` (`4c82461`). Conclusion was "no new grammar needed" |
| `lang42` | iteration 42 — bounded subprocess: `proc.run` bounded + parked (pidfd, caps, ceiling, owner-bound reaping), `proc.run_dl`; carries the alacritty/tmux/zen parity studies and the porch dependency-graph section from the same sweep | ✅ on `master` 2026-09-01 |
| `wmux` | the wmux track (`docs/stories/wmux/`, iteration 1 was language 43) — the terminal multiplexer, first of the softwares built with writeonce; story + gap-chain remap first, code follows gap by gap | on `dev` 2026-09-01 |
| `rt2` | the runtime-v2 track (`docs/stories/runtime-v2/`) — the runtime beyond sockets: streaming subprocess, PTY, signals-as-events, termios, fd passing, term.size/width; six iterations, all landed 2026-09-02 | on `dev` 2026-09-01 |
| `wmux` (code) | wmux rung 1 — the multiplexer example (`docs/examples/wmux`) + `just wmux` gate; sessions, attach by fd-handover, durable scrollback, restart replay | on `dev` 2026-09-02 (extends the `wmux` docs prefix) |
| `db2-7` | databasev2 7 — single-file store `WO_DATA=<path>.db` (registered after its first commit, `b31bd40`) | on `dev`, closed 2026-09-10 |
| `lang-18` | language 18 — `transaction { }` over the WAL's staged batch (registered after its first commit, `6b4b960`) | on `dev`, in progress since 2026-09-11 |
| `db2-ephemeral` | databasev2 2 task 6a — refuse `durable: true` without `WO_DATA`, `WO_EPHEMERAL=1` escape hatch, `.wob` v8 table bit (`WO_CLASSF_TABLE`); closes iteration 2 | on `dev` 2026-09-15 |
| `db2-4b` | databasev2 4 part B — the async barrier, re-brainstormed 2026-09-10 (docs only until the fold lands) | on `dev` 2026-09-15 |
| `db2-5` | databasev2 5 — bounded tables and eviction, the resident byte budget as Phase A; brainstormed to `ready` 2026-09-10 | on `dev` 2026-09-15 (docs) |
| `db2-14` | databasev2 14 — the shop workload story (`refine`) | on `dev` 2026-09-15 (docs) |
| `agents` | `.claude/agents` persona roster — codd/fielding/ada families, `lintor`, the README | on `dev` 2026-09-15 |
| `status` | cross-track reconciliation sweeps of the board, dependency graph and story tables (in use since `732c221`) | on `dev` |
| `tls` / `crypto` / `rv2-tls` / `rv2-aead` / `net` | runtime-v2 8 (the AEADs) and 9 (in-process TLS 1.3, both directions): `net.connect` (id 110), `net.connect_tls`/`read_tls`/`write_tls`, `net.accept_tls`, RSA-PSS + ECDSA-P256 signing, PEM/DER parsing; `just tls`, `just tls-server` | ✅ on `master` 2026-09-15 (registered after the fact) |
| `porch2-rng` | porch 2 phase A — `random_bytes` builtin (id 119) | on `dev` — not picked 2026-09-15: porch 2 is `in-progress` |
| `jarvis`, `rv2-obs`, `porch-cookies`/`-csrf`/`-routing`/`-streaming`/`-sse`/`-static`, `audit`, `workflow`, `runtime` (docs) | docs-only prefixes: the jarvis stories, rv2 7 brainstorm, the porch 2–8 brainstorms, the doc audit, the prebuild-feature workflow, the TLS CODE-LOGIC | ✅ on `master` 2026-09-15 |
| `gate`, `vm`, `arena`, `compiler`, `runtime` (fix) | one-off fixes: `e274f4a` + `ec797d9` (gates), `63065ff` (lang 41 double free), `78ae3be` (lang 44 poison-on-free), `2d54710` (lang-41 side defects), `35efa21` (poisoned class NULL fmap) | ✅ on `master` 2026-09-15 |
## Cherry-picks onto master
Newest first. `dev` hash is the original; `master` hash is what the cherry-pick
produced.
| Date | Prefix | Feature | `dev` → `master` |
| --- | --- | --- | --- |
| 2026-09-15 | `porch-store`, `rt2`, `tls`+`crypto`+`rv2-*`+`net`, `lang41` + one-off fixes, `db2-7`, `db2-keys` (13), `db2-ephemeral`, `db2-chains`, `query-corpus`, `agents`, the docs prefixes | **the 2026-09-01 → 09-15 `dev` catch-up, minus three unfinished features**: 129 commits picked in `dev` order (127 in the sweep, plus `e9213bb` and `1ce195d` — two fixes the verification on `master` forced: `woc build -o` failing on a fresh checkout, and the web-app keypool leg refused since 6a — committed on `dev` first, then picked) with `-x` (each `master` commit names its `dev` source), mapped per prefix below. **Left on `dev` on purpose:** the **wmux** track (59 commits — rungs 10/12/13/15/16/18 are `in-progress` and share the prefix with the done rungs), **language 18** `transaction { }` (10 commits — T7's durability legs open, criterion 1 outstanding), **porch 2** phase A `random_bytes` (2 commits — the iteration is `in-progress`). Conflicts: two `justfile` hunks (kept `tls`/`tls-server`, dropped the `wmux` recipe), `scripts/wmux-accept.sh` dropped from `4553ca1`, seven markdown files taken from the picked commit; three master-only follow-ups in `69114ab`. Verified on `master` after a fresh build in its own worktree: woc-test clean; `make -C runtime test` 21 suites 0 fail (test_wal 6660/0, test_tls 123/0, test_crypto 130/0, test_loader 36/0), `test-iso` 21 suites 0 fail, cli_smoke OK; `just oop-e2e` **127/0** (single-binary smoke 4/0 — the new `build-into-missing-dir` check), `just residency` **32/0**, `just db-actor` **10/0** (from a deleted target/), `just web-app` **56/0**, `just chat` **11/0**, `just subprocess` **12/0**, `just tls` **5/0**, `just tls-server` **5/0**, `just deps-accept` **8/0**, `just db-bench-quick` **185 checks, 0 failures**. `just fibers` 10 checks / **1 failure — the KNOWN TSan race in `wo_engine_stop` (vm.c:719)**, red on `dev` the same way (codd.md "Next bugs"), not a pick regression. Not run: `just site` (submodule not initialised in the worktree), `just wmux` (track not picked). | see the sub-table below; `69114ab` is master-only |
| 2026-09-01 | `lang42` | **iteration 42 — bounded subprocess**: `proc.run` parked (pidfd + epoll bundle, `_dl` retry mould) with deadline/output-cap/ceiling refusals by name and owner-bound reaping; `proc.run_dl` (id 96) states bounds per call; the pre-42 sequential-drain deadlock proven then dissolved. Includes the alacritty/tmux/zen-browser parity studies and the porch graph section. Zero conflicts. Verified on `master` after rebuild: 38 runtime suites 0 fail both dispatch flavors (`test_proc` 128/0, `test_wal` 5966/0), woc-test 557/0 (forced, not cached), subprocess-accept 12/0, site-accept 23/0 | `5b92e20` → `2f6d39d`, `75fbd30` → `b287bf7`, `821899b` → `afa16e5`, `c30507b` → `81c28d8`, `975959a` → `64542e5`, `a3b5dc3` → `ce98fa1`, `b147dd4` → `346f885`, `5dfbeda` → `49b0193` |
| 2026-08-31 | `db2-migrate` + `site-deploy` | **databasev2 12 — schema migrations v1**: WO_WAL_SCHEMA head record, name-keyed boot diff, record-level transcode for add/delete, poisons that bite only with records; plus the redeploy runbook the close-out edits (dev-only until now). Zero conflicts. Verified on `master`: 36 suites 0 fail (`test_wal` 5966/0), woc-test clean, residency-accept 14/0, site-accept 23/0 | `930a715` → `b594717`, `072e007` → `8d9207d`, `ba8519f` → `570e0d6`, `63a063b` → `b1b7984`, `b69092a` → `4a70fc7`, `b21943a` → `ace5699`, `4bb6ece` → `4f1fda1` |
| 2026-08-30 | `site-submodule` | **`docs/examples/site` becomes a submodule** — extracted to github.com/shoneyJ/writeonce-site with `git subtree split` (its own 9 commits of history, not a snapshot) | `4b56348` → `a5497a3`, `4eead89` → `565b894` |
| 2026-08-30 | `db2-keys` + `db2-delta` + `db2-chains` + `site` | **databasev2 `resident: keys`, end to end** — storage, readers, deletes, updates as delta records, bounded delta chains, and the tutorial chapter documenting them | 37 commits, mapped one-to-one below |
### 2026-09-15 — the `dev` catch-up
Picked in `dev` order onto `master` in a separate worktree (`git worktree add`), each with `cherry-pick -x`, so this table can be regenerated from `git log master` (`cherry picked from commit …` trailers). One row per prefix, pairs in `dev` order.
| Prefix | n | `dev` → `master` |
| --- | --- | --- |
| `porch-store` | 26 | `519d411` → `ddc8b99`, `5b1e82a` → `8eb36a9`, `aee7926` → `3e6eab7`, `fc09e94` → `3828c76`, `5c3544d` → `7061646`, `f079455` → `06b7722`, `a96ebe2` → `4a22da6`, `3a9bddc` → `0d98a52`, `676e651` → `9fb0cff`, `77e06c1` → `9190507`, `153fd29` → `eb8e019`, `a653dd0` → `bf69f82`, `831e9d8` → `569abef`, `eae1b06` → `75965b5`, `e61015f` → `0542cda`, `464147a` → `2d47671`, `9ad5947` → `f27fe3b`, `21934b1` → `e4d7922`, `2ac1b8b` → `360ca47`, `91099cf` → `b641c37`, `b738269` → `d4e5cce`, `c53ad58` → `f991f48`, `86e7244` → `47e5acf`, `6d48dbc` → `8904be8`, `a919ab1` → `23e5b0f`, `79e6da4` → `6d1288b` |
| `query-corpus` | 1 | `4c82461` → `2b70306` |
| `commit-history` | 5 | `bc8fec0` → `a95f58d`, `aa8abfb` → `bb7e1a1`, `22b5675` → `aa5f3da`, `ab7df69` → `d9d9632`, `d0e658f` → `c3c5d67` |
| `lang41` | 1 | `9dca0b4` → `6360088` |
| `site-update` | 1 | `a21a02f` → `d5da3ac` |
| `rt2` | 9 | `e0451cb` → `6ae251f`, `d313cde` → `0be01b7`, `9be87f1` → `b79597e`, `9836c9c` → `7485c66`, `14e03a6` → `055cb70`, `b439387` → `5340ef2`, `1d68902` → `3605e11`, `bc1b4f0` → `5eef0fc`, `1514fb4` → `1e5d81f` |
| `runtime` | 2 | `35efa21` → `784cd25`, `5670304` → `6c22cd3` |
| `porch-cookies` | 1 | `4d31d53` → `602daa6` |
| `porch-csrf` | 1 | `3a4fb42` → `c103df7` |
| `porch-routing` | 1 | `0589a13` → `5a04513` |
| `porch-streaming` | 1 | `1520540` → `d37c583` |
| `porch-sse` | 1 | `07f5357` → `699f811` |
| `porch-static` | 1 | `9801fce` → `a509656` |
| `net` | 1 | `13c6f12` → `92ac803` |
| `(no scope)` | 1 | `203470c` → `83335cf` |
| `rv2-tls` | 13 | `f1881cc` → `69c6822`, `e24b8ec` → `4f8a0ae`, `b929a20` → `8f4fbd2`, `ae42943` → `0f0cc60`, `3eab98c` → `7f0b189`, `796ed88` → `7eb0708`, `d49bc38` → `836c09f`, `8b6e721` → `8649d59`, `9662cd8` → `5b70ac1`, `9fcb4a9` → `3787a14`, `f02518c` → `a3f3dbd`, `57613bd` → `1f3358c`, `f3a3c96` → `f1f11c3` |
| `rv2-aead` | 4 | `c8a5a31` → `cb92908`, `db5bdf3` → `a15dfa0`, `249b1db` → `b83832c`, `138de17` → `be35434` |
| `crypto` | 12 | `961854a` → `74f3370`, `f12a745` → `74db22b`, `dccf650` → `411e8cc`, `c8d27b6` → `3fa0445`, `f41b1c5` → `579130a`, `9118177` → `781589d`, `92c996b` → `d502866`, `4ec1c75` → `4da6ab7`, `cf8fdfc` → `2181d6d`, `1bc6d04` → `e17986c`, `819d672` → `f7aebb2`, `fba3035` → `fb34da7` |
| `jarvis` | 2 | `a615ee8` → `f862dc2`, `8e160c3` → `a81135e` |
| `tls` | 15 | `5021a99` → `74d66ec`, `417fcc1` → `c2eb996`, `541c71b` → `2617bf4`, `afd9f23` → `de3984c`, `74c332d` → `ba34017`, `319ce8b` → `f9ed841`, `9d40055` → `2c0dd55`, `3811418` → `ab07609`, `6445d55` → `07c6dee`, `9a922b3` → `7ab9e3d`, `3d8bb14` → `398fbcc`, `34d2b8f` → `05d4d08`, `2d4c300` → `989fcdd`, `54020a4` → `a804ad4`, `ac3bf74` → `db6e414` |
| `rv2-tls,jarvis` | 1 | `4fdf071` → `2b33589` |
| `rv2-tls,status` | 1 | `ad87974` → `104e805` |
| `workflow` | 1 | `2bfbb0c` → `fff86d3` |
| `rv2-tls,jarvis,status` | 1 | `732c221` → `a4d4b34` |
| `vm` | 1 | `63065ff` → `6948cd2` |
| `audit` | 1 | `f1049dd` → `ba23483` |
| `arena` | 1 | `78ae3be` → `cddda8c` |
| `rv2-obs` | 1 | `feb11c3` → `3b97569` |
| `compiler` | 2 | `2d54710` → `35331ac`, `e9213bb` → `23504ee` |
| `db2-7` | 5 | `b31bd40` → `92bf6de`, `ccee2d0` → `5739a6c`, `f1985ba` → `39da4b4`, `aaea6b2` → `7200406`, `38f4f1e` → `8d48cac` |
| `gate` | 3 | `e274f4a` → `65745e6`, `ec797d9` → `3c1161a`, `1ce195d` → `896516c` |
| `db2-keys` | 3 | `6310078` → `30ea9eb`, `1b6750d` → `2019364`, `b5b1da7` → `5a6c702` |
| `db2-ephemeral` | 3 | `863692a` → `0e2eee6`, `4553ca1` → `719f7f3`, `2c35319` → `561bb2a` |
| `db2-chains` | 1 | `d841390` → `47ae475` |
| `agents` | 1 | `830bbb1` → `a12a0ec` |
| `db2-4b` | 1 | `7ceb7b8` → `07e368c` |
| `db2-5` | 1 | `579199a` → `6eddd8c` |
| `db2-14` | 1 | `f33ae98` → `2ed50f2` |
| `status` | 1 | `423b3c1` → `c41ed17` |
**What the pick taught.**
- **"Already on master" is the mapping table, never a prose mention.** `79e6da4`
(porch 1 re-scoped to the limiter, idempotency reverted to porch 9) was named
in the 2026-08-30 prose and had never been picked, so `master` still carried
the reverted middleware and 638 lines of gate legs for it. Filtering the pick
list on "hash appears anywhere in this file" skipped it; the trailing
`git diff --name-only dev` minus the excluded commits' footprint caught it.
`git cherry master dev` answers patch-equivalence; this table answers
"picked with conflicts".
- **Earlier conflict-resolved picks had dropped hunks**: `89a7456` lost
`b3d8c40`'s skill-catalog README link fix, the porch-store pick lost the
porch 9 story file. Both restored by `69114ab`.
- **`ec797d9` (executable bit) was a no-op until `79e6da4` reset the mode**, so
it is picked after it (`3c1161a`), out of `dev` order.
- **Excluding a track leaves its documentation dangling.** The board and graph
on `master` describe wmux and language 18 as the project's state (they are),
so `just linkcheck` on `master` reports the wmux story and spec links as
broken until that track is picked; `.dev/reference` links break in any
checkout without the developer-local symlinks and are not defects.
- **Proof of equality:** re-applying the 70 excluded commits onto `master` in a
scratch branch reproduces `dev` in every code path except the two files
below — so `master` is exactly `dev` minus wmux, language 18 and porch 2.
**Obligations when wmux is picked:** re-add the `wmux:` recipe to the
`justfile` (dropped in both `justfile` conflicts), and re-apply the
`WO_EPHEMERAL=1` edits to `scripts/wmux-accept.sh` from `dev`'s `4553ca1`
(the client legs refuse without them since databasev2 2 task 6a).
### 2026-08-30 — the databasev2 residency stack
The first cherry-pick under this convention, and it could not be a single
iteration: **databasev2 11 (bounded delta chains) does not stand alone.** Its
commits touch `wo_wal_fold_row_at`, `keys_fold_into` and `row_apply_field_keys`,
none of which existed on `master` — so the whole stack it sits on came with it,
in dev order:
| # | Prefix | `dev` | `master` | Title |
| --- | --- | --- | --- | --- |
| 1 | `db2-keys` | `125bd09` | `620c0a7` | feat(db2-keys): storage — drop the payload, read it back from the log |
| 2 | `db2-keys` | `08abd09` | `d985901` | feat(db2-keys): inserts and boot — payload dropped after the barrier |
| 3 | `db2-keys` | `0c97fa4` | `d8839c0` | feat(db2-keys): the query paths read through the iterator and borrow |
| 4 | `db2-keys` | `f606fc9` | `234b1f0` | feat(db2-keys): rewire remaining readers, survive compaction |
| 5 | `db2-keys` | `b3d8c40` | `89a7456` | docs(db2-keys): reconcile databasev2 and porch markdown with the code |
| 6 | `db2-chain-review` | `2ecaf0c` | `1af4910` | docs(db2-chain-review): review the databasev2 chain and dependency graph |
| 7 | `db2-keys` | `76b8fd9` | `390635c` | fix(db2-keys): delete on a keys-resident table was memory corruption |
| 8 | `db2-keys` | `c9c7e03` | `d27e774` | docs(db2-keys): a runnable example for per-table storage |
| 9 | `db2-keys` | `dc25462` | `c8a0c7b` | fix(db2-keys): a logged delete must replay on a keys-resident table |
| 10 | `db2-keys` | `d4104dc` | `4105f1c` | docs(db2-keys): the residency example becomes a product catalogue |
| 11 | `db2-keys` | `c9a88b0` | `daba10c` | docs(db2-keys): spec — delta records for keys-resident updates |
| 12 | `db2-delta` | `abb8fc9` | `b5cc77d` | docs(db2-delta): implementation plan for keys-resident delta updates |
| 13 | `db2-delta` | `c6cd486` | `efa118b` | docs(db2-delta): correct a line citation before execution |
| 14 | `db2-delta` | `9c6f832` | `ff73da7` | feat(db2-delta): WAL delta record kind and encoder |
| 15 | `db2-delta` | `20ba096` | `82dbd4a` | fix(db2-delta): make delta test detect a field_idx/back_off transposition |
| 16 | `db2-delta` | `a60231c` | `1f04cff` | feat(db2-delta): fold a delta chain, route reads through it |
| 17 | `db2-delta` | `173dbf2` | `38159b0` | fix(db2-delta): fold's cycle guard checks direction, not step count |
| 18 | `db2-delta` | `89c56a1` | `5b9ffb7` | feat(db2-delta): keys-resident updates append, indexes follow |
| 19 | `db2-delta` | `409186d` | `f1f4d13` | fix(db2-delta): unique shadow-check gets its own buffer, not r's |
| 20 | `db2-delta` | `4d13bce` | `dbfa385` | feat(db2-delta): wire the request path, defer re-point to the barrier |
| 21 | `db2-delta` | `c049ab9` | `d6eeacb` | fix(db2-delta): close the unique-shadow-check's same-drain blind spot |
| 22 | `db2-delta` | `7e4ae70` | `ef606e1` | feat(db2-delta): replay and compaction fold delta chains |
| 23 | `db2-delta` | `b87c68f` | `8dbeb2a` | feat(db2-delta): lift the resident:keys refusal, prove it end to end |
| 24 | `db2-delta` | `3ea6d64` | `76a9f17` | fix(db2-delta): refuse resident:keys with no WO_DATA at runtime |
| 25 | `db2-delta` | `d4b12d1` | `4ae3af2` | fix(db2-delta): borrow the pending re-point, not the stale durable offset |
| 26 | `db2-delta` | `fed9fe8` | `b8e4bc9` | fix(db2-delta): pend_repoint failure fatal; delta fold no longer trusts a live WAL |
| 27 | `db2-delta` | `b575678` | `bdedc50` | docs(db2-delta): resident:keys has storage; move done criteria to Met |
| 28 | `db2-delta` | `e643440` | `35aa0be` | docs(db2-delta): guide to log-structured rows for a new reader |
| 29 | `db2-chains` | `f667cad` | `0c874a6` | docs(db2-chains): spec + story for bounding a row's delta chain |
| 30 | `db2-keys` | `7cba9b1` | `ab292a4` | feat(db2-keys): task 7 — measure resident: keys against swapping |
| 31 | `db2-keys` | `abc276a` | `152b5ea` | feat(db2-keys): GB-scale bench modes, unmeasured |
| 32 | `db2-keys` | `a310496` | `3855e58` | feat(db2-keys): gate the residency measurement, close out task 7 |
| 33 | `db2-chains` | `1b808ab` | `e3c544c` | feat(db2-chains): bound a keys-resident row's delta chain |
| 34 | `db2-chain` | `f93b5d9` | `b375772` | test(db2-chain): cover flattening, and drop a ceiling no input could reach |
| 35 | `db2-chain` | `de39a88` | `5a98730` | docs(db2-chain): close out iteration 11 on the board |
| 36 | `site` | `3b503c0` | `461ba18` | feat(site): tutorial chapter for durable and resident storage modes |
| 37 | `commit-history` | `41923eb` | `397a2b6` | docs(commit-history): feature-to-cherry-pick reference |
**What was deliberately left on `dev`:** the 26 `porch-store` commits. porch 1
was re-scoped mid-flight (`79e6da4` reverts idempotency to porch 9), so it is
the exact case this file's “ready means complete, not merely green” bar exists to
catch. `lang41` and `query-corpus` also stayed — independent features, not
dependencies of this one.
**Three conflicts, all in docs, all resolved toward what `master` can honestly
claim:**
- `docs/examples/skill-catalog/README.md` — a one-line link fix inside a file
belonging to `query-corpus`, which is not on `master`. Edit dropped; the file
stays absent.
- `docs/00-databasev2-chain-review.md` — created by `db2-chain-review`, which the
prefix filter had excluded while later `db2-keys` commits kept editing it. Resolved
by picking that commit too, rather than dropping edit after edit.
- `docs/stories/00-status.md` — `b87c68f` carried one databasev2 status entry
bundled with two porch-1 entries. **Only the databasev2 entry was kept.** Taking
the whole block would have left `master` claiming porch 1 was done while none
of its code was there.
**Verified on `master` after the pick, not assumed:** `woc-test` clean; `wovm-test`
all 20 suites green (`test_wal` 5700/0, `test_table` 856/0); `just site` 23 checks,
0 failures; `residency-accept` 14 checks, 0 failures — including the leg proving
`resident: keys` without `WO_DATA` exits 2 and names the offending class.
**Still outstanding on `master`, and known:** databasev2 2 task 6's byte-budget
refusal. A missing *guard*, not an unhonoured annotation — the annotation is now
genuinely honoured, measured at a 2.55× smaller resident set. The other half of
task 6 (`durable: true` with no `WO_DATA` silently discarding writes) predates this
pick and is unchanged by it.
## Before this convention
Work up to 2026-08-29 landed on `master` by **merging** feature branches, so
those commits keep their original hashes and have no entry here.
`git log --merges master` is the record for that period.
The `db2-keys` and `porch-store` commits are the seam: they were written on
`porch-store-middleware` before this convention (`18ce4d5`, `f9c36ef`,
`11a92df`, `91411ae`, `6c8550a`, `01af1b9`) and were replayed onto `dev` with
prefixed titles. The replay was verified identical, not merely applied — after
it, `git diff porch-store-middleware dev` over the whole tree was empty.
On 2026-08-29 every other branch was consolidated so only `dev` and `master`
remain. Three could not be replayed and were preserved as **annotated tags**
instead — nothing is lost, and each tag's message says why:
| Tag | Why it is not on `dev` |
| --- | --- |
| `archive/cleanup-pre-existing-changes` | Aug 10, based on an Aug 8 commit. Carries `crates/` and `Cargo.toml` — the Rust runtime `master` has since deleted entirely. Replaying it would resurrect it. |
| `archive/ipc-attach` | Iteration 9c attach channel. Refactors `wo_row_insert`/`wo_row_update_field` into engine-encoded cores; `dev` rewrote those same functions for `db2-keys`. Two overlapping refactors of one function, ~250 conflicted lines. |
| `archive/keypair-auth` | Iteration 9d, builds on 9c — blocked by the same overlap. |
The 9c/9d hazard is specific and worth stating: that branch's contract
transfers ownership of `vals` **on failure as well as success**, while `dev`'s
keys-resident arm returns early *without* freeing. A merge that compiles and
passes could still leak or double-free. Reconciling them is an integration
task, not a conflict resolution — recover the work with
`git checkout -b <name> archive/ipc-attach` when it is scheduled.

View file

@ -1,154 +1,156 @@
# Markdown link audit — 2026-08-20 # Markdown link audit — re-run 2026-08-26
Scope: every `*.md` in the repo (`.git` excluded). Scope: every repo-authored `*.md`. `.git`, `target`, `dist`, `node_modules`,
External URLs were not fetched (no network verification performed). `_build` and — since 2026-08-26 — `.dev/` and `.superpowers/` are excluded; see
the note under the table. External URLs are not fetched (no network
verification).
| | files | relative links | broken paths | bad anchors | | | files | relative links | broken paths | bad anchors |
|---|---|---|---|---| |---|---|---|---|---|
| first scan | 207 | 574 | 97 | 0 | | first scan (2026-08-20) | 207 | 574 | 97 | 0 |
| after section A fixes | 206 | 569 | **88** | 0 | | after section A fixes (2026-08-20) | 206 | 569 | 88* | 0 |
| **re-run 2026-08-26, before fixes** | 235 | 675 | 77 | 0 |
| **re-run 2026-08-26, after fixes** | 237 | 652 | 23 | 0 |
| **after scoping the gate to repo-authored docs** | 149 | 656 | **0** | **0** |
Section A is repaired and verified. Sections B–F are pre-existing rot and \* The 2026-08-20 report's prose said 88 twice while its own sections B–F summed
still open — every one of the remaining 88 lives there. to 77. The 77 was right; the 88 was an arithmetic slip, corrected here.
**The gate is now clean: 0 broken, 0 bad anchors.**
The last 23 were all in `.dev/` — vendored plugin-skill copies and cloned
reference projects, neither of which this repo authors. `scripts/linkcheck.py`
now skips `.dev/` and `.superpowers/` alongside `.git`/`target`/`dist`. That was
forced by adding gofiber/fiber as a reference (2026-08-26): its own docs are
Docusaurus pages whose links resolve at site-build time, not on disk, so the
clone alone contributed 21 broken paths and 39 bad anchors. A gate that reports
the same dozens of failures forever is a gate nobody reads. Everything the repo
actually ships — `docs/`, `compiler/`, `runtime/`, `database/`, `tests/`,
`bench/`, `scripts/`, the root README — is still scanned, and is clean.
Re-check with `just linkcheck`. Re-check with `just linkcheck`.
Tool: `linkcheck.py` — walks the tree, strips fenced/inline code, extracts inline Tool: `scripts/linkcheck.py` — walks the tree, strips fenced/inline code,
links and reference definitions, resolves each relative target, and validates extracts inline links and reference definitions, resolves each relative target,
`#fragment` against GitHub-style heading slugs of the target file. and validates `#fragment` against GitHub-style heading slugs of the target file.
--- ---
## A. Regressions from the in-flight renumber — FIXED 2026-08-20 ## What the 2026-08-26 re-run changed
All nine broke because files moved in the working tree; each had a known ### 1. The dead-era exploration links — RESOLVED (48 links, 15 files)
successor. Repaired:
Sections B and C of the 2026-08-20 report left a decision open: the studies under
`docs/plan/exploration/` cite the old flat `docs/plan/NN-*.md` numbering and the
`docs/runtime/database/` tree, both removed with the Rust track on 2026-08-18,
and no successor map existed. That decision is now made.
**De-linked, not re-pointed.** The link *text* in these studies names the retired
plan by number — `[plan 09a]`, `[plan 11]`, ``[`12-engine-disk-cutover.md`]`` —
so aiming those at a story would have made each sentence assert something false
about a document that never said it. The targets were stripped and the text kept
as plain code spans. The studies still read correctly as the dated records they
are, and they no longer claim a file exists.
The successor map lives in
[`plan/discarded.md`](plan/discarded.md#successor-map-for-the-removed-rust-era-plan-paths)
— one row per retired path, naming what carries that work now (or stating
plainly that nothing does, as with `12-engine-disk-cutover.md` and
`08-sendfile-static-assets.md`). That table is what the 2026-08-20 report's
"Still open" note asked for.
Files touched: `assembly/{00-overview,02-writeonce-stance}.md`,
`c-runtime/{00-plan,01-architecture,02-single-binary}.md`,
`linux/{01-epoll,02-eventfd,03-timerfd,04-signalfd,05-inotify,06-sendfile,07-io_uring,08-mmap,11-memfd_create,12-pwrite-fsync}.md`.
### 2. `runtime/README.md` — RESOLVED (3 links)
`prototypes/wo-db/`, `docs/runtime/database/03-inmemory-engine.md` and
`docs/plan/09-concurrency-scaleout.md` all went when that README was restructured
to lead with `wovm` and demote `wo-rt.c` to a clearly-marked historical section.
It also carried two recipes that do not exist (`just rt-c-demo`,
`just rt-c-bench`) — not a link problem, fixed in the same pass. See
[`00-doc-audit.md`](00-doc-audit.md) §A6.
### 3. Two breaks the 2026-08-20 report did not have — RESOLVED
Both were caused by story files moving between status folders after that report:
| Source | Was | Now | | Source | Was | Now |
|---|---|---| |---|---|---|
| `docs/00-status.md:167` | `stories/language-runtime-database/05-language-surface.md` | `…/done/05-language-surface.md` | | `docs/examples/employee-list/README.md:5,6` | `…/refine/20-cross-program-tables.md`, `…/refine/21-keypair-attach-auth.md` | `…/hold/…` (both stories moved to `hold/` 2026-08-21) |
| `docs/00-status.md:187` | `stories/language-runtime-database/18-memory-db-features.md` | `…/hold/18-memory-db-features.md` | | `docs/stories/…/hold/26-blue-green-deploy.md:9` | `00-story.md` | `../00-story.md` (the sibling stopped being a sibling when 26 moved into `hold/`) |
| `docs/stories/language-runtime-database/00-story.md:60` | `05-language-surface.md` | `done/05-language-surface.md` |
| `docs/stories/language-runtime-database/00-story.md:69` | `18-memory-db-features.md` | `hold/18-memory-db-features.md` |
| `docs/stories/language-runtime-database/25-http-service.md:4` | `../00-story.md` | `00-story.md` |
| `docs/stories/language-runtime-database/26-blue-green-deploy.md:4` | `../00-story.md` | `00-story.md` |
| `.../refine/08-shard-actor-runtime.md:98` | `../hold/09e-durability-throughput-scale.md` | `22-durability-throughput-scale.md` |
| `.../refine/08-shard-actor-runtime.md:100` | `09f-io-uring-commit.md` | `23-io-uring-commit.md` |
| `.../refine/20-cross-program-tables.md:143` | `../hold/09d-keypair-attach-auth.md` | `21-keypair-attach-auth.md` |
The `25`/`26` pair used `../00-story.md` while `00-story.md` is a sibling — the This is the recurring shape: **a story folder move breaks every relative link
`refine/`-relative form pasted into files one level up. in and to that file.** Section A of the 2026-08-20 report was nine instances of
it; these are two more. Worth a check in whatever moves a story.
Link labels were renumbered with their targets, since the old IDs contradicted ### 4. Stale paths inside the report itself — RESOLVED
the new paths: `9e`→`22` and `9f`→`23` in `refine/08` (both the "Gated by the
benchmark" note and settled decision 4, "Order: 22 → the 8+11 arc → 23").
## B. Dead era: the old flat `docs/plan/NN-*.md` numbering (48 links) The 2026-08-20 repair table cited `docs/00-status.md` (now
`docs/stories/00-status.md`) and `refine/{08,11,19,20,21}` (now under `done/` and
`hold/`). That table has been retired into the history section below rather than
carried forward with paths that no longer resolve.
`docs/plan/` now holds only `compiler/`, `exploration/`, `oop-vm/`, ### 5. Four links the report listed as open had already been fixed
`discarded.md`, `learnings.md`. Every flat-numbered plan doc is gone, and no
successor path was recorded. Missing targets, by inbound count:
- `09-concurrency-scaleout.md` — 12 `docs/00-principles.md:57,77,78,87` resolved before this re-run — including the
- `11-wal-and-recovery.md` — 9 `examples/blog/README.md` reference that section D called a never-created file.
- `12-engine-disk-cutover.md` — 8 Section D's other entries stand.
- `10-storage-foundations.md` — 8
- `done/02-event-loop-epoll.md` — 4
- `13-class-model-live-pricing.md` — 3
- `07-inotify-content-watcher.md` — 3
- `08-sendfile-static-assets.md` — 2
- `15-mcp-streamable-http.md`, `16-postgres-mirror.md`,
`done/03-hand-rolled-http.md`, `done/04-cutover-remove-tokio-axum.md` — 1 each
Inbound from: all of `docs/plan/exploration/{linux,postgresql,c-runtime,assembly}/`,
plus `docs/00-principles.md:57,77,78`, `runtime/README.md:47`,
`.dev/reference/README.md:55,56,58`.
**Decision needed** — these exploration docs still cite a plan structure that no
longer exists. Either map each to its story successor
(e.g. concurrency-scaleout → `stories/.../refine/08-shard-actor-runtime.md`,
wal/storage → `refine/22-durability-throughput-scale.md`,
io_uring → `refine/23-io-uring-commit.md`) or strip the links and keep prose.
## C. Dead era: the `docs/runtime/database/` tree (7 links)
`docs/runtime/` does not exist. Missing targets:
- `03-inmemory-engine.md` — 5 (incl. one `#recovery` anchor)
- `02-wo-language.md` — 2 (incl. one `#concurrency-model` anchor)
- `07-wo-seg-migration.md` — 1
Inbound from `docs/plan/exploration/linux/{07-io_uring,08-mmap,11-memfd_create}.md`,
`docs/plan/exploration/{assembly/02-writeonce-stance,c-runtime/02-single-binary}.md`,
`runtime/README.md:43`, `.dev/reference/README.md:31`.
## D. Never-created / removed siblings (5 links)
| Source | Target | Note |
|---|---|---|
| `docs/plan/exploration/linux/06-sendfile.md:10` | `./07-splice.md` | slot 07 is `07-io_uring.md`; no splice doc was written |
| `docs/plan/exploration/assembly/00-overview.md:19` | `../../../.dev/reference/go/src/runtime/atomic_amd64.s` | wrong depth **and** file absent from the vendored Go tree |
| `docs/00-principles.md:87` | `examples/blog/README.md` | `docs/examples/blog/` never existed |
| `.dev/reference/rest/README.md:76` | `../../docs/examples/blog/README.md` | same missing example |
| `.dev/reference/README.md:41,59` | `../docs/plan/exploration/colibri/00-colibri-and-mixtral.md` | `exploration/colibri/` absent (2 links) |
## E. `prototypes/` tree gone (4 links)
`prototypes/` is not in the repo. Referenced as `prototypes/wo-db/` from
`docs/plan/exploration/c-runtime/00-plan.md:88`, `02-single-binary.md:83`,
`runtime/README.md:5`, and `prototypes/llama-moe-stream` from
`.dev/reference/README.md:59`.
## F. Vendored skill copies — not ours to fix (13 links)
`.dev/skills/` holds flattened copies of plugin skills. The originals ship as
directories with sibling reference files; flattening dropped them.
- `.dev/skills/context-mode/context-mode.md:297-300` → `./references/{patterns-javascript,patterns-python,patterns-shell,anti-patterns}.md`
- `.dev/skills/superpowers/requesting-code-review.md:34,95` → `code-reviewer.md`
- `.dev/skills/superpowers/subagent-driven-development.md:232,300,345,400,410` → `implementer-prompt.md`, `task-reviewer-prompt.md`, `re-review-prompt.md` (×2), `../requesting-code-review/code-reviewer.md`
- `.dev/skills/superpowers/test-driven-development.md:206` → `writing-good-tests.md`
- `.dev/skills/superpowers/writing-skills.md:12,587` → `../using-superpowers/references/{codex,gemini}-tools.md`, `testing-skills-with-subagents.md`
Leave as-is, or re-vendor the skills with their `references/` subdirectories.
--- ---
## Structural problems found alongside the links ## Out of gate scope — `.dev/` (was 23 links, now unscanned)
1. **Iteration 19 was double-booked — RESOLVED.** Recorded so the knowledge is not lost, but no longer reported by
`refine/19-chat-websocket-workload.md` and `refine/24-chat-websocket-workload.md` `just linkcheck`. Not ours to fix, unchanged in character from the 2026-08-20
were the same document, differing only in the `# Iteration NN` heading, while report's section F.
- **`.dev/skills/` (15 links)** — flattened copies of plugin skills. The
originals ship as directories with sibling `references/` files; flattening
dropped them. `context-mode.md:297-300`, `subagent-driven-development.md` (5),
`writing-skills.md` (3), `requesting-code-review.md` (2),
`test-driven-development.md:206`. Leave as-is, or re-vendor the skills with
their subdirectories.
- **`.dev/reference/` (8 links)** — `README.md` (7) points at the removed
`docs/plan/{linux,assembly}/` and `15-mcp-streamable-http.md`, the absent
`exploration/colibri/`, and `prototypes/llama-moe-stream`;
`rest/README.md:76` points at `docs/examples/blog/`, which never existed.
`.dev/` is gitignored (`git ls-files .dev` returns only `.dev/README.md`), so
these are per-developer notes, not repo content.
---
## History — the 2026-08-20 first pass
Kept for the record; every path below is as it was on that date.
### A. Regressions from the in-flight renumber — FIXED 2026-08-20
Nine links broke because files moved in the working tree; each had a known
successor. Sources: `docs/00-status.md:167,187`,
`docs/stories/language-runtime-database/00-story.md:60,69`, the `25`/`26` story
pair (which used `../00-story.md` while `00-story.md` was a sibling — the
`refine/`-relative form pasted into files one level up), `refine/08-shard-actor-runtime.md:98,100`,
and `refine/20-cross-program-tables.md:143`. Link labels were renumbered with
their targets, since the old IDs contradicted the new paths: `9e`→`22` and
`9f`→`23`.
### Structural problems found alongside the links
1. **Iteration 19 was double-booked — RESOLVED.** `refine/19-chat-websocket-workload.md`
and `refine/24-chat-websocket-workload.md` were the same document while
`19-missing-scalar-types.md` also claimed 19. `00-story.md`'s mapping line `19-missing-scalar-types.md` also claimed 19. `00-story.md`'s mapping line
(`24←19(chat)`) and table row 20 make **24 canonical**, so the 19 copy was made **24** canonical, so the 19 copy was deleted after repointing
deleted. `refine/11-fibers.md:13` had been pointing at the 19 copy — repointed `refine/11-fibers.md:13` at 24.
to 24 first, so the delete broke nothing. Prose in `refine/08` that named 2. **`08-shard-actor-runtime.md` existed twice — RESOLVED.** 58 lines at the
"iteration 19" for chat now says 24 (4 places). stories root vs 110 in `refine/`. The `refine/` copy superseded it outright
(the root copy still required `@gc`, retired by 7b, and cited
2. **`08-shard-actor-runtime.md` existed twice — RESOLVED.** `runtime/wo-rt.c`, removed with the Rust runtime). Root copy deleted.
58 lines at the stories root vs 110 in `refine/`. The `refine/` copy supersedes
it outright: same acceptance criteria plus the 2026-08-20 settled decisions, the
inferred-GC restatement (7b retired `@gc`, which the root copy still required),
and the corrected substrate path (the root copy cited `runtime/wo-rt.c`, removed
with the Rust runtime). Root copy deleted; the one inbound link,
`docs/00-status.md:171`, now points at `refine/`. Six other referrers already did.
3. **Unresolved merge-conflict markers were committed** into 3. **Unresolved merge-conflict markers were committed** into
`refine/20-cross-program-tables.md:139-145` — `<<<<<<<< HEAD:… / ======== / `refine/20-cross-program-tables.md:139-145`, from a rename-conflicted merge —
>>>>>>>> language-surface-strictness:…/hold/09c-cross-program-tables.md`, from a which is what produced that file's broken `09d` link. Resolved in favour of
rename-conflicted merge. This is what produced that file's broken `09d` link: HEAD. `grep` confirmed no other conflict markers under `docs/`.
the stale side was still in the file. Resolved in favour of HEAD (the renumbered 4. **A status disagreement, not a link problem:** `docs/00-status.md:171` showed
`21` text). `grep` confirms no other conflict markers under `docs/`. iteration 8 as ⬜ while `00-story.md:68` recorded arc stages 1+2 as landed.
Both now read landed.
## Still open
- Sections B–F above: 88 broken links, all pre-existing.
- `docs/plan/discarded.md` and `docs/plan/learnings.md` are the only survivors of
the old flat plan layout, which is why B and C have no successor map. A rename
table in one of them would let the exploration docs be repaired mechanically
rather than by guesswork.
- `docs/00-status.md:171` still shows iteration 8 as ⬜ while `00-story.md:68`
records arc stages 1+2 as landed 2026-08-20. Not a link problem — a status
disagreement between the two index docs. Left alone.
- `refine/23-io-uring-commit.md:26` still quotes the old order as
"9e → 8+11 → 9f" in a dated note. No link involved; left as historical record.

View file

@ -68,17 +68,42 @@ binary embeds its own source, so prod is always self-describing.
events; a database that is also the app must not blink. events; a database that is also the app must not blink.
*Enforced by:* [the blue-green spec](superpowers/specs/2026-08-03-blue-green-vm-design.md). *Enforced by:* [the blue-green spec](superpowers/specs/2026-08-03-blue-green-vm-design.md).
## 7. RAM is authoritative; the WAL makes it durable ## 7. The log is authoritative; residency is a declared per-table policy
**Amended 2026-08-26.** This principle read "RAM is authoritative; the WAL
makes it durable. All reads serve from memory." The durability half was never
under strain and is unchanged. The residency half was false for a real
workload, so it is now a declaration rather than a law.
**Durability, unconditional:** every mutation is WAL-logged and fsynced before
acknowledgment; boot replays the log; a torn tail is dropped whole by CRC; an
ack means the commit reached disk. Mirrors (Postgres) are reconstructible
backups that reads and acks never depend on. None of this is per-table and
none of it is negotiable.
**Residency, declared:** what a table keeps in memory is stated at the
declaration site. The default keeps every row resident and serves reads at
memory speed. A table that cannot fit says so, and then only its indexes are
resident while rows are read from the log by offset — the kernel page cache is
the hot copy, which is why the engine uses `pread` and deliberately not
`O_DIRECT`.
*Why the amendment:* the original wording is right for a knowledge-management
app and simply false for a 120 GB order table on a 32 GB host. A doctrine a
real workload cannot satisfy does not get followed, it gets ignored — and the
failure it produced was an OOM kill, which is the least debuggable outcome
available. The fix keeps one storage engine and one source of truth: the log
*is* the database, and RAM is how much of it you choose to serve fast. What was
rejected in 2026-08-18 and stays rejected is a *second* engine — a paged
B-tree with its own buffer pool ([`plan/discarded.md`](plan/discarded.md)).
Reading rows from the log we already write is not that.
All reads serve from memory. Every mutation is WAL-logged and fsynced
before acknowledgment; boot replays the log. Mirrors (Postgres) are
reconstructible backups that reads and acks never depend on.
*Why:* one source of truth with predictable latency; durability is a
sequential append, not a storage engine bolted to the side.
*Enforced by:* [the db-engine binding plan](superpowers/plans/2026-08-01-db-engine-binding.md) *Enforced by:* [the db-engine binding plan](superpowers/plans/2026-08-01-db-engine-binding.md)
(typed WAL + boot replay, shipped); the mirror-is-backup doctrine is (typed WAL + boot replay, shipped); the residency declaration and its
recorded in [`plan/discarded.md`](plan/discarded.md) (the Rust-era WAL enforcement are [databasev2 2](stories/databasev2/02-table-storage-modes.md);
and mirror plans 11/16 were removed with that track 2026-08-18). the mirror-is-backup doctrine is recorded in
[`plan/discarded.md`](plan/discarded.md) (the Rust-era WAL and mirror plans
11/16 were removed with that track 2026-08-18).
## 8. Samples force the grammar ## 8. Samples force the grammar
@ -101,9 +126,10 @@ directly instead of the lowest common denominator.
## 10. Capabilities are typed builtins — no FFI ## 10. Capabilities are typed builtins — no FFI
Programs reach the system only through audited stdlib builtins (`fs`, Programs reach the system only through audited stdlib builtins — six
`proc`, `net`, `time`, `json`): bounded reads, args-array-only process reserved namespaces (`fs`, `proc`, `net`, `time`, `json`, `env`): bounded
runs, handles that close on drop. There is no `extern`, no escape hatch. reads, args-array-only process runs, handles that close on drop. There is
no `extern`, no escape hatch.
*Why:* one FFI hole voids the entire memory-safety and security story; *Why:* one FFI hole voids the entire memory-safety and security story;
typed capabilities make the safe path the only path. typed capabilities make the safe path the only path.
*Enforced by:* [the systems-track spec Parts 2–3](superpowers/specs/2026-08-01-systems-track-design.md). *Enforced by:* [the systems-track spec Parts 2–3](superpowers/specs/2026-08-01-systems-track-design.md).

View file

@ -16,18 +16,25 @@ project.
``` ```
writeonce-all/ writeonce-all/
├── compiler/ OCaml `woc` — lexer→parser→types→owner→emit; produces the compiler binary ├── compiler/ OCaml `woc` — lexer→parser→types→gcinfer→owner→emit; produces the compiler binary
├── runtime/ C `wovm` — the register VM that runs .wob images (src/); phase A–F C reference (wo-rt.c, bench/) ├── runtime/ C `wovm` — the register VM that runs .wob images (src/); retired io_uring reference (wo-rt.c, bench/)
├── database/ C embedded engine — class-shaped tables, secondary indexes, typed WAL + recovery ├── database/ C embedded engine — class-shaped tables, secondary indexes, typed WAL + recovery
├── tests/ corpus/ — conformance fixtures: run / compile-fail / trap / gc ├── tests/ corpus/ — conformance fixtures: run / compile-fail / trap / gc (+ five reserved, still empty)
├── scripts/ oop-e2e.sh (corpus runner), mkdist.sh / install-accept.sh (packaging), sample acceptance ├── scripts/ the corpus runner, packaging, linkcheck, and one acceptance script per sample
├── docs/ ALL documentation: numbered docs, stories/, plan/, examples/, superpowers/ ├── bench/ baseline.json (the db-bench gate's thresholds) + results/ + compare/ (Go+SQLite peer)
├── docs/ ALL documentation: numbered docs, stories/, plan/, examples/, guides/, superpowers/
├── dist/ `just dist` output: writeonce-<ver>-linux-amd64.tar.gz + .sha256
├── .github/ workflows/release.yml — builds, verifies and publishes on a `v*` tag push
├── .claude/ agents/ — project subagent definitions (see docs/guides/codd-subagent.md)
├── .dev/ gitignored per-developer links + reference study trees (v1 crates, colibri, llama-cpp) ├── .dev/ gitignored per-developer links + reference study trees (v1 crates, colibri, llama-cpp)
├── justfile task runner: woc-/wovm-build, the *-test gates, oop-accept, dist, install-accept ├── justfile task runner: woc-/wovm-build, the *-test gates, oop-accept, dist, install-accept
├── VERSION single-sourced toolchain version (stamped into woc/wovm; asserted by `just dist`) ├── VERSION single-sourced toolchain version (stamped into woc/wovm; asserted by `just dist`)
└── README.md the getting-started front door (also the writeonce.de landing content) └── README.md the getting-started front door (also the writeonce.de landing content)
``` ```
`target/` and `.vscode/` are local build and editor state, not part of the
project layout.
## Root directories in detail ## Root directories in detail
### `compiler/` — the OCaml `woc` compiler ### `compiler/` — the OCaml `woc` compiler
@ -36,13 +43,19 @@ writeonce-all/
compiler/ compiler/
├── dune-project ├── dune-project
├── README.md orientation: pipeline map, build/test commands ├── README.md orientation: pipeline map, build/test commands
├── plan/ compiler-track docs: architecture.md + the woc plans
├── src/ one module per stage: diag, token, lexer, ast, parser, ├── src/ one module per stage: diag, token, lexer, ast, parser,
│ types, owner, emit, disasm, dump │ types, gcinfer, owner, emit, disasm, dump
├── bin/main.ml the woc executable (check / --emit / build / version modes) ├── bin/main.ml the woc executable — check / build-from-manifest / --emit /
└── test/ golden runner + golden/ fixtures per stage │ build / version / --update-deps / the --dump-* modes / -D
└── test/ golden runner + golden/ fixtures per stage (tokens, ast,
owner, owner-err, bc) + fixtures/driver/ CLI-smoke cases
``` ```
The compiler-track plan docs live under
[`plan/compiler/`](plan/compiler/architecture.md) in this `docs/` tree, not
inside `compiler/` — the repo rule below applies to the compiler like everything
else.
Doctrine: OCaml stdlib only — no Menhir, no ppx, no opam libraries; handwritten Doctrine: OCaml stdlib only — no Menhir, no ppx, no opam libraries; handwritten
lexer and recursive-descent parser. Build: `just woc-build`; gate: lexer and recursive-descent parser. Build: `just woc-build`; gate:
`just woc-test`. Architecture map: `just woc-test`. Architecture map:
@ -73,22 +86,34 @@ compiler (`emit.ml`), lowered to engine builtins — no SQL text in the image.
### `tests/`, `scripts/` ### `tests/`, `scripts/`
- `tests/corpus/` — the conformance spine: `run/`, `compile-fail/`, `trap/`, - `tests/corpus/` — the conformance spine. Four directories carry fixtures:
`gc/`. Exact-outcome matching: byte-equal stdout, exact `WO-E###`, exact trap `run/` (60), `compile-fail/` (46), `trap/` (5), `gc/` (2). Five more —
code. Driven by `scripts/oop-e2e.sh` (`just oop-e2e`). `actor/`, `db/`, `lang/`, `sys/`, `sample-logwatcher/` — are reserved slots
- `scripts/` — `oop-e2e.sh` (corpus), `mkdist.sh` + `install-accept.sh` from the original plan and still **empty**; see
(tarball packaging), and the per-sample acceptance scripts [`tests/corpus/README.md`](../tests/corpus/README.md) for which plan each was
(`employee-accept.sh`, `log-watcher-accept.sh`). to be filled by. Exact-outcome matching: byte-equal stdout, exact `WO-E###`,
exact trap code. Driven by `scripts/oop-e2e.sh` (`just oop-e2e`).
- `scripts/` — the corpus runner (`oop-e2e.sh`) and
`single-binary-smoke.sh`; packaging (`mkdist.sh`, `install-accept.sh`); the
docs gate (`linkcheck.py`); the benchmark campaign (`db-bench.py`); and one
acceptance script per sample — `employee-accept.sh`, `log-watcher-accept.sh`,
`web-app-accept.sh`, `site-accept.sh`, `fibers-accept.sh`,
`db-actor-accept.sh`, `deps-accept.sh`.
### `docs/` — all documentation ### `docs/` — all documentation
``` ```
docs/ docs/
├── 00-*, 01-problem.md, 08-*.md status / principles / code-review / problem / structure ├── 00-*.md, 01-problem.md, 08-*.md principles / code-review / dependency-graph /
├── stories/ the canonical iteration arc (language-runtime-database/) │ link-audit / doc-audit / problem / structure
├── examples/ log-watcher/, employee/, employee-list/ samples ├── stories/ 00-status.md (the board) + board-views.md +
│ the canonical iteration arc (language-runtime-database/,
│ FLAT — status lives in each story's frontmatter)
├── active-slice-*.md the live slice's one marker doc, deleted when it lands
├── guides/ runbooks: releasing, language-surface, subagents
├── examples/ 13 sample projects, 8 of them wired to a `just` recipe
├── plan/ compiler/ plans, oop-vm/ contracts, exploration/ studies, ├── plan/ compiler/ plans, oop-vm/ contracts, exploration/ studies,
│ discarded.md + learnings.md registers │ perf-targets.md, discarded.md + learnings.md registers
└── superpowers/ specs/ (approved designs) + plans/ (implementation plans) └── superpowers/ specs/ (approved designs) + plans/ (implementation plans)
``` ```
@ -106,15 +131,25 @@ gates.
`just woc-build` + `just wovm-build` produce the two binaries; `just oop-accept` `just woc-build` + `just wovm-build` produce the two binaries; `just oop-accept`
runs the full milestone gate (compile-time budget, conformance corpus under runs the full milestone gate (compile-time budget, conformance corpus under
ASan, single-binary smoke, both unit gates). Sample acceptance: ASan, single-binary smoke, both unit gates). Sample acceptance: `just employee`
`just employee` (database), `just log-watcher` (systems stdlib). Packaging: (database), `just log-watcher` (systems stdlib), `just web-app` and `just site`
`just dist` → `writeonce-<ver>-linux-amd64.tar.gz`, proven by (the framework consumed through `[deps]`), `just fibers` and `just db-actor`
`just install-accept`. (the concurrency arc), `just deps-accept` (the package manager),
`just db-bench` / `db-bench-quick` (the benchmark campaign, gated against
`bench/baseline.json`). Docs gate: `just linkcheck`. Packaging: `just dist` →
`writeonce-<ver>-linux-amd64.tar.gz`, proven by `just install-accept`;
publishing is `.github/workflows/release.yml` on a `v*` tag
(see [`guides/releasing.md`](guides/releasing.md)).
## Naming conventions ## Naming conventions
- Binaries: `woc` (OCaml compiler), `wovm` (C VM); a `woc build` / `woc <dir>` - Binaries: `woc` (OCaml compiler), `wovm` (C VM); a `woc build` / `woc <dir>`
output is named by the project's `wo.toml`. output is named by the project's `wo.toml`.
- Story iterations: `<NN>-<topic>.md`, flat in
`docs/stories/language-runtime-database/`. **No directory encodes status**
(directive 2026-08-26) — each story's `status:` frontmatter key is the only
place state is recorded, so a status change is a one-line edit and never
moves a file or breaks a link.
- Plan/spec files: `YYYY-MM-DD-<topic>.md` under `docs/superpowers/{specs,plans}/`; - Plan/spec files: `YYYY-MM-DD-<topic>.md` under `docs/superpowers/{specs,plans}/`;
compiler plans under `docs/plan/compiler/`; normative contracts under compiler plans under `docs/plan/compiler/`; normative contracts under
`docs/plan/oop-vm/`. `docs/plan/oop-vm/`.

View file

@ -0,0 +1,93 @@
# Iteration 24 T9 — the drain bug the gate was hiding
**Found 2026-08-27** while finishing T8/T9 on branch `chat-ws-lifecycle`.
Not fixed: the fix is an engine-level decision, recorded here so it is not
rediscovered.
## The symptom
`just chat`'s drain leg asserts both connected clients receive a WebSocket
close frame on `SIGTERM`. Against a **fresh** server it is flaky:
| Sample | Result |
| --- | --- |
| 5 fresh servers, 2 clients each | 4 × `close\|close`, 1 × `eof\|close` |
| 12 fresh servers | 3 failures, one of them `eof\|eof` |
| 16 fresh servers | 5 failures |
A failing client's socket reaches EOF with **no close frame and no
diagnostic** — the process exits and the kernel closes the fd.
## Why the gate never caught it
The drain leg did not start its own server. It inherited `$SRV` from the soak
leg — a server the soak had already pushed 1000 clients through, so every
shard was warm and every actor already scheduled. Draining a warm server hides
the cold-start race. Fixed in this change: **every leg now starts its own
server**, which is what exposed the bug.
## Root cause, traced
Instrumented the sample's actors (diagnostics not committed) and correlated
against failing runs:
1. `DIAG registry-shutdown rooms=1` — main's `send(reg, kind: 2)` **is**
delivered and the Registry runs.
2. `DIAG room-shutdown` — **never printed on a failing run.** The Room never
processes the `kind: 4` shutdown the Registry sends it.
3. The Writer's close branch never runs for the affected client, so no close
frame is written and the fd is never closed by the Writer. Its
`try net.write_dl(...)` is **not** failing — a diagnostic on that path
printed zero times.
4. A client that *does* get a close frame is usually saved by its own
**Reader** noticing `env.stopping()` and running its tail
(`DIAG reader-tail bob r2=1`), not by the room broadcast.
So the drain chain is main → Registry → Room → Writer, three hops across
shards, and **the Room's shard does not reliably adopt its inbox before the
engine stops.**
## What was ruled out
- **Not the spin budget.** Replacing `spin < 20000000` with a wall-clock
deadline of 1 s (`time.ticks()`) still failed 2 of 12. More time does not
help, which is the strongest evidence the room's shard is not being
scheduled at all rather than being scheduled late. That change was reverted:
it fixed nothing and cost a fixed 1 s on every shutdown.
- **Not `dummy_writer()` spawning during shutdown.** Hoisting it to a
Registry field spawned once at startup left 5 of 16 failing.
- **Not a write failure.** See point 3.
## The decision this needs
`main` cannot park after the stop flag (a park unwinds), so it spins — and
spinning is not a barrier. Either:
- **the engine drains pending inboxes before stopping**, so a `send` issued
before the stop flag is guaranteed delivered; or
- **the sample gets a real barrier** — the drain is acknowledged back to main,
which requires main to observe a reply without parking.
The first is the honest fix and belongs to the actor lifecycle (iteration 31,
absorbed into 24). It is a semantic guarantee — "a send before shutdown is
delivered" — not a tuning parameter, and it should be stated in the runtime's
lifecycle docs and pinned by a corpus fixture, not left to a spin count.
## Gate defects fixed alongside (all committed)
1. **fd check was core-count dependent.** `fds_before + 8` read lazy per-shard
init as a leak: shards initialise on first fiber, each taking one
`io_uring` + one `eventfd`, capped at `nproc`. On a 20-core box the first
wave legitimately adds 18. Measured 26 → 44 after 20 clients, then **still
44 after 40 more**. Replaced with the invariant the check is actually for:
a second wave must not raise the count. Core-count independent, and it
catches a slow leak that any fixed slack would hide.
2. **A failed leg orphaned its server.** The drain leg's python died on
`int("")` when `$SRV` was empty, so the soak server was never killed and
its listener broke the *next* run's soak on the same port. `cleanup` now
kills every server a run started, matched on the run's unique temp dir.
3. **Two legs the plan requires were missing** — `WO_SHARDS=1` (the
single-shard control that says a failure is placement's fault) and
`WO_MAILBOX=8` (the drop-slow-member backpressure path). Both added, both
green. The mailbox leg manufactures a genuinely slow member by shrinking
its `SO_RCVBUF`, so it needs no sleeps.

View file

@ -0,0 +1,82 @@
# `docs/examples/chat` — how the sample is put together
Iteration 24's acceptance workload: rooms, presence and broadcast over
WebSocket, actors on fibers across shards, one binary, no broker. It exists to
*drive* the actor work, so nearly every shape here is chosen to exercise
something the runtime claims.
Gate: `just chat` (`scripts/chat-accept.sh`), which logs to `/tmp/chat.log` —
`tail -F` it while the gate runs.
## The actors
| Actor | Owns | Answers |
| --- | --- | --- |
| `Registry` | name → room map, a fallback room | a `call` returning the room's address; spawns rooms on demand |
| `Room` | its member list (writer address + name) | join, leave, a text line, shutdown |
| `Reader` | the read half of one connection | nothing — it loops on the fd and sends onward |
| `Writer` | the **fd**, and the write half | text, pong, close |
| `ConnWorker` | one accepted connection | runs the HTTP layer over that fd |
`Registry` is the first honest consumer of `call`: the handler runs on the
connection worker's shard, the registry lives wherever placement put it, and
the reply is a scalar — the room's address. That is the cross-shard `call`
proof the gate asserts, not a contrivance added for it.
## Two actors per connection, not one
One fd, two directions, and they block independently. A single actor would have
to be inside `read` to notice the client, and inside `write` to deliver a
broadcast — it cannot be in both, so a broadcast would stall behind a quiet
client's read. Splitting them buys three things:
1. **The `Writer` is the sole writer of that fd.** Frames can never interleave,
which for a framed protocol is a correctness property and not a nicety.
2. **The `Reader` may block as long as it likes.** It sits in `read_dl` with a
30 s idle deadline and nothing else is waiting on it.
3. **The `Writer`'s mailbox becomes the backpressure point.** A slow client
stops draining its socket, its `Writer` blocks in `write_dl`, its mailbox
fills, and the room's next broadcast to it raises a catchable `WO_T_ACTOR`.
The room catches that and drops the member. **This is the whole reason the
mailbox cap is fail-fast** — the room survives its slowest member, and the
gate's `WO_MAILBOX=8` leg proves the path fires rather than assuming it.
`Room.say` is written around that: it shifts every member, tries the send, and
keeps only the members whose send succeeded — a failed one is sent a close and
dropped. So fan-out and eviction are the same pass.
## Who owns the fd
The `Writer`. It closes it, in every branch: a failed write sets `dead` and
closes; a close message writes the close frame and closes. The `Reader` closes
the fd itself in exactly one case — when its `send_close` to the writer traps,
meaning the writer is unreachable and nobody else will. Without that the fd
would leak on a dead-writer path.
`Writer.dead` guards against a second close, which matters because two
independent paths can decide a connection is finished (the reader seeing EOF,
and the room broadcasting shutdown).
## Shutdown choreography
On `env.stopping()` the accept loop stops and `main` sends one message to the
`Registry`, which fans out to every room; each room shifts its members and
sends each `Writer` a close; each writer writes the close frame and closes the
fd. `main` then spins — it may **not** park, because a park after the stop flag
unwinds — and returns, which is what stops the engine.
Independently, every `Reader` notices `env.stopping()` at its loop head and
runs its tail: leave the room, close the writer.
Both paths exist and that is deliberate: the reader path covers a connection
whose room is already gone, the room path covers a reader parked in a read that
has not come back yet.
**This is where iteration 40 came from.** The room path used to be unreliable:
a `Room` whose shard was idle at `SIGTERM` never adopted the shutdown message,
because an idle worker abandoned its inbox on stop. Clients that still got a
close frame were being saved by the reader path alone — which is why the
failure looked random and why a warmed-up server hid it. The engine now
guarantees that a send issued before the stop flag is delivered, so both paths
work as written. Nothing in this file changed to fix it, and that is the point:
the sample was right and the runtime was not.

335
docs/examples/chat/main.wo Normal file
View file

@ -0,0 +1,335 @@
-- chat — iteration 24's acceptance workload. Rooms, presence and
-- broadcast over WebSocket: every connection is a reader actor (sole fd
-- reader) plus a writer actor (sole fd writer); rooms and the registry
-- are actors; delivery between them is ownership-moving sends, across
-- shards when placement lands them there. One binary, no broker.
--
-- CHAT_TOKEN is not needed — chat is open; the framework serves it
-- through [deps] exactly like web-app:
-- woc . && ./target/chat 8080
-- ws://127.0.0.1:8080/ws?room=lobby&name=alice
--
-- The actor split exists because an actor takes ONE message at a time:
-- a single per-connection actor blocked in net read could never hear a
-- broadcast. The reader owns the socket's inbound half and the carry
-- buffer; the writer owns the outbound half so frames never interleave.
use env
use net
use time
use porch
use porch/http
use porch/router
-- ---- message types (one per actor) --------------------------------------
-- To a writer: 1 = text frame, 2 = close (frame + fd close), 3 = pong.
class WriterMsg {
kind: Int
text: Text
}
-- To a room: 1 = join, 2 = leave, 3 = text, 4 = shutdown (drain).
class RoomMsg {
kind: Int
name: Text
text: Text
writer: actor WriterMsg
}
-- To the registry: 1 = lookup (a `call` — the reply is the room's
-- address), 2 = shutdown every room (a `send` on SIGTERM).
class Lookup {
kind: Int
room: Text
}
-- To a reader: everything the connection's inbound loop needs.
class ReaderMsg {
fd: net.Conn
room: actor RoomMsg
writer: actor WriterMsg
name: Text
}
-- One connection accepted, one worker: builds its own App and runs the
-- framework's keep-alive loop (the serving-slice pattern).
class Conn {
fd: net.Conn
}
-- ---- the writer: sole owner of the outbound half -------------------------
class Writer {
fd: net.Conn
dead: Int
fn receive(msg: WriterMsg) {
if self.dead == 1 { return; }
if msg.kind == 1 {
let ok = try net.write_dl(self.fd, ws_text(msg.text), 2000) catch (e) false;
if ok == false {
-- a stalled or gone client: tear the fd; the reader will see EOF
-- and route the leave through the room
self.dead = 1;
net.close(self.fd);
}
return;
}
if msg.kind == 3 {
let ok2 = try net.write_dl(self.fd, ws_pong(msg.text), 2000) catch (e) false;
if ok2 == false {
self.dead = 1;
net.close(self.fd);
}
return;
}
-- close: the drain path (room shutdown or reader-detected close)
self.dead = 1;
let ig = try net.write_dl(self.fd, ws_close(), 1000) catch (e) false;
net.close(self.fd);
}
}
-- ---- the room: members, presence, fan-out --------------------------------
class Mem {
w: actor WriterMsg
name: Text
}
class Room {
members: multi Mem
fn receive(msg: RoomMsg) {
if msg.kind == 1 {
push(self.members, Mem { w: msg.writer, name: "${msg.name}" });
self.say("* ${msg.name} joined");
return;
}
if msg.kind == 2 {
let keep: multi Mem = [];
while len(self.members) > 0 {
let m = shift(self.members);
if m.name != msg.name { push(keep, m); }
}
self.members = keep;
self.say("* ${msg.name} left");
return;
}
if msg.kind == 3 {
self.say("${msg.name}: ${msg.text}");
return;
}
-- shutdown: every member gets a close frame; the list empties
while len(self.members) > 0 {
let m = shift(self.members);
let r = try send_close(m.w) catch (e) 0;
}
}
-- fan-out one line; a member whose mailbox is FULL is a slow client —
-- the fail-fast cap turns it into a drop-from-the-room (the backpressure
-- policy earning its keep)
fn say(line: Text) {
let keep: multi Mem = [];
while len(self.members) > 0 {
let m = shift(self.members);
let ok = try send_text(m.w, "${line}") catch (e) 0;
if ok == 1 {
push(keep, m);
} else {
let r = try send_close(m.w) catch (e) 0;
}
}
self.members = keep;
}
}
-- send wrappers: `try` is an expression, so give it Int results
fn send_text(w: actor WriterMsg, line: Text) -> Int {
send(w, WriterMsg { kind: 1, text: line });
return 1;
}
fn send_close(w: actor WriterMsg) -> Int {
send(w, WriterMsg { kind: 2, text: "" });
return 1;
}
-- ---- the registry: name -> room, spawn on demand --------------------------
class RoomRef {
r: actor RoomMsg
}
class Registry {
rooms: map<Text, RoomRef>
fallback: actor RoomMsg
fn receive(msg: Lookup) -> actor RoomMsg {
if msg.kind == 2 {
for k, v in self.rooms {
send(v.r, RoomMsg { kind: 4, name: "", text: "", writer: dummy_writer() });
}
return self.fallback;
}
if has(self.rooms, msg.room) == 1 {
let have = self.rooms[msg.room];
if have != nil {
return have.r;
}
}
let room: actor RoomMsg = spawn Room { members: [] };
self.rooms[msg.room] = RoomRef { r: room };
return room;
}
}
-- RoomMsg requires a writer field on every construction; the shutdown
-- message has no meaningful one, so a throwaway satisfies the shape (it
-- never receives anything — kind 4 reads no fields).
fn dummy_writer() -> actor WriterMsg {
let w: actor WriterMsg = spawn Writer { fd: 0 - 1, dead: 1 };
return w;
}
-- ---- the reader: sole owner of the inbound half ---------------------------
class Reader {
pad: Int
fn receive(msg: ReaderMsg) {
let carry = "";
let alive = true;
while alive {
if env.stopping() { alive = false; continue; }
let got = try net.read_dl(msg.fd, 4096, 30000) catch (e) nil;
if got == nil {
-- idle deadline or I/O trap: this client is done
alive = false;
continue;
}
let bytes = "${got}";
if len(bytes) == 0 {
alive = false;
continue;
}
carry = carry .. bytes;
let more = true;
while more {
let f = ws_parse(carry);
if f.kind == 0 {
more = false;
continue;
}
carry = f.rest;
if f.kind == 1 {
send(msg.room, RoomMsg { kind: 3, name: "${msg.name}", text: f.payload, writer: msg.writer });
continue;
}
if f.kind == 9 {
send(msg.writer, WriterMsg { kind: 3, text: f.payload });
continue;
}
if f.kind == 10 or f.kind == 2 {
continue; -- pongs ignored; binary tolerated (echo is not chat)
}
-- close frame or protocol error: stop reading
alive = false;
more = false;
}
}
-- the tail sends must survive full mailboxes (a leave storm after a
-- mass close): a trap here would kill the reader and orphan the fd
let r1 = try send_leave(msg.room, "${msg.name}", msg.writer) catch (e) 0;
let r2 = try send_close(msg.writer) catch (e) 0;
if r2 == 0 {
-- the writer is unreachable (full/dead): close the fd ourselves
net.close(msg.fd);
}
}
}
fn send_leave(room: actor RoomMsg, name: Text, w: actor WriterMsg) -> Int {
send(room, RoomMsg { kind: 2, name: name, text: "", writer: w });
return 1;
}
-- ---- HTTP: the upgrade route + usage --------------------------------------
class WsRoute {
reg: actor Lookup
fn handle(req: Req) -> Resp {
if ws_upgrade_valid(req) == false {
return bad_request("expected a websocket upgrade");
}
let rname = req.query["room"];
if rname == nil { return bad_request("expected ?room=<name>&name=<who>"); }
let who = req.query["name"];
if who == nil { return bad_request("expected ?room=<name>&name=<who>"); }
-- the cross-shard call: this handler runs on the connection worker's
-- shard, the registry lives wherever placement put it
let room = call(self.reg, Lookup { kind: 1, room: "${rname}" });
let fd = ws_accept(req);
let w: actor WriterMsg = spawn Writer { fd: fd, dead: 0 };
let rd: actor ReaderMsg = spawn Reader { pad: 0 };
send(room, RoomMsg { kind: 1, name: "${who}", text: "", writer: w });
send(rd, ReaderMsg { fd: fd, room: room, writer: w, name: "${who}" });
return hijacked();
}
}
class Usage {
pad: Int
fn handle(req: Req) -> Resp {
return ok_json("{\"ws\":\"/ws?room=<name>&name=<who>\"}");
}
}
fn build_app(reg: actor Lookup) -> App {
let app = App { middleware: [], routes: [] };
app.get("/", Usage { pad: 0 });
app.get("/ws", WsRoute { reg: reg });
return app;
}
class ConnWorker {
reg: actor Lookup
fn receive(msg: Conn) {
let app = build_app(self.reg);
app.handle_conn(msg.fd, 10000, 10000);
}
}
fn main(args: multi Text) -> Int {
if len(args) < 1 {
print_err("usage: chat <port>");
return 2;
}
let port = parse_int(args[0]);
if port == nil {
print_err("chat: <port> must be a number");
return 2;
}
let fb: actor RoomMsg = spawn Room { members: [] };
let reg: actor Lookup = spawn Registry { rooms: {}, fallback: fb };
let srv = net.listen("127.0.0.1", port);
print("listening on 127.0.0.1:${port}");
while true {
if env.stopping() {
-- the drain: every room broadcasts a close frame and writers flush.
-- main must NOT park here (a park after the stop flag unwinds), so
-- it SPINS — each loop back-edge pays a reduction, and the budget
-- hands the shard to the draining actors between slices; worker
-- shards keep adopting their inboxes until the engine stops.
send(reg, Lookup { kind: 2, room: "" });
let spin = 0;
while spin < 20000000 {
spin = spin + 1;
}
net.close(srv);
return 0;
}
let c = net.accept_dl(srv, 250);
if c != nil {
let w: actor Conn = spawn ConnWorker { reg: reg };
send(w, Conn { fd: c });
}
}
}

View file

@ -0,0 +1,9 @@
name = "chat"
version = "0.1.0"
description = "Iteration 24's acceptance workload: rooms + presence + broadcast over WebSocket — actors on fibers across shards, one binary, no broker"
[runtime]
wo = ">= 0.1"
[deps]
porch = { git = "https://github.com/shoneyj/porch", rev = "v0.1.0" }

View file

@ -0,0 +1,63 @@
# `db-actor` — the database reached from any shard
> **Status: shipped — arc stage 3's acceptance gate.** Run it with
> `just db-actor`. Landed 2026-08-21 with the shard-fiber arc
> ([story 8](../../stories/language-runtime-database/08-shard-actor-runtime.md)
> · [plan](../../superpowers/plans/2026-08-20-shard-fiber-arc.md)).
The database lives on **one** shard — the owner, shard 0 — because RAM is
authoritative and a single writer is what makes the WAL's ordering meaningful.
That is a problem the moment actors are placed round-robin across cores: a
`spawn`ed actor has no say in which shard it lands on, and before stage 3 a
worker-shard `insert` trapped `WO_T_DB` with "database engine not initialized".
Stage 3's answer is a **transparent DB actor**: statements issued off the owner
shard marshal to it, execute there, and materialize their replies back. The
program's source says nothing about any of it — the same `insert` and the same
`from … select` work wherever the actor happens to run. This sample exists to
prove exactly that, which is why its acceptance criterion is *placement
independence* rather than any particular output.
## What it does
`Note` is a `@table` with a secondary index on `tag`. `Writer` is an actor: each
one inserts a row, then scans the whole table and prints the sum it sees. `main`
spawns two writers, waits, then scans once itself.
With the default shard count, round-robin placement puts at least one writer off
the owner shard — so one of those inserts and one of those scans travel the RPC
path under test, and the other does not. Both must produce the same shape.
```bash
just db-actor # the gate
woc docs/examples/db-actor/ # or build it by hand
WO_SHARDS=1 ./docs/examples/db-actor/target/db-actor # force the local path
```
## What the gate proves
`scripts/db-actor-accept.sh`, 8 checks:
| Check | Why it is shaped that way |
| --- | --- |
| multi-shard, three rounds | The writer lines are asserted as a **set**, not a sequence — scheduling decides their order, and pinning it would be testing the scheduler, not the RPC. The `main` line is exact. |
| both `WO_IO` backends forced | The reply park has to be plane-independent: io_uring and epoll must give the same answer, or the parking is leaking into semantics. |
| single shard, byte-exact | The local path is untouched by stage 3. Any drift here means the RPC changed the non-RPC case. |
| `WO_DATA` restart pair | A worker's insert must commit on the **owner's** WAL before its ack, so a restart replays it: 2 rows, then 2+2 after a second run. This is the durability claim the RPC could most easily break. A program with any durable table (the default) refuses to start without `WO_DATA`; `WO_EPHEMERAL=1` opts into a RAM-only run, `@table(durable: false)` opts a table out. |
Run under `wovm_asan` and `wovm_tsan` as well — cross-shard message passing is
exactly where a data race would hide, and TSan covering this demo is the one
place it runs.
## Read it for
- **How little the source knows.** Compare `Writer.receive` here against the
same statements in [`employee`](../employee/): identical. Transparency is the
feature.
- **Why `main` waits.** `main` is not an actor and has no mailbox, so it sleeps
rather than awaiting — the gap iteration 31's `call` closes for actors and
[iteration 24](../../stories/language-runtime-database/24-chat-websocket-workload.md)
landed 2026-08-27.
Reasoning under the engine side: [`database/src/CODE-LOGIC.md`](../../../database/src/CODE-LOGIC.md).
Contract: [`plan/oop-vm/04-db-binding.md`](../../plan/oop-vm/04-db-binding.md).

View file

@ -24,9 +24,28 @@ strictly better. Recorded as a plan deviation.)
| `query N` | full equality probes on the k index (≈10 rows each), materialized and counted. | | `query N` | full equality probes on the k index (≈10 rows each), materialized and counted. |
| `write N` | alternating inserts (disjoint k range 2e6+) and updates through query results. Corrupts the checksum by design — durability legs run on a fresh store. | | `write N` | alternating inserts (disjoint k range 2e6+) and updates through query results. Corrupts the checksum by design — durability legs run on a fresh store. |
| `wal N` | the crash battery's vehicle: insert-only (k range 1e6+), `acked <i>` printed AFTER each insert returns — the return IS the ack (RAM applied, WAL record staged, ONE commit done). | | `wal N` | the crash battery's vehicle: insert-only (k range 1e6+), `acked <i>` printed AFTER each insert returns — the return IS the ack (RAM applied, WAL record staged, ONE commit done). |
| `wmix N C` | **databasev2 4:** every op a durable write (update through a query result), C at once. Exists because `mix` writes on one op in ten with C=4 — 20 writes in a quick run, measured mean batch **1.01** — so no existing leg could show whether group commit engages. Histogram kind 2, because a replayed store still holds the seeding run's kind-0/1 `Hist` rows. Seed first. |
| `boot` | **databasev2 3:** does NOTHING. With `WO_DATA` set the runtime replays the whole log before `main` runs, so a mode with no work of its own is the only honest way to price boot |
| `verify` | store vs its own Meta rows: count, checksum, one unique probe. Exit 3 on mismatch. | | `verify` | store vs its own Meta rows: count, checksum, one unique probe. Exit 3 on mismatch. |
| `verify-acked M` | after kill -9 mid-`wal`: rows 1..M exist with the right v; rows beyond M allowed (acked after the last print flushed). Exit 3 on mismatch. | | `verify-acked M` | after kill -9 mid-`wal`: rows 1..M exist with the right v; rows beyond M allowed (acked after the last print flushed). Exit 3 on mismatch. |
## Env knobs
| var | effect |
| --- | --- |
| `WO_DATA=<dir>` (or `WO_DATA=<path>.db`, below) | durability on: replay `<dir>/shard-0.wal` at boot, log every write. A program with any durable table (the default) refuses to start without `WO_DATA`; `WO_EPHEMERAL=1` opts into a RAM-only run, `@table(durable: false)` opts a table out. |
| `WO_EPHEMERAL=1` | **databasev2 2 task 6a:** the RAM-only opt-in the driver sets on its ram/msgrate/growth/randread legs. A `WO_DATA` exported in your shell no longer silently turns those legs durable — the two are incompatible and the run refuses loudly |
| `WO_SHARDS=<n>` | shard count. **`1` means every statement runs inline on shard 0 and group commit cannot engage** — batches form only where writes queue from other shards |
| `WO_CHECKPOINT_BYTES` / `WO_CHECKPOINT_RATIO` | **databasev2 3:** the checkpoint trigger — the log must exceed the floor AND exceed the ratio times the last compaction's own size. A tiny floor forces compaction in a few writes, which is how the gate tests the policy at all; an enormous one disables it, which is how the checkpoint leg measures the same workload with and without |
| `WO_WAL_STATS=1` | **databasev2 4:** print one line at exit — `walstats batches=… records=… peak_batch=… peak_staged=… compactions=… compact_us_max=… compact_us_total=… compacted_bytes=…`. Opt-in so it does not pollute every durable program's output. Mean batch is `records/batches`; **mean 1.0 means group commit is not engaging**, which is expected for a serial writer or `WO_SHARDS=1` and a bug anywhere else |
| `WO_DATA=<path>.db` | **databasev2 7:** the store as ONE file — the path IS the log (created if absent, its parent must exist; a directory or trailing `/` keeps the `<dir>/shard-0.wal` form). `scripts/db-bench.py --wo-data-file` runs the restart proof and the kill -9 battery against `<tmp>/app.db` instead of a directory; same acceptance, no metric, baseline untouched |
**Do not put `WO_DATA` on `/tmp`.** It is `tmpfs` on the reference machine,
where `fdatasync` is free: the same `wmix` run measured **195 000 ops/s at p50
1 µs** there against **2200 ops/s at p50 7200 µs** on ext4. There is no
durability barrier to price on a memory filesystem. The driver keeps its stores
under `bench/` for exactly this reason.
## Coordination idiom (this side of iteration 31) ## Coordination idiom (this side of iteration 31)
There is no request/response surface yet: concurrent modes drive There is no request/response surface yet: concurrent modes drive

View file

@ -1,3 +1,4 @@
use fs
use time use time
-- db-bench — iteration 22's load generator. Every measured mode prints -- db-bench — iteration 22's load generator. Every measured mode prints
@ -337,6 +338,91 @@ class Mixer {
} }
} }
-- databasev2 4 part A: every op a durable write, C at once.
--
-- Why this leg exists. `mix` writes on one op in ten with C=4, so at most a
-- handful of writes are ever in flight and group commit has almost nothing to
-- batch: measured mean batch 1.01 over 3112 barriers, peak 3. That is a
-- property of the WORKLOAD, not of the mechanism, and without a write-
-- concurrent leg the iteration's payoff cannot be evaluated either way.
--
-- Updates rather than inserts: comparable to what `mixwrite` measures, and the
-- row count stays flat so a long run does not turn into a growth test.
-- Histogram kind 2, because a replayed store still holds the seeding run's
-- kind-0/1 Hist rows and merging those would report someone else's latencies.
class WJob {
ops: Int
seed: Int
kmod: Int
}
class WMixer {
id: Int
fn receive(msg: WJob) {
let hw: map<Int, Int> = {};
let s = msg.seed;
let i = 0;
while i < msg.ops {
s = lcg(s);
let key = s % msg.kmod;
let o0 = time.ticks();
for r in from x in Item where x.k == key take 1 select x {
r.v = r.v + 1;
}
hist_add(hw, time.ticks() - o0);
i = i + 1;
}
hist_dump(hw, 2);
insert Meta { tag: "wmixdone${self.id}", val: msg.ops };
}
}
fn wmix_mode(total: Int, c: Int) -> Int {
let kmod = meta_val("kmod");
if kmod < 1 {
print_err("wmix: seed first");
return 1;
}
let per = total / c;
if per < 1 {
per = 1;
}
let wall0 = time.ticks();
let i = 0;
while i < c {
let a: actor WJob = spawn WMixer { id: i };
send(a, WJob { ops: per, seed: 4242 + i * 7919, kmod: kmod });
i = i + 1;
}
let done = 0;
while done < c {
time.sleep(20);
done = 0;
i = 0;
while i < c {
if meta_val("wmixdone${i}") >= 0 {
done = done + 1;
}
i = i + 1;
}
}
let wall = time.ticks() - wall0;
let hw: map<Int, Int> = {};
let nw = 0;
for x in from x in Hist select x {
if x.kind == 2 {
if has(hw, x.b) {
set(hw, x.b, get(hw, x.b) + x.c);
} else {
set(hw, x.b, x.c);
}
nw = nw + x.c;
}
}
report("wmix", nw, wall, hw);
return 0;
}
fn mix_mode(total: Int, c: Int) -> Int { fn mix_mode(total: Int, c: Int) -> Int {
let kmod = meta_val("kmod"); let kmod = meta_val("kmod");
if kmod < 1 { if kmod < 1 {
@ -465,10 +551,213 @@ fn all_mode(n: Int) -> Int {
fn usage() -> Int { fn usage() -> Int {
print_err("usage: db-bench <mode>"); print_err("usage: db-bench <mode>");
print_err(" all N | seed N | read N | query N | write N | wal N"); print_err(" all N | seed N | read N | query N | write N | wal N");
print_err(" mix N C | msgrate N | verify | verify-acked M"); print_err(" mix N C | wmix N C | msgrate N | growth N int|text | growth-verify");
print_err(" randread N R | replayseed N M | boot");
print_err(" verify | verify-acked M");
return 2; return 2;
} }
-- databasev2 1: the process's own resident size, in KiB. Read here rather
-- than sampled by the driver because the driver polls /proc every 250 ms and
-- would miss the value AT a decile boundary; per-row footprint is the headline
-- number of this iteration and deserves an exact reading, not a nearby one.
-- Absence is nil by stdlib convention, so a kernel without VmRSS reports 0
-- and the driver treats the leg as unavailable rather than as zero growth.
fn self_rss_kb() -> Int {
let st = try fs.read_all("/proc/self/status", 16384) catch (e) "";
let i = index_of(st, "VmRSS:");
if i < 0 {
return 0;
}
let rest = substr(st, i + 6, 24);
let n = 0;
let j = 0;
while j < len(rest) {
let c = byte_at(rest, j);
if c >= 48 and c <= 57 {
n = n * 10 + (c - 48);
} else {
if n > 0 {
return n;
}
}
j = j + 1;
}
return n;
}
-- databasev2 1: growth N SHAPE — insert N rows of one reference shape,
-- sampling read latency as the table grows so the driver can plot the CURVE
-- rather than two endpoints. Reports one metric line per decile so the point
-- at which p99 leaves its baseline is a MEASURED sample, not an estimate.
--
-- SHAPE is "int" (Item: two Ints plus a ref, all inline slot words) or "text"
-- (Wide: three Text columns, each a separate db_text allocation on top of the
-- slab slot). Per-row footprint differs by an order of magnitude between them,
-- which is exactly why the driver reports the two separately and never a single
-- "bytes per row".
--
-- The memory CAP is the driver's job (systemd-run --user --scope), not this
-- program's: the sample just grows and reports, so the same binary serves the
-- swap-off and swap-on legs unchanged.
-- after the process is OOM-killed mid-insert, the durable prefix must be
-- intact: rows 1..M all present with the right v and no holes. M is whatever
-- survived -- the claim under test is the SHAPE of the survivor, not its size,
-- because a SIGKILL can land between any two inserts.
-- databasev2 1: randread N R -- fill N rows, then read R of them by key in a
-- Weyl-sequence order that spreads across the WHOLE range. Under a cap smaller
-- than the table most of those reads must fault a page back in.
--
-- This is the leg the swap measurement was MISSING. `growth` inserts, and
-- inserting is append-mostly: cold pages are written once and never re-read, so
-- swap cost it ~1% (148s vs 150s uncapped). Random reads over an oversized
-- table are the opposite access pattern -- and they are exactly what
-- databasev2 2's `resident: keys` creates, since it reads rows back from a log
-- larger than RAM. No RNG in the language and none needed: i*2654435761 mod n
-- is a Weyl sequence, deterministic and spread, so the two legs read the SAME
-- key order and only residency differs.
-- databasev2 1, for iteration 3: the replay "before".
--
-- `boot` does NOTHING. That is the point: with WO_DATA set the runtime replays
-- the whole WAL before main runs, so the process's wall time IS the replay cost
-- plus a fixed startup. Any mode that touches rows would mix its own work into
-- the number.
fn boot_mode() -> Int {
print("booted");
return 0;
}
-- Build a store with N live rows and N+M total WAL records: M updates on top of
-- N inserts. The live dataset is IDENTICAL for any M -- only the history grows.
-- That is iteration 3's whole case: with no checkpoint, boot replays HISTORY,
-- not data, so a long-lived row that has been updated a thousand times costs a
-- thousand records at every boot forever.
fn replayseed_mode(n: Int, m: Int) -> Int {
let bref = insert Bucket { tag: "replay" };
let i = 1;
while i <= n {
insert Item { k: i, v: item_v(i), bucket: bref };
i = i + 1;
}
let j = 0;
while j < m {
let key = 1 + (j * 2654435761) % n;
for r in from x in Item where x.k == key take 1 select x {
r.v = r.v + 1;
}
j = j + 1;
}
print("replayseeded ${n} ${m}");
return 0;
}
fn randread_mode(n: Int, r: Int) -> Int {
let bref = insert Bucket { tag: "randread" };
let i = 1;
while i <= n {
insert Item { k: i, v: item_v(i), bucket: bref };
i = i + 1;
}
print("randreadfilled ${n} ${self_rss_kb()}");
let h: map<Int, Int> = {};
let hits = 0;
let t0 = time.ticks();
let j = 0;
while j < r {
let key = 1 + (j * 2654435761) % n;
let o0 = time.ticks();
for row in from x in Item where x.k == key take 1 select x {
if row.v == item_v(key) {
hits = hits + 1;
}
}
hist_add(h, time.ticks() - o0);
j = j + 1;
}
let el = time.ticks() - t0;
report("randread", r, el, h);
-- hits proves the reads RESOLVED; a collapse measured over misses is noise
print("randreadrss ${self_rss_kb()} ${hits}");
return 0;
}
fn growth_verify() -> Int {
let seen: map<Int, Int> = {};
let maxk = 0;
for r in from x in Item select x {
set(seen, r.k, r.v);
if r.k > maxk {
maxk = r.k;
}
}
let i = 1;
while i <= maxk {
if has(seen, i) == false {
print_err("growth-verify: hole at ${i} below max ${maxk}");
return 3;
}
if get(seen, i) != item_v(i) {
print_err("growth-verify: row ${i} v ${get(seen, i)} != ${item_v(i)}");
return 3;
}
i = i + 1;
}
print("growthverify ${maxk}");
return 0;
}
fn growth_mode(n: Int, shape: Text) -> Int {
let wide = shape == "text";
if wide == false and shape != "int" {
print_err("db-bench: growth SHAPE must be `int` or `text`");
return 2;
}
let step = n / 10;
if step < 1 {
step = 1;
}
let bref = insert Bucket { tag: "growth" };
let pad = "0123456789abcdef0123456789abcdef";
let i = 1;
while i <= n {
if wide {
insert Wide { k: i, a: "a${i}${pad}", b: "b${i}${pad}", note: "n${i}${pad}${pad}" };
} else {
insert Item { k: i, v: item_v(i), bucket: bref };
}
-- at each decile, sample the read path against what is resident NOW
if i % step == 0 {
let h: map<Int, Int> = {};
let probes = 200;
let pt0 = time.ticks();
let j = 0;
while j < probes {
let key = 1 + (j * step) % i;
let o0 = time.ticks();
if wide {
for r in from x in Wide where x.k == key take 1 select x {
hist_add(h, time.ticks() - o0);
}
} else {
for r in from x in Item where x.k == key take 1 select x {
hist_add(h, time.ticks() - o0);
}
}
j = j + 1;
}
let pel = time.ticks() - pt0;
-- op name carries the decile so the driver keys each sample distinctly
report("growth${i / step}", probes, pel, h);
-- rows and resident KiB at this decile: the driver divides to get the
-- per-row footprint for THIS shape
print("growthrss ${i / step} ${i} ${self_rss_kb()}");
}
i = i + 1;
}
print("growthdone ${n}");
return 0;
}
fn main(args: multi Text) -> Int { fn main(args: multi Text) -> Int {
if len(args) < 1 { if len(args) < 1 {
return usage(); return usage();
@ -476,6 +765,16 @@ fn main(args: multi Text) -> Int {
if args[0] == "verify" { if args[0] == "verify" {
return verify(); return verify();
} }
if args[0] == "growth-verify" {
return growth_verify();
}
-- Does NOTHING. With WO_DATA set the runtime replays the whole log before
-- main runs, so a mode with no work of its own measures replay plus a fixed
-- process start — which is what "boot time" has to mean. Both databasev2 1
-- (replay baseline) and databasev2 3 (checkpoint boot) price boot with it.
if args[0] == "boot" {
return boot_mode();
}
if len(args) < 2 { if len(args) < 2 {
return usage(); return usage();
} }
@ -508,6 +807,45 @@ fn main(args: multi Text) -> Int {
if args[0] == "msgrate" { if args[0] == "msgrate" {
return msgrate_mode(n); return msgrate_mode(n);
} }
if args[0] == "growth" {
if len(args) < 3 {
return usage();
}
return growth_mode(n, args[2]);
}
if args[0] == "replayseed" {
if len(args) < 3 {
return usage();
}
let mm = parse_int(args[2]);
if mm == nil or mm < 0 {
print_err("db-bench: <m> must be zero or more");
return 2;
}
return replayseed_mode(n, mm);
}
if args[0] == "randread" {
if len(args) < 3 {
return usage();
}
let rr = parse_int(args[2]);
if rr == nil or rr < 1 {
print_err("db-bench: <r> must be a positive number");
return 2;
}
return randread_mode(n, rr);
}
if args[0] == "wmix" {
if len(args) < 3 {
return usage();
}
let wc = parse_int(args[2]);
if wc == nil or wc < 1 {
print_err("db-bench: <c> must be a positive number");
return 2;
}
return wmix_mode(n, wc);
}
if args[0] == "mix" { if args[0] == "mix" {
if len(args) < 3 { if len(args) < 3 {
return usage(); return usage();

View file

@ -23,6 +23,20 @@ class Meta {
val: Int val: Int
} }
-- databasev2 1: the TEXT-HEAVY reference shape. `Item` above is the Int-only
-- reference as it stands (two Ints plus a ref, all inline slot words), so this
-- is its counterpart: every row drags a separate db_text allocation per Text
-- column on top of its slab slot. Per-row footprint differs by an order of
-- magnitude between the two, which is why a single "bytes per row" number is
-- meaningless and the growth mode reports the two shapes separately.
@table(name: "wide", index: [k])
class Wide {
k: Int
a: Text
b: Text
note: Text
}
-- mix actors dump their per-op histograms here (kind 0 = read, -- mix actors dump their per-op histograms here (kind 0 = read,
-- 1 = write); main scans and merges — exact aggregate percentiles, -- 1 = write); main scans and merges — exact aggregate percentiles,
-- and the merge itself dogfoods the store. -- and the merge itself dogfoods the store.

View file

@ -2,8 +2,8 @@
> **Status: target workload — does not compile on today's toolchain.** > **Status: target workload — does not compile on today's toolchain.**
> Written ahead of iterations > Written ahead of iterations
> [20 (cross-program tables)](../../stories/language-runtime-database/refine/20-cross-program-tables.md) > [9 (cross-program tables)](../../stories/databasev2/09-cross-program-tables.md)
> and [21 (keypair attach auth)](../../stories/language-runtime-database/refine/21-keypair-attach-auth.md), > and [10 (keypair attach auth)](../../stories/databasev2/10-keypair-attach-auth.md),
> the way every acceptance sample here precedes its features. It also leans > the way every acceptance sample here precedes its features. It also leans
> on 9/9b (the [employee sample](../employee/) it attaches to must run > on 9/9b (the [employee sample](../employee/) it attaches to must run
> first). > first).
@ -30,6 +30,11 @@ and pasted — the `PASTE-…-HERE` placeholders mark exactly where. The
connect-section name is the code's namespace: `[connect.employee]` is why connect-section name is the code's namespace: `[connect.employee]` is why
the source says `employee.Employee`. the source says `employee.Employee`.
B declares the shapes but stores nothing, so it runs under `WO_EPHEMERAL=1`: a
program with any durable table (the default) refuses to start without
`WO_DATA`; `WO_EPHEMERAL=1` opts into a RAM-only run, `@table(durable: false)`
opts a table out.
| Mode | What it proves | | Mode | What it proves |
| --- | --- | | --- | --- |
| `employee-list list` | typed reads over the wire, `e.dept.name` ref navigation executing inside A | | `employee-list list` | typed reads over the wire, `e.dept.name` ref navigation executing inside A |

View file

@ -1,14 +1,16 @@
# employee — the database track's acceptance workload # employee — the database track's acceptance workload
> **Status: target workload — does not compile on today's toolchain.** > **Status: shipped — this is the database track's acceptance gate.** Run it
> This sample is written *ahead of* the features it exercises, exactly as > with `just employee`. The sample was written *ahead of* the features it
> log-watcher was written ahead of iterations 5–7: the sample is the test, > exercises, exactly as log-watcher was written ahead of iterations 5–7: the
> and the plans compile toward it. It becomes buildable when iteration 9 > sample is the test, and the plans compiled toward it. Both landed — iteration
> (engine: [`2026-08-01-db-engine-binding.md`](../../superpowers/plans/2026-08-01-db-engine-binding.md)) > 9 (engine: [`2026-08-01-db-engine-binding.md`](../../superpowers/plans/2026-08-01-db-engine-binding.md))
> and iteration 9b (query surface: > and iteration 9b (query surface:
> [`2026-08-15-employee-relations-query.md`](../../plan/compiler/2026-08-15-employee-relations-query.md)) > [`2026-08-15-employee-relations-query.md`](../../plan/compiler/2026-08-15-employee-relations-query.md)).
> land. Normative semantics: > Normative semantics:
> [the 9b spec](../../superpowers/specs/2026-08-15-table-relations-query-design.md). > [the 9b spec](../../superpowers/specs/2026-08-15-table-relations-query-design.md).
> One clause below is still ahead of the compiler and marked where it appears:
> `group … by … into` parses and is then refused by the typechecker.
Two `@table` classes and every 9b feature load-bearing: Two `@table` classes and every 9b feature load-bearing:

View file

@ -185,8 +185,15 @@ inferred). The developer writes no memory annotations for either.
## Run status ## Run status
Iteration 7b is landing in phases (plan: Iteration 7b landed 2026-08-18 (plan:
[`../../superpowers/plans/2026-08-18-inferred-gc-mark-sweep.md`](../../superpowers/plans/2026-08-18-inferred-gc-mark-sweep.md)). [`../../superpowers/plans/2026-08-18-inferred-gc-mark-sweep.md`](../../superpowers/plans/2026-08-18-inferred-gc-mark-sweep.md)).
This sample compiles and runs on today's toolchain — `woc
docs/examples/gc-cycle/` then `./docs/examples/gc-cycle/target/gc-cycle`.
> **It has no `just` recipe.** The plan's phase 4 checked off a
> `just gc-cycle` acceptance that never landed; the sample is the one
> compiling example in the repo with no gate behind it. Run it by hand,
> and see the plan's 2026-08-26 disclosure note.
**Phase 1 (landed).** The inference pass classifies each class; `woc --dump-gc **Phase 1 (landed).** The inference pass classifies each class; `woc --dump-gc
docs/examples/gc-cycle` prints: docs/examples/gc-cycle` prints:

View file

@ -6,17 +6,17 @@ ported file for file, per the approved
(Part 4). A single-binary systems daemon: log-tail watcher, cron.d (Part 4). A single-binary systems daemon: log-tail watcher, cron.d
supervisor, flock/pgrep probes, hand-rolled MCP-over-HTTP server, JSONL supervisor, flock/pgrep probes, hand-rolled MCP-over-HTTP server, JSONL
detection sink. Program mode (`fn main`, blocking legal, one shard) plus the detection sink. Program mode (`fn main`, blocking legal, one shard) plus the
five builtin stdlib modules — `fs`, `proc`, `net`, `time`, `json` — carry stdlib modules it needs — `fs`, `proc`, `net`, `time`, `json`, `env` — carry
all of it; read each `.wo` next to its `.hx` sibling. all of it; read each `.wo` next to its `.hx` sibling.
> **Status: design artifact — the spec's forcing function.** The systems > **Status: shipped — the systems track's acceptance gate.** Run it with
> track is approved, pre-implementation. Today's `woc` (milestone 1) > `just log-watcher` (`just log-watcher::build` / `::soak 60` for the rest).
> recovers the `class`/`fn` skeletons in these files (`--dump-ast` lists > Landed with iteration 7 on 2026-08-15: executable, not merely compilable —
> every Watcher method) but diagnoses the adopted surface as WO-E101: > zero ASan leaks in all three modes, SIGTERM ends parked syscalls, fds flat,
> `use`, `typedef`, standalone union aliases (`type CronResult = …`), > `LW_SOAK` gate. The sample existed to force the grammar it uses (the
> `pub(read)`, `switch`, `try`. This sample exists to force that grammar > blog/ecommerce/pricing precedent), and every form it needed — `use`,
> (the blog/ecommerce/pricing precedent) and becomes the track's acceptance > `typedef`, standalone union aliases (`type CronResult = …`), `pub(read)`,
> test: it compiles and detects a real silent death when the track ships. > `switch`, `try` — is now shipped surface.
## The mapping ## The mapping

View file

@ -1,14 +1,24 @@
# writeonce-serve # porch — the writeonce web framework
> Renamed 2026-08-25: this library was `writeonce-framework`, imported as
> `use framework`. Stories, specs and plans dated before that still say the > **Named `porch` on 2026-08-26.** Rename history: `writeonce-framework`
> old name — they are dated records and were left as written. > (`use framework`) → `writeonce-serve` (`use serve`, 2026-08-25) → **`porch`**
> (`use porch`). Stories, specs, plans and the audit reports dated before each
> change still say the older name — they are dated records and were left as
> written, which is the repo's convention.
>
> Why `porch`: the structure in front of the house you actually enter through,
> and in writeonce the house *is* the database. The name appears only in `use`
> lines and the `[deps]` key — names resolve bare through `use` edges, so no
> handler body mentions it.
A web framework **written in writeonce**, consumed as a `[deps]` dependency A web framework **written in writeonce**, consumed as a `[deps]` dependency
(iteration 15). Spec: `docs/superpowers/specs/2026-08-18-web-framework-design.md` §B. (iteration 15). Roadmap: [`docs/stories/porch/`](../../stories/porch/00-story.md)
— its own track, eight iterations, numbered from 1, derived from
[the Fiber parity study](../../plan/exploration/fiber/00-fiber-parity.md). Spec: `docs/superpowers/specs/2026-08-18-web-framework-design.md` §B.
```toml ```toml
[deps] [deps]
writeonce-serve = { git = "https://github.com/shoneyj/writeonce-serve", rev = "v0.1.0" } porch = { git = "https://github.com/shoneyj/porch", rev = "v0.1.0" }
``` ```
## What it is ## What it is
@ -62,10 +72,18 @@ writeonce-serve = { git = "https://github.com/shoneyj/writeonce-serve", rev
cannot live in the library). Parallel requests, stalled-client cannot live in the library). Parallel requests, stalled-client
eviction and parked idle keep-alive are gate-proven. The plain eviction and parked idle keep-alive are gate-proven. The plain
`serve()` stays single-threaded for simple apps. `serve()` stays single-threaded for simple apps.
- **TLS: none, anywhere.** Deploy behind nginx/caddy; the proxy terminates - **TLS: available in the runtime, not used by this sample yet.** Since
TLS+ALPN and gives browsers HTTP/2 while this backend speaks HTTP/1.1 runtime-v2 9 (2026-09-09) the runtime terminates TLS 1.3 itself —
keep-alive. See the web-app sample's README for the nginx sketch. `net.accept_tls(listener, cert, key)` (see `docs/examples/tls-server`) — so a
- `Content-Length` bodies only (no chunked encoding), no WebSockets/SSE, front proxy is no longer mandatory. This sample still runs plaintext
HTTP/1.1 keep-alive behind nginx/caddy (which also supplies ALPN/HTTP/2);
see the web-app sample's README for the nginx sketch. HTTP/2 itself is a
separate future slice.
- `Content-Length` bodies only (no chunked encoding); **WebSockets ARE
supported since 2026-08-27** — `ws_accept` (`http/ws.wo`) performs the RFC
6455 handshake and hands back the hijacked `net.Conn`, and `http/wsframe.wo`
is a pure-`.wo` frame codec; `docs/examples/chat` is the worked example and
`just chat` its gate. **SSE is still absent**, and so is chunked encoding.
JSON-first (no templates). Form-encoded bodies parse through JSON-first (no templates). Form-encoded bodies parse through
`form_values(req)` (`+` and `%XX` decoded, nil on any other `form_values(req)` (`+` and `%XX` decoded, nil on any other
content-type); multipart/form-data through `multipart_parts(req)` content-type); multipart/form-data through `multipart_parts(req)`
@ -85,6 +103,13 @@ first (pure `.wo` cannot express it yet).
### Transport ### Transport
> Parity reference: [the Fiber v3.5.0 study](../../plan/exploration/fiber/00-fiber-parity.md)
> read all 32 of Fiber's middleware packages against this framework on
> 2026-08-26. **Nine already have a working counterpart here** (CORS, basic
> auth, key/bearer auth, security headers, ETag, static files, logger, host
> authorization, recover-as-500). The rows below marked ⛔/⏸ are what it found
> missing, each with an owner.
| Item | State | | Item | State |
| --- | --- | | --- | --- |
| HTTP/1.1 parsing | ✅ parses + 400-and-survive; duplicate `Content-Length` rejected outright (RFC 9112 §6.3, slice 2); BODY_MAX bounds headers and body | | HTTP/1.1 parsing | ✅ parses + 400-and-survive; duplicate `Content-Length` rejected outright (RFC 9112 §6.3, slice 2); BODY_MAX bounds headers and body |
@ -113,6 +138,7 @@ first (pure `.wo` cannot express it yet).
| Content negotiation | ✅ `media_type(req)` request-side; `accepts(req, mtype)` response-side (exact, type/*, */*; q-values stripped not ranked — ranking waits for an app serving alternates) — slice 2 | | Content negotiation | ✅ `media_type(req)` request-side; `accepts(req, mtype)` response-side (exact, type/*, */*; q-values stripped not ranked — ranking waits for an app serving alternates) — slice 2 |
| Trusted-proxy client IP | 🔶 `client_ip(req)` parses X-Forwarded-For; `net.peer(fd)` (iteration 35) exposes the peer — the verify middleware is now a pure-`.wo` candidate slice | | Trusted-proxy client IP | 🔶 `client_ip(req)` parses X-Forwarded-For; `net.peer(fd)` (iteration 35) exposes the peer — the verify middleware is now a pure-`.wo` candidate slice |
| Status/header setting · redirects | ✅ builders + `set_header` | | Status/header setting · redirects | ✅ builders + `set_header` |
| WebSockets · pub/sub | ✅ **2026-08-27 (iteration 24)** — `ws_accept` does the RFC 6455 handshake and hands back the hijacked `net.Conn`; `http/wsframe.wo` is a pure-`.wo` frame codec. Rooms/presence/broadcast are actors in `docs/examples/chat`, gated by `just chat` (11 checks, 1000-client soak, both `WO_IO` backends, ASan clean). No SSE |
| Lazy body streaming + backpressure · streaming responses · explicit commit point | ⏸ UNBLOCKED by the arc (8/11 landed 2026-08-21) — stays parked until its own slice | | Lazy body streaming + backpressure · streaming responses · explicit commit point | ⏸ UNBLOCKED by the arc (8/11 landed 2026-08-21) — stays parked until its own slice |
| ETag + conditional requests | ✅ `etag_for` (quoted base64 SHA-256) + `with_etag` (If-None-Match → 304) over iteration 34's digest builtins — slice 2 | | ETag + conditional requests | ✅ `etag_for` (quoted base64 SHA-256) + `with_etag` (If-None-Match → 304) over iteration 34's digest builtins — slice 2 |
@ -123,26 +149,73 @@ first (pure `.wo` cannot express it yet).
| Ordered middleware chain | ✅ registration order, `?Resp` short-circuits | | Ordered middleware chain | ✅ registration order, `?Resp` short-circuits |
| Request-scoped context | ✅ `req.ctx` map (slice 2): middleware writes, handlers read; identity stays in `principal` | | Request-scoped context | ✅ `req.ctx` map (slice 2): middleware writes, handlers read; identity stays in `principal` |
| Guaranteed teardown | 🔶 every fd closes on every path (gate-proven); no user teardown hooks yet | | Guaranteed teardown | 🔶 every fd closes on every path (gate-proven); no user teardown hooks yet |
| Cancellation into pending storage ops | ⏸ UNBLOCKED by the arc (8/11 landed 2026-08-21) — stays parked until its own slice | | Cancellation into pending storage ops | ⏸ **unblocked, not built.** The arc landed 2026-08-21 and iteration 24 (2026-08-27) added the lifecycle a cancellation would ride — `call` with a catchable trap when the callee dies, bounded mailboxes, `monitor`, and `time.after` for a deadline. Nothing here consumes them yet; it stays parked until its own slice |
| Panic recovery | 🔶 trap = 500 and the server survives ✅; "rolls back the transaction" is framework v2 (needs `transaction { }`, iteration 18) | | Panic recovery | 🔶 trap = 500 and the server survives ✅; "rolls back the transaction" is framework v2 (needs `transaction { }`, iteration 18) |
### Storage integration (the differentiator — framework v2 territory) ### Storage integration (the differentiator — framework v2 territory)
| Item | State | | Item | State |
| --- | --- | | --- | --- |
| Rate limiting (fixed window, durable) | ✅ `Limiter` middleware over a sharded actor pool — exact counting under 30 genuinely-parallel clients, WAL-durable across a SIGTERM restart, `trust_proxy` off by default with a `net.peer` fallback. **One gap, stated rather than hidden:** the fail-closed 503 on a saturated pool is correct by construction (same `try`/`catch` as the arm that was gate-proven) but has no leg of its own — saturating the count arm deterministically needs a slow actor, and only the reverted idempotency arm was slow. The proof lives in `archive/porch-idempotency` |
| Idempotent replay of unsafe requests | ⏸ **built, reviewed, then reverted 2026-08-30.** Not a design failure: the pool actor ran the route handler inside its own `receive` so a duplicate waited in the mailbox, and it passed its gates. It provoked a C-runtime SIGSEGV in `wo_arena_alloc`/`wo_str_new` under concurrent `call()`-parked callers. Whole in `archive/porch-idempotency`, which doubles as the reproduction harness. Blocked on the runtime fix |
| Transaction-per-request middleware (commit on 2xx, roll back otherwise) | ⏸ **v2** — needs iteration 18's `transaction { }` | | Transaction-per-request middleware (commit on 2xx, roll back otherwise) | ⏸ **v2** — needs iteration 18's `transaction { }` |
| Cancellation → rollback | ⏸ arc landed; still needs v2's `transaction { }` (iteration 18) | | Cancellation → rollback | ⏸ arc landed; still needs v2's `transaction { }` (iteration 18) |
| Migration generation + review workflow | ⬜ recorded future story (script-based destructive migrations) | | Migration generation + review workflow | ⬜ recorded future story (script-based destructive migrations) |
| Eager-loading API (N+1) | ⬜ query-surface work (9-series), not framework code | | Eager-loading API (N+1) | ⬜ query-surface work (9-series), not framework code |
| Tenant-scoped query roots | ⬜ future; wants the query surface to grow scoped roots first | | Tenant-scoped query roots | ⬜ future; wants the query surface to grow scoped roots first |
Four things anyone wiring the rate limiter or idempotency into a real app
needs to know, found in the course of building them ([porch 1](../../stories/porch/01-store-backed-middleware.md)):
- **`Idempotent` is a `Handler` decorator, not a `Middleware`.** It holds
`pool` + `inner` and implements `handle`, registered in place of the route's
own handler (`app.post("/x", Idempotent { ..., inner: RealHandler {} })`),
not via `app.use_mw`. This was forced, not stylistic: the actor has to be
handed the route's `Handler` so it can run it inside `receive`, and only the
handler slot exposes it.
- **`Pool` cannot live in actor state or in a message — `multi PoolSlot` can,
and that's how a real app shards across MORE than one connection.** `Pool`
is demand-promoted to "traced" the moment an app aliases it (a
`Limiter`/`Idempotent`'s own `pool: Pool` field, read on every request) and
WO-E222 refuses a traced value in actor state or a message. `PoolSlot` (and
`multi PoolSlot`) never gets pulled into that traced set on its own — an
actor holding `slots: multi PoolSlot` directly is the same shape
`docs/examples/chat/main.wo`'s `Room { members: multi Mem }` already uses
for a multi of actor handles, and it compiles and runs. Call `make_pool(n)`
**exactly ONCE, at process start** — never per connection, which would give
every connection its own actors and silently restore the lost-increment
race this whole design exists to prevent — then hand `pool_slots(pool)`
(`middleware/keypool.wo`) to every connection actor's spawn. Each
connection rebuilds a transient `Pool` via `pool_of(self.slots)` wherever a
`Limiter` or `Idempotent` needs one. Disclosure: the accept gate's own
`ConnWorker` fixtures (`scripts/web-app-accept.sh`) still build a
deliberately ONE-slot `Pool { actors: [PoolSlot { a: slot }] }` per leg —
the limiter/idempotent legs are testing other properties, and the
saturation leg wants exactly one actor to force mailbox overflow — so no
gate leg yet exercises `pool_slots`/`pool_of` sharding N actors across
connections.
- **A `call` reply is a copyable scalar only (WO-E226), and every `receive` in
the program must agree on one return type.** That is why the stored response
travels through the `@table` rather than the mailbox, and why outcome codes
are packed into an `Int` (`pool_pack`/`pool_count`/`pool_begin` in
`middleware/keypool.wo`).
- **Pool size is a capacity decision made ONCE, not a default to ignore or a
knob to re-tune per connection.** `make_pool(n)` — called once, per the
bullet above — spawns `n` actors, sharded by hash of the key; a hot key's
actor has a bounded mailbox (`WO_MAILBOX`, default 1024), and once it
saturates under load every further request for that key answers 503 rather
than being served uncounted or queued indefinitely. Undersizing `n`
produces more 503s under load — it does not silently let requests through
uncounted, and it does not silently overshoot the limiter's or idempotency
store's guarantees.
### Security ### Security
| Item | State | | Item | State |
| --- | --- | | --- | --- |
| Constant-time comparison · Authorization parsing · Basic auth · principal | ✅ `http/auth.wo`, `req.principal` | | Constant-time comparison · Authorization parsing · Basic auth · principal | ✅ `http/auth.wo`, `req.principal` |
| CORS | ✅ `Cors { allow_origin }` — preflight 204 (before) + origin stamp on every response (after) — slice 2 | | CORS | ✅ `Cors { allow_origin }` — preflight 204 (before) + origin stamp on every response (after) — slice 2 |
| Security headers | ✅ `SecurityHeaders` after-middleware (nosniff, DENY, referrer-policy); HSTS stays at the TLS proxy by design — slice 2 | | Security headers | ✅ `SecurityHeaders` after-middleware (nosniff, DENY, referrer-policy); HSTS is set wherever TLS terminates — the front proxy today, or the runtime itself once a sample adopts `net.accept_tls` (runtime-v2 9) — slice 2 |
| Host validation | ✅ `HostAllow { host }` answers 421 before any route — slice 2 | | Host validation | ✅ `HostAllow { host }` answers 421 before any route — slice 2 |
| Strict parsing | ✅ same item as Transport's row: duplicate Content-Length is a 400 | | Strict parsing | ✅ same item as Transport's row: duplicate Content-Length is a 400 |
@ -152,7 +225,14 @@ first (pure `.wo` cannot express it yet).
| --- | --- | | --- | --- |
| base64 | ✅ pure `.wo` (`http/auth.wo`) | | base64 | ✅ pure `.wo` (`http/auth.wo`) |
| SHA-1 · SHA-256 · HMAC-SHA256 | ✅ C runtime builtins (iteration 34, ids 85–87, RFC-vector gated); SHA-512/CRC32 wait for a consumer | | SHA-1 · SHA-256 · HMAC-SHA256 | ✅ C runtime builtins (iteration 34, ids 85–87, RFC-vector gated); SHA-512/CRC32 wait for a consumer |
| Unlocks (signed cookies, CSRF, session integrity, webhook verification, JWT HS256) | ⬜ UNBLOCKED (the primitives exist since iteration 34); each is its own slice; **hard stop at JWT HS256** — no RS256, no JOSE zoo | | Unlocks — signed cookies, webhook verification, JWT HS256 **verification** | ⬜ genuinely unblocked (integrity only needs iteration 34's HMAC); each its own slice; **hard stop at JWT HS256** — no RS256, no JOSE zoo |
| Unlocks — CSRF, session integrity, JWT **issuing** | ⛔ **BLOCKED, corrected 2026-08-26.** This row previously read "UNBLOCKED (the primitives exist since iteration 34)" and that was wrong: HMAC lets you *authenticate* a token, not *mint* one, and **writeonce has no source of randomness at all** (no `getrandom`, no CSPRNG builtin — grep the runtime). An HMAC over a guessable session id is a signed guess. A random-bytes builtin is [iteration 39](../../stories/language-runtime-database/39-web-framework-parity.md)'s first goal |
| Cookies (read + `Set-Cookie`) | ⛔ absent in BOTH directions, and `Resp.headers` is a `map<Text,Text>` so it structurally cannot carry two `Set-Cookie` lines — [iteration 39](../../stories/language-runtime-database/39-web-framework-parity.md) |
| Sessions · CSRF · rate limiting · idempotency | ⬜ [iteration 39](../../stories/language-runtime-database/39-web-framework-parity.md). Limiter and idempotency need only a `@table` + `time.ticks` and are the cheapest wins available; sessions and CSRF wait on randomness + cookies. `@table` gives all four a **durable** store, where Fiber ships in-memory and expects Redis |
| Compression · SSE · byte ranges · chunked bodies | ⏸ all four sit on the parked streaming seam (`serialize()` always emits `Content-Length`). Chunked REQUEST bodies are deliberately refused today (`internal/parse.wo:153-157`, request-smuggling note) — that refusal must survive whoever implements them |
| Typed binding of query/params/form/headers | ⏸ Fiber's `Bind` reflects over struct tags; principle 13 forbids reflection, so the answer is [iteration 29's `@derive`](../../stories/language-runtime-database/29-compile-time-metaprogramming.md). JSON bodies already work via `json.decode(t) as T` |
| PATCH/OPTIONS/HEAD/ALL helpers · named routes · per-route body limit · request id · `Location`/`Vary`/`Attachment` | ⬜ [iteration 39](../../stories/language-runtime-database/39-web-framework-parity.md) — registration and response sugar; `BODY_MAX = 1048576` is currently one compile-time number for the whole server |
| `proxy` middleware | ⛔ impossible today — no `net.connect` anywhere in the runtime ([iteration 38](../../stories/language-runtime-database/38-content-platform-capabilities.md)) |
## Layout and privacy (iteration 17) ## Layout and privacy (iteration 17)
@ -170,7 +250,7 @@ naming the kind, unless a demo `main` is added (lib+bin is allowed).
- **`internal/` — not importable by a consumer.** The connection-level request - **`internal/` — not importable by a consumer.** The connection-level request
parser and carry-state record (`parse.wo`) and the serve loop, status text, parser and carry-state record (`parse.wo`) and the serve loop, status text,
and response serializer (`serve.wo`) live here. A consuming app that writes and response serializer (`serve.wo`) live here. A consuming app that writes
`use writeonce-serve/internal` gets **WO-E108** at that `use`. The rule `use porch/internal` gets **WO-E108** at that `use`. The rule
is Go's: a path segment named `internal` is refused across the `[deps]` is Go's: a path segment named `internal` is refused across the `[deps]`
boundary only — the framework's own modules import it freely. boundary only — the framework's own modules import it freely.

View file

@ -0,0 +1,207 @@
-- porch/middleware/keypool.wo — the key pool: an actor per shard, picked by
-- hash of the key, that serializes rate-limit counting (this file, kind 1)
-- and idempotency begin (Task 4, kind 2) against the @table rows in
-- store.wo. This is the only file that knows a pool exists — the
-- middlewares call through it and never touch RateLimitCounter
-- themselves. IdempotencyKey is the one exception: the response has to
-- travel through that table (a Resp cannot ride the mailbox — see
-- below), so idempotent.wo reads the row a begin call already committed.
--
-- `call`'s reply crosses the actor boundary as a single copyable scalar
-- (WO-E226 — no class, no Text can ride it). The exact count is decided
-- atomically inside `receive`; `pool_count` packs it with the window's
-- remaining time into one Int and unpacks that into the `Verdict` callers
-- actually read, so the packing never leaks outside this file. kind 2
-- (Task 4) reuses the exact same pool_pack scheme for its outcome code —
-- WO-E226 forces every `receive` in the program to agree on one return
-- type, so a second encoding is not an option.
use time
-- To a pool actor. kind 1 = count (this file); kind 2 = begin (Task 4
-- fills in the arm — the fields below are already shaped for it: the
-- bare idempotency key travels in `key`, the body digest in `digest`,
-- and the actor runs `handler` against `req` itself so a duplicate waits
-- in the mailbox rather than needing a held reply).
-- To a pool actor. `kind` is kept even though only one kind exists today:
-- idempotency's `kind: 2` arm was built, reviewed and then REVERTED (see
-- archive/porch-idempotency), and it will come back. Adding a second kind is
-- a field and an `if`, not a redesign.
class PoolMsg {
kind: Int
key: Text
limit: Int -- count: max requests per window
window: Int -- count: window size, µs
}
-- What the limiter reads back from a count. `allowed` and `limit` are
-- filled in by `pool_count` — the caller already knows `limit`, it is the
-- one it sent. `count` and `reset_at` come from the actor.
class Verdict {
allowed: Bool
count: Int
limit: Int
reset_at: Int -- wall-clock ms (time.now()) when this key's window resets
}
-- PoolMsg requires `req`/`handler` on every construction (an actor
-- NOTE: this file used to carry NullHandler, dummy_req() and fresh_req().
-- They existed ONLY because PoolMsg had to carry a Req and a Handler for
-- idempotency's kind-2 arm, which meant every rate-limit count allocated a
-- throwaway Req (four maps) it never read. With that arm reverted the
-- placeholders go too, and counting stops paying for a feature it never
-- used. They are preserved with the arm in archive/porch-idempotency.
-- Packs (count, remaining-ms-in-window) into one Int: count * 1e9 +
-- remaining_ms, remaining_ms clamped to stay under 1e9 (~11.5 days —
-- far past any realistic rate-limit window). That clamp only blurs the
-- advisory reset header on an absurdly long window; it never touches the
-- count, which is the correctness-critical half.
fn pool_pack(count: Int, remaining_ms: Int) -> Int {
let r = remaining_ms;
if r < 0 { r = 0; }
if r >= 1_000_000_000 { r = 999_999_999; }
return count * 1_000_000_000 + r;
}
-- One actor per shard. Reads the row for the key, decides, and writes the
-- new count by assigning to the row's field — that writes through and
-- maintains indexes; never delete-then-insert as an update of the SAME
-- row (the window prune below IS a delete-then-insert, but of a fresh
-- row for the new window — the stale row is retired, not mutated).
class KeyActor {
fn receive(msg: PoolMsg) -> Int {
-- Only kind 1 exists today. The `kind: 2` arm — idempotency, where the
-- actor ran the route handler inside this receive so a duplicate waited
-- in the mailbox — was built, reviewed and then REVERTED. It is whole in
-- the tag archive/porch-idempotency, which doubles as the reproduction
-- harness for the C-runtime crash that caused the revert: a SIGSEGV in
-- wo_arena_alloc / wo_str_new under concurrent call()-parked callers.
-- That arm allocated 5x what this one does inside receive and moved a
-- whole Req plus a Handler through the mailbox; over ten gate runs every
-- failure was one of its legs, and none were this one's.
-- kind 1: count.
let now = time.ticks();
let hits = from c in RateLimitCounter where c.key == msg.key take 1 select c;
if len(hits) == 0 {
insert RateLimitCounter { key: msg.key, count: 1, window: now };
return pool_pack(1, msg.window / 1000);
}
let row = hits[0];
if now - row.window > msg.window {
-- the window fully elapsed: prune the stale row rather than reset it
-- in place — resetting keeps one row forever for every key ever
-- seen, an unbounded leak for IP-keyed limiting. There is no
-- sweeper; this lazy expiry on access is it.
delete row;
insert RateLimitCounter { key: msg.key, count: 1, window: now };
return pool_pack(1, msg.window / 1000);
}
row.count = row.count + 1;
let remaining_us = row.window + msg.window - now;
if remaining_us < 0 { remaining_us = 0; }
return pool_pack(row.count, remaining_us / 1000);
}
}
class PoolSlot {
a: actor PoolMsg
}
class Pool {
actors: multi PoolSlot
}
-- Spawns n identical actors and returns the pool. n is a capacity knob:
-- too small and a hot key's mailbox saturates under load (a `call` trap,
-- answered 503 by the middleware — never a silent bypass). n < 1 is a
-- caller misconfiguration, not a capacity choice, and guarding it HERE
-- (not in pool_select's division) is what matters: every pool_select call
-- runs inside the middleware's own `try ... catch (e) { print_err(...);
-- nil }`, so a mod-by-zero trap there would be misreported as ordinary
-- 503 saturation forever (though now at least logged, not silently
-- swallowed), never surfacing the real bug on its own.
pub fn make_pool(n: Int) -> Pool {
let count = n;
if count < 1 { count = 1; }
let actors: multi PoolSlot = [];
let i = 0;
while i < count {
push(actors, PoolSlot { a: spawn KeyActor {} });
i = i + 1;
}
return Pool { actors: actors };
}
-- Pool itself is demand-promoted to traced (WO-E222) the moment an app
-- aliases it — e.g. Limiter/Idempotent's own `pool: Pool` field, read on
-- every request without being consumed — so it can never live in an
-- actor's state or a message. PoolSlot is not: WO-E222's contains_traced
-- check only recurses into a field typed as a class name (or a `multi`/
-- `map` of one); `a: actor PoolMsg` is an actor handle, a different case
-- entirely, so it never pulls PoolSlot (or `multi PoolSlot`) into the
-- traced set the way wrapping it in Pool does. An actor CAN hold `multi
-- PoolSlot` directly in its own state — the exact shape chat/main.wo's
-- `Room { members: multi Mem }` already uses for a multi of actor
-- handles — which is what makes real per-connection sharding possible:
-- call make_pool(n) ONCE at process start, hand pool_slots(pool) to every
-- connection actor's spawn, and each one rebuilds a transient Pool via
-- pool_of(self.slots) wherever Limiter/Idempotent needs one. Calling
-- make_pool per connection instead (the natural misreading of this pair
-- sitting right after a capacity-sizing knob) gives every connection its
-- own actors and silently restores the lost-increment race this whole
-- design exists to prevent.
--
-- Both functions copy field-by-field, the same trick fresh_req uses above:
-- an actor handle is a plain, freely-copyable scalar (not traced), so
-- rebuilding each PoolSlot by value produces a list with no lingering
-- alias into the traced Pool (pool_slots) or the caller's own copy
-- (pool_of) — never a value some other reader could still be holding.
pub fn pool_slots(p: Pool) -> multi PoolSlot {
let out: multi PoolSlot = [];
for s in p.actors { push(out, PoolSlot { a: s.a }); }
return out;
}
pub fn pool_of(s: multi PoolSlot) -> Pool {
let out: multi PoolSlot = [];
for x in s { push(out, PoolSlot { a: x.a }); }
return Pool { actors: out };
}
-- Hashes a key to one of the pool's actors — sum of bytes modulo n, a
-- shard selector, not a security hash. The same key always selects the
-- same actor, which is the entire per-key serialization mechanism.
pub fn pool_select(pool: Pool, key: Text) -> actor PoolMsg {
let sum = 0;
let i = 0;
while i < len(key) {
sum = sum + byte_at(key, i);
i = i + 1;
}
let idx = sum % len(pool.actors);
return pool.actors[idx].a;
}
-- The count accessor every later task's limiter calls. Unpacks the
-- actor's scalar reply into the Verdict the limiter reads.
pub fn pool_count(pool: Pool, key: Text, limit: Int, window: Int) -> Verdict {
let a = pool_select(pool, key);
let raw = call(a, PoolMsg { kind: 1, key: key, limit: limit, window: window });
let count = raw / 1_000_000_000;
let remaining_ms = raw % 1_000_000_000;
return Verdict {
allowed: count <= limit,
count: count,
limit: limit,
reset_at: time.now() + remaining_ms
};
}
-- NOTE: pool_begin() lived here — the accessor idempotent.wo called to run a
-- request through the actor. Reverted with the kind-2 arm; whole in the tag
-- archive/porch-idempotency.

View file

@ -0,0 +1,109 @@
-- porch/middleware/limiter.wo — rate limiter middleware. All counting is
-- delegated to the key pool (keypool.wo): this file never reads or writes
-- RateLimitCounter and holds no window arithmetic of its own. That is what
-- makes the pool's per-key serialization guarantee actually apply — a
-- store call here would be a second, uncoordinated writer.
-- Iteration 1 of the porch track, porch-store task 3.
use time
use http
use net
-- Limiter counts requests per key per window by calling into the shared
-- pool and acting on the Verdict it returns.
-- On limit exceeded: 429 with Retry-After and X-RateLimit-* headers.
-- On a saturated pool (the key's actor mailbox is full under load): 503
-- with Retry-After. The request is refused, never let through — a limiter
-- that stops limiting under load is worse than no limiter, since
-- saturating the pool would otherwise be the bypass.
-- Key selection: req.principal wins when non-empty. Otherwise, trust_proxy
-- false (default) keys on net.peer(req.conn), which cannot be forged;
-- trust_proxy true keys on client_ip(req) (the left-most X-Forwarded-For
-- entry) — the app author's assertion that a proxy they control overwrites
-- that header.
-- The refused/saturated paths stamp their own headers directly on the Resp
-- they return. The allowed path has no Resp yet to stamp — before() stashes
-- the numbers on req.ctx, and `after` (same shape as Cors: register the one
-- value as both Mw and Aw) copies them onto whatever response the chain
-- eventually produces.
pub class Limiter {
pool: Pool
limit: Int
window: Int -- window size in µs (e.g., 60_000_000 = 60s)
trust_proxy: Bool = false
fn before(mut req: Req) -> ?Resp {
let key = limiter_key(self, req);
let v = try pool_count(self.pool, key, self.limit, self.window) catch (e) {
print_err("limiter: pool_count trapped: ${e.msg}");
nil
};
if v == nil {
let r = Resp { status: 503, headers: {}, body: "{\"error\":\"rate limiter saturated\"}" };
set_header(r, "content-type", "application/json");
set_header(r, "retry-after", "1");
return r;
}
let limit_hdr = "${v.limit}";
let remaining = v.limit - v.count;
if remaining < 0 { remaining = 0; }
let reset_hdr = "${v.reset_at / 1000}"; -- wall-clock ms -> Unix seconds
if v.allowed == false {
let retry_sec = ((v.reset_at - time.now()) / 1000) + 1;
let r = Resp { status: 429, headers: {}, body: "{\"error\":\"rate limit exceeded\"}" };
set_header(r, "content-type", "application/json");
set_header(r, "x-ratelimit-limit", limit_hdr);
set_header(r, "x-ratelimit-remaining", "0");
set_header(r, "x-ratelimit-reset", reset_hdr);
set_header(r, "retry-after", "${retry_sec}");
return r;
}
-- Allowed: attach headers to request for after-chain to stamp on response
req.ctx["ratelimit_limit"] = limit_hdr;
req.ctx["ratelimit_remaining"] = "${remaining}";
req.ctx["ratelimit_reset"] = reset_hdr;
return nil;
}
-- Stamps the allowed-path numbers before() stashed. A refused/saturated
-- request never reaches here with anything to stamp (before() only
-- writes ctx on the allowed path), so this is a no-op for those.
fn after(req: Req, mut r: Resp) {
let limit_hdr = req.ctx["ratelimit_limit"];
let remaining_hdr = req.ctx["ratelimit_remaining"];
let reset_hdr = req.ctx["ratelimit_reset"];
if limit_hdr == nil { return; }
if remaining_hdr == nil { return; }
if reset_hdr == nil { return; }
r.headers["x-ratelimit-limit"] = limit_hdr;
r.headers["x-ratelimit-remaining"] = remaining_hdr;
r.headers["x-ratelimit-reset"] = reset_hdr;
}
}
-- Key selection: identity first, then the trust_proxy-gated peer address.
-- An absent X-Forwarded-For under trust_proxy means there is nothing to
-- trust, not an empty identity: client_ip(req) == "" falls through to
-- net.peer(req.conn) rather than keying every such client on the literal
-- "ip:" bucket (that collapse was a real bug -- one client omitting the
-- header could exhaust the shared bucket and deny/hide the rest).
pub fn limiter_key(self: Limiter, req: Req) -> Text {
if req.principal != "" { return "principal:${req.principal}"; }
if self.trust_proxy {
let ip = client_ip(req);
if ip != "" { return "ip:${ip}"; }
}
let peer = net.peer(req.conn);
if peer != "" { return "ip:${peer}"; }
return "unknown";
}
-- Helper to build a Limiter with defaults
pub fn make_limiter(pool: Pool, limit: Int, window_sec: Int) -> Limiter {
return Limiter { pool: pool, limit: limit, window: window_sec * 1_000_000 };
}

View file

@ -0,0 +1,47 @@
-- porch/middleware/store.wo — store-backed middleware tables.
-- Two purpose-shaped @table classes for rate limiting and idempotency.
-- Iteration 1 of the porch track.
-- Rate limiter: fixed-window counter.
-- Key format: "ip:192.168.1.1" or "principal:alice"
-- Window = start of current window in time.ticks (µs monotonic)
@table(name: "rate_limit_counters", index: [key])
class RateLimitCounter {
key: Text @unique
count: Int
window: Int
}
-- ============================================================================
-- KEPT DELIBERATELY, UNUSED TODAY.
--
-- Nothing in porch reads or writes this table right now. The idempotency
-- middleware that did was reverted on 2026-08-30 — not because the design was
-- wrong (it was built, reviewed and works) but because it provoked a C-runtime
-- crash: a SIGSEGV in wo_arena_alloc / wo_str_new under concurrent
-- call()-parked callers allocating heavily inside an actor's receive. Over ten
-- gate runs every failure belonged to an idempotency leg and none to the rate
-- limiter's, which drives the same pool through the same machinery but
-- allocates a fifth as much.
--
-- The table stays because the schema is settled and re-adding it would be
-- churn, not design: `digest` as its own column (never folded into the key, or
-- "same key, different body" becomes undetectable) is the one decision that
-- cost a review round to get right. The middleware, its actor arm and its gate
-- legs are whole in the tag `archive/porch-idempotency`, which is also the
-- reproduction harness for the runtime bug.
--
-- If the runtime bug is fixed and idempotency is NOT resumed, delete this.
-- ============================================================================
-- Idempotency: stored response for replay.
-- Key format: "idem:keyheader" or "idem:keyheader:sha256(method|path|body)"
-- Response = JSON-encoded Resp {status, headers, body} (headers allowlist:
-- content-type, location, etag, cache-control)
-- created_at = time.ticks when stored (µs monotonic) for lazy expiry
@table(name: "idempotency_keys", index: [key])
class IdempotencyKey {
key: Text @unique
response: Text
created_at: Int
digest: Text
}

View file

@ -1,4 +1,4 @@
name = "writeonce-serve" name = "porch"
kind = "library" kind = "library"
version = "0.1.0" version = "0.1.0"
description = "A web framework written in writeonce: HTTP/1.1 keep-alive server core, router with :param captures, Handler/Middleware structural interfaces (iteration 16)" description = "A web framework written in writeonce: HTTP/1.1 keep-alive server core, router with :param captures, Handler/Middleware structural interfaces (iteration 16)"
@ -9,4 +9,4 @@ wo = ">= 0.1"
# A LIBRARY project (declared above since iteration 17): no `fn main` here — # A LIBRARY project (declared above since iteration 17): no `fn main` here —
# the consuming app owns the entry. `woc <dir>` typechecks the whole project. # the consuming app owns the entry. `woc <dir>` typechecks the whole project.
# Apps import this repo through `wo.toml [deps]` (iteration 15) and # Apps import this repo through `wo.toml [deps]` (iteration 15) and
# `use serve` / `use serve/http` / `use serve/router`. # `use porch` / `use porch/http` / `use porch/router`.

View file

@ -0,0 +1,152 @@
-- residency-bench — databasev2 2 task 7.
--
-- Two tables identical except the `resident` annotation (see types.wo), the
-- same fill, the same Weyl key order, the same read count. Run under a cgroup
-- memory cap by scripts/db-bench.py's `residency` leg:
--
-- control : a cap that binds neither mode -> what the mode COSTS
-- over-cap: a cap between the two resident sets -> what the mode BUYS
--
-- Prints the same shape db-bench's own legs do, so the harness parses it with
-- the same helpers: `<op> <n> <ops/sec> <p50> <p99>` plus an rss/hits line.
use fs
use time
fn hist_add(mut h: map<Int, Int>, us: Int) {
let b = us;
if b < 0 {
b = 0;
}
if b > 20000 {
b = 20000;
}
if has(h, b) {
set(h, b, get(h, b) + 1);
} else {
set(h, b, 1);
}
}
fn hist_pct(h: map<Int, Int>, total: Int, pct: Int) -> Int {
let target = total * pct / 100;
if target < 1 {
target = 1;
}
let seen = 0;
let b = 0;
while b <= 20000 {
if has(h, b) {
seen = seen + get(h, b);
if seen >= target {
return b;
}
}
b = b + 1;
}
return 20000;
}
fn report(op: Text, n: Int, total_us: Int, h: map<Int, Int>) {
let us = total_us;
if us < 1 {
us = 1;
}
let rate = n * 1000000 / us;
print("${op} ${n} ${rate} ${hist_pct(h, n, 50)} ${hist_pct(h, n, 99)}");
}
fn self_rss_kb() -> Int {
let st = try fs.read_all("/proc/self/status", 16384) catch (e) "";
let i = index_of(st, "VmRSS:");
if i < 0 {
return 0;
}
let rest = substr(st, i + 6, 24);
let n = 0;
let j = 0;
while j < len(rest) {
let c = byte_at(rest, j);
if c >= 48 and c <= 57 {
n = n * 10 + (c - 48);
} else {
if n > 0 {
return n;
}
}
j = j + 1;
}
return n;
}
fn wide_pad() -> Text {
return "0123456789abcdef0123456789abcdef";
}
fn wread_all(n: Int, r: Int) -> Int {
let pad = wide_pad();
let i = 1;
while i <= n {
insert WideA { k: i, a: "a${i}${pad}", b: "b${i}${pad}", note: "n${i}${pad}${pad}" };
i = i + 1;
}
print("wreadfilled ${n} ${self_rss_kb()}");
let h: map<Int, Int> = {};
let hits = 0;
let t0 = time.ticks();
let j = 0;
while j < r {
let key = 1 + (j * 2654435761) % n;
let o0 = time.ticks();
for row in from x in WideA where x.k == key take 1 select x {
if len(row.a) > 0 { hits = hits + 1; }
}
hist_add(h, time.ticks() - o0);
j = j + 1;
}
report("wreadall", r, time.ticks() - t0, h);
print("wreadallrss ${self_rss_kb()} ${hits}");
return 0;
}
fn wread_keys(n: Int, r: Int) -> Int {
let pad = wide_pad();
let i = 1;
while i <= n {
insert WideK { k: i, a: "a${i}${pad}", b: "b${i}${pad}", note: "n${i}${pad}${pad}" };
i = i + 1;
}
print("wreadfilled ${n} ${self_rss_kb()}");
let h: map<Int, Int> = {};
let hits = 0;
let t0 = time.ticks();
let j = 0;
while j < r {
let key = 1 + (j * 2654435761) % n;
let o0 = time.ticks();
for row in from x in WideK where x.k == key take 1 select x {
if len(row.a) > 0 { hits = hits + 1; }
}
hist_add(h, time.ticks() - o0);
j = j + 1;
}
report("wreadkeys", r, time.ticks() - t0, h);
print("wreadkeysrss ${self_rss_kb()} ${hits}");
return 0;
}
fn main(args: multi Text) -> Int {
if len(args) < 3 {
print_err("usage: residency-bench wreadall|wreadkeys N R");
return 2;
}
let n = parse_int(args[1]);
let r = parse_int(args[2]);
if n == nil or r == nil {
print_err("residency-bench: N and R must be positive numbers");
return 2;
}
if args[0] == "wreadall" { return wread_all(n, r); }
if args[0] == "wreadkeys" { return wread_keys(n, r); }
print_err("residency-bench: unknown mode ${args[0]}");
return 2;
}

View file

@ -0,0 +1,34 @@
-- databasev2 2 task 7: the residency A/B.
--
-- These two tables are IDENTICAL except for the `resident` annotation, so any
-- difference between them is the storage mode's doing and nothing else's.
--
-- WHY THIS IS ITS OWN PROGRAM rather than a mode inside db-bench: declaring a
-- `resident: keys` table is a WHOLE-PROGRAM constraint. Its rows live only in
-- the write-ahead log, so the runtime refuses to start without WO_DATA — and
-- that refusal fires for every mode in the module, including ones that never
-- touch the table. Putting these classes in db-bench's shared module made its
-- `growth`, `ceiling` and `randread` legs, which deliberately run WITHOUT
-- WO_DATA, refuse to start.
--
-- The shape is WIDE on purpose. An Int-only pair shows the two modes as
-- indistinguishable, and that is structural: dropping a payload frees each
-- field's VALUE, and an Int's value IS its inline slot word, so nothing is
-- freed and the slab stays allocated either way. Only rows with Text columns —
-- separate allocations that dropping genuinely releases — can show what the
-- mode is for.
@table(name: "wideall", index: [k], durable: true, resident: all)
class WideA {
k: Int
a: Text
b: Text
note: Text
}
@table(name: "widekeys", index: [k], durable: true, resident: keys)
class WideK {
k: Int
a: Text
b: Text
note: Text
}

View file

@ -0,0 +1,6 @@
name = "residency-bench"
version = "0.1.0"
description = "databasev2 2 task 7: resident: all vs resident: keys, identical tables, one annotation apart"
[runtime]
wo = ">= 0.1"

View file

@ -0,0 +1,113 @@
# residency — per-table storage
What [databasev2 2](../../stories/databasev2/02-table-storage-modes.md) added:
`durable` and `resident`, declared per `@table` instead of one environment
variable for the whole process.
Before it, `WO_DATA` was the only switch. Set, and every table is WAL-logged;
unset, and none are. Applications are not uniform — a session table is
disposable, a product's stock level is not, and a catalogue large enough to
matter does not fit in RAM at all. One global switch forces "everything is precious" or "nothing
is", and you pay for whichever is wrong. Since task 6a the default is enforced: a program with any durable table (the default) refuses to start without `WO_DATA`; `WO_EPHEMERAL=1` opts into a RAM-only run, `@table(durable: false)` opts a table out.
## Run it
```
just residency
```
The gate writes the example's own output to `/tmp/residency.log`, banner-
separated, so you can `tail -F` it while it runs.
Or by hand, which is the whole demonstration — the same program twice against
one data directory:
```
compiler/_build/default/bin/woc --emit docs/examples/residency/main.wo -o /tmp/residency.wob
mkdir -p /tmp/residency-data # WO_DATA=<dir> must exist; wovm will not create it (or WO_DATA=<path>.db: one file, parent must exist)
WO_DATA=/tmp/residency-data runtime/wovm /tmp/residency.wob seed
WO_DATA=/tmp/residency-data runtime/wovm /tmp/residency.wob order
```
```
seeded: products=2 carts=1 SKU-1 stock=10
after restart: products=2 carts=0
order: SKU-1 stock 10 -> 7
ok: first order placed; run `order` again to see it replay
```
The second run inserts nothing. Both products come back from the log; the cart
does not, because it was never written to it. Both tables were filled by the
same code — only the annotation differs, so the difference after the restart is
the annotation's doing and nothing else's.
**Run `order` a third time.** Stock goes 7 → 4, and the example says so: a
level below the seeded 10 can only mean an earlier order's *update* survived a
restart. That is the stronger claim — not just that inserts replay, but that a
field change does.
## The three modes
| Declaration | Meaning | State today |
| --- | --- | --- |
| `durable: true` (default) | WAL-logged, replayed at boot | ✅ works |
| `durable: false` | never written to the log; costs no disk and no fsync; empty after a restart | ✅ works |
| `resident: all` (default) | every row's payload lives in RAM | ✅ works |
| `resident: keys` | the id map stays resident, the payload lives in the WAL and is read back by offset | ✅ works, including update |
## `resident: keys`, and what it costs
`Product` above is declared `resident: keys` — the mode the track exists for. A
catalogue is the table that outgrows RAM first: only the `sku -> row` id map
stays in memory, and each row's payload is read back from the log. Storage, the
read paths, scans (including through the `sku` index, a Text column), `@unique`,
deletes, checkpoint survival, and update all work.
**A read costs one `pread` plus every delta since the row's last checkpoint.**
Updating a keys-resident row has no slab slot to mutate, so it is
read-modify-**append**: `place_order` moving `stock` appends a small delta
record (id, field, new value) chained off the row's previous record, rather
than rewriting `sku`, `name` and `price` to change one integer — the argument
for a delta at all, on the hottest write path a shop has. Reading the row back
folds that chain: the base row plus every delta not yet superseded or
checkpointed away. A row updated once costs a `pread` and one small decode on
top of the base read; a row updated many times between checkpoints costs one
decode per delta still in the chain.
Three limitations ship with this, on purpose documented rather than fixed:
1. **Mid-drain stale reads.** A request reading a row inside the same
uncommitted drain, while an earlier request in that drain has an in-flight
update to it, may see the last durable value, not that request's write.
Read-your-writes holds within a request, not across requests sharing a
drain. Closing it needs the fold to consult the WAL's staging buffer
generally, which is materially bigger than this feature.
2. **Replay is O(N²) in a row's delta-chain length.** Each replayed delta
re-folds the whole chain back to its base record, so boot cost for one long
chain is quadratic in that chain's length.
3. **Compaction cannot see chain length.** The checkpoint that flattens delta
chains triggers on the log's overall byte ratio, not on any one row's delta
count — so a single hot row taking many small updates (a popular SKU,
exactly this example's workload) can grow a long personal chain without
moving the aggregate ratio enough to fire a checkpoint. This mode's design
deliberately does not cap chain length, trusting compaction to bound it
instead; for a hot-row workload, it may not.
The refusal that used to stand here was earned, not reflexive: an audit before
lifting it found that `delete` on a keys-resident table was reading a WAL byte
offset as a slab index and freeing whatever it landed on — memory corruption,
not a missing feature — fixed and pinned by a test that SEGVs against the old
code. The same audit, repeated before lifting the update refusal, found a
second bug of the same shape: three index functions (and `db.c`'s field-read
and probe paths) were reading a keys-resident row's Text column through the
wrong struct layout, reproduced as a genuine ASan heap-buffer-overflow. Fixed
at the root — a keys-resident row now holds the same engine-encoded values a
`resident: all` row always has — and pinned by a test that reproduces the
overflow against the pre-fix code.
## What this example does NOT show
The mode-mismatch startup refusal, the zero-WAL-bytes measurement, and the two
compile-time refusals are proven by `scripts/residency-accept.sh` against
purpose-built snippets, because each needs a deliberately broken program or a
byte-level assertion on the log file. This example is the readable half.

View file

@ -0,0 +1,117 @@
-- residency — databasev2 2's per-table storage, demonstrated across a restart
-- with the workload the feature exists for: a product catalogue whose stock
-- moves every time an order is placed.
--
-- Before this iteration, durability was ONE environment variable for a whole
-- process: WO_DATA set and every @table is WAL-logged, or unset and none are.
-- Real applications are not uniform. A cart session is disposable; a product's
-- stock level is not; and a catalogue large enough to matter does not fit in
-- RAM at all. One global switch forces "everything is precious" or "nothing
-- is", and the developer pays for whichever is wrong.
--
-- Run it twice against the same WO_DATA directory:
--
-- mkdir -p /tmp/residency-data -- WO_DATA must exist already
-- WO_DATA=/tmp/residency-data wovm residency.wob seed
-- WO_DATA=/tmp/residency-data wovm residency.wob order
--
-- The second run places an order. Stock comes back decremented after a
-- restart; the cart does not come back at all.
-- Precious AND read-selectively resident: WAL-logged, replayed at boot, but
-- only the id -> log-offset map lives in RAM — each row's payload is read
-- back from the log. A real catalogue is the table that outgrows RAM first,
-- so this is the mode you would actually reach for one. Storage, reads,
-- scans through the `sku` index below (a Text column — exercised here, not
-- just the scalar columns other tests stuck to), `@unique`, deletes and
-- checkpoint survival all work, and so does UPDATE: `place_order` below moves
-- `stock` through a WAL delta record — read-modify-APPEND, not a slab
-- mutation, since a keys-resident row has no slab slot to mutate. See the
-- README for what a delta update costs a reader.
--
-- Only `stock` changes when an order is placed; `sku`, `name` and `price` do
-- not. Appending the whole row on every sale would rewrite every field to
-- change one integer, on the hottest write path a shop has — which is why
-- the delta is one field, not a full-row rewrite.
@table(name: "products", index: [sku], durable: true, resident: keys)
class Product {
sku: Text
name: Text
price: Int
stock: Int
}
-- Scratch: never written to the WAL, so it costs no disk and no fsync, and it
-- is EMPTY after a restart. That is the point — not a bug to work around.
@table(name: "carts", index: [token], durable: false)
class Cart {
token: Text
sku: Text
}
fn count_products() -> Int {
let n = 0;
for _p in from p in Product select p { n = n + 1; }
return n;
}
fn count_carts() -> Int {
let n = 0;
for _c in from c in Cart select c { n = n + 1; }
return n;
}
fn stock_of(sku: Text) -> Int {
for p in from p in Product where p.sku == sku select p { return p.stock; }
return 0 - 1;
}
-- The update this example exists to show: one field of one row moves, and the
-- other three do not.
fn place_order(sku: Text, qty: Int) -> Int {
for p in from p in Product where p.sku == sku select p {
if p.stock < qty { return 0 - 1; }
p.stock = p.stock - qty; -- writes through to the engine
return p.stock;
}
return 0 - 1;
}
fn main(args: multi Text) -> Int {
if len(args) > 0 {
if args[0] == "seed" {
insert Product { sku: "SKU-1", name: "kettle", price: 2999, stock: 10 };
insert Product { sku: "SKU-2", name: "mug", price: 799, stock: 40 };
-- a cart is scratch: same insert, different annotation, different fate
insert Cart { token: "cart-a", sku: "SKU-1" };
print("seeded: products=${count_products()} carts=${count_carts()} SKU-1 stock=${stock_of("SKU-1")}");
return 0;
}
if args[0] == "order" {
-- second run: no inserts. Whatever is here came from the log.
let before = stock_of("SKU-1");
let after = place_order("SKU-1", 3);
print("after restart: products=${count_products()} carts=${count_carts()}");
print("order: SKU-1 stock ${before} -> ${after}");
if count_carts() != 0 {
print("UNEXPECTED: a durable:false table survived a restart");
return 1;
}
if after != before - 3 {
print("UNEXPECTED: the stock update did not apply");
return 1;
}
-- Run `order` more than once and this is the interesting line: a stock
-- level below the seeded 10 can only mean an EARLIER order's update
-- survived a restart. The decrement is durable, not just the insert.
if before < 10 {
print("ok: an earlier order's decrement replayed from the log");
} else {
print("ok: first order placed; run `order` again to see it replay");
}
return 0;
}
}
print("usage: residency seed | residency order");
return 0;
}

View file

@ -0,0 +1,6 @@
name = "residency"
version = "0.1.0"
description = "databasev2 2: per-table storage — durable: true|false and resident: all|keys, shown across a restart"
[runtime]
wo = ">= 0.1"

View file

@ -10,9 +10,11 @@ has one concern, and the module system (one directory = one module,
``` ```
cd docs/examples/shop cd docs/examples/shop
woc . && WO_DATA=./data ./target/shop 8080 # durable store woc . && WO_DATA=./data ./target/shop 8080 # durable store
./target/shop 8080 # RAM-only (dev) WO_EPHEMERAL=1 ./target/shop 8080 # RAM-only (dev)
``` ```
A program with any durable table (the default) refuses to start without `WO_DATA`; `WO_EPHEMERAL=1` opts into a RAM-only run, `@table(durable: false)` opts a table out.
Browse http://127.0.0.1:8080/ — products → product page → buy (stock Browse http://127.0.0.1:8080/ — products → product page → buy (stock
checked and decremented) → confirmation → /orders. With `WO_DATA`, kill checked and decremented) → confirmation → /orders. With `WO_DATA`, kill
it and restart: the orders are still there (WAL replay). it and restart: the orders are still there (WAL replay).

View file

@ -2,7 +2,7 @@
-- wrapping every page with the shared header and footer. Styles are NOT -- wrapping every page with the shared header and footer. Styles are NOT
-- inlined — pages link /assets/style.css (served by static_files), so -- inlined — pages link /assets/style.css (served by static_files), so
-- markup and styling stay separate files. -- markup and styling stay separate files.
use serve/http use porch/http
use view use view
-- The app shell as a COMPONENT (writeonce-view's `Component`: fields in, Text -- The app shell as a COMPONENT (writeonce-view's `Component`: fields in, Text

View file

@ -4,9 +4,9 @@
-- --
-- WO_DATA=./data ./target/shop 8080 (run from the shop directory: -- WO_DATA=./data ./target/shop 8080 (run from the shop directory:
-- /assets/* serves from ./assets) -- /assets/* serves from ./assets)
use serve use porch
use serve/http use porch/http
use serve/router use porch/router
use product_list use product_list
use product_page use product_page
use orders use orders

View file

@ -1,7 +1,7 @@
-- orders/controller.wo — the buying flow: stock-checked order creation -- orders/controller.wo — the buying flow: stock-checked order creation
-- (decrement + insert are each WAL-committed before they acknowledge) -- (decrement + insert are each WAL-committed before they acknowledge)
-- and the orders list (ref navigation: o.product.name). -- and the orders list (ref navigation: o.product.name).
use serve/http use porch/http
use layout use layout
use time use time

View file

@ -3,7 +3,7 @@
-- directory = one module, view and controller together. The @tables it -- directory = one module, view and controller together. The @tables it
-- queries live in the root module, which is fine: a CLASS is reachable -- queries live in the root module, which is fine: a CLASS is reachable
-- across module lines (only free `fn`s are module-scoped). -- across module lines (only free `fn`s are module-scoped).
use serve/http use porch/http
use layout use layout
pub class ListProducts { pub class ListProducts {

View file

@ -1,5 +1,5 @@
-- product_page/controller.wo — the CONTROLLER for /p/:sku. -- product_page/controller.wo — the CONTROLLER for /p/:sku.
use serve/http use porch/http
use layout use layout
pub class ShowProduct { pub class ShowProduct {

View file

@ -8,5 +8,5 @@ wo = ">= 0.1"
# Two library dependencies, the site sample's proven shape. The [deps] # Two library dependencies, the site sample's proven shape. The [deps]
# KEY is the module name `use` imports. # KEY is the module name `use` imports.
[deps] [deps]
serve = { git = "https://github.com/shoneyj/writeonce-serve", rev = "v0.1.0" } porch = { git = "https://github.com/shoneyj/porch", rev = "v0.1.0" }
view = { git = "https://github.com/shoneyj/writeonce-view", rev = "v0.1.0" } view = { git = "https://github.com/shoneyj/writeonce-view", rev = "v0.1.0" }

1
docs/examples/site Submodule

@ -0,0 +1 @@
Subproject commit 003073f2df04edd53ac68aae18a06180b41c40fb

View file

@ -1,108 +0,0 @@
# site — how it is put together
Written 2026-08-23 with the sample's landing; restructured 2026-08-25
onto the program template's MVC layout (`docs/examples/shop`), so the two
samples now read the same way.
## The layout
| file | layer | what it owns |
| --- | --- | --- |
| `types.wo` | MODEL | the `Chapter` `@table`, the `ChapterLink` projection, `Chapters.links()`, and `seed_if_empty()` |
| `content.wo` | MODEL (content) | the nine chapter bodies as fragment-returning functions, plus `seed_chapters()` |
| `layout/app.wo` | VIEW (chrome) | `AppShell` — the component that fills writeonce-view's `Layout` — the two named widths, and `html_error` |
| `layout/header.wo`, `layout/footer.wo` | VIEW (chrome) | the shared nav bar (brand = mark + wordmark) and footer |
| `layout/logo.wo` | VIEW (chrome) | the mark as inline SVG, plus the `<head>` links |
| `install/view.wo`, `install/controller.wo` | VIEW + CONTROLLER | `/install` — the toolchain guide. Static copy, so `InstallPage` has no fields |
| `packages/view.wo`, `packages/controller.wo` | VIEW + CONTROLLER | `/packages` and `/packages/:name` — the catalogue, its cards, and per-package usage |
| `favicon/controller.wo` | CONTROLLER | `/favicon.svg` — builds its own `Resp` (image/svg+xml) |
| `home/view.wo` | VIEW | `HomePage` and the homepage's code showcase |
| `home/controller.wo` | CONTROLLER | `Home` — the `/` handler |
| `chapter/view.wo` | VIEW | `ChapterNav`, `ChapterPage` |
| `chapter/controller.wo` | CONTROLLER | `ShowChapter` — the `/ch/:slug` handler |
| `admin/controller.wo` | CONTROLLER | `AdminEdit` — bearer-gated edit, answers a redirect (no view: it redirects) |
| `health/controller.wo` | CONTROLLER | `Health` — the liveness probe (no view: it answers text) |
| `main.wo` | BOOTSTRAP | seed, routes, serve. Nothing else |
| `wo.toml` | — | the two `[deps]`: `framework` (serving) and `html` (markup) |
One feature = one directory = one module, holding that feature's view
and its controller together. A module sees its own declarations plus
what it `use`s, so `home/` reaching the chapter nav has to say `use
chapter`.
The model stays at the root and is reachable from everywhere: a CLASS
crosses module lines without being exported, and only a free `fn` is
module-scoped (`WO-E210`). That single rule explains the whole layout —
`Chapter` and `ChapterLink` are classes, so the feature modules just
name them; the shared query would have been a free fn, so it is a
`static fn` on `Chapters` instead. (`pub` cannot prefix an `@table`
class — recorded gap #1 — but nothing needs it to.)
## Decisions that are not obvious from the code
- **Chapters are rows, not constants.** `seed_if_empty()` inserts them
only when the table answers empty, so a WAL restart keeps admin edits
instead of reseeding over them — the sample's own proof of chapter 6's
claim. The seed bodies are BUILT with writeonce-view's builders at boot; after
that the table is the truth and the builders are never consulted again.
- **The seam is enforced by where the query sits.** `Chapters.links()`
lives with the MODEL and hands the view a `multi ChapterLink` —
a projection, not a cursor. No component in this sample touches the
database, which is what lets `ChapterNav` be the same component on the
homepage and on every chapter page, differing only by `current`.
- **`HomePage` and `ChapterPage` hold a `Component`, not chapter data.**
The nav arrives as an already-built child component in a slot, so
neither page knows what a chapter is. That is content projection —
Angular's `<ng-content>`, with the slot as an ordinary field.
- **Two widths, named once.** `AppShell` carries a `container` field and
`layout/app.wo` exports `reading_shell` / `wide_shell`. The Tailwind
class strings appear in exactly one place instead of being repeated at
every call site.
- **Auth is handler-side by doctrine.** The framework ships mechanism
(`bearer_token`, constant-time `ct_eq`); which routes are gated and by
which token is policy, so `AdminEdit` checks its own field. No global
middleware — the public pages stay public.
- **`ok_html` is the framework's**, beside `ok_text`/`ok_json`: a status
line plus a content-type is transport, not rendering.
- **`\$` in chapter code samples.** Chapter sources show interpolation
(`${port}`) inside string literals of a language that interpolates —
the lexer's `\$` escape keeps them literal; `code_block()` then
HTML-escapes the result. This is also why those two samples stay
escaped `"..."` strings rather than becoming raw literals: a raw
literal has no escape character, so it cannot spell a literal `${`.
- **Concat spans lines two ways now.** A line ENDING in `..` continues on
the next (the one newline suppression in the language) — it never works
at the START of a line. For markup, prefer the backtick raw literal:
real newlines, real double-quoted attributes, source indentation
removed at compile time, `${ }` raw and `{{ }}` auto-escaping. The old
"`..` does not straddle newlines, so build accumulator-style" note is
obsolete and was removed.
- **The logo is inline SVG, authored once.** `logo_svg(px)` goes in the
nav brand and `favicon_svg()` is served at `/favicon.svg` — a dark tile
with a two-stroke "W", white then accent blue. No asset pipeline, no
binary in the repo, and it stays legible at 16px. The `<head>` link
reaches the document through `Layout`'s `head` slot.
- **A raw literal cannot contain a literal `{{`.** The packages page has
prose ABOUT `{{ }}` holes, and writing it directly would have made it a
hole; it is written with `&#123;` entities instead. This is the same
limitation the chapter code samples hit with `${`, and the reason both
doors exist.
- **Downloads are the framework's, not the site's.** `/dl/*path` is
`StaticFiles` mounted in `main.wo` with a 16 MiB ceiling — no
controller, because there is no decision to make. `WO_DIST` says where
the tarballs are (default `./dist`). The install page offers the GitHub
release as primary and this as a mirror, with the `.sha256` beside it.
- **The supported-systems list is read off the binaries**, not off a
wish list: `file` gives the triple, and the highest `GLIBC_` symbol
version they import gives the libc floor (2.38 today). Overstating
support costs a reader an afternoon.
- **`SITE_HOST` picks the interface.** Loopback by default — right behind
a proxy — with the env var for reaching a dev instance across the LAN.
The bound address is printed at startup.
- **writeonce-view's sheet is static.** Tailwind's class NAMES, one hand-written
CSS string inlined per page by `page()` — self-contained responses, no
toolchain; growing the sheet is appending a line in `tw_css()`.
Gate: `just site` — see `scripts/site-accept.sh` (11 checks; the restart
leg polls `/health` instead of sleeping, so it does not share
web-app-accept's 0.5s boot race).

View file

@ -1,103 +0,0 @@
# site — writeonce.de
The language tutorial, served BY the language. One binary carries the HTTP
server, the router, the pages and the database; the chapters you read are
rows in a `@table`, the markup is built by the `writeonce-view` dependency, and
the whole thing is chapter 9's own example.
```
[deps]
serve = { git = "https://github.com/shoneyj/writeonce-serve", rev = "v0.1.0" }
view = { git = "https://github.com/shoneyj/writeonce-view", rev = "v0.1.0" }
```
## Run it
```
woc . && SITE_TOKEN=change-me WO_DATA=./data ./target/site 8080
```
It binds loopback by default. To reach it from another machine while
developing, name the interface:
```
SITE_HOST=0.0.0.0 SITE_TOKEN=change-me WO_DATA=./data ./target/site 8080
```
- `GET /` — the homepage; `GET /ch/<slug>` — one chapter.
- `GET /install` — the installation guide; `GET /packages` and
`GET /packages/<name>` — the package catalogue with copy-paste
`[deps]` lines and usage.
- `GET /favicon.svg` — the mark, inline SVG, no asset pipeline.
- `GET /dl/<file>` — release tarballs, served by the framework's
`StaticFiles` from `$WO_DIST` (default `./dist`, where `just dist`
writes them).
- `POST /admin/ch/<slug>` — edit a chapter (`title`/`body`, form-encoded,
`authorization: Bearer $SITE_TOKEN`). Edits are WAL-durable under
`WO_DATA` and replay on restart — that is chapter 6, demonstrated by
the site that teaches it.
- Without `WO_DATA` the chapters live in RAM and reseed on every boot.
The acceptance gate is `just site` (scripts/site-accept.sh): two file://
dep remotes, build, the page matrix, 401, an authed edit, SIGTERM, and
the edit surviving a restart.
## The file map
MVC, laid out exactly like the program template
([`docs/examples/shop`](../shop/README.md)) so the two read the same way:
| this app | layer |
| --- | --- |
| `types.wo` | MODEL — the `Chapter` `@table`, and seed-if-empty |
| `content.wo` | the nine chapter bodies + `seed_chapters()` |
| `layout/` | the chrome: `AppShell` (+ the two named widths), header, footer, `html_error` |
| `home/`, `chapter/`, `install/`, `packages/` | one module per feature: its `view.wo` (components: fields in, Text out) and its `controller.wo` (query the model, fill the components, answer a `Resp`) |
| `admin/`, `health/`, `favicon/` | controller-only features — a redirect, a text probe, an SVG |
| `layout/logo.wo` | the mark as inline SVG: one source for the nav brand and `/favicon.svg` |
| `main.wo` | bootstrap: seed, routes, serve — nothing else |
Every `render()` makes its class a component (writeonce-view's structural
`Component`). `HomePage` and `ChapterPage` each take the chapter nav as
an already-built child component in a slot, so neither knows what a
chapter is; `ChapterNav` is therefore literally the same component on the
homepage and on every chapter page, differing only by which `ord` is
current.
The seam that keeps it honest: **every query lives in a controller.**
`chapter_links()` sits in `chapter.controller.wo` and hands the views a
`multi ChapterLink` projection — no component in this sample touches the
database, and writeonce-view contains no query at all.
One feature = one directory = one module, holding that feature's view
and its controller. The `@table` lives in `types.wo` at the root and is
reachable from every feature module without being exported — a CLASS
crosses module lines, only a free `fn` is module-scoped (`WO-E210`).
That is why the query both pages need is `Chapters.links()`, a `static
fn` on a root class, rather than a free function one of them would have
to import from the other.
## writeonce.de deployment
The framework speaks HTTP/1.1 keep-alive and no TLS by design — terminate
TLS at the proxy and forward:
```
server {
server_name writeonce.de;
listen 443 ssl http2; # certs via certbot/acme
location / { proxy_pass http://127.0.0.1:8080; }
}
```
Run the binary under systemd (`Restart=on-failure`, `Environment=SITE_TOKEN=...`,
`Environment=WO_DATA=/var/lib/writeonce-site`); SIGTERM drains cleanly.
## What it demonstrates
Chapters 1–9 teach the language (values, containers, classes, optionals,
tables, actors, deps, serving); the app itself exercises the framework's
routing/:params, the Logging middleware, bearer auth (mechanism from
`http/auth.wo`, policy here), `form_values`, `@table` + query + update by
assignment, and `writeonce-view`'s escaping/builders/Tailwind-style utility
sheet — self-contained pages, no CDN, no JS, no build step.

View file

@ -1,33 +0,0 @@
-- admin.controller.wo — POST /admin/ch/:slug: title/body update,
-- form-encoded, bearer-gated. Mechanism (bearer_token, constant-time
-- ct_eq) is the framework's; POLICY — which routes, which token — is
-- this app's, right here. No rendering: the answer is a redirect.
use serve/http
pub class AdminEdit {
token: Text
fn handle(req: Req) -> Resp {
let got = bearer_token(req);
if got == nil { return unauthorized(); }
if ct_eq("${got}", self.token) == false { return unauthorized(); }
let slug = req.params["slug"];
if slug == nil { return not_found(); }
let hits = from c in Chapter where c.slug == slug take 1 select c;
if len(hits) == 0 { return not_found(); }
let f = form_values(req);
if f == nil { return bad_request("body must be form-encoded (title, body)"); }
let title = f["title"];
let body = f["body"];
if title == nil and body == nil { return bad_request("nothing to update"); }
if title != nil {
let t = trim("${title}");
if t == "" { return bad_request("title must not be empty"); }
hits[0].title = t;
}
if body != nil {
hits[0].body = "${body}";
}
return redirect("/ch/${slug}");
}
}

View file

@ -1,23 +0,0 @@
-- chapter/controller.wo — the CONTROLLER for `/ch/:slug`. It queries the
-- model and fills the view components that sit beside it in this module;
-- a view receives VALUES, never a cursor.
use serve/http
use layout
pub class ShowChapter {
fn handle(req: Req) -> Resp {
let slug = req.params["slug"];
if slug == nil {
return html_error(404, "No such chapter", "The address names no chapter.");
}
let hits = from c in Chapter where c.slug == slug take 1 select c;
if len(hits) == 0 {
return html_error(404, "No such chapter", "Nothing is filed under that slug.");
}
let c = hits[0];
let nav = ChapterNav { items: Chapters.links(), current: c.ord };
let page = ChapterPage { ord: c.ord, title: c.title, body: c.body, chapter_nav: nav };
let shell = reading_shell("writeonce — ${c.title}", page.render());
return ok_html(shell.render());
}
}

View file

@ -1,46 +0,0 @@
-- chapter/view.wo — the VIEW for `/ch/:slug`, plus the chapter nav that
-- the homepage reuses.
--
-- The MVC seam in one place: these components RENDER, the controller
-- QUERIES, and the two never meet. ChapterNav holds VALUES (a list of
-- links), so it renders identically on the homepage and on a chapter
-- page — the only difference is which ord is `current`. Reuse is the
-- same component with different fields, never copied markup.
use view
-- `ChapterLink` is the MODEL's projection type (types.wo); a class is
-- reachable across module lines, so the view just names it.
pub class ChapterNav {
items: multi ChapterLink
current: Int
fn render() -> Text {
let out = "";
for c in self.items {
let label = `${c.ord}. {{ c.title }}`;
if c.ord == self.current {
out = out .. el("li", "mb-2 font-bold text-gray-900", label);
} else {
out = out .. el("li", "mb-2", link("/ch/${c.slug}", "", label));
}
}
return el("ul", "list-disc pl-6", out);
}
}
-- One chapter. `body` is site-authored HTML held in the row, so it goes
-- through the RAW hole; the title is data and goes through `{{ }}`.
pub class ChapterPage {
ord: Int
title: Text
body: Text
chapter_nav: Component
fn render() -> Text {
let head = el("h1", "text-3xl font-bold mb-4", `${self.ord}. {{ self.title }}`);
let art = el("div", "bg-white rounded-lg border shadow-sm p-6", head .. self.body);
let nav = el("div", "mt-8", el("h2", "text-lg font-bold mb-2", "Chapters") .. self.chapter_nav.render());
return art .. nav;
}
}

View file

@ -1,100 +0,0 @@
-- content.wo — the tutorial chapters, seeded into the Chapter table on
-- first boot (types.wo's seed_if_empty). Model CONTENT, so it sits in
-- the root module beside types.wo: it inserts rows. Bodies are HTML fragments
-- BUILT with the writeonce-view dep — prose in el(), code samples through
-- code_block() which escapes them. Editing a chapter later (the admin
-- route) overwrites body/title in place; the WAL keeps the edit across
-- restarts, which is exactly chapter 6's lesson demonstrated by the
-- site that teaches it.
use view
fn ch_hello() -> Text {
let b = el("p", "leading-relaxed mb-4",
"A writeonce program is one directory of <code>.wo</code> files and one entry: a free " .. "function named <code>main</code>. It returns the process exit code. There is no " .. "runtime to install separately and no build pipeline — <code>woc build</code> produces " .. "ONE self-contained binary with the VM and your bytecode inside.");
b = b .. code_block("fn main() -> Int {\n print(\"hello, writeonce\");\n return 0;\n}");
b = b .. el("p", "leading-relaxed mt-4",
"Run it: <code>woc build . -o hello &amp;&amp; ./hello</code>. " .. "Statements end with <code>;</code>, blocks use braces, comments start with <code>--</code>.");
return b;
}
fn ch_values() -> Text {
let b = el("p", "leading-relaxed mb-4",
"<code>let</code> binds a value; the type is inferred. Scalars: <code>Int</code> (64-bit), " .. "<code>Float</code>, <code>Bool</code>, <code>Text</code> (bytes, binary-safe). Text " .. "interpolates with <code>\${...}</code> and concatenates with <code>..</code>. " .. "Integer literals speak hex and binary, and the full bitwise set is here: " .. "<code>&amp; | ^ &lt;&lt; &gt;&gt;</code> — grouped Go-style, so a mask compare needs no parentheses.");
b = b .. code_block("let port = 8080;\nlet pi = 3.14159;\nlet name = \"writeonce\";\nlet msg = \"listening on \${port}\";\n\nlet flags = 0b1010_0001;\nlet high = flags & 0xF0; -- bitwise AND, then == compares\nlet shifted = 1 << 12; -- 4096\nif flags & 0x80 != 0 {\n print(\"top bit set\"); -- groups (flags & 0x80) != 0\n}");
return b;
}
fn ch_containers() -> Text {
let b = el("p", "leading-relaxed mb-4",
"Two containers: <code>multi T</code> (a growable list) and <code>map&lt;K, V&gt;</code>. " .. "A map read <code>m[k]</code> answers nil when the key is absent — the everyday idiom " .. "for optional lookups like HTTP headers. <code>for .. in</code> walks both.");
b = b .. code_block("let langs: multi Text = [\"c\", \"ocaml\", \"writeonce\"];\npush(langs, \"more\");\nprint(\"count \${len(langs)}\");\n\nlet ages: map<Text, Int> = {};\nages[\"ada\"] = 36;\nlet a = ages[\"grace\"]; -- ?Int: nil, no trap\nif a == nil { print(\"unknown\"); }\n\nfor l in langs {\n print(l);\n}\nfor k, v in ages {\n print(\"\${k} is \${v}\");\n}");
return b;
}
fn ch_classes() -> Text {
let b = el("p", "leading-relaxed mb-4",
"Classes hold fields and methods. There are NO function values and NO closures — a " .. "deliberate doctrine: behavior travels as a class satisfying an interface, and " .. "satisfaction is structural (same method name and shape, Go-style, no " .. "<code>implements</code>). This is how the web framework takes handlers.");
b = b .. code_block("interface Handler {\n fn handle(req: Req) -> Resp\n}\n\nclass Hello {\n greeting: Text\n fn handle(req: Req) -> Resp {\n return ok_text(\"\${self.greeting}, \${req.path}\");\n }\n}\n\n-- any class with a matching handle() satisfies Handler\napp.get(\"/hello\", Hello { greeting: \"hi\" });");
return b;
}
fn ch_optionals() -> Text {
let b = el("p", "leading-relaxed mb-4",
"<code>?T</code> is a value or nil, and the compiler forces the check before use. " .. "Failures are TRAPS: named, catchable, never silent. <code>try ... catch (e)</code> is " .. "an expression; <code>e</code> carries code, line, method and message. Anything " .. "uncaught ends the program with the same structured report.");
b = b .. code_block("let n = parse_int(\"42x\"); -- ?Int\nif n == nil {\n print(\"not a number\");\n}\n\nlet r = try fs.read_all(\"/etc/missing\", 4096) catch (e) e.msg;\nprint(r); -- the file's bytes, or \"No such file or directory\"\n\nlet d = 0;\nlet q = try 10 / d catch (e) 0 - 1; -- DIV0 is a trap, caught here");
return b;
}
fn ch_tables() -> Text {
let b = el("p", "leading-relaxed mb-4",
"The database is IN the language. <code>@table</code> makes a class a table; " .. "<code>insert</code> writes a row; queries are first-class expressions; an UPDATE is a " .. "plain field assignment on a query result. With <code>WO_DATA=&lt;dir&gt;</code> every " .. "commit is WAL-durable before it is acknowledged and replays on restart — this very " .. "site stores these chapters that way, and the admin form's edits survive a kill.");
b = b .. code_block("@table(name: \"notes\", index: [tag])\nclass Note {\n tag: Text @unique\n val: Int\n}\n\ninsert Note { tag: \"first\", val: 1 };\n\nfor n in from x in Note where x.val > 0 order by x.tag select x {\n print(\"\${n.tag} = \${n.val}\");\n}\n\nlet hits = from x in Note where x.tag == \"first\" take 1 select x;\nif len(hits) == 1 {\n hits[0].val = 2; -- an update: assign through the row\n}");
return b;
}
fn ch_actors() -> Text {
let b = el("p", "leading-relaxed mb-4",
"Concurrency is actors on fibers: <code>spawn</code> makes an actor from a class with a " .. "<code>receive</code> method, <code>send</code> delivers one message at a time, and " .. "ownership MOVES with the message — no locks, no shared mutable state, no data races " .. "by construction. Blocking calls park the fiber; the shard serves others meanwhile. " .. "One VM per core by default; mailboxes are bounded (a full one is a catchable trap).");
b = b .. code_block("class Counter {\n total: Int\n fn receive(msg: Tick) {\n self.total = self.total + msg.n;\n print(\"total \${self.total}\");\n }\n}\n\nclass Tick {\n n: Int\n}\n\nfn main() -> Int {\n let c: actor Tick = spawn Counter { total: 0 };\n send(c, Tick { n: 1 });\n send(c, Tick { n: 2 });\n time.sleep(50); -- parks this fiber; the actor runs\n return 0;\n}");
return b;
}
fn ch_deps() -> Text {
let b = el("p", "leading-relaxed mb-4",
"Dependencies are git repositories pinned in <code>wo.toml</code>; <code>wo.lock</code> " .. "records the exact revision, and locked builds work offline. The [deps] KEY names the " .. "module you <code>use</code>. This site has two: the web framework, and the writeonce-view " .. "library that rendered the page you are reading.");
b = b .. code_block(`
[deps]
serve = { git = "https://github.com/shoneyj/writeonce-serve", rev = "v0.1.0" }
view = { git = "https://github.com/shoneyj/writeonce-view", rev = "v0.1.0" }`);
b = b .. code_block(`
use serve
use serve/http
use view
-- html's builders + tailwind-style utilities, zero JS, no build step:
let body = el("h1", "text-3xl font-bold", "Hello");
return ok_html(page("Hello", body));`);
return b;
}
fn ch_serving() -> Text {
let b = el("p", "leading-relaxed mb-4",
"The whole stack of this site: routes with <code>:param</code> captures, a middleware " .. "chain, handler classes, <code>@table</code> persistence, and server-rendered HTML — " .. "one binary behind a proxy. This is the site's own main, abbreviated:");
b = b .. code_block("fn main(args: multi Text) -> Int {\n seed_if_empty();\n let app = App { middleware: [], routes: [] };\n app.use_mw(Mw { m: Logging {} });\n app.get(\"/\", Home {});\n app.get(\"/ch/:slug\", ShowChapter {});\n app.post(\"/admin/ch/:slug\", AdminEdit { token: token });\n return app.serve(\"127.0.0.1\", port);\n}");
b = b .. el("p", "leading-relaxed mt-4",
"The admin route checks its bearer token in the handler — mechanism lives in the " .. "framework (<code>bearer_token</code>, constant-time <code>ct_eq</code>), POLICY stays " .. "in the app. Try editing this chapter: " .. "<code>curl -X POST -H \"authorization: Bearer ...\" -d \"title=...&amp;body=...\" /admin/ch/serving</code>.");
return b;
}
-- One seed row per chapter: (ord, slug, title, body-builder above).
pub fn seed_chapters() {
insert Chapter { slug: "hello", ord: 1, title: "Hello, writeonce", body: ch_hello() };
insert Chapter { slug: "values", ord: 2, title: "Values, Text and bitwise", body: ch_values() };
insert Chapter { slug: "containers", ord: 3, title: "multi and map", body: ch_containers() };
insert Chapter { slug: "classes", ord: 4, title: "Classes and interfaces", body: ch_classes() };
insert Chapter { slug: "optionals", ord: 5, title: "Optionals and traps", body: ch_optionals() };
insert Chapter { slug: "tables", ord: 6, title: "@table: the built-in database", body: ch_tables() };
insert Chapter { slug: "actors", ord: 7, title: "Actors and fibers", body: ch_actors() };
insert Chapter { slug: "deps", ord: 8, title: "Dependencies", body: ch_deps() };
insert Chapter { slug: "serving", ord: 9, title: "Serving the web (this site)", body: ch_serving() };
}

View file

@ -1,13 +0,0 @@
-- favicon/controller.wo — GET /favicon.svg. The one route that answers
-- something other than HTML or text, so it builds its own Resp.
use serve/http
use layout
pub class Favicon {
fn handle(req: Req) -> Resp {
let h: map<Text, Text> = {};
h["content-type"] = "image/svg+xml";
h["cache-control"] = "public, max-age=86400";
return Resp { status: 200, headers: h, body: favicon_svg() };
}
}

View file

@ -1,9 +0,0 @@
-- health.controller.wo — GET /health: the liveness probe the accept
-- script and any proxy poll. Text, not HTML, on purpose.
use serve/http
pub class Health {
fn handle(req: Req) -> Resp {
return ok_text("ok");
}
}

View file

@ -1,19 +0,0 @@
-- home/controller.wo — the CONTROLLER for `/`: query the model, fill the
-- view components that sit beside it, answer a Resp. One feature = one
-- directory = one module, view and controller together.
--
-- It reaches the chapter nav through `use chapter` and the query through
-- the model's `Chapters.links()` static — a class crosses module lines,
-- a free fn does not.
use serve/http
use layout
use chapter
pub class Home {
fn handle(req: Req) -> Resp {
let nav = ChapterNav { items: Chapters.links(), current: 0 };
let page = HomePage { chapter_nav: nav };
let shell = wide_shell("writeonce — learn the language", page.render());
return ok_html(shell.render());
}
}

View file

@ -1,53 +0,0 @@
-- home/view.wo — the VIEW for `/`. A component: fields in, Text out.
-- Everything on this page is static copy EXCEPT the chapter list, so
-- the one field is that list's already-built component — content
-- projection, the same slot pattern writeonce-view's `Layout` uses. HomePage
-- therefore knows nothing about chapters, the Chapter table, or how the
-- nav decides which entry is current.
use view
pub class HomePage {
chapter_nav: Component
fn render() -> Text {
-- hero: tagline + the two CTAs (the go.dev shape, no JS anywhere)
let h1 = el("h1", "text-4xl font-bold mb-4", "One language. One runtime.<br>One database. One binary.");
let sub = el("p", "text-lg text-gray-700 leading-relaxed mb-6", "writeonce is a language whose compiler, runtime, web server and " .. "database ship as a single never-stopping Linux binary. Ownership-" .. "checked memory, inferred GC where ownership cannot reach, actors " .. "on every core — and the page you are reading is served by it.");
let ctas = el("div", "flex items-center justify-center gap-4", btn_link("/ch/hello", "Get started", true) .. btn_link("https://github.com/shoneyj", "View source", false));
let hero = el("div", "text-center py-16", h1 .. sub .. ctas);
-- code showcase: a real flavor of the language
let show_head = el("h2", "text-2xl font-bold mb-2 text-center", "An actor per chat room, rows in the built-in database");
let show_cap = el("p", "text-sm text-gray-500 text-center mb-4", "No broker, no ORM, no async keyword — ownership moves the message, the WAL makes the row durable.");
let showcase = el("div", "mx-auto max-w-3xl mb-8", show_head .. show_cap .. home_snippet());
-- why-cards (2x2 grid, collapses on small screens)
let cards = card("One binary", "woc build emits a self-contained executable: VM, your bytecode, the database engine. Deploys are a file copy; the runtime swaps code in place.");
cards = cards .. card("Memory safety, no tax", "Rust-shaped ownership checked at compile time; where ownership cannot express the shape, the compiler infers GC — per shard, no global pause.");
cards = cards .. card("The database is built in", "Every class is a table. Inserts are WAL-logged before they acknowledge; restart replays. No server to operate, no connection string.");
cards = cards .. card("Actors on every core", "spawn returns an address, send moves ownership. Fibers park on io_uring instead of blocking threads — no async/await, ever.");
let grid = el("div", "grid grid-cols-2 gap-6 mb-8", cards);
-- chapters (the gate's anchor string lives here)
let learn = el("h2", "text-2xl font-bold mb-4", "Learn writeonce");
let learn_p = el("p", "leading-relaxed mb-4", "The tutorial is written in the language and stored in its tables — work through the chapters in order:");
let chapters = el("div", "bg-white rounded-lg border shadow-sm p-6 mb-8", learn .. learn_p .. self.chapter_nav.render());
return hero .. showcase .. grid .. chapters;
}
}
-- The homepage's code showcase: a real flavor of the language — an
-- actor per chat room, rows in the built-in database, one binary.
-- Page copy, so it lives with the page, not with the seed data.
fn home_snippet() -> Text {
let s = "@table\nclass Message {\n room: Text\n body: Text\n}\n\n";
s = s .. "class Room {\n name: Text\n fn receive(msg: Post) {\n";
s = s .. " insert Message { room: self.name, body: msg.body };\n";
s = s .. " print(\"[\${self.name}] \${msg.body}\");\n }\n}\n\n";
s = s .. "fn main() -> Int {\n";
s = s .. " let general: actor Post = spawn Room { name: \"general\" };\n";
s = s .. " send(general, Post { body: \"hello, writeonce\" });\n";
s = s .. " time.sleep(50);\n return 0;\n}";
return code_block(s);
}

Some files were not shown because too many files have changed in this diff Show more