Skip to content

fix(pi): prevent duplicate captain outcome reports - #3184

Merged
kunchenguid merged 7 commits into
mainfrom
fm/fm-envelope-modify-m1m2-r1
Aug 27, 2026
Merged

kunchenguid merged 7 commits into
mainfrom
fm/fm-envelope-modify-m1m2-r1

Conversation

@kunchenguid

@kunchenguid kunchenguid commented Aug 27, 2026 •

Copy link
Copy Markdown
Owner

Intent

Simplify PR #3184 (branch fm/fm-envelope-modify-m1m2-r1) down to M1 ONLY, on the captain's explicit instruction that the previous version of this PR was overly complicated. Judge this branch by its NET DIFF AGAINST MAIN, which is now 3 files and 27 inserted lines.

BACKGROUND. PR #3154 fixed a real silent-loss bug. The supervision branch's captain-facing outcome note is handed to Pi's model as the note's own text, so without self-description main could mistake an incoming supervision outcome for its own earlier answer and re-emit that stale answer while the outcome was silently lost. #3154 fixed that by making the note typed and self-describing. That protection MUST be preserved untouched; this change does not revert it.

THE DEFECT THIS FIXES (M1). The envelope #3154 introduced carried an UNCONDITIONAL order: "it is not your own earlier output" plus "Relay only this outcome to the captain now". That assertion is false whenever main was separately woken for the same event on its own row, because main firstmate and the supervision branch can each be independently notified of one merge. The unconditional order therefore turned the correct response (saying nothing new) into a mechanical re-report, and the captain saw one outcome reported twice.

THE FIX. Make the relay order CONDITIONAL in .pi/extensions/fm-branch-supervision.ts's CAPTAIN_OUTCOME_INSTRUCTION. Keep the self-description ("a supervision outcome delivered automatically by the supervision branch", "not typed by the captain"), then state that if main has already reported this outcome to the captain earlier in this conversation it must NOT report it again, and OTHERWISE relay only this outcome now, in one short message, in captain outcome language, without restating any earlier answer. This deliberate wording change to a natural-language instruction delivered to a model is the entire product change.

DELIBERATE DECISIONS BY THE CAPTAIN - do not flag these as omissions or regressions:

  • An earlier version of this branch also shipped "M2": suppression of the duplicate merge report at its source in mergeIntoMain, backed by a new bin/fm-pr-merge-notified.sh reading bin/fm-pr-lib.sh's pr-poll-merge-notified marker, plus its tests and docs, including documentation of an accepted latest-marker residual. The captain reviewed that and judged it OVERLY COMPLICATED, and explicitly instructed that ALL M2 machinery be removed and only M1 kept. The final commit on this branch is that removal. The absence of source-level duplicate suppression, of fm-pr-merge-notified.sh, and of a duplicate-suppression regression test is the captain's decision, not an oversight, and re-adding any of it would violate the instruction.
  • The branch keeps its earlier commits, including this pipeline's own earlier fix commits, and removes the superseded M2 material in a commit on top rather than by rewriting history, so no prior gate-fix commit is dropped. Judge the net effect, not the intermediate commits: the M2 code and docs those earlier commits touched are intentionally gone from the final tree.
  • Coverage was deliberately held to the SMALLEST behavior-level coverage that proves the softened wording still preserves genuinely new outcomes. The existing behavioral tests in tests/fm-pi-branch-extension.test.sh already drive the real delivery path, executing the extension's fm_branch_report tool and inspecting what is actually handed to Pi, and assert that a captain outcome is still delivered as exactly one invisible follow-up turn carrying the typed branch-outcome envelope and the outcome text. Those assertions were strengthened to require BOTH halves of the new conditional instruction, so the silent-loss property cannot regress unnoticed. The M2-specific duplicate-suppression regression was dropped per the captain. A mutation check was run: reverting the constant to the old unconditional wording makes the suite fail.
  • Test assertions match on the DELIVERED note text, which is the runtime output handed to Pi's model, not on implementation source bytes. That string is the intentional generated interface being changed, and this follows the pattern already established in this suite on main.
  • docs/pi-supervision-branch.md is the single owner of branch-outcome delivery, so exactly two sentences were added there recording that the relay instruction is now conditional and why. No other document was touched, per the one-owner rule in the firstmate-coding-guidelines skill. Reintroducing notes in docs/architecture.md, docs/configuration.md, docs/scripts.md, or docs/supervision-protocols/pi.md would duplicate that owner.

VERIFICATION ALREADY RUN LOCALLY on this exact tree: tests/fm-pi-branch-extension.test.sh passes with exit 0, bin/fm-lint.sh passes, bin/fm-doc-audience-check.sh passes.

DELIVERY CONSTRAINT: this must land on the SAME existing PR #3184. Merge authority stays with the captain - do NOT merge. Stop at checks green.

What Changed

  • Make captain-outcome relay instructions conditional so main does not repeat an outcome it already reported.
  • Preserve self-describing outcome delivery and document the conditional relay behavior.
  • Strengthen delivery-path tests for both duplicate avoidance and relay of new outcomes.

Risk Assessment

✅ Low: The change is narrowly scoped to conditional model-facing wording, preserves the typed self-describing envelope and new-outcome relay path, and conforms to the explicit M1-only intent.

Testing

Independently exercised the real fm_branch_report delivery path, typed-envelope decoding, conditional duplicate instruction, new-outcome relay instruction, and plain-text encoder fallback; targeted tests passed and runtime evidence confirms the exact hidden note delivered to Pi's model. The author-reported lint and documentation checks were not repeated because this phase prohibits static-analysis tools. No screenshot was appropriate because this surface is intentionally invisible model input rather than rendered UI.

Evidence: Runtime-delivered captain outcome envelope and model-facing body

Source: Runtime-delivered captain outcome envelope and model-facing body

End-to-end captain outcome delivery through fm_branch_report -> main follow-up
Operational input kind: branch-outcome
Delivered body read by Pi's model:
$'This is a supervision outcome delivered automatically by the supervision branch. It was not typed by the captain. If you have already reported this outcome to the captain earlier in this conversation, do not report it again. Otherwise relay only this outcome to the captain now, in one short message, in captain outcome language. Do not restate or repeat any earlier answer.\n\ntask-9: PR https://example.com/pr/9 checks green, ready for review'

Targeted test exit: 0

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ No issues found.

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Targeted test_branch_dispatch_two_stage_filter_and_prefix_contract from tests/fm-pi-branch-extension.test.sh
  • Targeted test_captain_outcome_encoding_failure_delivers_plain_instruction from tests/fm-pi-branch-extension.test.sh
  • Mutation check using the base commit's unconditional instruction; the strengthened behavior test failed as expected
  • Inspected the net diff and confirmed the M2 helper is absent from the final tree

✅ No issues found.

  • Inspected git diff 7ee0c192e9d664b022361bd4609303bebfc7de14..120f43b94001c1aaa8acb9cbe2022a11044a90cf and confirmed the net change is 3 files with 27 insertions and no M2 helper.
  • Ran bash tests/fm-pi-branch-extension.test.sh, exercising the real fm_branch_report delivery path, typed envelope decoding, conditional relay wording, single invisible follow-up delivery, routine delivery, and plain-text encoder fallback.
  • Verified bin/fm-pr-merge-notified.sh is absent and git status --short is clean.
  • Inspected the captured provider-facing captain-outcome artifact and its mutation-check evidence.

✅ No issues found.

  • bash tests/fm-pi-branch-extension.test.sh
  • bash -x tests/fm-pi-branch-extension.test.sh with extraction of the runtime-delivered operational kind and model-facing body into evidence
✅ **Document** - passed

✅ No issues found.

✅ No issues found.

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ No issues found.

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

✅ No issues found.

✅ No issues found.

The supervision branch's captain-outcome note told main, unconditionally,
that the note "is not your own earlier output" and to relay it now. When
main had already reported the same event, that assertion was false and the
order turned the correct response - saying nothing new - into a mechanical
re-report, so the captain saw one merge reported twice in 16 seconds.

Two independent changes, both needed:

- The relay instruction is now conditional. It still names itself as a
  supervision outcome so main cannot mistake it for its own earlier answer
  (the silent loss that instruction exists to prevent), and it now lets
  main stay quiet about an outcome it has already given the captain.

- The merge case is closed at its source rather than left to that judgment.
  One merge reaches a home on two independent paths by design - main's own
  permanently main-owned merge poll, and the branch's task-local status
  wake - and main's captain-facing text only reaches the branch's mirror at
  main's turn end, so the branch can escalate before it could possibly see
  the captain was already told. bin/fm-pr-merge-notified.sh answers that
  question from bin/fm-pr-lib.sh's canonical merge-notification marker, so
  the answer holds regardless of mirror timing. A captain outcome naming an
  already-published merge is delivered as the ordinary rendered note
  instead of opening a follow-up turn: still appended, still visible, still
  recorded with the verdict the branch decided, minus the wasted turn.

Any error, timeout, or unreadable state relays the outcome. A duplicate
announces itself; a lost outcome does not.

Regression coverage drives the real delivery path in both directions: a new
outcome must still reach the captain in exactly one follow-up turn even
beside an unrelated published merge, and an already-published merge must
open no second turn while a different PR in the same task still does. The
merge path's real producer and this new consumer are exercised end to end
in tests/fm-pr-merge.test.sh.

Pi-only by construction: the delivery path lives in .pi/extensions, so no
other harness loads it, and the new script only reads existing markers.
@greptile-apps

greptile-apps Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (4): Last reviewed commit: "no-mistakes(ci): Strengthened the runtim..." | Re-trigger Greptile

…ope fix

The captain reviewed this branch and judged the source-level duplicate
suppression overly complicated for the problem it solved, and asked for
the change to be reduced to the envelope wording alone.

Remove the mergeIntoMain downgrade path, bin/fm-pr-merge-notified.sh, and
every test and document that existed only for it. What remains is the
conditional captain-outcome instruction: main is told to stay quiet about
an outcome it has already reported and to relay anything else, which
covers the duplicate without a second mechanism.

The silent-loss protection is untouched - the note is still typed,
self-describing, and delivered as one invisible follow-up turn - and the
behavioral tests still assert that, now requiring both halves of the
conditional instruction.
@kunchenguid kunchenguid changed the title fix(pi): deduplicate already-reported supervision outcomes fix(pi): avoid duplicate supervision outcome reports Aug 27, 2026
Comment on lines +145 to +146
"If you have already reported this outcome to the captain earlier in this conversation, do not report it again. " +
"Otherwise relay only this outcome to the captain now, in one short message, in captain outcome language. " +

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Source deduplication is absent

When main has already reported a merge through its merge poll, mergeIntoMain still opens a follow-up turn for the matching captain verdict and relies only on this instruction for silence, causing the spurious model turn that source-level identity suppression is required to eliminate.

…hat this is intentionally an M1-only, model-facing conditional relay fix—not source-level suppression—addressing Greptile’s mistaken scope expectation without changing runtime behavior. Net diff remains 3 files and 27 insertions. Verified with fm-pi-branch-extension tests, fm-lint, doc audience check, and git diff --check; all passed
… captain outcome retains its required self-description and outcome text. Verified with `bash tests/fm-pi-branch-extension.test.sh`, `bin/fm-lint.sh`, `bin/fm-doc-audience-check.sh`, and `git diff --check`; all passed. The outer pipeline can now commit and attest the new head
@kunchenguid kunchenguid changed the title fix(pi): avoid duplicate supervision outcome reports fix(pi): prevent duplicate captain outcome reports Aug 27, 2026
@kunchenguid
kunchenguid merged commit 4f89f5b into main Aug 27, 2026
14 of 15 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-envelope-modify-m1m2-r1 branch August 27, 2026 20:12
prandelicious added a commit to prandelicious/firstmate that referenced this pull request Aug 29, 2026