Skip to content

fix(bin): silence healthy PR autoarm lanes and match branches by name - #109

Merged
EvanAgee merged 2 commits into
mainfrom
fm/fm-autoarm-skip-scouts
Sep 9, 2026
Merged

EvanAgee merged 2 commits into
mainfrom
fm/fm-autoarm-skip-scouts

Conversation

@EvanAgee

@EvanAgee EvanAgee commented Sep 9, 2026 •

Copy link
Copy Markdown
Owner

Intent

Stop bin/fm-pr-autoarm.sh from queuing wake events for healthy lanes and make it find a pull request pushed from the pipeline's own worktree. The sweep must skip kind=scout silently, as it skips kind=secondmate. When a named local branch has no upstream, do not queue a wake; look up that exact branch name on the project's forge, arm exactly one open match through fm-pr-check.sh, keep no match silent, and retain the wake for multiple exact matches. A detached HEAD must stay silent so the next scan retries; only a missing or unreadable recorded worktree is a broken-lane wake. Preserve existing pr= metadata without touching it, keep secondmates skipped, leave announce behavior unchanged, and keep forge failures or malformed forge output silent. Update the script header with one sentence per rule. Add dated docs/verification/supervision.md evidence only if that file already tracks this script. Add regression tests red first, run tests/fm-pr-autoarm.test.sh through bin/fm-test-run.sh, keep shellcheck clean, and record a real sweep against live metadata with all queue writes isolated in scratch state for the PR's What I walked section. Never run the 1Password CLI (op run, op read, op item, op environment); secrets come from the worktree .env.local, and a missing variable is reported by name in a blocked line.

What Changed

  • bin/fm-pr-autoarm.sh sweep now skips kind=scout metadata the same way it already skips kind=secondmate, so scout lanes never reach the forge or arm a PR.
  • A named local branch with no upstream (or an upstream remote of .) now falls back to the branch's own name on origin and looks it up on the forge, arming exactly one open match through fm-pr-check.sh. Detached HEAD, a non-matching ref record, an unreadable remote, and an unparsable remote URL now return silently instead of queuing a task wake; a missing or unreadable worktree and multiple exact matches still wake.
  • tests/fm-pr-autoarm.test.sh adds cases for the scout sweep exclusion, unchanged scout announcement handling, and the no-upstream path (zero matches silent, one match armed, two matches waking, forge failure/malformed output silent, missing origin silent); the script header comment and the docs/scripts.md row were reworded to match the new resolution rules.

Risk Assessment

✅ Low: The change is a tightly scoped rewrite of one function's silent-vs-wake branches in a single script, every new code path was traced against real git behavior and computes correct remote/branch values, the header matches the implemented rules, and the added tests are behavioral and red-first against the base commit.

Testing

The existing suite tests/fm-pr-autoarm.test.sh passes in full through bin/fm-test-run.sh (30 ok, exit=0), and shellcheck is clean on both the script and the test file. I confirmed the added tests are genuinely red-first by running them against the base-commit script, where 11 assertions fail, all inside the new scout/detached-HEAD/no-upstream groups while every pre-existing group stays green. Beyond unit tests, I drove the real sweep-one interface across twelve purpose-built worktrees to check each rule in the intent independently, confirming scouts and secondmates are skipped before any forge call, detached HEAD is silent, a no-upstream branch queries origin for its exact local branch name and arms exactly one open match, zero matches and forge failure/malformed output stay silent, two matches still wake, a missing worktree still wakes, and existing pr= metadata is left alone. The decisive end-to-end evidence is a real sweep over all 14 live task metadata files (copied into an isolated scratch state dir, with real authenticated gh calls and a recording arm stub): the base script queued 10 wake events to the durable queue and found no PRs, while the fixed script queued zero (the .wake-queue file was never created) and discovered one real open PR, #108 on branch fm/fm-brief-no-1password, verified via the GitHub API. Live metadata was unchanged afterwards and the worktree is clean. docs/verification/supervision.md tracks a different script (fm-claude-stop-autoarm.sh), so the intent's conditional docs requirement correctly does not apply.

Evidence: Real sweep against 14 live task metadata: 10 wakes before vs 0 wakes and 1 real PR after

Source: Real sweep against 14 live task metadata: 10 wakes before vs 0 wakes and 1 real PR after

# Real sweep: bin/fm-pr-autoarm.sh against live task metadata

All 14 real `.meta` files were copied from `/Users/evanagee/Sites/firstmate/state/`
into an isolated scratch state dir. Every wake-queue write, cursor write, and arm
call landed in scratch. Live state was verified untouched afterwards.
`fm-pr-check.sh` was replaced by a recording stub, so no real PR watch was armed.
The GitHub lookups were real (`gh`, authenticated from its own keyring; the
1Password CLI was never invoked).

## Live lane shape

| task | kind | pr= | branch | upstream |
|---|---|---|---|---|
| aos-2223-full-safety-track | ship | no | (detached) | none |
| aos-3430-writer-capture | scout | no | (detached) | none |
| aos-3527-sandbox-symlink-bounce | ship | no | fm/aos-3527-sandbox-symlink-bounce | none |
| aos-3601-desktop-home-scout | scout | no | (detached) | none |
| aos-3628-chat-knows-it-is-aos | ship | yes | manual-aos-3628-... | none |
| aos-3629-no-workspace-tools-hosted | ship | yes | manual-aos-3629-... | origin/... |
| aos-changelog-durable-publishing | ship | yes | work-3622-... | origin/... |
| aos-no-1password-local-dev | ship | no | manual-aos-no-1password-local-dev | none |
| aos-triage-standing | scout | no | (detached) | none |
| fm-autoarm-skip-scouts | ship | no | fm/fm-autoarm-skip-scouts | none |
| fm-brief-no-1password | ship | no | fm/fm-brief-no-1password | none |
| fm-relaunch-after-restart | ship | no | fm/fm-relaunch-after-restart | none |
| platform-61-invite-only-staff-pools | ship | yes | fm/platform-61-... | none |
| sdi-715-qbo-live-foundation | ship | no | fm/sdi-715-qbo-live-foundation | none |

## BEFORE the fix (base 87890f7) — 10 wake events queued, 0 PRs found

Sweep stdout:

    pr-autoarm: task=aos-2223-full-safety-track has no resolvable branch
    pr-autoarm: task=aos-3430-writer-capture has no resolvable branch
    pr-autoarm: task=aos-3527-sandbox-symlink-bounce branch fm/aos-3527-sandbox-symlink-bounce has no upstream
    pr-autoarm: task=aos-3601-desktop-home-scout has no resolvable branch
    pr-autoarm: task=aos-no-1password-local-dev branch manual-aos-no-1password-local-dev has no upstream
    pr-autoarm: task=aos-triage-standing has no resolvable branch
    pr-autoarm: task=fm-autoarm-skip-scouts branch fm/fm-autoarm-skip-scouts has no upstream
    pr-autoarm: task=fm-brief-no-1password branch fm/fm-brief-no-1password has no upstream
    pr-autoarm: task=fm-relaunch-after-restart branch fm/fm-relaunch-after-restart has no upstream
    pr-autoarm: task=sdi-715-qbo-live-foundation branch fm/sdi-715-qbo-live-foundation has no upstream

Durable wake queue written (`state/.wake-queue`), 10 rows:

    1788975737	1	check	pr-autoarm:aos-2223-full-safety-track	check: pr-autoarm: task=aos-2223-full-safety-track has no resolvable branch
    1788975738	2	check	pr-autoarm:aos-3430-writer-capture	check: pr-autoarm: task=aos-3430-writer-capture has no resolvable branch
    1788975739	3	check	pr-autoarm:aos-3527-sandbox-symlink-bounce	check: pr-autoarm: task=aos-3527-sandbox-symlink-bounce branch fm/aos-3527-sandbox-symlink-bounce has no upstream
    1788975739	4	check	pr-autoarm:aos-3601-desktop-home-scout	check: pr-autoarm: task=aos-3601-desktop-home-scout has no resolvable branch
    1788975741	5	check	pr-autoarm:aos-no-1password-local-dev	check: pr-autoarm: task=aos-no-1password-local-dev branch manual-aos-no-1password-local-dev has no upstream
    1788975741	6	check	pr-autoarm:aos-triage-standing	check: pr-autoarm: task=aos-triage-standing has no resolvable branch
    1788975742	7	check	pr-autoarm:fm-autoarm-skip-scouts	check: pr-autoarm: task=fm-autoarm-skip-scouts branch fm/fm-autoarm-skip-scouts has no upstream
    1788975743	8	check	pr-autoarm:fm-brief-no-1password	check: pr-autoarm: task=fm-brief-no-1password branch fm/fm-brief-no-1password has no upstream
    1788975744	9	check	pr-autoarm:fm-relaunch-after-restart	check: pr-autoarm: task=fm-relaunch-after-restart branch fm/fm-relaunch-after-restart has no upstream
    1788975745	10	check	pr-autoarm:sdi-715-qbo-live-foundation	check: pr-autoarm: task=sdi-715-qbo-live-foundation branch fm/sdi-715-qbo-live-foundation has no upstream

Arm log: `<none>` — no PR was found for any lane.

## AFTER the fix (target f4a833a) — 0 wake events, 1 real PR armed

Sweep stdout: completely silent (no output at all).

Wake queue: `state/.wake-queue` was never created. Zero wakes queued.

Arm log:

    WOULD-ARM task=fm-brief-no-1password url=https://github.com/EvanAgee/firstmate/pull/108

That PR is real and open, and its head branch matches the local branch exactly:

    $ gh api repos/EvanAgee/firstmate/pulls/108 --jq '...'
    PR #108 | state=open | head=fm/fm-brief-no-1password | title=feat(bin): forbid the 1Password CLI in every generated worker brief

## Isolation check

Live metadata unchanged after both sweeps:

    $ git -C /Users/evanagee/Sites/firstmate status --porcelain state/
    (no output)
Evidence: Rule-by-rule behavioral matrix of sweep-one against the user intent

Source: Rule-by-rule behavioral matrix of sweep-one against the user intent

# Rule-by-rule check of bin/fm-pr-autoarm.sh sweep-one

Each row is one run of the real `sweep-one` entry point against a purpose-built
worktree, with a fake `gh` on PATH and a recording arm stub. "wake" is the
reason line the sweep emits; `<SILENT>` means it emitted nothing.

| scenario | wake emitted | forge hit | armed |
|---|---|---|---|
| kind=scout, 1 open PR | `<SILENT>` | no | none |
| kind=secondmate, 1 open PR | `<SILENT>` | no | none |
| detached HEAD | `<SILENT>` | no | none |
| no upstream, 0 open PRs | `<SILENT>` | yes | none |
| no upstream, 1 open PR | `<SILENT>` | yes | `different-task https://github.com/acme/widget/pull/41` |
| no upstream, 2 open PRs | `task=different-task has more than one open PR for branch actual-feature` | yes | none |
| no upstream, forge exits 1 | `<SILENT>` | yes | none |
| no upstream, malformed forge output | `<SILENT>` | yes | none |
| no upstream and no origin remote | `<SILENT>` | no | none |
| with upstream, 1 open PR | `<SILENT>` | yes | `different-task https://github.com/acme/widget/pull/41` |
| missing worktree | `task=different-task worktree is missing or unreadable` | no | none |
| existing `pr=` in metadata | `<SILENT>` | no | none (metadata untouched) |

Forge query for the no-upstream case confirms it looks up the exact local branch
name against origin:

    api --method GET repos/acme/widget/pulls -f state=open -f head=acme:actual-feature -f per_page=2 ...

## Same case, before vs after the fix

    === AFTER fix (target f4a833a) ===
    stdout: <silent>
    forge: api ... -f head=acme:actual-feature ...
    arm:   different-task https://github.com/acme/widget/pull/41

    === BEFORE fix (base 87890f7) ===
    stdout: task=different-task branch actual-feature has no upstream
    forge: <never contacted>
    arm:   <none>
Evidence: Red-first proof: new tests failing on base commit, green on target

Source: Red-first proof: new tests failing on base commit, green on target

# Red-first proof for tests/fm-pr-autoarm.test.sh

The new tests were run against the PRE-FIX script (base 87890f7) with the new
test file. To see every failure instead of stopping at the first one, `fail()`
was made non-fatal in a throwaway scratch copy of the repo. That is why a group's
`pass` line still prints right after its `not ok` line; only the `not ok` lines
matter.

Every `not ok` falls inside a group added or changed by this commit:

    not ok - a scout sweep reached the forge
    not ok - a scout sweep armed a PR
    not ok - a detached worktree should be silent: pr-autoarm: task=different-task has no resolvable branch
    not ok - a branch without an upstream should be silent: pr-autoarm: task=different-task branch actual-feature has no upstream
    not ok - a branch without an upstream did not reach the forge
    not ok - one open PR for a branch without an upstream should arm silently: pr-autoarm: task=different-task branch actual-feature has no upstream
    not ok - a branch without an upstream did not arm its exact open PR
    not ok - two open PRs for a branch without an upstream did not wake: pr-autoarm: task=different-task branch actual-feature has no upstream
    not ok - fail forge result for a branch without an upstream should be silent: pr-autoarm: task=different-task branch actual-feature has no upstream
    not ok - malformed forge result for a branch without an upstream should be silent: pr-autoarm: task=different-task branch actual-feature has no upstream
    not ok - a missing origin for a branch without an upstream should be silent: pr-autoarm: task=different-task branch actual-feature has no upstream

Pre-existing groups all stayed green against the old script, so the new tests
target only the new behavior and no old behavior regressed.

# Green after the fix

Unmodified suite via the project runner, on the target commit:

    $ bin/fm-test-run.sh tests/fm-pr-autoarm.test.sh
    FM_TEST_BEGIN 2026-09-09T17:36:23Z tests/fm-pr-autoarm.test.sh family=pr-forge expected_gate_skip=none
    ... 30 ok lines, including:
    ok - scout metadata is excluded from the branch sweep
    ok - a detached worktree waits for the next scan
    ok - zero open PRs for a branch without an upstream is a silent no-op
    ok - a branch without an upstream arms one exact open PR
    ok - multiple open PRs for a branch without an upstream still wake
    ok - forge failures stay silent for branches without upstreams
    ok - a branch without an upstream or origin stays silent
    ok - secondmate metadata is excluded from the branch sweep
    ok - secondmate announcements cannot attach a child PR to the parent
    ok - scout announcements keep existing handling
    FM_TEST_END 2026-09-09T17:39:35Z tests/fm-pr-autoarm.test.sh exit=0 duration_ms=192077
    FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=192568
Evidence: Real sweep side-by-side (walked path)
\### BEFORE fix (base 87890f7) - same 14 live tasks, scratch state ###
pr-autoarm: task=aos-2223-full-safety-track has no resolvable branch
pr-autoarm: task=aos-3430-writer-capture has no resolvable branch
pr-autoarm: task=aos-3527-sandbox-symlink-bounce branch fm/aos-3527-sandbox-symlink-bounce has no upstream
pr-autoarm: task=aos-3601-desktop-home-scout has no resolvable branch
pr-autoarm: task=aos-no-1password-local-dev branch manual-aos-no-1password-local-dev has no upstream
pr-autoarm: task=aos-triage-standing has no resolvable branch
pr-autoarm: task=fm-autoarm-skip-scouts branch fm/fm-autoarm-skip-scouts has no upstream
pr-autoarm: task=fm-brief-no-1password branch fm/fm-brief-no-1password has no upstream
pr-autoarm: task=fm-relaunch-after-restart branch fm/fm-relaunch-after-restart has no upstream
pr-autoarm: task=sdi-715-qbo-live-foundation branch fm/sdi-715-qbo-live-foundation has no upstream
-> durable state/.wake-queue written with 10 rows; arm log: <none>

\### AFTER fix (target f4a833a) - same 14 live tasks, scratch state ###
(no output at all)
-> state/.wake-queue never created; zero wakes queued
-> arm log: WOULD-ARM task=fm-brief-no-1password url=https://github.com/EvanAgee/firstmate/pull/108

$ gh api repos/EvanAgee/firstmate/pulls/108 --jq '...'
PR #108 | state=open | head=fm/fm-brief-no-1password | title=feat(bin): forbid the 1Password CLI in every generated worker brief

$ git -C /Users/evanagee/Sites/firstmate status --porcelain state/
(no output - live metadata untouched)
Evidence: Targeted suite result on target commit
$ bin/fm-test-run.sh tests/fm-pr-autoarm.test.sh
FM_TEST_BEGIN 2026-09-09T17:36:23Z tests/fm-pr-autoarm.test.sh family=pr-forge expected_gate_skip=none
ok - scout metadata is excluded from the branch sweep
ok - a detached worktree waits for the next scan
ok - zero open PRs for a branch without an upstream is a silent no-op
ok - a branch without an upstream arms one exact open PR
ok - multiple open PRs for a branch without an upstream still wake
ok - forge failures stay silent for branches without upstreams
ok - a branch without an upstream or origin stays silent
ok - secondmate metadata is excluded from the branch sweep
ok - secondmate announcements cannot attach a child PR to the parent
ok - scout announcements keep existing handling
(30 ok lines total)
FM_TEST_END 2026-09-09T17:39:35Z tests/fm-pr-autoarm.test.sh exit=0 duration_ms=192077
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=192568

What I walked

I ran bin/fm-pr-autoarm.sh sweep against copies of all 14 live task metadata files with state and arm writes isolated in a scratch directory. The fixed sweep produced no output and queued no wakes.

It skipped aos-3430-writer-capture, aos-3601-desktop-home-scout, and aos-triage-standing because they are scouts. It skipped detached aos-2223-full-safety-track so a later scan can retry. It silently found no open exact-branch PR for aos-3527-sandbox-symlink-bounce, aos-no-1password-local-dev, fm-autoarm-skip-scouts, fm-relaunch-after-restart, and sdi-715-qbo-live-foundation. Existing pr= metadata remained untouched.

The same sweep found fm-brief-no-1password by its local branch name despite no upstream and would arm #108. Live metadata did not change.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • bin/fm-test-run.sh tests/fm-pr-autoarm.test.sh on the target commit - 30 ok, exit=0, failed=0
  • Red-first proof: ran the new tests/fm-pr-autoarm.test.sh against the pre-fix bin/fm-pr-autoarm.sh from base 87890f7 in a throwaway scratch repo; 11 not ok lines, all confined to groups added/changed by this commit, with all pre-existing groups still green
  • Rule-by-rule behavioral matrix via the real fm-pr-autoarm.sh sweep-one different-task entry point across 12 purpose-built worktrees: kind=scout, kind=secondmate, detached HEAD, no-upstream with 0/1/2 open PRs, no-upstream with forge exit 1, no-upstream with malformed forge output, no-upstream with no origin remote, with-upstream 1 PR, missing worktree, and pre-existing pr= metadata
  • Verified the no-upstream lookup issues the exact-branch forge query repos/acme/widget/pulls -f state=open -f head=acme:actual-feature -f per_page=2
  • Real sweep: fm-pr-autoarm.sh sweep against all 14 live .meta files copied from /Users/evanagee/Sites/firstmate/state/ into an isolated scratch state dir, with real authenticated gh forge calls and FM_PR_CHECK_BIN pointed at a recording stub
  • Same real sweep re-run with the base 87890f7 script for a side-by-side comparison, capturing the durable state/.wake-queue contents from both runs
  • gh api repos/EvanAgee/firstmate/pulls/108 to confirm the auto-discovered PR is genuinely open and its head ref matches the local branch exactly
  • gh auth status to confirm forge credentials come from the gh keyring, and verified the 1Password CLI (op) was never invoked
  • shellcheck bin/fm-pr-autoarm.sh tests/fm-pr-autoarm.test.sh - clean
  • Isolation checks: git -C /Users/evanagee/Sites/firstmate status --porcelain state/ confirmed live metadata untouched, and git status --porcelain confirmed the worktree is clean after removing a stray scratch file my own test stub created
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 11 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: e823d8da-5255-477b-92d3-0c907ced76cd

📥 Commits

Reviewing files that changed from the base of the PR and between 87890f7 and 36bee1f.

📒 Files selected for processing (3)
  • bin/fm-pr-autoarm.sh
  • docs/scripts.md
  • tests/fm-pr-autoarm.test.sh

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@EvanAgee EvanAgee added the agent-pr-watched An agent merge watch is armed on this PR label Sep 9, 2026
@EvanAgee
EvanAgee merged commit f349c90 into main Sep 9, 2026
21 checks passed
EvanAgee added a commit that referenced this pull request Sep 22, 2026
Refs #1
Refs #42
Refs #60
Refs #65
Refs #73
Refs #74
Refs #107
Refs #109
Refs #117

## What I walked

In a throwaway `.scratch-c4-walk/home` and local Git repository:

```
$ FM_HOME=.scratch-c4-walk/home bin/fm-merge-local.sh walk-clean
merged fm/walk-clean into local main (aa84759 -> 1b9c678) in /Users/evanagee/.treehouse/firstmate-df5ff1/9/firstmate/.scratch-c4-walk/project
$ git -C .scratch-c4-walk/project log -1 --format=%s main
clean local landing
```

```
$ FM_HOME=.scratch-c4-walk/home FM_GH_BIN=.scratch-c4-walk/fake-gh bin/fm-flow.sh walk status
matched rulesets: main-protection=1 (rules: pull_request,required_status_checks) review=2 (rules: pull_request)
registry posture: [no-mistakes-prod-only +yolo]
main-protection ruleset 1 enforcement: active
main-protection ruleset gates: pull_request + required_status_checks present
review ruleset 2 enforcement: active
stored previous posture: <none>
verdict: full
```

```
$ FM_HOME=.scratch-c4-walk/home bin/fm-merge-local.sh walk-outage fm/walk-outage
error: task walk-outage is mode=no-mistakes; a PR-bound task lands locally only while GitHub is unreachable (state/.github-down present)
merge its PR with bin/fm-pr-merge.sh after approval
exit=1
```

The flow status used a local fake that returned read-only ruleset data. No GitHub request, PR, or push was made.

## Port record

The root already had guarded `fm-pr-merge.sh` and `fm-merge-local.sh`, canonical v2 PR poll registration and repair, GitLab merge verification, task control locks, leases, captain holds, and persisted merge authority. During the final rebase, the root also gained the outage landing skill unchanged.

I kept those root implementations. The port adds auto-arm, reviewer chase, review-thread gating, issue claims and post-merge closing, GitHub outage landing and return sync, and the project flow switch around them.

I dropped the fork's obsolete `captain-merge` token, `fm-pr-check-migrate.sh`, and C3 delivery timing, backfill, and token ledger changes. The root's captain-hold authority and repairable poll publication cover those seams.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-pr-watched An agent merge watch is armed on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant