# FTS5 recovery acceptance: current consistency is not historical preservation

## Main result

A recovered database needs an explicit definition of what must survive.
For the existing Hesela FTS5 fixtures, two different comparisons are useful:

1. **Historical rows:** exact equality of the ordered mapping from integer
   document identifier to UTF-8 text, against a trusted earlier snapshot.
2. **Present index:** exact equality of stored term/document/column/position
   tuples to a newly constructed reference index of the current rows.

Neither comparison substitutes for the other. A correct index can describe
the wrong historical text. Unchanged text can coexist with a stale index.
A multiset of texts also loses the association between documents and IDs.

This supplement reuses the SAME 17 previously designed cases. It does not
add an incident sample or claim a new SQLite vulnerability. The contribution
is a common, executable acceptance rule that connects three earlier results.

## Native results

Both measured builds produced the following same comparison outcomes.
Each build has 59 dependent before/after/copy/rebuild states, not 59 independent
experiments. The second run repeats the same cases, not another population.

| Observation per build | Count |
| --- | ---: |
| Existing designed cases | 17 |
| Recorded states | 59 |
| PRAGMA, internal FTS5 and external rank=1 checks all pass | 52 |
| Both row and index comparisons pass | 39 |
| All ordinary checks pass but the row/index contract fails | 13 |
| Historical identifier-to-text mapping differs | 20 |
| Stored token instances differ from a fresh current-content index | 9 |
| Rebuilt index agrees with current text, but historical mapping differs | 7 |

These counts are coverage of intentionally selected witnesses. They are NOT
false-negative probabilities, field failure rates, or estimates for other
schemas, tokenizers, SQLite releases or storage devices.

### Three mechanisms, one acceptance decision

| Existing witness | Ordinary checks | Current index | Historical mapping |
| --- | --- | --- | --- |
| Unchanged baseline | Pass | Equal | Equal |
| Minus sign removed from text | Pass | Equal | Different |
| az replaced by bq without updating FTS5 | Pass | Different | Different |
| Implicit rowids changed by VACUUM, then index rebuilt | Pass | Equal | Different |

**Normalization:** unicode61 tokenization can map different text to the same
indexed representation. Therefore token equality cannot establish text
preservation. SQLite documents the tokenizer's normalization rules in
[FTS5 section 4.3.1](https://sqlite.org/fts5.html#unicode61_tokenizer).

**Checksum witness:** the existing az/bq case has unequal stored and expected
tokens, yet rank=1 accepts it on both measured builds. This supplement compares
the actual instance tuples rather than treating that success as exact equality.
The parent's retained source proof explains the collision; this is an observed
implementation limitation, not a claim that the public API promises an
adversarial integrity guarantee.

**Maintenance:** ordinary VACUUM can change unaliased rowids. Rebuilding FTS5
then restores agreement with the current mapping, not the old identifiers.
The tested incidental-index and VACUUM INTO controls are observations, not a
substitute for a documented stable key.
See [VACUUM section 3](https://sqlite.org/lang_vacuum.html).

The [FTS5 vocabulary API](https://sqlite.org/fts5.html#the_fts5vocab_virtual_table_module)
exposes instance-level positions for full-detail indexes. The
[rebuild command](https://sqlite.org/fts5.html#the_rebuild_command) reconstructs
from current content. A [completed backup](https://sqlite.org/backup.html)
copies database state; it does not decide whether that state satisfies the
application's earlier recovery target.

## What the code actually checks

The new code uses the existing observers at parent commit
b5b5dcc9a33b49b70a7f493bf2c2090dd6417cd1, checks their pinned SHA-256 values
BEFORE importing them, and records the runtime source ID and build options.

Token and checksum instances come from those original native observers.
For the maintenance fixtures, the supplement reads all stored instances using
a temporary vocabulary table on a read-only connection. File hashes before
and after inspection must match. It never rebuilds the inspected database.
The fresh comparison index lives separately in memory.

Rows and instances are compared directly after canonical sorting. SHA-256
values identify evidence; the acceptance decision does not rely on a hash
collision assumption. Text equality means the decoded UTF-8 strings in this
TEXT-only schema, not byte-for-byte equality of whole database files.

The baseline is the known original input in these controlled fixtures.
In a real recovery workflow, an independently retained and authenticated
manifest, stable document keys and a consistent source snapshot would be
needed. A manifest computed AFTER damage cannot establish earlier correctness.
Do not silently make a newly rebuilt index the historical baseline.

## Reproduce

Python with SQLite FTS5 is required; there are no third-party dependencies.
From the extracted acceptance-contract directory:

```sh
python3 -B acceptance.py --output fresh-results.json
python3 -B -m unittest -v test_acceptance.py
python3 -B -O -m unittest -v test_acceptance.py
python3 -B acceptance.py --validate results.json
```

The command refuses to overwrite an existing output. The capture includes all
59 raw row/instance comparisons and the separate booleans, not just totals.
results.json records CPython 3.12.3 / SQLite 3.45.1; results-sqlite3531.json
records CPython 3.13.16 / SQLite 3.53.1 on the same host. These builds differ in
more than one variable. Their comparison observations are exactly equal.

Four test executions (14 methods each, two runtimes, normal and optimized)
passed. Tests include fourteen altered-report controls, invalid row/token shapes,
the healthy baselines, position and ID sensitivity, empty-state handling,
the checksum witness, and exact comparison with the retained capture.

## Boundaries and publication status

This is a bounded research demonstrator, NOT a production database checker.
It deliberately supports one TEXT column named body, integer identifiers,
unicode61, detail=full and the existing fixtures. It does not certify arbitrary
schemas, prefix indexes, custom tokenizers, foreign keys, triggers, durability,
concurrency, crash recovery, authenticity or malicious databases. The reference
index uses the SAME SQLite engine, so common-mode engine defects remain possible.

The original studies and their full diagnostic captures remain unchanged in
the parent research packet. No new article, glossary entity or site build was
created. This synthesis is submitted to the existing research PR3297; adapting
the reviewed result into existing publication PR3187/3188 remains pending.
No merge, website deployment, visual acceptance or independent peer review
is claimed.
