feat(603): adopt OKF's optional stale-after and Sources decision-record metadata

Evaluated the Open Knowledge Format (GoogleCloudPlatform/knowledge-catalog okf
v0.2, scaccogatto/okf-skills) as a replacement for our decision-record system and
rejected it: its conformance rules are deliberately permissive exactly where ours
are strict (broken links, unknown types and missing fields must all be tolerated;
`deprecated` points at no successor), and its stable identity is the file path,
which the breadcrumb rule tells agents not to trust.

Adopted two of its optional families instead, additively:

- `stale-after: YYYY-MM-DD` on the metadata line — marks a record asserting an
  outside-world fact as due for re-confirmation. Absolute date, no TTL.
- `**Sources:**` in the metadata block — the evidence a record rests on, as
  distinct from `Signals:` (recall keywords).

Neither is required; absence is never an error. A malformed `stale-after` is
blocking (it would silently never fire), but a past-due record is only a
non-blocking `::notice::` — going stale is the passage of time, not a defect in
whatever commit is under test. The catalog's new "Review due" section renders the
date only and never a clock-derived verdict, so it cannot drift `--check` red on a
calendar boundary with no commit touching the corpus.

No backfill: no existing record adopts either field here.

fixes #603
This commit is contained in:
2026-07-25 15:22:50 +02:00
parent abeef63f05
commit 0ad02db651
10 changed files with 231 additions and 1 deletions
+9
View File
@@ -11,5 +11,14 @@
Rationale prose here.
## 2026-07-19 — Optional stale-after / Sources example (#603)
`key: ci.peak-anon-measurement` · `status: active` · `since: 2026-07-19` · `supersedes: none` · `superseded-by: none` · `stale-after: 2027-01-15`
**Rule:** The test job reports a sampled true peak anon.
**Signals:** ci, memory · paths: scripts/ci-peak-anon.sh · issues: #412
**Mechanics:** docs/ci-cd.md → CI lanes
**Sources:** gitea run 4471 (measured) · scripts/ci-peak-anon.sh
Rationale prose here.
## 2026-07-11 — Legacy unmigrated example (#231)
Some prose with no metadata line at all.
+41
View File
@@ -1,4 +1,5 @@
from pathlib import Path
from typing import Any
import scripts.build_decisions_catalog as bc
import scripts.decisions_lib as dl
@@ -49,3 +50,43 @@ def test_anchor_matches_gitea_double_hyphen_slug():
b = bc._anchor("2026-07-16 — Optional advertised IPTV base URL (`iptv.base_url`)…")
assert "iptvbase_url" in b
def _r(key: str, **kw: Any) -> dl.Record:
base: dict[str, Any] = dict(
heading=f"H {key}",
source=Path("decisions.md"),
lineno=1,
key=key,
status="active",
rule="r",
)
base.update(kw)
return dl.Record(**base)
def test_review_due_section_lists_dated_records_soonest_first():
out = bc.render_catalog(
[
_r("b.later", stale_after="2027-03-01"),
_r("a.sooner", stale_after="2026-09-01"),
_r("c.undated"),
]
)
assert "## Review due" in out
assert out.index("2026-09-01") < out.index("2027-03-01")
assert "c.undated" not in out.split("## Review due")[1]
def test_review_due_section_omitted_when_no_record_is_dated():
assert "## Review due" not in bc.render_catalog([_r("a.b")])
def test_catalog_is_date_independent():
"""The generated file must never bake in 'today' — CI checks it with --check, so a
time-dependent render would drift red on a calendar boundary with no commit touching it."""
past = bc.render_catalog([_r("a.b", stale_after="2020-01-01")])
future = bc.render_catalog([_r("a.b", stale_after="2099-01-01")])
# A long-past and a far-future date must produce byte-identical output apart from the date
# itself: no stale/fresh verdict, no marker, nothing derived from the clock.
assert past.replace("2020-01-01", "D") == future.replace("2099-01-01", "D")
+15
View File
@@ -32,3 +32,18 @@ def test_legacy_record_is_unmigrated():
def test_index_section_parses_as_heading():
recs = dl.parse_file(FIX)
assert any(r.heading == "Index" for r in recs)
def test_parses_optional_stale_after_and_sources():
recs = dl.parse_file(FIX)
r = next(r for r in recs if r.key == "ci.peak-anon-measurement")
assert r.stale_after == "2027-01-15"
assert r.sources is not None
assert "gitea run 4471" in r.sources
def test_optional_fields_default_to_none_when_absent():
recs = dl.parse_file(FIX)
r = next(r for r in recs if r.key == "ci.runner-placement")
assert r.stale_after is None
assert r.sources is None
+45
View File
@@ -411,3 +411,48 @@ def test_diff_engine_demoted_migrated_to_legacy_unmigrated(tmp_path, monkeypatch
_removed, _rewritten, demoted = dv._diff_findings("HEAD~1", "HEAD")
assert "2026-01-01 — Some decision (#1)" in demoted
# ---- optional stale-after / Sources metadata (ersatztv#603) ----
def test_stale_after_absent_is_not_an_error():
assert _v([_rec(key="a.b")]) == []
def test_wellformed_stale_after_is_not_an_error():
assert _v([_rec(key="a.b", stale_after="2027-01-01")]) == []
def test_malformed_stale_after_fails():
for bad in ("2027-13-01", "01-01-2027", "soon", "2027-02-30"):
errs = _v([_rec(key="a.b", stale_after=bad)])
assert any("not a YYYY-MM-DD date" in e for e in errs), bad
def test_past_due_record_does_not_fail_validation():
"""A record going stale is the passage of time, not a defect in the commit under test."""
errs = _v([_rec(key="a.b", stale_after="2020-01-01")])
assert errs == []
def test_stale_records_reports_only_past_due_active():
today = dv.date(2026, 7, 25)
recs = [
_rec(key="past.due", heading="Past", stale_after="2026-07-24"),
_rec(key="due.today", heading="Today", stale_after="2026-07-25"), # today >= date → stale
_rec(key="not.yet", heading="Future", stale_after="2026-07-26"),
_rec(key="no.date", heading="Undated"),
_rec(key="arch.ived", heading="Archived", status="superseded", stale_after="2020-01-01"),
]
assert dv.stale_records(recs, today) == [("Past", "2026-07-24"), ("Today", "2026-07-25")]
def test_stale_records_ignores_malformed_date():
"""A malformed date is caught as a blocking format error; it must not also crash the notice path."""
assert dv.stale_records([_rec(key="a.b", stale_after="whenever")], dv.date(2026, 7, 25)) == []
def test_sources_is_optional_and_never_required():
assert _v([_rec(key="a.b")]) == []
assert _v([_rec(key="a.b", sources="ci run 1234 · docs/ci-cd.md")]) == []