# etcd snapshot restoration: the watcher boundary is part of recovery

Native research and publication replay, 28 November 2026. Scope issue #7918.
This extends existing recovery coverage; it is not a new storage failure-rate
study or independent peer review. The public packet preserves raw observations,
snapshot bytes, source receipts and tests. A fourth clean publication replay
is retained in capture-d; all four captures have identical normalized outcomes.

## Finding

A correct etcd snapshot restore does not establish that a client's retained
cache agrees with the restored keyspace. In pinned etcd **3.6.16**, a resumed
watch starting exactly at the marked compaction revision was accepted.
It delivered new updates, yet a key unchanged since restoration retained the
wrong value in our deliberately naive cache reconstruction.

For snapshot revision **3** and a saved next-watch cursor **6**:
- No bump, or bump **1**, delivered the heartbeat at revision 6 but missed
  the earlier post-restore update.
- Bump **3** with `--mark-compacted` restored revision 6. The watch delivered
  revisions 7 and 8 without cancellation; the unchanged key remained stale.
- Bump **4** or **100**, with the same flag, canceled that old cursor at
  compaction revision 7 or 103.
- An explicit current-range read followed by a watch from its revision plus
  one recovered the exact constructed state in every case.

These are five designed cases, each repeated on a separate fresh source
cluster and snapshot, not five independent samples of production behavior.
Two invalid flag combinations were also run in each capture. The CLI rejected
bump-without-mark and mark-without-bump; we did not fabricate a successful
bump-only restore.

See [the generated table](table.md), [machine-readable results](results.json),
and the complete [first](capture-a/capture.json) and
[second](capture-b/capture.json) native transcripts. A third execution from
an archive of source commit 8c8d4cef9e62635c541f6c87a419040ea2f654ca
matched both original runs; its full evidence is in [capture-c](capture-c/capture.json).

## Why the boundary matters

The [recovery guide][recovery] explains the revision rollback problem and
recommends a bump with compaction for watch consumers. The [watch API][api]
defines an inclusive start revision. Its [guarantees][guarantees] depend on
available history; they do not promise seamless continuation across an
operator-created replacement cluster.

The pinned [restore implementation][engine] advances the latest revision and
records a scheduled compaction point. It does not manufacture all the events
needed to transform a later client cache back into snapshot contents.
The [watcher selection code][group] cancels when `minRev < compactRev`,
not when the values are equal. This exact inequality explains the equality
control. The [watch registration code][store] also preserves a requested
future starting revision rather than lowering it to an earlier restored state.

Consequently, for this implementation and a known resumed cursor W, a marked
boundary C must satisfy **C > W** to force that cursor's compaction rejection.
With snapshot revision S and bump B, the fixture tests C = S + B. For integer
counters, B >= W - S + 1 is the arithmetic boundary when a positive bump is
required. This is a derived condition for a known cursor, not an operational
recommendation to use the minimum bump. Real recovery needs an adequately
conservative bound on all relevant client cursors and documented behavior
when that bound is unknown.

The number of modified keys is not interchangeable with the revision delta:
one modifying transaction can change multiple keys at one revision.
A restored high counter also does not recover post-snapshot values.

## Experiment and evidence chain

1. Start a single-member server on dynamically selected loopback ports.
2. Write two synthetic keys, reaching revision 3, and save a native snapshot
   with etcdctl. Its SHA-256 footer is retained and independently checked.
3. Change both keys, reaching revision 5; retain that full client view and
   next cursor 6. Stop the original server cleanly.
4. Restore the same snapshot with each option set into a new private directory.
   No integrity-check bypass is used. Record both values and per-key metadata.
5. Change one key after restoration. If necessary, advance the store with a
   clock key outside the watched prefix, then create a heartbeat within it.
6. Open a new watch from cursor 6 and read until the positive heartbeat event
   or explicit compaction cancellation. A timeout is a failed experiment,
   never evidence that an event was absent.
7. Apply returned native events to the retained view in a small explicit
   Python cache model; compare it with a current native range response.
8. Independently relist, change the key again, and read a watch from the relist
   revision plus one. Check exact equality with the final native range.

The network operations, restored state and watch messages are native etcd
observations. Applying events to a dictionary is an application-level
counterexample model, not a running Kubernetes informer. The old cursor is
intentionally reused despite the changed cluster identity. Cluster-aware
clients may invalidate earlier; this packet does not generalize behavior
to every client.

`experiment.py` produces raw captures. `verify.py` separately checks the
designed state transitions, identities, flags, exact event sets, cancellation
boundaries, snapshot bytes and repair controls. `report.py` derives the table.
`test_evidence.py` includes altered-evidence rejection controls. Assertions
essential to validation use explicit exceptions and remain active with
Python optimization.

## Reproduction

Use Python 3.11+ with its standard library on Linux amd64. No Python package
installation, root permission, external service or production endpoint is
needed. Download the official [3.6.16 release archive][release], verify it
against the publisher's SHA256SUMS, and extract etcd, etcdctl and etcdutl.
The harness also refuses binaries whose exact hashes differ from the tested
release. Binary and source receipts are in [source-receipts.json](source-receipts.json).

From this directory:

```sh
python3 experiment.py --bin-dir /absolute/path/to/bin --output replay
python3 verify.py capture-a/capture.json capture-b/capture.json replay/capture.json
python3 -m unittest -v test_evidence.py
python3 -O -m unittest -v test_evidence.py
python3 report.py
```

The output directory must not exist. Allow roughly 0.5 GiB temporary disk
headroom for etcd's WAL files; the retained snapshot is much smaller.
Only disposable data directories are removed automatically. Native processes
are terminated and reaped even on ordinary exceptions. The usual
bind-close-start port-allocation race can cause a failed run; it does not
license killing another service. No benchmark timing is inferred.

Snapshot bytes, cluster IDs, ports and log timestamps can differ between
runs. Exact logical outcomes must match; whole-capture hashes identify
specific retained runs rather than promise byte-identical fresh captures.
The tiny snapshot images contain only invented keys plus cluster metadata.
Full upstream pages/code are retained privately by URL and digest, not copied
into this packet. Authored code and fixtures: MIT; etcd binaries: Apache-2.0.

## Limits and contribution

One host and one pinned build; no Kubernetes, real workload, multi-member
failover, crash/power-loss injection, concurrent writers, lease recovery,
performance test or frequency estimate. The source server was stopped cleanly
after capture. The repeated captures are reproducibility checks, not confidence
intervals. No claim of a newly discovered vulnerability.

This adds a consumer-state acceptance condition to Hesela's existing
[backup-verification analysis][hesela-backup] and
[snapshot recovery analysis][hesela-snapshot]. Existing #7895 separately
studies key-incarnation comparisons. This packet does not modify its evidence
or imply that revision-based CAS remains a cross-restore identity guarantee.

The practical contribution is a reproducible counterexample to the
assumption that a successful restored database plus a working event stream
proves cache recovery. [integration.md](integration.md) preserves the original pre-publication
proposal as historical context. The existing analysis and restore-test entry
link the evidence; the publication table is generated from validated results.

[recovery]: https://etcd.io/docs/v3.6/op-guide/recovery/
[api]: https://etcd.io/docs/v3.6/learning/api/
[guarantees]: https://etcd.io/docs/v3.6/learning/api_guarantees/
[engine]: https://raw.githubusercontent.com/etcd-io/etcd/v3.6.16/etcdutl/snapshot/v3_snapshot.go
[group]: https://raw.githubusercontent.com/etcd-io/etcd/v3.6.16/server/storage/mvcc/watcher_group.go
[store]: https://raw.githubusercontent.com/etcd-io/etcd/v3.6.16/server/storage/mvcc/watchable_store.go
[release]: https://github.com/etcd-io/etcd/releases/download/v3.6.16/etcd-v3.6.16-linux-amd64.tar.gz
[hesela-backup]: https://hesela.com/analyses/backup-verification-is-not-a-restore-test/
[hesela-snapshot]: https://hesela.com/analyses/snapshot-backup-recovery-boundaries/
