Repository navigation
fix(bin): collect follow-up results from remote work homes - #3503
Merged
Merged
Conversation
A public commitment whose work is bound to a REMOTE secondmate home could never receive its typed terminal result. `fm-public-followup.sh brief` printed an emit command carrying this home's own absolute path and this checkout's own script path, neither of which exists on the machine the worker runs on, so the worker had nothing it could write to that the owning home would ever read - and `consume` kept finding nothing while the promise stayed open. The brief is now route-aware: for a remote work home it prints that route's own code root and home with `--stage-in`, so the typed event is staged in the home where the work actually runs, and the closing paragraph names the owning home as the one on the other machine instead of pointing at the path above it. The owning home collects those staged results over the same SSH route it reaches that secondmate on, because the transport only runs outbound: `consume` pulls them into its own inbox and reconciles them exactly as it reconciles a local report. Collection is non-destructive until the result is durably held, so a dropped connection cannot lose a terminal result, and a route that could not be reached is named in `consume`'s output with the promise left open rather than reported as an empty inbox. A local work home is untouched: the brief still prints `--home` with this home and this checkout's script, and the event still lands directly in this home's typed terminal-result inbox. This is the emit-side counterpart of the retire/clear fix in #3479 and reuses the remote-route resolution that landed with it. Reconciling a loop bound to a remote route now reaches that route, so the existing remote cases drive `consume` through the same faked transport their other steps already use.
Confidence Score: 5/5The PR appears safe to merge, with no concrete blocking or independently actionable non-blocking defect identified. The changed flow validates remote staging homes, retains remote copies until local durable publication, reports route failures, and feeds collected events through the existing authoritative reconciliation and duplicate-suppression path. Reviews (1): Last reviewed commit: "no-mistakes(document): Document remote f..." | Re-trigger Greptile |
Marcos-Leyva
added a commit
to Marcos-Leyva/firstmate
that referenced
this pull request
Sep 3, 2026
) * fix: surface inbound Relay media to responding agents (kunchenguid#3442) * fix: surface inbound Relay attachments to the responding agent A Discord support thread's screenshots were never seen by the agent handling the mention. The relay delivered them and the poll stashed them: the reporter's images arrived on the `thread_starter` entry of `in_reply_to_chain` while the mention's own media list was empty. The gap was in the responder's playbook, which enumerated a fixed field list (`request_id`, `text`, `in_reply_to`, `in_reply_to_chain`) and so made every other field, attachments included, invisible. Fix it where the gap is, in prose: - Read the complete payload object rather than a fixed field list, so media and later relay fields are never skipped again. - Fetch and view attached media with the agent's own tools, on the mention and on every chain entry, and call out the common shape where only the thread starter carries the screenshots. - Restrict those fetches to known-good platform media hosts over https (Discord: cdn.discordapp.com, media.discordapp.net, images-ext-1.discordapp.net, images-ext-2.discordapp.net; X: pbs.twimg.com, video.twimg.com), report a blocked host instead of working around it, and treat everything fetched as untrusted public input on the same terms as the surrounding thread text. The poll stays out of it and downloads nothing, so no third-party bytes are pulled on the polling path. The new test pins the contract the playbook depends on: a mention in the incident's shape, with an empty top-level media list and screenshots on the thread starter, must reach the inbox with the payload intact and its media URLs unfetched. * no-mistakes(review): Preserve media authority and enforce poll-only fetching * no-mistakes(document): Clarify Relay attachment safety prose * fix(bin): defer inactive reconciliation during startup (kunchenguid#3480) * Defer inactive startup reconciliation * no-mistakes(review): Queue deferred inactive reconciliation diagnostics durably * no-mistakes(review): Require worker phases to cover startup requests * no-mistakes(review): Make diagnostic wakes safely acknowledgeable * no-mistakes(document): Document deferred startup phase coverage * fix(bin): bound wake drain presentation lock waits (kunchenguid#3475) * fix: bound status presentation lock waits * no-mistakes(review): Distinguish malformed presentation locks from live contention * no-mistakes(review): Bound no-ack drain queue lock acquisition * no-mistakes(document): Document bounded presentation-lock drain behavior * no-mistakes(lint): Annotate bounded lock output global * no-mistakes(ci): Added deterministic regression coverage for successful bounded-lock acquisition after live contention, verifying helper-to-caller PID ownership handoff and caller release. Verified with bash syntax checks, git diff checks, and the full fm-wake-queue test suite * fix(bin): retire public follow-ups in remote homes (kunchenguid#3479) * fix(relay): close a public loop whose work lives in a remote secondmate home A public-followup loop bound to a REMOTE secondmate could never be closed. `clear_public_followup_link` (bin/fm-public-followup.sh:701) required an absolute recorded `work_home_path` for a `secondmate:*` work home, but a remote route has no local path on this machine, so registration records that field empty (bin/fm-public-followup.sh:291). Every close ran that clear first, so `retire` died with "could not clear the legacy X link ... retained for reconciliation" forever, and `deliver` posted the public reply and then stranded the loop at `posted`. `--force` never covered that step. The clear now goes to the remote home over that route's SSH transport, running `fm-x-followup.sh --clear <work-id>` through `bin/fm-on.sh`. The route is decided from `data/secondmates.md` before any local path is consulted, so a same-named local directory can never stand in for a remote home, and registrations already on disk retire without needing a new field. `fm-on.sh` passes ssh's status through, so 255 stays the established "delivered but completion unknown" result this codebase already reconciles: the close is refused, the registration and the remote link are left exactly as they were, and the message names the unknown completion instead of claiming a definite failure. Local secondmate and `main` work homes are untouched, and `--force` still governs only the unresolved-obligation refusal. Three regression cases drive a remote route end to end, faking only the ssh binary at the FM_SSH_BIN seam and then running the real remote entrypoint against a local checkout, so the clear that must reach the remote home actually happens there. * no-mistakes(review): Guard remote link clears by request identity * no-mistakes(review): Fail guarded clears on unreadable remote state * no-mistakes(review): Reject guarded clears on non-writable remote state * no-mistakes(review): Allow no-link retirement in non-writable remote state * no-mistakes(document): Correct public-followup verification guarantee count * no-mistakes(ci): Fixed the guarded link-clear race by ensuring absence is decided under the metadata lock whenever publication is possible. Added a behavioral concurrency regression test. Verified with fm-x-mode and fm-public-followup suites, Bash syntax checks, diff checks, and bin/fm-lint.sh * no-mistakes(ci): Fixed the guarded link-clear race by refusing an unlocked absence decision when a publisher already owns the metadata lock in a non-writable directory. Added a behavioral concurrency regression test. Verified with fm-x-mode, fm-public-followup, syntax/diff checks, and fm-lint * no-mistakes(ci): Fixed the guarded-clear race by refusing all guarded clears when the metadata parent is non-writable, including apparent link absence. Added a behavioral regression with a publisher waiting to create the lock, updated remote-retirement expectations and verification docs. Passed fm-x-mode, fm-public-followup, fm-lint, documentation audience, Bash syntax, and diff checks * fix(relay): bound the guarded remote link clear so it refuses instead of hanging The guarded clear checks that the remote state directory is writable before taking the metadata lock, but that check cannot close the window: the parent can turn non-writable between the check and lock creation, and a lock held by a live holder is indistinguishable from that at the acquire. `fm_lock_acquire_wait` is an unbounded `while ! try; do sleep 0.1; done`, so either case retried forever and `deliver` or `retire` wedged with nothing reported, instead of returning the retained-for-reconciliation refusal the guard exists to produce. This path runs unattended over the secondmate transport, where a wedge is worse than either outcome the guard defines. The guarded clear now acquires through `fm_lock_acquire_wait_bounded` (FMX_LINK_CLEAR_LOCK_TIMEOUT, default 10 seconds) and refuses on timeout through the existing failure path. Unguarded local callers keep the ordinary unbounded wait, so local behavior is unchanged. The bounded primitive's header no longer claims presentation-only scope, since this is a second authorized caller; nothing else in the shared lock infrastructure changed. The regression holds the metadata lock with a genuinely live process while leaving the state directory writable, so the refusal can only come from the bound and never from the writability precondition. Against the unbounded wait it does not terminate at all; with the bound it refuses, retains the registration, writes no receipt, and leaves the remote link untouched. * no-mistakes(review): Harden lock-timeout regression with independent deadline * no-mistakes(review): Restore no-op guarded clears on read-only state * no-mistakes(document): Clarify remote public-followup cleanup contract * fix(bin): support process events under symlinked homes (
Intent
Fix a fundamental gap in firstmate's public-followup EMIT path: a worker in a REMOTE secondmate home could not deliver its typed terminal-result event to the MAIN (owning) home, so a promised public follow-up sat unresolved until firstmate hand-emitted it.
SYMPTOM (reproduced twice, 2026-09-01): fmdev-f1's actionable-update fix (#3268, merged 2026-08-29) never produced a consumable event in the main home; and sshhip-h7 ran the exact fm-public-followup-emit.sh command from its brief for pf-sshhip-purchase-screentime-hint-r1 after merging sshhip #396, yet the main home's 'consume' found nothing and 'deliver' still said the loop was waiting on its bound work.
ROOT CAUSE: 'fm-public-followup.sh brief' printed an emit command carrying '--home
' plus this checkout's own script path. When the bound work lives in a REMOTE secondmate home on ANOTHER HOST, neither path exists there (the mini's firstmate root is ~/fm-homes/firstmate, not the main home's path), so the typed event was written nowhere the main home reads, and the promise stayed open.WHAT WAS BUILT (accepted requirements, all of which must hold):
DELIBERATE DECISIONS a reviewer reading only the diff would not know:
CONSTRAINTS the user set: this edits firstmate SHARED, TRACKED material (bin/), so firstmate-coding-guidelines applies and bin/fm-timeout-lib.sh stays the single owner of bounded execution. Bash must stay bash-3.2-safe (macOS default). Tests must be behavioral and must never assert on implementation source text. Every commit carries NO co-author trailer.
What Changed
Risk Assessment
✅ Low: The change is well-bounded, preserves the local path, fails loudly on genuine remote collection failures, and the follow-up fixes align collection with open registrations only.
Testing
Inspected the change, ran the focused public-followup suite and individual remote regressions, fixed two outdated test arrangements, then demonstrated the route-aware brief, Bash 3.2 staging, successful pull collection, staged-copy retirement, and fail-loud unreachable-route behavior in a reviewer-visible CLI transcript; all final targeted checks succeeded.
Evidence: Remote public-followup end-to-end and unreachable-route CLI transcript
Source: Remote public-followup end-to-end and unreachable-route CLI transcript
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 2 issues found → auto-fixed (8) ✅
bin/fm-public-followup.sh:362- Required criterion 3 says an unreachable/refusing remote route must be named and consume must exit non-zero, while criterion 1 requires a route-aware brief. The newif ! public_followup_route_is_remote ... --homefallback conflates a local route with a missing or unreadable route. Concrete sequence: register/brief a remote obligation, stage its result, then remove or corrupt itssecondmates.mdrecord; collection skips it at line 500 andconsumeexits successfully with an empty inbox. If the record is unavailable beforebrief, lines 362-364 recreate the original bug by printing this machine's--homepath. Also, paths containing..or//pass lines 368-372 but are later refused byfm-on.sh. Use a route resolution boundary that distinguishes local, valid remote, and unresolved/invalid remote states, and fail loudly for the latter. Because this corrects explicit route behavior required by the author, the remedy needs user review.bin/fm-public-followup-emit.sh:207- Required criterion 3 says--stage-in"refuses a path that is not a firstmate home." The added check accepts any ordinary directory containing a realstate/subdirectory. For example,/tmp/unrelated/statepasses and the event is successfully written into/tmp/unrelated/state/public-followup/outbox, where the owning route will never collect it. Validate the established Firstmate/secondmate identity markers—ideally matching.fm-secondmate-hometo--source-home—rather than treatingstate/alone as proof. This contradicts an explicit acceptance requirement, so the behavioral remedy requires user review.🔧 Fix: Fail loudly on unresolved routes and invalid staging homes
2 errors still open:
bin/fm-public-followup.sh:355- Any current remote record with the same secondmate id is accepted without proving it is the route used when the obligation was registered. Concrete sequence: register and brief against remote route A, let the worker stage its result in A, then reassign that id to route B;consumedrains B, receives nothing, and exits 0 while the result remains indefinitely in A. This violates the required same-route delivery and fail-loud invariant. The earliest durable boundary is registration/route resolution: retain enough route identity to detect reassignment before briefing or collecting. Because that remedy adds durable registration state, it requires authorization.bin/fm-public-followup-collect.sh:79- An existing but unreadable or unsafe outbox is treated like an empty one. For example, ifstate/public-followup/outboxloses search/read permission, the glob yields no readable files,drainexits 0, and owningconsumereports no failure although a staged result may remain there. Distinguish an absent outbox from an existing invalid/unreadable outbox and return non-zero for the latter so the owning obligation is reported as unreached.🔧 Fix: Fail collection when remote outbox is unreadable
1 error still open:
bin/fm-public-followup.sh:355- Remote resolution trusts any current record with the same secondmate id, without proving it is the route used when the obligation was registered. If work stages its result on route A and that id is reassigned to route B before consume, collection drains B, finds nothing, exits successfully, and leaves the result stranded on A. This violates the required same-route, fail-loud delivery invariant. Persisting and checking the registered remote route identity adds durable registration state, so the remedy requires authorization.🔧 Fix: Surface reassigned remote routes during empty collection
2 errors still open:
bin/fm-public-followup.sh:559- Every reachable remote obligation still inpending-workis reported as reassigned whenever its worker has not staged a result yet. A normal sequence—register remote work, then runconsumebefore completion—now prints a false retained-result claim and exits non-zero, contradicting the command's silent-empty behavior. This heuristic also misses the claimed reassignment case whenobligation_jsonis unavailable becausedeliverybecomes empty. Distinguishing reassignment from an ordinarily empty route requires durable route identity, which the authorized fix explicitly forbids; revert this heuristic and ask the user to choose between accepting that limitation or authorizing durable identity state.bin/fm-public-followup.sh:514- A missing, unreadable, or corruptwork_homefield makes the new collector silentlycontinue. If a result is staged remotely and the owning registration becomes unreadable or loses that field,consumefinds no local event and exits 0 while the result remains stranded. Validate each registration before selecting its route and report the obligation as unreached with a non-zero result when its route-bearing registration is invalid.🔧 Fix: Fail remote collection on invalid registrations
2 errors still open:
bin/fm-public-followup.sh:566- A normal unfinished remote obligation is reported as reassigned wheneverconsumereaches its valid route before the worker stages a result: delivery ispending-work, the remote payload and local inbox are empty, so consume prints a false retained-result claim and exits non-zero. Empty output cannot distinguish ordinary pending work from reassignment without the durable route identity that was explicitly forbidden. Revert this pipeline-added heuristic and ask the user to choose between accepting the documented reassignment limitation or authorizing durable identity state.bin/fm-public-followup.sh:510- The loop skips symlinked or otherwise non-regular registration entries before the new registration validation runs. If a valid remote result is staged and its local registration is replaced by a symlink, the registration presence gate remains active, collection silently skips it, andconsumeexits 0 with the result stranded remotely. Report such named registry entries as invalid and return non-zero instead of continuing silently.🔧 Fix: Reject unsafe registration entries during remote collection
1 error still open:
bin/fm-public-followup.sh:570- A normal unfinished remote obligation is reported as reassigned wheneverconsumeruns before the worker stages a result: delivery ispending-work, the reachable route returns an empty payload, and no local event exists, so consume falsely claims a retained result and exits non-zero. Empty output cannot distinguish this ordinary state from reassignment without the durable route identity explicitly forbidden by the authorized remedy. Revert the pipeline-added empty-response heuristic and ask whether to accept the documented rare reassignment limitation or authorize route identity state.🔧 Fix: Restore healthy empty remote collection behavior
1 error still open:
bin/fm-public-followup.sh:537- Collection contacts the remote route for every retained remote registration, including obligations whose terminal event is already accepted or whose loop isstate=delivered. Concrete sequence: collect and deliver a remote result, retain the delivered registration as required, then runconsumewhile that secondmate is offline; consume falsely reports an unreached retained result and exits non-zero even though no result remains to deliver. Restrict remote collection to obligations still awaiting their terminal work event; because this changes user-visible collection semantics and may require consulting tasks-axi state, confirm the intended selection boundary.🔧 Fix: Skip remote collection for delivered registrations
1 error still open:
bin/fm-public-followup.sh:523- The required delivered-state skip occurs only after full registration validation. A retained record withstate=deliveredbut a missing or invalid relation/work field fails at line 516, printsunreached, and makesconsumenon-zero despite owing no result. This contradicts the criterion that an already-delivered registration must not produce a false unreached line. Read the existing loop state and skip delivered records before route-bearing validation; authorization is required because this is an intent-conformance finding.🔧 Fix: Skip delivered registrations before route validation
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-public-followup.test.sh— initial runs exposed stale test assumptions; final focused-suite rerun completed successfullyFM_TEST_ONLY=<remote regression> bash tests/fm-public-followup.test.shfor remote delivery, offline delivered registrations, transport failure, unreadable outbox, invalid registration, route loss, empty collection, path safety, duplicate collection, staging refusal, and unchanged local deliveryEnd-to-end hermetic CLI exercise: generated a remote brief, ran its printed--stage-incommand with macOS/bin/bash3.2, collected into the owning home, and verified ready state plus staged-copy retirementHermetic unreachable-route exercise: ran consume against a fake unreachable SSH route and verified retained-for-reconciliation output, exit 1, and pending-work stateInspected the target diff and final worktree status; removed the transient evidence driver✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.