fix(622): bind H10 merge consent to the reviewed sha via a required commit status
review-verdict/h10 Awaiting review verdict for 628ae46
Review verdict / Set review-verdict status (pull_request) Successful in 9s
PR Gates / CI image pin matches docker/ci (pull_request) Successful in 11s
PR Gates / Docs update reminder (pull_request) Successful in 15s
PR Gates / decisions lifecycle (pull_request) Successful in 26s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Failing after 1m28s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 9s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 7s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 16m59s
Build ErsatzTV Image / Functional E2E (curl + UI contracts) (pull_request) Successful in 19m5s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped

`pretooluse-merge-consent.sh` proves all three consent conditions at the moment
the merge tool is called. With `merge_when_checks_succeed=true`, condition (a) is
delegated to Gitea, which then merges whatever head is green at ITS merge time —
while (b) Done-when and (c) the head-referencing verdict were proven against the
head at SCHEDULING time. Every commit pushed in between merges unreviewed. The
gate is not bypassed; it is satisfied against a snapshot that stops being true.

Demonstrated as a controlled A/B rather than inferred, with a CI check left
pending so Gitea waits as it really does:

  without a required verdict context: unreviewed commit B MERGED
  with it:                            same sequence REFUSED
  after reviewing B and posting it:   merges — blocked, not deadlocked

NOTE the anecdote in #622 is wrong and is corrected in the docs rather than
repeated: PR #619 does carry `Review-verdict: MERGEABLE @ 02c82b35`, posted six
seconds before the merge, explicitly re-reviewing the follow-up commits. #622 was
filed off a lagging API read. The hole is real regardless, and structural —
nothing FORCED that re-review inside the window Gitea would have merged in. This
turns a property that held by diligence into one that holds by construction.

The fix is the sha, not a smarter check. A Gitea commit status belongs to exactly
one commit, so a status written for a parent cannot be inherited by a child that
did not exist yet. `review-verdict/h10` becomes a REQUIRED status check on main:
push a new head and the context is simply absent, which Gitea reads as
not-passing (verified against 1.25.4: missing AND pending both block, and
auto-merge re-checks the current head). It also covers merge paths the hook never
sees — Gitea UI, raw API, another agent's session.

- scripts/post-review-verdict.sh writes the comment and the status together so
  they cannot drift, and re-reads head after commenting: if a commit landed
  mid-flight it writes NO status and exits non-zero rather than retargeting the
  verdict at a commit nobody read.
- .gitea/workflows/review-verdict.yml auto-passes the two exempt classes that
  would otherwise deadlock — Renovate-authored (platformAutomerge) and docs-only
  — and marks everything else pending. Exemptions are void when the PR touches
  .claude/, .gitea/, .husky/, scripts/ or docker/ci/.
- The hook refuses to SCHEDULE an auto-merge unless that status is green on head,
  and no longer claims "CI green" on the mwcs path, where it never read CI.

Two silent false negatives in the exemption path, both found by verifying rather
than reasoning, both fixed at BOTH call sites (workflow and the hook's
pre-existing docs-only carve-out):

- The files endpoint caps at 50 rows and IGNORES a larger `limit` — PR #619 has
  194 changed files and `?limit=100` returns 50. A single page saw ZERO protected
  paths there where the full enumeration finds ten. Both now page to exhaustion
  and withhold the exemption if they cannot complete.
- A rename is ONE row whose `filename` is the destination, the source only in
  `previous_filename`. Verified live: `.gitea/workflows/renovate.yml` ->
  `docs/innocuous-note.md` presented as docs-only with no protected path visible.
  Both now read BOTH sides.

Limits are documented, not papered over: base changes leave the head sha (and so
the verdict) unchanged, and a PR editing the workflow is judged by its own edited
copy — so PROTECTED is a guardrail against accident, not a tamper-proof control.

fixes #622
This commit is contained in:
2026-07-25 21:51:02 +02:00
parent 8e84191a03
commit 628ae46f7f
9 changed files with 789 additions and 9 deletions
+59 -4
View File
@@ -620,10 +620,65 @@ grep of `docker-build.yml` still validates the five pin-bearing jobs
(`test`/`migrations`/`functional-e2e`/`api-docs`/`format`) that remain there. `api-docs` and
`format` stay in `docker-build.yml` because they carry the shared-image `container:` + pin and run
on the healthy `ubuntu-latest` lane (where they skipped correctly). None of the three moved jobs is
a **required** check — branch protection requires only `Build & test (.NET)` and `EF migration
integrity` — so relocating them (their status-context prefix changes from `Build ErsatzTV Image /
…` to `PR Gates / …`) does not affect merges. The file declares `defaults: run: shell: bash`
because `ci-image-pin` uses `mapfile`/`set -o pipefail`.
a **required** check — branch protection requires `Build & test (.NET)`, `EF migration integrity`
and `review-verdict/h10` (next section) — so relocating them (their status-context prefix changes
from `Build ErsatzTV Image / …` to `PR Gates / …`) does not affect merges. The file declares
`defaults: run: shell: bash` because `ci-image-pin` uses `mapfile`/`set -o pipefail`.
## Review-verdict gate (`review-verdict/h10`, required — `.gitea/workflows/review-verdict.yml`)
**A required status check named `review-verdict/h10`, written per-sha, is what actually stops an
unreviewed commit from merging** (ersatztv#622). It is not produced by a job's success/failure; it
is a commit status that `scripts/post-review-verdict.sh` POSTs onto one specific sha.
**The hole it closes.** `pretooluse-merge-consent.sh` proves its three consent conditions at the
moment the merge tool is called. Pass `merge_when_checks_succeed=true` and Gitea performs the merge
*later*, against whatever head is green then — while the Done-when and review-verdict checks were
proven against the head at **scheduling** time. Every commit pushed in between merges unreviewed.
This was demonstrated as a controlled A/B rather than inferred (`ci/fake` stands in for a slow CI
check so Gitea waits, as it really does): review head A → post its verdict → schedule auto-merge →
push an unreviewed commit B → CI greens on B. **Without** the required verdict context, B merged.
**With** it, the same sequence was refused, and merged only once B itself was reviewed.
Note the motivating anecdote in ersatztv#622 — "PR #619 merged 263 insertions with no verdict" —
is **wrong**: #619 does carry `Review-verdict: MERGEABLE @ 02c82b35`, posted six seconds before the
merge, explicitly re-reviewing the follow-up commits. It was filed from an API read that lagged.
The gap is real anyway, and structural: nothing *forced* that re-review inside the 45-minute window
where Gitea would have merged whatever went green. This turns diligence into construction.
**Why a commit status fixes it and a smarter hook cannot.** A status belongs to exactly one sha, so
a new commit *cannot inherit it*: the required context is simply absent on the new head, Gitea's
merge-requirement check reads that as not-passing, and the scheduled auto-merge refuses to fire.
The invariant self-invalidates — nothing has to notice the push. It also covers merge paths the
hook never sees (Gitea UI, raw API, another agent's session).
**Posting a verdict.** After reviewing a PR's *current* head:
```bash
ETV_GITEA_BASICAUTH=user:pass scripts/post-review-verdict.sh <pr> MERGEABLE [note...]
```
That posts both the `Review-verdict: … @ <sha>` comment (the human-readable artifact, and the
hook's condition (c)) and the `review-verdict/h10` status on the same sha. `BLOCKED` /
`NOT-MERGEABLE` post a `failure` status instead. The script re-reads the head after commenting: if
a commit landed mid-flight it writes **no** status and exits non-zero rather than retargeting your
verdict at a commit you never read.
**Exemptions** are handled by `review-verdict.yml` on every `pull_request` event, which posts the
status as `success` for **Renovate-authored** PRs (it uses `platformAutomerge: true`, so a required
verdict with no exemption would stall every dependency bump) and for **docs-only** PRs, and as
`pending` for everything else so the block has a visible reason. Both exemptions are **void when the
PR touches `.claude/`, `.gitea/`, `.husky/`, `scripts/` or `docker/ci/`** — a PR that can weaken the
gate must not be able to exempt itself from the gate. That includes Renovate's `docker/ci` base
bumps, which already need the manual publish-then-pin two-step anyway.
It lives in its **own workflow file** on purpose: `pr-checks.yml` sets `cancel-in-progress: true`,
and a cancelled run there would leave an exempt PR with no status and no further push to
re-trigger it. Its own job context (`Review verdict / Set review-verdict status`) is **not** the
required check — a workflow must not satisfy the gate merely by running successfully.
Full rationale: `docs/decisions/records/release/verdict-status-check.md`.
## CI toolchain image (`docker/ci/Dockerfile`, `.gitea/workflows/ci-image.yml`)
+1
View File
@@ -111,6 +111,7 @@ the link for rationale. Superseded/retired history lives in `archive/`. Regenera
| `release.prepush-clean-worktree-guard` | A fail-open pre-push hook blocks a push when any file in the branch's diff vs `origin/main` also has uncommitted working-tree or index changes, since a stale-index commit (e.g. `git reset --soft` + `git add` over an edited-but-unstaged fix) can silently push, CI-test, and get reviewed a different tree than the one on disk. Scope is precise to pushed-diff files; escape hatch `ETV_ALLOW_DIRTY_PUSH=1`. | 2026-07-17 | [link](records/release/prepush-clean-worktree-guard.md) |
| `release.promotion-floating-prod` | Prod tracks the floating `:prod` image reference; a tag build's immutable `:<version>` image is scanned first, then promotion happens via a separate manual `DeployStack`, with daily auto-update only as a fallback — tag with enough runway before 03:00 to avoid an unscanned promotion. | 2026-07-13 | [link](records/release/promotion-floating-prod.md) |
| `release.review-verdict-gate` | A PR may not merge until a `Review-verdict: <MERGEABLE\|APPROVED\|BLOCKED\|NOT-MERGEABLE> @ <head-sha>` comment references the PR's current head sha (short-sha prefix match, line-start marker only, negative wins over positive on the same head); folds into the H6 merge-consent hook as condition (c). | 2026-07-12 | [link](records/release/review-verdict-gate.md) |
| `release.verdict-status-check` | The H10 review verdict is written as a `review-verdict/h10` Gitea **commit status** on the exact reviewed sha by `scripts/post-review-verdict.sh`, and that context is a REQUIRED status check on `main`. Because a status belongs to one sha, a later commit cannot inherit it, so Gitea's own `merge_when_checks_succeed` refuses to merge a head no one reviewed. The PreToolUse hook additionally refuses to SCHEDULE an auto-merge unless that status is already green on head. A `pull_request` workflow auto-passes the two exempt classes (Renovate-authored, docs-only) unless the PR touches a protected path (`.claude/`, `.gitea/`, `.husky/`, `scripts/`, `docker/ci/`). This extends — does not supersede — `release.review-verdict-gate` (#303 H10), whose comment convention remains the human-readable artifact and the hook's condition (c). | 2026-07-25 | [link](records/release/verdict-status-check.md) |
| `rulebuilder.relative-date-macros` | The visual rule builder's `inLast`/`notInLast` date operators compile to/parse from the pre-existing `CustomMultiFieldQueryParser` macros `released_inthelast`/`released_notinthelast` and `added_inthelast`/`added_notinthelast`, value form `"<n> day\|week\|month\|year"`; there is no backend change. | 2026-07-23 | [link](records/rulebuilder/relative-date-macros.md) |
| `scan.collections-scan-status` | `GET /api/v1/media-sources/collections-scan-status` reports a family-global (not per-source), boolean-only active-scan set read from `IEntityLocker`; the SPA reconciles authoritatively against it (with a grace-tick helper) instead of a fixed client-side timeout. | 2026-07-12 | [link](records/scan/collections-scan-status.md) |
| `scan.getoraddfolder-db-lookup` | `ILibraryRepository.GetOrAddFolder` resolves the existing folder via a DB query on `(LibraryPathId, Path)`, not the caller's `LibraryPath.LibraryFolders` in-memory navigation, since that navigation is only eager-loaded on the local scan path and is null on remote (Jellyfin) callers. | 2026-07-20 | [link](records/scan/getoraddfolder-db-lookup.md) |
@@ -0,0 +1,115 @@
---
key: release.verdict-status-check
title: '2026-07-25 — H10 is enforced server-side as a per-sha required status check, not only by the PreToolUse hook (#622)'
status: active
since: '2026-07-25'
supersedes: none
superseded-by: none
rule: 'The H10 review verdict is written as a `review-verdict/h10` Gitea **commit status** on the exact reviewed sha by `scripts/post-review-verdict.sh`, and that context is a REQUIRED status check on `main`. Because a status belongs to one sha, a later commit cannot inherit it, so Gitea''s own `merge_when_checks_succeed` refuses to merge a head no one reviewed. The PreToolUse hook additionally refuses to SCHEDULE an auto-merge unless that status is already green on head. A `pull_request` workflow auto-passes the two exempt classes (Renovate-authored, docs-only) unless the PR touches a protected path (`.claude/`, `.gitea/`, `.husky/`, `scripts/`, `docker/ci/`). This extends — does not supersede — `release.review-verdict-gate` (#303 H10), whose comment convention remains the human-readable artifact and the hook''s condition (c).'
signals: 'merge_when_checks_succeed freezes consent, auto-merge merges an unreviewed head, verdict bound to sha, review-verdict/h10 required check, post-review-verdict.sh, Renovate platformAutomerge exemption · paths: `scripts/post-review-verdict.sh`, `.gitea/workflows/review-verdict.yml`, `.claude/hooks/pretooluse-merge-consent.sh` · issues: #622, #303 (H6/H10), #242, #619'
mechanics: '`scripts/tests/test_post_review_verdict.py` (incl. a TOCTOU head-moved case and cross-checks against the hook''s own condition-(c) regexes); branch protection `status_check_contexts` on `main`'
---
`pretooluse-merge-consent.sh` evaluates all three consent conditions **at the moment the merge tool is
called**. That is sound for an immediate merge and unsound for a scheduled one. When the call passes
`merge_when_checks_succeed=true`, condition (a) is deliberately delegated to Gitea — but Gitea then
merges whatever head is green at *its* merge time, while (b) Done-when and (c) the head-referencing
verdict were proven against the head that existed at **scheduling** time. Any commit pushed in between
merges with no verdict covering it. The gate is not bypassed; it is **satisfied against a snapshot that
stops being true**.
This is the same shape as the failure H10 was created to fix (#242, "re-review the fix commit, not just
the initial diff"), reintroduced through the scheduling path rather than through forgetfulness. It also
interacted badly with a convention we actively encouraged: append-only files hit the conflict treadmill,
and the documented remedy was "rebase, then schedule `merge_when_checks_succeed`" — steering exactly the
high-churn PRs, the ones most likely to grow follow-up commits, onto the one path where H10 stopped
applying.
**Correction on the motivating anecdote.** #622 was filed claiming PR #619 merged 263 insertions with no
covering verdict. That is **false**, and the record is corrected here rather than repeated: #619 carries a
*second* verdict comment, `Review-verdict: MERGEABLE @ 02c82b35`, posted at 20:36:02 — six seconds before
the 20:36:08 merge — which explicitly re-reviewed the two follow-up commits ("the verdict on record was
stale … so they got their own scoped review"). The original claim came from reading the comment list while
the Gitea API lagged. So the incident is evidence of the convention *working under diligence*, not of it
failing.
The hole is nevertheless real, and is structural rather than anecdotal: **nothing forced that re-review**.
It happened because a human chose to, inside a 45-minute window in which Gitea would have merged whatever
was green. That is exactly the distinction this record exists to close — turning a property that held by
diligence into one that holds by construction. The justification below therefore rests on a controlled
experiment, not on the anecdote (`ci/fake` stands in for a slow CI check, so Gitea waits, as it really
does):
| arm | required contexts | unreviewed commit pushed after scheduling |
| --- | --- | --- |
| without this change | `ci/fake` | **merged** |
| with this change | `ci/fake`, `review-verdict/h10` | **refused** |
| then review the new head and post its verdict | | merges — blocked, not deadlocked |
The negative-control arm is what makes this meaningful: the fix *changes the outcome*, rather than the
observation passing for an unrelated reason.
**The fix is the sha, not a smarter check.** A Gitea commit status is attached to exactly one commit, so
a status written for a parent cannot be inherited by a child that did not exist yet. Making
`review-verdict/h10` a required status check on `main` therefore makes the invariant self-invalidating
by construction: push a new head and the required context is simply absent, which Gitea's
merge-requirement check treats as not-passing, and the scheduled auto-merge refuses to fire until that
head is re-reviewed. No re-evaluation hook, no polling, no second snapshot to go stale. Three properties
follow that no hook-side fix could deliver:
- it covers **every** merge path — Gitea UI, raw API, auto-merge, another agent's session — not only
calls that happen to route through the Claude PreToolUse hook;
- it needs no event to re-fire, because absence-of-status *is* the block;
- it cannot be satisfied by a workflow merely running successfully, since the required context is the
status the workflow *posts*, never the workflow's own job status.
The comment convention of `release.review-verdict-gate` is unchanged and still load-bearing: it is what a
human reads, and it remains the hook's condition (c). `post-review-verdict.sh` writes both from one
command so they cannot drift, and re-reads the head after posting the comment — if a commit landed in
between it writes **no** status and exits non-zero rather than retargeting the verdict at a commit nobody
reviewed (#622 in miniature). Where the two ever disagree, the status wins, because it is the one a merge
is actually gated on.
**Exemptions, and why they are narrow.** A required check applies to every PR, including Renovate's,
which uses `platformAutomerge: true` — Gitea's own auto-merge — to land patch bumps unattended. So
`.gitea/workflows/review-verdict.yml` posts the status as `success` for Renovate-authored PRs and for
docs-only PRs, and `pending` for everything else (an explicit blocking reason beats a silently-missing
check). Both exemptions are void when the PR touches a **protected path** — `.claude/`, `.gitea/`,
`.husky/`, `scripts/`, `docker/ci/` — because a PR that weakens the merge gate must never be able to
exempt itself from the merge gate. This deliberately also means Renovate's `docker/ci/Dockerfile` base
bumps need a real verdict; those already require the manual publish-then-pin two-step
(`docs/ci-cd.md` → "CI toolchain image"), so unattended merge was never correct for them.
Two deliberate non-choices. The workflow lives in **its own file** rather than joining `pr-checks.yml`,
whose `cancel-in-progress: true` would let a superseding push cancel the run that grants an exemption,
stranding a Renovate PR with no status and no further push to re-trigger it. And the workflow's
docs-only pattern is **narrower** than the merge-consent hook's: the hook also lets `.claude/`/`.gitea/`/
`.husky/` through, which is safe there only because that path falls through to a human prompt, whereas
here it would post a green status with nobody in the loop.
Option (2) from #622 — "refuse to schedule when the branch can still move" — was rejected as close to a
no-op on its own, since it cannot stop a later push. It survives only as the hook-side precondition
described above, which is now meaningful precisely *because* the server-side status exists to check.
**Known limits, stated rather than papered over.** This raises the floor against *accident*, which is the
failure mode we actually have; it is not a control against a determined author of a PR, and should not be
described as one:
1. **A rename hides a path unless both sides are read.** Gitea reports a `git mv` as ONE row whose
`filename` is the destination, with the source only in `previous_filename` — so reading `filename`
alone lets a PR move a protected file into `docs/` and look docs-only. Verified live
(`.gitea/workflows/renovate.yml` → `docs/innocuous-note.md` showed no protected path). Both the
workflow and the hook now read **both** sides. Noting the near-miss: an initial check against #619
suggested Gitea exposed no rename data at all, which was a false negative — that PR simply contained
no renames. A constructed positive case settled it; an arbitrary sample did not.
2. **The file list must be paged.** The endpoint caps at 50 rows and silently ignores a larger `limit`
(PR #619: 194 changed files, `?limit=100` returns 50). A single-page read is a silent false negative —
on #619 it saw **zero** protected paths where the full enumeration finds ten. Both call sites now page
to exhaustion and withhold the exemption if they cannot.
3. **Changing a PR's base does not change its head sha**, so a verdict status keeps applying to a diff
that has materially changed. Not currently handled; low exposure here because base changes are rare
and manual.
4. **A PR that edits `review-verdict.yml` itself is judged by its own edited copy** if Gitea runs
`pull_request` workflows from the PR head. The `PROTECTED` list is therefore a guardrail against
accidental self-exemption, **not** a tamper-proof control. Acceptable for a two-account repo
(`timothy`, `renovate`); it would not be for an untrusted-contributor repo.
+5
View File
@@ -296,6 +296,11 @@ HARD CONSTRAINTS:
- **Merge consent is DERIVED, not asked.** The H6/H10 gate auto-grants when the `## Done-when` boxes are
ticked, a fresh `Review-verdict` references the current head, and CI is green; confirm in conversation
only when the gate ASKS. Prior pre-approvals never carry over. → `release.merge-consent-autogrant`
- **Post every review verdict with `scripts/post-review-verdict.sh <pr> <VERDICT>`** — never hand-write the
comment. It also writes the `review-verdict/h10` commit status, which is the REQUIRED check that actually
gates the merge; a comment alone leaves it absent. Being sha-bound is the point: a commit pushed after an
auto-merge is scheduled clears it, so scheduled merges can no longer land unreviewed code.
→ `release.verdict-status-check`
- **After the push, fixes are follow-up commits** — never amend or force-push a pushed branch.
→ `process.pr-routine-sequence`