Skip to content

feat: add opt-in fleet activity ledger - #5375

Merged
kunchenguid merged 4 commits into
mainfrom
fm/fm-fleet-ledger-min-r1
Sep 23, 2026
Merged

kunchenguid merged 4 commits into
mainfrom
fm/fm-fleet-ledger-min-r1

Conversation

@kunchenguid

@kunchenguid kunchenguid commented Sep 23, 2026 •

Copy link
Copy Markdown
Owner

Intent

A user asked publicly for an "official hook for firstmate status": a stable, documented ledger that external tools can read to follow all the activity in a firstmate fleet.

"ok let's do it - make it opt-in to avoid overhead for everyone though"

A first attempt grew too complex in review. The follow-up decision:

"for activity ledger do C after your assessment of what the right minimum scope is, then ask a new crewmate to start from clean slate, potentially referencing what's done in that branch but don't inherit all the complexity"

The first attempt is kept for reference on branch fm/fm-fleet-activity-ledger-r1 on origin.

Minimum scope (firstmate's assessment - this IS the spec; everything else is out):

  • Opt-in by a presence flag config/fleet-ledger; when absent, producers do one file-existence test and nothing else.
  • One append-only JSONL file state/fleet-ledger.jsonl; each line {v:1, ts, event, task, ...}. Readers ignore unknown members/events.
  • Exactly four events: task.dispatched (kind, project, harness, model), task.status (state word, key, text = the status line after the first colon, verbatim, capped), task.merged (pr or local), task.cleaned_up.
  • Producers: fm-spawn (dispatched), the watcher's existing poll (status lines: new complete lines per task via a simple per-task byte offset), the merge path (merged), fm-teardown (cleaned_up). No other hook sites.
  • Documented limits instead of machinery: status records are at-least-once and may trail by one poll; no fsync/crash durability; no seq numbers; no rotation (file grows; document how to truncate); lines written while no watcher runs are picked up on its next run; text is exactly what the status log holds, so give ledger readers the same trust as state/.
  • OUT of scope (list as follow-up ideas in the doc, do not build): session/away events, relaunch, pr_recorded, seq and gap detection, rotation, cross-rotation continuity, backfill/replay, secret scrubbing beyond what status lines already contain, privacy guarantees stronger than "same as state/".
  • Target: small - one lib/script plus a handful of one-line hooks, a short contract doc, and behavioral tests. If review findings push beyond this spec, escalate to me rather than growing it.
  • Live-validate: opt in a disposable home, dispatch a throwaway worker, have it write status lines, merge/clean up, and show the ledger lines; plus prove zero writes when the flag is absent.

When this work reaches its promised terminal outcome, report it as typed data
(never as a sentence for someone to parse) by running exactly:

~/fm-homes/firstmate/bin/fm-public-followup-emit.sh
--stage-in ~/fm-homes/fmdev-f1
--obligation public-fleet-ledger
--relation rel-fleet-ledger-v2
--source-home secondmate:fmdev-f1
--work-id fm-fleet-ledger-min-r1
--generation 2
--outcome pr-merged
--deliverable pr_url=
--outcome-text ''

Do not post anything publicly yourself and do not look for the public thread:
the home that owes that reply is on another machine and owns it. Leave the
result exactly where the command above puts it; that home collects it over the
same route it reaches you on, and nothing here needs a path back to it.

What Changed

  • Add a config/fleet-ledger presence flag and an append-only JSONL ledger for task dispatch, status, merge, and cleanup events.
  • Hook ledger writes into spawn, watcher polling, merge, and teardown; capture complete status lines using per-task byte offsets.
  • Document the record contract and limits, and add lifecycle tests covering enabled and disabled homes.

Risk Assessment

Both findings raised here (status-text contract and merge/cleanup status capture) were resolved by the review decisions below.

Testing

The focused behavioral test passed. Direct executable-writer checks showed zero ledger writes with the flag absent and the expected verbatim status text, event order, and offset cleanup with it present. A named Herdr lab was provisioned and torn down, but the gate’s spawn guard prevented the live worker lifecycle; its diagnostic and the writer’s JSONL output were captured. Temporary worktree data was removed.

  • Live validation: ⚠️ inconclusive - 2 of 3 scenarios driven live against the product
Scenario Result Live Evidence
With the flag absent, a user invokes ledger dispatch and status capture and gets no ledger or offset file ✅ pass live Executable writer commands; ledger-writer-output.log
With the flag present, a user records dispatch, complete and partial status lines, local merge, and cleanup in ordered JSONL with verbatim status text ✅ pass live Executable writer commands and jq assertions; ledger-writer-output.log
A throwaway Herdr worker dispatches, reports status, lands locally, and cleans up while a flag-off worker produces no ledger files ⏸️ untested no The product’s fleet guard refuses fm-spawn when NO_MISTAKES_GATE is set. An authorized non-gate process must run the supplied lifecycle script against this head; the workspace boundary also requires i…
Evidence: Named Herdr lab attempt and spawn refusal

Source: Named Herdr lab attempt and spawn refusal

lab session: fm-lab-fm-fleet-ledger-31889-24564
=== case flag=on home=~/.no-mistakes/worktrees/52b07e9083e7/01M365MQD0FNT77ZHMY4X4SRRK/.ledger-live-tmp/on/home
config/: fleet-ledger herdr-presentation-spaces 
--- spawn
error: no-mistakes gate agent must not drive the fleet (NO_MISTAKES_GATE set)
spawn rc=3
--- spawn diagnostic
~/.no-mistakes/worktrees/52b07e9083e7/01M365MQD0FNT77ZHMY4X4SRRK/.ledger-live-tmp/on/home/data/ledger-live-on:
total 8
drwxr-xr-x@ 3 kunchen  staff   96 Sep 22 21:00 .
drwxr-xr-x@ 3 kunchen  staff   96 Sep 22 21:00 ..
-rw-r--r--@ 1 kunchen  staff  130 Sep 22 21:00 brief.md

~/.no-mistakes/worktrees/52b07e9083e7/01M365MQD0FNT77ZHMY4X4SRRK/.ledger-live-tmp/on/home/state:
total 0
drwxr-xr-x@ 2 kunchen  staff   64 Sep 22 21:00 .
drwxr-xr-x@ 6 kunchen  staff  192 Sep 22 21:00 ..
{"client":{"version":"0.9.0","channel":"stable","protocol":22,"endpoint_protocol_generation":1,"endpoint_capabilities":["surface_interest","presentation_effects_fence","health_check"],"binary":"/etc/profiles/per-user/kunchen/bin/herdr","session":"fm-lab-fm-fleet-ledger-31889-24564"},"server":{"status":"running","running":true,"version":"0.9.0","protocol":22,"capabilities":{"live_handoff":true,"detached_server_daemon":false,"endpoint_protocol_generation":1,"surface_interest":true,"health_check":true},"compatible":true,"endpoint_compatible":true,"socket":"~/.config/herdr/sessions/fm-lab-fm-fleet-ledger-31889-24564/herdr.sock","session":"fm-lab-fm-fleet-ledger-31889-24564","restart_needed":false,"server_binary_stale":false},"update":{"restart_needed":false,"server_binary_stale":false}}
lab teardown rc=0
Evidence: Executable ledger writer output

Source: Executable ledger writer output

FLAG OFF: no ledger or offset after dispatch and status capture
FLAG ON: ledger records from executable writer:
{"v":1,"ts":1790136055,"event":"task.dispatched","task":"demo","kind":"ship","project":"sample","harness":"claude","model":null}
{"v":1,"ts":1790136055,"event":"task.status","task":"demo","state":"working","key":null,"text":"  started  "}
{"v":1,"ts":1790136055,"event":"task.status","task":"demo","state":"needs-decision","key":"pick","text":" choose now"}
{"v":1,"ts":1790136055,"event":"task.status","task":"demo","state":null,"key":null,"text":"partial completed"}
{"v":1,"ts":1790136055,"event":"task.status","task":"demo","state":"done","key":"pick","text":" [key=pick] ready"}
{"v":1,"ts":1790136055,"event":"task.merged","task":"demo","via":"local"}
{"v":1,"ts":1790136055,"event":"task.cleaned_up","task":"demo"}
CLEANUP: task offset removed
- Outcome: ⚠️ 2 warnings across 2 runs (10m37s)

Live lifecycle validation (run outside the gate)

The required live worker lifecycle could not run inside the validation gate, because the fleet guard refuses fm-spawn whenever NO_MISTAKES_GATE is set.
The worker therefore ran it from an ordinary (non-gate) process against a byte-exact snapshot of pipeline head 8360eff9, and the test step was approved under that recorded exception.
The pushed head d29ef731 differs from 8360eff9 only by the document step's wording edits to docs/configuration.md and docs/fleet-ledger.md; no code changed.
Evidence file: data/fm-fleet-ledger-min-r1/live-evidence/run-4-head-8360eff9.txt in the supervising firstmate home.

Setup: a named fm-lab- Herdr session through fm-herdr-lab.sh with its teardown trap; disposable homes under /private/tmp; a throwaway raw-shell worker spawned with fm-spawn.sh --backend herdr --mode local-only; the real watcher poll via fm-watch-checkpoint.sh; then fm-merge-local.sh and fm-teardown.sh.

Flag on - the final ledger:

{"v":1,"ts":1790136102,"event":"task.dispatched","task":"ledger-live-on","kind":"ship","project":"ledgerlive-on","harness":"sh","model":null}
{"v":1,"ts":1790136106,"event":"task.status","task":"ledger-live-on","state":"working","key":null,"text":" live worker started"}
{"v":1,"ts":1790136106,"event":"task.status","task":"ledger-live-on","state":"needs-decision","key":"live-pick","text":" live worker asks a question"}
{"v":1,"ts":1790136106,"event":"task.status","task":"ledger-live-on","state":"done","key":null,"text":" live worker ready in branch"}
{"v":1,"ts":1790136112,"event":"task.merged","task":"ledger-live-on","via":"local"}
{"v":1,"ts":1790136117,"event":"task.cleaned_up","task":"ledger-live-on"}

Flag off - the same lifecycle (spawn, poll, local merge, teardown all exit 0) left no *fleet-ledger* file in state/.
The lab teardown verified the default Herdr session unchanged.

Review decisions

  • Status text: fixed to the literal contract - text is everything after the first colon, verbatim, then capped.
  • Merge and cleanup status capture: kept by decision. It runs inside the named merged and cleaned_up hooks and preserves at-least-once delivery, because cleanup deletes the task's status log before the next watcher poll could read it.
  • Stamped-line state finding: not applied; a false positive - working [at=...]: setup records state: working (covered by tests/fm-fleet-ledger.test.sh and the live run above).
  • Explicit [key=default] finding: not applied; the shared status parser treats an unkeyed line as key default, so both record null, and preserving it would grow the minimum scope.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 4 issues (2 errors, 2 warnings)
  • 🚨 bin/fm-fleet-ledger.sh:137 - The required text = the status line after the first colon, verbatim, capped contract is contradicted here: status_line_note removes leading whitespace and a note-head [key=...] token. For done: [key=review] ready, the ledger records ready, not [key=review] ready. docs/fleet-ledger.md:41 documents the same exception. Ask whether to honor the specified verbatim field; do not silently change the public contract.
  • ⚠️ bin/fm-fleet-ledger.sh:190 - The merge-time status capture, and its cleanup-time counterpart at bin/fm-fleet-ledger.sh:198, add an eager status producer beyond the specified watcher's existing poll (status lines) and No other hook sites. A status line written after a poll is published during merge or teardown instead of on a watcher poll; the lifecycle test explicitly relies on this path. This component is not required by the stated producer list. Ask whether to remove both eager captures; teardown's deletion of the status log makes that scope decision consequential.

🔧 Fix applied.
4 issues (2 errors, 2 warnings) still open:

  • 🚨 bin/fm-fleet-ledger.sh:137 - The required text = the status line after the first colon, verbatim, capped contract is contradicted here: status_line_note removes leading whitespace and a note-head [key=...] token. For done: [key=review] ready, the ledger records ready, not [key=review] ready. docs/fleet-ledger.md:41 documents the same exception. Ask whether to honor the specified verbatim field; do not silently change the public contract.
  • ⚠️ bin/fm-fleet-ledger.sh:190 - The merge-time status capture, and its cleanup-time counterpart at bin/fm-fleet-ledger.sh:198, add an eager status producer beyond the specified watcher's existing poll (status lines) and No other hook sites. A status line written after a poll is published during merge or teardown instead of on a watcher poll; the lifecycle test explicitly relies on this path. This component is not required by the stated producer list. Ask whether to remove both eager captures; teardown's deletion of the status log makes that scope decision consequential.
  • 🚨 bin/fm-fleet-ledger.sh:133 - A normally stamped line such as working [at=1790000000]: setup reaches line 134 with verb=working [at=1790000000], which is rejected and recorded with state:null instead of working. Keyed lines such as needs-decision [key=pick-one]: ... lose their state the same way. Extract the leading state word without treating status metadata as part of it.
  • ⚠️ bin/fm-fleet-ledger.sh:136 - A real status writer emits resolved [key=default]: ..., but this branch records its key as null, indistinguishable from an unkeyed line. The shared parser returns default for both cases; preserve default when a key token is explicitly present, whether before the colon or at the note head.
⚠️ **Test** - 2 warnings
  • ⚠️ The named Herdr lab provisioned, but the throwaway worker spawn did not finish within 240 seconds. The lab was safely torn down, but the required live worker-to-merge lifecycle remains unverified. Re-run it with a bounded spawn diagnostic and capture the resulting ledger.
  • ⚠️ live validation verdict: inconclusive (3 of 4 scenarios were driven live against the product); untested: A throwaway Herdr worker dispatches, reports status, lands locally, and cleans up in a named lab
  • Live validation: ⚠️ inconclusive - 3 of 4 scenarios driven live against the product
Scenario Result Live Evidence
With the flag absent, a dispatch leaves no ledger or offset ✅ pass live Manual disposable-home bin/fm-fleet-ledger.sh dispatched check; the focused producer test also exercised the full disabled lifecycle.
With the flag enabled, status lines appear before local merge and cleanup records ✅ pass live fleet-ledger-cli.jsonl; tests/fm-fleet-ledger.test.sh additionally exercised the real producer scripts with a fake terminal backend.
A later poll captures existing complete lines, caps text, and waits for an incomplete line ✅ pass live Manual disposable-home capture and JSONL assertions, including a repeated unchanged poll.
A throwaway Herdr worker dispatches, reports status, lands locally, and cleans up in a named lab ⏸️ untested no The Herdr worker spawn did not complete within the command timeout. Provide a bounded spawn diagnostic or a working lab launch path, then re-run the full lifecycle.
  • tests/fm-fleet-ledger.test.sh
  • Manual disposable-home ledger CLI check: flag absent, then dispatch, capture, local merge, and cleanup
  • Manual boundary check: opt-in after status was written, 2000-character cap, unchanged poll, and incomplete line
  • Attempted named Herdr lab worker lifecycle; spawn timed out after 240 seconds and guarded teardown completed

🔧 No changes applied.
2 warnings still open:

  • ⚠️ The named Herdr lab provisioned, but fm-spawn refused with “NO_MISTAKES_GATE set.” The required worker-to-merge lifecycle could not be demonstrated in this gate process. Re-run the supplied script from an authorized non-gate process against this head, using a disposable home and the guarded lab helper.
  • ⚠️ live validation verdict: inconclusive (2 of 3 scenarios were driven live against the product); untested: A throwaway Herdr worker dispatches, reports status, lands locally, and cleans up while a flag-off worker produces no ledger files
  • Live validation: ⚠️ inconclusive - 2 of 3 scenarios driven live against the product
Scenario Result Live Evidence
With the flag absent, a user invokes ledger dispatch and status capture and gets no ledger or offset file ✅ pass live Executable writer commands; ledger-writer-output.log
With the flag present, a user records dispatch, complete and partial status lines, local merge, and cleanup in ordered JSONL with verbatim status text ✅ pass live Executable writer commands and jq assertions; ledger-writer-output.log
A throwaway Herdr worker dispatches, reports status, lands locally, and cleans up while a flag-off worker produces no ledger files ⏸️ untested no The product’s fleet guard refuses fm-spawn when NO_MISTAKES_GATE is set. An authorized non-gate process must run the supplied lifecycle script against this head; the workspace boundary also requires i…
  • tests/fm-fleet-ledger.test.sh
  • bash .ledger-live-run.sh against this worktree in a named Herdr lab; spawn refused and lab teardown succeeded
  • Direct bin/fm-fleet-ledger.sh dispatch, capture, local merge, and cleanup with the flag absent and present; verified JSONL records and offset removal with jq
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Homes that create config/fleet-ledger get an append-only JSONL file,
state/fleet-ledger.jsonl, recording task.dispatched, task.status,
task.merged, and task.cleaned_up so outside tools can follow a fleet.
With the flag absent each producer does one file test and nothing else.
docs/fleet-ledger.md owns the record contract and its documented limits.
…test.sh: the replacement-wake test now waits for the prompt to start before releasing it. The focused test passed twice, and git diff --check passed
@kunchenguid
kunchenguid merged commit f2ab14a into main Sep 23, 2026
20 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-fleet-ledger-min-r1 branch September 23, 2026 05:20