# An etcd key version is not a durable incarnation identifier

## Finding

An atomic condition can be evaluated correctly and still protect the wrong
property. In etcd v3.6.16, a stale equality check on a key's `version` accepted a
delete-and-recreate history, including recreation with different bytes. Its
version was 1 both before deletion and after recreation. This is expected API
behavior, not an etcd defect.

A creation-revision condition rejected recreation but accepted modifications to
the surviving key. A modification-revision condition rejected both kinds of
intervening writes. All five tested guards accepted an unrelated-key update.
These are native controlled observations, not simulated results or failure rates.

## Why this belongs in Hesela

The existing [compare-and-swap definition](https://hesela.dev/terms/compare-and-swap/)
already warns about value A-B-A and documents version reset, but does not connect
those facts to choosing an actual condition. The existing
[storage consistency analysis](https://hesela.com/analyses/storage-consistency-ordering/)
separates atomic updates from other guarantees. This packet supplies executable
evidence for that distinction, without inventing a new article or synonymous term.

The useful contribution is the cross-check: API metadata, native execution and
the exact comparison implementation agree. We do not claim to have discovered
the ABA problem or a new theorem.

## Method

One official Linux amd64 etcd 3.6.16 binary was tested in three freshly initialized
single-member clusters. Each cluster ran on loopback in an isolated temporary
directory. The harness shut down and waited for its own server before returning.

Eight explicitly ordered histories were each tested with five conditions:
VALUE, VERSION, CREATE, MOD and the conjunction CREATE + VERSION. Every case used
a new key initially holding A at version 1. The first observer retained that
snapshot. After the intervening history, one transaction tested the stale
condition and either wrote `stale-write` or read the current value without
modifying it. A final read checked the result. The schedules are sequential
interleavings chosen to exhibit stale observations; there are no timing races
or claims about a population of production workloads.

The endpoint is etcd's real JSON/gRPC gateway, not an emulation. Values and keys
are base64-encoded and 64-bit integer fields are sent as decimal strings. The
gateway mapping is described in the
[official gateway documentation](https://etcd.io/docs/v3.6/dev-guide/api_grpc_gateway/).

See [the generated table](results.md), [machine-readable results](results.json)
and the three raw captures. Each capture contains 40 distinct condition/history
pairs and the complete requests and parsed JSON responses. Across runs, 120
case observations were retained. This is a selected deterministic matrix, not
a random sample; confidence intervals and percentages would misrepresent it.

## Interpretation

**VALUE equality:** it asks whether the present bytes equal the observed bytes.
In-place A-B-A and deletion followed by recreation of A both satisfy it.
That can be exactly the intended condition for a state-based operation.

**VERSION equality:** it detects the tested in-place writes, including writing
A over A, but loses identity across deletion. In the recreate-with-B case it
accepted even though both the creation revision and the value had changed.

**CREATE equality:** it distinguishes the observed key's lifetime from a later
creation at the same name. It intentionally does not distinguish updates within
that lifetime. Using it alone for an unchanged-read check is insufficient.

**MOD equality:** it distinguishes the tested key modifications since the read.
Use the observed key's `mod_revision`, not the response header's store revision:
an unrelated write can advance the latter without modifying this key. The
unrelated-key control demonstrates that a key-level guard need not reject such
an update. These interpretations follow the fields defined in the
[pinned protobuf](https://github.com/etcd-io/etcd/blob/0b065e61c679ea81f6862bb24c9815f7fc673966/api/mvccpb/kv.proto)
and are checked against the native results.

**CREATE + VERSION:** the tested conjunction rejected both in-place modification
and recreation. This does not establish universal equivalence to MOD under all
operations, range predicates, restore histories or overflow conditions.

A correct CAS does not prove that nothing happened since an earlier read. It
proves its actual predicate held at the atomic operation. Which historical
changes the predicate can distinguish depends on the selected metadata.

## From source to observation

The [etcd API documentation](https://etcd.io/docs/v3.6/learning/api/) names the
per-key fields, distinguishes the global store revision and defines a transaction
as a conjunction of comparisons followed by one branch. Its examples are a
contract, not evidence that every predicate protects the same property.

At source commit `0b065e61c679ea81f6862bb24c9815f7fc673966`,
[`applyCompare` and `compareKV`](https://github.com/etcd-io/etcd/blob/0b065e61c679ea81f6862bb24c9815f7fc673966/server/etcdserver/txn/txn.go)
select the requested field. Missing-key value comparison fails; the non-value
path compares against zero-valued metadata. Therefore a zero-version test is
an absence check at execution, not proof that the name has never existed.
That last consequence is source-derived; this matrix starts with present keys
and does not experimentally test the zero-version predicate.

[`storeTxnWrite.put`](https://github.com/etcd-io/etcd/blob/0b065e61c679ea81f6862bb24c9815f7fc673966/server/storage/mvcc/kvstore_txn.go)
retains an existing key's creation revision, sets its modification revision to
the current write revision and increments its version. A fresh key starts a new
creation. Our same-bytes control confirms that an ordinary Put is still counted
as a modification even when its payload equals the prior payload.

## Scope and limits

The findings concern single-key equality predicates and ordinary Put/Delete
operations in one uninterrupted logical cluster history. No lease expiry,
compaction, restart, leader loss, network partition or snapshot restore was run.
There is one server build and one host environment. Fresh clusters are a
repeatability check, not independent peer review or cross-version validation.

Do not promote a numeric revision to an eternal cross-cluster identity. The
[recovery documentation](https://etcd.io/docs/v3.6/op-guide/recovery/) explains
that restoring an older snapshot may move the observed revision backward and
creates a new logical cluster. Its revision-bump guidance addresses recovery
consumers; it is not experimentally validated here and is not a blanket proof
that stale key tokens are safe across restore.

Nor does a successful metadata comparison fence a delayed write to an external
storage system. The protected update must be inside the appropriate atomic
operation, or the destination needs its own checked fencing contract. This is
an engineering consequence of the operation's scope, not a distributed fault
test. A timeout can leave completion unknown, as the
[API guarantees](https://etcd.io/docs/v3.6/learning/api_guarantees/) warn.

## Reproduce

Python's standard library is sufficient. Obtain the official etcd 3.6.16
Linux amd64 release and verify the archive before execution:

```sh
gh release download v3.6.16 --repo etcd-io/etcd --pattern etcd-v3.6.16-linux-amd64.tar.gz --pattern SHA256SUMS
sha256sum -c --ignore-missing SHA256SUMS
tar -xzf etcd-v3.6.16-linux-amd64.tar.gz etcd-v3.6.16-linux-amd64/etcd
python3 experiment.py --etcd ./etcd-v3.6.16-linux-amd64/etcd --output fresh-capture.json
python3 verify.py fresh-capture.json
python3 -m unittest -v test_evidence.py
python3 -O -m unittest -v test_evidence.py
python3 report.py
```

Run the Python commands from this packet directory. The harness refuses to
overwrite an existing capture. It has no option to connect to an existing
cluster. Only its own disposable database is changed.

Official release archive SHA-256:
`c8c0d96d8292ef085deabbf735e9561d3d396768e4d606df005aa25964f21911`.

Extracted tested binary SHA-256:
`769222687e03cb2ee0c420193a5012d4ff2a35a47e8f27ae9540dd2acfa3ac49`.

The archive matched both the upstream SHA256SUMS entry and GitHub release asset
digest. These are provenance checks from the same publisher, not independent
software audits. Version output and host details are embedded in the captures.

## Evidence and rights

`source-receipts.json` records seven fetched resources: six technical sources
and the upstream license, with URLs, access times, locators and SHA-256 hashes.
The code commit is pinned; web documentation may change later. Copies retained
outside Git are research evidence, not republished pages. etcd is Apache-2.0;
its binary and source are not redistributed in this packet. The harness,
verification logic and synthesis are newly authored for Hesela. No new license
is asserted for the repository or for third-party text.

Publication review on 2026-11-29 added a third fresh-cluster capture and tightened
the verifier. The old verifier accepted a changed cluster ID or read-header
revision in otherwise unchanged evidence. Negative controls now reject those
mutations, mixed member IDs, wrong branch revisions and incorrect deletion
counts. This repairs Hesela's evidence validation, not etcd.

For the conceptual boundary, see [publication review](publication.md).
Publication and deployment acceptance are recorded separately in the repository
handoff; these native observations alone do not establish site acceptance.
