# SQLite backup progress: writer identity and source views

This is a bounded software experiment on synthetic data, not a new SQLite defect.
It connects completion, progress and freshness instead of treating them as one
success flag. No benchmark, physical-I/O estimate or power-loss result is claimed.

## Reproduce

Requires Linux, Python 3, stat and an installed SQLite shared library.
The script creates and removes only private temporary databases; it accepts a
work directory, never an existing database path. Output creation is exclusive.
No package installation, network access or elevated privilege is required.

```sh
python3 observe.py --work-root /tmp --output replay.json
python3 -m unittest -v test_observe.py
python3 -O -m unittest -v test_observe.py
```

Run the tests with this directory as the working directory. Keep observations.json
beside the two scripts. A failed command can leave an empty output reservation;
do not treat that as a receipt. Use a new output name for another attempt.

## Method and oracle

Seven schedules, repeated three times with fresh files. Source modes DELETE and
WAL each test an idle source, another-connection writer, and same-source-handle
writer. The seventh schedule pins a generation-10 WAL read transaction while a
separate connection commits. Calls are sequentially interleaved in one thread,
not simultaneously executed.

Each source has 64 rows, 4096-byte pages, synchronous FULL, no automatic WAL
checkpoint and deterministic complete payloads. It occupies 266 pages in the
recorded build. Initial copying requests eight pages. Six rounds each commit
the next generation (11 through 16), then request two backup pages; the idle
control only takes those steps. The fixture's source page count stays fixed.
Counters are read before and after each commit and after each step.

Then the writer is idle and the same backup object drains to SQLITE_DONE.
Finish must return OK. Close and reopen the destination read-only; compare every
ID, generation and full payload with the independently specified oracle, and run
integrity_check. Pinned case expects generation 10, others the last committed
generation (or 10 for idle). Hashes supplement exact comparisons, not replace them.
The destination handle is never used by another API while backup is active.

## Recorded results

All three repetitions agree. After the initial eight-page step, 258 remain.
External writes give 264 remaining after each of the six subsequent steps,
all SQLITE_OK, in both source journal modes. Idle, same-handle and pinned
controls progress through 256, 254, 252, 250, 248, 246.
Quiescent draining completes all cases. Pinned copies retain generation 10 while
the latest source is generation 16; same-handle and external cases copy 16.
Every reopened destination passes integrity_check and exact full-row comparison.

Six rounds demonstrate repeated resets, not an observed infinite execution.
The official guide separately warns that sufficiently frequent restarts may
prevent completion. No elapsed-time, disk-I/O or production failure-rate inference
is supported. Same-handle progress does not prove writes impose zero copy work.

## Source chain

Reviewed 2026-10-21:
- https://www.sqlite.org/backup.html, sections 3.1-3.2: restart, same-handle exception,
  liveness caveat and counter reporting.
- https://www.sqlite.org/c3ref/backup_finish.html: lifecycle, counters, destination
  exclusivity and terminal step status. Transient-finish discrepancy is covered
  by Hesela's separate abandonment experiment, not retested here.
- https://www.sqlite.org/isolation.html: retained WAL read snapshots.
- https://github.com/sqlite/sqlite/blob/version-3.45.1/src/backup.c:
  sqlite3BackupRestart resets iNext; backupUpdate updates already-copied pages;
  backup_step opens a source read transaction only when none exists.

The installed build identifies itself as 3.45.1 with an alt1 source-ID suffix;
the upstream tag is mechanism context, not claimed byte-identical package source.
Exact runtime identity, compile options and source SHA-256 are in observations.
No third-party dataset or source text is redistributed. Fixture and driver are
Hesela-authored; binding/fixture helpers derive from earlier Hesela work.

## Corpus connection and limits

Extend backup-verification-is-not-a-restore-test at sqlite-backup-progress and the
existing sqlite-online-backup term. No new duplicate term or standalone article.
Existing snapshot and completion experiments retain their own sample sizes.

Do not infer current-release behavior, shared-cache behavior, growth behavior,
cross-process scheduling, recovery time, WAL-size cost or crash safety. The
filesystem label ext2/ext3 is the stat tool's report, not a full mount description.
WAL is the only mode tested with a retained read snapshot.

Pilot: a generation-1 fixture changed page count on its first update. That failed
the fixed-size check and was not counted. The final fixture starts at generation
10 and verifies constant page count. The probe and final repetitions are not pooled.
