decisions: a record file that fails to parse is silently invisible — no structural "one keyed record per file" check #621

Closed
opened 2026-07-25 20:35:40 +02:00 by timothy · 1 comment
Owner

Found in adversarial review of #610 / PR #619 (non-blocking there; no existing content is at risk).

The gap

Nothing enforces that every *.md under docs/decisions/records/ and docs/decisions/archive/<area>/ parses to exactly one keyed record. A file that fails to parse yields [] and simply vanishes from the corpus — no error, no warning, everything green.

Reproduced end-to-end: drop a hand-authored record under records/ci/ using a YAML block scalar —

rule: >-
  a long rule wrapped
  over two lines

— which is exactly what YAML invites for this corpus's very long rule: values. _read_frontmatter returns None on any indented continuation line, so:

  • decisions_validate.py → OK
  • build_decisions_catalog.py --check → up to date
  • the record is absent from the catalog
  • zero errors anywhere

Under PyYAML that same file parsed fine, so #610's dependency-free reader widens a hole that already existed (unterminated frontmatter was silently [] before it too).

Why it matters more than it looks

This is the corpus's own failure mode turned on itself. The whole point of the decision system is retrievability, and the one thing worse than a missing record is a missing record that reports success — the same class as the #609 marker bug (a gate printing OK while doing nothing) and the #603 stale-after bug (a field that silently never fires).

What is NOT at risk: an existing record disappearing stays loud — the no-vanish check catches it. This only bites a newly added record, where the author's own PR looks clean.

Fix

A structural check in decisions_validate.py: for every *.md under the record wings (excluding _NON_DECISION_FILES and the stripped legacy files), assert it parses to exactly one record and that record has a key. Error, not warning — a file in records/ that is not a record is a mistake by definition.

That makes every parse-failure mode loud at once: unterminated frontmatter, block scalars, indented structure, a stray note file, an empty file.

Consider also relaxing _read_frontmatter to accept block scalars, since it is the natural thing to reach for on long values — but the structural check is the important half, because it converts any future reader limitation from silent to loud.

Done-when

  • Every file under the record wings must parse to exactly one keyed record; violations are errors
  • Test: a block-scalar record file fails validation loudly (mutation-verified — it must go red without the check)
  • Test: an unterminated-frontmatter file fails loudly
  • Test: a legitimate record still passes, and legacy/stripped files stay exempt
  • Decide whether _read_frontmatter should accept block scalars, and record the decision either way
  • Adversarial review passed
Found in adversarial review of #610 / PR #619 (non-blocking there; no existing content is at risk). ## The gap Nothing enforces that **every `*.md` under `docs/decisions/records/` and `docs/decisions/archive/<area>/` parses to exactly one keyed record**. A file that fails to parse yields `[]` and simply vanishes from the corpus — no error, no warning, everything green. Reproduced end-to-end: drop a hand-authored record under `records/ci/` using a YAML block scalar — ```yaml rule: >- a long rule wrapped over two lines ``` — which is exactly what YAML invites for this corpus's very long `rule:` values. `_read_frontmatter` returns `None` on any indented continuation line, so: - `decisions_validate.py` → **OK** - `build_decisions_catalog.py --check` → **up to date** - the record is absent from the catalog - zero errors anywhere Under PyYAML that same file parsed fine, so #610's dependency-free reader **widens** a hole that already existed (unterminated frontmatter was silently `[]` before it too). ## Why it matters more than it looks This is the corpus's own failure mode turned on itself. The whole point of the decision system is retrievability, and the one thing worse than a missing record is a missing record that reports success — the same class as the #609 marker bug (a gate printing `OK` while doing nothing) and the #603 `stale-after` bug (a field that silently never fires). **What is NOT at risk:** an *existing* record disappearing stays loud — the no-vanish check catches it. This only bites a **newly added** record, where the author's own PR looks clean. ## Fix A structural check in `decisions_validate.py`: for every `*.md` under the record wings (excluding `_NON_DECISION_FILES` and the stripped legacy files), assert it parses to exactly one record **and** that record has a key. Error, not warning — a file in `records/` that is not a record is a mistake by definition. That makes every parse-failure mode loud at once: unterminated frontmatter, block scalars, indented structure, a stray note file, an empty file. Consider also relaxing `_read_frontmatter` to accept block scalars, since it is the natural thing to reach for on long values — but the structural check is the important half, because it converts *any* future reader limitation from silent to loud. ## Done-when - [x] Every file under the record wings must parse to exactly one keyed record; violations are errors - [x] Test: a block-scalar record file fails validation loudly (mutation-verified — it must go red without the check) - [x] Test: an unterminated-frontmatter file fails loudly - [x] Test: a legitimate record still passes, and legacy/stripped files stay exempt - [x] Decide whether `_read_frontmatter` should accept block scalars, and record the decision either way - [x] Adversarial review passed
timothy added the priority: medium label 2026-07-25 22:02:56 +02:00
timothy added the in-progress label 2026-07-26 00:27:29 +02:00
Author
Owner

Closing record

Outcome: Shipped in PR #641 (merged as eb339084). decisions_validate.py now asserts, per PATH, that every *.md under docs/decisions/records/** and archive/** parses to exactly one keyed record, reported as a validator ERROR. New decision record docs.record-wing-parse-guard.

Root cause: Nothing tied a file to a record. _parse_frontmatter returns [] for anything it cannot read, and every consumer treated an empty list as "this file contributes no records" — indistinguishable from "this file has no records to contribute". The no-vanish diff check covered an existing record disappearing, but structurally cannot see a newly added one, because there is no base state to diff against. #610's dependency-free reader widened the hole (block scalars parse fine under PyYAML), it did not create it.

Decisions/conventions changed: added docs.record-wing-parse-guard. Block scalars are deliberately NOT supported — correct folding is a real subset of YAML and a subtly wrong folder would silently alter rule text, which is the failure class being closed. Every record value goes on one line.

Reusable knowledge:

  • A guard's own wiring needs a test. Deleting the single line calling record_wing_faults() from main() left the whole suite green while a real record vanished — the guard defeated by a one-line edit, inside the fix for exactly that class of defect.
  • Exempt by exact path, never by basename. _NON_DECISION_FILES is a set of topic-dir names; applying it to the wings would have skipped a genuine records/docs/retrieval-eval.md, a path the key↔path rule makes mandatory.
  • Exempt by identity, not location. "Anything directly in archive/" left that directory unguarded; the exemption now tests for the stripped-index shape.
  • Structural checks catch parse-to-zero and parse-to-many, but not parse-to-WRONG — a block scalar with an unindented continuation yields one valid keyed record whose rule is truncated to >-. Caught separately by an unknown-frontmatter-key check.

Verification: 194 tests (up from 111), mutation-verified — short-circuiting record_wing_faults reddens 11; neutering only the scan loop reddens 10; each individual fix reddens exactly its own test. Reproduced the original defect end-to-end on main (validator OK, catalog "up to date", record absent) and confirmed the branch turns it into a named error. Green under jq 1.8.2 and jq 1.6. Three independent cold reviews (rounds 1–3), final verdict MERGEABLE.

Deferred: one review finding declined with reason — making the empty-wing anti-vacuity check symmetric across both wings. Zero active records means the scan measured nothing (a clean result would be vacuous); zero archived records is normal for any young repo, and git tracks no empty directory, so symmetry would fail a correct corpus. The asymmetry is documented in code and pinned by a test so it is not "fixed" back. Informational leftovers not actioned: the five legacy flat topic files sit outside both wings (they hold zero keyed records), and the frontmatter schema is now strict-closed, so a future field must extend _FM_TO_FIELD.

Docs updated: docs/decisions/records/docs/record-wing-parse-guard.md (new), docs/decisions/README.md (regenerated), docs/ci-cd.md → decisions-guard job.

## Closing record **Outcome:** Shipped in PR #641 (merged as `eb339084`). `decisions_validate.py` now asserts, per PATH, that every `*.md` under `docs/decisions/records/**` and `archive/**` parses to exactly one **keyed** record, reported as a validator ERROR. New decision record `docs.record-wing-parse-guard`. **Root cause:** Nothing tied a *file* to a *record*. `_parse_frontmatter` returns `[]` for anything it cannot read, and every consumer treated an empty list as "this file contributes no records" — indistinguishable from "this file has no records to contribute". The no-vanish diff check covered an *existing* record disappearing, but structurally cannot see a **newly added** one, because there is no base state to diff against. #610's dependency-free reader widened the hole (block scalars parse fine under PyYAML), it did not create it. **Decisions/conventions changed:** added `docs.record-wing-parse-guard`. Block scalars are deliberately NOT supported — correct folding is a real subset of YAML and a subtly wrong folder would silently *alter rule text*, which is the failure class being closed. Every record value goes on one line. **Reusable knowledge:** - A guard's own wiring needs a test. Deleting the single line calling `record_wing_faults()` from `main()` left the whole suite green while a real record vanished — the guard defeated by a one-line edit, inside the fix for exactly that class of defect. - **Exempt by exact path, never by basename.** `_NON_DECISION_FILES` is a set of *topic-dir* names; applying it to the wings would have skipped a genuine `records/docs/retrieval-eval.md`, a path the key↔path rule makes mandatory. - **Exempt by identity, not location.** "Anything directly in `archive/`" left that directory unguarded; the exemption now tests for the stripped-index *shape*. - Structural checks catch parse-to-zero and parse-to-many, but not **parse-to-WRONG** — a block scalar with an unindented continuation yields one valid keyed record whose `rule` is truncated to `>-`. Caught separately by an unknown-frontmatter-key check. **Verification:** 194 tests (up from 111), mutation-verified — short-circuiting `record_wing_faults` reddens 11; neutering only the scan loop reddens 10; each individual fix reddens exactly its own test. Reproduced the original defect end-to-end on `main` (validator OK, catalog "up to date", record absent) and confirmed the branch turns it into a named error. Green under jq 1.8.2 and jq 1.6. Three independent cold reviews (rounds 1–3), final verdict MERGEABLE. **Deferred:** one review finding **declined with reason** — making the empty-wing anti-vacuity check symmetric across both wings. Zero *active* records means the scan measured nothing (a clean result would be vacuous); zero *archived* records is normal for any young repo, and git tracks no empty directory, so symmetry would fail a correct corpus. The asymmetry is documented in code and pinned by a test so it is not "fixed" back. Informational leftovers not actioned: the five legacy flat topic files sit outside both wings (they hold zero keyed records), and the frontmatter schema is now strict-closed, so a future field must extend `_FM_TO_FIELD`. **Docs updated:** `docs/decisions/records/docs/record-wing-parse-guard.md` (new), `docs/decisions/README.md` (regenerated), `docs/ci-cd.md` → `decisions-guard` job.
timothy removed the in-progress label 2026-07-26 13:24:05 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: timothy/ersatztv#621