fix(763): round 7 — reject an empty post-write history, and the fourth overclaim

A fourth cold review returned NOT-MERGEABLE on two Mediums. Both fixed, plus
its three Lows.

MEDIUM, and a defect this branch introduced. Tolerating a `null`/`[]` page 1 as
"complete, zero rows" is correct for the PRE-write caller — a head nothing has
posted to genuinely has no statuses — and impossible for the POST-write one,
which has just written a row to that sha. The body is well-formed, so nothing
retries it, and the walk reports success: `raced=0` concluded from a list that
cannot be real, on the one path whose failure direction is toward SUCCESS.
Worse than the code it replaced, which at least emitted a `::warning::` — a
logged fail-open had become an unlogged one. Reviewer measured both directions.

The post-write caller now rejects an empty result itself; the walk stays
caller-agnostic because the pre-write caller genuinely needs the empty answer.
This is NOT the withdrawn currency witness: that asked whether ANY row sat above
the mark, which an unrelated newer row satisfied while the rejection stayed
hidden, and it fired on schema-valid staleness. This asks only whether the list
is EMPTY — a state no unrelated row can produce and no ordering can disguise.
It carries neither defect. Proved by fixture; disarming it reddens the named
test, and the previously-uncovered `null`-at-page-1 clause is now covered too.

MEDIUM — the fourth overclaim of the same class, in the decision record body:
"Uncertainty must fail closed at both ends … Both repair now." The page-2 probe
was DELETED, not converted; it repairs nothing. It also contradicted the
record's own `rule:` ("the two directions are NOT symmetric") and the bullet
directly beneath it. Round 5 retracted this wording in `docs/ci-cd.md` only —
the sweep was by subject, not by the retracted words.

Also fixed:
  - the record presented "an empty FIRST page is legitimate" as a property of
    the walk; it is a property of the pre-write caller.
  - `docs/ci-cd.md` called the numeric-only id comparisons a fix for mark
    inflation; they are a TYPE guard, closing the string half. A corrupt but
    genuinely numeric id still inflates the mark — not attacker-controllable,
    since ids are server-assigned, and now stated rather than implied.
  - `test_a_partial_mark_is_SAFE...`'s self-guard promised to detect that the
    fallback ran; it keys on a warning emitted by a different condition, so
    deleting the fallback left it green. Its sibling is what reddens; the
    message now says what it actually pins.
  - the order-faithful fixture appended the job's own POST after the reversal,
    serving the NEWEST row on the OLDEST page — the opposite of DESC, in the one
    fixture that exists to be ordering-faithful.
  - "twice per walk" for the wasted sleep; it is once per walk, twice per run.
  - a dead counter read in the DESC mode.

Rebased onto b16ec15d6 (the other session's #781/#799 docs work; no file
overlap, no conflicts).

Verification: `scripts/tests` 1097 passed, 2 skipped; fifteen executed mutations
across rounds 2-7; decisions_validate and build_decisions_catalog --check exit 0.

refs #763

Decisions-Edit: yes
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-28 17:47:06 +02:00
co-authored by Claude Opus 5
parent 89db6022d9
commit e6f04cc739
5 changed files with 117 additions and 24 deletions
+27 -4
View File
@@ -798,7 +798,7 @@ jobs:
# Gitea restart either, and saying so is the point: this absorbs a momentary blip, not
# an outage. An outage still lands on `ph_ok=no`, which is the safe direction.
# Only BETWEEN attempts — sleeping after the last one delays a failure nobody is
# waiting on, twice per walk.
# waiting on, once per walk and so twice per job run.
if [ "$try" -eq 1 ]; then sleep 1; fi
done
# `null` COUNTS AS AN EMPTY PAGE, though this endpoint returns `[]` today. An
@@ -806,9 +806,12 @@ jobs:
# really did return `null` past the end, so the walk never reached a validated empty
# page and the fence withheld EVERY exemption. Re-adopting that narrowing on a second
# endpoint would be worse, because this walk's failure is the STICKY sentinel — every
# exempt PR would need a human verdict, per head. Tolerating `null` costs nothing and
# cannot misread `[]`; asserting the endpoint will never change its empty shape is a
# bet with no upside.
# exempt PR would need a human verdict, per head. It cannot misread `[]` either.
#
# It is NOT free, though, and the cost lands on one caller: an empty page 1 accepted as
# "complete, zero rows" is correct BEFORE the write and impossible AFTER it. The
# post-write caller therefore rejects an empty result itself, below — this walk stays
# caller-agnostic because the pre-write caller genuinely needs the empty answer.
case "$kind" in
null) ph_ok=yes; ph_rows=$acc; return 0 ;;
array) ;;
@@ -1323,6 +1326,26 @@ jobs:
# is the wrong direction on this path; see below.
if [ "$state" = "success" ] && [ "$max_id_before" -ge 0 ]; then
page_statuses
# AN EMPTY HISTORY IS IMPOSSIBLE HERE, so it is not evidence. This job has just POSTed to
# this sha, and `/statuses/{sha}` returns one row per POST, so a well-formed response
# saying "no statuses exist" contradicts a write that succeeded. Accepting it yields
# `raced=0` — a green concluded from a list that cannot be real — on the one path whose
# failure direction is toward SUCCESS, and silently, since the walk itself reports
# success. Before this endpoint was paged, the equivalent response at least produced a
# `::warning::`; tolerating a `null`/`[]` page 1 here would have turned a logged fail-open
# into an unlogged one.
#
# THIS IS NOT THE WITHDRAWN CURRENCY WITNESS, and the difference is what makes it safe.
# That mechanism asked "is there ANY row above the mark", which an unrelated newer row
# satisfied while the rejection stayed hidden, and which fired on schema-valid staleness.
# This asks only whether the list is EMPTY — a state no unrelated row can produce and no
# ordering can disguise. It carries neither defect.
ph_len_after=$(printf '%s' "$ph_rows" | jq -r 'if type == "array" then length else 0 end' 2>/dev/null) || ph_len_after=0
case "$ph_len_after" in ''|*[!0-9]*) ph_len_after=0 ;; esac
if [ "$ph_ok" = yes ] && [ "$ph_len_after" -eq 0 ]; then
echo "::warning::The status history for ${SHA:0:7} came back empty after this job posted to it, which cannot be true, so a raced verdict could not be ruled out. Repairing ${CONTEXT} to pending."
ph_ok=no
fi
# WHY the repair fired, so the log can stop asserting something it does not know. The
# sentinel DESCRIPTION stays generic on purpose — the classification recognises it as a
# fixed point, so its wording is load-bearing — but the `::error::` beside it need not be.
+11 -2
View File
@@ -1614,8 +1614,10 @@ The two directions are **not** symmetric, and the asymmetry is deliberate:
unchanged here. A non-empty history carrying no numeric id is reported as unusable rather than
collapsed to 0.
Two id comparisons are **numeric-only**, both closing a fail-open: jq orders strings above every
number, so one `"id": "99999"` would inflate the high-water mark until nothing looked newer, and
Two id comparisons are **numeric-only**, closing the *string* half of a fail-open (a type guard, not
a value bound — a corrupt but genuinely numeric id would still inflate the mark, which is not
attacker-controllable since ids are server-assigned): jq orders strings above every number, so one
`"id": "99999"` would inflate the high-water mark until nothing looked newer, and
`.id > $since` would read any string id as newer than any mark — making a pre-existing base-mismatched
verdict look raced on every run, a permanent stall. `.creator` is likewise type-tested before it is
indexed, because `.creator.login` on a non-object exits jq 5 and, under `set -e`, took the step down
@@ -1639,6 +1641,13 @@ GETs with no snapshot token, so under DESC a new row lands at position 0 — on
while everything else shifts down. It is bounded: a row arriving after this job's POST is not one the
job overwrote, and being newest it wins on the combined endpoint branch protection reads.
**An empty post-write history is rejected.** The walk terminates on an empty page — correct before the
write, impossible after it, since this job has just POSTed and the endpoint returns one row per POST. A
well-formed "no statuses exist" is not retried (the body is valid), so accepting it would conclude
`raced=0` from a list that cannot be real, silently. This is *not* the withdrawn currency witness: that
asked whether ANY row sat above the mark, which an unrelated newer row satisfied; this asks only whether
the list is empty, which no unrelated row can produce.
The `::error::` distinguishes a verdict actually found from an unverifiable read; the sentinel
*description* stays generic, because the classification recognises it as a fixed point.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+62 -7
View File
@@ -1139,9 +1139,6 @@ if "/statuses/" in url:
# repair on a head nothing raced, which is the #761 failure. This fixture is what makes
# that difference observable.
order_faithful = True
ctr = out / "history_reads.txt"
seen = int(ctr.read_text()) if ctr.exists() else 0
ctr.write_text(str(seen + 1))
rows = [{"id": 7000 + i, "context": "ci/other", "status": "success",
"creator": None, "description": "unrelated"}
for i in range(60) if 7000 + i != 7055]
@@ -1149,6 +1146,14 @@ if "/statuses/" in url:
"creator": {"login": "timothy"},
"description": "Review-verdict: MERGEABLE @ a9e3e23 (base: other)"})
rows.sort(key=lambda r: r["id"])
elif mode == "null-page1-after-post":
# The post-write read answers "no statuses exist" for a sha this job has just POSTed to —
# impossible, but well-formed, so no retry fires and the walk reports success over it. A
# human verdict really did land in the write window, and accepting the empty answer buries
# it behind a green nobody could see was unverified.
rows = [{"id": 7000 + i, "context": "ci/other", "status": "success",
"creator": None, "description": "unrelated"} for i in range(3)]
rows.append(dict(raced_row))
elif mode == "null-terminator":
# This endpoint returns `[]` past the end today. `null` is what `/issues/{n}/timeline`
# returns, and an array-only gate on THAT endpoint was ersatztv#751 — the walk never
@@ -1245,9 +1250,17 @@ if "/statuses/" in url:
# the double crashed rather than because the mark was computed correctly.
nxt = max([r.get("id") for pg in pages for r in pg
if isinstance(r.get("id"), int)] or [0]) + 1
pages[-1].append({"id": nxt, "context": body.get("context"),
"status": body.get("state"), "creator": None,
"description": body.get("description", "")})
own = {"id": nxt, "context": body.get("context"),
"status": body.get("state"), "creator": None,
"description": body.get("description", "")}
# WHERE the newest row goes depends on the served ordering. Under DESC it is FIRST;
# appending it last would put the job's own POST on the OLDEST page, the arrangement
# the order-faithful fixture exists to rule out. Ordering-blind modes keep insertion
# order, which is what lets them place a row beyond page 1.
if order_faithful and not want_asc:
pages[0].insert(0, own)
else:
pages[-1].append(own)
snapshot.write_text(json.dumps(pages))
else:
n_logical = int(logical.read_text()) if logical.exists() else 1
@@ -1276,6 +1289,9 @@ if "/statuses/" in url:
sys.exit(0)
if hist_page > 1 and mode == "second-page-error":
sys.exit(22)
if hist_page == 1 and mode == "null-page1-after-post" and n_logical >= 2:
print("null")
sys.exit(0)
if hist_page > 1 and mode == "null-terminator" and hist_page > len(pages):
print("null")
sys.exit(0)
@@ -3813,8 +3829,12 @@ def test_a_partial_mark_is_SAFE_because_the_newest_rows_are_on_page_1(tmp_path):
posted, r = _run_classify(tmp_path, _emitting("docs/a.md"), history_mode="premark-page2-error-desc")
assert r.returncode == 0, r.stderr
log = r.stdout + r.stderr
# This pins that the walk really was INCOMPLETE — it does not prove the fallback ran, because the
# warning is emitted by a different condition than the one that salvages the mark. Deleting the
# fallback leaves this line green; the sibling test
# `test_a_PRE_WRITE_paging_failure_still_yields_a_usable_high_water_mark` is what reddens then.
assert "taking the high-water mark over the" in log, (
f"the partial-list fallback did not run, so this test is not measuring it:\n{r.stdout[-900:]}"
f"the pre-write walk completed, so this test is not exercising a partial mark at all:\n{r.stdout[-900:]}"
)
seq = _posted_sequence(tmp_path)
assert len(seq) == 1, (
@@ -3827,6 +3847,41 @@ def test_a_partial_mark_is_SAFE_because_the_newest_rows_are_on_page_1(tmp_path):
)
def test_an_EMPTY_post_write_history_is_not_evidence_that_nothing_raced(tmp_path):
"""A well-formed response that cannot be true must not be trusted, and this one is free to reach.
The walk terminates on an empty page — correct BEFORE the write, where a head nothing has posted
to genuinely has no statuses. AFTER the write it is impossible: this job has just POSTed, and
`/statuses/{sha}` returns one row per POST, so "no statuses exist" contradicts a write that
succeeded. Nothing retries it either, because the body is valid JSON of the right type.
Accepting it yields `raced=0` from a list that cannot be real, on the one path whose failure
direction is toward SUCCESS — and silently, since the walk reports success. Here a human verdict
really did land in the write window and would be buried behind an unverified green.
This is NOT the withdrawn currency witness. That asked "is there ANY row above the mark", which an
unrelated newer row satisfied while the rejection stayed hidden. This asks only whether the list is
EMPTY — a state no unrelated row can produce and no ordering can disguise.
"""
posted, r = _run_classify(tmp_path, _emitting("docs/a.md"), history_mode="null-page1-after-post")
assert r.returncode == 0, r.stderr
log = r.stdout + r.stderr
seq = _posted_sequence(tmp_path)
assert len(seq) == 2, (
"an empty post-write history was accepted as proof that nothing raced this write, so the "
f"exemption stands over a verdict it cannot have seen. Posts: {seq}\n{r.stdout[-900:]}"
)
assert seq[0]["state"] == "success" and seq[1]["state"] == "pending", (
f"expected an exemption then a repair to pending; got {seq}"
)
assert "came back empty" in log, (
f"repaired, but the impossible empty read was not reported as the reason:\n{r.stdout[-900:]}"
)
assert "was overwritten" not in log, (
f"an unverifiable read was reported as an overwritten human verdict:\n{r.stdout[-900:]}"
)
def test_a_NULL_page_terminates_the_walk_as_an_empty_one(tmp_path):
"""`/statuses/{sha}` returns `[]` past the end today; `/issues/{n}/timeline` returns bare `null`.