# Reconstructing with mixed stripe versions

A correct XOR operation can return the wrong block when its inputs describe
different stripe states. Cache durability and input consistency are separate
requirements: preserving bytes does not establish which version belongs in
a reconstruction.

This is a constructed teaching example using one-byte units, not a RIMAC
implementation, replication, hardware test or newly discovered RIMAC defect.
The values are chosen for readable hexadecimal arithmetic.

## One update, four reconstruction paths

Let A = 0x3c and B = 0xa5. Parity P = A XOR B = 0x99.
Change B to 0x5a while A is unchanged. The matching new parity is
0x66, either by recomputing A XOR B or by P_new = P_old XOR B_old XOR B_new.

| Survivor B | Parity | Reconstructed A | Interpretation |
| --- | --- | --- | --- |
| 0xa5 | 0x99 | 0x3c | Consistent before update |
| 0x5a | 0x66 | 0x3c | Consistent after update |
| 0x5a | 0x99 | 0xc3 | New survivor, old parity |
| 0xa5 | 0x66 | 0xc3 | Old survivor, new parity |

For one changed survivor and an unchanged missing target,
A_reconstructed = A XOR B_old XOR B_new.
Any actual single-survivor change therefore changes the reconstructed target.
The four-bit exhaustive check covers 16 x 16 x 15 = 3,840 input triples, all
wrong when new B is combined with old parity. This is an algebraic domain,
not a sample of disks, an estimated error probability or a confidence interval.

With more changed survivors, their XOR differences can cancel. The tests
include that counterexample, so the single-change conclusion must not be
generalized to every mixture of versions.

## Consistent parity can still describe old data

Now update A from 0x3c to 0x42, leaving B = 0xa5. Suppose the latest A and
matching parity 0xe7 are only in protected cache; disk still holds the old
state with parity 0x99. If both current cached values are lost before destage,
disk-only reconstruction returns 0x3c. Its parity check passes, yet it is
not the intended latest A. A trustworthy retained current parity instead
reconstructs 0x42 from B.

This is a hypothetical loss of required state, not a claim that the RIMAC
design loses its protected cache. The arithmetic does not model battery
failure, acknowledgement ordering, crash recovery or atomic cache updates.
A parity comparison alone supplies neither the intended version nor an
independent reference for the requested content.

## Connection to the sources

The [RIMAC corpus entry](https://hesela.dev/terms/rimac/) describes the paper,
its protected-cache assumptions and its separate read paths. The paper's
section 4.2 explicitly updates parity immediately. Deferred member writes
must not be misread as permission to reconstruct from stale parity.

The [Linux v6.12 PPL documentation](https://github.com/torvalds/linux/blob/v6.12/Documentation/driver-api/md/raid5-ppl.rst)
independently explains why inconsistent data/parity after an interrupted
update can damage reconstruction of even an unchanged missing block.
It also distinguishes closing that write hole from preserving in-flight data.
PPL is a separate mechanism, not an implementation of RIMAC.

## Reproduce

Download [model.py](model.py), [test_model.py](test_model.py) and
[results.json](results.json) into one directory. Python 3 uses only its
standard library; no network, packages or storage devices are required.

```sh
python3 -B model.py --check
python3 -B -m unittest discover -s . -p test_model.py
python3 -B -O -m unittest discover -s . -p test_model.py
```

The JSON uses decimal byte values. The model rejects out-of-range values,
booleans, and reconstructions with zero or multiple missing data units.
The tests use an independent bit-counting parity oracle as well as exhaustive
small-domain enumeration. They test these calculations, not a full RAID stack.

Original example and code: Hesela, 2026-11-29. Reuse under CC0-1.0.
Cited papers and documentation retain their own licenses.
