Skip to content

feat(bin): accept repeated --allow-red waivers and record what they waived - #5232

Open
ivannovak wants to merge 3 commits into
kunchenguid:mainfrom
ivannovak:fm/firstmate-pr-merge-multi-waiver
Open

ivannovak wants to merge 3 commits into
kunchenguid:mainfrom
ivannovak:fm/firstmate-pr-merge-multi-waiver

Conversation

@ivannovak

Copy link
Copy Markdown

Intent

Allow the guarded merge path to express multiple explicitly named waived checks so an authorized multi-check merge remains recorded and guarded.

What Changed

  • bin/fm-pr-merge.sh drops the "only once" guard on --allow-red, so the flag can be repeated to name several explicitly authorized red checks in one merge; each name still waives only checks matching it exactly, every unnamed red check still refuses by name, and the waiver is still refused while the away-posture record exists.
  • A waived merge is no longer reported or recorded as a fully green one: github_verify_mergeable collects the red checks a waiver actually covered and names them in its verification line instead of claiming every required check green, and a new record_waived_red_checks persists one merge_waived_check=<name> line per covered check into the task meta under the merge-metadata lock already held by persist_accepted_merge_authority — replacing any lines from an earlier merge and clearing them when nothing was waived — with the persist failure message distinguishing which of the two records failed.
  • fm_pr_metadata_identity_parse in bin/fm-pr-lib.sh admits the new non-empty merge_waived_check= key after pr=; AGENTS.md and docs/architecture.md restate the waiver contract as repeatable-and-recorded, and tests/fm-pr-merge.test.sh replaces the duplicate-waiver refusal case with coverage for a multi-waiver merge, an unlisted red check beside named waivers, and a waiver that covered nothing (which must leave the green claim intact and clear a stale recorded name).

Risk Assessment

✅ Low: The follow-up closes the round-1 gap durably and verifiably - the waiver set is written before the merge-authority record and a recording failure skips that record entirely, so no path can leave an authority record asserting an unqualified green merge - the 0600 precondition is guaranteed by the same run's record_pr_metadata, the fm-pr-lib.sh allowlist change keeps every existing meta consumer and the armed poll valid, no other meta writer drops the new key, and the recorded check name is inert against every anchored meta read; the only open item is a documented semantic choice to record the used rather than the authorized waiver set.

Testing

I exercised the multi-waiver merge path end-to-end against the real fm-pr-merge.sh and captured an operator-visible CLI transcript: two separately named waivers merge a PR whose lint and unit checks are red, the verification line names both waived checks rather than claiming every check green, and both land in the task meta as merge_waived_check= lines beside the merge-authority record; an unnamed red security check still refuses with no forge call, the away-posture record still refuses the multi-waiver form, and a waiver that covered nothing records nothing while clearing a stale record. The full tests/fm-pr-merge.test.sh suite passes, and a negative control against the base implementation shows the three new tests going red there, so they genuinely test the change. The sibling suite covering the changed metadata parser passes in full when run alone; two earlier runs of it each failed at a different watcher-bounded test with empty stderr, which I traced to that suite's 10-second watcher alarm under machine load — those tests pass repeatedly in isolation here and the suite is green on the base tree, so it is pre-existing load sensitivity, not a regression from this change. The change is UI-free (a shell CLI), so the CLI transcript and persisted meta file are the end-user-visible artifacts; no screenshot applies.

Evidence: CLI transcript: multi-waiver merge, unlisted red check, unused waiver, away refusal

================================================================
SCENARIO 1 - captain waived two named red checks: lint and unit
================================================================

live GitHub check rollup at head:
    lint: FAILURE
    unit: FAILURE
    build: SUCCESS

$ fm-pr-merge.sh task-x1 https://github.com/example/repo/pull/88 --allow-red lint --allow-red unit

    ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    ●  WATCHER DOWN - SUPERVISION IS OFF
    ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
    ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
    ●  This is a supervision warning only; the guarded operation WILL still run.
    ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
    ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    verified: https://github.com/example/repo/pull/88 is open and mergeable at head c0ffeec0ffeec0ffeec0ffeec0ffeec0ffeec0ff, with every other required check green and these red checks explicitly waived: 'lint', 'unit'
    armed: state/task-x1.check.sh
    verified: https://github.com/example/repo/pull/88 is merged (state=MERGED, merged=true, isInMergeQueue=false)

    exit status: 0

--- forge command actually issued (gh.log) ---
    gh pr merge 88 --repo example/repo --match-head-commit c0ffeec0ffeec0ffeec0ffeec0ffeec0ffeec0ff --squash

--- task meta on disk (state/task-x1.meta) ---
    window=fm-task-x1
    worktree=/private/var/folders/pq/43bb80gj31x7009tmpvfjcy40000gn/T/fm-pr-merge-tests.f0NfIT/evidence-multi-waiver/wt
    project=/private/var/folders/pq/43bb80gj31x7009tmpvfjcy40000gn/T/fm-pr-merge-tests.f0NfIT/evidence-multi-waiver/project
    kind=ship
    mode=no-mistakes
    pr=https://github.com/example/repo/pull/88
    pr_head=c0ffeec0ffeec0ffeec0ffeec0ffeec0ffeec0ff
    merge_waived_check=lint
    merge_waived_check=unit

================================================================
SCENARIO 2 - same two waivers, but a third red check 'security' was never named
================================================================

live GitHub check rollup at head:
    lint: FAILURE
    unit: FAILURE
    security: FAILURE

$ fm-pr-merge.sh task-x1 https://github.com/example/repo/pull/89 --allow-red lint --allow-red unit

    ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    ●  WATCHER DOWN - SUPERVISION IS OFF
    ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
    ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
    ●  This is a supervision warning only; the guarded operation WILL still run.
    ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
    ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    error: refusing to merge https://github.com/example/repo/pull/89
      - check 'security' is not green
    error: these checks are not green: security

    exit status: 1

--- forge commands issued (gh.log) ---
    (none - no merge was submitted)

--- waiver records in task meta ---
    (none - nothing merged, nothing recorded)

================================================================
SCENARIO 3 - a waiver that covered no red check, over a stale earlier record
================================================================

task meta carries a waiver from an earlier merge:
    merge_waived_check=stale-from-an-earlier-merge

live GitHub check rollup at head:
    build: SUCCESS

$ fm-pr-merge.sh task-x1 https://github.com/example/repo/pull/90 --allow-red lint

    ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    ●  WATCHER DOWN - SUPERVISION IS OFF
    ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
    ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
    ●  This is a supervision warning only; the guarded operation WILL still run.
    ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
    ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    verified: https://github.com/example/repo/pull/90 is open and mergeable, with every required check green at head e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1
    armed: state/task-x1.check.sh
    verified: https://github.com/example/repo/pull/90 is merged (state=MERGED, merged=true, isInMergeQueue=false)

    exit status: 0

--- forge command actually issued (gh.log) ---
    gh pr merge 90 --repo example/repo --match-head-commit e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1 --squash

--- merge authority record written ---
    state/task-x1.merge-authority exists

--- waiver records in task meta after the merge ---
    (none - the unused waiver recorded nothing and the stale record was cleared)

--- task meta on disk (state/task-x1.meta) ---
    window=fm-task-x1
    worktree=/private/var/folders/pq/43bb80gj31x7009tmpvfjcy40000gn/T/fm-pr-merge-tests.f0NfIT/evidence-unused-waiver/wt
    project=/private/var/folders/pq/43bb80gj31x7009tmpvfjcy40000gn/T/fm-pr-merge-tests.f0NfIT/evidence-unused-waiver/project
    kind=ship
    mode=no-mistakes
    pr=https://github.com/example/repo/pull/90
    pr_head=e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1

================================================================
SCENARIO 4 - two named waivers while the away-posture record exists
================================================================

the captain is away (state/.afk-contract present)

$ fm-pr-merge.sh task-x1 https://github.com/example/repo/pull/91 --allow-red lint --allow-red unit

    error: --allow-red is attended-only; while the away-posture record exists the green check is absolute

    exit status: 2

--- forge commands issued (gh.log) ---
    (none - no merge was submitted)

================================================================
DONE
================================================================
Evidence: Persisted task meta after an authorized two-check red merge

window=fm-task-x1 kind=ship mode=no-mistakes pr=https://github.com/example/repo/pull/88&#10;pr_head=c0ffeec0ffeec0ffeec0ffeec0ffeec0ffeec0ff&#10;merge_waived_check=lint&#10;merge_waived_check=unit

window=fm-task-x1
worktree=/private/var/folders/pq/43bb80gj31x7009tmpvfjcy40000gn/T/fm-pr-merge-tests.f0NfIT/evidence-multi-waiver/wt
project=/private/var/folders/pq/43bb80gj31x7009tmpvfjcy40000gn/T/fm-pr-merge-tests.f0NfIT/evidence-multi-waiver/project
kind=ship
mode=no-mistakes
pr=https://github.com/example/repo/pull/88
pr_head=c0ffeec0ffeec0ffeec0ffeec0ffeec0ffeec0ff
merge_waived_check=lint
merge_waived_check=unit
Evidence: Key transcript excerpt: two named waivers merge, a third unnamed red check refuses
$ fm-pr-merge.sh task-x1 https://github.com/example/repo/pull/88 --allow-red lint --allow-red unit
rollup at head: lint: FAILURE, unit: FAILURE, build: SUCCESS
verified: https://github.com/example/repo/pull/88 is open and mergeable at head c0ffee..., with every other required check green and these red checks explicitly waived: 'lint', 'unit'
verified: https://github.com/example/repo/pull/88 is merged (state=MERGED, merged=true, isInMergeQueue=false)
exit status: 0
gh pr merge 88 --repo example/repo --match-head-commit c0ffeec0ffeec0ffeec0ffeec0ffeec0ffeec0ff --squash
meta: merge_waived_check=lint / merge_waived_check=unit

$ fm-pr-merge.sh task-x1 https://github.com/example/repo/pull/89 --allow-red lint --allow-red unit
rollup at head: lint: FAILURE, unit: FAILURE, security: FAILURE
error: refusing to merge https://github.com/example/repo/pull/89
- check 'security' is not green
error: these checks are not green: security
exit status: 1
forge commands issued: (none - no merge was submitted)

$ fm-pr-merge.sh task-x1 https://github.com/example/repo/pull/91 --allow-red lint --allow-red unit # captain away
error: --allow-red is attended-only; while the away-posture record exists the green check is absolute
exit status: 2
Evidence: Negative control: the new tests against the base implementation (8c1cdb7)

not ok - github-allow-red-multiple: named waivers should merge error: --allow-red may be specified only once CONTROL: test_allow_red_accepts_multiple_separately_named_checks FAILED against the base implementation not ok - github-allow-red-unlisted: an unlisted red check must refuse: expected exit 1, got 2 CONTROL: test_allow_red_refuses_an_unlisted_red_check FAILED against the base implementation not ok - github-allow-red-unused: an unused waiver was recorded (meta still held merge_waived_check=stale) CONTROL: test_a_waived_merge_records_only_the_checks_it_waived FAILED against the base implementation

Negative control: the NEW tests/fm-pr-merge.test.sh run against the BASE implementation (8c1cdb7) of bin/fm-pr-merge.sh + bin/fm-pr-lib.sh.
Purpose: prove the new assertions are not inert - they must go red without the change.

not ok - github-allow-red-multiple: named waivers should merge
error: --allow-red may be specified only once
CONTROL: test_allow_red_accepts_multiple_separately_named_checks FAILED against the base implementation (exit 1)
not ok - github-allow-red-unlisted: an unlisted red check must refuse: expected exit 1, got 2
CONTROL: test_allow_red_refuses_an_unlisted_red_check FAILED against the base implementation (exit 1)
not ok - github-allow-red-unused: an unused waiver was recorded
window=fm-task-x1
worktree=/private/var/folders/pq/43bb80gj31x7009tmpvfjcy40000gn/T/fm-pr-merge-tests.Oz95MB/github-allow-red-unused/wt
project=/private/var/folders/pq/43bb80gj31x7009tmpvfjcy40000gn/T/fm-pr-merge-tests.Oz95MB/github-allow-red-unused/project
kind=ship
mode=no-mistakes
merge_waived_check=stale
pr=https://github.com/example/repo/pull/90
pr_head=b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2
CONTROL: test_a_waived_merge_records_only_the_checks_it_waived FAILED against the base implementation (exit 1)
ok - fm-pr-merge requires each red-check waiver as a separate named argument
CONTROL: test_allow_red_requires_a_separate_name PASSED against the base implementation
Evidence: fm-pr-merge suite result
$ bin/fm-test-run.sh tests/fm-pr-merge.test.sh   (tail)

ok - an uncommitted marker retry preserves at least one durable outcome
ok - a secondmate home that cannot report upward says so instead of merging in silence
ok - fm-pr-merge proceeds when the home carries no backlog at all
ok - fm-pr-merge refuses when the backlog exists but cannot be read
ok - fm-pr-merge refuses when its configured backend cannot be read
ok - fm-pr-merge refuses when its user backend configuration cannot be read
ok - fm-pr-merge refuses when its user backend configuration directory cannot be traversed
ok - fm-pr-merge proceeds once when its user configuration directory and backlog are genuinely absent
ok - fm-pr-merge honors a backend override over an unreadable user configuration
ok - fm-pr-merge refuses red GitHub checks and waives only a named --allow-red check
ok - fm-pr-merge refuses a draft pull request and one with no boolean draft state
ok - fm-pr-merge merges when a failed check run was replaced by a passing re-run
ok - fm-pr-merge never lets a check run supersede a legacy status context
ok - fm-pr-merge still refuses when a check's current run failed after an earlier pass
ok - fm-pr-merge uses start order when the old success finishes last
ok - fm-pr-merge supersedes an old cancellation that finishes last
ok - fm-pr-merge keeps a check red while its re-run is still in flight
ok - fm-pr-merge never lets one check's pass clear another check's failure
ok - fm-pr-merge clears a failure only on a proven later pass of the same check
ok - fm-pr-merge keeps --allow-red scoped to its named check beside a superseded failure
ok - fm-pr-merge rechecks away presence before an attended red merge
ok - fm-pr-merge requires each red-check waiver as a separate named argument
ok - fm-pr-merge accepts multiple separately named red-check waivers and records the merge
ok - fm-pr-merge still refuses an unlisted red check beside multiple named waivers
ok - fm-pr-merge records a red-check waiver only for a check it actually waived
ok - while the away-posture record exists any green merge lands under away authority, yolo or not, and attended merges stay untagged
ok - under the away-posture record the branch merges a green task, is refused on a red check with or without --allow-red, and is refused at the partition while attended
ok - a branch merge refuses under the lock when the away record is archived during preflight
ok - away posture permits immediate merges but refuses every asynchronous path
ok - away merge proceeds on a plan-gated 403 because that repository cannot have a merge queue
ok - the away record does not bypass red checks, and a recorded pr= must match the URL
ok - an unreadable away-posture record refuses the merge instead of skipping the record
ok - no away-record archive or replacement lands between the authority read and the merge
ok - a record made unreadable before the merge's own authority read refuses the merge
ok - a merge that cannot lock the away record refuses instead of merging unlocked
ok - fm-pr-merge refuses --allow-red on GitLab
FM_TEST_END 2026-09-22T02:41:57Z tests/fm-pr-merge.test.sh exit=0 duration_ms=595812 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=595921
FM_TEST_SUMMARY_FAMILY family=pr-forge count=1 duration_ms=595812 failed=0
FM_TEST_SLOWEST rank=1 script=tests/fm-pr-merge.test.sh duration_ms=595812
bin/fm-test-run.sh tests/fm-pr-merge.test.sh 2>&1  132.68s user 263.26s system 66% cpu 9:56.03 total
tail -40  0.00s user 0.00s system 0% cpu 9:56.03 total

[exited with code 0]
Evidence: Reproduction driver used to produce the CLI transcript
#!/usr/bin/env bash
# Evidence driver: drives the REAL bin/fm-pr-merge.sh through the guarded merge
# path with mocked `gh`/`gh-axi`, and prints the operator-visible transcript:
# the command, the script's verification/refusal lines, the forge command it
# actually issued, and the task meta it left behind.
#
# Usage: multi-waiver-demo.sh <repo-root>
set -u
TREE=${1:?repo root required}

# The suite's own fixture helpers, with its bare `test_*` invocation lines
# stripped so sourcing defines helpers without running the whole suite.
# The filtered copy must sit beside tests/lib.sh, which the suite resolves
# relative to its own source path; it is deleted the moment it is sourced.
FILTERED=$(mktemp "$TREE/tests/.fm-evidence-helpers.XXXXXX.sh")
grep -v '^test_[A-Za-z0-9_]*$' "$TREE/tests/fm-pr-merge.test.sh" > "$FILTERED"
trap 'rm -f "$FILTERED"' EXIT
# shellcheck disable=SC1090
. "$FILTERED"
rm -f "$FILTERED"
set +e +u

hr() { printf '\n================================================================\n%s\n================================================================\n' "$1"; }
show_meta() {
  printf '\n--- task meta on disk (state/task-x1.meta) ---\n'
  sed 's/^/    /' "$1"
}

# ---------------------------------------------------------------- scenario 1
hr "SCENARIO 1 - captain waived two named red checks: lint and unit"
case_dir=$(make_case evidence-multi-waiver)
mkdir -p "$case_dir/wt"
add_gh_mocks "$case_dir" c0ffeec0ffeec0ffeec0ffeec0ffeec0ffeec0ff
write_github_rollup_json "$case_dir" c0ffeec0ffeec0ffeec0ffeec0ffeec0ffeec0ff \
  "$(check_run lint COMPLETED FAILURE 2026-09-21T10:00:00Z)" \
  "$(check_run unit COMPLETED FAILURE 2026-09-21T10:00:00Z)" \
  "$(check_run build COMPLETED SUCCESS 2026-09-21T10:00:00Z)"
printf '\nlive GitHub check rollup at head:\n'
"$JQ_BIN" -r '.statusCheckRollup[] | "    \(.name): \(.conclusion)"' "$case_dir/github-view.json"
printf '\n$ fm-pr-merge.sh task-x1 https://github.com/example/repo/pull/88 --allow-red lint --allow-red unit\n\n'
run_pr_merge "$case_dir" task-x1 https://github.com/example/repo/pull/88 \
  --allow-red lint --allow-red unit > "$case_dir/stdout" 2> "$case_dir/stderr"
rc1=$?
sed 's/^/    /' "$case_dir/stderr"
sed 's/^/    /' "$case_dir/stdout"
printf '\n    exit status: %s\n' "$rc1"
printf '\n--- forge command actually issued (gh.log) ---\n'
grep '^pr merge ' "$case_dir/gh.log" | sed 's/^/    gh /'
show_meta "$case_dir/state/task-x1.meta"
cp "$case_dir/state/task-x1.meta" "${EVIDENCE_DIR:-.}/scenario1-task-x1.meta"

# ---------------------------------------------------------------- scenario 2
hr "SCENARIO 2 - same two waivers, but a third red check 'security' was never named"
case_dir=$(make_case evidence-unlisted-red)
mkdir -p "$case_dir/wt"
add_gh_mocks "$case_dir" d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0
write_github_rollup_json "$case_dir" d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0 \
  "$(check_run lint COMPLETED FAILURE 2026-09-21T10:00:00Z)" \
  "$(check_run unit COMPLETED FAILURE 2026-09-21T10:00:00Z)" \
  "$(check_run security COMPLETED FAILURE 2026-09-21T10:00:00Z)"
printf '\nlive GitHub check rollup at head:\n'
"$JQ_BIN" -r '.statusCheckRollup[] | "    \(.name): \(.conclusion)"' "$case_dir/github-view.json"
printf '\n$ fm-pr-merge.sh task-x1 https://github.com/example/repo/pull/89 --allow-red lint --allow-red unit\n\n'
run_pr_merge "$case_dir" task-x1 https://github.com/example/repo/pull/89 \
  --allow-red lint --allow-red unit > "$case_dir/stdout" 2> "$case_dir/stderr"
rc2=$?
sed 's/^/    /' "$case_dir/stderr"
printf '\n    exit status: %s\n' "$rc2"
printf '\n--- forge commands issued (gh.log) ---\n'
if grep -q '^pr merge ' "$case_dir/gh.log"; then
  grep '^pr merge ' "$case_dir/gh.log" | sed 's/^/    gh /'
else
  printf '    (none - no merge was submitted)\n'
fi
printf '\n--- waiver records in task meta ---\n'
if grep -q '^merge_waived_check=' "$case_dir/state/task-x1.meta"; then
  grep '^merge_waived_check=' "$case_dir/state/task-x1.meta" | sed 's/^/    /'
else
  printf '    (none - nothing merged, nothing recorded)\n'
fi

# ---------------------------------------------------------------- scenario 3
hr "SCENARIO 3 - a waiver that covered no red check, over a stale earlier record"
case_dir=$(make_case evidence-unused-waiver)
mkdir -p "$case_dir/wt"
add_gh_mocks "$case_dir" e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1
write_github_rollup_json "$case_dir" e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1 \
  "$(check_run build COMPLETED SUCCESS 2026-09-21T10:00:00Z)"
printf '%s\n' 'merge_waived_check=stale-from-an-earlier-merge' >> "$case_dir/state/task-x1.meta"
printf '\ntask meta carries a waiver from an earlier merge:\n'
grep '^merge_waived_check=' "$case_dir/state/task-x1.meta" | sed 's/^/    /'
printf '\nlive GitHub check rollup at head:\n'
"$JQ_BIN" -r '.statusCheckRollup[] | "    \(.name): \(.conclusion)"' "$case_dir/github-view.json"
printf '\n$ fm-pr-merge.sh task-x1 https://github.com/example/repo/pull/90 --allow-red lint\n\n'
run_pr_merge "$case_dir" task-x1 https://github.com/example/repo/pull/90 \
  --allow-red lint > "$case_dir/stdout" 2> "$case_dir/stderr"
rc3=$?
sed 's/^/    /' "$case_dir/stderr"
sed 's/^/    /' "$case_dir/stdout"
printf '\n    exit status: %s\n' "$rc3"
printf '\n--- forge command actually issued (gh.log) ---\n'
grep '^pr merge ' "$case_dir/gh.log" | sed 's/^/    gh /'
printf '\n--- merge authority record written ---\n'
if [ -f "$case_dir/state/task-x1.merge-authority" ]; then
  printf '    state/task-x1.merge-authority exists\n'
else
  printf '    (absent)\n'
fi
printf '\n--- waiver records in task meta after the merge ---\n'
if grep -q '^merge_waived_check=' "$case_dir/state/task-x1.meta"; then
  grep '^merge_waived_check=' "$case_dir/state/task-x1.meta" | sed 's/^/    /'
else
  printf '    (none - the unused waiver recorded nothing and the stale record was cleared)\n'
fi
show_meta "$case_dir/state/task-x1.meta"

# ---------------------------------------------------------------- scenario 4
hr "SCENARIO 4 - two named waivers while the away-posture record exists"
case_dir=$(make_case evidence-multi-waiver-away)
mkdir -p "$case_dir/wt"
add_gh_mocks "$case_dir" f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2
write_github_rollup_json "$case_dir" f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2 \
  "$(check_run lint COMPLETED FAILURE 2026-09-21T10:00:00Z)" \
  "$(check_run unit COMPLETED FAILURE 2026-09-21T10:00:00Z)"
write_away_record "$case_dir" --words 'merge task-x1 when green'
printf '\nthe captain is away (state/.afk-contract present)\n'
printf '\n$ fm-pr-merge.sh task-x1 https://github.com/example/repo/pull/91 --allow-red lint --allow-red unit\n\n'
run_pr_merge "$case_dir" task-x1 https://github.com/example/repo/pull/91 \
  --allow-red lint --allow-red unit > "$case_dir/stdout" 2> "$case_dir/stderr"
rc4=$?
sed 's/^/    /' "$case_dir/stderr"
printf '\n    exit status: %s\n' "$rc4"
printf '\n--- forge commands issued (gh.log) ---\n'
if grep -q '^pr merge ' "$case_dir/gh.log"; then
  grep '^pr merge ' "$case_dir/gh.log" | sed 's/^/    gh /'
else
  printf '    (none - no merge was submitted)\n'
fi

hr "DONE"
- Outcome: ⚠️ 1 warning across 1 run (44m24s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 infos
  • ⚠️ bin/fm-pr-merge.sh:666 - A waived red merge leaves no evidence of the waiver. On success github_verify_mergeable prints 'verified: <url> is open and mergeable, with every required check green at head <sha>' unconditionally (bin/fm-pr-merge.sh:666), and the only durable artifacts - meta 'pr=' and state/<id>.merge-authority written by persist_accepted_merge_authority - record provider/host/path/number/authority but never the waived check names. Failure scenario: a caller runs fm-pr-merge.sh task-x1 &lt;pr-url&gt; --allow-red lint --allow-red unit --allow-red security on a pull request whose entire red set is lint+unit+security; every red name is covered at bin/fm-pr-merge.sh:647, refusals stays empty, stderr asserts every required check was green, and the persisted merge-authority record is byte-identical to a fully green merge - so nothing after the fact can distinguish an authorized three-check red merge from a clean one, and the 'still requires every other check green' guard is vacuous once the named set covers the whole red set. Before this change the discrepancy was bounded to one check; it is now unbounded. Recommend naming the waived checks in the verified line and persisting them alongside the merge authority, since that is the earliest shared boundary where the merge is already recorded.
  • ℹ️ bin/fm-pr-merge.sh:163 - --allow-red accepts any non-empty next token as the check name, including another option. Failure scenario: fm-pr-merge.sh task-x1 &lt;pr-url&gt; --allow-red lint --allow-red --attended-override -- --admin registers a waiver literally named '--attended-override', leaves ATTENDED_OVERRIDE=false, and then reject_protected_forge_args refuses --admin with a message about protection bypass rather than about the missing waiver name. It fails closed (a bogus waiver matches no check name, so any real red check still refuses), but the refusal misattributes the cause. Allowing repetition makes this mid-command-line shape plausible where a single occurrence made it unlikely; rejecting a value that begins with '-' (or at least '--') at bin/fm-pr-merge.sh:163 turns it into an accurate parse error.
  • ℹ️ tests/fm-pr-merge.test.sh:2725 - test_allow_red_requires_a_separate_name passes 'fm-pr-merge requires each red-check waiver as a separate named argument' but only exercises the --allow-red=lint equals form; the deleted duplicate-waiver case was its only other assertion. The error: --allow-red requires a check name branch at bin/fm-pr-merge.sh:163 has no test anywhere in the suite (grep for 'requires a check name' over tests/ returns nothing). Failure scenario: that guard could be deleted or inverted - e.g. dropping the [ -n &#34;${2:-}&#34; ] test so a trailing --allow-red shifts past the end of the argument list - and the whole suite would stay green while the test's own pass message still claims the behavior is covered.

🔧 Fix: record and report named red-check waivers on merge
2 infos still open:

  • ℹ️ bin/fm-pr-merge.sh:400 - The durable record describes what the merge landed on, not what was authorized. FM_PR_WAIVED_CHECKS only collects a name that matched a check the live read reported red (bin/fm-pr-merge.sh:661-668), and record_waived_red_checks returns early when that set is empty (bin/fm-pr-merge.sh:978-981), so a waiver that covered nothing is neither reported nor recorded. Failure scenario: an agent merges with --allow-red lint --allow-red security on a pull request where only lint is red; the meta records merge_waived_check=lint and the verification line names only 'lint', so no artifact shows that the run was also carrying authority to waive 'security' - an auditor reconstructing what the merge was allowed to bypass sees the used subset only. This is deliberate and documented (the comment at bin/fm-pr-merge.sh:397-399 and the test at tests/fm-pr-merge.test.sh:2775 both pin it), and it is arguably the more honest record, but it diverges from a literal reading of the round-1 fix instruction 'Record every named red-check waiver durably beside merge authority', so confirm the outcome-only semantic is what you want before it becomes the recorded contract.
  • ℹ️ bin/fm-pr-merge.sh:976 - record_waived_red_checks (bin/fm-pr-merge.sh:976-1011) is a third hand-maintained copy of the atomic meta-publish sequence - mktemp in STATE, filter one key, append, chmod 0600, fm_pr_private_file_valid, fm_pr_metadata_identity_parse, fm_pr_regular_destination_on_device_or_absent, mv, re-validate - after bin/fm-pr-check.sh:131-149 and the weaker variant in bin/fm-x-lib.sh:915-960. The new copy is correct as written: its single [ &#34;$FM_PR_META_URL&#34; = &#34;$URL&#34; ] check subsumes fm-pr-check's four provider/host/path/number comparisons because all four are derived from that canonical URL by fm_pr_url_parse, and every failure path reaches the rm -f -- &#34;$tmp&#34; at line 1009. Noting it because a future change to the privacy or device contract in bin/fm-pr-lib.sh now has to be mirrored into three sites by hand and a divergence would be silent; a shared fm_pr_meta_publish <meta> <state> <drop-key> <line>... helper in bin/fm-pr-lib.sh, which already owns fm_pr_private_file_valid and fm_pr_metadata_identity_parse, is the boundary that would collapse them. No action needed for this merge.
⚠️ **Test** - 1 warning
  • ⚠️ tests/fm-pr-check-security.test.sh:697 - Pre-existing flakiness (not caused by this change): tests/fm-pr-check-security.test.sh bounds each watcher cycle with a 10-second alarm in run_watcher_bounded, and under machine load that bound trips, failing whichever watcher-driven test happens to be running with an empty stderr. I saw it fail at test_merged_poll_row_carries_the_merge_authority in one run and test_valid_recording_and_merge_derivation in another; both pass 3/3 in isolation on this branch, the whole suite passes when run alone (38 ok / 0 not ok), and the same suite is green on the base tree. No action needed for this change; noting it because the same bound can red a loaded CI lane.
  • bin/fm-test-run.sh tests/fm-pr-merge.test.sh — full suite green (exit=0), including the new multi-waiver, unlisted-red-check, and waiver-recording cases plus the retained GitLab and away-posture refusals
  • Manual CLI demonstration driving the real bin/fm-pr-merge.sh through four scenarios (multi-waiver merge, unlisted red check, unused waiver over a stale record, multi-waiver while away) with the suite's gh/gh-axi mocks; transcript and resulting task meta captured
  • Negative control: test_allow_red_accepts_multiple_separately_named_checks, test_allow_red_refuses_an_unlisted_red_check, test_a_waived_merge_records_only_the_checks_it_waived run against the base implementation (git archive 8c1cdb7) — all three fail there; test_allow_red_requires_a_separate_name passes on both as expected
  • bash tests/fm-pr-check-security.test.sh — the only suite exercising the changed fm_pr_metadata_identity_parse; full pass (38 ok, 0 not ok) when run alone on this branch, and the same suite green on the base tree
  • test_valid_recording_and_merge_derivation and test_merged_poll_row_carries_the_merge_authority run in isolation on this branch 3x each — pass every time
  • git status --porcelain — worktree clean after testing; temporary base-control tree and helper files removed
⚠️ **Document** - 1 info
  • ℹ️ bin/fm-pr-lib.sh:345 - bin/fm-pr-lib.sh's fm_pr_metadata_identity_parse holds the cross-producer allowlist of meta keys permitted after pr=, and this change extended it with merge_waived_check= without a doc comment. I deliberately left it uncommented: the surrounding entries (pr_head=, x_request=, x_platform=, ...) carry no comment either, and a comment there would only restate the case list, which the placement policy forbids. The per-key contract is owned by each producer's header (AGENTS.md:122), and fm-pr-merge.sh's record_waived_red_checks header already states why a waived-check line must survive that validation. Flagging as a judgment call, not a gap: if a future change makes that allowlist a stated contract, fm-pr-lib.sh's header is the place for it.
⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 1)

🔧 Fix: install pinned actionlint locally so workflow lint runs
1 warning still open:

  • ⚠️ linter found issues (exit code 1)
✅ **Push** - passed

✅ No issues found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant