From 72cca9a28024e4ce2aef125d41e4756b5d66973f Mon Sep 17 00:00:00 2001 From: Timothy Date: Sun, 30 Aug 2026 04:31:54 +0200 Subject: [PATCH] =?UTF-8?q?fix(849):=20round=207=20=E2=80=94=20the=20arms?= =?UTF-8?q?=20judged=20the=20wrong=20snapshot,=20and=20two=20comments=20th?= =?UTF-8?q?at=20invited=20a=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Claude-Session: https://claude.ai/code/session_019T79beF1Ufid3dXju4yqkF --- .gitea/workflows/review-verdict.yml | 39 ++++++-- docs/ci-cd.md | 4 +- .../ci/verdict-unverified-write-sentinel.md | 2 +- scripts/tests/test_pr_changed_files.py | 91 ++++++++++++++++++- 4 files changed, 124 insertions(+), 12 deletions(-) diff --git a/.gitea/workflows/review-verdict.yml b/.gitea/workflows/review-verdict.yml index 36648c1ac..47b046bba 100644 --- a/.gitea/workflows/review-verdict.yml +++ b/.gitea/workflows/review-verdict.yml @@ -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 diff --git a/docs/ci-cd.md b/docs/ci-cd.md index c4c9d8d7b..3735e296a 100644 --- a/docs/ci-cd.md +++ b/docs/ci-cd.md @@ -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 diff --git a/docs/decisions/records/ci/verdict-unverified-write-sentinel.md b/docs/decisions/records/ci/verdict-unverified-write-sentinel.md index cadec28fc..b5fed479d 100644 --- a/docs/decisions/records/ci/verdict-unverified-write-sentinel.md +++ b/docs/decisions/records/ci/verdict-unverified-write-sentinel.md @@ -7,7 +7,7 @@ supersedes: none superseded-by: none rule: 'The `review-verdict/h10` job runs its post-write race check after EVERY status write, not only an exemption `success`, and where no mark exists to run it against, the write ITSELF becomes the sentinel — so every status this job writes is either verified against the history or marked as unverifiable: a GENERIC `pending` masks a rejection landing in its own write window exactly as a `success` does, and because it carries no marker a later run re-derives it into an exemption with the human row now below THAT run''s high-water mark — the damage arrives one event later, not never. Where a write cannot be checked at all the job writes a SECOND sentinel, `UNVERIFIED_DESC`, distinct from the repair sentinel and never interchangeable with it: the repair sentinel ASSERTS that a verdict existed and was buried, which only the arm that actually COUNTED such a row may claim, while every "could not check" arm — an unreadable or over-cap history, an impossible empty history, an unusable count — states only what it established. Both are STICKY (the classification refuses to grant an exemption over either, and re-writes its own description verbatim, so each is a FIXED POINT a later run cannot re-derive into `success`); only the unverified one is RECONCILABLE. Reconciliation is what bounds the stall that got the #742 attempt withdrawn: a later run pages `/statuses/{sha}` IN FULL and, ONLY IF that history contains the sentinel''s own row, either finds a `Review-verdict:` row underneath the sentinel — an established fact, so it UPGRADES to the repair sentinel, clearable only by a human — or finds none, resolving the uncertainty and clearing it so the PR is classified normally. The reconciliation is sound because the two endpoints differ: a verdict this job masked is invisible on the COMBINED endpoint (latest row per context, which is the sentinel) and still present in the per-POST history. It is deliberately BROADER than the inheritance test — no `H10_REVIEWERS` membership, no `(base: …)` match — because over-counting upgrades to a stall a human clears in one command while MISSING one re-exempts a head carrying a buried rejection. ONLY a COMPLETE walk CONTAINING THE CURRENT SENTINEL ROW — matched by the `id` the combined read reported, not merely by a row with the same description — may clear it. Description alone is satisfied by an OLDER identical sentinel, which is exactly what a fixed point produces: with an earlier sentinel and a buried verdict below the current one, a read carrying only the earlier row satisfies the test, the sentinel clears, and the verdict ends up below the fresh mark. Where the server omits `id` there is nothing to match on and the check degrades to the description, which is the pre-existing behaviour rather than a new hole. The witness is not optional decoration: `ex_unverified` means the combined endpoint just returned that row, and `/statuses/{sha}` keeps one row per POST, so a complete history WITHOUT it — an empty one included — contradicts a write that demonstrably happened. `page_statuses` accepts an empty page 1 as complete (correct for a first-run mark), which is what made that shape reachable, and clearing on it exempted a head whose sentinel may have been sitting on a rejection. This is NOT the withdrawn currency witness: that asked whether ANY row sat above the mark, which an unrelated row satisfied, and it made one anomaly permanent — this asks for a SPECIFIC row already known to exist. Failing it costs one run in the transient case; it is NOT bounded in general, because a history past the 20-page cap can never be walked completely, so such a head needs a human verdict and no later run will clear it. When NO high-water mark can be established the write is withheld BEFORE the POST rather than posted and repaired, since the defect is known in advance and publishing a green to take it back opens a window branch protection — and an already-scheduled auto-merge — can see. EVERY re-derivable state is downgraded there, not only `success`: an earlier draft restricted it to the exemption on the grounds that a sticky generic `pending` "withholds nothing, since an unreviewed PR is blocked already", which analysed the wrong PR — the damaging case is one that IS exemptible and got the generic `pending` only from a transient enumeration failure, whose unmarked description the next run re-derives into the exemption with the human row below its own mark. `$REPAIR_DESC` is the one exemption, being the stronger fact and not re-derivable. SEPARATELY, the retarget count is re-taken AFTER the POST on the exemption path, which closes the PERMANENT forged green `ci.verdict-write-retarget-fence` recorded as its residual: a retarget landing after the final pre-write count leaves a stale `success` with the `edited` event already consumed by a successor that short-circuited, so nothing remains to reclassify. Re-counting afterwards means a retarget later than the re-check necessarily queues a successor that STARTS after the stale `success` exists, and a machine-written `success` is re-derived rather than inherited. The RETARGET axis only: a push after the POST moves the head, so the status no longer gates that PR, while a retarget changes the effective diff with the sha unchanged. An untrusted post-POST count repairs too — reaching that point with `success` means both earlier counts were trusted, so a third unreadable read is a fresh failure and "I cannot tell whether the base moved" must not resolve to leaving a green. FINALLY, every path that cannot establish what the head carries REPLACES the unknown state instead of merely declining to write — the combined read (retried once first), all four page-2 completeness refusals, and the fence branch that cannot trust its retarget count while holding a derived `success`. That last one is reached only AFTER the classification declined to inherit the row the head carries, so posting nothing left the declined row current; its message used to say the context "stays absent", which is true only of a head that had none. The two OBSERVED-mutation arms take the same decision for the same reason, scoped to a head that actually carries a declined row: they still refuse to post their CLASSIFICATION, which was computed against a base or head the PR may no longer have, but a row this run declined must not stay authoritative for the whole window until a successor finishes — and for a PR''s FIRST push no successor is queued at all. Every element and every consumed field of the combined response is TYPE-CHECKED before extraction, and a schema failure routes to the same replacement rather than dying: `.statuses` being an array was checked and its ELEMENTS were not, so one scalar made `select(.context == $c)` hard-error and `set -e` took the step down before any path could mark the head. The path-predicate failure replaces too. And the write helper RETURNS a status: its first version ended the failure arm with a successful `echo`, so it reported 0 after both POSTs failed and the fence caller exited 0 as though the head had been marked. Declining protects a real verdict and leaves a FORGED one — an off-list `success` is the row #742 exists to revoke, revocation happens by re-deriving it, and an unreadable read is the one thing that stops it while the job goes red on a status branch protection does not read. Nothing is destroyed: the per-POST history keeps the masked verdict and the next run''s reconciliation upgrades to the repair sentinel, telling the reviewer to re-post rather than silently un-approving them. The page-2 refusals were briefly excluded on the reasoning that the probe fires when NO row for this context was on page 1, so there is no green of any provenance to leave standing — self-contradictory, since the ONLY reason page 2 is read is that the row MAY be beyond page 1. WRITING THE SENTINEL AND FAILING THE JOB ARE SEPARATE DECISIONS: the read refusals were already non-zero exits on `main` and stay red, while the fence branch exited 0 there and still does, because an unreadable timeline is an ordinary hiccup and reddening every one of them is noise this file elsewhere refuses to add. The repair also has a FLOOR — it may never write a description weaker than the one this run decided, or a transient post-write read rewrites a correct `$REPAIR_DESC` carry-forward with the machine-clearable sentinel — and it is skipped entirely when it would rewrite what is already there.' signals: 'exemption success standing over a human failure, generic pending re-derived into an exemption, unverified write sentinel, reconcilable sentinel vs repair sentinel, no high-water mark could be established, post-write verification runs for every write, retarget after the POST leaves a permanent forged green, unreadable combined status read leaves an off-list green, why did my docs-only PR lose its exemption, why does the gate say the write could not be verified · paths: `.gitea/workflows/review-verdict.yml`, `scripts/tests/test_pr_changed_files.py` · issues: #849, #742, #763, #706, #803' -mechanics: '`UNVERIFIED_DESC` ("Status write could not be verified — re-post the verdict") beside `REPAIR_DESC`; `read_existing_verdict()` sets `ex_unverified` from a prefix match, retries the combined read once and on persistent failure calls `repair_status_to "$UNVERIFIED_DESC"` before `exit 1`; the RECONCILE block runs `page_statuses` and counts `Review-verdict:` rows with a non-null creator, clearing `ex_unverified`, upgrading to `ex_repair`, or carrying the sentinel forward on `ph_ok != yes`; the classification chain is `exempt` → `ex_repair` → `ex_unverified` → generic, so the repair sentinel outranks the unverified one; the no-mark downgrade sits AFTER the mark (referencing `$max_id_before` earlier is an unbound variable under `set -u`); the mid-run guard adds `[ "$ex_desc" != "$pre_desc" ]`, which the repair guard does not need because a pre-existing repair sentinel forces its own description while a pre-existing unverified one is deliberately replaced after reconciliation; the post-write gate is `if [ "$max_id_before" -ge 0 ]`, with the no-mark case handled before the POST instead; `replace_unknown_state()` is the shared writer for every path that cannot establish the head''s state and `replace_unknown_and_die()` wraps it for the two read refusals that were already non-zero exits; the reconciliation witness is a count of rows carrying the `id` the combined read reported, falling back to a description match only where the server omits `id`; `pre_id`/`ex_id` extend the mid-run changed-row comparison to row IDENTITY through a shared `row_replaced` flag, since two sentinel POSTs are byte-identical by design — and an id difference counts only when BOTH reads supplied one, because a response that omits `id` beside one that includes it would otherwise report a replacement that did not happen and make the run abstain over a row it had already declined (the combined endpoint carries `id` — measured 2026-08-29 at 1.27.1, head 736649b3, 8 rows, ids 14..30); `--arg own "$desc"` excludes the job''s OWN row from both machine-sentinel selectors, which became necessary the moment the block started running for every write; `.description` is TYPE-TESTED before `startswith`, since `(.description // "")` does not replace a NUMBER and `startswith` then hard-errors, killing the whole count and losing a genuine verdict beside the malformed row; `repair_status_to()` is the shared retry-once writer for all three repair sites; tests `test_a_verdict_racing_a_PENDING_write_is_repaired_to_the_repair_sentinel`, `test_a_raced_PENDING_write_repairs_and_the_repair_SURVIVES_the_next_run`, `test_the_unverified_sentinel_is_a_FIXED_POINT_while_it_cannot_be_reconciled`, `test_the_unverified_sentinel_is_RECONCILED_AWAY_once_the_history_can_be_read`, `test_the_reconciliation_UPGRADES_to_the_repair_sentinel_when_a_verdict_is_BURIED`, `test_a_RETARGET_AFTER_the_POST_replaces_the_exemption`, `test_an_UNREADABLE_retarget_count_AFTER_the_POST_also_replaces_the_exemption`, `test_a_MALFORMED_description_row_does_not_kill_the_post_write_count`, `test_a_transport_failure_on_the_STATUS_READ_REPLACES_the_unknown_state`, each paired with a `test_MUTATION_…` proof that disarms the shipped clause it names through `_run_classify(mutate=…)`, whose count assertion is the binding. Some of those mutants restore text this branch or `origin/main` actually shipped — every clause that HAS a predecessor is mutated back to it — and the rest disarm clauses that have none, because the blocks they gate are new — the section header in that file enumerates which is which, because "restores the exact predecessor" is true of only some of them. SIX CLAUSES ARE DELIBERATELY UNPROVEN and are ENUMERATED rather than counted, because an inventory that undercounts is the same overclaim as one that invents coverage: the path-predicate failure branch (fires only when `grep -c` exits above 1); the empty-`row` refusal (`first // {}` always yields an object for any body that passed the shape gate); page 2''s non-numeric length (`(.statuses // []) | length` is numeric for every body that reaches it, and a non-JSON body is caught one branch earlier by `more_kind`); the `$witness` non-numeric normalisation (`select(((.id | numbers) // -1) == $wid)` cannot error, and a non-numeric `.id` takes the schema-fault route BEFORE the witness runs); the unusable-`buried`-count arm (same argument, plus its own description type test); and the unusable-`raced_unverified`-count arm, whose filter is type-safe for every row a fixture can pose. 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 carries. They were found by a mutation SWEEP over every clause the diff adds, which is the technique that finds this class; a per-finding review does not. Measured on this branch: 60 mutants, 40 red, 20 survivors, on a tree that had already been through three per-finding review rounds by two model families.' +mechanics: '`UNVERIFIED_DESC` ("Status write could not be verified — re-post the verdict") beside `REPAIR_DESC`; `read_existing_verdict()` sets `ex_unverified` from a prefix match, retries the combined read once and on persistent failure calls `repair_status_to "$UNVERIFIED_DESC"` before `exit 1`; the RECONCILE block runs `page_statuses` and counts `Review-verdict:` rows with a non-null creator, clearing `ex_unverified`, upgrading to `ex_repair`, or carrying the sentinel forward on `ph_ok != yes`; the classification chain is `exempt` → `ex_repair` → `ex_unverified` → generic, so the repair sentinel outranks the unverified one; the no-mark downgrade sits AFTER the mark (referencing `$max_id_before` earlier is an unbound variable under `set -u`); the mid-run guard is keyed on `$row_replaced`, which the repair guard does not need because a pre-existing repair sentinel forces its own description while a pre-existing unverified one is deliberately replaced after reconciliation; the post-write gate is `if [ "$max_id_before" -ge 0 ]`, with the no-mark case handled before the POST instead; `replace_unknown_state()` is the shared writer for every path that cannot establish the head''s state and `replace_unknown_and_die()` wraps it for the two read refusals that were already non-zero exits; the reconciliation witness is a count of rows carrying the `id` the combined read reported, falling back to a description match only where the server omits `id`; `pre_id`/`ex_id` extend the mid-run changed-row comparison to row IDENTITY through a shared `row_replaced` flag, since two sentinel POSTs are byte-identical by design — and an id difference counts only when BOTH reads supplied one, because a response that omits `id` beside one that includes it would otherwise report a replacement that did not happen and make the run abstain over a row it had already declined (the combined endpoint carries `id` — measured 2026-08-29 at 1.27.1, head 736649b3, 8 rows, ids 14..30); `--arg own "$desc"` excludes the job''s OWN row from both machine-sentinel selectors, which became necessary the moment the block started running for every write; `.description` is TYPE-TESTED before `startswith`, since `(.description // "")` does not replace a NUMBER and `startswith` then hard-errors, killing the whole count and losing a genuine verdict beside the malformed row; `repair_status_to()` is the shared retry-once writer for all three repair sites; tests `test_a_verdict_racing_a_PENDING_write_is_repaired_to_the_repair_sentinel`, `test_a_raced_PENDING_write_repairs_and_the_repair_SURVIVES_the_next_run`, `test_the_unverified_sentinel_is_a_FIXED_POINT_while_it_cannot_be_reconciled`, `test_the_unverified_sentinel_is_RECONCILED_AWAY_once_the_history_can_be_read`, `test_the_reconciliation_UPGRADES_to_the_repair_sentinel_when_a_verdict_is_BURIED`, `test_a_RETARGET_AFTER_the_POST_replaces_the_exemption`, `test_an_UNREADABLE_retarget_count_AFTER_the_POST_also_replaces_the_exemption`, `test_a_MALFORMED_description_row_does_not_kill_the_post_write_count`, `test_a_transport_failure_on_the_STATUS_READ_REPLACES_the_unknown_state`, each paired with a `test_MUTATION_…` proof that disarms the shipped clause it names through `_run_classify(mutate=…)`, whose count assertion is the binding. Some of those mutants restore text this branch or `origin/main` actually shipped — every clause that HAS a predecessor is mutated back to it — and the rest disarm clauses that have none, because the blocks they gate are new — the section header in that file enumerates which is which, because "restores the exact predecessor" is true of only some of them. SIX CLAUSES ARE DELIBERATELY UNPROVEN and are ENUMERATED rather than counted, because an inventory that undercounts is the same overclaim as one that invents coverage: the path-predicate failure branch (fires only when `grep -c` exits above 1); the empty-`row` refusal (`first // {}` always yields an object for any body that passed the shape gate); page 2''s non-numeric length (`(.statuses // []) | length` is numeric for every body that reaches it, and a non-JSON body is caught one branch earlier by `more_kind`); the `$witness` non-numeric normalisation — `select(((.id | numbers) // -1) == $wid)` cannot error and `$ph_rows` is a validated array, which is the operative reason; the schema-fault route is NOT (it governs the COMBINED endpoint''s row, while the `.id` inside that filter belongs to `/statuses/{sha}` rows, which nothing type-checks); the unusable-`buried`-count arm (same argument, plus its own description type test); and the unusable-`raced_unverified`-count arm, whose filter is type-safe for every row a fixture can pose. 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 carries. They were found by a mutation SWEEP over every clause the diff adds — disarm each, run the whole suite per mutant — which is the technique that finds this class; a per-finding review reads what the diff says it does, and a sweep measures what the tests pin. The sweep''s surviving MUTANTS outnumber the clauses, since several clauses admit more than one disarming edit; the six here are the distinct clauses those survivors collapse onto. Provenance and the run-by-run numbers are in ersatztv#849.' --- `ci.verdict-write-retarget-fence` fenced the write and verified it afterwards. Five routes survived diff --git a/scripts/tests/test_pr_changed_files.py b/scripts/tests/test_pr_changed_files.py index 40a54eefd..4a561a686 100644 --- a/scripts/tests/test_pr_changed_files.py +++ b/scripts/tests/test_pr_changed_files.py @@ -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.