# Current-state repair and historical reads

An exact teaching model accompanying Hesela's replica-repair analysis.
It is not a DIRECT implementation or a reproduced cluster experiment.

## Reproduce

Requires Node.js with ES modules and the built-in test runner, no packages.

```sh
node model.mjs --check
node --test model.test.mjs
```

Run `node model.mjs --write` only to regenerate `results.json`.
All inputs and the enumeration order are fixed; no seed is needed.

## The question

Does a complete, correct current image determine an earlier snapshot?
No. Two histories can have the same current image and different earlier values.
A correct current-state patch therefore does not by itself authorize a historical
read. Refusing a read with insufficient evidence is different from returning an
empty result.

## Model and evidence

One key starts absent. Four logical operations each set A, set B or delete it.
A snapshot at t means the state **after** operations 1 through t. These are
shared logical positions chosen for the example, not local RocksDB sequence numbers.

The observer receives only the intact current state at position 4. Earlier
operations are unavailable. This is deliberately weaker than a verified retained
history, and deliberately stronger than a corrupt or partial current patch.
The model enumerates every compatible history instead of substituting current
data for an older read. `null` means confirmed absence; `unresolved` is a
separate status and never means absence.

There are 81 histories, grouped into three classes of 27 by current state.
Each class has 27 * 26 / 2 unordered distinct-history pairs, hence 1,053 pairs
with matching current state. At each historical position, 729 pairs disagree
and 324 agree. Three historical positions give 3,159 pair-position comparisons.
These are finite counts, not probabilities or observed transaction rates.
The implementation groups histories by current state and then by historical state,
using n * (n - 1) / 2 to count each bucket's unordered pairs. It avoids visiting
all history pairs. The independent pair-by-pair oracle still checks the four-step
example; closed-form checks cover every supported history length, one through eight.

The initial state and the current state are determined by the supplied evidence.
Each intermediate position remains ambiguous. The two matching examples in the
table illustrate accidental correctness: a guessed value can be right without
being justified by the observer's information.

## Boundaries

The counterexample establishes insufficiency of current-only evidence, not that
historical recovery is impossible. An intact historical image with a verified
logical-time mapping may provide the missing information. No disk, compaction,
network, corruption detector, recovery implementation or transaction scheduler
is simulated. No conclusion about a current product's fault behavior follows.

DIRECT's historical design invalidates local snapshots when corruption leaves
their affected versions unknown (Tai et al., section 4.2.5). The separate RocksDB
snapshot documentation explains the local sequence-number scope and timestamped
snapshot coordination. See `sources.json` for source locators.

## Integration

The article links the existing DIRECT, read-repair and MVCC corpus entries.
It does not introduce a new term or change an existing machine-readable schema.
The downloadable model and generated JSON contain no third-party source text.
