# Atomic Name Exchange Does Not Give a Reader a Snapshot

## Result

A complete two-name list, two successful file reads and matching captured/restored
SHA-256 digests can coexist with omission of one of two live objects. In our
controlled Linux fixture, an atomic exchange between the two opens made both
reads select the same inode. Exchanging the names back also made the beginning
and ending name-to-inode maps agree, without repairing the captured pair.

This is an executed counterexample to an acceptance rule, not a newly discovered
Linux bug. Hesela's existing rename article already warns that separate lookups
can straddle an exchange. This packet makes that warning independently
reproducible and connects it to inventory validation.

## Why This Adds Value

The existing directory-walk experiment moves one file across a scan frontier,
producing zero or two observations. Here **both names remain present and exactly
two names are captured**. The mismatch is between names and distinct objects,
not a missing name or failed operation. The ABA control also defeats a simple
begin/end identity comparison. Neither result requires changing file contents.

The hard-link control prevents the wrong fix: one distinct inode for two names
can be entirely correct when both names intentionally reference the same object.
A validator needs the intended relationship, not a rule that every name must
have a unique inode.

## Method and Population

- Host: Linux 6.8.0-149-generic, x86_64, glibc 2.39, Python 3.12.3, effective UID 1001.
- Filesystems: ext4 and tmpfs on the same host; mount options are retained.
- Seven schedules, two read orders, two filesystem locations, two repetitions:
  56 recorded executions in observations.json.
- A fresh 56-execution run under Python -O is retained in replay.json. Its
  derived summary is identical, although inode numbers and times legitimately differ.
- Two 64-byte files contain distinct fixed payloads. Only the hard-link control
  uses one object with two names. Source data is generated, not field telemetry.
- The harness completes enumeration before exchanging names. It retains original
  descriptors as an identity/content oracle, preventing inode-reuse ambiguity.
- Every read uses a new descriptor-relative open, followed by fstat and pread,
  except the pinned-before control, which opens both descriptors first.
- renameat2(RENAME_EXCHANGE) is invoked through the libc ABI, with typed ctypes
  arguments and immediate error handling. This is a native operation, not a model.
- Scheduling is deliberately sequential: reads and exchanges are interleaved at
  fixed boundaries. No timing lottery, external writer or probabilistic race.
- Each read's bytes are written to a disposable destination and read back. Hash
  equality compares that copy with the bytes actually captured, not a separately
  established name-to-content snapshot.

No original source object is removed or modified during observation. The fixture
and copied bytes are cleaned only after all observations have been collected.
Private temporary directories ensure no existing user tree is scanned or changed.

## Schedules and Results

The machine-generated table is in table.md and the structured form is summary.json.
Each row summarizes eight agreeing executions per capture, not independent devices.

1. stable: open/read both names without an exchange.
2. exchange_before: exchange first, then open/read both names.
3. pinned_before: open both names before exchange, then read the held descriptors.
4. between_opens: read the first name, exchange, then read the second name.
5. aba: the preceding schedule, then exchange back before final inspection.
6. guarded_aba: compare each opened object's identity with the retained initial
   per-name oracle; decline the mismatched second read and mark capture incomplete.
7. hardlinks: two names deliberately reference one inode, with no exchange.

Both interleaved unguarded schedules capture one distinct object twice. The
other object remains readable through its held oracle and remains named in the
source. Their name-to-object capture is neither the pre-exchange nor the
post-exchange state. In ABA, final identities return to their initial values.

The guard detects this fixture's second mismatch, but does not complete the copy.
It is a fail-closed demonstration with a stable, deliberately constructed oracle,
not a portable snapshot protocol. Acquiring that oracle on an independently
changing real tree would itself require coordination.

Opening both descriptors before the sole exchange works in this schedule.
Opening them sequentially while an exchange occurs between them is exactly the
failing schedule. Therefore "use descriptors" is necessary for some identity
problems but insufficient as a general multi-object capture prescription.

In the table, "Accepted" means only that the fixture rule saw two completed
captures and no identity-guard rejection. It is deliberately weaker than snapshot
acceptance and is not the verdict of any backup product.

## Four Separate Acceptance Questions

| Question | Evidence needed | What this experiment shows |
|---|---|---|
| Were all required names discovered? | An expected name set and explicit exclusions/error policy | Both names were discovered before mutation. |
| Which objects did those names select? | Identity attached to each actual open, with a valid reference | Two names can select the same original object. |
| Did the copied bytes change? | A byte reference with clear origin | Every captured/restored digest matched. |
| Do all captured bindings belong to one valid view? | A view identifier or a validated capture protocol | The duplicate pair is in neither legal namespace state. |

The last conclusion combines the observed call order with the documented atomic
exchange contract. We did not instrument every instant inside the kernel or
attempt to re-prove rename atomicity. Retaining before/after states alone would
not suffice for arbitrary unobserved mutations; here the harness owns every
mutation and never overlaps operations.

## Connection to Research and the Existing Corpus

Linux documents atomic exchange and descriptor lifetime separately [rename, open].
Kernel directory-locking documentation describes individual namespace primitives,
not a transaction spanning multiple application opens [locking].
ViewBox's FAST 2014 design instead synchronizes frozen views [viewbox]. Its
single-client and multi-client guarantees differ; this packet does not reproduce
its kernel, cloud protocol, corruption injection or performance evaluation.

Existing Hesela work remains authoritative for its own scope:
- Published tmpfile/rename article: operation contracts and held descriptors.
- Published inotify analysis: directory-walk frontier and notification boundaries.
- PR #4022 and publication drafts #4119/#4120: cached metadata versus opened
  object/content; those are different fixtures and should not be relabeled here.
- PR #5466 and drafts #5474/#5475: suppressed traversal errors.
- PR #5472: duplicated directory descriptors and lost userspace prefetch.

Sources and exact locators are in SOURCE_REVIEW.md and sources.json.
The proposed integration extends the existing rename article and its existing
rename-exchange record; it creates no competing article or duplicate term.

## Reproduce

Run from this directory with Linux, Python 3, libc renameat2 and findmnt:

    python3 study.py --directory . --directory /dev/shm --output fresh.json --summary fresh-summary.json
    python3 -m unittest -v test_study
    python3 -O -m unittest -v test_study

Output paths must not exist. Unsupported operations abort; they are not silently
skipped or labeled passing. Fresh matrix sizes can differ if different roots or
repetition counts are requested; the checked-in evidence tests require the
recorded 56-execution design.

For offline evidence replay, with no native fixture execution:

    python3 study.py --replay observations.json --output checked.json --summary checked-summary.json

The standard unittest suite includes 14 small native controls on the current
temporary filesystem. It also rejects dropped/duplicated observations, changed
digests, corrupted identities, impossible swaps and missing/reordered events.

Create a standalone package with python3 package.py --output fresh.zip.
The archive has an explicit member list, source hashes and a deterministic layout.
Its manifest detects accidental modification, not malicious replacement by an
untrusted distributor. Third-party full texts are not included.

## Limits

This is one host and two local filesystem types, not a failure-rate population.
The repetition denominator describes executions, not empirical risk.
We tested no backup utility, NFS/SMB, power interruption, concurrent in-place
write, snapshot implementation, openat2 policy or application transaction.

We do not claim identical mtime/ctime values across exchange, only endpoint
identity equality in ABA. A stable inode does not make its content immutable.
The hard-link control preserves name-to-object mapping in the evidence, but the
disposable copied outputs are separate files: hard-link restoration fidelity is
not tested. Restored inode numbers are not expected to match source inode numbers.

All generated fixtures and observations are authored by Hesela. No new dataset
license is assigned here; follow repository and site reuse policy before public
distribution. Source receipt hashes identify downloads, not permission to
redistribute third-party material.

Status: research candidate, not independently reviewed or site-integrated.
No merge, deployment, visual QA, SEO gain or background execution is implied.
