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
+141 -1
View File
@@ -27,7 +27,6 @@ def _v(recs: list[dl.Record], **kw: Any) -> list[str]:
args: dict[str, Any] = dict(
archive_keys=set(),
catalog_ok=True,
budget_ok=True,
removed=[],
rewritten=[],
archive_records=[],
@@ -938,3 +937,144 @@ def test_an_empty_ARCHIVE_wing_is_legitimate(tmp_path):
records, archive = _wing(tmp_path)
(records / "ci" / "good.md").write_text(_GOOD)
assert dv.record_wing_faults(records, archive) == [], "an empty archive must not fault"
# --- #620: per-record ceiling replaces the aggregate budget --------------------------------------
_MINIMAL_RECORD = (
"---\n"
"key: ci.a\n"
"title: '2026-01-01 — A (#1)'\n"
"status: active\n"
"since: '2026-01-01'\n"
"supersedes: none\n"
"superseded-by: none\n"
"rule: 'r'\n"
"signals: 's'\n"
"---\n\nprose.\n"
)
def _rec_body(key: str, lines: int) -> dl.Record:
return _rec(key=key, heading=key, body="\n".join(f"prose line {i}" for i in range(lines)))
def test_oversized_records_flags_only_those_over_the_ceiling():
recs = [_rec_body("a.short", 10), _rec_body("b.exact", 60), _rec_body("c.long", 61)]
assert dv.oversized_records(recs, 60) == [("c.long", 61)], "the ceiling must be exclusive"
def test_oversized_records_sorts_longest_first():
recs = [_rec_body("a.mid", 80), _rec_body("b.big", 200), _rec_body("c.small", 70)]
assert [k for k, _ in dv.oversized_records(recs, 60)] == ["b.big", "a.mid", "c.small"]
def test_oversized_records_can_go_green():
"""The property the aggregate budget structurally lacked: a corpus that satisfies it.
An aggregate over a monotonically growing corpus can only ratchet — it goes red and stays red
until someone raises the number. A per-record ceiling is satisfiable and re-satisfiable, which
is what makes a red mean something."""
recs = [_rec_body("a.short", 10), _rec_body("b.short", 20)]
assert dv.oversized_records(recs, 60) == []
def test_budget_total_excludes_the_generated_catalog(tmp_path, monkeypatch):
"""#620: the catalog gains one row per record and cannot be consolidated away.
Counting it made the 'schedule a consolidation' number partly a record COUNT, pointing the
reader at work that cannot be done. Mutation-sensitive by construction: the catalog here is
large and distinctively sized, so re-adding it would change the total by exactly 500."""
topic = tmp_path / "docs" / "decisions"
records = topic / "records" / "ci"
records.mkdir(parents=True)
(records / "a.md").write_text(_MINIMAL_RECORD)
(topic / "README.md").write_text("\n".join(f"| row {i} |" for i in range(500)))
monkeypatch.setattr(dv.dl, "REPO_ROOT", tmp_path)
monkeypatch.setattr(dv.dl, "DECISIONS_MD", tmp_path / "docs" / "decisions.md")
monkeypatch.setattr(dv.dl, "TOPIC_DIR", topic)
monkeypatch.setattr(dv.dl, "ARCHIVE_DIR", topic / "archive")
monkeypatch.setattr(dv.dl, "RECORDS_DIR", records)
total = dv._budget_total()
assert total < 100, f"the 500-line generated catalog leaked into the total ({total})"
def test_real_corpus_ceiling_sits_at_the_TAIL_BOUNDARY_of_the_distribution():
"""Guards the calibration claim. This is the FOURTH version; the failures are the lesson.
v1 `max(under) <= 60 < min(over)` — true by construction of those two lists.
v2 a minimum gap WIDTH — but a ceiling of 200 also sits in a wide gap, so it passed.
v3 a 2-12% fraction band plus "clear air" measured against `min(over)` — the nearest
record ABOVE the ceiling. That made the test a hostage to an unrelated record: one
ordinary 62-line addition reddened it with the ceiling correctly placed, and the only
remedy the assertion admitted was to RAISE the ceiling. That is the ratchet this whole
change abolishes, reinstated as a hard failure in what #631 makes a blocking CI job.
The fraction band had the same coupling more slowly (12 more long records breached it),
and `0 <= headroom` was vacuous — `max(under)` is by construction <= ceiling.
v4 states the property directly and scale-free: **the ceiling marks the start of the tail**,
i.e. it sits between the 90th and 95th percentile of record lengths. Percentiles move WITH the
corpus, so routine growth cannot ratchet this; it fires only when the ceiling genuinely stops
marking the tail boundary, which is exactly when it should be re-derived.
"""
recs = [r for r in dl.all_active_records() if r.key]
assert len(recs) > 100, f"corpus looks empty ({len(recs)}) — this check would be vacuous"
ceiling = dv.RECORD_CEILING_DEFAULT # the value the CLI actually uses; cannot drift from here
lengths = sorted(dv.record_prose_lines(r) for r in recs)
p90 = lengths[int(len(lengths) * 0.90)]
p95 = lengths[int(len(lengths) * 0.95)]
assert p90 <= ceiling <= p95, (
f"the ceiling ({ceiling}) no longer marks the tail boundary: p90={p90}, p95={p95}. "
f"Below p90 it cuts into the bulk and every author will learn to ignore it; above p95 it is "
f"parked among the outliers and signals nothing. Re-derive it from the distribution."
)
def test_retired_budget_flag_says_it_is_ignored(capsys):
"""A retired flag must announce itself, not no-op silently.
Accepting `--budget 100` and enforcing nothing would be the same 'reports success while doing
nothing' defect this change exists to retire (#603 stale-after, #609 marker)."""
dv.main(["--budget", "100"])
err = capsys.readouterr().err
assert "--budget 100 is RETIRED and was IGNORED" in err, err
def test_no_budget_flag_means_no_retirement_warning(capsys):
dv.main([])
assert "RETIRED" not in capsys.readouterr().err
def test_main_actually_REPORTS_the_ceiling_and_the_trend(capsys):
"""The new signal's live wiring was untested: `if oversized:` -> `if False:`, or bumping the
default ceiling to 999999, left every test green while main() reported nothing. Only the pure
function `oversized_records()` was covered — so the replacement signal could silently do
nothing, which is the exact defect this change exists to retire."""
dv.main([])
err = capsys.readouterr().err
assert "prose lines across" in err, "the aggregate trend notice must always print"
assert "exceed the" in err and "prose ceiling" in err, "the per-record ceiling warning must print"
over = [r.key for r in dl.all_active_records()
if r.key and dv.record_prose_lines(r) > dv.RECORD_CEILING_DEFAULT]
assert over, "precondition: the live corpus has at least one over-ceiling record"
assert any(k in err for k in over), "the warning must NAME the offending records"
def test_trend_notice_reports_record_prose_and_scaffolding_separately(capsys):
"""The notice used to print `_budget_total()` 'across N records', mixing two incompatible
definitions of prose: the total includes ~600 lines of headings and keyless scaffolding
belonging to no record, so dividing it by the record count and comparing that to the 60-line
ceiling compares incommensurable units — a small instance of the 'the metric is not what it
says it is' defect this change indicts."""
dv.main([])
err = capsys.readouterr().err
recs = [r for r in dl.all_active_records() if r.key]
record_prose = sum(dv.record_prose_lines(r) for r in recs)
assert f"{record_prose} prose lines across {len(recs)} records" in err, err
assert "non-record scaffolding" in err, err