feat: export continuity hard-gate and watchdog workstream

This commit is contained in:
2026-04-24 12:36:31 +08:00
commit 111cf27634
24 changed files with 3648 additions and 0 deletions

View File

@@ -0,0 +1,410 @@
# Approved-Plan Continuity Hard-Gate Implementation Plan
> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
**Goal:** Prevent approved-plan flows from stopping after a task completes by requiring a real next-dispatch receipt unless the workflow explicitly transitions to `waiting_user`, `blocked`, or `pending_verification`.
**Architecture:** Build this in very small slices. First define continuity receipt fields and failure states, then pin the continuity failure with fail-first tests, then implement a minimal evaluator, then bind planner output to real dispatch receipts, then enforce reply-closure continuity. Keep every slice narrow enough to verify in isolation.
**Tech Stack:** Node.js, MJS test runners, file-backed JSON receipts, force-recall hook integration
---
### Task 1: Define continuity receipt fields
**Files:**
- Create: `docs/runbooks/approved-plan-continuity.md`
**Step 1: Write only the receipt field list**
- Define:
- `planId`
- `currentTask`
- `nextDerivedAction`
- `dispatchedAt`
**Step 2: Verify file exists**
Run: `test -f docs/runbooks/approved-plan-continuity.md && echo OK`
Expected: `OK`
**Step 3: Commit**
```bash
git add docs/runbooks/approved-plan-continuity.md
git commit -m "docs: define continuity dispatch receipt core fields"
```
### Task 2: Define receipt linkage fields
**Files:**
- Modify: `docs/runbooks/approved-plan-continuity.md`
**Step 1: Add linkage fields**
- Define:
- `dispatchRunId`
- `childSessionKey`
- `replyClosureState`
**Step 2: Verify field names exist**
Run: `grep -n "dispatchRunId\|childSessionKey\|replyClosureState" docs/runbooks/approved-plan-continuity.md`
Expected: matching lines found
**Step 3: Commit**
```bash
git add docs/runbooks/approved-plan-continuity.md
git commit -m "docs: define continuity receipt linkage fields"
```
### Task 3: Define legal terminal states
**Files:**
- Modify: `docs/runbooks/approved-plan-continuity.md`
**Step 1: Add legal closure states**
- Define the only legal non-dispatch closures:
- `waiting_user`
- `blocked`
- `pending_verification`
**Step 2: Verify text exists**
Run: `grep -n "waiting_user\|blocked\|pending_verification" docs/runbooks/approved-plan-continuity.md`
Expected: matching lines found
**Step 3: Commit**
```bash
git add docs/runbooks/approved-plan-continuity.md
git commit -m "docs: define legal approved-plan terminal states"
```
### Task 4: Create continuity gate script skeleton
**Files:**
- Create: `scripts/approved_plan_continuity_gate.mjs`
**Step 1: Add CLI skeleton**
- Support `--input` and placeholder JSON output.
**Step 2: Verify it runs**
Run: `node scripts/approved_plan_continuity_gate.mjs --compact --input /dev/null || true`
Expected: placeholder response or controlled failure
**Step 3: Commit**
```bash
git add scripts/approved_plan_continuity_gate.mjs
git commit -m "chore: add approved-plan continuity gate skeleton"
```
### Task 5: Create continuity gate test skeleton
**Files:**
- Create: `scripts/test_approved_plan_continuity_gate.mjs`
**Step 1: Add test harness skeleton**
- Basic runner + fixture helper only.
**Step 2: Verify it runs**
Run: `node scripts/test_approved_plan_continuity_gate.mjs || true`
Expected: test runner executes
**Step 3: Commit**
```bash
git add scripts/test_approved_plan_continuity_gate.mjs
git commit -m "test: add continuity gate test skeleton"
```
### Task 6: Add fail-first test for missing dispatch receipt
**Files:**
- Modify: `scripts/test_approved_plan_continuity_gate.mjs`
**Step 1: Write the test**
- task complete
- next action known
- no dispatch receipt
- not waiting/blocked/pending_verification
- expect continuity failure
**Step 2: Run tests to verify it fails**
Run: `node scripts/test_approved_plan_continuity_gate.mjs`
Expected: FAIL
**Step 3: Commit**
```bash
git add scripts/test_approved_plan_continuity_gate.mjs
git commit -m "test: fail when approved plan step stops without dispatch receipt"
```
### Task 7: Add pass test for existing dispatch receipt
**Files:**
- Modify: `scripts/test_approved_plan_continuity_gate.mjs`
**Step 1: Write the test**
- task complete
- next action known
- dispatch receipt exists
- expect pass
**Step 2: Run tests to verify it fails**
Run: `node scripts/test_approved_plan_continuity_gate.mjs`
Expected: FAIL until evaluator exists
**Step 3: Commit**
```bash
git add scripts/test_approved_plan_continuity_gate.mjs
git commit -m "test: allow approved plan step with dispatch receipt"
```
### Task 8: Add pass test for waiting_user closure
**Files:**
- Modify: `scripts/test_approved_plan_continuity_gate.mjs`
**Step 1: Write the test**
- task complete
- next action known
- no dispatch receipt
- replyClosureState=`waiting_user`
- expect pass
**Step 2: Run tests to verify it fails**
Run: `node scripts/test_approved_plan_continuity_gate.mjs`
Expected: FAIL until evaluator exists
**Step 3: Commit**
```bash
git add scripts/test_approved_plan_continuity_gate.mjs
git commit -m "test: allow waiting_user continuity closure"
```
### Task 9: Add pass test for blocked closure
**Files:**
- Modify: `scripts/test_approved_plan_continuity_gate.mjs`
**Step 1: Write the test**
- replyClosureState=`blocked`
- expect pass
**Step 2: Run tests to verify it fails**
Run: `node scripts/test_approved_plan_continuity_gate.mjs`
Expected: FAIL until evaluator exists
**Step 3: Commit**
```bash
git add scripts/test_approved_plan_continuity_gate.mjs
git commit -m "test: allow blocked continuity closure"
```
### Task 10: Add pass test for pending_verification closure
**Files:**
- Modify: `scripts/test_approved_plan_continuity_gate.mjs`
**Step 1: Write the test**
- replyClosureState=`pending_verification`
- expect pass
**Step 2: Run tests to verify it fails**
Run: `node scripts/test_approved_plan_continuity_gate.mjs`
Expected: FAIL until evaluator exists
**Step 3: Commit**
```bash
git add scripts/test_approved_plan_continuity_gate.mjs
git commit -m "test: allow pending verification continuity closure"
```
### Task 11: Implement minimal continuity evaluator
**Files:**
- Modify: `scripts/approved_plan_continuity_gate.mjs`
**Step 1: Add evaluator logic**
- Fail only when:
- approved plan task complete
- next action known
- no dispatch receipt
- and not in legal terminal state
**Step 2: Run tests**
Run: `node scripts/test_approved_plan_continuity_gate.mjs`
Expected: PASS for Tasks 6-10
**Step 3: Commit**
```bash
git add scripts/approved_plan_continuity_gate.mjs scripts/test_approved_plan_continuity_gate.mjs
git commit -m "feat: evaluate approved-plan continuity closure"
```
### Task 12: Create dispatch binding skeleton
**Files:**
- Create: `scripts/approved_plan_dispatch_binding.mjs`
**Step 1: Add CLI skeleton**
- Support input parsing and placeholder receipt output.
**Step 2: Verify it runs**
Run: `node scripts/approved_plan_dispatch_binding.mjs --compact --input /dev/null || true`
Expected: placeholder response or controlled failure
**Step 3: Commit**
```bash
git add scripts/approved_plan_dispatch_binding.mjs
git commit -m "chore: add approved-plan dispatch binding skeleton"
```
### Task 13: Add fail-first test for planner action without bound dispatch
**Files:**
- Modify: `scripts/test_approved_plan_continuity_gate.mjs`
**Step 1: Write the test**
- planner returns `derivedAction`
- but no dispatch receipt is written
- expect fail
**Step 2: Run tests to verify it fails**
Run: `node scripts/test_approved_plan_continuity_gate.mjs`
Expected: FAIL
**Step 3: Commit**
```bash
git add scripts/test_approved_plan_continuity_gate.mjs
git commit -m "test: fail when derived action has no bound dispatch"
```
### Task 14: Add pass test for planner action with bound dispatch receipt
**Files:**
- Modify: `scripts/test_approved_plan_continuity_gate.mjs`
**Step 1: Write the test**
- planner returns `derivedAction`
- receipt is written
- expect pass
**Step 2: Run tests to verify it fails**
Run: `node scripts/test_approved_plan_continuity_gate.mjs`
Expected: FAIL until binding exists
**Step 3: Commit**
```bash
git add scripts/test_approved_plan_continuity_gate.mjs
git commit -m "test: pass when derived action is bound to dispatch receipt"
```
### Task 15: Define continuity receipt state storage
**Files:**
- Create: `state/approved-plan-continuity/.gitkeep`
- Create: `state/approved-plan-continuity/README.md`
**Step 1: Write the state shape**
- Include receipt filenames and minimum fields.
**Step 2: Verify files exist**
Run: `test -f state/approved-plan-continuity/README.md && test -f state/approved-plan-continuity/.gitkeep && echo OK`
Expected: `OK`
**Step 3: Commit**
```bash
git add state/approved-plan-continuity/.gitkeep state/approved-plan-continuity/README.md
git commit -m "docs: define approved-plan continuity receipt storage"
```
### Task 16: Implement minimal dispatch receipt writer
**Files:**
- Modify: `scripts/approved_plan_dispatch_binding.mjs`
**Step 1: Write dispatch receipts**
- When a known action is truly bound, write file-backed receipt.
**Step 2: Run tests**
Run: `node scripts/test_approved_plan_continuity_gate.mjs`
Expected: binding tests pass
**Step 3: Commit**
```bash
git add scripts/approved_plan_dispatch_binding.mjs scripts/test_approved_plan_continuity_gate.mjs state/approved-plan-continuity/.gitkeep state/approved-plan-continuity/README.md
git commit -m "feat: write approved-plan continuity dispatch receipts"
```
### Task 17: Add fail-first regression for “task done but stopped”
**Files:**
- Modify: `scripts/test_approved_plan_continuity_gate.mjs`
**Step 1: Write the regression test**
- completed task
- next step known
- no dispatch receipt
- reply tries to close anyway
- expect violation
**Step 2: Run tests to verify it fails if regression exists**
Run: `node scripts/test_approved_plan_continuity_gate.mjs`
Expected: PASS after fix, but must detect regression if broken
**Step 3: Commit**
```bash
git add scripts/test_approved_plan_continuity_gate.mjs
git commit -m "test: lock regression for task done but stopped"
```
### Task 18: Hook continuity gate into force-recall handler
**Files:**
- Modify: `hooks/force-recall/handler.ts`
**Step 1: Wire continuity gate into reply closure path**
- Enforce continuity before normal closeout.
**Step 2: Run targeted verification**
Run:
- `node scripts/test_approved_plan_continuity_gate.mjs`
- `node scripts/test_force_recall_long_task_preflight.mjs`
- `node --check hooks/force-recall/handler.ts`
Expected: PASS
**Step 3: Commit**
```bash
git add hooks/force-recall/handler.ts scripts/approved_plan_continuity_gate.mjs scripts/approved_plan_dispatch_binding.mjs scripts/test_approved_plan_continuity_gate.mjs
git commit -m "feat: enforce approved-plan continuity at reply closure"
```
### Task 19: Peer review continuity evaluator and binding
**Files:**
- Review: `scripts/approved_plan_continuity_gate.mjs`
- Review: `scripts/approved_plan_dispatch_binding.mjs`
- Review: `scripts/test_approved_plan_continuity_gate.mjs`
**Step 1: Request review**
- Focus: does this really fix continuity failure instead of adding prompt-only guidance?
**Step 2: Record verdict**
- Include commands and findings.
**Step 3: Apply follow-up fixes if needed**
```bash
# only if reviewer requests changes
git add <changed-files>
git commit -m "fix: address continuity gate review feedback"
```
### Task 20: Peer review hook integration and handoff
**Files:**
- Review: `hooks/force-recall/handler.ts`
- Review: `docs/runbooks/approved-plan-continuity.md`
- Review: `state/approved-plan-continuity/README.md`
**Step 1: Request review**
- Focus: can approved-plan task completion still stop without dispatch receipt?
**Step 2: Record verification output**
- Include commands and reviewer verdict.
**Step 3: Final state**
- Leave task in `pending_verification`; do not mark complete.

View File

@@ -0,0 +1,686 @@
# Subagent Anti-Blackhole / Completion-Delivery Watchdog Implementation Plan
> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
**Goal:** Prevent B-class fake timeouts where a subagent finishes, stalls, or loses its return path off-thread and the main conversation never receives a trustworthy completion update.
**Architecture:** Build this in very small layers: first define receipts and states, then pin the blackhole cases with fail-first tests, then implement deterministic receipt-state logic, then add done-but-not-forwarded recovery decisions, then add owner-visible reporting rules and scenario simulations. Keep all early slices file-backed and test-driven before touching any live-session integration.
**Tech Stack:** Node.js, MJS test runners, file-backed JSON state, OpenClaw subagent/session concepts, docs/runbooks
---
### Task 1: Define dispatch receipt fields
**Files:**
- Modify: `docs/runbooks/subagent-anti-blackhole.md`
**Step 1: Write the receipt field list**
- Define only dispatch fields:
- `runId`
- `childSessionKey`
- `dispatchAt`
- `expectedBy`
**Step 2: Verify file contains the new field names**
Run: `grep -n "runId\|childSessionKey\|dispatchAt\|expectedBy" docs/runbooks/subagent-anti-blackhole.md`
Expected: matching lines found
**Step 3: Commit**
```bash
git add docs/runbooks/subagent-anti-blackhole.md
git commit -m "docs: define subagent dispatch receipt fields"
```
### Task 2: Define completion receipt fields
**Files:**
- Modify: `docs/runbooks/subagent-anti-blackhole.md`
**Step 1: Write the completion field list**
- Define only completion fields:
- `completionReceivedAt`
- `forwardedToMain`
- `resultSource`
**Step 2: Verify file contains the new field names**
Run: `grep -n "completionReceivedAt\|forwardedToMain\|resultSource" docs/runbooks/subagent-anti-blackhole.md`
Expected: matching lines found
**Step 3: Commit**
```bash
git add docs/runbooks/subagent-anti-blackhole.md
git commit -m "docs: define subagent completion receipt fields"
```
### Task 3: Define watchdog statuses
**Files:**
- Modify: `docs/runbooks/subagent-anti-blackhole.md`
**Step 1: Add the status enum**
- Define:
- `active`
- `suspect_delivery_failure`
- `done_but_not_forwarded`
- `completed`
- `recovered`
- `blocked`
**Step 2: Verify status names exist**
Run: `grep -n "suspect_delivery_failure\|done_but_not_forwarded\|recovered" docs/runbooks/subagent-anti-blackhole.md`
Expected: matching lines found
**Step 3: Commit**
```bash
git add docs/runbooks/subagent-anti-blackhole.md
git commit -m "docs: define subagent watchdog statuses"
```
### Task 4: Define B-class failure modes
**Files:**
- Modify: `docs/runbooks/subagent-anti-blackhole.md`
**Step 1: Write the failure mode bullets**
- Add:
- done but not forwarded
- no completion event received
- session exists but no result bounce
- unclear slow-run vs delivery failure
**Step 2: Verify phrases exist**
Run: `grep -n "done but not forwarded\|completion event\|result bounce\|delivery failure" docs/runbooks/subagent-anti-blackhole.md`
Expected: matching lines found
**Step 3: Commit**
```bash
git add docs/runbooks/subagent-anti-blackhole.md
git commit -m "docs: define B-class subagent failure modes"
```
### Task 5: Create watchdog script skeleton
**Files:**
- Create: `scripts/subagent_delivery_watchdog.mjs`
**Step 1: Create the script shell**
- Add CLI parsing and a placeholder JSON response.
**Step 2: Verify it runs**
Run: `node scripts/subagent_delivery_watchdog.mjs --compact --input /dev/null || true`
Expected: script exists and is executable enough for next test work
**Step 3: Commit**
```bash
git add scripts/subagent_delivery_watchdog.mjs
git commit -m "chore: add subagent delivery watchdog skeleton"
```
### Task 6: Create watchdog test skeleton
**Files:**
- Create: `scripts/test_subagent_delivery_watchdog.mjs`
**Step 1: Create the test shell**
- Add basic harness structure and fixture runner.
**Step 2: Verify test file executes**
Run: `node scripts/test_subagent_delivery_watchdog.mjs || true`
Expected: test runner executes, even if failing
**Step 3: Commit**
```bash
git add scripts/test_subagent_delivery_watchdog.mjs
git commit -m "test: add subagent watchdog test skeleton"
```
### Task 7: Add active-before-SLA test
**Files:**
- Modify: `scripts/test_subagent_delivery_watchdog.mjs`
**Step 1: Write the test**
- dispatch exists
- no completion receipt yet
- current time still before SLA
- expect `active`
**Step 2: Run test to verify it fails**
Run: `node scripts/test_subagent_delivery_watchdog.mjs`
Expected: FAIL on missing logic
**Step 3: Commit**
```bash
git add scripts/test_subagent_delivery_watchdog.mjs
git commit -m "test: require active status before SLA breach"
```
### Task 8: Add suspect-delivery-failure test
**Files:**
- Modify: `scripts/test_subagent_delivery_watchdog.mjs`
**Step 1: Write the test**
- dispatch exists
- no completion receipt
- current time beyond SLA
- expect `suspect_delivery_failure`
**Step 2: Run test to verify it fails**
Run: `node scripts/test_subagent_delivery_watchdog.mjs`
Expected: FAIL on new assertion
**Step 3: Commit**
```bash
git add scripts/test_subagent_delivery_watchdog.mjs
git commit -m "test: detect suspected delivery failure after SLA"
```
### Task 9: Add completed-status test
**Files:**
- Modify: `scripts/test_subagent_delivery_watchdog.mjs`
**Step 1: Write the test**
- dispatch exists
- completion receipt exists
- expect `completed`
**Step 2: Run test to verify it fails**
Run: `node scripts/test_subagent_delivery_watchdog.mjs`
Expected: FAIL on completed path
**Step 3: Commit**
```bash
git add scripts/test_subagent_delivery_watchdog.mjs
git commit -m "test: close watchdog on completion receipt"
```
### Task 10: Add state shape fixture
**Files:**
- Create: `state/subagent-delivery-watchdog/README.md`
- Create: `state/subagent-delivery-watchdog/.gitkeep`
**Step 1: Define the state JSON shape in README**
- Include receipt fields and status fields.
**Step 2: Verify files exist**
Run: `test -f state/subagent-delivery-watchdog/README.md && test -f state/subagent-delivery-watchdog/.gitkeep && echo OK`
Expected: `OK`
**Step 3: Commit**
```bash
git add state/subagent-delivery-watchdog/README.md state/subagent-delivery-watchdog/.gitkeep
git commit -m "docs: define watchdog state storage shape"
```
### Task 11: Implement dispatch receipt write
**Files:**
- Modify: `scripts/subagent_delivery_watchdog.mjs`
**Step 1: Add a function to write dispatch receipt state**
- Only handle a new dispatch record.
**Step 2: Run tests**
Run: `node scripts/test_subagent_delivery_watchdog.mjs`
Expected: some tests still fail, but dispatch state path exists
**Step 3: Commit**
```bash
git add scripts/subagent_delivery_watchdog.mjs
git commit -m "feat: write subagent dispatch receipt state"
```
### Task 12: Implement completion receipt write
**Files:**
- Modify: `scripts/subagent_delivery_watchdog.mjs`
**Step 1: Add a function to write completion receipt state**
- Only update completion-related fields.
**Step 2: Run tests**
Run: `node scripts/test_subagent_delivery_watchdog.mjs`
Expected: some tests still fail, but completion data path exists
**Step 3: Commit**
```bash
git add scripts/subagent_delivery_watchdog.mjs
git commit -m "feat: write subagent completion receipt state"
```
### Task 13: Implement status recompute for active/completed/suspect
**Files:**
- Modify: `scripts/subagent_delivery_watchdog.mjs`
**Step 1: Add status recompute logic**
- Implement only:
- `active`
- `suspect_delivery_failure`
- `completed`
**Step 2: Run tests**
Run: `node scripts/test_subagent_delivery_watchdog.mjs`
Expected: Task 7-9 tests pass
**Step 3: Commit**
```bash
git add scripts/subagent_delivery_watchdog.mjs scripts/test_subagent_delivery_watchdog.mjs
git commit -m "feat: recompute basic watchdog statuses"
```
### Task 14: Add done-but-not-forwarded test
**Files:**
- Modify: `scripts/test_subagent_delivery_watchdog.mjs`
**Step 1: Write the test**
- child run marked done
- no completion receipt in main thread
- expect `done_but_not_forwarded`
**Step 2: Run tests to verify it fails**
Run: `node scripts/test_subagent_delivery_watchdog.mjs`
Expected: FAIL on new assertion
**Step 3: Commit**
```bash
git add scripts/test_subagent_delivery_watchdog.mjs
git commit -m "test: detect done but not forwarded state"
```
### Task 15: Implement done-but-not-forwarded state
**Files:**
- Modify: `scripts/subagent_delivery_watchdog.mjs`
**Step 1: Add done-but-not-forwarded detection**
- Use child-done signal + missing completion receipt.
**Step 2: Run tests**
Run: `node scripts/test_subagent_delivery_watchdog.mjs`
Expected: done-but-not-forwarded test passes
**Step 3: Commit**
```bash
git add scripts/subagent_delivery_watchdog.mjs scripts/test_subagent_delivery_watchdog.mjs
git commit -m "feat: detect done without forwarded completion"
```
### Task 16: Add first recovery-action test
**Files:**
- Modify: `scripts/test_subagent_delivery_watchdog.mjs`
**Step 1: Write fetch-history recovery test**
- done but not forwarded
- no prior recovery action
- expect recovery decision `fetch_history`
**Step 2: Run tests to verify it fails**
Run: `node scripts/test_subagent_delivery_watchdog.mjs`
Expected: FAIL on recovery decision
**Step 3: Commit**
```bash
git add scripts/test_subagent_delivery_watchdog.mjs
git commit -m "test: fetch history after missing forwarded completion"
```
### Task 17: Implement fetch-history recovery decision
**Files:**
- Modify: `scripts/subagent_delivery_watchdog.mjs`
**Step 1: Add minimal recovery decision logic**
- Return `fetch_history` for first-time done-but-not-forwarded.
**Step 2: Run tests**
Run: `node scripts/test_subagent_delivery_watchdog.mjs`
Expected: fetch-history recovery test passes
**Step 3: Commit**
```bash
git add scripts/subagent_delivery_watchdog.mjs scripts/test_subagent_delivery_watchdog.mjs
git commit -m "feat: recover with history fetch first"
```
### Task 18: Add respawn-escalation test
**Files:**
- Modify: `scripts/test_subagent_delivery_watchdog.mjs`
**Step 1: Write the respawn test**
- recovery already attempted once
- still no forwarded completion
- expect `respawn`
**Step 2: Run tests to verify it fails**
Run: `node scripts/test_subagent_delivery_watchdog.mjs`
Expected: FAIL on respawn decision
**Step 3: Commit**
```bash
git add scripts/test_subagent_delivery_watchdog.mjs
git commit -m "test: escalate to respawn after failed recovery"
```
### Task 19: Implement respawn decision
**Files:**
- Modify: `scripts/subagent_delivery_watchdog.mjs`
**Step 1: Add respawn logic**
- Return `respawn` when fetch-history path did not recover delivery.
**Step 2: Run tests**
Run: `node scripts/test_subagent_delivery_watchdog.mjs`
Expected: respawn test passes
**Step 3: Commit**
```bash
git add scripts/subagent_delivery_watchdog.mjs scripts/test_subagent_delivery_watchdog.mjs
git commit -m "feat: respawn after failed delivery recovery"
```
### Task 20: Add blocked-escalation test
**Files:**
- Modify: `scripts/test_subagent_delivery_watchdog.mjs`
**Step 1: Write the blocked test**
- repeated recovery failure
- expect `blocked` plus owner-visible reporting requirement
**Step 2: Run tests to verify it fails**
Run: `node scripts/test_subagent_delivery_watchdog.mjs`
Expected: FAIL on blocked escalation
**Step 3: Commit**
```bash
git add scripts/test_subagent_delivery_watchdog.mjs
git commit -m "test: escalate repeated delivery failures to blocked"
```
### Task 21: Implement blocked escalation
**Files:**
- Modify: `scripts/subagent_delivery_watchdog.mjs`
**Step 1: Add blocked escalation logic**
- repeated recovery failure -> `blocked`
**Step 2: Run tests**
Run: `node scripts/test_subagent_delivery_watchdog.mjs`
Expected: blocked escalation test passes
**Step 3: Commit**
```bash
git add scripts/subagent_delivery_watchdog.mjs scripts/test_subagent_delivery_watchdog.mjs
git commit -m "feat: block repeated subagent delivery failures"
```
### Task 22: Add owner-visible reporting rule for suspect state
**Files:**
- Modify: `WORKFLOW.md`
- Modify: `AGENTS.md`
- Modify: `docs/runbooks/subagent-anti-blackhole.md`
**Step 1: Add suspect-state reporting rule**
- If SLA is crossed with no completion receipt, the owner must be informed.
**Step 2: Verify text exists**
Run: `grep -RIn "SLA\|suspect_delivery_failure" WORKFLOW.md AGENTS.md docs/runbooks/subagent-anti-blackhole.md`
Expected: matching lines found
**Step 3: Commit**
```bash
git add WORKFLOW.md AGENTS.md docs/runbooks/subagent-anti-blackhole.md
git commit -m "docs: require reporting on suspect delivery failure"
```
### Task 23: Add owner-visible reporting rule for done-but-not-forwarded
**Files:**
- Modify: `WORKFLOW.md`
- Modify: `AGENTS.md`
- Modify: `docs/runbooks/subagent-anti-blackhole.md`
**Step 1: Add done-but-not-forwarded reporting rule**
- Must state that result exists but did not bounce back.
**Step 2: Verify text exists**
Run: `grep -RIn "done but not forwarded\|did not bounce back" WORKFLOW.md AGENTS.md docs/runbooks/subagent-anti-blackhole.md`
Expected: matching lines found
**Step 3: Commit**
```bash
git add WORKFLOW.md AGENTS.md docs/runbooks/subagent-anti-blackhole.md
git commit -m "docs: require reporting on missing forwarded completion"
```
### Task 24: Add rule to fetch history before respawn
**Files:**
- Modify: `WORKFLOW.md`
- Modify: `docs/runbooks/subagent-delivery-recovery.md`
**Step 1: Add the history-first rule**
- Done-but-not-forwarded should prefer `fetch_history` before `respawn`.
**Step 2: Verify text exists**
Run: `grep -RIn "fetch_history\|before respawn" WORKFLOW.md docs/runbooks/subagent-delivery-recovery.md`
Expected: matching lines found
**Step 3: Commit**
```bash
git add WORKFLOW.md docs/runbooks/subagent-delivery-recovery.md
git commit -m "docs: prefer history fetch before respawn"
```
### Task 25: Add no-silent-waiting-after-SLA rule
**Files:**
- Modify: `WORKFLOW.md`
- Modify: `AGENTS.md`
**Step 1: Add the no-silent-waiting rule**
- Once SLA is crossed, silent waiting is forbidden.
**Step 2: Verify text exists**
Run: `grep -RIn "silent waiting\|SLA" WORKFLOW.md AGENTS.md`
Expected: matching lines found
**Step 3: Commit**
```bash
git add WORKFLOW.md AGENTS.md
git commit -m "docs: forbid silent waiting after subagent SLA"
```
### Task 26: Create blackhole scenario test shell
**Files:**
- Create: `scripts/test_subagent_blackhole_scenarios.mjs`
**Step 1: Create the scenario test shell**
- Add empty scenario harness.
**Step 2: Verify file runs**
Run: `node scripts/test_subagent_blackhole_scenarios.mjs || true`
Expected: file executes, even if not complete
**Step 3: Commit**
```bash
git add scripts/test_subagent_blackhole_scenarios.mjs
git commit -m "test: add subagent blackhole scenario harness"
```
### Task 27: Add normal-completion scenario
**Files:**
- Modify: `scripts/test_subagent_blackhole_scenarios.mjs`
**Step 1: Write the scenario**
- dispatch -> completion receipt -> completed
**Step 2: Run tests**
Run: `node scripts/test_subagent_blackhole_scenarios.mjs`
Expected: scenario still may fail until engine wiring is ready
**Step 3: Commit**
```bash
git add scripts/test_subagent_blackhole_scenarios.mjs
git commit -m "test: add normal subagent completion scenario"
```
### Task 28: Add slow-but-active scenario
**Files:**
- Modify: `scripts/test_subagent_blackhole_scenarios.mjs`
**Step 1: Write the scenario**
- dispatch before SLA -> active
**Step 2: Run tests**
Run: `node scripts/test_subagent_blackhole_scenarios.mjs`
Expected: scenario result captured
**Step 3: Commit**
```bash
git add scripts/test_subagent_blackhole_scenarios.mjs
git commit -m "test: add slow but active subagent scenario"
```
### Task 29: Add done-but-not-forwarded scenario
**Files:**
- Modify: `scripts/test_subagent_blackhole_scenarios.mjs`
**Step 1: Write the scenario**
- child done -> no completion receipt -> fetch_history
**Step 2: Run tests**
Run: `node scripts/test_subagent_blackhole_scenarios.mjs`
Expected: scenario result captured
**Step 3: Commit**
```bash
git add scripts/test_subagent_blackhole_scenarios.mjs
git commit -m "test: add done but not forwarded scenario"
```
### Task 30: Add missing-completion-event scenario
**Files:**
- Modify: `scripts/test_subagent_blackhole_scenarios.mjs`
**Step 1: Write the scenario**
- no bounce, no completion receipt, beyond SLA -> suspect delivery failure
**Step 2: Run tests**
Run: `node scripts/test_subagent_blackhole_scenarios.mjs`
Expected: scenario result captured
**Step 3: Commit**
```bash
git add scripts/test_subagent_blackhole_scenarios.mjs
git commit -m "test: add missing completion event scenario"
```
### Task 31: Add repeated-failure escalation scenario
**Files:**
- Modify: `scripts/test_subagent_blackhole_scenarios.mjs`
**Step 1: Write the scenario**
- fetch_history fails -> respawn fails -> blocked
**Step 2: Run tests**
Run: `node scripts/test_subagent_blackhole_scenarios.mjs`
Expected: scenario result captured
**Step 3: Commit**
```bash
git add scripts/test_subagent_blackhole_scenarios.mjs
git commit -m "test: add repeated blackhole escalation scenario"
```
### Task 32: Run the full local watchdog test set
**Files:**
- Modify if needed: `scripts/test_subagent_delivery_watchdog.mjs`
- Modify if needed: `scripts/test_subagent_blackhole_scenarios.mjs`
**Step 1: Run the combined tests**
Run:
- `node scripts/test_subagent_delivery_watchdog.mjs`
- `node scripts/test_subagent_blackhole_scenarios.mjs`
Expected: PASS
**Step 2: Fix only minimal wiring needed for all-pass**
- Keep changes scoped to watchdog logic/tests.
**Step 3: Commit**
```bash
git add scripts/test_subagent_delivery_watchdog.mjs scripts/test_subagent_blackhole_scenarios.mjs scripts/subagent_delivery_watchdog.mjs
git commit -m "test: pass full subagent blackhole watchdog suite"
```
### Task 33: Peer review watchdog state logic
**Files:**
- Review: `scripts/subagent_delivery_watchdog.mjs`
- Review: `scripts/test_subagent_delivery_watchdog.mjs`
**Step 1: Request reviewer focus on receipt state logic**
- Verify statuses and transitions match B-class failure goals.
**Step 2: Record reviewer verdict**
- Include commands and findings.
**Step 3: Commit any follow-up fixes if needed**
```bash
# only if reviewer requests changes
git add <changed-files>
git commit -m "fix: address watchdog state review feedback"
```
### Task 34: Peer review recovery decisions
**Files:**
- Review: `scripts/subagent_delivery_watchdog.mjs`
- Review: `docs/runbooks/subagent-delivery-recovery.md`
**Step 1: Request reviewer focus on recovery ordering**
- Verify fetch-history before respawn and blocked escalation.
**Step 2: Record reviewer verdict**
- Include commands and findings.
**Step 3: Commit any follow-up fixes if needed**
```bash
# only if reviewer requests changes
git add <changed-files>
git commit -m "fix: address recovery decision review feedback"
```
### Task 35: Peer review scenario coverage and handoff
**Files:**
- Review: `scripts/test_subagent_blackhole_scenarios.mjs`
- Review: `docs/runbooks/subagent-anti-blackhole.md`
- Review: `docs/runbooks/subagent-delivery-recovery.md`
**Step 1: Request reviewer focus on blackhole realism**
- Confirm this targets fake timeout / no-bounce cases, not just slow work.
**Step 2: Record verification output**
- Include exact commands and reviewer verdict.
**Step 3: Final state**
- Leave task in `pending_verification`; do not mark complete.