fix(849): round 5+6 — the survivors a mutation SWEEP found, and the six that cannot be reached

Codex was unavailable for this round (usage quota), so the cross-family reviewer was
replaced by a same-family agent doing one mechanical job: enumerate every security-bearing
clause the diff adds, disarm each, and run the WHOLE suite per mutant. 60 mutants, 40 red,
20 survivors — a yield no per-finding review in this series came close to, because a review
looks at what the diff says it does and a sweep looks at what the tests actually pin.

## Proved (nine)

- the description type test in the RECONCILIATION `buried` filter — exact twin of the
  post-write one, which had a proof; without it a numeric description hard-errors
  `startswith`, the count comes back unusable, and the genuine verdict on the next row is
  lost with it;
- the `.status` / `.description` / `.id` type tests, parametrised over all four consumed
  fields so a fifth cannot be added without a case (`.creator`'s was the only one proved);
- both retry loops — the combined read and `repair_status_to`'s second POST. Against a stub
  that fails EVERY attempt a retrying reader and a one-shot reader are indistinguishable,
  which is how a retry ships unexercised; the fixtures now fail only the first attempt;
- the mid-run guard's self-exemption, which is what stops a sentinel-writing run abstaining
  on the row it was about to replace with an equivalent one;
- both repair-write failure paths (the repair and the post-POST replacement), reachable only
  with a stub that lets the FIRST post through and fails the rest — with every post failing
  the job dies on its own classification write and never reaches them;
- the two `state=pending` updates after a repair. The first is load-bearing beyond tidiness:
  without it a repaired head re-enters the post-POST check and, on a retarget it then
  observes, replaces `$REPAIR_DESC` with the weaker reconcilable sentinel — the same ordering
  inversion the floor beside it exists to prevent, reached by another route.

## Declared unreachable (six), enumerated rather than counted

The path-predicate failure branch; the empty-`row` refusal; page 2's non-numeric length; the
`$witness` normalisation; and the two unusable-count arms. Each is defence in depth behind a
filter that makes its input well-formed for every case a fixture can pose — the same standing
exception the post-write unusable-count arm already carried.

That set has gone two -> five -> six across three rounds as the sweep widened. Naming them is
the point: an inventory that undercounts reads as a checked claim and talks the next reader
out of verifying, which is the same defect as inventing coverage — and this branch has
already had to correct that twice.

refs #849
Decisions-Edit: yes

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019T79beF1Ufid3dXju4yqkF
This commit is contained in:
2026-08-30 05:13:29 +02:00
co-authored by Claude Opus 5
parent 28e82fcb59
commit bbaf1d76f8
3 changed files with 366 additions and 4 deletions
+364 -2
View File
@@ -956,6 +956,24 @@ url = [a for a in args if a.startswith("http")][-1]
out = pathlib.Path(os.environ["STUB_DIR"])
if "-X" in args and args[args.index("-X") + 1] == "POST":
if os.environ.get("STUB_POST_FAILS") == "after-first":
# THE FIRST POST SUCCEEDS AND EVERY LATER ONE FAILS. That is the only arrangement that
# reaches a REPAIR write's failure handling: with every POST failing, the job dies on the
# first one and never gets there, so the two behaviours are indistinguishable.
ctr = out / "post_attempts.txt"
seen = int(ctr.read_text()) if ctr.exists() else 0
ctr.write_text(str(seen + 1))
if seen > 0:
sys.exit(22)
if os.environ.get("STUB_POST_FAILS") == "first":
# ONLY THE FIRST ATTEMPT, so a writer that retries succeeds and one that does not fails.
# Against a stub that fails EVERY attempt the two are indistinguishable, which is how a
# retry loop ends up shipped and unexercised.
ctr = out / "post_attempts.txt"
seen = int(ctr.read_text()) if ctr.exists() else 0
ctr.write_text(str(seen + 1))
if seen == 0:
sys.exit(22)
if os.environ.get("STUB_POST_FAILS") == "1":
# EVERY POST FAILS, retries included. `gh` is `curl -sf`, so an HTTP error is exit 22 with
# empty stdout. Without this the write helpers' failure arms are unreachable — and one of
@@ -1582,6 +1600,30 @@ if "/status" in url:
"description": "Review-verdict: MERGEABLE @ a9e3e23 (base: main)"}]
print(json.dumps({"state": "success", "total_count": len(rows), "statuses": rows}))
sys.exit(0)
if mode == "flaky-combined":
# THE FIRST ATTEMPT ONLY. The read is retried once; without the retry this head reads as
# unreadable and takes the replacement path, which is a real behavioural difference and the
# only thing that distinguishes a retrying read from a one-shot one.
ctr = out / "combined_attempts.txt"
seen = int(ctr.read_text()) if ctr.exists() else 0
ctr.write_text(str(seen + 1))
if seen == 0:
sys.exit(22)
print(empty_statuses())
sys.exit(0)
if mode.startswith("malformed-field:"):
# ONE CONSUMED FIELD AT A TIME. The `.creator` case had a proof and the other three did not,
# which is the per-FIELD gap this repo has a record for: a route written once for the field
# that produced it, and the siblings left to the reader's assumption.
field = mode.split(":", 1)[1]
row = {"id": 5, "context": "review-verdict/h10", "status": "failure",
"creator": {"login": "timothy"},
"description": "Review-verdict: BLOCKED @ a9e3e23 (base: main)"}
# `.id` is a NUMBER when well-formed, so corrupting it needs a string; the other three
# are strings or an object, so a number corrupts them.
row[field] = "seven" if field == "id" else 7
print(json.dumps({"state": "failure", "total_count": 1, "statuses": [row]}))
sys.exit(0)
if mode.startswith("sentinel-with-id:"):
# THE CURRENT SENTINEL, AT A STABLE ID, on both reads. The reconciliation witness has to
# identify THIS row, so a fixture needs the combined endpoint to name an id that the seeded
@@ -1733,7 +1775,7 @@ def _run_classify(
timeline_terminator: str = "null",
status_empty_shape: str = "null",
mutate: tuple[str, str] | None = None,
post_fails: bool = False,
post_fails: bool | str = False,
):
"""Execute the workflow's classify `run:` block with a stubbed enumeration script.
@@ -1774,7 +1816,7 @@ def _run_classify(
env["STUB_HISTORY_CREATOR"] = history_creator
env["STUB_HISTORY_EXTRA"] = json.dumps(history_extra) if history_extra else ""
env["STUB_UNVERIFIED_DESC"] = UNVERIFIED_DESC
env["STUB_POST_FAILS"] = "1" if post_fails else ""
env["STUB_POST_FAILS"] = post_fails if isinstance(post_fails, str) else ("1" if post_fails else "")
env["STUB_MIDRUN_CREATOR"] = midrun_creator
env["STUB_PRE_ROW"] = pre_row
env["STUB_MIDRUN_ROW"] = midrun_row
@@ -6329,6 +6371,326 @@ def test_a_STRING_id_on_the_current_row_takes_the_SCHEMA_FAULT_route(tmp_path):
)
@pytest.mark.parametrize("field", ["status", "creator", "description", "id"])
def test_EVERY_consumed_field_of_the_existing_row_takes_the_SCHEMA_FAULT_route(tmp_path, field):
"""Swept by FIELD, not written once for the field that produced it.
The `.creator` case is the one a review measured, and a route written for it alone leaves the
other three to the reader's assumption — which is the per-field gap this repo keeps re-learning.
Each of the four is read by a decision: `.creator` and `.description` by the provenance test,
`.status` by both short-circuits, `.id` by the reconciliation witness.
"""
posted, r = _run_classify(tmp_path, _emitting("docs/a.md"), status_mode=f"malformed-field:{field}")
assert posted is not None and posted["description"] == UNVERIFIED_DESC, (
f"a corrupt .{field} did not take the fault route: {posted}\n{r.stdout[-900:]}"
)
assert r.returncode != 0, "an unreadable row must still fail the job"
@pytest.mark.parametrize(
"field,shipped,mutated",
[
("status", '(.status | type) == "null" then "" else $f end', 'true then "" else "" end'),
(
"description",
'(.description | type) == "null" then "" else $f end',
'true then "" else "" end',
),
],
)
def test_MUTATION_a_malformed_field_read_as_ABSENT_stops_reaching_the_fault_route(tmp_path, field, shipped, mutated):
"""The two fields whose type test had no proof of its own.
`.creator`'s is proved separately (it is the one whose failure greens a rejection outright). For
these two the mutant's damage is quieter and still real: the row reads as stateless or
descriptionless, so the provenance tests see nothing to inherit and the run re-derives a head it
cannot actually read.
"""
posted, rm = _run_classify(
tmp_path / "mutant",
_emitting("docs/a.md"),
status_mode=f"malformed-field:{field}",
mutate=(f"elif {shipped}", f"elif {mutated}"),
)
assert posted is None or posted["description"] != UNVERIFIED_DESC, (
f"the mutant still took the fault route for .{field}, so its own type test is not what sends "
f"it there: {posted}\n{rm.stdout[-900:]}"
)
def test_a_MALFORMED_description_in_the_history_does_not_lose_the_verdict_beside_it(tmp_path):
"""The reconciliation's `buried` filter, twin of the post-write one that already had a proof.
`(.description | type) == "string"` is what keeps a numeric description from hard-erroring
`startswith`. Without it the whole count comes back unusable, the sentinel is carried forward,
and the genuine verdict on the next row — the one reconciliation exists to find — is never
counted, so the head never gets its human-only marker.
"""
seed = [
_sentinel_row(),
{
"id": 4100,
"context": "review-verdict/h10",
"status": "failure",
"creator": {"login": "timothy"},
"description": 7,
},
{
"id": 4200,
"context": "review-verdict/h10",
"status": "failure",
"creator": {"login": "timothy"},
"description": "Review-verdict: BLOCKED @ a9e3e23 (base: main)",
},
]
posted, r = _run_classify(
tmp_path / "fixed",
_emitting("docs/a.md"),
status_mode="existing:pending",
status_creator=None,
status_desc=UNVERIFIED_DESC,
history_extra=seed,
)
assert posted is not None and posted["description"] == REPAIR_DESC, (
f"the verdict beside a malformed row was lost with it: {posted}\n{r.stdout[-900:]}"
)
mutant, rm = _run_classify(
tmp_path / "mutant",
_emitting("docs/a.md"),
status_mode="existing:pending",
status_creator=None,
status_desc=UNVERIFIED_DESC,
history_extra=seed,
mutate=(
'| select(((.description | type) == "string")\n'
' and (.description | startswith("Review-verdict:")))] | length\') || buried=""',
'| select((.description // "") | startswith("Review-verdict:"))] | length\') || buried=""',
),
)
assert mutant is not None and mutant["description"] != REPAIR_DESC, (
"the mutant still upgraded, so the description type test is not what keeps the verdict "
f"countable: {mutant}\n{rm.stdout[-900:]}"
)
def test_the_combined_read_RETRIES_a_transient_failure(tmp_path):
"""A retry that never retries is a silent degradation, and this one is load-bearing.
It is what keeps the route-5 replacement attached to a PERSISTENT failure: without it a single
blip costs a head whatever verdict it carries, which is the trade the comment there explicitly
says the retry buys down. Against a stub that fails EVERY attempt a retrying read and a one-shot
read are indistinguishable, which is how it shipped unexercised.
"""
posted, r = _run_classify(tmp_path / "fixed", _emitting("docs/a.md"), status_mode="flaky-combined")
assert posted is not None and posted["state"] == "success", (
f"a transient combined-read failure was not retried: {posted}\n{r.stdout[-900:]}"
)
mutant, rm = _run_classify(
tmp_path / "mutant",
_emitting("docs/a.md"),
status_mode="flaky-combined",
mutate=(" for try in 1 2; do\n json=$(gh", " for try in 1; do\n json=$(gh"),
)
assert mutant is not None and mutant["description"] == UNVERIFIED_DESC, (
"the mutant did not take the replacement path, so the retry is not what absorbs the blip: "
f"{mutant}\n{rm.stdout[-900:]}"
)
def test_the_sentinel_write_RETRIES_a_transient_POST_failure(tmp_path):
"""`repair_status_to`'s second attempt, on the one write whose failure leaves the gate unmarked."""
posted, r = _run_classify(
tmp_path / "fixed",
_emitting("docs/a.md"),
timeline_mode="unreadable",
post_fails="first",
)
assert posted is not None and posted["description"] == UNVERIFIED_DESC, (
f"a transient POST failure lost the sentinel write: {posted}\n{r.stdout[-900:]}"
)
mutant, rm = _run_classify(
tmp_path / "mutant",
_emitting("docs/a.md"),
timeline_mode="unreadable",
post_fails="first",
# The SECOND attempt only. The block is byte-identical to the first, so the clause is
# that second copy TOGETHER WITH the `return 1` after it, which is what makes it unique.
mutate=(
" if gh -X POST -H 'Content-Type: application/json' -d \"$body\" \\\n"
' "$BASE_URL/repos/$REPO/statuses/$SHA" >/dev/null 2>&1; then\n'
" return 0\n"
" fi\n"
" return 1",
" return 1",
),
)
assert mutant is None, (
"the mutant still wrote the sentinel, so the second attempt is not what absorbs the blip: "
f"{mutant}\n{rm.stdout[-900:]}"
)
def test_a_run_whose_OWN_write_is_the_sentinel_does_not_abstain_on_it(tmp_path):
"""The mid-run sentinel guard exempts a run that is itself writing a sentinel.
Without that exemption the run abstains on a row it was about to replace with an equivalent one,
posts nothing, and the head keeps whichever sentinel got there first — which is not wrong in
state but IS the deadlock shape: replacing a sentinel with a sentinel loses nothing, and refusing
to is how a fixed point stops converging.
The fixture is the case that needs it: the head's sentinel is replaced mid-run (ids 100 -> 200,
byte-identical text), and the seed does NOT name id 100, so reconciliation cannot clear it and
this run's own write is the sentinel too.
"""
seed = [_sentinel_row(4321)]
posted, r = _run_classify(
tmp_path / "fixed",
_emitting("docs/a.md"),
status_mode="sentinel-replaced-mid-run",
history_extra=seed,
)
assert posted is not None and posted["description"] == UNVERIFIED_DESC, (
f"the run abstained on a row its own write would have matched: {posted}\n{r.stdout[-900:]}"
)
mutant, rm = _run_classify(
tmp_path / "mutant",
_emitting("docs/a.md"),
status_mode="sentinel-replaced-mid-run",
history_extra=seed,
mutate=(
' && [ "$desc" != "$REPAIR_DESC" ] && [ "$desc" != "$UNVERIFIED_DESC" ]; then',
" ; then",
),
)
assert mutant is None, (
"the mutant did not abstain, so the sentinel exemptions on that guard are not what lets a "
f"sentinel-writing run through: {mutant}\n{rm.stdout[-900:]}"
)
def test_a_FAILED_repair_write_FAILS_the_job(tmp_path):
"""The repair is the write whose failure leaves an unverified status standing.
`post_fails="after-first"` is the only arrangement that reaches it: with every POST failing the
job dies on its own classification write and never gets here, so a job that ignores the repair's
result and one that acts on it look identical.
"""
posted, r = _run_classify(
tmp_path / "fixed",
"#!/usr/bin/env bash\n" + DOCS_ONLY + "exit 1\n",
history_mode="human-after-post",
post_fails="after-first",
)
assert r.returncode != 0, f"a repair that never landed reported a clean run:\n{r.stdout[-900:]}"
assert "COULD NOT REPAIR" in (r.stdout + r.stderr), (
f"the job went red, but not because the repair failed:\n{r.stdout[-900:]}"
)
_, rm = _run_classify(
tmp_path / "mutant",
"#!/usr/bin/env bash\n" + DOCS_ONLY + "exit 1\n",
history_mode="human-after-post",
post_fails="after-first",
mutate=(' if ! repair_status_to "$repair_desc"; then', " if false; then"),
)
assert rm.returncode == 0, (
"the mutant still failed the job, so the repair's result is not what reddens it: "
f"rc={rm.returncode}\n{rm.stdout[-900:]}"
)
def test_MUTATION_a_repair_that_leaves_state_at_success_re_enters_the_post_POST_check(tmp_path):
"""`state=pending` after the repair is what keeps the post-POST check off a repaired head.
Without it the block still sees `success`, walks the timeline a third time, and — on a retarget
it then observes — replaces the REPAIR sentinel with the weaker reconcilable one. That is the
same ordering inversion the floor beside it exists to prevent, reached by a different route.
"""
posted, r = _run_classify(
tmp_path / "fixed",
_emitting("docs/a.md"),
history_mode="human-after-post",
timeline_mode="moves:0,0,1",
)
seq = _posted_sequence(tmp_path / "fixed")
assert len(seq) == 2 and seq[-1]["description"] == REPAIR_DESC, (
f"expected the exemption then the repair, and nothing after it: {seq}\n{r.stdout[-900:]}"
)
_run_classify(
tmp_path / "mutant",
_emitting("docs/a.md"),
history_mode="human-after-post",
timeline_mode="moves:0,0,1",
mutate=(
' echo "Repaired ${CONTEXT} to pending on ${SHA:0:7} (${repair_desc})."\n state=pending',
' echo "Repaired ${CONTEXT} to pending on ${SHA:0:7} (${repair_desc})."',
),
)
mseq = _posted_sequence(tmp_path / "mutant")
assert len(mseq) == 3 and mseq[-1]["description"] == UNVERIFIED_DESC, (
"the mutant did not re-enter the post-POST check, so the state update is not what keeps it "
f"out and the assertion above proves nothing about it: {mseq}"
)
def test_a_FAILED_post_POST_replacement_FAILS_the_job(tmp_path):
"""The post-POST replacement is the write that takes back a green already published."""
posted, r = _run_classify(
tmp_path / "fixed",
_emitting("docs/a.md"),
timeline_mode="moves:0,0,1",
post_fails="after-first",
)
assert r.returncode != 0, f"a stale exemption was left standing and the job reported clean:\n{r.stdout[-900:]}"
assert "COULD NOT REPLACE" in (r.stdout + r.stderr), (
f"the job went red, but not because the replacement failed:\n{r.stdout[-900:]}"
)
_, rm = _run_classify(
tmp_path / "mutant",
_emitting("docs/a.md"),
timeline_mode="moves:0,0,1",
post_fails="after-first",
mutate=(' if ! repair_status_to "$UNVERIFIED_DESC"; then', " if false; then"),
)
assert rm.returncode == 0, (
"the mutant still failed the job, so the replacement's result is not what reddens it: "
f"rc={rm.returncode}\n{rm.stdout[-900:]}"
)
def test_MUTATION_a_post_POST_replacement_that_leaves_state_at_success_stops_asking_for_a_verdict(
tmp_path,
):
"""`state=pending` after the replacement is what makes the job ask for a verdict.
The closing notice — the line that names the command a reviewer runs — is keyed on `$state`. Left
at `success`, the head is pending and nothing on screen says so.
"""
posted, r = _run_classify(tmp_path / "fixed", _emitting("docs/a.md"), timeline_mode="moves:0,0,1")
assert "needs an H10 review verdict" in (r.stdout + r.stderr), (
f"the head was replaced with the sentinel but the run never asked for a verdict:\n{r.stdout[-900:]}"
)
_, rm = _run_classify(
tmp_path / "mutant",
_emitting("docs/a.md"),
timeline_mode="moves:0,0,1",
mutate=(
' echo "Replaced ${CONTEXT} with the unverified-write sentinel on ${SHA:0:7}."\n state=pending',
' echo "Replaced ${CONTEXT} with the unverified-write sentinel on ${SHA:0:7}."',
),
)
assert "needs an H10 review verdict" not in (rm.stdout + rm.stderr), (
"the mutant still asked for a verdict, so the state update is not what produces the notice"
)
# --- Workflow token scope (ersatztv#748) -------------------------------------------------------
#
# Both assertions guard a property whose violation is SILENT and, for the first, unrecoverable.