Skip to content

feat(bin): record worker event time and task relaunches in fleet ledger - #49

Merged
clarsen merged 3 commits into
mainfrom
fm/wake-ledger-time-relaunch
Nov 22, 2026
Merged

clarsen merged 3 commits into
mainfrom
fm/wake-ledger-time-relaunch

Conversation

@clarsen

@clarsen clarsen commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Intent

I approve the wake question.

Approved first stories 4 and 12 of the Wake initiative:

  • Story 4, Fleet ledger carries the worker's event time: status records gain an optional at member from the status line's [at=<epoch>] stamp; docs/fleet-ledger.md documents it; existing members unchanged. Verify: a status line stamped [at=N] yields a record with at=N and its other members unchanged; the ledger suite passes.
  • Story 12, Fleet ledger records worker relaunches: a relaunch of an existing task writes a new ledger event carrying the task id, documented in docs/fleet-ledger.md; existing events unchanged. Verify: relaunching a test task writes exactly one relaunch record; a fresh dispatch writes none; the ledger suite passes.

Context: the captain approved Wake on 2026-11-21 ("I approve the wake question"), a firstmate throughput retrospective: a deterministic daily collector plus a thin /wake judgment skill. Approved defaults: daily note written automatically as a file, weekly /wake with chat summary; no cost capture yet; Sunday weekly cutoff; one manual retro first; changes land only in this fork (github.com/clarsen/firstmate), nothing offered to upstream firstmate. The product-owner ticket tree is ~/src/therealfirstmate/data/wake-value-model-revise/tickets (initiative-wake.md, value-model.md, epic-wake-daily-record/).

What Changed

  • task.status ledger records now include an optional at member, taken from the status line's [at=<epoch>] stamp when it is valid. The member is left out when the line has no valid stamp, and the existing state/key/text members are unchanged.
  • Adds a task.relaunched event with a new fm-fleet-ledger.sh relaunched <task> command. When the ledger is on, bin/fm-spawn.sh --relaunch writes this event once the replacement worker has launched; fm-control.sh relaunch goes through the same path. Fresh dispatches still write only task.dispatched. Before writing the event, the command records any status lines still waiting for that task.
  • Updates docs/fleet-ledger.md for both changes: the new event and the at member, an updated example, relaunch added to the capture triggers, and "relaunch events" removed from the deferred follow-ups. Adds tests to tests/fm-fleet-ledger.test.sh and tests/fm-control-relaunch.test.sh.

Risk Assessment

✅ Low: The change adds one optional at member and one new event to an opt-in ledger. Each relaunch path writes exactly one task.relaunched: fm-control relaunch calls fm-spawn --relaunch once, and fm-control has no emitter of its own. The at value comes from the shared parser in fm-classify-lib, so the existing members are unchanged.

Testing

I ran both ledger test suites and drove the real worker status command and fm-fleet-ledger.sh relaunched in a disposable marked lab home. Stamped status lines get at with the other members unchanged, and bad or missing stamps add no at. A relaunch writes exactly one task.relaunched record after capturing pending status, and bad arguments and the flag-off case write nothing. The fm-control and fm-spawn relaunch paths, and the fresh-dispatch case with no relaunch record, passed in the hermetic suites that run the real scripts with a stubbed tmux. A fully live tmux spawn and relaunch could not run because this host's tmux server crashes on capture-pane -p. I removed the lab home and its treehouse slot afterwards, and the worktree is clean.

  • Live validation: ✅ go - 5 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Story 4: a worker runs its generated status command with [at=1790000123] and the ledger gets a task.status record with at=1790000123 and unchanged state, key and text (lab home, synthetic lines) ✅ pass live live-ledger-cli.log: record {state:"working",key:null,text:" wake live probe",at:1790000123}; a stamped line with [key=lamp] keeps key "lamp" and adds at=1790000200
Story 4 adversarial: an unstamped line or a malformed [at=soon] stamp gives a record with no at member and the other members unchanged ✅ pass live live-ledger-cli.log: status_without_at = [" no stamp here", " malformed stamp"]
Story 12: fm-fleet-ledger.sh relaunched &lt;task&gt; writes exactly one task.relaunched record with the task id, after first capturing the task's pending status line ✅ pass live live-ledger-cli.log: the pending paused line (at=1790000300) is recorded, then {"event":"task.relaunched","task":"wake-live"}; relaunched count = 1
Story 12 adversarial: relaunched with a missing task, an extra argument, or an invalid task id is refused; with the ledger flag off it writes nothing ✅ pass live live-ledger-cli.log: rc=2 usage for all three bad calls; flag off leaves the ledger at 6 lines before and after
Story 12 end-to-end: fm-control.sh relaunch and a direct fm-spawn.sh --relaunch each write exactly one relaunch record, and a fresh dispatch writes none ✅ pass live bash tests/fm-control-relaunch.test.sh: 'fm-control relaunch records exactly one task.relaunched event' and 'fm-spawn --relaunch records exactly one task.relaunched event' pass. `bash tests/fm-fleet…
Story 12 fully live: a real Claude worker is spawned on a private lab tmux socket, then relaunched with fm-control, and the ledger shows one dispatched and one relaunched record ⏸️ untested no I built a lab home with a backlog item, a filled brief and a bare-origin project, then ran the real fm-spawn on the lab's own tmux socket. Every attempt failed with 'no server running', because this h…
Evidence: Live ledger CLI transcript (Story 4 and Story 12)
=== status command from generated brief ===
echo "{state} [at=<epoch>]: {one short line}" >> '~/tmp/fm-lab.TiwdqL/state/wake-live.status' && { [ ! -e '~/tmp/fm-lab.TiwdqL/config/fleet-ledger' ] || '{run-worktree}/bin/fm-fleet-ledger.sh' appended '~/tmp/fm-lab.TiwdqL/config' '~/tmp/fm-lab.TiwdqL/state/wake-live.status' >/dev/null 2>&1 || true; }

=== worker appends stamped / unstamped / malformed lines ===
$ echo "working [at=1790000123]: wake live probe" >> '~/tmp/fm-lab.TiwdqL/state/wake-live.status' && { [ ! -e '~/tmp/fm-lab.TiwdqL/con
rc=0
$ echo "needs-decision [at=1790000200] [key=lamp]: pick a lamp colour" >> '~/tmp/fm-lab.TiwdqL/state/wake-live.status' && { [ ! -e '~/
rc=0
$ echo "working: no stamp here" >> '~/tmp/fm-lab.TiwdqL/state/wake-live.status' && { [ ! -e '~/tmp/fm-lab.TiwdqL/config/fleet-ledger' 
rc=0
$ echo "working [at=soon]: malformed stamp" >> '~/tmp/fm-lab.TiwdqL/state/wake-live.status' && { [ ! -e '~/tmp/fm-lab.TiwdqL/config/fl
rc=0

=== status log ===
working [at=1790000123]: wake live probe
needs-decision [at=1790000200] [key=lamp]: pick a lamp colour
working: no stamp here
working [at=soon]: malformed stamp

=== ledger ===
{"v":1,"ts":1795322170,"event":"task.status","task":"wake-live","state":"working","key":null,"text":" wake live probe","at":1790000123}
{"v":1,"ts":1795322170,"event":"task.status","task":"wake-live","state":"needs-decision","key":"lamp","text":" pick a lamp colour","at":1790000200}
{"v":1,"ts":1795322170,"event":"task.status","task":"wake-live","state":"working","key":null,"text":" no stamp here"}
{"v":1,"ts":1795322170,"event":"task.status","task":"wake-live","state":"working","key":null,"text":" malformed stamp"}

=== pending line then relaunched (fm-fleet-ledger.sh relaunched) ===
rc=0
{"v":1,"ts":1795322171,"event":"task.status","task":"wake-live","state":"paused","key":null,"text":" pending before relaunch","at":1790000300}
{"v":1,"ts":1795322171,"event":"task.relaunched","task":"wake-live"}

=== adversarial: relaunched usage guards ===
usage: fm-fleet-ledger.sh dispatched <task> <kind> <project> <harness> <model> | relaunched <task> | pr_ready <task> <url> | merged <task> pr <url> | merged <task> local | cleaned_up <task> | capture | appended <config> <state>/<task>.status
rc=2 (no task)
usage: fm-fleet-ledger.sh dispatched <task> <kind> <project> <harness> <model> | relaunched <task> | pr_ready <task> <url> | merged <task> pr <url> | merged <task> local | cleaned_up <task> | capture | appended <config> <state>/<task>.status
rc=2 (extra arg)
usage: fm-fleet-ledger.sh dispatched <task> <kind> <project> <harness> <model> | relaunched <task> | pr_ready <task> <url> | merged <task> pr <url> | merged <task> local | cleaned_up <task> | capture | appended <config> <state>/<task>.status
rc=2 (bad task id)

=== counts ===
{"relaunched":1,"status_with_at":[["working",1790000123],["needs-decision",1790000200],["paused",1790000300]],"status_without_at":[" no stamp here"," malformed stamp"]}

=== flag off: relaunched writes nothing ===
rc=0 lines before=6 after=6
Evidence: Fleet ledger suite output
ok - flag on: dispatch, polled status lines, the local merge after its task's pending lines, and cleanup are recorded in order
ok - flag on: a PR merge is recorded once, after the task's pending status lines
ok - flag on: registering a PR records task.pr_ready with its full URL after the task's pending status lines, and the merge-time re-record adds nothing
ok - flag on: a worker's status command records its line at once, and the watcher backstop does not record it again
ok - status records carry valid worker event times without changing the existing members
ok - flag on, state override outside the home: the worker's status command records its line at once
ok - flag on, relative config override: a worker running elsewhere still records its line at once
ok - append failing: the worker's status command exits nonzero and records nothing
ok - ledger failing: the worker's status line still lands exactly, quietly, and the backstop records it later
ok - flag off: the worker's status command is a plain append and leaves no ledger file, offset, or lock
ok - flag off: the whole lifecycle leaves no ledger file, offset, or lock
rc=0
Evidence: Control relaunch suite output
ok - fm-spawn --relaunch: tracked opencode wiring is retired as on main
ok - fm-control removes the dialog file after exit and after relaunch
ok - fm-control exit removes the dialog file before it releases the control lock
ok - fm-control relaunch: a same-harness relaunch replaces the agent in the same endpoint and worktree
ok - fm-control relaunch records exactly one task.relaunched event
ok - fm-spawn --relaunch records exactly one task.relaunched event
ok - fm-control relaunch: pending composer text refuses before the exit command is typed
ok - fm-control relaunch: an unreadable composer fails safe before the exit command is typed
ok - fm-control relaunch: a linked spawning home preserves committed and unfinished work in the recorded copy
ok - fm-control relaunch: an armed PR poll survives replacement launch publication
ok - fm-control relaunch: a traced replacement keeps an armed PR poll authenticated
ok - fm-control relaunch: delivery and concurrent task metadata publication serialize
ok - fm-control relaunch: disabling tracing clears metadata and pane context
ok - fm-control relaunch: progress and the Firstmate-worktree worker identity reach the replacement
ok - fm-control relaunch: the progress note's inbox listing is silent on an empty inbox
ok - fm-control relaunch: a ship task refuses without the progress note its replacement needs
ok - fm-control relaunch: switching harness is one ordinary relaunch, and the old wiring goes with the old agent
ok - fm-control relaunch: a refused relaunch onto polytoken keeps the project's own hook layer and the running agent
ok - fm-control relaunch: a refused polytoken profile leaves the running agent untouched
ok - fm-spawn --relaunch: retiring a raw polytoken launch's wiring keeps the project's own layers
ok - fm-control relaunch: a harness switch resets model and effort unless they are named too
ok - fm-control relaunch: a prefixed recorded harness can switch adapters transactionally
ok - fm-control relaunch: a prefixed command requires an explicit replacement harness
ok - fm-control relaunch: a same-harness relaunch keeps the profile axes it was running with
ok - native Ultra relaunch preserves its profile and rejects an unsupported model before stopping
ok - fm-control relaunch: a signed-out worker account pin refuses before the old agent stops
ok - fm-control relaunch: the replacement follows the home's current worker account pin
ok - fm-control relaunch: mate pins are re-read for Claude and Pi, and unusable pins refuse before stopping the agent
ok - fm-control relaunch: a Pi replacement keeps the home's tool exclusions
ok - fm-control relaunch: exclusion-list refusals happen before the running agent stops
ok - fm-control relaunch: explicit model and effort win over the recorded ones
ok - fm-control relaunch: refuses to relaunch onto an adapter with no verified mechanics
ok - fm-control relaunch: the retired incarnation's global turn-end token is revoked
ok - fm-control relaunch: wiring cleanup failure refuses replacement arming
ok - fm-control-lib: one owner resolves each harness's turn-end registry entry, and refuses a malformed token
ok - fm-control relaunch: a secondmate relaunch re-resolves its durable configured harness pin
ok - fm-control relaunch: a claude secondmate keeps settings.local.json and retires the state settings file and the Stop pointer
ok - fm-control relaunch: a mate with a per-mate override line lands on that override, not the default pin
ok - fm-control relaunch: a mate with no override line still resolves the default pin
ok - fm-control relaunch: a legacy secondmate pin file still relaunches the mate onto its first line
ok - fm-control relaunch: an unparseable secondmate pin refuses before anything is stopped
ok - fm-control relaunch: invalid configured effort is ignored before stop
ok - fm-control relaunch: an adapter unverified for this task kind refuses before the agent is stopped
ok - fm-control relaunch: explicit secondmate harness resets unnamed profile axes
ok - fm-control relaunch: a ship task keeps its recorded harness instead of re-reading crew config
ok - fm-spawn --relaunch: with no explicit harness it reuses the task's recorded one, never the crew default
ok - fm-spawn --relaunch: a promoted scout with a recorded custom branch relaunches on it instead of being refused
ok - fm-promote/fm-spawn --relaunch: the current ship contract supersedes stale scout delivery text
ok - fm-spawn --relaunch: wiring armed under a prefixed harness name is still retired
ok - fm-spawn --relaunch: switching away from muse retires its session binding
ok - fm-spawn --relaunch: switching away from cursor retires its session binding
ok - fm-control relaunch: an unaccountable local copy refuses before the agent is touched
ok - fm-control relaunch: a worker with nothing to work from is never launched
ok - fm-control relaunch: a refusal before the agent is stopped leaves the durable record untouched
ok - fm-control relaunch: checkpoint inspection failures refuse before stopping
ok - fm-control relaunch: a launch failure after the stop keeps the prior record and reports the real state
ok - fm-control relaunch: unpublished rollback keeps concurrent durable metadata
ok - fm-control relaunch: post-publication failure keeps the new durable record
ok - fm-control relaunch: partial stop reconciles actual agent state
ok - fm-control relaunch: failed journal replacement preserves durable phase
ok - fm-spawn relaunch: prepublication abort removes replacement state
ok - fm-control relaunch: the checkpoint records the exact unlanded work it preserved
ok - fm-control relaunch: a secondmate's child work is accounted for and its charter is left alone
ok - fm-control relaunch: a secondmate home that is not this secondmate's is refused
ok - fm-control relaunch: unreadable child records fail checkpoint
ok - fm-control relaunch: unlistable state fails checkpoint
ok - fm-control relaunch: a vanished watcher scratch file does not fail the child-record checkpoint
ok - fm-control relaunch: two control actions on one task serialize instead of interleaving
ok - fm-spawn relaunch: direct entry participates in lifecycle serialization
ok - fm-promote: promotion participates in lifecycle serialization
ok - fm-spawn --relaunch: refuses to launch a second agent into a live endpoint
ok - fm-spawn --relaunch: symlinked records refuse before inspection
ok - fm-spawn --relaunch: keeps its early meta lock continuous
ok - fm-spawn --relaunch: pending closes refuse before replacement begins
ok - fm-spawn --relaunch: every identity axis comes from the record, and a contradicting flag refuses
ok - fm-spawn --relaunch: an unrecorded task is refused
ok - fm-spawn --relaunch: refuses to start a replacement outside the copy holding its work
ok - tmux: a window absent from its session refuses both verbs rather than being assumed gone
ok - tmux: an unfindable session refuses both verbs, so a live agent is never duplicated
ok - tmux: a dead server on this socket refuses both verbs rather than proving absence
ok - reclaim: an unclassifiable endpoint is still refused, so two agents cannot share one
not ok - Herdr Pi relaunch should complete (pi registration)
error: pi executable not found on PATH; install it or select a different verified harness: expected exit 0, got 1
rc=1
Evidence: Attempted live tmux spawn/relaunch transcript (host tmux crash)

=== fresh spawn (fm-spawn.sh wake-live3 --harness claude) ===
fm-gate-refuse: gate agent lifecycle permitted only against lab home ~/tmp/fm-lab.TiwdqL
notice: wake-live3 ships mode=local-only while the standing posture for sample is no-mistakes - less rigor than the captain's standing posture; proceed only on a current explicit captain instruction or an intake judgment you can state
no server running on ~/tmp/fm-lab.TiwdqL/tmux/tmux-20690/fm-lab
warning: leaving task wake-live3's slot claim on ~/.treehouse/sample-9c9ba2/1/sample in place; the Treehouse project lock is no longer held, so the next spawn's claim replaces it
spawn rc=1

=== ledger after fresh dispatch ===
cat: ~/tmp/fm-lab.TiwdqL/state/fleet-ledger.jsonl: No such file or directory

=== waiting for the worker's status line ===

=== ledger after worker status ===
cat: ~/tmp/fm-lab.TiwdqL/state/fleet-ledger.jsonl: No such file or directory

=== worker pane ===
no server running on ~/tmp/fm-lab.TiwdqL/tmux/tmux-20690/fm-lab

=== relaunch (fm-control.sh wake-live3 relaunch) ===
fm-gate-refuse: gate agent lifecycle permitted only against lab home ~/tmp/fm-lab.TiwdqL
error: no task 'wake-live3' in ~/tmp/fm-lab.TiwdqL/state (fm-control resolves an exact task id only)
relaunch rc=1

=== ledger after relaunch ===
cat: ~/tmp/fm-lab.TiwdqL/state/fleet-ledger.jsonl: No such file or directory

=== relaunched record count ===
jq: error: Could not open file ~/tmp/fm-lab.TiwdqL/state/fleet-ledger.jsonl: No such file or directory
0

=== dispatched record count ===
jq: error: Could not open file ~/tmp/fm-lab.TiwdqL/state/fleet-ledger.jsonl: No such file or directory
0

=== status file after relaunch ===
cat: ~/tmp/fm-lab.TiwdqL/state/wake-live3.status: No such file or directory

=== final ledger ===
cat: ~/tmp/fm-lab.TiwdqL/state/fleet-ledger.jsonl: No such file or directory

=== worker pane after relaunch ===
no server running on ~/tmp/fm-lab.TiwdqL/tmux/tmux-20690/fm-lab

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 warning
  • ⚠️ bin/fm-control.sh:1268 - Only fm-control.sh relaunch writes task.relaunched. The fm-spawn.sh --relaunch header (bin/fm-spawn.sh:67-75) still documents a supported direct path, "deliberately re-launching an already-stopped task". That path replaces the worker for an existing task, and bin/fm-spawn.sh:8536 skips dispatched when RELAUNCH=1, so it writes no ledger event at all. A captain who relaunches a stopped task this way leaves no record, which conflicts with Story 12 ("a relaunch of an existing task writes a new ledger event"). The docs row for task.relaunched (docs/fleet-ledger.md:33) and the producer comment (bin/fm-fleet-ledger.sh:15, "successful replacement only") describe only the control-plane path. One remedy is to write the event from fm-spawn's existing ledger line when RELAUNCH=1. The trade-off is that the event would then fire when the replacement is launched rather than after it is confirmed alive. The other remedy is to document that a direct fm-spawn relaunch is not recorded. Which semantics to choose is a product decision.

🔧 Fix applied.
1 warning still open:

  • ⚠️ bin/fm-control.sh:1268 - Only fm-control.sh relaunch writes task.relaunched. The fm-spawn.sh --relaunch header (bin/fm-spawn.sh:67-75) still documents a supported direct path, "deliberately re-launching an already-stopped task". That path replaces the worker for an existing task, and bin/fm-spawn.sh:8536 skips dispatched when RELAUNCH=1, so it writes no ledger event at all. A captain who relaunches a stopped task this way leaves no record, which conflicts with Story 12 ("a relaunch of an existing task writes a new ledger event"). The docs row for task.relaunched (docs/fleet-ledger.md:33) and the producer comment (bin/fm-fleet-ledger.sh:15, "successful replacement only") describe only the control-plane path. One remedy is to write the event from fm-spawn's existing ledger line when RELAUNCH=1. The trade-off is that the event would then fire when the replacement is launched rather than after it is confirmed alive. The other remedy is to document that a direct fm-spawn relaunch is not recorded. Which semantics to choose is a product decision.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 5 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Story 4: a worker runs its generated status command with [at=1790000123] and the ledger gets a task.status record with at=1790000123 and unchanged state, key and text (lab home, synthetic lines) ✅ pass live live-ledger-cli.log: record {state:"working",key:null,text:" wake live probe",at:1790000123}; a stamped line with [key=lamp] keeps key "lamp" and adds at=1790000200
Story 4 adversarial: an unstamped line or a malformed [at=soon] stamp gives a record with no at member and the other members unchanged ✅ pass live live-ledger-cli.log: status_without_at = [" no stamp here", " malformed stamp"]
Story 12: fm-fleet-ledger.sh relaunched &lt;task&gt; writes exactly one task.relaunched record with the task id, after first capturing the task's pending status line ✅ pass live live-ledger-cli.log: the pending paused line (at=1790000300) is recorded, then {"event":"task.relaunched","task":"wake-live"}; relaunched count = 1
Story 12 adversarial: relaunched with a missing task, an extra argument, or an invalid task id is refused; with the ledger flag off it writes nothing ✅ pass live live-ledger-cli.log: rc=2 usage for all three bad calls; flag off leaves the ledger at 6 lines before and after
Story 12 end-to-end: fm-control.sh relaunch and a direct fm-spawn.sh --relaunch each write exactly one relaunch record, and a fresh dispatch writes none ✅ pass live bash tests/fm-control-relaunch.test.sh: 'fm-control relaunch records exactly one task.relaunched event' and 'fm-spawn --relaunch records exactly one task.relaunched event' pass. `bash tests/fm-fleet…
Story 12 fully live: a real Claude worker is spawned on a private lab tmux socket, then relaunched with fm-control, and the ledger shows one dispatched and one relaunched record ⏸️ untested no I built a lab home with a backlog item, a filled brief and a bare-origin project, then ran the real fm-spawn on the lab's own tmux socket. Every attempt failed with 'no server running', because this h…
  • bash tests/fm-fleet-ledger.test.sh (rc=0, includes the new at-stamp and no-relaunch-on-fresh-dispatch assertions)
  • bash tests/fm-control-relaunch.test.sh: both new ledger relaunch tests pass. The suite as a whole exits 1 at the later 'Herdr Pi relaunch' test, which fails because pi is not on PATH on this host; that test is unrelated to this change.
  • Live: bin/fm-lab-home.sh create, then bin/fm-brief.sh wake-live sample --mode local-only in the lab home, then the generated worker status command run with stamped, unstamped and malformed lines
  • Live: bin/fm-fleet-ledger.sh relaunched wake-live with a pending status line, the usage-guard cases, and the flag-off case
  • Attempted live: real bin/fm-spawn.sh ... --harness claude on a private tmux -L fm-lab socket; blocked by the host tmux server crashing on capture-pane
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@clarsen
clarsen merged commit 878b272 into main Nov 22, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant