# Watchman history continuity: reproducible observations

This is a controlled software experiment, not discovery of a Watchman defect.
The independent contribution is a complete native-response-to-client-state trace:
a valid response can leave an incorrectly maintained index stale.

## Result and method
Six scenarios, two Linux filesystems (ext4 and tmpfs), three repetitions each:
36 executions on one host. Each fixture starts with keep.dat and gone.dat.
All but the quiet control delete gone.dat and create added.dat before querying.
No writer runs concurrently with a query. The exact filename set in the private
fixture is the oracle; this does not validate file contents or a real backup.

Continuous history reports the deletion and addition. Recreating the root watch
makes the old clock fresh: default results contain current names without the old
deletion. Applying those results as a delta leaves gone.dat in the client index.
The empty-on-fresh option instead returns no names; applying it as an empty delta
leaves both a stale name and a missing one. A complete replacement baseline
recovers membership in these quiescent fixtures.

Two other schedules intentionally discard a response. Advancing to its clock
before applying it, or reusing a named cursor already consumed by the query,
produces an empty non-fresh retry. Replaying the earlier explicit clock recovers
the changes while that history remains available. These are deliberately broken
consumer schedules, not injected crashes or server errors.

## Reproduce
Requires Linux, Python 3, findmnt and a compatible Watchman binary. No Python
packages, privileges, network service or global watch removal is required.

```sh
python3 -B observe.py --binary /absolute/path/to/watchman --directory /tmp --directory /dev/shm --repetitions 3 --output replay.json
python3 -B -m unittest -v test_observe
python3 -B -O -m unittest -v test_observe
```

The original binary is Ubuntu noble amd64 watchman 4.9.0-7build4, reporting 4.9.0.
It was downloaded with apt-get download and extracted using dpkg-deb -x, without
installation. libpcre3 2:8.39-15build1 was extracted alongside it. For that private
layout, set LD_LIBRARY_PATH to the extracted lib/x86_64-linux-gnu and
usr/lib/x86_64-linux-gnu directories before executing the runner.
This older packaged version is an experimental target, not deployment advice.
No claim is made that a current release has been run.

Every server has an explicit private socket, log, PID and state file, a blank
global configuration and disabled state saving. Clients cannot spawn another
server or fall back to local mode. Shutdown targets only that socket and waits
for the spawned child. Existing watches are never contacted. Output refuses to
overwrite an existing file. Failed commands, error responses and failed oracles
abort the experiment.

results.json preserves requests, responses, opaque clocks and environmental
versions. Random root path labels alone are replaced by <root>. summary.json is
derived by summarize(), not hand-entered. Replays are not added to the original
sample. Repetitions check stability; these deliberately constructed cases do not
estimate an incidence or require population confidence intervals.

## Interpretation
Treat fresh results as a loss of delta continuity, not proof of no changes.
Replace the complete declared index scope only after a complete successful
baseline. With empty_on_fresh_instance, obtain that baseline explicitly.
Publish index updates and their cursor as one recoverable state transition.
An explicit old cursor enables retry only while its history remains valid.

The query uses a suffix expression, not a suffix generator combined with since.
Generators combine candidates; a filter narrows the selected generator.
A cookie synchronization barrier is not an atomic file-content snapshot.

Not tested: overflow, automatic recrawl, history aging, symlink targets,
daemon restart, concurrent mutation, application capture or power-loss recovery.
Root-watch reset uses watch-del/watch on private fixtures. Documentation
describes broader fresh-instance causes, but this experiment measures only reset
and the selected consumer schedules.

## Sources and rights
Official documentation, accessed 2026-10-21:
- https://facebook.github.io/watchman/docs/cmd/query
- https://facebook.github.io/watchman/docs/clockspec
- https://facebook.github.io/watchman/docs/file-query
- https://facebook.github.io/watchman/docs/cmd/clock
- https://facebook.github.io/watchman/docs/cli-options
- https://facebook.github.io/watchman/docs/troubleshooting

Pinned implementation inspected:
- https://github.com/facebook/watchman/blob/v4.9.0/clockspec.cpp
- https://github.com/facebook/watchman/blob/v4.9.0/query/eval.cpp
- https://github.com/facebook/watchman/blob/v4.9.0/tests/integration/test_since.py

The upstream tests already specify fresh-instance behavior. The v4.9.0
ClockSpec::evaluate checks server identity, root number and age-out position,
and advances named cursors during query evaluation. Query evaluation omits
deleted nodes for fresh instances and honors empty_on_fresh_instance.
No upstream code, documentation text or binary is redistributed here.
Watchman package copyright identifies Apache-2.0 plus component licenses.
manifest.json records source/package and artifact hashes.
Original fixture observations and summary are dedicated under CC0-1.0.
Original runner and tests are MIT-licensed; see LICENSE.
