Skip to content

fix(bin): let a secondmate's PR merge under the captain's away authority - #15

Merged
VasanthAmana merged 2 commits into
merkensoft-iris:mainfrom
VasanthAmana:fm/merge-path-away-authority
Oct 16, 2026
Merged

VasanthAmana merged 2 commits into
merkensoft-iris:mainfrom
VasanthAmana:fm/merge-path-away-authority

Conversation

@VasanthAmana

Copy link
Copy Markdown

Intent

Let second-mate PRs merge while the captain is away.

Problem statement (this repository is public; the description below is the whole context):

  • While a home's away-posture record (state/.afk-contract) exists, bin/fm-pr-merge.sh --secondmate <mate> <child-task> <pr-url> refuses every merge with: "a secondmate's PR merge is refused while this home's away record exists: the secondmate's home cannot see that record and would merge as attended; nothing was merged".
  • The refusal is correct as far as it goes: the owning secondmate home performs the merge through its own guarded path, and that home cannot see the parent's away record, so it would apply attended rules (for example, attended-only waivers) instead of away rules.
  • The consequence: during away mode, a green PR built by a second mate's child task cannot be merged by anyone, even when the captain's away instructions call for merging green PRs. Main-home task PRs merge fine in the same situation.
  • The supervision branch (supervision host / away session) also reported it could not merge a second mate's PR, so such merges are left for the captain's return.

Wanted: under away mode, a second mate's green PR merges under the same away-authority rules that apply to a main-home PR - synchronous merge only, no red merge, no attended-only waivers (--allow-red / --allow-missing refused), merge metadata recorded - by passing the away authority across the home boundary to the owning home's guarded merge, rather than bypassing the owning home's guards.

What Changed

  • bin/fm-pr-merge.sh --secondmate no longer refuses a merge just because this home's away record exists. When an away record exists, it now adds a leading --parent-away-authority to the owning home's merge, whether that home is local (via exec) or remote (via fm-on.sh). For a remote home, this home holds its own away-record lock across the synchronous call. If the record can't be read or locked, the merge is refused. The routed exec also drops this home's FM_SUPERVISION_ACTOR. The supervision branch can now route a secondmate merge exactly when it could merge a main-home PR.

  • A new --parent-away-authority entry path makes the owning home apply the away rules:

    • only a synchronous merge is allowed, so --auto and GitLab auto-merge are refused;
    • the attended-only --allow-red / --allow-missing waivers are refused;
    • away is recorded as the merge authority.

    A local owning home checks its claim against the live away record of the parent named in its .fm-secondmate-parent binding, holding that record's lock. If the parent's record no longer exists, the merge is refused. A remote owning home applies the away rules on the parent's word. The flag is refused when the home has no secondmate identity or parent binding, and when it is combined with --secondmate.

  • Updated the script header and docs/architecture.md to describe how each route proves the away authority. Extended tests/fm-pr-merge.test.sh to cover the new routing and refusals.

Risk Assessment

✅ Low: The fix round adds a narrow fail-closed guard. When the local secondmate route carries no away authority, the supervision branch is now refused before the exec, so it can no longer hand off an attended merge. The regression test drives the archive race through the real entrypoint and would fail without the guard.

Testing

All 8 secondmate-merge tests passed under stock bash 3.2. They drive the real fm-pr-merge.sh entrypoint, but against a fake gh and a fake ssh, so none of the results are live. The regression runs reproduce both bugs. With the base script, the old refusal comes back and the away-merge test fails. With the script from before the review fix, the lapse-race test fails. No scenario was driven against a real forge, so every scenario is marked untested. Merging a real GitHub PR was not run, because that needs a disposable repo and approval for an outward-facing merge.

  • Live validation: ⚠️ inconclusive - 0 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Captain away, parent runs fm-pr-merge.sh --secondmate mate-x task-x1 &lt;green PR&gt;: the merge lands through the owning home, which records away authority and reports 'merged ... away' upward ⏸️ untested no The earlier payload ran this only against a fake gh (test_secondmate_merge_carries_the_parent_away_authority and the CLI transcript), so no live result was established. A live run needs a disposable G…
While the parent is away, a routed merge with --allow-red, --allow-missing, or --auto is refused as attended-only and never reaches the forge ⏸️ untested no The earlier payload checked this only against a fake gh forge, so no live result was established. A live run needs a real GitHub repo/PR and gh credentials.
The captain's return (archiving the record) during the owning home's forge call is blocked by the parent's record lock ⏸️ untested no The earlier payload injected the race at a fake gh merge call, so no live result was established. A live run needs a real forge merge during real away mode.
Adversarial: the away record is archived after the supervision branch's actor check but before routing; the branch is refused (exit 6) and no forge merge runs ⏸️ untested no The earlier payload injected the race through a wrapped fm-afk-contract.sh against a fake gh forge, so no live result was established.
Adversarial: --parent-away-authority with no parent away record, a record that lapses mid-preflight, no parent binding, or a re-route is refused with no forge merge ⏸️ untested no The earlier payload checked this only against a fake gh forge (test_owning_home_refuses_an_unbacked_parent_away_claim), so no live result was established.
Remote secondmate: the parent holds its record lock across the ssh call and passes --parent-away-authority; the remote home applies the away rules ⏸️ untested no The earlier payload used a fake ssh and a fake gh, so no live result was established. A live run needs a reachable remote secondmate host and a real forge.
Attended (no away record) supervision branch is still refused a secondmate route; other owning-home guards are unchanged ⏸️ untested no The earlier payload checked this only against a fake gh forge, so no live result was established.
Real GitHub PR built by a secondmate child merges during real away mode ⏸️ untested no This needs a disposable GitHub repo with a real green PR, gh credentials, and the captain's approval for an outward-facing merge. None of these were available in this gate run. Provide a throwaway rep…
Evidence: Targeted secondmate merge test run (HEAD, bash 3.2)

Source: Targeted secondmate merge test run (HEAD, bash 3.2)

ok - a parent merges a secondmate child's PR through the owning home's own guarded path
ok - a secondmate child's PR still meets every guard of the owning home's merge
ok - a secondmate merge is refused unless the registry routes to that secondmate's own home
ok - a routed secondmate merge carries the parent's away authority into the owning home's guarded merge
ok - a secondmate route refuses the supervision branch when the away record lapses before routing
ok - an owning home honors away authority only from its bound parent's live record
ok - a remote secondmate merge carries the parent's away authority under the parent's record lock
ok - a remote secondmate child's PR is merged by that home's own guarded path on its host
ALL-DONE
Evidence: Regression tests against the base and pre-review-fix scripts (both fail as expected)

Source: Regression tests against the base and pre-review-fix scripts (both fail as expected)

== bin/fm-pr-merge.sh at 176a7889
●  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/78 is open and mergeable, with every unwaived required check reported and every unwaived check green at head 7878787878787878787878787878787878787878: expected exit 6, got 0
ok - a routed secondmate merge carries the parent's away authority into the owning home's guarded merge
== bin/fm-pr-merge.sh at 9664eed7
not ok - secondmate-route-lapse: the record was never archived after the actor check
not ok - secondmate-merge-away: --allow-red should stay attended-only under the parent's record: expected exit 2, got 1
Evidence: CLI transcript: secondmate PR merge while the parent is away, base vs HEAD (fake gh)

Source: CLI transcript: secondmate PR merge while the parent is away, base vs HEAD (fake gh)

===== BASE 9664eed7 =====
$ fm-pr-merge.sh --secondmate mate-x task-x1 https://github.com/example/repo/pull/74 --allow-red ci   # parent home away
error: a secondmate's PR merge is refused while this home's away record exists: the secondmate's home cannot see that record and would merge as attended; nothing was merged
exit=1
$ fm-pr-merge.sh --secondmate mate-x task-x1 https://github.com/example/repo/pull/74   # parent home away
error: a secondmate's PR merge is refused while this home's away record exists: the secondmate's home cannot see that record and would merge as attended; nothing was merged
exit=1
-- forge merge calls:
(none)
-- owning home merge-authority record:
(none)
-- parent status from mate-x:
(none)

===== HEAD 255515ac =====
$ fm-pr-merge.sh --secondmate mate-x task-x1 https://github.com/example/repo/pull/74 --allow-red ci   # parent home away
error: --allow-red is attended-only; while the away-posture record exists the green check is absolute
exit=2
$ fm-pr-merge.sh --secondmate mate-x task-x1 https://github.com/example/repo/pull/74   # parent home away
armed: state/task-x1.check.sh
verified: https://github.com/example/repo/pull/74 is open and mergeable, with every unwaived required check reported and every unwaived check green at head 7474747474747474747474747474747474747474
verified: https://github.com/example/repo/pull/74 is merged (state=MERGED, merged=true, isInMergeQueue=false)
exit=0
-- forge merge calls:
pr merge 74 --repo example/repo --match-head-commit 7474747474747474747474747474747474747474 --squash
-- owning home merge-authority record:
fm-merge-authority-v1
github
github.com
example/repo
74
away
-- parent status from mate-x:
done [key=child-pr-task-x1] [at=1792135016]: child task-x1 PR ready: https://github.com/example/repo/pull/74 mode=no-mistakes
done [key=merged-task-x1] [at=1792135017]: merged task-x1 https://github.com/example/repo/pull/74 away
- Outcome: ⚠️ 1 warning across 1 run (2m54s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • ⚠️ bin/fm-pr-merge.sh:257 - The local --secondmate route can let the supervision branch trigger an attended merge. It checks the actor with fm_lease_forbid_branch --away-relocated at line 213, which passes because the away record exists. It then reads the posture again in routed_away_authority without holding the record lock. If the captain returns and the record is archived between those two reads, ROUTED_AWAY_ARGS comes back empty. The script then execs the owning home with env -u FM_SUPERVISION_ACTOR and no --parent-away-authority, so the owning home runs an ordinary attended merge where --allow-red/--allow-missing are accepted, even though the branch must never do that. The main-home path closes this gap by repeating the actor check under the away-record lock (require_current_away_authority), and the remote route here does the same at lines 238-244. The local route has neither protection, and stripping the actor means the owning home cannot catch it either. Smallest fix: on the local route, refuse when the caller is the branch actor (fm_lease_actor = branch) and ROUTED_AWAY_ARGS is empty. With the flag, the owning home already checks the parent's live record under its lock and refuses if the record has lapsed, so this fails closed.

🔧 Fix applied.
✅ Re-checked - no issues remain.

⚠️ **Test** - 1 warning
  • ⚠️ live validation verdict: inconclusive (0 of 8 scenarios were driven live against the product); untested: Captain away, parent runs fm-pr-merge.sh --secondmate mate-x task-x1 &lt;green PR&gt;: the merge lands through the owning home, which records away authority and reports 'merged ... away' upward, While the parent is away, a routed merge with --allow-red, --allow-missing, or --auto is refused as attended-only and never reaches the forge, The captain's return (archiving the record) during the owning home's forge call is blocked by the parent's record lock, Adversarial: the away record is archived after the supervision branch's actor check but before routing; the branch is refused (exit 6) and no forge merge runs, Adversarial: --parent-away-authority with no parent away record, a record that lapses mid-preflight, no parent binding, or a re-route is refused with no forge merge, Remote secondmate: the parent holds its record lock across the ssh call and passes --parent-away-authority; the remote home applies the away rules, Attended (no away record) supervision branch is still refused a secondmate route; other owning-home guards are unchanged, Real GitHub PR built by a secondmate child merges during real away mode
  • Live validation: ⚠️ inconclusive - 0 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Captain away, parent runs fm-pr-merge.sh --secondmate mate-x task-x1 &lt;green PR&gt;: the merge lands through the owning home, which records away authority and reports 'merged ... away' upward ⏸️ untested no The earlier payload ran this only against a fake gh (test_secondmate_merge_carries_the_parent_away_authority and the CLI transcript), so no live result was established. A live run needs a disposable G…
While the parent is away, a routed merge with --allow-red, --allow-missing, or --auto is refused as attended-only and never reaches the forge ⏸️ untested no The earlier payload checked this only against a fake gh forge, so no live result was established. A live run needs a real GitHub repo/PR and gh credentials.
The captain's return (archiving the record) during the owning home's forge call is blocked by the parent's record lock ⏸️ untested no The earlier payload injected the race at a fake gh merge call, so no live result was established. A live run needs a real forge merge during real away mode.
Adversarial: the away record is archived after the supervision branch's actor check but before routing; the branch is refused (exit 6) and no forge merge runs ⏸️ untested no The earlier payload injected the race through a wrapped fm-afk-contract.sh against a fake gh forge, so no live result was established.
Adversarial: --parent-away-authority with no parent away record, a record that lapses mid-preflight, no parent binding, or a re-route is refused with no forge merge ⏸️ untested no The earlier payload checked this only against a fake gh forge (test_owning_home_refuses_an_unbacked_parent_away_claim), so no live result was established.
Remote secondmate: the parent holds its record lock across the ssh call and passes --parent-away-authority; the remote home applies the away rules ⏸️ untested no The earlier payload used a fake ssh and a fake gh, so no live result was established. A live run needs a reachable remote secondmate host and a real forge.
Attended (no away record) supervision branch is still refused a secondmate route; other owning-home guards are unchanged ⏸️ untested no The earlier payload checked this only against a fake gh forge, so no live result was established.
Real GitHub PR built by a secondmate child merges during real away mode ⏸️ untested no This needs a disposable GitHub repo with a real green PR, gh credentials, and the captain's approval for an outward-facing merge. None of these were available in this gate run. Provide a throwaway rep…
  • Ran the 8 secondmate-merge test functions from tests/fm-pr-merge.test.sh under stock /bin/bash 3.2, sourcing the file without its top-level test calls: test_parent_merges_a_secondmate_child_pr_through_the_owning_home, test_secondmate_merge_keeps_the_owning_home_guards, test_secondmate_merge_refuses_what_the_parent_cannot_route, test_secondmate_merge_carries_the_parent_away_authority, test_secondmate_route_refuses_the_branch_when_the_record_lapses, test_owning_home_refuses_an_unbacked_parent_away_claim, test_remote_secondmate_merge_carries_the_parent_away_authority, test_remote_secondmate_merge_runs_in_the_owning_home. All 8 passed, with a fake gh and a fake ssh.
  • Before/after regression check: ran the HEAD tests against bin/fm-pr-merge.sh from 9664eed7 (base) and from 176a7889 (before the review fix), each in its own git-archive export.
  • CLI transcript of fm-pr-merge.sh --secondmate mate-x task-x1 &lt;url&gt;, with and without --allow-red ci, run from a parent home with an active away record, at base and at HEAD, against a fake gh.
✅ **Document** - passed

✅ No issues found.

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

✅ No issues found.

While the away-posture record exists, fm-pr-merge.sh --secondmate refused
every merge because the owning home cannot see the parent's record and
would merge as attended. A green child PR therefore could not be merged
during away mode, by main or by the supervision branch.

The parent now passes its away authority explicitly as a leading
--parent-away-authority, and the owning home's own guarded merge applies
the away rules: synchronous only, no red merge, --allow-red and
--allow-missing refused, no unprovable merge queue, and away recorded as
the merge authority. A local owning home proves the claim against its
bound parent's live record and holds that record's lock across the forge
call, so a lapsed or absent parent record refuses the merge; a home with
no parent binding refuses the flag. A remote owning home cannot reach the
record, so the parent holds its record lock across the synchronous
transport call and reads the posture under it. The supervision branch may
route the merge exactly when it may merge a main-home PR, and the owning
home no longer inherits the parent's supervision actor.
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