Skip to content

fix(bin): durably report merged pull requests - #3104

Merged
kunchenguid merged 13 commits into
mainfrom
fm/fm-eddies-fix-eddie-radio-silence-fixes-durable-self-m-86
Aug 26, 2026
Merged

kunchenguid merged 13 commits into
mainfrom
fm/fm-eddies-fix-eddie-radio-silence-fixes-durable-self-m-86

Conversation

@kunchenguid

Copy link
Copy Markdown
Owner

Intent

Close the merge-silence hole in Firstmate in ONE PR: a merge that lands must leave a durable, captain-facing outcome instead of living only in an agent's memory.

Confirmed root cause from the diagnosis report: a self-performed merge via bin/fm-pr-merge.sh emitted no durable record anywhere, and under a project merging with standing authority there is no merge poll confirmation either, so three real merges reached the captain as total silence.

Accepted scope, all of it required:

  1. A self-performed merge emits ONE durable outcome. After a SUCCESSFUL merge only (so a refused or failed merge records nothing), on both the GitHub and GitLab paths. In a secondmate home (.fm-secondmate-home present) append-once to the parent reply channel in the exact shape report_to_parent() already uses in bin/fm-inactive-reconcile.sh, e.g. 'done [key=merged-]: merged '. In a main home append a durable check wake through fm_wake_append naming the merged PR. Deliberate constraints from the captain: reuse the existing append-once helper shape and the existing armed reply channel, add NO new state file and NO new transport, and keep it roughly the size of report_to_parent().

  2. Fold in the captain-GitHub-UI merge ONLY if the same outcome path covers it. The captain was explicit: 'Do not invent a second watch path if one outcome/report path covers both.' It DID fit: the existing merge poll's 'merged' confirmation in bin/fm-watch.sh now feeds the very same emitter, so a merge this home performed and a merge the captain performed on the forge produce one consistent durably-recorded outcome. No new subsystem and no second watch path were added. In a main home the merge poll's own durable row already is the captain's record, so the shared emitter is a deliberate no-op there to avoid double-reporting; the real gap it closes is the secondmate home, where the poll's row never travelled up to the parent. That main-vs-secondmate asymmetry is intentional, not an oversight.

  3. Name the missing trigger in the mate charter (bin/fm-brief.sh). The charter listed report triggers as 'material phase changes, a captain decision, a real blocker, a failure, or work ready for review'. Under a project shipping with standing merge authority, work is never 'ready for review' because it is already merged, so the list silently omitted the case that matters. 'work you landed' is now in the list, spelled out as a merge the mate performed itself and one the captain merged on the forge, so the contract the mate re-reads every turn agrees with AGENTS.md.

  4. Optional hardening the captain permitted if clean and low-risk: bin/fm-inactive-reconcile.sh degraded a failed parent report into a notice that never named the cause. When the parent binding is missing or unparseable it now names .fm-secondmate-parent in the actionable diagnostic. Kept because it stayed small; it was to be dropped rather than expanded if it grew.

Design decisions a reviewer reading only the diff would not know:

  • The new bin/fm-merge-outcome-lib.sh is deliberately a NEW small library rather than functions added to bin/fm-pr-lib.sh, because fm-pr-lib.sh is dependency-light and widely sourced, and this needs fm-wake-lib.sh and fm-secondmate-parent-lib.sh.
  • At-most-once is achieved by reusing the EXISTING canonical merge-notification marker owned by bin/fm-pr-lib.sh (fm_pr_poll_merge_already_notified / fm_pr_poll_merge_mark_notified) rather than inventing a new dedupe record. A self-performed merge claims that marker, so the later poll detection of the same merge is absorbed and retired instead of reported twice. The poll path's caller keeps owning that marker for the merge it detected.
  • The explicit parameter (self vs poll) is intentional and is what lets one function serve both callers without double-enqueuing a main-home row.
  • fm_wake_append's globals are contained with the local-declaration-then-source pattern already established in bin/fm-pending-reply-lib.sh.
  • A merge that landed but whose record could not be written prints an actionable line to stderr and still exits 0, because the merge really did land; reporting it as a failed merge would be worse.
  • One existing test in tests/fm-pr-check-security.test.sh was updated rather than left alone: a self-merge now enqueues its own durable outcome, so that test acknowledges the record and adds a stop-cycle check before asserting the poll retires. That is the new intended behavior, not a workaround.

Explicitly OUT OF SCOPE and untouched, by captain instruction: backfilling .fm-secondmate-parent into other homes (that is a write into another home and belongs to the main firstmate), the Bearings projection gate in bin/fm-fleet-snapshot.sh, and the board-close / heartbeat supervision-routing change (a different ship handled by another worker).

Known adjacent gap deliberately NOT built and flagged instead: an approved local-only landing via bin/fm-merge-local.sh has the same silence shape, but it has no PR URL to name, so covering it needs a different outcome shape rather than this same call. Left as follow-up for the captain to decide.

This is Firstmate's own shared tracked material, so firstmate-coding-guidelines applies: one sentence per line in tracked Markdown, plain dash never an em dash, no agent co-author, shellcheck-clean bin scripts, colocated tests named .test.sh extending existing runners, and tests that exercise executable interfaces rather than asserting implementation source text. The change touches no harness-dependent or vendor-rendered surface, so the per-harness live verification axis is not applicable.

Delivery: no-mistakes pipeline, merge authority stays with the captain. Report the PR URL when CI is green.

What Changed

  • Publish confirmed GitHub and GitLab merge outcomes through one deduplicated, role-aware path for self-performed and poll-detected merges.
  • Route secondmate outcomes to the parent reply channel and main-home outcomes to the durable wake queue without recording failed, refused, queued, or unconfirmed merges.
  • Update the mate charter to require reporting landed work and make missing secondmate parent bindings actionable.

Risk Assessment

✅ Low: The change consistently routes confirmed merges through one locked durable publication boundary, preserves retry behavior, and introduces no substantiated new material defect.

Testing

Inspected the merge-outcome diff, ran the focused merge, watcher-security, charter, and inactive-reconciliation tests, and demonstrated the real merge entrypoint end-to-end for both home roles; durable captain-facing records and canonical markers were produced as intended, with no failures or residual worktree artifacts.

Evidence: End-to-end durable merge outcome transcript

Source: End-to-end durable merge outcome transcript

END-TO-END DURABLE MERGE OUTCOME DEMO

$ fm-pr-merge.sh task-main https://github.com/acme/demo/pull/42  # main home
exit: 0
forge calls:
pr merge 42 --repo acme/demo --squash
pr view 42 --repo acme/demo
captain-facing durable wake:
1	check	merged-task-main-https://github.com/acme/demo/pull/42	check: merge landed: task-main https://github.com/acme/demo/pull/42
canonical notification marker:
fm-pr-poll-merge-notified-v1
github
github.com
acme/demo
42

$ fm-pr-merge.sh task-mate https://github.com/acme/demo/pull/43  # secondmate home
exit: 0
forge calls:
pr merge 43 --repo acme/demo --squash
pr view 43 --repo acme/demo
durable parent reply:
done [key=merged-task-mate]: merged task-mate https://github.com/acme/demo/pull/43
canonical notification marker:
fm-pr-poll-merge-notified-v1
github
github.com
acme/demo
43
- Outcome: 🔧 1 issue found → auto-fixed ✅ across 2 runs (18m40s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

🔧 **Test** - 1 issue found → auto-fixed ✅
  • ⚠️ tests/fm-pr-check-security.test.sh:3208 - The self-merge/poll concurrency test intermittently exited with an empty watcher error once. The same test subsequently passed repeatedly, indicating timing-related test flakiness rather than a reproducible product failure.
  • bash tests/fm-pr-merge.test.sh
  • bash tests/fm-brief.test.sh
  • bash tests/fm-inactive-reconcile.test.sh
  • bash tests/fm-pr-check-security.test.sh (merge-related cases passed before the broader script exceeded the 300-second limit)
  • Focused execution of test_merged_poll_retries_a_failed_upward_report, test_self_merge_and_poll_publish_one_outcome, test_merged_poll_reports_upward_from_a_secondmate_home_once, test_different_merged_pr_for_same_task_is_not_absorbed, and test_retirement_crash_recovery
  • Repeated test_self_merge_and_poll_publish_one_outcome alone and after its preceding retry test to assess the intermittent failure
  • Executed bin/fm-pr-merge.sh task-x1 <pr-url> in isolated secondmate fixtures for confirmed and queued GitHub merge states, then inspected the parent reply channel, canonical marker, and armed poll

🔧 Fix: Make merge outcome interleaving test deterministic
✅ Re-checked - no issues remain.

  • git diff --stat 07bf0c8556c70b5241516efad0e51f802484c748..e35aa356d242fa5a759217ffc93667ff24a5f62a and targeted source/test inspection
  • bash tests/fm-pr-merge.test.sh
  • bash tests/fm-pr-check-security.test.sh
  • bash tests/fm-brief.test.sh
  • bash tests/fm-inactive-reconcile.test.sh
  • Executed bin/fm-pr-merge.sh with mocked successful GitHub merges in main-home and secondmate-home sandboxes, then captured the durable wake, exact parent reply, and canonical notification markers
  • git status --short confirmed testing left the worktree clean
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

A merge was the one lifecycle event that left no record outside the
merging agent's memory. bin/fm-pr-merge.sh ended at the forge call, and a
home merging under standing authority never waits for the merge poll that
would otherwise confirm it, so three real merges reached the captain as
silence.

bin/fm-merge-outcome-lib.sh is the single owner of that record. A
secondmate home reports the landed PR upward on the same parent reply
channel its terminal-outcome backstop already uses; a main home records
it on the durable wake queue. The record is at most once per task and
canonical PR identity, and only a merge that actually landed produces one.

The merge poll feeds that same channel when it detects a merge this home
did not perform, so the captain's own forge merge and a merge firstmate
performed itself produce one consistent outcome instead of two reporting
paths. No new state file and no second watch path.

Two smaller gaps from the same failure:

- A mate charter listed its report triggers without naming a landed
  merge. Under standing merge authority nothing is ever "ready for
  review", so the enumerated list silently omitted the case that matters.
- A secondmate home seeded without its parent binding failed every
  terminal-outcome report for the same reason, and the diagnostic never
  named the binding. It does now.
@greptile-apps

greptile-apps Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Confidence Score: 4/5

The PR is not yet safe to merge because poll-detected merges can still be delivered more than once.

The shared emitter durably queues a poll-detected merge, after which the watcher independently wakes immediately, appends another durable check row for the same result, and wakes again.

Files Needing Attention: bin/fm-watch.sh, bin/fm-merge-outcome-lib.sh

Reviews (2): Last reviewed commit: "fix(lint): keep the merge-outcome librar..." | Re-trigger Greptile

Comment thread bin/fm-watch.sh Resolved
bin/fm-watch.sh followed the new merge-outcome library's source graph,
which reaches the wake queue, PR identity, and secondmate parent
libraries. Expanding that inside an already-large lint root pushed
ShellCheck's external-source analysis past the bounded CI lint worker:
the Lint job was killed with SIGTERM after five silent minutes, twice,
having emitted no diagnostics at all.

Make it an analysis boundary, exactly as the transition and inbox owners
directly above and below it already are and for the same stated reason.
Coverage is unchanged because the library is a canonical lint root in its
own right and is still linted as one.

Measured locally: the watcher goes from not terminating within 120s to
9s clean, and the library alone lints in 1s clean.
@kunchenguid
kunchenguid merged commit 662a8c7 into main Aug 26, 2026
23 of 26 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-eddies-fix-eddie-radio-silence-fixes-durable-self-m-86 branch August 26, 2026 20:13
akrcdev added a commit to akrcdev/firstmate that referenced this pull request Aug 29, 2026