Repository navigation
fix(captain-msg): consume alert-router-relayed inbound payloads - #44
Merged
Merged
Conversation
The Stage-7 alert-router cutover moved fm.ba.id.au off this repo's own listener, so every inbound Twilio webhook was 401'd. Teslemetry/tools PR #26 made the router relay /captain-msg verbatim into the existing inbox dir instead of validating it; this teaches the poll path to validate and normalize (or quarantine) that shape, sharing one HMAC implementation with the direct-listener path via a new fm_twilio_sig.py module.
Bre77
added a commit
that referenced
this pull request
Jul 29, 2026
…#45) * feat(provenance): label fleet PRs and drop Claude's co-author trailer The captain's commits now carry a single identity everywhere, so fleet work needs metadata-based provenance instead: an "fm" PR label (name configurable via config/pr-label) applied once fm-pr-check.sh records pr=, covering every delivery mode that opens a PR (no-mistakes, direct-PR, fork-only) from one call site, degrading to a stderr warning rather than ever losing a PR. Claude Code injects its own Co-Authored-By trailer regardless of AGENTS.md's no-agent-co-author rule; fm-spawn.sh now scopes --settings '{"attribution":{"commit":""}}' to every claude crewmate/secondmate launch, verified empirically against a real self-drafted commit. Codex and opencode were checked and do not inject an equivalent trailer in firstmate's actual launch shape; pi, grok, and kimi were unavailable to check and are left unverified rather than guessed at. * fix(tests): restore the executable bit on fm-captain-msg.test.sh Committed as mode 100644 by #42/#44, so bin/fm-fork-deliver.sh's local gate (which execs each tests/*.test.sh directly) hits Permission denied; real CI is unaffected since bin/fm-test-run.sh invokes tests via `bash "$script"`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
fm.ba.id.aulands on the shared alert-router, not this repo's own listener, so every inbound Twilio webhook to/captain-msgwas 401'd (the router authenticates with a sharedX-ClickStack-Secretheader Twilio cannot send).Teslemetry/toolsPR fix(spawn): require a proven worktree root before ending the treehouse poll #26 fixed the router side:/captain-msgnow carries no router-side auth at all and relays every POST verbatim -{"url", "signature", "body"}- into this home'sstate/captain-msg-inbox/, the exact directorybin/fm-captain-msg-lib.shalready pointed at. The router holds no Twilio Account Auth Token and makes no trust decision about the content; validation has to happen downstream.docs/betterstack-webhook.md): same-host direct filesystem write into the existing inbox dir over a sharedfirstmate:fm-alertsgroup, not a new transport. That side (pm2 dotenv, directory perms) was deployed and verified live separately (srv-router-captain-msg-deploy).bin/fm-clickstack-listener.pyintobin/fm_twilio_sig.py, imported in-process by the listener (unchanged behavior, still verified against Twilio's canonical test vector) and called out-of-process by a newbin/fm-twilio-sig-verify.pyCLI (Auth Token on stdin, never argv/env) - one owner, two callers, per the direct-listener and router-relay paths.bin/fm-captain-msg-poll.shnow validates a router-relayed payload at poll time before ever treating it as a pending reply: signature +Frommatch, normalize a valid one in place into the same{received_at, params}shape the direct listener already produces (so thecaptain-msg-responseskill and every downstream consumer never has to know which path a reply came through), and quarantine an invalid one -state/captain-msg-inbox/quarantine/, with a reason sidecar, loud output so the wake still fires. An infra failure to validate (1Password unreachable,jq/python3missing) is reported loudly too, but the payload stays untouched for a retry - never quarantined on a hunch, and never counted as a trusted pending reply either.bin/fm-bootstrap.sh's presence-gatedcaptain_msg_setup(reproduced it correctly generating the shim from this home's real config, in isolation) - the config file was dropped mid-session, and bootstrap only runs once at session start (AGENTS.mdsection 3), so it never got the chance. Documented the fix indocs/captain-messaging.mdSetup: runbin/fm-bootstrap.shonce after a mid-session config drop.docs/captain-messaging.md"Inbound route" rewritten for both paths (router-relayed and direct-listener), with a new "Validation" subsection covering the quarantine contract;.agents/skills/captain-msg-response/SKILL.mdupdated for the quarantine wake and the two validation points.Testing
tests/fm-captain-msg.test.sh(+18 cases, 42 total):fm-twilio-sig-verify.pystandalone (valid/tampered-body/wrong-URL), and the poll's full router-relay path - valid normalization, quarantine (tampered body, missing signature,Frommismatch, unrecognized shape) each with a reason sidecar and never counted pending, the auth-token-fetch-failure path (loud, untouched, not quarantined, not trusted), and confirmation an already-normalized payload is never re-validated (optripwired on the second poll).tests/fm-clickstack.test.sh/tests/fm-betterstack.test.sh(pre-existing, unmodified): still fully green - the shared-listener signature refactor left both routes' own behavior untouched.bin/fm-lint.sh(shellcheck, pinned): clean.bin/fm-doc-audience-check.sh: clean.pendingreply whenever validation itself failed (e.g. 1Password unreachable) - the pending scan now only counts already-normalized ("params"-shaped) files.Follow-up after merge
The router-side relay is already live and verified (
srv-router-captain-msg-deploy,Teslemetry/toolsPR #26 deployed to the pm2 alert-router). Two things remain, both outside a worktree's reach:bin/fm-bootstrap.shonce (or let the next session start do it) sostate/captain-msg-watch.check.shgets armed againstconfig/captain-msg.env, which is already present.bin/fm-captain-msg.sh+ a real reply) to close the loop end to end with the wake actually firing - the definition of done for this feature, but not something a fork-only crewmate branch can trigger against production credentials.Full narrative / original brief
Adapt firstmate's captain-messaging inbound path to consume the alert-router's relayed payloads, restoring the two-way phone channel. Root cause: since the Stage-7 router cutover, https://fm.ba.id.au/captain-msg lands on the alert-router, not this home's own listener; tools PR 26 added a router relay that persists each Twilio post (raw form body bytes + X-Twilio-Signature header + original URL) into a captain-msg inbox dir; a parallel ops task (srv-router-captain-msg-deploy) deployed it.
Work: extend the captain-msg inbound path to consume router-relayed payloads (validate the Twilio signature from the stored body+header+URL, reusing the listener's validation semantics, plus the From-number check), surfacing the message as a pending inbound exactly like the direct-webhook path; determine empirically how BetterStack's relay reaches state/betterstack-inbox/ and mirror the same mechanism rather than inventing transport; ensure the watcher check shim is generated by the same bootstrap owner that arms the other webhook polls, finding and fixing the generation path if broken; update docs/captain-messaging.md for the router-relay reality; colocated tests for signature validation, From mismatch, and quarantine behavior; and, once the router deploy reports live, an inbound reply payload consumed end to end with the wake firing.