# Rsync interrupted writes and retry selection

Native, local-path software experiment. This is a reproduction of a documented
warning, not a newly discovered vulnerability or a device-reliability estimate.

## Question

After a real interrupted --inplace --update transfer, can a successful retry with
--checksum or --ignore-times leave mixed old/new bytes? Does temporary-file mode
preserve a different state at the published destination pathname?

## Reproduce

Use Linux, Python 3 and rsync. No root privileges, network peer or real device is
needed. The runner creates private temporary directories and refuses to overwrite
its output file. Allow at least 64 MiB free scratch space.

```sh
python3 -B observe.py --scratch /dev/shm --output replay-system.json
python3 -B observe.py --binary /path/to/rsync --scratch /dev/shm --output replay-other.json
python3 -B -m unittest -v test_observe
HESELA_RSYNC_LIVE=1 python3 -B -O -m unittest -v test_observe
```

HESELA_RSYNC_BINARY selects a different binary for the opt-in native tests.
Those tests execute eight extra interruption/retry schedules; they are validation,
not extra rows in the retained dataset. Tests and runtime guards work under -O.

## Protocol

Each case starts fresh with a 4,194,304-byte source of B bytes and an equal-size
destination of A bytes. Source mtime is 1700000000 seconds; initial destination
mtime is 1600000000 seconds. These deliberately old dates ensure initial selection.
The test verifies both requested timestamps were retained.

Initial transfers use --times --update --no-whole-file --block-size=4096
--checksum-choice=md5 --bwlimit=256, optionally --inplace. There is no compression.
MD5 is a compatibility control, not authentication. Exact byte comparisons are
independent of rsync's checksums.

The process starts in its own session. The runner waits until a 65,536-byte B
prefix is visible at the destination (in-place) or its newly created temporary
file (temporary mode), sends SIGSTOP then SIGKILL to that process group, and
waits for captured pipes to close. A 12-second timeout fails the case; it does
not substitute a time-based interruption. Inspection then verifies actual
partial progress. The byte position reached can vary with scheduling.

Each retry operates on that same case's interrupted destination, not a clone.
The four policies are --update, --update --checksum, --update --ignore-times,
and --checksum without --update. Retry removes only the bandwidth throttle
and substitutes the listed selection flags; it retains the initial write mode.
Each mode/policy combination has its own new interruption, repeated twice per
binary. This is 2 modes x 4 policies x 2 repetitions x 2 binaries = 32 cases.

## Retained results

All 32 retries returned zero. The 12 in-place retries retaining --update
transferred zero files and retained mixed bytes. All four in-place retries
without --update and all 16 temporary-mode retries matched the source exactly.
Before retry, every in-place target retained its original 4 MiB length while
containing both generations. Temporary mode preserved the original target's
bytes, inode and mtime, with partial data in a separate temporary file.

Every source retained its bytes, size and mtime. Every final target was checked
byte-for-byte; results also include counts, hashes, inode IDs, nanosecond mtimes,
commands, return codes and raw output. Nanosecond values are decimal strings
to avoid loss of precision in ordinary JavaScript JSON parsers.

The authoritative-source control is not blanket recovery advice. Real newer
destination data may need preservation. Resolve version authority and preserve
the incomplete state before choosing an overwrite policy.

## Provenance, scope and limitations

results-3.2.7.json identifies the installed distro binary; results-3.4.1.json
identifies the existing isolated upstream build. provenance.json retains its
archive/build hashes and configure flags. The runner hashes itself and its tests.

We measured Linux 6.8.0-146-generic, tmpfs and local peers. We did not test SSH,
mixed-version peers, concurrent writers, all partial-file policies, signals with
cleanup handlers, kernel crashes, power failures, on-disk persistence or a
multi-file consistent snapshot. SIGKILL can leave temporary debris. The harness
removes only its own disposable directories after collecting their state.
Two deliberate repetitions are not a sample of field incidents or a confidence
interval. An exact interruption offset is not a portable invariant.

Primary sources, accessed 2026-10-21:
- https://download.samba.org/pub/rsync/rsync.1 (--update and --inplace)
- https://github.com/RsyncProject/rsync/blob/v3.4.1/generator.c (recv_generator)
- https://github.com/RsyncProject/rsync/blob/v3.4.1/receiver.c (in-place/open_tmpfile branches)

Source review and the upstream source-file hashes are retained in
content/research/rsync-interruption/source-review.md in the repository.
Code/notes: MIT, see LICENSE. Observations: CC0-1.0.
Rsync is GPL-3.0-or-later; no upstream source or binary is redistributed.

## Separate dry-run diagnostic probe (2026-10-21)

diagnose.py imports the unchanged observe.py barrier and creates four new
interruptions: two modes on each of the two hash-identified binaries. Two
dry-run inspections then query each retained target. Eight inspections are not
eight repair attempts and are not pooled into the original 32-case dataset.

```sh
python3 -B diagnose.py --binary /usr/bin/rsync --binary /path/to/rsync \
  --scratch /dev/shm --output diagnostic-replay.json
python3 -B -m unittest -v test_diagnose
```

diagnostics.json preserves commands, raw itemized output, hashes, version and
environment. --checksum --update skipped both mixed in-place targets;
--checksum alone selected them. Both policies selected the old published target
in temporary mode. No inspection changed bytes, size, inode or mtime; read-side
atime changes are not checked. No repair runs in this probe. These are quiescent
local regular files, not a whole-tree integrity audit or a performance result.
Keep --dry-run in diagnostic commands. Source authority remains a separate
decision; selection is not evidence that an overwrite should be authorized.

The new tests mutate recorded selection, raw output, dry-run flags, destination
state and policy coverage to require rejection. HESELA_RSYNC_LIVE=1 repeats two
fresh interruptions per configured binary as validation, not published samples.
The existing harness, its tests and the two original result files are unchanged.
