fix(620): signal corpus size per RECORD; the aggregate becomes an unthresholded trend
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 13s
PR Gates / CI image pin matches docker/ci (pull_request) Successful in 20s
PR Gates / Docs update reminder (pull_request) Successful in 28s
PR Gates / decisions lifecycle (pull_request) Successful in 30s
Review verdict / Set review-verdict status (pull_request) Successful in 12s
PR Gates / Script tests (pytest) (pull_request) Successful in 42s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 1m31s
Build ErsatzTV Image / Functional E2E (curl + UI contracts) (pull_request) Successful in 18m33s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 21m27s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 22m24s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
review-verdict/h10 Review-verdict: MERGEABLE @ fefd11d

Squashed from 7 commits (4 review rounds) to keep the rebase onto #621 tractable; the
full round-by-round history is on PR #642.

corpus was 5658/5600 — over budget and warning again — 3h35m after #619 put it at 5228,
with nobody consolidating anything.

So this does NOT re-baseline. An aggregate over a monotonically growing corpus can only
ratchet; that is the "permanently red, therefore no signal" state #542 re-baselined away
from, and growth is not even a smooth rate to plan against (the corpus FELL from 5089 to
5042 across four days, then gained 427 in one evening as two large records landed).

Replaces it with a per-record prose ceiling (default 60), non-blocking, naming each
record over it — not monotonic, so it can go red AND green, and it points at a file. The
aggregate is still printed as an unthresholded trend notice, with record prose and
non-record scaffolding reported separately because they are not the same unit. The
GENERATED catalog is no longer counted at all: it gains one row per record and no
consolidation can shrink it, which made the metric partly a record COUNT in a line-count
costume.

The calibration test took FOUR versions, and the failures are the durable lesson:
  v1  true by construction (`max(under) <= 60 < min(over)` over lists built by that test)
  v2  a gap WIDTH — a ceiling of 200 also sits in a wide gap, so it passed
  v3  fraction band + "clear air" vs the nearest record above — hostage to an unrelated
      record: one ordinary 62-line addition reddened it with the ceiling correctly
      placed, and the only remedy was to RAISE the ceiling. That is this very treadmill,
      as a hard failure in what #631 makes a blocking job.
  v4  `p90 <= ceiling <= p95` — the property stated directly and scale-free.
Two rules recorded: a guard test must depend only on the thing it guards, and a threshold
over a growing population must be expressed in that population's own terms.

Candidates: all over-ceiling records assessed, each actioned or declined with a reason.
The largest (scan.libraryfolder-unique-identity, 230 lines) is a legitimate DECLINE — a
dozen-odd distinct traps whose only copy that is. Nothing pruned, so no archive or
supersession was required. An automated redundancy metric is explicitly rejected.

Also: `--budget` is accepted but announces its retirement rather than no-opping silently;
the dead `budget_ok` parameter is gone; and five "untresholded" typos are fixed, one of
which was propagating into the generated catalog row and MemPalace's per-key drawer.

Refs #620

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-26 13:57:01 +02:00
co-authored by Claude Opus 5
parent 59558e134f
commit fefd11dffe
6 changed files with 380 additions and 33 deletions
+90 -22
View File
@@ -48,6 +48,10 @@ _LEGACY_EDIT_TOKEN = "[decisions-edit]" # noqa: S105 (a commit-message marker,
# sorting by date because this regex forces a fixed-width zero-padded form.
_STALE_AFTER_RE = re.compile(r"^\d{4}-\d{2}-\d{2}$")
# Per-record prose ceiling (#620). A module constant, not a bare argparse default, so the test that
# guards the calibration claim asserts against the SAME value the CLI uses and the two cannot drift.
RECORD_CEILING_DEFAULT = 60
def _parse_stale_after(value: str | None) -> date | None:
"""`stale-after` as a date, or None if absent, empty, or malformed.
@@ -91,7 +95,6 @@ def validate(
*,
archive_keys,
catalog_ok,
budget_ok,
removed,
rewritten,
archive_records=None,
@@ -199,9 +202,6 @@ def validate(
if not catalog_ok:
errs.append("docs/decisions/README.md active catalog is stale — run build_decisions_catalog.py")
if not budget_ok:
# non-blocking: reported as a warning by the caller (main()), never added here.
pass
return errs
@@ -573,8 +573,9 @@ def _archive_keys() -> set[str]:
def _budget_total() -> int:
"""Lines of PROSE in the active corpus — YAML frontmatter excluded.
The budget exists to bound how much narrative a reader/agent must get through, so it counts
prose, not metadata. Under the #610 split each record carries ~11 frontmatter lines plus two
Since #620 this is a TREND figure with no threshold attached; the name is historical. It counts
prose rather than metadata because the question it answers is how much narrative a reader/agent
must get through. Under the #610 split each record carries ~11 frontmatter lines plus two
fences (1789 lines across 166 records), which are the structured restatement of what used to be
one dense backtick line — counting them would inflate the metric without any new knowledge
being added.
@@ -584,6 +585,14 @@ def _budget_total() -> int:
over budget; prose-only puts the same content comfortably under. The consolidation work is still
worth doing — it is simply no longer being signalled by a warning that was partly measuring
punctuation. Pre-migration this function is inert: no legacy file has frontmatter.
Since #620 this is reported as an informational TREND only — it no longer carries a threshold.
The GENERATED catalog (`docs/decisions/README.md`) is also no longer counted: it used to be
added on top, which quietly made this partly a record-COUNT metric wearing a line-count
costume, since the catalog gains exactly one row per active record and no amount of
consolidating prose can shrink it (189 of the 5658 lines it last reported were that file).
Counting un-prunable generated output in a number whose stated remedy was "schedule a
consolidation" pointed the reader at work that cannot be done.
"""
total = 0
for f in dl.active_files():
@@ -596,14 +605,41 @@ def _budget_total() -> int:
if end is not None:
lines = lines[end + 1 :]
total += len(lines)
cat = dl.TOPIC_DIR / "README.md"
if cat.exists():
total += len(cat.read_text(encoding="utf-8").splitlines())
return total
def _budget_ok(limit: int) -> bool:
return _budget_total() <= limit
def record_prose_lines(rec) -> int:
"""Prose lines in one record's body (frontmatter already stripped by the parser)."""
return len((rec.body or "").splitlines())
def oversized_records(records, ceiling: int) -> list[tuple[str, int]]:
"""Active records whose prose exceeds `ceiling`, longest first (#620).
This REPLACES the aggregate line budget as the corpus's actionable size signal. The aggregate
measured a monotonically growing quantity: a healthy project's decision corpus only gets
bigger, so any fixed total is a ratchet that must periodically be raised — which is exactly the
"permanently red, therefore no signal at all" state #542 re-baselined away from and #620 was
filed about. Re-baselining it again would only restart that treadmill: the growth is not a smooth
rate to set a threshold against — the corpus FELL from 5089 to 5042 across four days, then gained
427 in a single evening as two large records landed.
A per-record ceiling is NOT monotonic. It measures the shape of individual records rather than
the size of the corpus, so it can go red and green again, and it names a file the reader can
act on instead of asserting that "the corpus" is too big.
The ceiling sits at a natural gap in the real distribution rather than a round number: at #620
the records run 0..59 prose lines (median 26, p90 52) and then jump straight to 83, with
nothing in between. 60 separates the bulk from the tail without splitting a cluster.
IMPORTANT — a prompt for judgement, not a target. Length is a PROXY for "grown past what a
reader can absorb", and the proxy is demonstrably wrong sometimes: the largest record in the
corpus (`scan.libraryfolder-unique-identity`, 230 lines) is thirteen distinct hard-won traps,
and shortening it would delete the only copy of most of them. Appearing in this list is an
invitation to check for REDUNDANCY, never an instruction to cut.
"""
out = [(r.key, record_prose_lines(r)) for r in records if r.key]
return sorted([kv for kv in out if kv[1] > ceiling], key=lambda kv: -kv[1])
def _catalog_ok() -> bool:
@@ -621,26 +657,37 @@ def main(argv=None) -> int:
ap = argparse.ArgumentParser()
ap.add_argument("--base")
ap.add_argument("--head")
# Aggregate active-corpus budget. Re-baselined 2026-07-21 (#542): 4800 -> 5600. The corpus grew
# by ~530 lines because 31 workflow/CI/review rules were MOVED into it from
# docs/handoffs/chicorytv-issue-queue.md, which was their only copy. That is the corpus doing its
# job, not drift — the knowledge existed already, it just wasn't retrievable. Do not raise this
# again to accommodate genuinely new records; that is what the warning is for.
ap.add_argument("--budget", type=int, default=5600)
# Per-record prose ceiling — the corpus's size signal since #620, replacing the aggregate
# budget. See `oversized_records` for why a total was the wrong instrument (it ratchets on a
# monotonically growing quantity) and why 60 (a natural gap in the distribution, not a round
# number). `--budget` is still ACCEPTED so an existing caller keeps working, but it no longer
# does anything — and it SAYS SO when passed (below) rather than no-opping quietly. A flag that
# takes a threshold and silently enforces nothing is the same "reports success while doing
# nothing" defect as #603's `stale-after` and #609's marker; retiring one signal must not
# introduce another.
ap.add_argument("--record-ceiling", type=int, default=RECORD_CEILING_DEFAULT)
ap.add_argument("--budget", type=int, default=None, help=argparse.SUPPRESS)
args = ap.parse_args(argv)
if args.budget is not None:
print(
f"::warning::decisions-validate: --budget {args.budget} is RETIRED and was IGNORED "
f"(#620) — the aggregate is now an unthresholded trend. Use --record-ceiling for the "
f"enforceable per-record signal.",
file=sys.stderr,
)
records = dl.all_active_records()
archive_records = []
if dl.ARCHIVE_DIR.exists():
for f in dl.ARCHIVE_DIR.rglob("*.md"): # rglob: archive is nested by area after #610
archive_records += dl.parse_file(f)
removed, rewritten, demoted = _diff_findings(args.base, args.head) if args.base and args.head else ([], [], [])
budget_ok = _budget_ok(args.budget)
oversized = oversized_records(records, args.record_ceiling)
errs = validate(
records,
archive_keys=_archive_keys(),
catalog_ok=_catalog_ok(),
budget_ok=budget_ok,
removed=removed,
rewritten=rewritten,
archive_records=archive_records,
@@ -648,10 +695,31 @@ def main(argv=None) -> int:
wing_faults=record_wing_faults(),
)
if not budget_ok:
# Aggregate: an unthresholded TREND, not a gate (#620). Printed every run so the number stays
# visible, with no pass/fail attached — a total over a monotonically growing corpus can only
# ratchet, and a permanently-tripped warning is indistinguishable from no warning at all.
keyed = [r for r in records if r.key]
record_prose = sum(record_prose_lines(r) for r in keyed)
total_prose = _budget_total()
print(
f"::notice::decisions-validate: {record_prose} prose lines across {len(keyed)} records "
f"(mean {record_prose // max(len(keyed), 1)}), plus {total_prose - record_prose} lines of "
f"non-record scaffolding = {total_prose} total. Trend only — no threshold; the per-record "
f"ceiling below is the actionable signal.",
file=sys.stderr,
)
# Per-record ceiling: NON-BLOCKING by design (#520 — a size condition must never turn an
# unrelated PR red). Names the files, so the reader can act instead of being told the corpus is
# "too big". Being listed is an invitation to check for redundancy, NOT an instruction to cut:
# the longest record in the corpus is 13 distinct traps and is a legitimate decline (#620).
if oversized:
listed = "; ".join(f"{k} ({n} lines)" for k, n in oversized)
print(
f"::warning::decisions-validate: aggregate active-corpus is {_budget_total()} lines "
f"(budget {args.budget}) — schedule a consolidation",
f"::warning::decisions-validate: {len(oversized)} record(s) exceed the "
f"{args.record_ceiling}-line prose ceiling — check each for redundancy against its "
f"siblings (a long record that is all distinct findings is fine, say so and move on): "
f"{listed}",
file=sys.stderr,
)