MJ-skill/autonomous-chain-control-flow/SKILL.md
--- name: autonomous-chain-control-flow description: Wake-signal handling in user-authorized autonomous chains (arc plan / long-running /loop / multi-round research arc). Encodes two principles — (1) "wake signal = advance trigger, NOT inbound notification": any signal that lifts Claude out of idle (cron probe tick, background task completion notification, ScheduleWakeup fire, mid-chain user message) is a state-machine advance trigger; (2) "wake-source paths are independently failable + silent-s
npx skillsauth add develata/deve-skills MJ-skill/autonomous-chain-control-flowInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
In an autonomous chain (user-authorized multi-step task that proceeds without per-step approval — arc plan / long /loop / multi-round research), Claude's execution model is an event loop + state machine, not request-response. Any signal that wakes Claude from idle — task-notification (background bash done), cron probe tick (CronCreate fire-as-input), ScheduleWakeup fire, mid-chain user message — is a state-machine advance trigger, NOT an inbound message to merely acknowledge. Wake-source paths are independently failable (each has known failure modes — see §Wake-source independence below), so on any wake, Claude's first action MUST be: (0) full chain-state sweep (don't trust the current wake to be exhaustive), (1) read state implications, (2) find next executable transition, (3) execute until next true yield point (= external dispatch / wait-on-external / user-checkpoint).
<task-notification> arrives mid-chain (background bash completion)ScheduleWakeup firesOn any wake signal in autonomous chain context:
0. FULL STATE SWEEP — do NOT trust the current wake to be exhaustive. Independent of
what the wake signal says, scan ALL in-flight chain state:
- all in-flight background tasks: read their log tail + grep DISPATCH_STATUS
- all active CronList probes: check each probe's sentinel + corresponding log
- all expected output artifacts: ls -la the run dir for new files
- TodoWrite: which task is in_progress?
If sweep reveals a TERMINAL state the current wake didn't mention
(e.g., a different background task also completed silently), include
that transition in steps 1-3.
1. READ STATE IMPLICATIONS — given the sweep findings, what round / stage was I in?
What was the last yield point waiting for? Which TERMINAL
states are newly visible?
2. FIND TRANSITION(S) — given current state + ALL newly-terminal items (not just the
wake source), what is/are the next executable transition(s)?
Examples:
- "background task completed" + sweep finds OTHER task also done → handle both
- "probe tick: codex DISPATCH_STATUS=completed" → CronDelete probe + read artifact + advance
- "ScheduleWakeup fire" → continue from where the loop left off + sweep for any other state change
- "user mid-chain 'continue'" → sweep, then resume next pending todo (likely covering items the user is implicitly flagging by saying "continue")
3. EXECUTE TO NEXT YIELD — run all transitions until reaching a true yield (= external
codex dispatch in flight, wait-on-user-input, waiting for
human review). Do NOT stop early. Do NOT report
"ready to advance" and wait.
Step 0 is the silent-stuck defense. If a wake source fails (probe message lost / task-notification suppressed / etc.), the sweep at the NEXT wake (from any other source — including a user message) catches the missed terminal. Without step 0, a lost wake = permanently lost chain advance.
| Signal type | Source | Wake semantics |
|---|---|---|
| Background-task completion | <task-notification> from run_in_background:true Bash | dispatch finished → check artifact + advance |
| Cron probe tick | CronCreate recurring=true fires as user-shaped input | check sentinel + dispatch status + advance or report progress |
| ScheduleWakeup fire | Self-scheduled (rare in arc plans, common in /loop) | continue the loop logic |
| Mid-chain user message | User types during autonomous chain | check if redirect (new directive) or continuation (advance) |
All four collapse to the same handler: sweep → read state → find transition → execute.
Each wake source has independent failure modes; no single source is reliable enough alone:
| Source | Known failure mode |
|---|---|
| <task-notification> | Codex CLI internal errors (e.g., record rollout items: thread not found) can suppress harness's notification dispatch even when child process exits 0 cleanly. Observed 2026-05-18 E2 R0. |
| Cron probe tick | Fire-then-input mechanism can lose messages: probe fires + CronDeletes itself on terminal detect, but the fire's user-message payload doesn't always reach Claude's input stream (race / queue / harness state). Observed 2026-05-18 E2 R0 (c23ca85e self-deleted but no PROBE_TICK message ever landed). |
| ScheduleWakeup | Only fires when scheduled; if author forgot to schedule it as a backup, no fallback exists. |
| Mid-chain user message | Requires the human to notice silence — defeats autonomous-chain purpose. |
Architectural conclusion: Redundancy across sources, plus Step 0 full-state sweep on any wake (including user messages), is the only robust handler. Belt + suspenders, not pick-one.
Operational defense per dispatch:
codex-dispatch-watchdog — current lifecycle: v3 2-tick grace self-delete.<task-notification> is the primary path).ScheduleWakeup at estimated-dispatch-time + 5 min as a last-resort backup for dispatches >10 min wall.Probe terminal detection, prompt template, sentinel touch, counter file, and self-delete lifecycle live in codex-dispatch-watchdog § "Layer 2 — Cron probe" and § "Terminal-state lifecycle". Current lifecycle at this review: v3 2-tick grace self-delete (probe re-reports terminal on tick 1, self-deletes on tick 2).
This skill adds only the semantic rule: any probe fire is a wake signal. On a terminal probe fire, run the 4-step wake handler starting with step-0 full state sweep, then advance the chain. Claude MAY explicitly CronDelete after acting for faster cleanup; otherwise the watchdog v3 lifecycle self-deletes on the second terminal tick.
If an autonomous chain adds extra terminal predicates (e.g. a HALT marker), treat them as additive status checks inside the watchdog pattern, not as a separate probe lifecycle.
Avoid wake-signal names that imply "passive notification" (PROBE_TICK, notification, update). Prefer active-voice naming (CHAIN_TICK, RESUME_TRIGGER, ADVANCE_SIGNAL) — this is the linguistics fix that makes the principle harder to forget.
If you author probe prompts, end the terminal-report line with a verb command, not a status noun:
| ❌ "next: Stage 4 convergence" | ✅ "advance to Stage 4 NOW (wake = advance trigger)" | |---|---|
Observed failure: probe 0f71a526 fired with content PROBE_TICK ... DISPATCH_STATUS=completed. Claude:
User correction: "为什么没走autonomous". The probe tick was the main-session activation. Step (4) was the failure — Claude treated the wake as a notification to acknowledge, not as an advance trigger to execute on.
Root cause (per first-principles diagnosis at the time): Claude carried a request-response mental model into autonomous-chain context. The wake-signal taxonomy + 4-step handler above counters this.
Observed failure: codex E2 R0 lit review dispatch (bg br34irrbe, probe c23ca85e) ran ~10 min, completed cleanly:
=== DISPATCH_STATUS=completed (exit 0) ===_LIT_REVIEW_CODEX.md (16551 bytes) writtenERROR codex_core::session: failed to record rollout items: thread ... not found before exitBut Claude never got woken:
<task-notification> never arrived (suppressed, probably by the rollout-items session error)c23ca85e was already deleted by the time Claude looked (CronDelete c23ca85e → "No scheduled job") — it self-deleted on terminal detect (prior pattern) but its fire message never reached Claude's input streamClaude waited silently for ~5 min until the user manually said "进入下部分, autonomous", which finally triggered investigation.
Root cause (per first-principles diagnosis at the time): wake-source paths are independently failable, and the prior architecture treated probe self-delete on terminal as fire-and-forget — single point of failure. Fix: Step 0 full state sweep on ANY wake (including user messages) catches missed terminals; the probe lifecycle (now v3 2-tick grace self-delete, per codex-dispatch-watchdog) prevents permanent loss of the probe-signal path by guaranteeing ≥2 terminal fires before deletion.
| Composes with | Role |
|---|---|
| codex-dispatch-watchdog | cron probe is the physical carrier of one wake-signal class; this skill describes the semantic handling of all wake signals including probe ticks |
| research-round-lifecycle | chain state = round state machine; this skill describes the wake-to-advance protocol that moves between rounds in autonomous mode |
| claude-decision-discipline G5 | plan*do iteration assumes plan-state is queried at each step; this skill operationalizes "query plan-state on every wake" |
<task-notification> as just a status update + reporting it to user without advancingBefore ending a turn in autonomous chain, verify:
CronDelete any probe whose terminal I've already acted on? (v3 probes self-delete on the 2nd terminal tick; explicit CronDelete after advance is just faster cleanup — see codex-dispatch-watchdog)If any item is "no" — keep going, you have not yet reached a yield.
tools
Collect and audit Codex token usage with a bundled Python CLI and optional Windows batch launchers. Use this skill when the user asks to check Codex token usage, generate daily token audit logs, calculate monthly CostUSD totals, review Codex spending, or run Codex token usage scripts on Windows, Bash, WSL, or Linux.
tools
Use when giving the user an INLINE reply that carries a trade-off, a decision, a verdict, or a non-trivial finding (decision brief / round verdict / failure root-cause). NOT for "done"/status confirmations, one-line answers, or pure data dumps. Forces a compact decision-brief shape and blocks internal tool-name / file-path bleed into user-facing text.
development
Use for cross-file or cross-chapter terminology audits and corpus-wide term unification in thesis/paper sources — extract candidate term drift, build a decision queue, classify each occurrence, apply accepted replacements safely, and verify counts/build. Trigger on "术语审计", "术语统一", "术语一致性", "逐词审", "这个词全文怎么用", "把 X 全文改成 Y", "terminology audit", or "unify term X". Do NOT use for ordinary prose drafting or a single known-location edit; use academic-writing for prose quality and claim-boundary judgment.
tools
Use for ANY codex CLI dispatch via dispatch wrapper (no time threshold; presence-of-risk triggers, not estimated wall — stdin-EOF stalls occur at <60s). Combines internal log-inactivity watchdog wrapper + external Claude-session cron probe + sentinel hook enforcement. Detects stalls in ≤60-270s vs hours-without-detection failure mode.