# CRAQ read-selection examples

These are Hesela's constructed snapshots, not a CRAQ implementation, benchmark,
formal proof of the full protocol or reproduction of paper measurements.
No network, filesystem fault injection or external dependencies are used.
The original model, generator and tests are released under CC0-1.0.

Run with Node.js 22 or newer:
```sh
node --test model.test.mjs
node generate.mjs --write
```

The generator records source SHA-256 digests and deterministic output. It omits a
changing timestamp; the editorial creation date is 2026-10-22. No random seed is
needed. Keep the original three snapshot modules together. The default command prints JSON.

## State and interpretation

Each node has a latest received version and a highest acknowledged clean version.
The tail commits on receipt. Writes move head to tail; acknowledgements move back.
The explorer enumerates reachable snapshots by delivering one next version at a
time. An independent test enumerates ordered integer tuples instead of replaying
the transition code. The three-node/two-write report contains 21 snapshots and
63 node reads. These counts are coverage, not failure frequencies.

The deliberately incorrect newest-local and last-clean policies generate two
sequential-read counterexamples: 1 then 0. The selected CRAQ-style policy returns
the tail's version in every frozen snapshot. Retained versions span clean through
latest. Actual message overlap, garbage collection, membership changes, retries,
fault detection, disk persistence and availability are outside this model.

## Primary sources

- Jeff Terrace and Michael J. Freedman, Object Storage on CRAQ, USENIX ATC 2009:
  https://www.usenix.org/legacy/event/usenix09/tech/full_papers/terrace/terrace.pdf
- Robbert van Renesse and Fred B. Schneider, Chain Replication for Supporting
  High Throughput and Availability, OSDI 2004, pp. 91-104:
  https://www.usenix.org/legacy/events/osdi04/tech/full_papers/renesse/renesse.pdf

Read the source review and scope in the companion analysis:
https://hesela.com/analyses/replication-acknowledgements-durability-lag/#craq

## Completed-operation supplement, 2026-10-22

The original snapshots and results.json are unchanged. A separate read-history
checker tests four original histories of one register initially equal to zero.
It searches sequential orders that obey every response-before-invocation edge
and the register's sequential specification. Event positions are unique logical
indices, not synchronized wall-clock timestamps.

Run:
```sh
node --test read-history.test.mjs oracle-review.test.mjs
node generate-histories.mjs --write
```

histories.json includes a witness order or null and SHA-256 hashes. The checker
accepts at most six completed, successful operations. It rejects duplicate IDs,
tied event positions and invalid values. Tests compare all six read/write interval
orders against an independent two-operation oracle, including an impossible
returned value. An independent unpruned oracle also checks all 5,760 three-operation
histories with binary values, initial value zero and distinct event positions.
Overlapping reads may complete in reverse value order; sequential
reads cannot reverse unless an intervening write restores the old value.

This is not a general-purpose production history checker. It does not complete
pending operations, model failures, retries or CRAQ messages, establish convergence,
resolve delayed-query/version-deletion races, or measure availability or durability.
A finite history cannot establish the eventual-convergence liveness property.

Additional primary sources:
- Herlihy and Wing, Linearizability, 1990, section 2.2:
  https://www.cs.columbia.edu/~wing/publications/HerlihyWing90.pdf
- Werner Vogels, Eventually Consistent - Revisited, 23 December 2008:
  https://www.allthingsdistributed.com/2008/12/eventually_consistent.html
- DeCandia et al., Dynamo, SOSP 2007, section 4.4:
  https://www.allthingsdistributed.com/files/amazon-dynamo-sosp2007.pdf

## Delayed-query supplement, 2026-10-23

The two original reports remain byte-identical. A separate source-path model
enumerates five events after a read has started at a dirty replica. Initially,
local versions are 1 and 2, with 1 committed at both replica and tail. Events:
query the tail, commit 2, acknowledge 2 locally, receive uncommitted 3, and resolve
the query. ACK follows commit and resolution follows query; other orderings vary.
This admits 30 schedules. Four reach the selected extended-fallback mismatch.
These are finite coverage counts, not rates or a workload distribution.

Run:
```sh
node --test reclamation.test.mjs
node generate-reclamation.mjs --write
```

The independent positional oracle derives outcomes from event indices instead
of replaying transitions. Original CRAQ source is NOT executed or redistributed.
The model ignores network connection ordering, Tame scheduling, asynchronous
storage callbacks, RPC failures and membership changes. Its checked alternative
illustrates matching committed data and metadata, not a generally verified fix.

Pinned implementation: https://github.com/jterrace/craq/blob/c394900b4da384abc7af2a2723140c693778e767/chain_node.Tc
Repository commit c394900b4da384abc7af2a2723140c693778e767, dated 2012-02-09.
Raw chain_node.Tc SHA-256:
21cd06ddd5ea77b841a76352caf5519f2cf3621ad79644274007c780ed5d6b5c.
Review process_tail_read, process_tail_read_ex and process_ack together.
This archived revision is not asserted to be the exact 2009 evaluation binary.
