Skip to content

Latest commit

 

History

History
126 lines (97 loc) · 6.1 KB

completion_probe.md

File metadata and controls

126 lines (97 loc) · 6.1 KB

completion_probe.sh

Revision: 1 Last modified: 2026-12-04T19:00:00Z

Overview

completion_probe.sh answers an open empirical question by measurement: does the platform's SubagentStop hook fire at real completion, or at launch?

That question is recorded as open in the data model (data-model §9.1: "UNCONFIRMED (R5 open item 1): whether Claude Code's SubagentStop hook fires at real completion (not at launch) for backgrounded Agent-tool launches"). It matters because the whole agent-registry design depends on complete meaning complete. If the hook fires at launch, then a complete row is a lie about time, and any supervisor that reaps or advances on it is acting on a false signal.

Rather than assume an answer, this probe reproduces the suspected defect (ATM-858 D1). It launches one background agent per dispatch kind, each ending in a known marker-file write as its LAST action, then compares two independent clocks:

  • the launch timestamp, taken from the registry's own dispatched row — never a locally-read clock (§11.4.6);
  • the marker-write timestamp, read from the filesystem — the ground truth of real completion, never assumed.

It then records, in order, every hook event the single-writer registry captured for that dispatch's correlation key.

The RED condition is literal and contract-defined: a complete-class registry row that exists strictly before the marker file's real write time — or that exists with no marker at all.

Prerequisites

  • bash, python3.
  • The single-writer registry scripts/hooks/agent_registry_writer.sh and its JSONL output (default docs/requests/agent_registry.jsonl relative to the repo root this script lives under).
  • A writable marker path inside a directory the agent can write.
  • No environment variables are read.

Usage examples

# 1. derive the correlation key for a dispatch (pure, no side effects)
bash scripts/fastcycle/orchestration/completion_probe.sh key \
  --session SID-123 --tool Agent \
  --description "T-B01 probe run" --prompt-file probe-prompt.txt

# 2. launch agents and watch for the truth
bash scripts/fastcycle/orchestration/completion_probe.sh watch \
  --key <16-hex-key> \
  --marker /tmp/probe/marker.txt \
  --dispatch-kind agent_tool_background \
  --out probe.json

# with an explicit registry and tighter polling
bash scripts/fastcycle/orchestration/completion_probe.sh watch \
  --key <16-hex-key> --marker /tmp/probe/marker.txt \
  --dispatch-kind workflow_agent --out probe.json \
  --registry docs/requests/agent_registry.jsonl \
  --timeout-seconds 900 --poll-interval-seconds 5 --settle-seconds 10

Exit codes

Code Meaning
0 Success. key printed the 16-hex correlation key; watch completed and wrote --out.
2 Usage error — missing or invalid arguments (key on missing/invalid args; die_usage in general).
4 The control needle failed, aborting the whole watch invocation.

key is a pure function: no side effects, no dispatch. That is why the same inputs must always yield the same key — it is the join between a dispatch and its hook events.

Subcommands

Subcommand Effect
key --session SID --tool NAME --description DESC [--prompt TEXT | --prompt-file PATH] Prints the 16-hex correlation key. No side effects.
watch --key KEY --marker PATH --dispatch-kind {agent_tool_background|workflow_agent} --out PATH [--registry PATH] [--timeout-seconds N] [--poll-interval-seconds N] [--settle-seconds N] Polls the registry for every event carrying --key, and the marker for its real appearance, mtime and expected content; writes probe.json.

Edge cases

  • No marker ever appears. The probe reports a timeout rather than declaring compliance; absence of a marker is not evidence that the hook fired correctly.
  • A complete row before the marker. The RED condition — this is a finding, recorded in the output, not a pass.
  • A complete row with no marker at all. Also the RED condition.
  • Registry file missing. Cannot establish the launch timestamp, so the comparison cannot be made honestly; the run does not manufacture one.
  • Needle failure. Exit 4, aborting the whole watch — a probe whose own instrument cannot be trusted must not emit a verdict.
  • --settle-seconds too small. The marker write and its registry event are two separate facts; a short settle window can observe one without the other. Increase it rather than reinterpreting the gap.
  • Reusing a --key across runs. The key is derived from session/tool/description, so a reused description joins unrelated events. Use a distinct description per probe run.

Internal behaviour

  1. Dispatches on the subcommand; unknown forms exit 2.
  2. key: hashes the session, tool, description (and prompt, when supplied) into a 16-hex key and prints it.
  3. watch: reads the registry's dispatched row for the key to obtain the launch timestamp; polls the marker path for real appearance, mtime and expected content; while polling, collects every registry event carrying that key in order.
  4. Runs the control needle; a failure aborts with 4.
  5. Applies the RED condition (a complete row strictly before the marker's write time, or a complete row with no marker) and writes probe.json.
  6. Exits 0 on a completed probe.

Related scripts

Reads the output of scripts/hooks/agent_registry_writer.sh (the single-writer registry) — it must not write the registry itself.

Contract: specs/004-fast-dev-cycles/contracts/agent-registry-and-handoff.md — which requires this probe to run before AR-003 source (b) is trusted. plan.md T-B01 ("Completion-signal probe (reproduction of ATM-858 D1)"); data-model §9.1.

See also docs/scripts/heartbeat.sh.md (the complementary liveness question: is it still working? vs. is it done?) and docs/scripts/handoff.py.md.

Last verified

2026-12-04 — bash -n scripts/fastcycle/orchestration/completion_probe.sh → exit 0. bash scripts/fastcycle/orchestration/completion_probe.sh with no subcommand exits 2 with a usage message on stderr (die_usage).