Skip to content

Storage contract for paros: #292–#304 (redoes #298, without #295) - #305

Merged
PierreZ merged 18 commits into
mainfrom
claude/journal-issues-299-304-292
Oct 6, 2026
Merged

PierreZ merged 18 commits into
mainfrom
claude/journal-issues-299-304-292

Conversation

@PierreZ

@PierreZ PierreZ commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

Against main. Redoes the work of the closed #298 (#293, #294, #296, #297) and resolves #299–#304 and #292: one Conventional Commit per issue, each with its red→green evidence in the message, plus two journal bugs the new chaos found. #295 was closed as not planned (reasons on the issue), so it is not here.

#293–#297, redone from #298

Issue Commit Outcome
#293 91e3a52 Journal::open syncs every ancestor of the journal directory (and, in #301's commit, the directory itself)
#294 5b85b26 under Striped, a domain allowed node-local damage counts against every stripe's tolerance
#296 f8c957e, 2f5eae1 owner-scoped, byte-range corrupt_bytes / EIO on SimWorld and FaultContext, plus FaultContext::durable_bytes(ip, path) to read the target's durable bytes before aiming, with no I/O and no draws
#297.3 21e7d7a SimContext::crash_self, and a SelfCrash handle for code that holds no SimContext (paros's driver hooks)
#297.1, #297.2 f48797a no new API (see below)

Not carried over from #298:

Carried over from #298's draft: the topology tests reported a wrong pattern by returning a process error, which never fails a run, so they could not fail. They now panic.

#299–#304 and #292

Issue Commit What changed Red before → green after
#304 31d3ac4 save_meta spends its generation before writing a copy; two valid copies of one generation that disagree are MetadataCorrupt reopen returned the failed promise=2, now promise=3
#303 8b92140 Journal::peek_meta: no recovery, no repair, nothing created new API
#299 17d017f every batch starts on a fresh block; format v4 whole log read as torn (next_index 1), now intact
#300 a63c2bf reserved slot records; a torn identifier in the last batch ends the log; the block holding a cut is never rewritten zeroed slot silently cut the log, now DoubleFault; torn last-batch identity refused, now a torn tail
#301 949e2c5 durable start.0/1 before prefix unlinks; SegmentGap; walk bounded by the slot table; open syncs the journal directory resurrected segment cut the log or panicked; crash-loop seed 4 lost the whole log
#302 8875191 append_checkpoint / checkpoint() / Recovery::checkpoint, with the batch's entry count new API; the replay-vs-history oracle goes red without the count
#292 dbe9b76 storage_fault_mask, the storage twin of network_fault_mask: ten families, each zeroing sampled probabilities masked family never fires, identical draw counts

Dropped after review

  • StorageFault::BarrierViolation and StorageFault::SlowDisk (added in 540943c, removed in e6a1884). No Random or Swarm profile draws barrier violations, so that family masked nothing. SlowDisk undid the buggify knobs' throughput spikes, a performance knob rather than a fault family, with no network equivalent.
  • FaultContext::storage(ip) (in f8c957e, replaced in 2f5eae1). Its reads were real storage I/O: they took simulated time, drew randomness and rolled fault coins, so aiming perturbed the run. durable_bytes reads a known file's durable image instead. It cannot list a directory, so a full JournalAtlas::scan from an injector is not possible.

Bugs the new chaos found

  • Open returned unsynced entries after a graceful restart (11c8064). The next crash took them back. Recovery now syncs what it keeps; found by the journal example under storage chaos.
  • Open trusted a segment name a failed earlier attempt left undurable. Fixed in 949e2c5.

Deliberate choices to review

  • start_index stays segment-granular, to keep paros's fallback to the history before a damaged checkpoint.
  • A checkpoint cut short is never named, but not removed: a caller may have adopted what survived of it.
  • Slot-table writes stay whole-block: a lost acknowledged slot is rebuilt from its intact entry.
  • Residual: an entry cut by a truncation returns only if two identifiers are damaged together.

Gates (on this branch)

  • cargo fmt; cargo clippy --all-targets -- -D warnings; cargo nextest run: 1,312 passed.
  • moonpool-sim clippy without default features and wasm32 check; rustdoc -D warnings; mdbook build.
  • Journal crash loops: 3,000 seeds per model under the paper's oracle, the full physics included (run before the last two commits, which touch only moonpool-sim).
  • cargo xtask sim run journal (Chaos::Storage(Random), Keep): green (same).

Checked against paros (f2b2502)

Built through a local [patch] before #295 and the review removals, nothing committed to paros. paros calls none of the removed APIs, so dropping them changes nothing on the paros side. It compiles with no source changes:

  • cargo nextest run: 471 passed.
  • sim-paros-hunt main 2000: no violations.
  • canary 200: no determinism break.

Follow-ups on the paros side when the pin advances:

  • Error mapping: map SegmentGap and CheckpointTooLarge explicitly.
  • Format probes: use peek_meta in resolve_provisioning and resolve_created.
  • Checkpoints: move the brackets to append_checkpoint; an image must fit one segment, and a cut fragment stays in the log.
  • Matchmakers: register them with .cluster() to give them failure domains.
  • Fault ledger: retire the 1:1 ledger checks of paros#176 in favour of outcome checks and the journal's verdict gates.
  • Storage chaos: mask PhantomWrite, DiskFailure and Degradation. Barrier violations need no mask (no profile draws them), and the knobs' slow-disk spikes stay on.

Closes #292, closes #293, closes #294, closes #296, closes #297, closes #299, closes #300, closes #301, closes #302, closes #303, closes #304.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Tq9joyAz9Y6ptfKQB1bnnh

claude added 2 commits October 6, 2026 05:13
…able

`Journal::open` synced only the immediate parent of `dir`, so for a nested
directory (`data/journals/<tenant>/<journal>`) a crash after the first open
could drop an ancestor's name, and with it the meta, the format marker and
every synced entry: a power loss turned into an amnesiac node.

`open` now syncs the parent of every component of `dir`, root first. It
syncs pre-existing ancestors too, since an earlier open may have created
them and failed before its syncs completed.

The new `a_nested_journal_survives_a_crash_after_its_first_open` test opens
`a/b/c/wal` with `unsynced_dir_entry_loss_probability = 1.0`, appends,
crashes and reopens; it fails on the old code.

Closes #293

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017Pv7ppXLHvimhFfSqMapGy
Under `FaultPattern::Striped`, stripe `s` could be damaged in the domains
its rotation picked, and node-local bytes in the independently drawn
`local` domains. A format that gives up its whole replica on node-local
damage (moonpool-journal refusing to open on a double fault, say) then
lost stripe `s` in two domains at tolerance 1: an unwinnable run.

A domain allowed node-local damage now counts as damaged for every stripe:
it may damage anything, and the stripes rotate over the other domains,
one each. So `local` holds `tolerance - 1` domains and stripe `s` is
damaged in at most `local` plus the one domain it rotates to. At the
default tolerance of 1 no node-local byte is damaged under this pattern
(minority and rolling still cover it). A striped seed draws one fewer
index than before.

The new `node_local_damage_counts_against_every_stripe` test treats any
node-local loss as the loss of every stripe in that zone and checks, over
40 seeds at tolerance 1 and 2, that no stripe loses copies in more than
`tolerance` zones; it fails on the old code.

Closes #294

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017Pv7ppXLHvimhFfSqMapGy
@PierreZ
PierreZ force-pushed the claude/journal-issues-299-304-292 branch from 6b4c50a to d914eab Compare October 6, 2026 05:38
@PierreZ PierreZ changed the title moonpool-journal storage contract for paros: #299–#304 and #292 Storage contract for paros: #293–#304 and #292 (redoes #298) Oct 6, 2026
@PierreZ
PierreZ changed the base branch from claude/moonpool-issues-293-297-167usn to main October 6, 2026 05:38
claude added 14 commits October 6, 2026 06:04
`SimWorld::corrupt_file` and `fail_file_with_eio` are path-global and
sector-granular, and a scripted `FaultInjector` cannot reach them. A
replicated format whose nodes share a path and pack several records per
sector could not damage one copy of one record on one node.

- `SimWorld::corrupt_process_file_bytes(ip, path, bytes)` durably mutates
  exactly `bytes` of `ip`'s file: each byte XORed with a nonzero mask of
  its offset (no draws), in the durable image and in the visible one
  wherever no unsynced write covers it. The durability stamp is
  recomputed, so a later crash does not report a lost synced write. A
  range past the durable end is `StorageError::OutOfRange`.
- `SimWorld::fail_process_file_with_eio` / `clear_process_file_eio`
  scope EIO to one owner's file.
- `FaultContext::corrupt_bytes`, `fail_file_with_eio` and
  `clear_file_eio` expose the three to fault injectors, by process IP.
- `FaultContext::storage(ip)` hands an injector a provider scoped to that
  process's disk, to read where a record lives before aiming at it (a
  format's layout scanned on a crashed node, say).

Tests: two owners of the same path, the corruption changes only the named
bytes (across a sector boundary) of one, survives a crash without tripping
the lost-synced-write oracle (it trips without the re-stamp), and is
deterministic; owner-scoped EIO fails only its owner; a scripted fault
injector damages one replica of three byte for byte.

Closes #296

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tq9joyAz9Y6ptfKQB1bnnh
A process that wants a power loss at an exact point of its own protocol
(a crash while a journal append's sync is in flight, paros#202) had to
round-trip through a fault injector polling the state handle.

`SimContext::crash_self(kind, recovery_delay)` schedules the same
`ProcessForceKill` a fault injector does, for the caller's IP, one tick
from now: tasks aborted, connections reset, storage through crash
resolution (`CrashAndWipe` also wipes). With a delay the process
restarts after it; without one it stays down until an injector restarts
it. No draws. It fails from a workload and for `RebootKind::Graceful` (a
process shuts down gracefully by returning).

`SimContext::self_crash()` returns the same capability as a `SelfCrash`
handle (`Clone + Send + Sync + 'static`), for code that holds no
`SimContext`: paros's driver hooks live in the provider-generic driver.
`crash_self` is a shorthand for it.

A force-killed process is now recorded dead by the process manager
itself, so a self-crash counts against attrition budgets until it
restarts, like an injector's kill.

Test: a process syncs old bytes, writes new ones, crashes itself and
then syncs; nothing runs past the crash, every sector reads back old or
new on the next boot, and across ten seeds some sector rolled back.

Part of #297

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tq9joyAz9Y6ptfKQB1bnnh
…cluster() group

#297 asked for two more things besides `crash_self`; neither becomes an
API.

- A locality for `.processes()` groups (item 2). Several `.cluster()`
  groups are already supported, each with its own IP range, so a second
  role that needs failure domains (paros's matchmakers beside its
  acceptors) is a second `.cluster()` group with its own
  `replicated_storage_faults` call. Giving `.processes()` members phantom
  domains that only the replication plan would see (#298's draft) would
  make attrition, the machine registry and the fault plan disagree on
  which processes share fate. `a_second_cluster_group_draws_its_own_pattern`
  shows two `.cluster()` groups each drawing a pattern over their own
  domains (zones for one, machines for the other); registered with
  `.processes()` instead, the matchmakers draw none and it fails. The
  storage-faults chapter says so.
- A tolerance a process sets at boot (item 1) is left out: the system
  under test would configure the faults aimed at it ("first caller wins",
  with damage already done kept). The tolerance stays the builder's.

The topology tests' `ReplicaProcess` reported a wrong pattern by
returning an error, which only ends the process and never fails the run,
so those checks could not fail (found by #298's draft); it now panics.

Closes #297

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tq9joyAz9Y6ptfKQB1bnnh
… copy

`DualFile::store` bumped its generation only after both copies landed. A
save that failed after both renames (the directory sync behind `meta.1`)
left the generation unspent, so a retry with a newer value wrote the same
generation; a crash after the retry's first copy then left two valid copies
of one generation, the failed (older) value among them, and loading picked
it silently. For a Paxos caller that is a promise rolled back.

The generation is now spent before the first copy is written and stays
spent when the save fails, and loading refuses two valid copies of one
generation with different payloads as `MetadataCorrupt` instead of picking
one. No new draws; the on-disk format is unchanged. A failed `save_meta`
does not poison the journal, so the caller can retry it in place.

Red before the fix, green after:
- `a_retried_metadata_save_outranks_the_one_that_failed` (a scripted
  provider fails the directory sync after `meta.1`'s rename, then refuses
  the retry's `meta.1` rename): the reopen returned `promise=2`, the failed
  save, instead of `promise=3`.
- `two_copies_of_one_generation_that_disagree_are_refused`: opened instead
  of returning `MetadataCorrupt`.

The crash loop now draws `sync_failure_probability` (0, 0.02, 0.1) under
every model, retries a failed save with a fresh value (the metadata oracle
accepts any value tried since the last acknowledged one), and reopens on an
I/O error from recovery. It does not reach this interleaving by chance (600
paper seeds stay green on the old code); the targeted test is the witness.

Closes #304

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tq9joyAz9Y6ptfKQB1bnnh
…etadata

A caller that keeps a format marker in the journal's metadata had to run
`Journal::open` plus a whole replay to learn whether a store was formatted,
and `open` is not read-only: it repairs headers and slots, rewrites a stale
metadata copy, zeroes past the end, and may truncate the last batch. A probe
meant to look could change what the real boot finds.

`Journal::peek_meta(&provider, dir)` returns what `meta()` would after an
open, from the newest valid copy, through the same choice as loading
(`DualFile::peek` shares it): no repair of a damaged or older copy, nothing
created, `None` when neither copy exists (an absent directory included),
`MetadataCorrupt` when a copy exists and none is valid. Read-only, no draws.

`peeking_at_the_metadata_changes_nothing` (did not compile before: the API
did not exist): an empty disk peeks `None` and stays without the
directory; after `save_meta` the value peeks back; with `meta.0` damaged the
value still peeks and `meta.0` is byte-for-byte unchanged afterwards, the
next open reporting `meta_repaired`; with both damaged, `MetadataCorrupt`.

Closes #303

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tq9joyAz9Y6ptfKQB1bnnh
Every append rewrote bytes an earlier `fdatasync` had made durable: the
data write began at the block the previous batch ended in, refilling its
lead from a cached copy (the `tail` cache). The simulated disk drops a
sector's durability stamp on any write, and its crash physics
(`crash_lost_probability`, `crash_latent_fault_probability`,
`shorn_write_probability`, all drawn by `Chaos::Storage(Random)` and
`Swarm`) may then lose, garble or shear it, taking acknowledged entries
with it. On a real disk the same pattern is a torn-sector hazard.

A batch now starts on the block boundary after the last entry and pads its
last block with zeros (up to one block of padding per batch: space, never a
sync); the `tail` cache is gone. `fitting` counts from the boundary. The
slot table keeps its whole-block writes, which do rewrite neighbouring
acknowledged slots: a crash that loses one leaves its entry intact, and the
walk rebuilds the slot. To find that entry the walk's fallback now knows
the layout (`locate`): a continuation sits right after its predecessor, a
batch start on the next block boundary, and the entry's batch-start flag
must agree with where it was found; a batch start off a boundary is
rejected as stale or misdirected. The past-the-end check after a torn tail
looks as far as the next block's first header, where a discarded batch
sits. Format version 4: a version-3 segment, packed back to back, is
refused rather than misread. The same seed still replays; every seed names
a different run.

Suffix truncation and the clean-up after a torn tail still rewrite the
block holding the cut; making those safe needs the reserved slots of #300,
which also lands the strict oracle on the harsh crash loop.

Red before the fix, green after:
`a_crash_during_an_append_cannot_reach_the_batch_before_it` appends batch
A (three entries), then one 64-byte entry that fits in A's last block, and
crashes one simulation step short of B's sync on a disk that loses every
dirty sector to zeros. Before: the reopen returned `next_index` 1 — A's
shared block and slots were zeroed, recovery read the whole log as a torn
tail and dropped every acknowledged entry. After: A is whole (`next_index`
4), its lost slots rebuilt, nothing reported corrupt or ambiguous. Tests
that hard-coded packed offsets now read them from `JournalAtlas::scan`.

Refs #299

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tq9joyAz9Y6ptfKQB1bnnh
…n the last batch ends the log

Two rules of the slot table disagreed with the record contract downstream
callers rely on (paros#20: "all-zeros is always faulty, never empty"):

1. All zeros meant "never written". A synced slot that came back zeroed (a
   lost sector, a zero-filled EIO, a misdirected page of zeros) read as
   absent, and beside a damaged entry ended the log — every acknowledged
   entry after it silently cut, CTRL's Figure 2 bug in disguise.
2. A bad slot beside a bad entry was a double fault everywhere, the last
   batch included, though a crash before that batch's sync tears both: the
   node refused to boot over a batch nobody acknowledged.

Every slot of a new segment is now formatted with a reserved record (its
own index, the reserved flag, a CRC over the lot — TigerBeetle's reserved
headers); suffix truncation and recovery's clean-up write reserved records
instead of zeros. `SlotState` is `Reserved` / `Valid` / `Bad`: zeros, and a
reserved record naming another index (misdirected), are `Bad`. A reserved
slot ends the log. A bad slot beside a bad entry ends it too (`torn_tail`)
when the index is in the last batch — the tail segment, no batch-start
identifier further on before a reserved one (identifiers past a reserved
one are leftovers of a cut a crash interrupted, and prove nothing); before
the last batch it stays `DoubleFault`.

With those, truncation and recovery stop rewriting the block that holds the
cut: it holds kept entries, and the cut entries' bytes in it are inert
behind their reserved slots; only whole blocks from the next boundary are
zeroed. Those bytes sit where a continuation of the last kept entry would,
so a cut also marks the last kept slot `cut` (a slot-only flag), and the
walk never takes what follows a cut entry for a continuation even if the
reserved slot after it is later damaged. The mark is written only once the
resets are durable, with the zeroing: written together, a torn write could
make the mark durable beside a never-reset damaged identifier and refuse a
continuation an unfinished cut still needs (harsh seed 725 found that).
Format version 4 (bumped in the previous commit, not yet released) gains
the reserved and cut flags. No new draws.

The journal now never rewrites a sector holding an acknowledged entry, so
the harsh crash loop takes the paper model's oracle (#299's acceptance):
nothing acknowledged lost, reported corrupt or ambiguous, every boot opens,
under crash-lost up to 0.3, latent faults up to 0.1, shorn writes up to
0.2, garbage fill 1.0. 3,000 seeds of each model pass (harsh: 7,162 lost
acknowledged identifiers rebuilt, 1,990 torn tails, no refusal). The aimed
test now shows aiming raises the identifiers recovery rebuilds (24,130 vs
7,162 on 3,000 seeds; 905 vs 276 on the default 120).

Red before, green after:
- `a_zeroed_slot_is_damage_never_the_end_of_the_log`: beside a damaged
  entry before the last batch, the zeroed slot silently ended the log at
  `next_index` 2 instead of `DoubleFault`.
- `a_torn_identifier_in_the_last_batch_ends_the_log`: `DoubleFault { 3 }`
  instead of opening with `torn_tail`, entries 1 and 2 intact.
- the strict harsh crash loop on the previous commit's source: seed 3
  refused to open (double fault on an unacknowledged torn batch).
- `a_damaged_slot_past_a_cut_does_not_bring_the_cut_entry_back` and
  `a_suffix_cut_mid_block_never_brings_the_cut_entries_back` guard the
  no-rewrite cut (the old code rewrote the block, so they passed there).

Closes #299
Closes #300

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tq9joyAz9Y6ptfKQB1bnnh
…is read as the end

`truncate_prefix` deleted the dropped segments, then ran one `sync_dir`.
Nothing durable said the start had moved, and with
`unsynced_dir_entry_loss_probability` each unlink resolves on its own at a
crash: `[seg-1, seg-3, …]` could come back. `Segment::walk` then took its
limit from the next segment's name: if seg-1 had rolled over on a full data
region, the walk met the first empty slot past seg-1's real end and `open`
deleted every later segment, the live log included; if seg-1 had rolled
over on a full slot table, the walk indexed past the table and panicked.

- `truncate_prefix` records the new start in its own two-copy record
  (`start.0`, `start.1`, a `DualFile` like the metadata) before any unlink.
  `open` deletes any segment wholly below the recorded start, and refuses
  with the new `JournalError::SegmentGap` when the segment holding it is
  missing. `start_index` stays segment-granular: a caller that checkpoints
  and then drops the prefix keeps the history before an unreadable
  checkpoint for as long as its segment lives.
- A sealed segment must reach the next one's first index exactly; ending
  short is `SegmentGap`, checked before recovery writes anything, never a
  truncation of what follows. The walk's limit is the slot table, the next
  name only a cross-check.
- `truncate_suffix` syncs the directory after each unlink (newest first), so
  a crash undoes at most the last one and the survivors stay a prefix.
- `open` syncs the journal directory itself before trusting what it lists.
  The crash loop, with directory-entry loss and sync failures both on, found
  it (seed 4): a rollover's rename landed, its directory sync failed, the
  reopen recovered the visible-but-not-durable segment and acknowledged
  appends into it, and the next crash took its name and the whole log.
- `JournalRegion::Start { copy }` charts the start copies;
  `JournalAtlas::scan` skips segments the next open will delete.

No new draws.

Red before, green after:
- `a_segment_resurrected_below_the_start_is_deleted_not_walked`: three
  segments, `truncate_prefix` past the second, seg-1 put back byte for byte
  (an undone unlink). Data-full rollover: the reopen cut the live log
  (`torn_tail`). Table-full rollover: index out of bounds in the walk.
- `a_missing_segment_is_refused_not_read_as_the_end`: opened, deleting the
  segments after the hole, instead of `SegmentGap`.
- the crash loop (paper and harsh, seed 4 round 1): an acknowledged entry
  lost to the undurable segment name, until `open` synced the directory.

The crash loop's writer now also truncates prefixes (ledger entries below
`before` stop being guaranteed when it starts; the oracle matches by index),
draws `unsynced_dir_entry_loss_probability` (0, 0.5, 1) under every model,
and runs on 48 KiB segments so compaction lands in most recoveries (2,854 of
3,000 paper seeds). It does not reach the unlink interleaving by chance
(1,500 seeds green on the old walk); the targeted tests are the witnesses.
3,000 seeds of each model pass.

Closes #301

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tq9joyAz9Y6ptfKQB1bnnh
…he prefix before it

A journal of operations folded at boot needs compaction: re-emit the folded
state, then drop the history before it. Callers built the rest themselves
around `truncate_prefix` (paros: bracketed `Begin … End` batches and a boot
plan in both of its stores), re-deriving batch boundaries the journal
already knows.

- `Journal::append_checkpoint(&records)` appends one batch flagged as a
  checkpoint and returns its indexes. It is never split: when the current
  segment cannot hold it, the journal rolls over first, so a checkpoint is
  always one batch and one sync; one that no segment could hold, or an
  empty one, is `JournalError::CheckpointTooLarge`, nothing written.
- The checkpoint flag sits beside the batch-start flag in the first entry
  and its slot, so the far identifier alone says "this opens a checkpoint",
  together with the batch's entry count (in the field that was reserved;
  format version 4, not yet released). Without the count, a checkpoint a
  crash cut at a reserved slot would leave a shorter run of entries that all
  verify and pass for a complete image.
- `Journal::checkpoint()` and `Recovery::checkpoint` name the newest
  checkpoint whose every entry is in the log and intact. A damaged one is
  reported in `corrupt` like any damaged batch and passed over for the one
  before it, or `None` with the whole history still live; one cut short (by
  a crash, or a suffix truncation through it) is passed over too. A crash
  leaves a cut checkpoint as the last batch, handled as today, truncated or
  kept per `AmbiguousTail`; it is never removed on its own, since a caller
  may have adopted what survived of it.
- `read_range` is unchanged: a caller replays `checkpoint.start..next_index()`.
  Dropping the prefix stays the caller's `truncate_prefix(checkpoint.start)`
  (durable start first, #301), so a crash between the two is harmless; the
  trigger stays the caller's.

No new draws.

The crash loop checkpoints on a third of its seeds: the writer folds its
records into a state (digests of its ordinary records), re-emits it with
`append_checkpoint`, drops its prefix only behind the newest checkpoint,
and never cuts into one; every recovery checks that replaying from
`Recovery::checkpoint` gives exactly the state the whole history gives
(2,128 replays judged on 3,000 paper seeds) and that once the prefix is
gone a checkpoint is always there. Ignoring the count in `checkpoint()`
turns it red (harsh seed 48: a cut fragment named as the checkpoint).
Removing a cut tail checkpoint at open, an earlier draft, turned it red
too (harsh seed 243: a fragment the caller had adopted by cutting inside
it). 3,000 seeds of each model pass.

Targeted tests (they did not compile before: the API did not exist):
- `a_damaged_checkpoint_is_passed_over_for_the_one_before_it`: damage C2
  through the atlas, C1 is named; damage C1 too, `None`, all history live.
- `a_crash_mid_checkpoint_leaves_the_one_before_it`: crash one step short
  of the checkpoint's sync on a disk that loses every dirty sector, under
  `Truncate` and `Keep`: the log ends where it began, the previous named.
- `a_checkpoint_cut_short_is_never_named`: a suffix truncation through C2
  leaves intact entries, C1 is named.
- `a_checkpoint_is_never_split_across_segments`: 20 entries after 120 of
  128 slots roll over first; 129 entries are `CheckpointTooLarge`.

Closes #302

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tq9joyAz9Y6ptfKQB1bnnh
…e twin of network_fault_mask

`Chaos::Storage` was all or nothing. A system under test can be honestly
out of contract for a family: a replicated log on a local journal cannot
survive a phantom write dropping both writes of an acknowledged append (one
forgotten vote breaks quorum intersection), and a disk that fails for good
needs a watchdog it may not have yet.

`SimulationBuilder::storage_fault_mask(StorageFaultMask::all().without(
StorageFault::PhantomWrite))` works like `NetworkFaultMask`: one
`StorageFault` per family in `StorageConfiguration` (`Corruption`, `Eio`,
`Misdirect`, `PhantomWrite`, `SyncFailure`, `ShortTransfer`,
`DirEntryLoss`, `CrashDamage`, `Degradation`, `DiskFailure`), zeroing the
masked probabilities. It is applied after Random/Swarm sampling and after
`apply_buggify_knobs`, immediately before `set_storage_config`, exactly
where the network mask goes. It consumes no draws, so recipes and replay
are unchanged, and the default mask (`all()`) is inert. A mask only
suppresses: it never revives a family the swarm switched off.

Acceptance (`a_storage_fault_mask_keeps_its_family_out_and_draws_nothing`,
in the builder's tests, where the per-iteration world is built): over 24
seeds of `Chaos::Storage(Swarm)` + `BuggifyKnobs` with `PhantomWrite` (and
`DiskFailure`, which would hang the write load) masked, the rng call count
is identical with and without the mask, the installed world has both
probabilities at zero (while some unmasked seed drew phantom writes), and
a 400-write load records no `PhantomWrite` in
`take_storage_fault_records()`. Dropping the `PhantomWrite` arm from
`apply_to` fails it at seed 2. The book's storage-faults chapter and the
fault reference gain the mask and its field mapping.

Builds on the implementation first drafted in #290.

Closes #292

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tq9joyAz9Y6ptfKQB1bnnh
A process that restarts without a power loss — a graceful reboot, the
process alone crashing — finds its predecessor's unsynced writes still in
the page cache. `Journal::open` took them into the log and returned, never
syncing them; the caller acted on them (a Paxos acceptor answers the next
`Prepare` with the accept it finds), and the next power loss could take
them back. `Segment::recover` now syncs the segment before returning, so
every entry opening reports is durable; PostgreSQL and RocksDB fsync their
logs on recovery for the same reason. One `fdatasync` per segment per open.

Found by the journal example under `Chaos::Storage(Random)` (the next
commit): seed 1866840337034485835 — an unacknowledged batch landed, a
graceful reboot reopened over it and the node adopted it, a crash then
rolled its slot sector back to the reserved records, and the node lost
three entries it had adopted (`no acknowledged entry is lost`, next 373 <
376).

Red before, green after: `what_opening_reports_survives_the_next_power_loss`
(an append stopped one step short of its sync, a reopen without a crash
that reports it, then a crash on a disk that loses unsynced sectors: the
entry was gone, `next_index` 4 instead of 5). The crash loop now ends one
round in four with the process restarting rather than the power (4,624
restarts on 3,000 paper seeds), which on the unsynced open fails at harsh
seed 9 and paper seed 101; the open-retry bound rises to 256, since an open
now issues a sync per segment and syncs fail up to one in ten there. 3,000
seeds of each model pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tq9joyAz9Y6ptfKQB1bnnh
…(Random), keeping the ambiguous tail

The journal simulation ran crash attrition on the default disk only. It now
adds `Chaos::Storage(ChaosMode::Random)` with a `storage_fault_mask` (#292)
that leaves out what a lone node cannot repair — corruption, EIO,
misdirected and phantom writes, disk failure — and keeps the crash physics
(lost, latent and shorn sectors), lost directory entries, failed syncs,
short transfers and slow-disk episodes. The journal uses
`AmbiguousTail::Keep`, a replicated caller's policy: kept ambiguous entries
are discarded by the node's reconcile, which plays the replication layer.

A failed sync (any I/O error) poisons the journal, and the node now reopens
it in place, as a caller should, in a fresh epoch
(`an I/O error made the node reopen its journal`); only a non-I/O error
trips the existing assertions. Compaction drops the ledger's guarantee for
the entries before `before` when it starts, not after it returns, so a
crash part-way can no longer leave the ledger expecting entries the journal
already dropped. Every `assert_always!` message is unchanged.

`cargo xtask sim run journal`: 4 runs of 50 seeds green with the journal's
sync-on-open fix (the first run of this configuration, before it, failed
seed 1866840337034485835). The report shows the storage families landing:
sync failures, short transfers, lost/latent/garbage-filled sectors,
correlated rollbacks, stall and throttle episodes.

Refs #299

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tq9joyAz9Y6ptfKQB1bnnh
The book's journal chapter shows the example's new builder (storage chaos
with the lone-node mask, `AmbiguousTail::Keep`, reopen on I/O errors) and
the bug it found; the examples crate's map says the same.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tq9joyAz9Y6ptfKQB1bnnh
paros starts its storage chaos with four families masked (paros#176,
docs/architecture.md §5): phantom writes, a hung disk, barrier violations
and moonpool's slow-disk extremes. `StorageFaultMask` covered the first two
and the stall/throttle episodes, but had no family for sync lies, and none
for the seed-wide slow disk `apply_buggify_knobs` spikes IOPS (100–5,000)
and bandwidth (1–20 MB/s) to — a performance knob, not a probability, so
zeroing could not express it.

- `StorageFault::BarrierViolation` zeroes `barrier_violation_probability`
  (no Random or Swarm profile draws it; a hand-made one may).
- `StorageFault::SlowDisk`: the builder keeps the profile as sampled before
  the knobs, and a masked `SlowDisk` restores its IOPS and bandwidth after
  them. The knobs still draw, so no seed's draw count moves.

`a_masked_slow_disk_keeps_the_sampled_throughput`: over 64 seeds of
`Chaos::Storage(Random)` with buggify fully active, the masked world keeps
exactly the throughput the unknobbed profile sampled while some unmasked
seed was spiked, with the same rng call count as unmasked. The mask unit
test covers `BarrierViolation`. Book: the configuration appendix and the
fault reference list both families.

Refs #292

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tq9joyAz9Y6ptfKQB1bnnh
@PierreZ
PierreZ force-pushed the claude/journal-issues-299-304-292 branch from d914eab to 540943c Compare October 6, 2026 06:16
@PierreZ PierreZ changed the title Storage contract for paros: #293–#304 and #292 (redoes #298) Storage contract for paros: #292–#304 (redoes #298, without #295) Oct 6, 2026
claude added 2 commits October 6, 2026 09:03
…amilies

Reverts 540943c. `StorageFault::BarrierViolation` masked nothing: no Random
or Swarm profile draws barrier violations, so under the builder the family
was dead code. `StorageFault::SlowDisk` undid the buggify knobs' throughput
spikes, a performance knob rather than a fault family, which broke parity
with `NetworkFaultMask`. `StorageFaultMask` keeps the ten families that zero
a sampled probability.

Refs #292

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tq9joyAz9Y6ptfKQB1bnnh
…text::storage

`FaultContext::storage(ip)` handed a fault injector an ordinary provider on
a node's disk. Its reads were real storage operations: they took simulated
time, drew randomness and rolled that disk's fault coins, so aiming an
injection perturbed the run, and the read meant to locate a record could
itself come back damaged.

`FaultContext::durable_bytes(ip, path)`, backed by
`SimWorld::process_file_durable_bytes`, returns a copy of the file's
durable image instead: the bytes as of its last successful sync, which a
crash keeps and `corrupt_bytes` addresses. It takes no simulated time,
rolls no coin and draws nothing.

The #296 injector test now aims with it and checks the draw count is
unchanged. A new storage test checks it leaves out an unsynced write,
reads only the named node's file (another node's damage stays its own),
returns `NotFound` for a missing file and draws nothing. Book: the
storage-faults chapter.

Refs #296

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tq9joyAz9Y6ptfKQB1bnnh
@PierreZ
PierreZ merged commit 160d897 into main Oct 6, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment