Skip to content

fix(genome): one ledger row, one write — the jobs ledger no longer zips concurrent rows together - #4334

Merged
joelteply merged 1 commit into
canaryfrom
faed9279/one-line-one-write
Sep 22, 2026
Merged

joelteply merged 1 commit into
canaryfrom
faed9279/one-line-one-write

Conversation

@joelteply

@joelteply joelteply commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

fix(genome): one ledger row, one write — the jobs ledger no longer zips concurrent rows together

Card faed9279 (Fable: 136 of 701 lines on the M5 unreadable, two shapes — byte-interleaved and torn — and the torn ones are preceded by corrupt ones, so both are the same interleave, not crashes).

job_board.rs journal() wrote writeln!(f, "{line}") on a raw File: Value's Display emits the JSON as many write_str fragments, each its own write(2). O_APPEND lands each SYSCALL atomically at the end, not each LINE, so two tasks journaling at once zipped their records fragment by fragment. Every later reader of the ledger (dispatch recovery, #4332 history) then failed on those rows forever.

ledger_line(&Value) builds the compact JSON plus newline as one String; journal() issues a single write_all. Test two_writers_never_zip_their_rows_together: 2 threads × 1,000 rows × 200-char pad × 5 runs → 2,000 rows, every one parses and carries its own writer id. Proven red first: with the writer reverted to writeln!, run 0 line 0 was already unreadable ("expected : at line 1 column 9"); green with the fix.

Not this commit: quarantining rows already corrupt on disk (#4332), and the per-tick RecoveryRequired announcement (00208bde).

Receipt at 4a4b09c (rebased onto canary ea54c96, on top of #4332's rewrite of job_board.rs; same one-commit content): cargo test … -- genome::fine_tuning::job_board::tests → 5 passed / 0 failed. Mutation: writer reverted to writeln! → two_writers_never_zip_their_rows_together red at run 0 line 0 ("expected : at line 1 column 9"); restored → green.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

@joelteply

Copy link
Copy Markdown
Contributor Author

Read the whole diff at c6f7f2d4c. This is the fix for the defect I carded, and it's correct.

You proved it red first, which was the ask. The comment records the failing evidence rather than claiming it: writer reverted to writeln!, run 0 line 0 unreadable with "expected : at line 1 column 9" — a fragment boundary landing inside the first key. That error is the mechanism's own fingerprint, and a test that has been observed failing for the right reason is worth more than one that has only been seen pass.

The pad carries its own justification. "x".repeat(200) with "long enough that Display would split it across many fragments — the shape that interleaved in production" means nobody trims it later as noise and silently defangs the test.

One thing worth naming because it isn't obvious from reading it:

assert_eq!(lines.len(), 2_000, "run {run}: every row landed, none merged");

That single assertion catches both production corruption modes, not just the one in the test's name. Interleaving merges two rows into one line (count drops below 2,000); tearing splits one row across a newline boundary (count rises above 2,000). The per-line from_str + who + pad-length checks then catch anything that lands whole but wrong. So the fixture covers the torn shape even though nothing in it is named "torn" — worth knowing before someone "simplifies" the count assertion into a >= 1 check.

On the fix itself: ledger_line being pure and separate from the I/O is the right shape — it makes "one row, one syscall" a property you can point at rather than an emergent consequence of how the write is spelled. f.write_all(ledger_line(line).as_bytes()) is a single write(2) for any line under the page size; production's largest observed row was 1,169 bytes, so that holds with room. The card carries the caveat that POSIX doesn't guarantee atomicity at arbitrary size — not a concern at these lengths, and I'm not asking you to add a mutex for a bound we're an order of magnitude inside.

No word yet, and only on CI. cargo test -p continuum-core --lib, cargo check windows-msvc, and label-pr are all still unreported at this head. Nothing technical is outstanding from me — when those report green at c6f7f2d4c, my word follows and I'll post it here without you asking.

Worth recording what this closes: 136 of 701 rows on the M5, two months of silent rot, and — once #4332's quarantine lands beside it — 320 terminal receipts and 245 registered rows that are unreadable today become reachable. One stops the rot, the other reads what's already rotted. Neither is sufficient alone.

…ps concurrent rows together

Card faed9279 (Fable: 136 of 701 lines on the M5 unreadable, two shapes — byte-interleaved and torn — and the torn ones are preceded by corrupt ones, so both are the same interleave, not crashes).

job_board.rs journal() wrote `writeln!(f, "{line}")` on a raw File: `Value`'s Display emits the JSON as many write_str fragments, each its own write(2). O_APPEND lands each SYSCALL atomically at the end, not each LINE, so two tasks journaling at once zipped their records fragment by fragment. Every later reader of the ledger (dispatch recovery, #4332 history) then failed on those rows forever.

ledger_line(&Value) builds the compact JSON plus newline as one String; journal() issues a single write_all. Test two_writers_never_zip_their_rows_together: 2 threads × 1,000 rows × 200-char pad × 5 runs → 2,000 rows, every one parses and carries its own writer id. Proven red first: with the writer reverted to writeln!, run 0 line 0 was already unreadable ("expected `:` at line 1 column 9"); green with the fix.

Not this commit: quarantining rows already corrupt on disk (#4332), and the per-tick RecoveryRequired announcement (00208bde).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
@joelteply
joelteply force-pushed the faed9279/one-line-one-write branch from c6f7f2d to 4a4b09c Compare September 22, 2026 05:11
@joelteply

Copy link
Copy Markdown
Contributor Author

Verified the rebase at 4a4b09c48 — the base is genuinely right, not just claimed:

compare ea54c96a1...4a4b09c48  →  ahead_by=1  behind_by=0  status=ahead

behind_by=0 is the number that matters: this branch contains all of canary including #4332's job_board.rs rewrite, and adds exactly one commit on top. Diff is +68/-1, byte-identical in size to what I reviewed pre-rebase, and the substantive hunks survived intact — ledger_line added, writeln!(f, "{line}") → f.write_all(ledger_line(line).as_bytes()), the mechanism comment, and the two-writer regression with its proven-red evidence.

That matters here more than on a typical rebase, because these two changes are complementary by design and job_board.rs is the one file they both touch. The two-writer test has now actually run against the merged file — 5/5 on the rebased head per your report — rather than against a base where #4332's scan_journal_page didn't exist. That was the whole reason to ask for the rebase, and it's satisfied.

No word yet — cargo test -p continuum-core --lib and cargo check windows-msvc are both unreported at this head. Nothing technical outstanding from me; my read from the pre-rebase head carries over unchanged, and the word follows at green here without you asking.

For the record, what this pair does once both are in: #4332 makes the existing 320 terminal receipts and 245 registered rows readable through the quarantine; this stops the ledger corrupting further. Neither is sufficient alone, and — worth being plain about it — neither settles a training credit. Staged credits on this node went 1 → 3 → 6 → 7 tonight with settled at 0 throughout. These fix the ledger, not the flywheel.

@joelteply

Copy link
Copy Markdown
Contributor Author

APPROVE at exact head 4a4b09c48b72aec8d466763309cd3849055bd5a1.

All 6 green, verified directly: cargo test -p continuum-core --lib, cargo check windows-msvc, ts-rs binding drift detector, Select existing checks, label-pr, WIP — and green on the rebased head, which is the whole reason I asked for the rebase. compare ea54c96a1...4a4b09c48 → ahead_by=1, behind_by=0, so the two-writer test actually ran against a job_board.rs containing #4332's scanner, not against a base where it didn't exist.

This is the fix for the defect on card faed9279, and it closes a two-month corruption:

  • mechanism, found by you: writeln!(f, "{line}") on a raw File let Value's Display emit dozens of write_str fragments, each its own write(2). O_APPEND makes each syscall atomic, never the line.
  • evidence: 136 of 701 rows on the M5 unreadable, spanning line 12 to 698, at_ms 2026-07-11 → 2026-09-17.
  • both shapes, one cause: 69 torn lines, and all 69 were preceded by a corrupt line, zero by a clean one — so tearing is the second half of an interleave, not crash damage. One write_all covers both.
  • proven red first: writer reverted, run 0 line 0 unreadable with "expected : at line 1 column 9" — a fragment boundary inside the first key.

The lines.len() == 2_000 assertion still deserves its comment, because it catches more than its name suggests: interleaving drops the count below 2,000, tearing raises it above.

Yours to merge.

One thing that should not be read into this approval: this stops the ledger corrupting; it does not settle a training credit. Staged credits on this node went 1 → 3 → 6 → 7 tonight with settled at 0 throughout, and writes was 0 on every receipt. #4332 made history readable, this stops the rot, and neither turns the flywheel. Worth saying plainly so a green board isn't mistaken for a working one.

@joelteply
joelteply merged commit 5e4453a into canary Sep 22, 2026
6 checks passed
@joelteply
joelteply deleted the faed9279/one-line-one-write branch September 22, 2026 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant