Skip to content

feat(bin): add idempotent inbox capture, replies, receipts, and readiness JSON - #5103

Merged
kunchenguid merged 6 commits into
kunchenguid:mainfrom
cliflacata-svg:fm/fm-console-order-contract-2
Sep 21, 2026
Merged

kunchenguid merged 6 commits into
kunchenguid:mainfrom
cliflacata-svg:fm/fm-console-order-contract-2

Conversation

@cliflacata-svg

Copy link
Copy Markdown
Contributor

Intent

The captain authorized starting the web front end for the VPS base of operations on 2026-09-20, after reading the scoping report. This task is that report's section 8, step 1, backend half.

What is wanted, in substance: a browser console that can be opened from any device to see what the fleet is doing, give it orders, and read its answers. Cost-sensitive: a design that spends model tokens to render a page or to remember a conversation is the wrong answer. There are exactly three subscriptions (Claude Pro, ChatGPT Plus/Codex, SuperGrok) and no budget for a new paid service.

This task builds NONE of the web UI and starts no HTTP service. It builds the durable contract underneath it, because the existing scripts cannot yet support a browser client honestly: an order submitted over HTTP can be silently duplicated on retry, a saved order whose wake announcement failed looks like a failure, there is no machine-readable way to see whether an order was acknowledged, there is no durable path for the primary's actual answer to come back to the submitter, and there is no structured way to tell whether a primary is even alive to receive the order.

The specific findings this task acts on:

  • fm-inbox.sh note - atomically publishes a note and appends one check wake, accepts multiline text and invokes no model. The scout demonstrated the duplication gap directly: the same multiline body submitted twice produced two notes and two wake rows (ids 1789931606-dhVOWS and 1789931606-jmovsu).
  • note currently exits nonzero after a note is already saved when announcing fails, so a caller that treats every nonzero exit as permission to retry creates duplicates.
  • list and drain are human text, so a client would otherwise have to parse a directory itself.
  • fm-lock.sh status is human output and always exits zero, and a held lock does not prove the holder is consuming wakes.
  • "Wake queued" is not "agent awakened"; an HTTP success must never manufacture approval, delivery, or completion.

Section 8 step 1 backend half, in substance: extend the existing inbox and health owners so a caller can supply a request id when capturing an order and a retry reuses the original note, including after a crash between recording and announcing; expose a saved-but-wake-failed result that is repairable without creating another note; add a bounded JSON view of pending and handled notes with acknowledgement and recorded replies, stating what it omitted rather than implying the first page is everything; give the primary a supported way to publish its actual answer against a note id as a durable record with a cursor so a client can read what is new; and add a read-only structured projection of whether a primary can currently receive work (lock ownership, wake-consumer health, away posture, observation age) that can say unknown honestly and does not infer liveness from a lock, a session, or a pane.

Standing direction this must not paint into a corner: persistent expert agents selected by task type, agents that debate to a conclusion, durable memory on cheaper models, all on the VPS and reachable from any device, doing real coding work against GitHub. Keep identity and correlation independent of any harness name or terminal pane.

What Changed

  • bin/fm-inbox.sh note takes an optional --request-id <id> and --json. The request id is recorded before the wake is announced, so a retry returns the original note and does not create a new one, even after a crash between those two steps. With either flag, a note that was saved but whose wake failed exits 3 instead of 1, so a caller knows to repair it rather than resubmit. The new announce <id> command repairs that wake without creating another note. It skips notes that are already acknowledged, and it refuses notes older than this change because nothing on disk shows whether their wake was announced. Plain note/list/drain output and exit codes are unchanged.
  • New reply <id> saves the primary's actual answer against a note id: one reply per note, each stamped with a per-home sequence number. New receipts [--after <cursor>] [--all-pending] [--all-handled] [--all-replies] returns bounded JSON listing pending and handled notes with their acknowledgement and announcement state and any reply. It also returns a cursor for reading new replies and an omitted[] list naming anything left out by the default limits. AGENTS.md now tells the primary to publish durable answers with reply.
  • New read-only ready outputs JSON on whether the primary can currently take work: lock ownership, wake-consumer health, away posture and when the state was observed. It reports unknown when it can't tell, and never treats a lock, session or pane as proof of liveness. This uses a new fm_session_lock_inspect helper in bin/fm-session-lock-lib.sh, which fm-lock.sh status now shares without changing its output. Docs are updated, and a new tests/fm-inbox.test.sh covers the new commands.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The fix round correctly implements all four requested fixes: acknowledged notes get no wake, receipts skips missing files and reads bad bytes safely, the sequence counter can't go backwards, and a reply without a valid seq is reported as malformed. Both announce_note callers handle the new return code 2, and the new tests are behavioral regressions. What remains is one minor inconsistency in the announced value for legacy handled notes.

Testing

I ran the focused inbox test and two live CLI scripts against temporary FM_HOMEs; every scenario passed. The scripts cover: - idempotent retry and repair after a wake failure (made real with a read-only wake queue) - no wake for a note already acknowledged - bounded receipts that report what they omitted - replies and the forward-only cursor, including after the sequence counter was lost - the ready projection across free, stale, unknown and live-holder locks, away status and an old beacon - invalid inputs, and the unchanged plain note path The change is CLI-only, with no UI and no Herdr lifecycle, so no screenshots or Herdr lab were needed. Evidence is CLI transcripts. The temp homes were removed and the worktree is clean.

  • Live validation: ✅ go - 11 of 11 scenarios driven live against the product
Scenario Result Live Evidence
Client retries the same multiline order with the same request id and gets the original note back as a replay; one note, one wake ✅ pass live drive-console-contract.transcript.txt S1: created then replay, same id, wake rows 1, notes 1
Order saved but its wake append fails: exit 3 with saved=true/announced=false, retry replays the same id, and announce repairs with exactly one wake and no new note ✅ pass live drive-console-contract.transcript.txt S2: exit 3 twice with the same id; announce gives announced=true, a second announce adds no wake, wake rows go 1 to 2 only
Adversarial: a saved-but-unannounced note that the primary acks before repair gets no wake from announce or request-id replay ✅ pass live drive-console-contract.transcript.txt S3: acknowledged=true, announced=false, exit 0, wake rows unchanged at 2
Primary publishes an answer against a note id; a second reply is refused; receipts show it with a cursor ✅ pass live drive-console-contract.transcript.txt S4: reply created, second reply exit 1 'already recorded', receipts show reply with cursor 000000000001/2
Client polls receipts --after &lt;cursor&gt; and sees only replies newer than its cursor ✅ pass live drive-cursor-and-ready.transcript.txt: after 000000000002 only 'answer C' (cursor 3)
Adversarial: the reply sequence counter file is lost, and the next reply still sorts after the client's cursor ✅ pass live drive-cursor-and-ready.transcript.txt: .seq deleted, next reply gets cursor 000000000004 and is visible after 3
Receipts are bounded and disclose omitted notes, with a way to reveal them ✅ pass live drive-console-contract.transcript.txt S5: 20 shown, omitted 'pending notes omitted by bound: 6' reveal '--all-pending'; --all-pending shows 26, omitted []
ready says can_receive true only for a live harness lock holder with a fresh wake beacon, and reports away status ✅ pass live drive-cursor-and-ready.transcript.txt: held/healthy gives can_receive true; after .afk posture=away
Adversarial: ready does not infer liveness from a lock file (free, dead pid, non-harness pid, stale beacon, holder exited) and never modifies the lock ✅ pass live drive-console-contract.transcript.txt S6 plus drive-cursor-and-ready.transcript.txt: free gives false; non-harness pid gives lock unknown and can_receive 'unknown'; dead pid gives stale/false; 2h beac…
Adversarial inputs: path-escaping request id, empty body, unknown note id, and a body that looks like a flag ✅ pass live drive-console-contract.transcript.txt S7: invalid id and empty body refused with exit 1; announce/reply for a missing note exit 1; '-- --all-pending' is queued as the note body
The plain human note/list/drain path and fm-lock.sh status wording are unchanged ✅ pass live drive-console-contract.transcript.txt S8 and fm-lock status lines; fm-inbox.test.log 'plain note keeps exit 1'
Evidence: Live CLI transcript: idempotency, repair, acked-no-wake, receipts, ready, adversarial inputs

Source: Live CLI transcript: idempotency, repair, acked-no-wake, receipts, ready, adversarial inputs

== S1 idempotent retry of a multiline order ==
$ fm-inbox.sh note --request-id web-req-1 --json -
{"schema":"fm-inbox-note.v1","outcome":"created","id":"1789967985-krv5Ab","request_id":"web-req-1","saved":true,"announced":true,"acknowledged":false,"path":"/tmp/fm-console-live.vRrqgU/state/inbox/1789967985-krv5Ab.note"}
[exit 0]
$ fm-inbox.sh note --request-id web-req-1 --json -
{"schema":"fm-inbox-note.v1","outcome":"replay","id":"1789967985-krv5Ab","request_id":"web-req-1","saved":true,"announced":true,"acknowledged":false,"path":"/tmp/fm-console-live.vRrqgU/state/inbox/1789967985-krv5Ab.note"}
[exit 0]
wake rows: 1  notes pending: 1  handled: 0

== S2 saved but wake failed -> exit 3, repair without second note ==
$ fm-inbox.sh note --request-id web-req-2 --json fix the flaky test
~/.no-mistakes/worktrees/be2e8740e3ea/01M3160NPCGZS4B894JST8VVTQ/bin/fm-wake-lib.sh: line 1844: /tmp/fm-console-live.vRrqgU/state/.wake-queue: Permission denied
{"schema":"fm-inbox-note.v1","outcome":"created","id":"1789967986-ajAf6V","request_id":"web-req-2","saved":true,"announced":false,"acknowledged":false,"path":"/tmp/fm-console-live.vRrqgU/state/inbox/1789967986-ajAf6V.note"}
fm-inbox: note 1789967986-ajAf6V is saved at /tmp/fm-console-live.vRrqgU/state/inbox/1789967986-ajAf6V.note but firstmate was NOT woken
[exit 3]
$ fm-inbox.sh note --request-id web-req-2 --json fix the flaky test
~/.no-mistakes/worktrees/be2e8740e3ea/01M3160NPCGZS4B894JST8VVTQ/bin/fm-wake-lib.sh: line 1844: /tmp/fm-console-live.vRrqgU/state/.wake-queue: Permission denied
{"schema":"fm-inbox-note.v1","outcome":"replay","id":"1789967986-ajAf6V","request_id":"web-req-2","saved":true,"announced":false,"acknowledged":false,"path":"/tmp/fm-console-live.vRrqgU/state/inbox/1789967986-ajAf6V.note"}
fm-inbox: note 1789967986-ajAf6V is saved at /tmp/fm-console-live.vRrqgU/state/inbox/1789967986-ajAf6V.note but firstmate was NOT woken
[exit 3]
wake rows: 1  notes pending: 2  handled: 0
$ fm-inbox.sh announce --json 1789967986-ajAf6V
{"schema":"fm-inbox-note.v1","outcome":"created","id":"1789967986-ajAf6V","request_id":null,"saved":true,"announced":true,"acknowledged":false,"path":"/tmp/fm-console-live.vRrqgU/state/inbox/1789967986-ajAf6V.note"}
[exit 0]
$ fm-inbox.sh announce --json 1789967986-ajAf6V
{"schema":"fm-inbox-note.v1","outcome":"replay","id":"1789967986-ajAf6V","request_id":null,"saved":true,"announced":true,"acknowledged":false,"path":"/tmp/fm-console-live.vRrqgU/state/inbox/1789967986-ajAf6V.note"}
[exit 0]
$ fm-inbox.sh note --request-id web-req-2 --json fix the flaky test
{"schema":"fm-inbox-note.v1","outcome":"replay","id":"1789967986-ajAf6V","request_id":"web-req-2","saved":true,"announced":true,"acknowledged":false,"path":"/tmp/fm-console-live.vRrqgU/state/inbox/1789967986-ajAf6V.note"}
[exit 0]
wake rows: 2  notes pending: 2  handled: 0

== S3 acked note gets no repair wake ==
$ fm-inbox.sh note --request-id web-req-3 --json acked before repair
~/.no-mistakes/worktrees/be2e8740e3ea/01M3160NPCGZS4B894JST8VVTQ/bin/fm-wake-lib.sh: line 1844: /tmp/fm-console-live.vRrqgU/state/.wake-queue: Permission denied
{"schema":"fm-inbox-note.v1","outcome":"created","id":"1789967986-ur6mAH","request_id":"web-req-3","saved":true,"announced":false,"acknowledged":false,"path":"/tmp/fm-console-live.vRrqgU/state/inbox/1789967986-ur6mAH.note"}
fm-inbox: note 1789967986-ur6mAH is saved at /tmp/fm-console-live.vRrqgU/state/inbox/1789967986-ur6mAH.note but firstmate was NOT woken
[exit 3]
$ fm-inbox.sh drain --ack 1789967986-ur6mAH
acked 1789967986-ur6mAH
[exit 0]
$ fm-inbox.sh announce --json 1789967986-ur6mAH
{"schema":"fm-inbox-note.v1","outcome":"replay","id":"1789967986-ur6mAH","request_id":null,"saved":true,"announced":false,"acknowledged":true,"path":"/tmp/fm-console-live.vRrqgU/state/inbox/handled/1789967986-ur6mAH.note"}
[exit 0]
$ fm-inbox.sh note --request-id web-req-3 --json acked before repair
{"schema":"fm-inbox-note.v1","outcome":"replay","id":"1789967986-ur6mAH","request_id":"web-req-3","saved":true,"announced":false,"acknowledged":true,"path":"/tmp/fm-console-live.vRrqgU/state/inbox/handled/1789967986-ur6mAH.note"}
[exit 0]
wake rows: 2  notes pending: 2  handled: 1

== S4 primary replies; receipts cursor ==
$ fm-inbox.sh drain --ack 1789967985-krv5Ab
acked 1789967985-krv5Ab
[exit 0]
$ fm-inbox.sh reply --json 1789967985-krv5Ab Console deploy started; PR to follow.
{"schema":"fm-inbox-reply.v1","outcome":"created","id":"1789967985-krv5Ab","path":"/tmp/fm-console-live.vRrqgU/state/inbox/.replies/1789967985-krv5Ab"}
[exit 0]
$ fm-inbox.sh reply --json 1789967985-krv5Ab second answer
fm-inbox: reply already recorded for 1789967985-krv5Ab
[exit 1]
[receipts exit 0]
Expecting value: line 1 column 1 (char 0)
cursor=
$ fm-inbox.sh reply --json 1789967986-ajAf6V Flaky test fixed.
{"schema":"fm-inbox-reply.v1","outcome":"created","id":"1789967986-ajAf6V","path":"/tmp/fm-console-live.vRrqgU/state/inbox/.replies/1789967986-ajAf6V"}
[exit 0]
$ fm-inbox.sh receipts --after <cursor>
{
    "schema": "fm-inbox-receipts.v1",
    "home": "tmp/fm-console-live.vRrqgU",
    "generated": "2026-09-21T05:19:47Z",
    "pending": [
        {
            "id": "1789967986-ajAf6V",
            "at": "2026-09-21T05:19:46Z",
            "source": "text",
            "request_id": "web-req-2",
            "body": "fix the flaky test",
            "acknowledged": false,
            "announced": true,
            "reply": {
                "id": "1789967986-ajAf6V",
                "at": "2026-09-21T05:19:47Z",
                "body": "Flaky test fixed.",
                "cursor": "000000000002"
            }
        }
    ],
    "handled": [
        {
            "id": "1789967986-ur6mAH",
            "at": "2026-09-21T05:19:46Z",
            "source": "text",
            "request_id": "web-req-3",
            "body": "acked before repair",
            "acknowledged": true,
            "announced": false,
            "reply": null
        },
        {
            "id": "1789967985-krv5Ab",
            "at": "2026-09-21T05:19:45Z",
            "source": "text",
            "request_id": "web-req-1",
            "body": "deploy the console\nsecond line",
            "acknowledged": true,
            "announced": true,
            "reply": {
                "id": "1789967985-krv5Ab",
                "at": "2026-09-21T05:19:46Z",
                "body": "Console deploy started; PR to follow.",
                "cursor": "000000000001"
            }
        }
    ],
    "replies": [
        {
            "id": "1789967985-krv5Ab",
            "at": "2026-09-21T05:19:46Z",
            "body": "Console deploy started; PR to follow.",
            "cursor": "000000000001"
        },
        {
            "id": "1789967986-ajAf6V",
            "at": "2026-09-21T05:19:47Z",
            "body": "Flaky test fixed.",
            "cursor": "000000000002"
        }
    ],
    "reply_cursor": "000000000002",
    "omitted": []
}

== S5 bounded receipts with omission disclosure ==
pending shown: 20 omitted: [{"surface": "pending notes omitted by bound: 6", "reveal": "pass --all-pending"}]
--all-pending shown: 26 omitted: []

== S6 readiness projection ==
$ fm-inbox.sh ready
{"schema":"fm-primary-ready.v1","home":"tmp/fm-console-live.vRrqgU","observed_at":"2026-09-21T05:19:51Z","lock":{"state":"free","pid":null,"live_harness":false},"wake_consumer":{"state":"unknown","reason":"supervision-model-unknown-for-home","beacon_age_seconds":null},"posture":{"state":"present"},"can_receive":false}
[exit 0]
$ fm-inbox.sh ready
{"schema":"fm-primary-ready.v1","home":"tmp/fm-console-live.vRrqgU","observed_at":"2026-09-21T05:19:51Z","lock":{"state":"unknown","pid":2810722,"live_harness":false},"wake_consumer":{"state":"unknown","reason":"supervision-model-unknown-for-home","beacon_age_seconds":0},"posture":{"state":"present"},"can_receive":"unknown"}
[exit 0]
$ fm-inbox.sh ready
{"schema":"fm-primary-ready.v1","home":"tmp/fm-console-live.vRrqgU","observed_at":"2026-09-21T05:19:51Z","lock":{"state":"stale","pid":999999,"live_harness":false},"wake_consumer":{"state":"unknown","reason":"supervision-model-unknown-for-home","beacon_age_seconds":0},"posture":{"state":"present"},"can_receive":false}
[exit 0]
$ fm-lock.sh status
lock: stale (pid 999999 dead or not a harness)
[exit 0]

== S7 adversarial: bad ids, empty body, body that looks like flags ==
$ fm-inbox.sh note --request-id ../escape --json x
fm-inbox: invalid request id (use 1-128 characters: A-Za-z0-9._:-)
[exit 1]
$ fm-inbox.sh note --request-id ok-1 --json 
fm-inbox: refusing to queue an empty note
[exit 1]
$ fm-inbox.sh note --request-id dash-1 --json -- --all-pending
{"schema":"fm-inbox-note.v1","outcome":"created","id":"1789967991-Mzi8T3","request_id":"dash-1","saved":true,"announced":true,"acknowledged":false,"path":"/tmp/fm-console-live.vRrqgU/state/inbox/1789967991-Mzi8T3.note"}
[exit 0]
$ fm-inbox.sh announce --json no-such-note
fm-inbox: no such note: no-such-note
[exit 1]
$ fm-inbox.sh reply --json no-such-note x
fm-inbox: no such note: no-such-note
[exit 1]

== S8 plain human note path unchanged ==
$ fm-inbox.sh note plain human note
queued 1789967991-jCDQHL
  plain human note
  firstmate will pick this up at its next check.
[exit 0]
1789967991-jCDQHL
    plain human note
[exit 0]
Evidence: Live CLI transcript: reply cursor increments and readiness with live holder/away/stale beacon

Source: Live CLI transcript: reply cursor increments and readiness with live holder/away/stale beacon

== reply cursor: client reads only what is new ==
client cursor after first poll: 000000000002
$ fm-inbox.sh receipts --after 000000000002  (replies[] only)
{
 "replies": [
  {
   "id": "1789968011-DnU48F",
   "at": "2026-09-21T05:20:11Z",
   "body": "answer C",
   "cursor": "000000000003"
  }
 ],
 "reply_cursor": "000000000003"
}
--- simulate lost .seq counter, then a new reply
after 3 -> [('1789968011-mDepnQ', 'answer D', '000000000004')]

== ready: live harness holder + fresh beacon, then away ==
$ fm-inbox.sh ready
{"schema":"fm-primary-ready.v1","home":"tmp/fm-console-live2.IwzYM1","observed_at":"2026-09-21T05:20:12Z","lock":{"state":"held","pid":2815479,"live_harness":true},"wake_consumer":{"state":"healthy","reason":"supervised","beacon_age_seconds":0},"posture":{"state":"present"},"can_receive":true}

$ fm-lock.sh status
lock: held by live harness pid 2815479
$ fm-inbox.sh ready  (after .afk=away)
{"schema":"fm-primary-ready.v1","home":"tmp/fm-console-live2.IwzYM1","observed_at":"2026-09-21T05:20:12Z","lock":{"state":"held","pid":2815479,"live_harness":true},"wake_consumer":{"state":"healthy","reason":"supervised","beacon_age_seconds":0},"posture":{"state":"away"},"can_receive":true}

$ fm-inbox.sh ready  (beacon 2h old)
{"schema":"fm-primary-ready.v1","home":"tmp/fm-console-live2.IwzYM1","observed_at":"2026-09-21T05:20:12Z","lock":{"state":"held","pid":2815479,"live_harness":true},"wake_consumer":{"state":"down","reason":"stale-beacon","beacon_age_seconds":7200},"posture":{"state":"away"},"can_receive":false}

$ fm-inbox.sh ready  (holder exited)
{"schema":"fm-primary-ready.v1","home":"tmp/fm-console-live2.IwzYM1","observed_at":"2026-09-21T05:20:12Z","lock":{"state":"stale","pid":2815479,"live_harness":false},"wake_consumer":{"state":"unknown","reason":"supervision-model-unknown-for-home","beacon_age_seconds":7200},"posture":{"state":"away"},"can_receive":false}

lock file untouched by ready: 2815479
Evidence: Driver script (contract)

Source: Driver script (contract)

#!/usr/bin/env bash
# Live CLI drive of the console order contract in a throwaway FM_HOME.
set -u
BIN=~/.no-mistakes/worktrees/be2e8740e3ea/01M3160NPCGZS4B894JST8VVTQ/bin
H=$(mktemp -d /tmp/fm-console-live.XXXXXX); mkdir -p $H/state $H/data $H/config
export FM_HOME=$H FM_STATE_OVERRIDE=$H/state FM_DATA_OVERRIDE=$H/data FM_CONFIG_OVERRIDE=$H/config
inbox(){ echo "\$ fm-inbox.sh $*"; "$BIN/fm-inbox.sh" "$@"; echo "[exit $?]"; }
wakes(){ echo "wake rows: $(grep -c 'inbox:' $H/state/.wake-queue 2>/dev/null || echo 0)  notes pending: $(ls $H/state/inbox/*.note 2>/dev/null | wc -l)  handled: $(ls $H/state/inbox/handled/*.note 2>/dev/null | wc -l)"; }
echo "== S1 idempotent retry of a multiline order =="
printf 'deploy the console\nsecond line\n' | inbox note --request-id web-req-1 --json -
printf 'deploy the console\nsecond line\n' | inbox note --request-id web-req-1 --json -
wakes
echo; echo "== S2 saved but wake failed -> exit 3, repair without second note =="
touch $H/state/.wake-queue; chmod 444 $H/state/.wake-queue
inbox note --request-id web-req-2 --json "fix the flaky test"
ID2=$(ls -t $H/state/inbox/*.note | head -1 | xargs basename | sed 's/\.note$//')
inbox note --request-id web-req-2 --json "fix the flaky test"
wakes
chmod 644 $H/state/.wake-queue
inbox announce --json "$ID2"
inbox announce --json "$ID2"
inbox note --request-id web-req-2 --json "fix the flaky test"
wakes
echo; echo "== S3 acked note gets no repair wake =="
chmod 444 $H/state/.wake-queue
inbox note --request-id web-req-3 --json "acked before repair"
ID3=$(ls -t $H/state/inbox/*.note | head -1 | xargs basename | sed 's/\.note$//')
chmod 644 $H/state/.wake-queue
inbox drain --ack "$ID3"
inbox announce --json "$ID3"
inbox note --request-id web-req-3 --json "acked before repair"
wakes
echo; echo "== S4 primary replies; receipts cursor =="
ID1=$(python3 -c 'import json,sys;print(json.load(open(sys.argv[1]))["id"])' <(printf 'x\n' | "$BIN/fm-inbox.sh" note --request-id web-req-1 --json - 2>/dev/null))
inbox drain --ack "$ID1"
inbox reply --json "$ID1" "Console deploy started; PR to follow."
inbox reply --json "$ID1" "second answer"
inbox receipts > $H/r1.json; echo "[receipts exit $?]"; python3 -m json.tool $H/r1.json
CUR=$(python3 -c 'import json,sys;print(json.load(open(sys.argv[1])).get("cursor") or json.load(open(sys.argv[1]))["replies"]["cursor"])' $H/r1.json 2>/dev/null)
echo "cursor=$CUR"
inbox reply --json "$ID2" "Flaky test fixed."
echo "\$ fm-inbox.sh receipts --after <cursor>"; "$BIN/fm-inbox.sh" receipts --after "$CUR" | python3 -m json.tool
echo; echo "== S5 bounded receipts with omission disclosure =="
for i in $(seq 1 25); do "$BIN/fm-inbox.sh" note --request-id bulk-$i --json "bulk $i" >/dev/null; done
"$BIN/fm-inbox.sh" receipts | python3 -c 'import json,sys;d=json.load(sys.stdin);print("pending shown:",len(d["pending"]),"omitted:",json.dumps(d.get("omitted")))'
"$BIN/fm-inbox.sh" receipts --all-pending | python3 -c 'import json,sys;d=json.load(sys.stdin);print("--all-pending shown:",len(d["pending"]),"omitted:",json.dumps(d.get("omitted")))'
echo; echo "== S6 readiness projection =="
inbox ready
printf '%s\n' $$ > $H/state/.lock; touch $H/state/.last-watcher-beat
inbox ready
printf '999999\n' > $H/state/.lock
inbox ready
echo "\$ fm-lock.sh status"; "$BIN/fm-lock.sh" status; echo "[exit $?]"
touch $H/state/away 2>/dev/null
echo; echo "== S7 adversarial: bad ids, empty body, body that looks like flags =="
inbox note --request-id '../escape' --json "x"
inbox note --request-id ok-1 --json ""
inbox note --request-id dash-1 --json -- --all-pending
inbox announce --json 'no-such-note'
inbox reply --json 'no-such-note' "x"
echo; echo "== S8 plain human note path unchanged =="
inbox note "plain human note"
inbox list | tail -3
rm -rf "$H"
Evidence: Driver script (cursor + ready)

Source: Driver script (cursor + ready)

#!/usr/bin/env bash
set -u
BIN=~/.no-mistakes/worktrees/be2e8740e3ea/01M3160NPCGZS4B894JST8VVTQ/bin
H=$(mktemp -d /tmp/fm-console-live2.XXXXXX); mkdir -p $H/state $H/data $H/config
export FM_HOME=$H FM_STATE_OVERRIDE=$H/state FM_DATA_OVERRIDE=$H/data FM_CONFIG_OVERRIDE=$H/config
nid(){ "$BIN/fm-inbox.sh" note --request-id "$1" --json "$2" | python3 -c 'import json,sys;print(json.load(sys.stdin)["id"])'; }
echo "== reply cursor: client reads only what is new =="
A=$(nid a "order A"); B=$(nid b "order B"); C=$(nid c "order C")
"$BIN/fm-inbox.sh" reply "$A" "answer A" >/dev/null; "$BIN/fm-inbox.sh" reply "$B" "answer B" >/dev/null
CUR=$("$BIN/fm-inbox.sh" receipts | python3 -c 'import json,sys;print(json.load(sys.stdin)["reply_cursor"])')
echo "client cursor after first poll: $CUR"
"$BIN/fm-inbox.sh" reply "$C" "answer C" >/dev/null
echo "\$ fm-inbox.sh receipts --after $CUR  (replies[] only)"
"$BIN/fm-inbox.sh" receipts --after "$CUR" | python3 -c 'import json,sys;d=json.load(sys.stdin);print(json.dumps({"replies":d["replies"],"reply_cursor":d["reply_cursor"]},indent=1))'
echo "--- simulate lost .seq counter, then a new reply"
rm -f $H/state/inbox/.replies/.seq; D=$(nid d "order D"); "$BIN/fm-inbox.sh" reply "$D" "answer D" >/dev/null
CUR2=$("$BIN/fm-inbox.sh" receipts --after "$CUR" | python3 -c 'import json,sys;print(json.load(sys.stdin)["reply_cursor"])')
"$BIN/fm-inbox.sh" receipts --after 000000000003 | python3 -c 'import json,sys;d=json.load(sys.stdin);print("after 3 ->",[(r["id"],r["body"],r["cursor"]) for r in d["replies"]])'
echo; echo "== ready: live harness holder + fresh beacon, then away =="
perl -e '$0="claude"; sleep 30' & HP=$!; sleep 0.3
printf '%s\n' $HP > $H/state/.lock; touch $H/state/.last-watcher-beat
echo "\$ fm-inbox.sh ready"; "$BIN/fm-inbox.sh" ready; echo
echo "\$ fm-lock.sh status"; "$BIN/fm-lock.sh" status
echo away > $H/state/.afk
echo "\$ fm-inbox.sh ready  (after .afk=away)"; "$BIN/fm-inbox.sh" ready; echo
touch -d '2 hours ago' $H/state/.last-watcher-beat
echo "\$ fm-inbox.sh ready  (beacon 2h old)"; "$BIN/fm-inbox.sh" ready; echo
kill $HP; wait $HP 2>/dev/null
echo "\$ fm-inbox.sh ready  (holder exited)"; "$BIN/fm-inbox.sh" ready; echo
ls $H/state/.lock >/dev/null && echo "lock file untouched by ready: $(cat $H/state/.lock)"
rm -rf "$H"
Evidence: Focused test log

Source: Focused test log

ok - plain note, list, and wake stay on the historical human path
ok - plain note keeps exit 1 for a saved-but-unannounced failure
ok - the same request id returns the original note as a distinguishable replay
ok - a crash between recording the request id and publishing the note reuses the original id
ok - saved-but-unannounced notes are repairable without creating a second note
ok - repair and replay do not wake firstmate for an already-acknowledged note
ok - receipts JSON is bounded by fixed bounds and discloses what it omitted
ok - notes that predate the announcement marker are unknown, not re-announced
ok - the reply channel is durable and its cursor is a strict order
ok - the reply cursor never goes backwards when the sequence counter is lost
ok - a reply without a valid sequence is reported as malformed
ok - a non-UTF-8 note does not break the receipts view
ok - readiness says unknown (or not-receivable) instead of inferring liveness from a lock
ok - empty bodies and unsafe request ids are refused
ok - a note body that opens with a double dash is queued as text
ok - drain --ack still moves the note to handled

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ⚠️ bin/fm-inbox.sh:358 - A repair or replay can add a wake for a note the primary has already acknowledged. finish_note_result (replay path) and cmd_announce (line 515) call announce_note for any note that has no marker, and note_path also resolves notes in inbox/handled/. Concrete sequence: note --request-id r1 --json saves the note but the wake append fails, so it exits 3. The primary wakes for something else, sees the note during its normal drain, and runs drain --ack. The client then follows the documented repair flow (announce &lt;id&gt;, or a retry with r1). A check wake is appended for a note that is already handled, so the primary spends a model turn on an empty inbox. The intent is explicitly cost-sensitive about spending tokens. Fix: in announce_note/finish_note_result, skip the append when the note is in handled/ and report it as acknowledged (announced is not needed) rather than appending a wake.
  • ⚠️ bin/fm-inbox.sh:646 - receipts fails the whole view on a single bad or moving file. parse_record calls Path.read_text(encoding=&#34;utf-8&#34;) with no error handling. (1) If drain --ack moves a note from inbox/ to handled/ between the glob and the read, a FileNotFoundError traceback makes receipts exit nonzero. A client that polls receipts while the primary acks notes will hit this. The same race can also list one note under both pending and handled in one snapshot. (2) If any note or reply contains bytes that are not valid UTF-8 (note - accepts arbitrary stdin), a UnicodeDecodeError breaks receipts permanently, because handled notes are never purged. Fix: skip files that vanish (catch FileNotFoundError), decode with errors="replace", and drop from pending any id that also appears in handled.
  • ℹ️ bin/fm-inbox.sh:542 - next_reply_seq rewrites .replies/.seq in place with printf &gt;, which truncates the file before writing. If that write is interrupted, or the file is lost, the next reply restarts at seq 1. Its cursor 000000000001|... then sorts below any cursor a client already holds, so receipts --after silently hides every new reply until the counter climbs back past the old value. Fix: write the counter via a temp file and mv, and/or seed it from max(seq of existing reply files) + 1 so the cursor can never go backwards.
  • ⚠️ bin/fm-inbox.sh:684 - Simplification: the receipts reply cursor has a fallback for replies "recorded before the sequence existed": a missing or non-numeric seq becomes 0, with ties broken by at/id. reply is new in this change and every reply it writes carries seq=, so no shipped reply lacks a sequence. No intent requirement needs this legacy path. Recommend removing it and treating a reply without a valid seq as malformed, rather than keeping a second ordering rule.

🔧 Fix applied.
1 info still open:

  • ℹ️ bin/fm-inbox.sh:513 - cmd_announce changes any non-true state to acknowledged when the note is in handled/, and then emits &#34;announced&#34;: false at line 547. That includes unknown, a legacy note written before the marker existed. For that note the JSON claims it was not announced. receipts reports announced: null for the same note (see the enrich comment: "not announced" cannot be read off this state). Concrete case: a pre-marker note that was drained with drain --ack, then announce --json &lt;id&gt;, gives {&#34;outcome&#34;:&#34;replay&#34;,&#34;announced&#34;:false,&#34;acknowledged&#34;:true}, while receipts gives announced: null. Fix: keep the original state and pass unknown as the announced argument when the prior state was unknown, so emit_note_json prints null.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 11 of 11 scenarios driven live against the product
Scenario Result Live Evidence
Client retries the same multiline order with the same request id and gets the original note back as a replay; one note, one wake ✅ pass live drive-console-contract.transcript.txt S1: created then replay, same id, wake rows 1, notes 1
Order saved but its wake append fails: exit 3 with saved=true/announced=false, retry replays the same id, and announce repairs with exactly one wake and no new note ✅ pass live drive-console-contract.transcript.txt S2: exit 3 twice with the same id; announce gives announced=true, a second announce adds no wake, wake rows go 1 to 2 only
Adversarial: a saved-but-unannounced note that the primary acks before repair gets no wake from announce or request-id replay ✅ pass live drive-console-contract.transcript.txt S3: acknowledged=true, announced=false, exit 0, wake rows unchanged at 2
Primary publishes an answer against a note id; a second reply is refused; receipts show it with a cursor ✅ pass live drive-console-contract.transcript.txt S4: reply created, second reply exit 1 'already recorded', receipts show reply with cursor 000000000001/2
Client polls receipts --after &lt;cursor&gt; and sees only replies newer than its cursor ✅ pass live drive-cursor-and-ready.transcript.txt: after 000000000002 only 'answer C' (cursor 3)
Adversarial: the reply sequence counter file is lost, and the next reply still sorts after the client's cursor ✅ pass live drive-cursor-and-ready.transcript.txt: .seq deleted, next reply gets cursor 000000000004 and is visible after 3
Receipts are bounded and disclose omitted notes, with a way to reveal them ✅ pass live drive-console-contract.transcript.txt S5: 20 shown, omitted 'pending notes omitted by bound: 6' reveal '--all-pending'; --all-pending shows 26, omitted []
ready says can_receive true only for a live harness lock holder with a fresh wake beacon, and reports away status ✅ pass live drive-cursor-and-ready.transcript.txt: held/healthy gives can_receive true; after .afk posture=away
Adversarial: ready does not infer liveness from a lock file (free, dead pid, non-harness pid, stale beacon, holder exited) and never modifies the lock ✅ pass live drive-console-contract.transcript.txt S6 plus drive-cursor-and-ready.transcript.txt: free gives false; non-harness pid gives lock unknown and can_receive 'unknown'; dead pid gives stale/false; 2h beac…
Adversarial inputs: path-escaping request id, empty body, unknown note id, and a body that looks like a flag ✅ pass live drive-console-contract.transcript.txt S7: invalid id and empty body refused with exit 1; announce/reply for a missing note exit 1; '-- --all-pending' is queued as the note body
The plain human note/list/drain path and fm-lock.sh status wording are unchanged ✅ pass live drive-console-contract.transcript.txt S8 and fm-lock status lines; fm-inbox.test.log 'plain note keeps exit 1'
  • bash tests/fm-inbox.test.sh (focused suite for the changed contract, 16 cases, all ok)
  • drive-console-contract.sh: live CLI drive in a throwaway FM_HOME: multiline request-id retry, wake failure made real with a read-only .wake-queue (exit 3, replay, announce repair, second announce), drain --ack then repair/replay, reply + duplicate reply, receipts bounds with --all-pending, ready for free/unknown/stale locks, fm-lock.sh status, bad/empty/dash-body inputs, the plain human note/list path
  • drive-cursor-and-ready.sh: receipts --after &lt;cursor&gt; returns only the new reply; deleted .replies/.seq then new reply stays at seq 4; ready with a live claude-named lock holder + fresh beacon, then .afk=away, then a 2h-old beacon, then the holder exits; the lock file is unchanged afterwards
✅ **Document** - passed

✅ No issues found.

🔧 **Lint** - 1 issue found → auto-fixed → no changes applied (2) ✅
  • ⚠️ linter found issues (exit code 1)

🔧 Fix applied.
1 warning still open:

  • ⚠️ linter found issues (exit code 1)

🔧 No changes applied.
1 warning still open:

  • ⚠️ linter found issues (exit code 1)

🔧 No changes applied.
✅ Re-checked - no issues remain.

✅ **Push** - passed

✅ No issues found.

Let a caller supply a request id when publishing a captain inbox note so a
retry returns the original note instead of creating a second one, including
across the crash window between save and wake announcement. Separate saved
from announced so a failed wake is repairable without enqueueing again.
Add bounded receipts JSON with omission disclosure, a durable primary reply
against a note id, and a read-only readiness projection that can say
unknown instead of inferring liveness from a lock file.
…-json

Remove the extra JSON surface from fm-lock.sh so its human status still
always exits zero. Have the readiness projection classify the inspected
home from the lock-holder pid via fm-harness.sh ancestry, with an explicit
FM_SUPERVISION_MODEL still winning and an unknown model when there is no
holder. Prove the yes path when that ancestry names a known harness.
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Triage stamp — contract-class opt-in; attestation MATCH; CI+NM SUCCESS; VISION aligned.

  • HEAD f4c63c0a62741addab16d224b019ccdff5f1397b matches attestation head_sha.
  • Unconfigured plain note/list/drain human output and exit codes preserved; new surfaces gated behind --request-id/--json and subcommands announce/reply/receipts/ready.
  • Tip vs main: durable request-id capture, announce repair, bounded receipts with omission disclosure, one reply per note with forward-only cursor, read-only ready that can say unknown — no always-on wake class or default-on observer.
  • No closing-issues references. Author not blocked. Safe review: no security withhold.
  • Auto-merge eligible (opt-in + green + MATCH). Squash-merging.

@kunchenguid kunchenguid left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Speaking as Kun's firstmate:

Safe review approve. Opt-in console-backend contract; plain inbox path preserved; request-id and readiness paths refuse unsafe ids and can say unknown honestly.

@kunchenguid
kunchenguid merged commit 631bc26 into kunchenguid:main Sep 21, 2026
19 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Merged — thank you @cliflacata-svg. The idempotent inbox capture / receipts / reply / readiness contract lands on main as opt-in surfaces with the plain note path preserved.

dscott98 pushed a commit to Simplifying-Cloud/firstmate that referenced this pull request Sep 21, 2026
…ness JSON (kunchenguid#5103)

* feat(bin): add idempotent inbox orders, receipts, replies, and readiness

Let a caller supply a request id when publishing a captain inbox note so a
retry returns the original note instead of creating a second one, including
across the crash window between save and wake announcement. Separate saved
from announced so a failed wake is repairable without enqueueing again.
Add bounded receipts JSON with omission disclosure, a durable primary reply
against a note id, and a read-only readiness projection that can say
unknown instead of inferring liveness from a lock file.

* no-mistakes(review): fix(bin): honest inbox announce, reply cursor, and readiness verdict

* fix(bin): resolve ready from lock-holder ancestry; drop lock status --json

Remove the extra JSON surface from fm-lock.sh so its human status still
always exits zero. Have the readiness projection classify the inspected
home from the lock-holder pid via fm-harness.sh ancestry, with an explicit
FM_SUPERVISION_MODEL still winning and an unknown model when there is no
holder. Prove the yes path when that ancestry names a known harness.

* no-mistakes(review): Harden inbox announce, receipts reads, and reply sequence cursor

* no-mistakes(document): Note read-only lock inspection in scripts inventory

* no-mistakes(lint): Pass missing id argument to malformed-reply test printf

---------

Co-authored-by: cliflacata-svg <[email protected]>
dscott98 added a commit to Simplifying-Cloud/firstmate that referenced this pull request Sep 21, 2026
…nation (#4)

* feat: route Lavish feedback directly to owning workers (kunchenguid#5099)

* feat(procevent): route worker-owned Lavish rounds

* no-mistakes(review): drop duplicate artifact field from task-owned registration

* no-mistakes(review): post worker reply once, fix ring label, keep re-arm atomic

* no-mistakes(review): keep worker board owned until terminal round acknowledged

* no-mistakes(review): refuse every retirement of an open worker-owned round

* no-mistakes(review): use real lavish reply flag, isolate reply generations

* no-mistakes(review): drop .posted marker for best-effort reply posting

* no-mistakes(review): consume staged reply after listener setup, refuse orphaned captures

* no-mistakes(review): require a reachable owner, redeliver open rounds, roll back failed re-arms

* no-mistakes(review): re-arm only to acknowledge an open round

* no-mistakes(review): conclude only a still-open terminal round

* no-mistakes(review): record the acknowledgement before retiring the board

* no-mistakes(review): retain the registration across a conclude, qualify terminal docs

* no-mistakes(document): Document worker-owned Lavish round lifecycle

* fix(bin): fit pull observation within the contribution poll budget (kunchenguid#5107)

* fix(bin): reserve contribution observation budget

* no-mistakes(review): Strengthen slow-read regression test to exceed the poll budget

* feat(bin): add idempotent inbox capture, replies, receipts, and readiness JSON (kunchenguid#5103)

* feat(bin): add idempotent inbox orders, receipts, replies, and readiness

Let a caller supply a request id when publishing a captain inbox note so a
retry returns the original note instead of creating a second one, including
across the crash window between save and wake announcement. Separate saved
from announced so a failed wake is repairable without enqueueing again.
Add bounded receipts JSON with omission disclosure, a durable primary reply
against a note id, and a read-only readiness projection that can say
unknown instead of inferring liveness from a lock file.

* no-mistakes(review): fix(bin): honest inbox announce, reply cursor, and readiness verdict

* fix(bin): resolve ready from lock-holder ancestry; drop lock status --json

Remove the extra JSON surface from fm-lock.sh so its human status still
always exits zero. Have the readiness projection classify the inspected
home from the lock-holder pid via fm-harness.sh ancestry, with an explicit
FM_SUPERVISION_MODEL still winning and an unknown model when there is no
holder. Prove the yes path when that ancestry names a known harness.

* no-mistakes(review): Harden inbox announce, receipts reads, and reply sequence cursor

* no-mistakes(document): Note read-only lock inspection in scripts inventory

* no-mistakes(lint): Pass missing id argument to malformed-reply test printf

---------

Co-authored-by: cliflacata-svg <[email protected]>

* fix(bin): stop harness footer rows below a composer from reading as pending text (kunchenguid#5118)

* fix(composer): stop a harness footer row from reading as a composer holding text

A harness draws its own furniture below the composer - a user statusLine, a
permission-mode hint - and the cursorless "bottom-most shape wins" rule looks
exactly there. `→` (U+2192) is Cursor's prompt glyph but ordinary text
everywhere else, so a statusLine opening with `→` was selected as a bare
composer, swallowed the hint row beneath it as wrapped input, and answered
`pending` on a visibly empty pane. `fm_task_inbox_ring` defers on exactly that
verdict, and `bin/fm-watch.sh`'s re-ring calls the same function, so the first
doorbell and every retry were skipped and the worker never saw the steer.

Measured live on 2026-09-20: three of five Claude Code 2.1.236 worker panes on
Herdr 0.8.0 had genuinely empty composers and every one of them was refused.

A separator pair that closed over a bare agent-glyph row is a proven composer
container, so the contiguous non-blank rows below its closing rule are that
composer's footer and are no longer composer candidates. The demotion is bounded
by all three of its own preconditions: a blank row ends the zone, a pair that
closed over no glyph row demotes nothing, and a shape with no separator pair at
all (Cursor's half-block rules) is untouched. Real unsubmitted text in that same
composer, including a stray SGR mouse report left by a click in the pane, still
reads `pending`.

Pinned by two portable regressions and by a new cursorless arm on the live
composer-matrix guard, which re-reads each harness's already-proven-idle pane
the way every non-tmux backend reads it and fails naming the harness and
version when that read is `pending`.

* no-mistakes(review): make composer footer-zone demotion shape-independent

* no-mistakes(review): make footer-zone demotion refuse-only and drop rescan

* no-mistakes(lint): quote probe-absent sentinel to clear ShellCheck SC2100

---------

Co-authored-by: Koen Muller <[email protected]>

* feat(bin): append optional home-local include to briefs (kunchenguid#5115)

Co-authored-by: guanchengh-lgtm <[email protected]>

* fix(bin): report a branch with no validation run as absent instead of an unreadable runs table (kunchenguid#5114)

* fix(bin): stop misreading a no-run branch as an unreadable runs table

Defect: when `no-mistakes axi status`'s overview is truncated (a task's
own branch has zero rows among the shown ones), fm_nm_select_run's
Python fallback derived the repo identity for its direct SQLite query
from a `repo: <path>` line it expected in the overview text. The real
CLI never emits that line, truncated or not (see the genuine capture at
tests/captures/no-mistakes-v1.70.1/overview.toon, which has only
`count:`/`runs[...]:`), so the lookup always failed and reported
"unreadable runs table" for a task that simply has no run on its
branch. On a fleet with many concurrent runs, every idle-branch task
hits the truncated-overview path routinely, so this fired every few
minutes and drowned genuine unreadable/blocked verdicts in noise.

Fix: derive the repo identity from the task worktree path instead,
which is exactly the value `no-mistakes` records as a repo's
`working_path` (confirmed against the existing capped-overview test
fixtures, which already register repos by worktree path). A worktree
path that is not absolute cannot be matched and still reads as
unreadable rather than being guessed at. Also raise the reader's
SQLite busy timeout from 1s to 30s so ordinary lock contention on a
busy fleet cannot masquerade as an unreadable database.

Safety: every other verdict byte-for-byte unchanged - the repo lookup
still requires exactly one matching row (a genuinely corrupt or
mismatched repos table still reports unreadable, per the existing
`repo` failure-mode test), the branch query and row validation are
untouched, and a zero-row result for the branch still flows through
the same recursive re-parse that already turns an empty `runs[0]{...}`
table into `absent`. Added a regression test
(test_capped_overview_without_repo_line_and_no_runs_reports_absent)
that reproduces the real overview shape - capped, zero rows for the
task's branch, no `repo: ` line - and asserts the crew state falls
through to the pane/busy verdict instead of reporting unknown or
"unreadable". Full fm-crew-state.test.sh suite passes unchanged
otherwise.

* fix: recovered same-branch inventory awk misreads empty result as unreadable

fm_nm_select_run's deep SQLite reader rebuilds a `count:`/`runs[...]:`
overview and re-runs it through the same awk selection pass. When that
rebuilt inventory has zero rows for the branch, the row-matching loop never
executes, so its counters (`seen`) stay at awk's uninitialized empty string
while `expected` and `shown` are plain strings parsed from the header text.
Comparing an uninitialized value against a non-numeric string uses string
comparison, so "" != "0" is true, and the END block takes the "unreadable
runs table" branch instead of falling through to the correct "absent"
verdict for a branch with genuinely zero runs.

Coerce the affected END comparisons with `+0` so they are always numeric,
matching seen/expected/shown/total regardless of whether awk classified
them as strings or numeric strings. A truncated or genuinely malformed
inventory still differs numerically and still reports unreadable.

* no-mistakes(review