ADR 0014 — Canonicalisation is fixed, not versioned
Status: accepted · 2026-09-15 · amends ADR 0002
Context. ADR 0002 chose RFC 8785 for canonical_json and let the reference implementation use Python's json.dumps(sort_keys=True, separators=(",", ":")), "which agrees with JCS for all fixtures". Running the RFC's own test vectors (tests/test_jcs.py) showed where it does not: floats with an integer value or a small magnitude (0.0, 120.0, 1e-06) and object keys outside the Basic Multilingual Plane. Adapters write such floats (alt_m, speed_mps, heading_deg), so records made before the fix carry hashes that a conformant implementation cannot recompute. Two ways out: keep the old rule in the code behind a per-record version, or fix the rule and move the records.
Decision. One canonicalisation, RFC 8785, for every record. The code carries no other rule and no version switch; logbook.json format names the rule a record's hashes were computed with, and the implementation refuses to verify or write a record whose format is not its own. A record hashed under the old rule is migrated forward, once: every line keeps id, seq, the content fields and recorded_at; prev and hash are recomputed in seq order; the old files are kept beside the record; logbook.json gains a lineage entry with the old format and head; and the migration appends one migration/v1 line naming the old head, so the migration is itself part of the chain. The old serialiser survives only in the test that builds a synthetic 0.1 record.
Consequences. A second implementation implements RFC 8785 and nothing else; that is what "the spec fits in an afternoon" needs. An old head is still meaningful: it is in lineage and in the chain, and anyone holding a 0.1 export can recompute it from the kept files with the 0.1 rule. Migration is the one operation that rewrites prev and hash; it rewrites nothing else, refuses a record whose 0.1 links are already broken, and writes into a temporary folder first, so an interrupted run leaves the record as it was. Any future change to the hash rule takes the same road: a new format name, a refusal, a migration, a lineage entry.
Amendment (2026-10-13). The 0.1 rule now also lives in store.hash_0_1, read by migrate's gate alone: before any line is rehashed, every 0.1 hash is recomputed under the rule it was written with and every link checked, so a 0.1 record that does not verify is refused and nothing is touched. Writing and verifying a record still use one canonicalisation, RFC 8785; the test that builds a synthetic 0.1 record keeps its own copy of the old serialiser.