cron-agent-patterns
Layered timeout defense for cron-orchestrated agents calling external APIs (LLM CLI, HTTP, subprocess) — nested tiers, anti-patterns, headroom.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Layered timeout defense for cron-orchestrated agents calling external APIs (LLM CLI, HTTP, subprocess) — nested tiers, anti-patterns, headroom.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | cron-agent-patterns |
| description | Layered timeout defense for cron-orchestrated agents calling external APIs (LLM CLI, HTTP, subprocess) — nested tiers, anti-patterns, headroom. |
TL;DR: A cron-orchestrated agent that makes external API calls (LLM CLI, HTTP client, subprocess) can hang, drift past its window, or overlap the next cron tick. Defend with nested timeouts — each tier strictly smaller than the one enclosing it — plus symmetric deadline guards and explicit headroom for the next fallback tier.
Load this skill when implementing or reviewing any agent that:
sleep-loop) andThe pattern is stack-agnostic — the tier names below map onto any runtime
(Python signal/subprocess, Node timers/AbortController, Go context,
shell timeout).
Order the timeouts so each inner budget is strictly smaller than the budget enclosing it. Violating the strict-nesting invariant means an inner tier can never fire before the outer one preempts it — the inner guard becomes dead code.
(a) per-call timeout < (b) per-cycle deadline budget
(wall-clock, time.monotonic)
(b) per-cycle deadline < (c) SIGALRM safety net
(catches C-level blocked syscalls the
library-level timeout cannot interrupt)
(c) SIGALRM safety net < (d) shell `timeout --kill-after` outermost guard
(cron-level watchdog; kills the whole
process tree if everything above wedges)
--timeout). Must be short enough that
the whole cycle — including retries and fallbacks — still fits inside (b).deadline = time.monotonic() + CYCLE_BUDGET_SEC). Before every
external call, check time.monotonic() < deadline; skip the call if not.SIGALRM (or the runtime's equivalent
hard alarm) so the process is forced back into your handler and raises a
CycleTimeout.timeout --kill-after=<grace> <hard-limit> <cmd>. This is the last line of
defense when everything in-process has wedged. Set it above (c) so the
in-process net gets first chance to exit cleanly.Per-call timeout == cycle budget. If the per-call limit equals the whole cycle budget, the math forbids the call from ever fitting alongside retries or the next-tier fallback. A single slow call consumes the entire window.
max(N, deadline - now) floor. Flooring a per-call timeout at a constant
N re-inflates a doomed call after the deadline has already passed:
once deadline - now goes negative, max(1.0, deadline - now) stages a
fresh 1-second call past the deadline. Never floor the remaining budget —
if deadline - now <= 0, skip the call, do not clamp it back up.
except Exception: pass swallowing the alarm. A bare
except Exception: around the call body silently eats the exception raised
by the SIGALRM handler, so the safety net never propagates. Re-raise
CycleTimeout (or the equivalent) before the generic handler:
try:
result = call_provider(...)
except CycleTimeout:
raise # let the safety net escape
except Exception:
log_and_continue() # only ordinary failures land here
MC_RESERVE_SEC) from the budget handed to each tier:
tier_budget = (deadline - now) - RESERVE_SEC. Without headroom the primary
consumes the whole budget and the fallback is dead on arrival — producing
duplicate timeout alerts with no recovery.CycleTimeout re-raised before any generic except.timeout --kill-after wraps the whole invocation as outermost guard.Schema and migration semantics for /dr-doctor — thin one-liner contract, 6-pass migration, data-loss safety, conflict resolution. Loaded by self-heal.
Core Datarim rules. Load this entry first, then only the fragment needed for paths, storage, numbering, backlog, routing, or archive behavior.
Post-QA hardening — detects task type (code, docs, research, legal, content, infra) and applies the matching verification checklist before archiving.
Testing pyramid, frameworks, mocking. Load first; then the fragment for the active gate (live smoke, silent failure, bats, legacy triage).
Preserve Datarim task continuity while orchestrated Claude Code or Codex sessions compact or clear context at deterministic pressure thresholds.
Immutability contract for all pipeline stages: artefact freeze, V-AC parity, non-code parity, anti-tautological rule, and return-to-source transition.