fix(609): scope the decisions edit token to the subject line or a trailer
PR Gates / CI image pin matches docker/ci (pull_request) Successful in 11s
PR Gates / Docs update reminder (pull_request) Successful in 11s
PR Gates / decisions lifecycle (pull_request) Successful in 20s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 8m0s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 8s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 7s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 15m36s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Build ErsatzTV Image / Functional E2E (curl + UI contracts) (pull_request) Successful in 17m25s

The token was armed by a bare substring match over every commit message in the
range, so a commit that merely DESCRIBED the mechanism armed it and skipped the
entire `if not token:` block -- all three rationale-rewrite comparisons (active
survivors, active->archive laundering, archive survivors). `removed` and `demoted`
still ran, so the job printed `decisions-validate: OK` while doing nothing. It
bit in PR#605, which had hand-resolved an append-vs-append conflict inside
docs/decisions.md -- precisely the operation the guard exists to police.

Now recognized in exactly two places:
  * the commit SUBJECT line -- the established form. All twenty prior tokened
    commits append it to the subject (or place it mid-subject, as docs(434)
    does); none put it on its own line, so the obvious "own-line only" rule
    would have broken every historical use.
  * a `Decisions-Edit: <reason>` git trailer -- the forward-looking form, which
    can carry a reason the bracketed marker cannot.

Fail-open posture unchanged: unresolvable git means the token reads unarmed, so
the guard still runs.

Verified by measuring the guard rather than reading a green check -- a positive
control over the real corpus across all three placements: no token fires (exit 1),
subject token suppresses (exit 0), body-only mention fires (exit 1). Plus an
end-to-end matcher test against a throwaway git repo covering the established
form, mid-subject placement, the trailer, a merge commit quoting a tokened PR
title, a multi-commit range, and an unresolvable ref.

fixes #609
This commit is contained in:
2026-07-25 16:48:52 +02:00
parent fd70e6eb4f
commit 09df6de534
4 changed files with 117 additions and 4 deletions
+38
View File
@@ -61,6 +61,14 @@ lifecycle writes (adding a new active record, relocating a superseded/retired re
updating metadata fields, regenerating the catalog) are token-free; the validator proves they're
legitimate structurally instead of gating on the token.
**Where the token counts (ersatztv#609).** It is recognized in a commit's **subject line** (the
established form — append it, as every prior use does) or as a **`Decisions-Edit: <reason>`** git
trailer. It is *not* recognized anywhere else in the message body, so you can safely write *about*
the mechanism in a commit body without arming it. That scoping is the fix for a real failure: the
check used to be a bare substring over the whole message, so a commit merely describing the token
armed it and silently suppressed every rationale-rewrite comparison — the job still printed
`decisions-validate: OK` while doing nothing.
---
## Index
@@ -3777,3 +3785,33 @@ section renders the date itself, never a stale/fresh verdict.
much of this corpus is agent-authored, distinguishing agent-inferred from human-confirmed-after-
measuring is real signal; it just needs its own actor convention and wasn't worth coupling to this
change.
## 2026-07-25 — The decisions edit token is recognized only in the subject line or a trailer, never in body prose (#609)
`key: docs.decision-edit-token-scope` · `status: active` · `since: 2026-07-25` · `supersedes: none` · `superseded-by: none`
**Rule:** `scripts/decisions_validate.py` arms `[decisions-edit]` only from a commit's **subject line** or a **`Decisions-Edit:` git trailer** — never from anywhere else in the message body, so a commit that merely *describes* the token cannot silently disable the rationale-rewrite guard.
**Signals:** decisions-edit token, edit token armed, bare substring match, guard no-op, green but vacuous, body-diff suppressed, subject line, Decisions-Edit trailer, token_armed_in · paths: scripts/decisions_validate.py · issues: #609, #603, #605
**Mechanics:** `scripts/decisions_validate.py` → `token_armed_in` / `_token_armed`; docs/decisions.md → header "Where the token counts"
**Sources:** PR#605, where a commit message explaining why no token was needed armed it and suppressed all three rationale comparisons; caught in adversarial review, not by CI
**The failure was a gate reading green while doing nothing.** The old check was
`EDIT_TOKEN.lower() in git log --format=%B mb..head`, a bare substring over every commit message in
the range. Any mention armed it — including prose *about* the mechanism — and arming it skips the
entire `if not token:` block: all three rationale comparisons (active survivors, active→archive
laundering, archive survivors). `removed` and `demoted` still ran, so the job printed
`decisions-validate: OK` and looked healthy. It bit in the PR that introduced `stale-after` (#603),
and it bit in the worst possible place: that PR had hand-resolved an append-vs-append conflict inside
`docs/decisions.md`, which is precisely the operation the guard exists to police.
**Scoping to the subject preserves every historical use.** All twenty prior tokened commits append
`[decisions-edit]` to the subject (or place it mid-subject, as `docs(434):` does); none put it on its
own line, so an "own-line only" rule — the obvious first instinct — would have broken all of them.
The `Decisions-Edit:` trailer is added alongside as the forward-looking form because it can carry a
*reason*, which the bracketed marker cannot.
**Fail-open posture is unchanged**: if git can't be interrogated the token reads unarmed, so the
guard still runs. Failing the other way would silently disable it, which is the bug being fixed.
**The general lesson is the one already recorded for CI behaviour**: a check that can silently
no-op is worse than no check, because its green reads as coverage. Verify a guard by *measuring that
it fires* — a positive control that mutates a record and expects a red — not by observing that the
job passed.
+1
View File
@@ -61,6 +61,7 @@ the link for rationale. Superseded/retired history lives in `archive/`. Regenera
| `concurrency.replace-all-contract` | Replace-all aggregate PUTs carry a uniform plain `int Version` concurrency token (EF `.IsConcurrencyToken()`), checked pre-save and enforced by the EF UPDATE guard, returning 412 (not 409) on a stale `If-Match`. | 2026-07-11 | [link](optimistic-concurrency.md#2026-07-11--optimistic-concurrency-contract-for-replace-all-puts-253-pr1-infra--block-reference) |
| `concurrency.schedule-item-child-identity` | `PUT /api/schedules/{id}/items` reconciles by an optional round-tripped child `Id` (null/absent/0 ⇒ new item), never by array position, so fill-group/shuffle state follows the logical item across reorders; an unknown or duplicate id is rejected 422 (checked after the §7a `CheckVersion`, so 412 precedes 422). | 2026-07-11 | [link](optimistic-concurrency.md#2026-07-11--stable-child-identity-for-schedule-item-replace-259-split-from-252253) |
| `docs.convention-docs-session-start` | Docs-first, not source-first: conventions (api-conventions, spa-conventions, e2e-local, blazor-route-parity, domain-model, decisions, README) are read from docs, not reverse-engineered from code, via `docs/README.md`'s task-signal map — only the sections it points to for the task at hand, not the whole set. Each doc is updated in the same PR that changes what it documents, replacing deferred/follow-up doc updates. | 2026-07-07 | [link](../decisions.md#2026-07-07--convention-docs-read-at-session-start-updated-in-pr) |
| `docs.decision-edit-token-scope` | `scripts/decisions_validate.py` arms `[decisions-edit]` only from a commit's **subject line** or a **`Decisions-Edit:` git trailer** — never from anywhere else in the message body, so a commit that merely *describes* the token cannot silently disable the rationale-rewrite guard. | 2026-07-25 | [link](../decisions.md#2026-07-25--the-decisions-edit-token-is-recognized-only-in-the-subject-line-or-a-trailer-never-in-body-prose-609) |
| `docs.decision-lifecycle` | every decision `##` record (active or archived) carries a 5-field metadata block (`key`, `status`, `since`, `supersedes`, `superseded-by`) checked by `scripts/decisions_validate.py`; a record is never deleted or line-edited to reverse a call — it is moved to `docs/decisions/archive/` with `status: superseded`/`retired` and a reciprocal `superseded-by`/`supersedes` key pair to its replacement. | 2026-07-21 | [link](../decisions.md#2026-07-21--decision-records-carry-a-lifecycle-schema-validated-by-a-script-append-only-by-diff-is-retired-521) |
| `docs.decision-optional-provenance` | Decision records gain two OPTIONAL fields — `stale-after: YYYY-MM-DD` on the metadata line and a `**Sources:**` line in the metadata block; the Open Knowledge Format (OKF) itself is NOT adopted as the record format. | 2026-07-25 | [link](../decisions.md#2026-07-25--okf-evaluated-and-rejected-as-a-replacement-two-of-its-optional-fields-adopted-603) |
| `docs.tracker-comment-retrofit` | When the knowledge exporter flags an over-cap tracker issue and excludes it from ingestion, triage its comments instead of assuming a retrofit is owed — and for each decision-shaped item check the **worked issue first**, because a tracker session comment is by construction a précis of the fuller closing record posted on the issue it narrates. Applied to #237 (111 comments) this yielded **zero** records, so server-management#642's "a fact found only in a #237 comment" retrieval row has no valid subject and its interim target (an already-migrated record) is permanent. | 2026-07-21 | [link](../decisions.md#2026-07-21--check-the-worked-issue-before-the-decision-corpus-a-closed-trackers-comments-need-no-retrofit-524) |
+46 -4
View File
@@ -231,6 +231,51 @@ def _archive_records_at(ref: str):
return by_heading
_TRAILER_KEY = "Decisions-Edit"
_REC_SEP, _FIELD_SEP = "\x1e", "\x1f"
def token_armed_in(subject: str, trailer: str) -> bool:
"""Whether ONE commit legitimately carries the edit token.
Recognized in exactly two places:
* the commit SUBJECT (first line) — the established form; every historical use appends
`[decisions-edit]` to the subject, so this stays backward compatible.
* a `Decisions-Edit:` git trailer — the forward-looking form, which can carry a reason.
Deliberately NOT the rest of the body. The old check was a bare substring over the whole
message, so a commit that merely *described* the token armed it and silently suppressed every
rationale-rewrite comparison for the PR — a gate reporting green while doing nothing, and it
bit hardest in a PR that hand-resolved a conflict inside the corpus the guard protects (#609).
"""
if EDIT_TOKEN.lower() in subject.lower():
return True
return bool(trailer.strip())
def _token_armed(mb: str, head: str) -> bool:
"""True if ANY commit in mb..head carries the token. Unresolvable git → False (guard runs)."""
out = _run(
[
"git",
"log",
f"--format=%s{_FIELD_SEP}%(trailers:key={_TRAILER_KEY},valueonly){_REC_SEP}",
f"{mb}..{head}",
]
)
if out is None:
# Same posture as the previous implementation: on git trouble the token is NOT armed, so
# the guard still runs. Failing the other way would silently disable it.
return False
for entry in out.split(_REC_SEP):
if not entry.strip():
continue
subject, _, trailer = entry.partition(_FIELD_SEP)
if token_armed_in(subject.strip(), trailer):
return True
return False
def _rationale(rec) -> str:
"""Record body with the contiguous top metadata block stripped, whitespace-normalized.
@@ -261,10 +306,7 @@ def _diff_findings(base: str, head: str) -> tuple[list[str], list[str], list[str
file=sys.stderr,
)
return [], [], []
if EDIT_TOKEN.lower() in (_run(["git", "log", "--format=%B", f"{mb}..{head}"]) or "").lower():
token = True
else:
token = False
token = _token_armed(mb, head)
base_active = _records_at(mb, _active_paths_at(mb))
head_active = _records_at(head, _active_paths_at(head))
+32
View File
@@ -478,3 +478,35 @@ def test_malformed_stale_after_on_an_archive_record_is_caught():
arch = _rec(key="a.old", status="superseded", superseded_by="a.b", stale_after="soon")
errs = _v([_rec(key="a.b", supersedes="a.old")], archive_records=[arch], archive_keys={"a.old"})
assert any("not a YYYY-MM-DD date" in e for e in errs)
# ---- edit-token scoping (ersatztv#609) ----
def test_token_armed_by_subject_the_established_form():
"""Every historical use appends it to the subject; that must keep working."""
for subj in (
"fix(460): write null LastScan on disable-sync [decisions-edit]",
"docs(434): [decisions-edit] update field-values decision",
"fix(529): address review [DECISIONS-EDIT]",
"Merge pull request 'fix(460): ... [decisions-edit]' (#601) from x into main",
):
assert dv.token_armed_in(subj, ""), subj
def test_token_armed_by_trailer():
assert dv.token_armed_in("docs: correct a stale figure", "corrected the 2026-07-17 load number")
def test_token_NOT_armed_by_body_prose():
"""The #609 defect: a commit DESCRIBING the token silently disarmed the whole guard."""
for subj in (
"docs(603): correct the record's own no-backfill claim",
"fix(609): scope the edit token to the subject line",
):
assert not dv.token_armed_in(subj, ""), subj
def test_token_not_armed_by_empty_or_whitespace_trailer():
assert not dv.token_armed_in("docs: something", "")
assert not dv.token_armed_in("docs: something", " \n ")