Detached worker completion routing
Why this exists
A one-shot runner — hermes -z, a cron job, a Kanban worker, a stateless HTTP
endpoint, a Bloodbank-command invocation — cannot receive terminal
notifications for background processes it starts. The tooling states this at
launch ("it cannot receive an async completion after the turn ends"). Anything
still running when the turn ends is unsupervised: nobody learns it finished,
nobody learns it died.
Not hypothetical. On 2026-10-02, two detached Codex implementers on the
holocene board (HOLOC-9, HOLOC-10) died silently mid-run — no terminal marker,
no final report, clean git tree. In both cases the only reason the death was
noticed same-minute is durable completion routing built before dispatch.
Silent worker death is a supervision problem to engineer for, not a verdict on
any particular worker CLI.
When this skill applies
Dispatch any long-running worker (implementer, build, emulator run, reviewer,
watcher) when ALL of these hold:
- the orchestrating session ends when its turn ends (one-shot context), or may
end before the worker does;
- the result of the worker must be reported or acted on;
- no human is watching the process.
If the session CAN await the result (interactive foreground with
process(action='wait') or a synchronous subagent), ordinary await supervision
is simpler — use that instead.
Workflow (in order — routing is built before the session exits)
- Dispatch with a durable spool. One ignored directory per ticket under
the role runtime (e.g.
agents/hermes/pm/runtime/workers/<TICKET>/):
task.md (full self-contained worker prompt — ACs verbatim, allowed and
forbidden writes, output contract), dispatch.json (identity, PIDs,
session ids, paths), worker stdout JSONL + stderr files, a designated
final-message file, and an initialized handback bundle.
- Prove the worker actually started before claiming anything. The process
exists with its cwd inside the assigned worktree. For Codex: the native
session id from the JSONL
thread.started matches completed gateway usage
rows — gateway-proof.py session --session-id <id>. A launched wrapper is
not a started worker.
- Pin exact process identity. Record PID and
/proc/<pid>/stat
field 22 (starttime) at dispatch. Parse by splitting after the LAST ) —
comm can contain spaces and parens — and take token index 19 past the comm
field. The start-tick defeats PID reuse; a PID alone does not.
- Write progress-first discipline into the worker prompt. The worker
writes a progress skeleton (identity, base SHA, unproven AC matrix) BEFORE
long exploration or builds, and heartbeats the handback bundle. A silent
death must still leave evidence on disk.
- Launch a completion watcher before the session exits. The watcher polls
the pinned identity (PID + start-tick), and on exit (or timeout) inspects
the worker's own artifacts — never the watcher's assumptions.
- The watcher also tracks elapsed wall-clock time against a
dispatch-declared
expected_minutes; see
references/detached-completion-routing.md § elapsed-time escalation
for the escalation ladder (over-budget → interrogate-why on recovery;
2× over-budget → operator-facing notification).
- Classify honestly. Terminal JSONL markers (
turn.completed /
turn.failed / turn.aborted) plus a nonempty final-message file.
worker_exited_incomplete is a legitimate outcome. A handback bundle that
passes validate is structural evidence only — a dead worker's bundle
validates too. It can never manufacture DONE.
- Route exactly ONE deterministic completion command. Canonical
bloodbank.agent.invocation.start (existing type — never invent a new
event type, never emit an invocation-completed fact) back to the owning PM
agent for handback/review or recovery:
command_id / idempotency_key derived uuid5 from the worker session
→ a watcher restart re-publishes identical bytes, and the gateway
deduplicates on redelivery;
- the exact envelope is persisted to disk BEFORE the first publish attempt;
- bounded transport retries resend identical bytes and NEVER retrigger,
restart, or signal the worker;
data.context carries {reason: worker-handback, repo, ticket_key, ticket_id, board_id, workspace, worker_session, watcher_outcome, watcher_evidence} — the recovery turn gets everything without guessing.
- Note:
reason: worker-handback does not match the n8n Ticket Pickup
Chip's ticket-grooming|ticket-delegation reasons, so the recovery turn
does not fight the pipeline over agent:working. Keep it that way.
- Verify before walking away. Watcher unit tests green (including the
fake-process fixture), watcher state files 0600 / dir 0700, envelope on
disk equals published bytes, and a restart is an idempotent no-op.
Pitfalls
- Fake
/proc fixtures put the tick in the wrong field. Real
/proc/<pid>/stat has starttime at field 22; a naive test fixture writing
it at field 5 makes the parser correctly report "exited" and the whole suite
fails. Fixture must emit the state token plus 18 filler fields, then the
tick (see references for the exact recipe).
notify_on_complete=true is silently ignored in one-shot contexts. The
launch output says so — read it, and never rely on a completion ping you
were told you cannot receive.
- A delegated tooling subagent may die before its final report (API
failure after its file writes succeeded). Its artifacts are
unverified-but-present: stat, read, and test them yourself. A missing
self-report is not missing work; re-dispatching duplicates effort. In the
HOLOC-10 session the watcher subagent died pre-report with a correct script
and a broken fixture on disk — the parent fixed the fixture in minutes.
- Retries are transport-only. A retry loop that re-runs the worker or
mints a second command id breaks the exactly-once property.
- Don't conflate outcomes. success / worker_failed /
worker_exited_incomplete / watch_timeout are four different facts; publish
the one that is true, and let the recovery turn decide.
Verification steps
- Watcher test suite passes locally (fake proc tree + fake bus — no live
command is ever sent from tests).
ps confirms the pinned PID is the intended process; the recorded
start-tick matches a live read of /proc/<pid>/stat.
- Gateway receipts prove the worker's first real inference (Codex: session id
match in usage rows).
- After the worker exits: watcher-notification.json shows exactly one
published command; watcher-envelope.json equals the published body; exit
code reflects the honest outcome (0 success / 1 failure / 2 could-not-publish).
Support files
references/detached-completion-routing.md — full watcher design contract,
the /proc stat parsing recipe, envelope determinism details, and both
2026-10-02 incident walkthroughs (HOLOC-9, HOLOC-10).
templates/watcher-config.json — the proven watcher configuration shape,
parameterized.
1---2name: detached-worker-completion3description: Use when a delegated worker outlives the launching session.4metadata:5 source: https://skillmd.com/skills/delorenj/detached-worker-completion6---78# Detached worker completion routing910## Why this exists1112A one-shot runner — `hermes -z`, a cron job, a Kanban worker, a stateless HTTP13endpoint, a Bloodbank-command invocation — **cannot receive terminal14notifications for background processes it starts**. The tooling states this at15launch ("it cannot receive an async completion after the turn ends"). Anything16still running when the turn ends is unsupervised: nobody learns it finished,17nobody learns it died.1819Not hypothetical. On 2026-10-02, two detached Codex implementers on the20holocene board (HOLOC-9, HOLOC-10) died silently mid-run — no terminal marker,21no final report, clean git tree. In both cases the only reason the death was22noticed same-minute is durable completion routing built **before** dispatch.23Silent worker death is a supervision problem to engineer for, not a verdict on24any particular worker CLI.2526## When this skill applies2728Dispatch any long-running worker (implementer, build, emulator run, reviewer,29watcher) when ALL of these hold:3031- the orchestrating session ends when its turn ends (one-shot context), or may32 end before the worker does;33- the result of the worker must be reported or acted on;34- no human is watching the process.3536If the session CAN await the result (interactive foreground with37`process(action='wait')` or a synchronous subagent), ordinary await supervision38is simpler — use that instead.3940## Workflow (in order — routing is built before the session exits)41421. **Dispatch with a durable spool.** One ignored directory per ticket under43 the role runtime (e.g. `agents/hermes/pm/runtime/workers/<TICKET>/`):44 `task.md` (full self-contained worker prompt — ACs verbatim, allowed and45 forbidden writes, output contract), `dispatch.json` (identity, PIDs,46 session ids, paths), worker stdout JSONL + stderr files, a designated47 final-message file, and an initialized handback bundle.482. **Prove the worker actually started before claiming anything.** The process49 exists with its cwd inside the assigned worktree. For Codex: the native50 session id from the JSONL `thread.started` matches completed gateway usage51 rows — `gateway-proof.py session --session-id <id>`. A launched wrapper is52 not a started worker.533. **Pin exact process identity.** Record PID **and** `/proc/<pid>/stat`54 field 22 (starttime) at dispatch. Parse by splitting after the LAST `)` —55 comm can contain spaces and parens — and take token index 19 past the comm56 field. The start-tick defeats PID reuse; a PID alone does not.574. **Write progress-first discipline into the worker prompt.** The worker58 writes a progress skeleton (identity, base SHA, unproven AC matrix) BEFORE59 long exploration or builds, and heartbeats the handback bundle. A silent60 death must still leave evidence on disk.615. **Launch a completion watcher before the session exits.** The watcher polls62 the pinned identity (PID + start-tick), and on exit (or timeout) inspects63 the worker's own artifacts — never the watcher's assumptions.64 - The watcher also tracks **elapsed wall-clock time** against a65 dispatch-declared `expected_minutes`; see66 `references/detached-completion-routing.md` § elapsed-time escalation67 for the escalation ladder (over-budget → interrogate-why on recovery;68 2× over-budget → operator-facing notification).696. **Classify honestly.** Terminal JSONL markers (`turn.completed` /70 `turn.failed` / `turn.aborted`) plus a nonempty final-message file.71 `worker_exited_incomplete` is a legitimate outcome. A handback bundle that72 passes `validate` is **structural evidence only** — a dead worker's bundle73 validates too. It can never manufacture DONE.747. **Route exactly ONE deterministic completion command.** Canonical75 `bloodbank.agent.invocation.start` (existing type — never invent a new76 event type, never emit an invocation-completed fact) back to the owning PM77 agent for handback/review or recovery:78 - `command_id` / `idempotency_key` derived `uuid5` from the worker session79 → a watcher restart re-publishes identical bytes, and the gateway80 deduplicates on redelivery;81 - the exact envelope is persisted to disk BEFORE the first publish attempt;82 - bounded transport retries resend identical bytes and NEVER retrigger,83 restart, or signal the worker;84 - `data.context` carries `{reason: worker-handback, repo, ticket_key,85 ticket_id, board_id, workspace, worker_session, watcher_outcome,86 watcher_evidence}` — the recovery turn gets everything without guessing.87 - Note: `reason: worker-handback` does not match the n8n Ticket Pickup88 Chip's `ticket-grooming|ticket-delegation` reasons, so the recovery turn89 does not fight the pipeline over `agent:working`. Keep it that way.908. **Verify before walking away.** Watcher unit tests green (including the91 fake-process fixture), watcher state files 0600 / dir 0700, envelope on92 disk equals published bytes, and a restart is an idempotent no-op.9394## Pitfalls9596- **Fake `/proc` fixtures put the tick in the wrong field.** Real97 `/proc/<pid>/stat` has starttime at field 22; a naive test fixture writing98 it at field 5 makes the parser correctly report "exited" and the whole suite99 fails. Fixture must emit the state token plus 18 filler fields, then the100 tick (see references for the exact recipe).101- **`notify_on_complete=true` is silently ignored in one-shot contexts.** The102 launch output says so — read it, and never rely on a completion ping you103 were told you cannot receive.104- **A delegated tooling subagent may die before its final report** (API105 failure after its file writes succeeded). Its artifacts are106 unverified-but-present: stat, read, and test them yourself. A missing107 self-report is not missing work; re-dispatching duplicates effort. In the108 HOLOC-10 session the watcher subagent died pre-report with a correct script109 and a broken fixture on disk — the parent fixed the fixture in minutes.110- **Retries are transport-only.** A retry loop that re-runs the worker or111 mints a second command id breaks the exactly-once property.112- **Don't conflate outcomes.** success / worker_failed /113 worker_exited_incomplete / watch_timeout are four different facts; publish114 the one that is true, and let the recovery turn decide.115116## Verification steps1171181. Watcher test suite passes locally (fake proc tree + fake bus — no live119 command is ever sent from tests).1202. `ps` confirms the pinned PID is the intended process; the recorded121 start-tick matches a live read of `/proc/<pid>/stat`.1223. Gateway receipts prove the worker's first real inference (Codex: session id123 match in usage rows).1244. After the worker exits: watcher-notification.json shows exactly one125 published command; watcher-envelope.json equals the published body; exit126 code reflects the honest outcome (0 success / 1 failure / 2 could-not-publish).127128## Support files129130- `references/detached-completion-routing.md` — full watcher design contract,131 the `/proc` stat parsing recipe, envelope determinism details, and both132 2026-10-02 incident walkthroughs (HOLOC-9, HOLOC-10).133- `templates/watcher-config.json` — the proven watcher configuration shape,134 parameterized.