Skip to content

feat(bin): emit hold, reply, and wake spans to complete return-path tracing - #6

Merged
andrewesweet merged 6 commits into
mainfrom
fm/fm-trace-return-spans
Sep 13, 2026
Merged

andrewesweet merged 6 commits into
mainfrom
fm/fm-trace-return-spans

Conversation

@andrewesweet

@andrewesweet andrewesweet commented Sep 13, 2026 •

Copy link
Copy Markdown
Owner

Intent

Implement PR 6 of the accepted Firstmate end-to-end tracing design to complete the return path: firstmate.hold spans cover recorded hold time through answer/release or verified reconciliation; firstmate.reply spans cover delivered secondmate requests through correlated reply settlement in the parent home; firstmate.wake spans cover task-keyed queued events through successful acknowledgement. Use the task or secondmate's existing trace as appropriate. Do not emit taskless heartbeats or per-poll activity. Reuse bounded best-effort OTLP emission under the existing default-off decision, and preserve hold/answer, reply-settlement and acknowledgement correctness. Ship only to andrewesweet/firstmate, never upstream.

What Changed

  • bin/fm-captain-hold.sh emits a firstmate.hold span after a successful answer, release, or reconcile close is durably published, covering the recorded hold-set time through the settlement with firstmate.hold.close_mode and a bounded firstmate.hold.reason; --origin calls join the origin task's trace and idempotent replays emit nothing.
  • bin/fm-pending-reply-lib.sh emits one firstmate.reply span per newly settled pending-reply record from the parent home's meta, covering the delivered epoch through settlement with firstmate.corr and firstmate.reply.via; bin/fm-wake-drain.sh partitions acknowledged rows in one awk pass, emits a firstmate.wake span per consumed task-keyed row (kind, seq, key) after the acknowledgement commit, and captures a telemetry-only state/.wake-trace.<task> at presentation so tasks torn down before acknowledgement still get their span.
  • bin/fm-trace-span-lib.sh catalogues the three new spans; AGENTS.md, docs/trace-context.md, and docs/verification/trace-context.md document the wake capture and the new entries; tests added in tests/fm-captain-hold-lifecycle.test.sh, tests/fm-pending-reply.test.sh, tests/fm-remote-reply.test.sh, and tests/fm-wake-queue.test.sh, and the remote transport lanes fixture now copies the trace span lib and its deps.

Risk Assessment

✅ Low: Each new emission sits after its durable settlement or acknowledgement commit, always returns 0, is gated by the frozen session decision and a validated carrier, and the single-pass queue partition preserves the prior actor/cutoff/ownership predicate byte-for-byte; the only new state is the telemetry-only .wake-trace capture whose task name is validated by fm_wake_status_key_map and which acknowledgement discards, and every new test drives real entrypoints with a recording fake curl.

Testing

Ran the six suites the change touches (fm-trace-span-lib, fm-captain-hold-lifecycle, fm-pending-reply, fm-wake-queue, fm-remote-reply, fm-remote-transport-lanes): all pass once the session's leaked FM_* env vars are unset (fm-captain-hold-lifecycle's pre-existing secondmate teardown test fails identically on the base commit under that leaked FM_PUBLIC_FOLLOWUP_PRIMARY_HOME, so it is an environment artefact, not a regression). Then drove the product live against a real Python OTLP/HTTP receiver with real curl: wake presentation writes captures and posts nothing; acknowledgement posts exactly one firstmate.wake per task-keyed signal row (none for stale/check/heartbeat), both spans share one end instant, the torn-down task's span uses the capture, captures are discarded, replay posts nothing, an unreachable receiver and a disabled home change nothing; captain answer, origin-linked answer and --release each post one firstmate.hold on the right trace from the FM_CAPTAIN_HOLD_NOW stamp with close_mode and a 160-char-bounded reason, replay and refused answer post nothing; fm-send creates the pending record and the watcher tick settles the correlated reply posting one firstmate.reply from delivered_epoch with corr and via=status, replay nothing, receiver-down settlement still resolves. Reconcile close and the remote fake-SSH chain are covered by the passing suites rather than a separate live drive. No UI surface, so no screenshots.

  • Live validation: ✅ go - 18 of 18 scenarios driven live against the product
Scenario Result Live Evidence
Wake acknowledgement posts one firstmate.wake per task-keyed signal row on the task trace, starting at queue time; stale/check/heartbeat rows post nothing ✅ pass live live-wake-hold-transcript.txt, otlp-received.jsonl (5 queued rows, 2 spans, traceIds match carriers, startTimeUnixNano = row epoch)
Presentation drain emits no span (no per-poll activity) and only writes telemetry captures ✅ pass live live-wake-hold-transcript.txt: 'spans received after presentation: 0', captures listed
Task torn down between presentation and ack still gets its wake span via the captured carrier; every span of the batch shares one end instant; capture discarded ✅ pass live live-wake-hold-transcript.txt: gone.meta removed before ack; span on trace aaaa…ab; both endTimeUnixNano 1789295672474000000; '.wake-trace.*: No such file'
Replaying an already-acknowledged batch posts no wake spans ✅ pass live live-wake-hold-transcript.txt: 'spans received after replay: 2'
Adversarial: unreachable OTLP receiver never blocks or slows wake acknowledgement beyond the bounded timeout; queue still cleared silently ✅ pass live live-wake-hold-transcript.txt: 'ack rc=0 stderr_bytes=0 elapsed_ms=219 queue_bytes=0'
Adversarial: unwritable wake capture is silent on presentation stderr and blocks neither presentation nor acknowledgement ✅ pass live bash tests/fm-wake-queue.test.sh test_wake_spans_survive_teardown_and_share_one_acknowledgement_instant (real drain executable, .wake-trace.kept.tmp as directory)
Disabled trace session: acknowledgement writes no captures and posts nothing ✅ pass live live-wake-hold-transcript.txt: 'captures=0 spans_before=2 spans_after=2'
Captain answer posts one firstmate.hold on the held task's trace from the recorded hold-set stamp with close_mode=answered and the reason ✅ pass live otlp-received.jsonl span 3; transcript start_utc 2026-06-01T12:00:00Z matches FM_CAPTAIN_HOLD_NOW
Idempotent answer replay of a completed close posts nothing ✅ pass live live-wake-hold-transcript.txt: replay rc=0, exactly 3 hold spans total
Separate --origin captain call joins the same-home origin task's trace at its own hold-set time ✅ pass live otlp-received.jsonl: traceId 6666…67 parent 8888…89 start 2026-06-01T13:00:00Z
--release posts close_mode=released with reason bounded to 160 chars ✅ pass live transcript: close_mode released, reason len=160 from a 200-char --reason
Refused answer (absent task) posts no hold span ✅ pass live transcript: 'refused rc=1', spans_before=5 spans_after=5
Verified reconcile close posts close_mode=reconciled; taskless captain call and disabled session post nothing ✅ pass live bash tests/fm-captain-hold-lifecycle.test.sh test_close_paths_emit_hold_spans_over_the_recorded_hold_time (real hold/answer/reconcile entrypoints, real tasks-axi backend)
Delivered secondmate request settling on a correlated reply posts one firstmate.reply on the secondmate trace from delivered_epoch with firstmate.corr and firstmate.reply.via=status; settlement correc… ✅ pass live live-reply-transcript.txt, otlp-received-reply.jsonl: phase=resolved, span start 1789295743000ms = delivered_epoch
Replayed watcher tick on an already-resolved reply posts nothing ✅ pass live live-reply-transcript.txt: 'second tick ... spans=2'
Adversarial: receiver down still resolves the reply within the bounded timeout ✅ pass live live-reply-transcript.txt: 'tick rc=0 elapsed_ms=307 phase=resolved'
Remote route: settlement of a mirrored delta emits the reply span from the parent home, never the remote host ✅ pass live bash tests/fm-remote-reply.test.sh (real fake-SSH chain, ALL TESTS PASSED)
Remote transport lanes fixture worker sources fm-trace-span-lib.sh and its siblings (fix from latest commit) ✅ pass live bash tests/fm-remote-transport-lanes.test.sh ALL TESTS PASSED
Evidence: Live wake + hold transcript (real drain/hold scripts, real curl, real OTLP receiver)

Source: Live wake + hold transcript (real drain/hold scripts, real curl, real OTLP receiver)

\### SCENARIO wake: presentation captures, ack emits task-keyed spans only
--- queue before presentation:
1789295671	1	signal	traced.status	signal: /tmp/nm-live.CjDHbj/live-wake/state/traced.status
1789295671	2	signal	gone.status	signal: /tmp/nm-live.CjDHbj/live-wake/state/gone.status
1789295671	3	stale	firstmate:traced	stale: firstmate:traced
1789295671	4	check	startup-network	check: startup-network still pending
1789295672	5	heartbeat	heartbeat	heartbeat
--- presentation stdout:
1789295671	1	signal	traced.status	signal: /tmp/nm-live.CjDHbj/live-wake/state/traced.status
1789295671	2	signal	gone.status	signal: /tmp/nm-live.CjDHbj/live-wake/state/gone.status
1789295671	3	stale	firstmate:traced	stale: firstmate:traced
1789295671	4	check	startup-network	check: startup-network still pending
1789295672	5	heartbeat	heartbeat	heartbeat
--- presentation stderr:
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 5 --recovery-generation 3479714.1789295671.NhQQPM
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  2 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
●  This is a supervision warning only; the guarded operation WILL still run.
●  After draining queued wakes, watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.
--- spans received after presentation: 0
--- captures written:
-rw------- 1 andre andre 100 Sep 13 11:34 /tmp/nm-live.CjDHbj/live-wake/state/.wake-trace.gone
-rw------- 1 andre andre 156 Sep 13 11:34 /tmp/nm-live.CjDHbj/live-wake/state/.wake-trace.traced
traceparent=00-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab-bbbbbbbbbbbbbbbc-01
kind=ship
endpoint_task_id=gone
--- teardown removes gone.meta before ack
ack rc=0
--- queue after ack: 0 bytes
--- captures after ack:
ls: cannot access '/tmp/nm-live.CjDHbj/live-wake/state/.wake-trace.*': No such file or directory
--- spans received after ack: 2
{"name":"firstmate.wake","traceId":"11111111111111111111111111111112","parentSpanId":"3333333333333334","startTimeUnixNano":"1789295671000000000","endTimeUnixNano":"1789295672474000000","attrs":{"firstmate.wake.kind":"signal","firstmate.wake.seq":"1","firstmate.wake.key":"traced.status"}}
{"name":"firstmate.wake","traceId":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab","parentSpanId":"bbbbbbbbbbbbbbbc","startTimeUnixNano":"1789295671000000000","endTimeUnixNano":"1789295672474000000","attrs":{"firstmate.wake.kind":"signal","firstmate.wake.seq":"2","firstmate.wake.key":"gone.status"}}
--- replay ack (must emit nothing new)
replay rc=0
--- spans received after replay: 2

\### SCENARIO wake: unreachable receiver never blocks acknowledgement
ack rc=0 stderr_bytes=0 elapsed_ms=219 queue_bytes=0

\### SCENARIO wake: disabled home emits nothing
ack rc=0 captures=0 spans_before=2 spans_after=2

\### SCENARIO hold: answer / release / origin-linked emit firstmate.hold; replay emits nothing
traced-call
answered: traced-call
answer rc=0
--- replay answer:
answered: traced-call
replay rc=0
origin-call
answered: origin-call
traced-work
released: traced-work
--- hold spans received (expected 3: answered, answered(origin trace), released; replay none):
{"name":"firstmate.hold","traceId":"11111111111111111111111111111112","parentSpanId":"3333333333333334","start_utc":"2026-06-01T12:00:00Z","attrs":{"firstmate.hold.close_mode":"answered","firstmate.hold.reason":"captain must choose the export shape"}}
{"name":"firstmate.hold","traceId":"66666666666666666666666666666667","parentSpanId":"8888888888888889","start_utc":"2026-06-01T13:00:00Z","attrs":{"firstmate.hold.close_mode":"answered","firstmate.hold.reason":"origin needs a ruling"}}
{"name":"firstmate.hold","traceId":"22222222222222222222222222222224","parentSpanId":"4444444444444448","start_utc":"2026-06-02T08:30:00Z","attrs":{"firstmate.hold.close_mode":"released","firstmate.hold.reason":"len=160"}}
--- resource of last span:
{"service.name":"firstmate","firstmate.task.id":"traced-work","firstmate.home":"/tmp/nm-live.CjDHbj/live-hold","firstmate.task.kind":"ship"}
--- refused answer (unknown task) emits nothing:
fm-captain-hold: captain-held task no-such-task is absent from this home's configured backlog (data directory /tmp/nm-live.CjDHbj/live-hold/data)
refused rc=1
spans_before=5 spans_after=5
Evidence: OTLP requests received by the receiver during wake + hold scenarios (JSONL, one POST per line)

Source: OTLP requests received by the receiver during wake + hold scenarios (JSONL, one POST per line)

{"path": "/v1/traces", "content_type": "application/json", "body": {"resourceSpans": [{"resource": {"attributes": [{"key": "service.name", "value": {"stringValue": "firstmate"}}, {"key": "firstmate.task.id", "value": {"stringValue": "traced"}}, {"key": "firstmate.project", "value": {"stringValue": "sample"}}, {"key": "firstmate.home", "value": {"stringValue": "/tmp/nm-live.CjDHbj/live-wake"}}, {"key": "firstmate.task.kind", "value": {"stringValue": "ship"}}]}, "scopeSpans": [{"scope": {"name": "firstmate"}, "spans": [{"traceId": "11111111111111111111111111111112", "spanId": "82e71c1773d8e5bd", "parentSpanId": "3333333333333334", "name": "firstmate.wake", "kind": 1, "startTimeUnixNano": "1789295671000000000", "endTimeUnixNano": "1789295672474000000", "attributes": [{"key": "firstmate.wake.kind", "value": {"stringValue": "signal"}}, {"key": "firstmate.wake.seq", "value": {"stringValue": "1"}}, {"key": "firstmate.wake.key", "value": {"stringValue": "traced.status"}}]}]}]}]}}
{"path": "/v1/traces", "content_type": "application/json", "body": {"resourceSpans": [{"resource": {"attributes": [{"key": "service.name", "value": {"stringValue": "firstmate"}}, {"key": "firstmate.task.id", "value": {"stringValue": "gone"}}, {"key": "firstmate.home", "value": {"stringValue": "/tmp/nm-live.CjDHbj/live-wake"}}, {"key": "firstmate.task.kind", "value": {"stringValue": "ship"}}]}, "scopeSpans": [{"scope": {"name": "firstmate"}, "spans": [{"traceId": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab", "spanId": "7f957cd279011ca1", "parentSpanId": "bbbbbbbbbbbbbbbc", "name": "firstmate.wake", "kind": 1, "startTimeUnixNano": "1789295671000000000", "endTimeUnixNano": "1789295672474000000", "attributes": [{"key": "firstmate.wake.kind", "value": {"stringValue": "signal"}}, {"key": "firstmate.wake.seq", "value": {"stringValue": "2"}}, {"key": "firstmate.wake.key", "value": {"stringValue": "gone.status"}}]}]}]}]}}
{"path": "/v1/traces", "content_type": "application/json", "body": {"resourceSpans": [{"resource": {"attributes": [{"key": "service.name", "value": {"stringValue": "firstmate"}}, {"key": "firstmate.task.id", "value": {"stringValue": "traced-call"}}, {"key": "firstmate.project", "value": {"stringValue": "sample"}}, {"key": "firstmate.home", "value": {"stringValue": "/tmp/nm-live.CjDHbj/live-hold"}}, {"key": "firstmate.task.kind", "value": {"stringValue": "ship"}}, {"key": "firstmate.harness", "value": {"stringValue": "codex"}}]}, "scopeSpans": [{"scope": {"name": "firstmate"}, "spans": [{"traceId": "11111111111111111111111111111112", "spanId": "2f55802635fc5e22", "parentSpanId": "3333333333333334", "name": "firstmate.hold", "kind": 1, "startTimeUnixNano": "1780315200000000000", "endTimeUnixNano": "1789295675525000000", "attributes": [{"key": "firstmate.hold.close_mode", "value": {"stringValue": "answered"}}, {"key": "firstmate.hold.reason", "value": {"stringValue": "captain must choose the export shape"}}]}]}]}]}}
{"path": "/v1/traces", "content_type": "application/json", "body": {"resourceSpans": [{"resource": {"attributes": [{"key": "service.name", "value": {"stringValue": "firstmate"}}, {"key": "firstmate.task.id", "value": {"stringValue": "traced-origin"}}, {"key": "firstmate.project", "value": {"stringValue": "sample"}}, {"key": "firstmate.home", "value": {"stringValue": "/tmp/nm-live.CjDHbj/live-hold"}}, {"key": "firstmate.task.kind", "value": {"stringValue": "ship"}}]}, "scopeSpans": [{"scope": {"name": "firstmate"}, "spans": [{"traceId": "66666666666666666666666666666667", "spanId": "a66ef3b53e0a0e26", "parentSpanId": "8888888888888889", "name": "firstmate.hold", "kind": 1, "startTimeUnixNano": "1780318800000000000", "endTimeUnixNano": "1789295677969000000", "attributes": [{"key": "firstmate.hold.close_mode", "value": {"stringValue": "answered"}}, {"key": "firstmate.hold.reason", "value": {"stringValue": "origin needs a ruling"}}]}]}]}]}}
{"path": "/v1/traces", "content_type": "application/json", "body": {"resourceSpans": [{"resource": {"attributes": [{"key": "service.name", "value": {"stringValue": "firstmate"}}, {"key": "firstmate.task.id", "value": {"stringValue": "traced-work"}}, {"key": "firstmate.home", "value": {"stringValue": "/tmp/nm-live.CjDHbj/live-hold"}}, {"key": "firstmate.task.kind", "value": {"stringValue": "ship"}}]}, "scopeSpans": [{"scope": {"name": "firstmate"}, "spans": [{"traceId": "22222222222222222222222222222224", "spanId": "10303321f2daa631", "parentSpanId": "4444444444444448", "name": "firstmate.hold", "kind": 1, "startTimeUnixNano": "1780389000000000000", "endTimeUnixNano": "1789295679885000000", "attributes": [{"key": "firstmate.hold.close_mode", "value": {"stringValue": "released"}}, {"key": "firstmate.hold.reason", "value": {"stringValue": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}}]}]}]}]}}
Evidence: Live reply transcript (fm-send, watcher tick settlement, real OTLP receiver)

Source: Live reply transcript (fm-send, watcher tick settlement, real OTLP receiver)

\### SCENARIO reply: delivered secondmate request settles on correlated reply, emits firstmate.reply on the secondmate trace
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
●  This is a supervision warning only; the requested message WILL still be sent.
●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
fm-send: doorbell not typed because the agent in sess:fm-hibit has exited; the steer is durably recorded at /tmp/nm-live-reply.jhwRzB/parent/state/hibit.inbox/001.msg for recovery (stuck-crewmate-recovery), and the watcher will not re-ring a dead pane
--- pending-reply record after send:
schema=fm-pending-reply.v1
corr_id=531b8a385a440d60
task_id=hibit
parent_home=/tmp/nm-live-reply.jhwRzB/parent
parent_status=/tmp/nm-live-reply.jhwRzB/parent/state/hibit.status
parent_status_scan_signature=
request_summary=audit the build
created_epoch=1789295743
phase=awaiting_report
turn_seen_busy=0
request_turn_completed_epoch=
recovery_attempted_epoch=
recovery_sender_pid=
recovery_sender_identity=
recovery_sent_epoch=
recovery_delivery_outcome=
recovery_turn_seen_busy=0
recovery_turn_completed_epoch=
escalated_epoch=
resolved_epoch=
resolved_via=
wrong_home_hits=0
wrong_home_first_sighting=
wrong_home_sightings=
wrong_home_scan_signature=
grace_secs=0
delivered_epoch=1789295743
--- spans so far: 1
--- secondmate replies with correlated status line
--- watcher tick (fm_pending_reply_tick, as bin/fm-watch.sh calls it)
tick rc=0
--- record after settlement:
delivered_epoch=1789295743
phase=resolved
resolved_epoch=1789295743
resolved_via=status
--- spans received: 2
{"name":"firstmate.steer","traceId":"11111111111111111111111111111112","parentSpanId":"3333333333333334","start_utc":"2026-09-13T10:35:43Z","end_utc":"2026-09-13T10:35:43Z","attrs":{"firstmate.plane":"inbox","firstmate.corr":"531b8a385a440d60","firstmate.inbox.seq":"001"}}
{"name":"firstmate.reply","traceId":"11111111111111111111111111111112","parentSpanId":"3333333333333334","start_utc":"2026-09-13T10:35:43Z","end_utc":"2026-09-13T10:35:43Z","attrs":{"firstmate.corr":"531b8a385a440d60","firstmate.reply.via":"status"}}
{"service.name":"firstmate","firstmate.task.id":"hibit","firstmate.project":"sm","firstmate.home":"/tmp/nm-live-reply.jhwRzB/parent","firstmate.task.kind":"secondmate","firstmate.secondmate.id":"hibit","firstmate.harness":"echo"}
{"service.name":"firstmate","firstmate.task.id":"hibit","firstmate.project":"sm","firstmate.home":"/tmp/nm-live-reply.jhwRzB/parent","firstmate.task.kind":"secondmate","firstmate.secondmate.id":"hibit","firstmate.harness":"echo"}
record delivered_epoch=1789295743 span_start_ms=1789295743629000000
1789295743000 corr=531b8a385a440d60
--- second tick (replay) must emit nothing
tick rc=0 spans=2
--- adversarial: receiver down, settlement still lands
tick rc=0 elapsed_ms=307 phase=resolved
Evidence: OTLP requests received during reply scenario (steer span from send, reply span from settlement)

Source: OTLP requests received during reply scenario (steer span from send, reply span from settlement)

{"path": "/v1/traces", "content_type": "application/json", "body": {"resourceSpans": [{"resource": {"attributes": [{"key": "service.name", "value": {"stringValue": "firstmate"}}, {"key": "firstmate.task.id", "value": {"stringValue": "hibit"}}, {"key": "firstmate.project", "value": {"stringValue": "sm"}}, {"key": "firstmate.home", "value": {"stringValue": "/tmp/nm-live-reply.jhwRzB/parent"}}, {"key": "firstmate.task.kind", "value": {"stringValue": "secondmate"}}, {"key": "firstmate.secondmate.id", "value": {"stringValue": "hibit"}}, {"key": "firstmate.harness", "value": {"stringValue": "echo"}}]}, "scopeSpans": [{"scope": {"name": "firstmate"}, "spans": [{"traceId": "11111111111111111111111111111112", "spanId": "c6bea30b6c0a3a50", "parentSpanId": "3333333333333334", "name": "firstmate.steer", "kind": 1, "startTimeUnixNano": "1789295743629000000", "endTimeUnixNano": "1789295743629000000", "attributes": [{"key": "firstmate.plane", "value": {"stringValue": "inbox"}}, {"key": "firstmate.corr", "value": {"stringValue": "531b8a385a440d60"}}, {"key": "firstmate.inbox.seq", "value": {"stringValue": "001"}}]}]}]}]}}
{"path": "/v1/traces", "content_type": "application/json", "body": {"resourceSpans": [{"resource": {"attributes": [{"key": "service.name", "value": {"stringValue": "firstmate"}}, {"key": "firstmate.task.id", "value": {"stringValue": "hibit"}}, {"key": "firstmate.project", "value": {"stringValue": "sm"}}, {"key": "firstmate.home", "value": {"stringValue": "/tmp/nm-live-reply.jhwRzB/parent"}}, {"key": "firstmate.task.kind", "value": {"stringValue": "secondmate"}}, {"key": "firstmate.secondmate.id", "value": {"stringValue": "hibit"}}, {"key": "firstmate.harness", "value": {"stringValue": "echo"}}]}, "scopeSpans": [{"scope": {"name": "firstmate"}, "spans": [{"traceId": "11111111111111111111111111111112", "spanId": "8d8d7eeafda33152", "parentSpanId": "3333333333333334", "name": "firstmate.reply", "kind": 1, "startTimeUnixNano": "1789295743000000000", "endTimeUnixNano": "1789295743989000000", "attributes": [{"key": "firstmate.corr", "value": {"stringValue": "531b8a385a440d60"}}, {"key": "firstmate.reply.via", "value": {"stringValue": "status"}}]}]}]}]}}
{"path": "/v1/traces", "content_type": "application/json", "body": {"resourceSpans": [{"resource": {"attributes": [{"key": "service.name", "value": {"stringValue": "firstmate"}}, {"key": "firstmate.task.id", "value": {"stringValue": "hibit"}}, {"key": "firstmate.project", "value": {"stringValue": "sm"}}, {"key": "firstmate.home", "value": {"stringValue": "/tmp/nm-live-reply.jhwRzB/parent2"}}, {"key": "firstmate.task.kind", "value": {"stringValue": "secondmate"}}, {"key": "firstmate.secondmate.id", "value": {"stringValue": "hibit"}}, {"key": "firstmate.harness", "value": {"stringValue": "echo"}}]}, "scopeSpans": [{"scope": {"name": "firstmate"}, "spans": [{"traceId": "11111111111111111111111111111112", "spanId": "57f8c82028cefd2c", "parentSpanId": "3333333333333334", "name": "firstmate.steer", "kind": 1, "startTimeUnixNano": "1789295744356000000", "endTimeUnixNano": "1789295744356000000", "attributes": [{"key": "firstmate.plane", "value": {"stringValue": "inbox"}}, {"key": "firstmate.corr", "value": {"stringValue": "3eb8425a1bb946cf"}}, {"key": "firstmate.inbox.seq", "value": {"stringValue": "001"}}]}]}]}]}}
Evidence: Wake spans as received (one per task-keyed row, shared end instant, torn-down task on captured trace)
{"name":"firstmate.wake","traceId":"11111111111111111111111111111112","parentSpanId":"3333333333333334","startTimeUnixNano":"1789295671000000000","endTimeUnixNano":"1789295672474000000","attrs":{"firstmate.wake.kind":"signal","firstmate.wake.seq":"1","firstmate.wake.key":"traced.status"}}
{"name":"firstmate.wake","traceId":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab","parentSpanId":"bbbbbbbbbbbbbbbc","startTimeUnixNano":"1789295671000000000","endTimeUnixNano":"1789295672474000000","attrs":{"firstmate.wake.kind":"signal","firstmate.wake.seq":"2","firstmate.wake.key":"gone.status"}}
(queue had 5 rows: 2 signal, 1 stale, 1 check, 1 heartbeat; presentation posted 0; replay ack posted 0; receiver-down ack rc=0 in 219ms)
Evidence: Hold spans as received (answer, origin-linked answer, release; replay and refused answer posted nothing)
{"name":"firstmate.hold","traceId":"11111111111111111111111111111112","parentSpanId":"3333333333333334","start_utc":"2026-06-01T12:00:00Z","attrs":{"firstmate.hold.close_mode":"answered","firstmate.hold.reason":"captain must choose the export shape"}}
{"name":"firstmate.hold","traceId":"66666666666666666666666666666667","parentSpanId":"8888888888888889","start_utc":"2026-06-01T13:00:00Z","attrs":{"firstmate.hold.close_mode":"answered","firstmate.hold.reason":"origin needs a ruling"}}
{"name":"firstmate.hold","traceId":"22222222222222222222222222222224","parentSpanId":"4444444444444448","start_utc":"2026-06-02T08:30:00Z","attrs":{"firstmate.hold.close_mode":"released","firstmate.hold.reason":"len=160"}}
Evidence: Reply span as received after watcher-tick settlement
record after settlement: phase=resolved resolved_via=status delivered_epoch=1789295743
{"name":"firstmate.reply","traceId":"11111111111111111111111111111112","parentSpanId":"3333333333333334","start_utc":"2026-09-13T10:35:43Z","attrs":{"firstmate.corr":"531b8a385a440d60","firstmate.reply.via":"status"}}
resource: {"service.name":"firstmate","firstmate.task.id":"hibit","firstmate.task.kind":"secondmate","firstmate.secondmate.id":"hibit",...}
second tick (replay): spans stay 2; receiver-down tick: rc=0, phase=resolved, 307ms

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 18 of 18 scenarios driven live against the product
Scenario Result Live Evidence
Wake acknowledgement posts one firstmate.wake per task-keyed signal row on the task trace, starting at queue time; stale/check/heartbeat rows post nothing ✅ pass live live-wake-hold-transcript.txt, otlp-received.jsonl (5 queued rows, 2 spans, traceIds match carriers, startTimeUnixNano = row epoch)
Presentation drain emits no span (no per-poll activity) and only writes telemetry captures ✅ pass live live-wake-hold-transcript.txt: 'spans received after presentation: 0', captures listed
Task torn down between presentation and ack still gets its wake span via the captured carrier; every span of the batch shares one end instant; capture discarded ✅ pass live live-wake-hold-transcript.txt: gone.meta removed before ack; span on trace aaaa…ab; both endTimeUnixNano 1789295672474000000; '.wake-trace.*: No such file'
Replaying an already-acknowledged batch posts no wake spans ✅ pass live live-wake-hold-transcript.txt: 'spans received after replay: 2'
Adversarial: unreachable OTLP receiver never blocks or slows wake acknowledgement beyond the bounded timeout; queue still cleared silently ✅ pass live live-wake-hold-transcript.txt: 'ack rc=0 stderr_bytes=0 elapsed_ms=219 queue_bytes=0'
Adversarial: unwritable wake capture is silent on presentation stderr and blocks neither presentation nor acknowledgement ✅ pass live bash tests/fm-wake-queue.test.sh test_wake_spans_survive_teardown_and_share_one_acknowledgement_instant (real drain executable, .wake-trace.kept.tmp as directory)
Disabled trace session: acknowledgement writes no captures and posts nothing ✅ pass live live-wake-hold-transcript.txt: 'captures=0 spans_before=2 spans_after=2'
Captain answer posts one firstmate.hold on the held task's trace from the recorded hold-set stamp with close_mode=answered and the reason ✅ pass live otlp-received.jsonl span 3; transcript start_utc 2026-06-01T12:00:00Z matches FM_CAPTAIN_HOLD_NOW
Idempotent answer replay of a completed close posts nothing ✅ pass live live-wake-hold-transcript.txt: replay rc=0, exactly 3 hold spans total
Separate --origin captain call joins the same-home origin task's trace at its own hold-set time ✅ pass live otlp-received.jsonl: traceId 6666…67 parent 8888…89 start 2026-06-01T13:00:00Z
--release posts close_mode=released with reason bounded to 160 chars ✅ pass live transcript: close_mode released, reason len=160 from a 200-char --reason
Refused answer (absent task) posts no hold span ✅ pass live transcript: 'refused rc=1', spans_before=5 spans_after=5
Verified reconcile close posts close_mode=reconciled; taskless captain call and disabled session post nothing ✅ pass live bash tests/fm-captain-hold-lifecycle.test.sh test_close_paths_emit_hold_spans_over_the_recorded_hold_time (real hold/answer/reconcile entrypoints, real tasks-axi backend)
Delivered secondmate request settling on a correlated reply posts one firstmate.reply on the secondmate trace from delivered_epoch with firstmate.corr and firstmate.reply.via=status; settlement correc… ✅ pass live live-reply-transcript.txt, otlp-received-reply.jsonl: phase=resolved, span start 1789295743000ms = delivered_epoch
Replayed watcher tick on an already-resolved reply posts nothing ✅ pass live live-reply-transcript.txt: 'second tick ... spans=2'
Adversarial: receiver down still resolves the reply within the bounded timeout ✅ pass live live-reply-transcript.txt: 'tick rc=0 elapsed_ms=307 phase=resolved'
Remote route: settlement of a mirrored delta emits the reply span from the parent home, never the remote host ✅ pass live bash tests/fm-remote-reply.test.sh (real fake-SSH chain, ALL TESTS PASSED)
Remote transport lanes fixture worker sources fm-trace-span-lib.sh and its siblings (fix from latest commit) ✅ pass live bash tests/fm-remote-transport-lanes.test.sh ALL TESTS PASSED
  • bash tests/fm-trace-span-lib.test.sh (10 ok)
  • env -u FM_PUBLIC_FOLLOWUP_PRIMARY_HOME ... bash tests/fm-captain-hold-lifecycle.test.sh (51 ok, includes test_close_paths_emit_hold_spans_over_the_recorded_hold_time)
  • bash tests/fm-pending-reply.test.sh (41 ok, includes test_settle_emits_parent_reply_span_once)
  • bash tests/fm-wake-queue.test.sh (43 ok, includes both wake-span tests incl. unwritable-capture fail-open)
  • bash tests/fm-remote-reply.test.sh (20 ok, remote settle emits from parent home)
  • bash tests/fm-remote-transport-lanes.test.sh (12 ok, fixture lib copy fix)
  • Live: /tmp/nm-live/drive.sh — real fm-wake-drain.sh presentation + --ack-through + replay, real fm-captain-hold.sh hold/answer/--origin/--release/replay/refused, real curl to python OTLP receiver on 127.0.0.1:43181; receiver-down and session-off variants
  • Live: /tmp/nm-live/drive-reply.sh — real fm-send.sh marked secondmate send (tmux stubbed as transport), correlated status reply, fm_pending_reply_tick settlement, replay, receiver-down; real curl to OTLP receiver on 127.0.0.1:43182
  • Base-commit comparison of fm-captain-hold-lifecycle under leaked env (fails identically at 8c1a640) to classify the env failure
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@andrewesweet
andrewesweet force-pushed the fm/fm-trace-return-spans branch from e9b1a7d to 78e0c6c Compare September 13, 2026 07:58
@andrewesweet andrewesweet changed the title feat(bin): emit hold, reply, and wake spans to complete the return-path tracing feat(bin): emit hold, reply, and wake spans to complete return-path tracing Sep 13, 2026
andrewesweet and others added 6 commits September 13, 2026 10:09
Complete the return path of the firstmate lifecycle span catalogue.
firstmate.hold covers a held task's recorded hold-set time through its
answer, release, or verified reconcile close, with the close mode and a
bounded reason captured from the pre-close record. firstmate.reply joins
the second mate agent's trace through the parent home's own meta, covering
a delivered request's confirmed delivery through its correlated
settlement, once per newly settled record. firstmate.wake covers a
task-keyed queue row from its queue time through a successful
acknowledgement, and never emits for heartbeats, per-poll checks, or rows
whose key maps to no task.

All three emit through the existing bounded best-effort OTLP emitter only
when their settlement or acknowledgement durably succeeds, stay silent for
untraced tasks and disabled homes, and can never change hold, settlement,
or acknowledgement outcomes. Verified through the hold lifecycle,
pending-reply, remote-reply, and wake-queue suites with a recording fake
curl, including disabled-session and untraced-task omission.
…-transport-lanes.test.sh: the fixture copies a subset of bin/ into a remote-root, and bin/fm-pending-reply-lib.sh now sources fm-trace-span-lib.sh unconditionally (per the round-2 ruling removing the presence fallback), so the worker died with "fm-trace-span-lib.sh: No such file or directory". Fixed by adding fm-trace-span-lib.sh and its sibling deps fm-trace-context-lib.sh and fm-timing-lib.sh to the fixture copy list. Ran the test locally: ALL TESTS PASSED. Shellcheck clean (pre-existing SC1091 info only). "PR must be raised via no-mistakes" is an attestation head_sha mismatch (e9b1a7d vs 78e0c6c) caused by a later pipeline push; not a code defect, resolved by the outer executor's re-push
@andrewesweet
andrewesweet force-pushed the fm/fm-trace-return-spans branch from 7dc62c9 to 4d09daf Compare September 13, 2026 09:30
@andrewesweet
andrewesweet merged commit f926396 into main Sep 13, 2026
14 of 15 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