fix(retrieval-gate): row 5 reads ~/ paths, refuses absolute ones and checks the bundle's tree ref

The committed hold-out registration carried two absolute paths of the machine
it was written on, in a public repository, and its `bundle_ref` was read by no
line: other bytes at the registered bundle path would have been measured as
the registered bundle.

- A registered path must be `~/...` and is expanded when read; an absolute or
  otherwise relative path is a NO with its reason and is never followed.
- A twelfth check, "the bundle is the registered tree", measures the bundle
  with `consume.bundle_ref` against the pinned ref; a mismatch, an absent
  bundle or no pinned ref is a NO, and the hold-out is then NOT run.
- An absent set is reported with its registered `~/` path.

Chose `~/` over an environment variable because the file then explains
itself and the gate needs no extra setup. The change is in
`tools/okf_retrieval_gate.py` only; `src/` is untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-09-23 10:24:21 +02:00
commit 90cc463cd9
Signed by: ktg
SSH key fingerprint: SHA256:JakMjO6FTBBzN0Bhfj9saOoEjaFxlSdYuZQQpM/lF9Q

View file

@ -1642,9 +1642,55 @@ def _as_share(value: object) -> float | None:
return number
#: A registration is committed to a PUBLIC repository and read on more than
#: one machine, so every path it names is written under the home directory
#: and expanded when read. An absolute path names ONE machine -- it is refused
#: with its reason and never followed, so a machine path cannot be registered
#: again without row 5 saying so.
HOME_PREFIX = "~/"
def _home_path(value: object) -> tuple[Path | None, str]:
"""A registered path expanded against the home directory, or None and
the reason it is refused. The text returned beside a path is the
registration's own `~/...`, so a row names what was registered and never
the machine it was read on."""
text = value.strip() if isinstance(value, str) else ""
if not text:
return None, "not named"
if not text.startswith(HOME_PREFIX):
kind = "an absolute path" if Path(text).is_absolute() else "not under the home directory"
return None, f"`{text}` is {kind}; a registration names `{HOME_PREFIX}...` and no machine"
return Path(text).expanduser(), text
def _registered_bundle(spec: Mapping[str, object]) -> tuple[Path | None, str]:
"""The bundle the registration names, IF its tree still measures the
`bundle_ref` the registration pins; otherwise None and why.
A bundle path is a place, and a place can be filled with other bytes: the
ref is what makes the path the registered bundle."""
path, text = _home_path(spec.get("bundle"))
if path is None:
return None, text
registered = spec.get("bundle_ref")
if not isinstance(registered, str) or not registered:
return None, "the registration pins no bundle_ref"
if not path.is_dir():
return None, f"the bundle is absent at {text}"
try:
measured = consume.bundle_ref(path)
except Exception as error: # a bundle that cannot be measured is a NO
return None, f"no ref could be measured at {text}: {type(error).__name__}: {error}"
if measured != registered:
return None, f"{text} measures {measured}, the registration pins {registered}"
return path, f"{text} measures the pinned {registered[:24]}"
def _hold_out_verdict(
spec: Mapping[str, object],
set_path: Path,
set_path: Path | None,
set_text: str,
bundle: Path | None,
pinned: str,
threshold: float | None,
) -> tuple[bool, str]:
@ -1653,19 +1699,20 @@ def _hold_out_verdict(
Every refusal is a NO with its reason and never an exception: a
registration naming an absent set is a finding about the registration.
A bundle that is not the registered tree is never measured -- a share
read off other bytes is not the registered hold-out's.
"""
if threshold is None:
return False, "no numeric threshold to compare with"
bundle = str(spec.get("bundle", ""))
if not bundle:
return False, "the registration names no bundle to measure against"
if bundle is None:
return False, "not run: the bundle is not the registered tree"
if set_path is None:
return False, f"not run: the set is {set_text}"
if not set_path.is_file():
return False, f"the set is absent at {_display(set_path)}"
return False, f"the set is absent at {set_text}"
try:
question_set = read_hold_out_set(set_path, pinned)
bundles = _bundle_map(bundle)
if list(bundles) == [""] and question_set.bundle:
bundles = {question_set.bundle: bundles[""]}
bundles = {question_set.bundle: bundle}
units = [
unit
for question in question_set.questions
@ -1710,6 +1757,15 @@ def row_five(
registration first and the ranking change second, and it is red today
because neither has happened.
AND IT NAMES NO MACHINE, AND THE BUNDLE IT NAMES IS THE ONE IT PINNED.
Until 2026-09-23 the committed registration carried two absolute paths of
the machine it was written on, in a public repository, and `bundle_ref`
was a field no line read -- other bytes at the registered bundle path
would have been measured as the registered bundle. Its paths are now
`~/...`, expanded when read, and an absolute one is a NO; the bundle's
tree is measured with `consume.bundle_ref` and a ref other than the pinned
one is a NO, with the hold-out NOT run against it.
WHAT GIT CANNOT PROVE, stated rather than implied: that nobody read the
number before writing the threshold. A number can be read from an
uncommitted working tree, and no history shows that. What history does
@ -1732,6 +1788,9 @@ def row_five(
" and a bundle named, so the set can be RUN and its share put "
"beside the threshold. A number never compared with a measurement "
"is a note",
" both paths written `~/...` -- the file is public and an "
"absolute path names one machine -- and the bundle's tree ref "
"pinned as `bundle_ref`, so other bytes at that path are not measured",
" and COMMITTED before the ranking moves: git must show the "
f"registration in a commit of its own, with a later commit to "
f"{RANKING_PATH}. That is the half a session cannot write about itself",
@ -1744,10 +1803,10 @@ def row_five(
checks: list[tuple[str, bool, str]] = []
threshold = str(spec.get("threshold", ""))
written_at = str(spec.get("threshold_written_at", ""))
set_path = Path(str(spec.get("set", "")))
set_path, set_text = _home_path(spec.get("set"))
pinned = str(spec.get("sha256", ""))
readings = spec.get("readings", [])
checks.append(("a set is named", bool(str(spec.get("set", ""))), str(set_path)))
checks.append(("a set is named", set_path is not None, set_text))
checks.append(("a sha256 is pinned", len(pinned) == 64, pinned[:12]))
number = _as_share(threshold)
checks.append(
@ -1765,13 +1824,16 @@ def row_five(
str(spec.get("written_by", "")),
)
)
present = set_path is not None and set_path.is_file()
checks.append(
(
"the pinned bytes are the bytes on disk",
set_path.is_file() and sha256_of(set_path) == pinned,
"present" if set_path.is_file() else "absent",
present and set_path is not None and sha256_of(set_path) == pinned,
f"present at {set_text}" if present else f"absent at {set_text}",
)
)
bundle, bundle_note = _registered_bundle(spec)
checks.append(("the bundle is the registered tree", bundle is not None, bundle_note))
early = [
reading
for reading in readings
@ -1789,7 +1851,7 @@ def row_five(
# whole check until 2026-09-20, and `report-only; any number is acceptable
# for v1` passed it. The hold-out is run HERE, against the bundle the
# registration names, and the row says what it measured.
cleared, note = _hold_out_verdict(spec, set_path, pinned, number)
cleared, note = _hold_out_verdict(set_path, set_text, bundle, pinned, number)
checks.append(("the measured hold-out clears the threshold", cleared, note))
history = provenance(registration)