fix(849): round 7 — the arms judged the wrong snapshot, and two comments that invited a bug

A fourth cold review of the tip. No Blockers, no High: it enumerated every POST site and
every exit and could not construct an input where this branch writes a `success` that
`origin/main` would not.

## The arms judged the wrong snapshot

`mark_declined_row_if_any`'s three refusals all read `$pre_*` — the FIRST read — while the
POST replaces whatever row is CURRENT. So a reviewer's verdict arriving between the two
reads slipped past every refusal written to protect it: the base mismatch clears
`ex_attributable` so the mid-run abstain declines, `pre_creator` is empty so the allow-list
loop declines, and the arm marks a row nobody evaluated. Executed trace, control and case.
Both snapshots are consulted now, and either one vetoes.

Recovery was not free, which is why it mattered: the next run's reconciliation counts that
`Review-verdict:` row as buried and upgrades to the human-only sentinel — exactly the cost
the refusal exists to avoid.

The arm also marked this job's OWN ordinary machine `pending`. Every PR past its first run
carries one, so "kept off the commonest path in this job" was true only of a head with no
status at all. Scoped on the DESCRIPTION rather than on `creator: null`, which would also
exclude a machine `success` from another workflow — the row this marking exists for.

## Two comments that invited a bug

- One still described the round-4 REGRESSION as the intended behaviour ("a malformed row
  reads as no creator, hence re-derived"), two lines below the block recording that it was
  fixed. Adjacent comments giving contradictory accounts of one line, and the stale one
  licenses reinstating it.
- The fault token's justification said "no Gitea status field contains a NUL". The token is
  SOH (0x01). That is not pedantry: `$'\000…'` is the EMPTY STRING in bash, so an editor
  correcting the code to match the comment would make every legitimately-absent field
  compare equal to the token and send every clean head down the fail-closed route — the gate
  would stall every PR.

## Docs

The record quoted a predicate that no longer exists (`[ "$ex_desc" != "$pre_desc" ]`, now
`$row_replaced`); `docs/ci-cd.md` stated the reconciliation witness unconditionally when the
code degrades to a description match where the server omits `id`; one of the six unproven
clauses carried a wrong `because` (the conclusion holds via `(.id | numbers) // -1` over a
validated array, not via the schema-fault route, which governs a different endpoint's row);
and the record's own counts read as a contradiction cold — 20 surviving MUTANTS collapse
onto 6 distinct CLAUSES, several clauses admitting more than one disarming edit. The
run-by-run provenance moved to the issue, where `docs.no-session-narrative` says it belongs.

Two existing mutation proofs lost their binding to the reworded clauses and failed loudly
rather than measuring the unmutated body, which is what that count assertion is for. Rebound.

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 6fdf48de2d
commit 72cca9a280
4 changed files with 124 additions and 12 deletions
+31 -8
View File
@@ -700,14 +700,20 @@ jobs:
# the `{}` no-verdict row), and a type the schema does not allow, which is unknown state
# and takes the same route an unreadable ELEMENT already takes two lines up.
#
# The token cannot collide with a real value: no Gitea status field contains a NUL.
# SOH (0x01), and the byte matters: `$'\000…'` is the EMPTY STRING in bash, so
# "correcting" this to NUL would make every legitimately-absent field compare equal to the
# token and send every clean head down the fail-closed route — the gate would stall every
# PR. A control character is what makes collision impossible; NUL is the one that cannot
# be used.
SCHEMA_FAULT=$'\001schema-fault'
ex_id=$(printf '%s' "$row" | jq -r --arg f "$SCHEMA_FAULT" 'if (.id | type) == "number" then (.id | tostring) elif (.id | type) == "null" then "" else $f end')
ex_state=$(printf '%s' "$row" | jq -r --arg f "$SCHEMA_FAULT" 'if (.status | type) == "string" then .status elif (.status | type) == "null" then "" else $f end')
# `.creator.login` HARD-ERRORS on any non-object creator — the same defect #763 fixed in
# the post-write filter, still live on this read. `(.creator | type)` short-circuits it,
# so a malformed row reads as "no creator" (unattributable, hence re-derived) instead of
# killing the step after a `success` is already standing.
# so the step is not killed; the wrong TYPE then takes the fault route above rather than
# reading as "no creator", which is what made it re-derivable. (An earlier version of
# this comment described that re-derivation as the intended behaviour — it was the
# regression the block above records.)
ex_creator=$(printf '%s' "$row" | jq -r --arg f "$SCHEMA_FAULT" 'if (.creator | type) == "object" then (.creator.login // "") elif (.creator | type) == "null" then "" else $f end')
ex_desc=$(printf '%s' "$row" | jq -r --arg f "$SCHEMA_FAULT" 'if (.description | type) == "string" then .description elif (.description | type) == "null" then "" else $f end')
for _f in "$ex_id" "$ex_state" "$ex_creator" "$ex_desc"; do
@@ -1741,7 +1747,7 @@ jobs:
# THE SAME RULE FOR THE UNVERIFIED SENTINEL (ersatztv#849), with one clause the repair
# guard above does not need.
#
# `[ "$ex_desc" != "$pre_desc" ]` IS LOAD-BEARING, and leaving it out deadlocks the PR. The
# `$row_replaced` IS LOAD-BEARING HERE, and leaving it out deadlocks the PR. The
# repair guard gets its "arrived DURING this run" test for free: a repair sentinel present
# at the FIRST read forces `desc="$REPAIR_DESC"`, so the guard cannot fire on a
# pre-existing one. That is NOT true here — the reconciliation above deliberately CLEARS a
@@ -1799,12 +1805,29 @@ jobs:
# nothing, and a write there would be noise on the commonest path in this job.
mark_declined_row_if_any() { # $1 = the ::notice:: this arm already emitted
local rv
if [ -z "$pre_state" ]; then return 0; fi
# DECIDED ON THE ROW THIS POST ACTUALLY REPLACES, which is the one the LAST read saw.
# The refusals below read `$pre_*` — the FIRST read — and the write replaces `$ex_*`, so a
# reviewer's verdict arriving between the two reads was buried by the very refusal
# written to protect it: `ex_attributable` is cleared by a base mismatch so the mid-run
# abstain declines, `pre_creator` is empty so the allow-list loop declines, and the mark
# fires on a row nobody evaluated. Both snapshots are consulted, and either one vetoes.
if [ -z "$pre_state" ] && [ -z "$ex_state" ]; then return 0; fi
# THIS JOB'S OWN ORDINARY OUTPUT IS NOT WORTH MARKING. Every PR past its first run carries
# a machine `pending` with the generic description, so "kept off the commonest path in this
# job" was true only of a head with NO status at all. Replacing it costs a paged history
# walk and a spurious `::error::` on an entirely ordinary event, and withholds nothing —
# a generic `pending` blocks the merge already. Scoped to the description rather than to
# `creator: null`, which would also exclude a machine `success` from another workflow —
# exactly the row this marking exists for.
case "$ex_desc" in
"Awaiting review verdict"*) if [ "$ex_state" = pending ]; then return 0; fi ;;
esac
# NEVER WEAKEN THE REPAIR SENTINEL. `replace_unknown_state` writes the machine-clearable
# one, and a head carrying `$REPAIR_DESC` has a non-empty `pre_state`, so the bare scope
# test fired on it — inverting the ordering this same change added a floor to protect at
# the repair site. One mechanism, three writers, and only two had the rule.
if [ "$desc" = "$REPAIR_DESC" ] || [ "$pre_desc" = "$REPAIR_DESC" ]; then return 0; fi
if [ "$desc" = "$REPAIR_DESC" ] || [ "$pre_desc" = "$REPAIR_DESC" ] \
|| [ "$ex_desc" = "$REPAIR_DESC" ]; then return 0; fi
# NEVER BURY A ROW AN ALLOW-LISTED REVIEWER WROTE. "Declined" is decided against THIS
# event's `$BASE_REF`, so a genuine verdict recorded for another base is declined here and
# is still the right answer for the base it names — the successor run for that base
@@ -1814,9 +1837,9 @@ jobs:
# wrote the row, not whether it governs this diff. An off-list row is exactly what this
# marking exists for, and is left to it.
for rv in $H10_REVIEWERS; do
if [ "$rv" = "$pre_creator" ]; then return 0; fi
if [ "$rv" = "$pre_creator" ] || [ "$rv" = "$ex_creator" ]; then return 0; fi
done
replace_unknown_state "$1 This head already carried a ${CONTEXT} that this run did not inherit, so leaving it alone would keep it authoritative until a successor finishes — and for a PR's FIRST push no successor is queued at all." || return 1
replace_unknown_state "$1 This head carries a ${CONTEXT} that this run did not inherit, so leaving it alone would keep it authoritative until a successor finishes — and for a PR's FIRST push no successor is queued at all." || return 1
return 0
}
count_pr_mutations
+3 -1
View File
@@ -1786,7 +1786,9 @@ failing the job are separate decisions: the read refusals were already non-zero
the fence branch exited 0 and still does.
**Reconciliation needs a witness.** It may clear the sentinel only over a complete history that
CONTAINS the sentinel's own row. `ex_unverified` means the combined endpoint just returned that row
CONTAINS the sentinel's own row, matched by the `id` the combined read reported — degrading to a
DESCRIPTION match, which identifies a row with the same text rather than that row, only where the
server omits `id`. `ex_unverified` means the combined endpoint just returned that row
and `/statuses/{sha}` keeps one row per POST, so a complete-but-empty history contradicts a write
that demonstrably happened — and `page_statuses` accepts an empty page 1 as complete, which is what
made the shape reachable. The cost lands where the replacement actually cost something: on an
File diff suppressed because one or more lines are too long
+89 -2
View File
@@ -5870,7 +5870,10 @@ def test_MUTATION_not_marking_the_declined_row_leaves_it_authoritative(tmp_path)
status_mode="existing:success",
status_creator="mallory",
timeline_mode="moves:0,1",
mutate=('if [ -z "$pre_state" ]; then return 0; fi', "return 0"),
mutate=(
'if [ -z "$pre_state" ] && [ -z "$ex_state" ]; then return 0; fi',
"return 0",
),
)
seq = _posted_sequence(tmp_path / "mutant")
assert seq == [], (
@@ -6232,7 +6235,8 @@ def test_MUTATION_a_bare_scope_test_on_the_arms_buries_both(tmp_path):
status_desc=REPAIR_DESC,
timeline_mode="moves:0,1",
mutate=(
'if [ "$desc" = "$REPAIR_DESC" ] || [ "$pre_desc" = "$REPAIR_DESC" ]; then return 0; fi',
'if [ "$desc" = "$REPAIR_DESC" ] || [ "$pre_desc" = "$REPAIR_DESC" ] \\\n'
' || [ "$ex_desc" = "$REPAIR_DESC" ]; then return 0; fi',
":",
),
)
@@ -6691,6 +6695,89 @@ def test_MUTATION_a_post_POST_replacement_that_leaves_state_at_success_stops_ask
)
def test_a_reviewers_verdict_ARRIVING_MID_RUN_is_not_buried_by_an_abstaining_arm(tmp_path):
"""The refusals must judge the row the POST replaces, not the one the run started with.
All three read `$pre_*`, the FIRST read, while the write replaces whatever is current — so a
reviewer's verdict arriving BETWEEN the two reads slipped past every one of them: the base
mismatch clears `ex_attributable` so the mid-run abstain declines, `pre_creator` is empty so the
allow-list loop declines, and the arm marks a row nobody evaluated. The static case was covered;
this is the one that moves.
Recovery is not free either: the next run's reconciliation counts that `Review-verdict:` row as
buried and upgrades to the human-only sentinel — exactly the cost the refusal exists to avoid.
"""
posted, r = _run_classify(
tmp_path,
_emitting("docs/a.md"),
status_mode="appears-on-read:2",
midrun_row="timothy|failure|Review-verdict: BLOCKED @ a9e3e23 (base: probe/scratch)",
push_mode="moves:0,1",
)
assert posted is None, (
f"a reviewer's verdict that landed mid-run was buried by an abstaining arm: {posted}\n{r.stdout[-900:]}"
)
def test_MUTATION_deciding_the_arms_refusals_on_the_FIRST_read_buries_it(tmp_path):
"""Restores the round-4 form: the allow-list veto reading only the opening snapshot."""
posted, rm = _run_classify(
tmp_path / "mutant",
_emitting("docs/a.md"),
status_mode="appears-on-read:2",
midrun_row="timothy|failure|Review-verdict: BLOCKED @ a9e3e23 (base: probe/scratch)",
push_mode="moves:0,1",
mutate=(
'if [ "$rv" = "$pre_creator" ] || [ "$rv" = "$ex_creator" ]; then return 0; fi',
'if [ "$rv" = "$pre_creator" ]; then return 0; fi',
),
)
assert posted is not None and posted["description"] == UNVERIFIED_DESC, (
"the mutant did not bury it, so consulting the CURRENT read is not what protects it and the "
f"test above proves nothing about it: {posted}\n{rm.stdout[-900:]}"
)
def test_an_ORDINARY_machine_pending_is_not_worth_marking(tmp_path):
"""Every PR past its first run carries one, so this is the commonest head there is.
Replacing it costs a paged history walk and a spurious `::error::` on an entirely ordinary event,
and withholds nothing — a generic `pending` blocks the merge already. The scoping comment claimed
the write was kept off the common path, which was true only of a head with NO status at all.
"""
posted, r = _run_classify(
tmp_path,
_emitting("docs/a.md"),
status_mode="existing:pending",
status_creator=None,
status_desc="Awaiting review verdict for a9e3e23",
push_mode="moves:0,1",
)
assert posted is None, (
f"this job's own ordinary output was replaced with the sticky sentinel: {posted}\n{r.stdout[-900:]}"
)
def test_positive_control_a_machine_SUCCESS_is_still_marked(tmp_path):
"""The scoping is on the DESCRIPTION, not on `creator: null`.
Excluding every machine-written row would exclude a `success` posted by another workflow — which
is precisely the row this marking exists for, and the reason the exclusion is not written the
obvious way.
"""
posted, r = _run_classify(
tmp_path,
_emitting("docs/a.md"),
status_mode="existing:success",
status_creator=None,
status_desc="Exempt: docs-only change (no code, no protected path)",
push_mode="moves:0,1",
)
assert posted is not None and posted["description"] == UNVERIFIED_DESC, (
f"a machine `success` was left authoritative while the arm abstained: {posted}\n{r.stdout[-900:]}"
)
# --- Workflow token scope (ersatztv#748) -------------------------------------------------------
#
# Both assertions guard a property whose violation is SILENT and, for the first, unrecoverable.