Skip to content

feat(self-healing): API-key preflight + cost_preflight claim-guard + launchd KeepAlive - #8

Open
kushalj1997 wants to merge 1 commit into
mainfrom
codex/agent-swarm-p0-self-healing-20260607
Open

feat(self-healing): API-key preflight + cost_preflight claim-guard + launchd KeepAlive#8
kushalj1997 wants to merge 1 commit into
mainfrom
codex/agent-swarm-p0-self-healing-20260607

Conversation

@kushalj1997

Copy link
Copy Markdown
Owner

agent-swarm self-healing P0 — survive failures without a babysitter

Three self-healing features so the perpetual swarm keeps running as reliable code, not something an agent has to nurse:

  1. API-key fail-fastconductors/env.py:require_anthropic_api_key() (deliberately never returns the key value — readiness proof only), wired into factory.py + api.py. An API conductor now refuses to claim a task when ANTHROPIC_API_KEY is missing/blank, instead of claiming it then dying mid-run and stranding the task.
  2. cost_preflight enforcedsupervisor._preflight_before_claim() runs cost_preflight (which was written + unit-tested but never actually called) before every claim, rejecting over-cap tasks; same guard wired into perpetual.py's drive path.
  3. launchd KeepAlivedocs/launchd/ template + README for OS-level auto-restart of the perpetual supervisor. No API key embedded (placeholders only).

Tests: test_conductor_api, test_conductor_factory, test_perpetual, test_supervisor, test_launchd_template.

⚠️ Do NOT merge until tested — two known risks to validate first

  • cost_preflight starvation: ensure the default cost_cap_usd is generous enough that a normal sliced task passes, and prefer hold-admit over hard-reject on ambiguous estimates — otherwise agents idle. Mitigation: assign work in slices + sane cap.
  • launchd env var: the API-key fail-fast + launchctl setenv combo can crash-loop the supervisor if the key doesn't reach the launchd context. Prefer a runtime wrapper that reads the key from the chmod-600 api_keys/ file (the DM task-queue-wrapper pattern) before ever launchctl load-ing it.

Implemented by the Codex agent-swarm worker; published by Claude per direct operator approval (Kushal, 2026-06-07). Verified: placeholders only, no real key in any committed file.

🤖 Generated with Claude Code

…launchd KeepAlive

Three self-healing P0s so the perpetual swarm survives failures without an agent
babysitting it:

1. API-key fail-fast — conductors/env.py require_anthropic_api_key() (deliberately
   never returns the key value, only proves readiness) wired into factory.py +
   api.py, so an API conductor refuses to claim a task when ANTHROPIC_API_KEY is
   missing/blank instead of claiming it then dying mid-run (stranded task).
2. cost_preflight enforced — supervisor._preflight_before_claim() runs
   cost_preflight (previously written + unit-tested but NEVER called) before every
   claim, rejecting over-cap tasks; same guard wired into perpetual.py's drive path.
3. launchd KeepAlive — docs/launchd/ template + README for OS-level auto-restart of
   the perpetual supervisor. NO API key embedded in the plist (placeholders only).

Tests: test_conductor_api, test_conductor_factory, test_perpetual, test_supervisor,
test_launchd_template.

Known follow-ups before activation (tracked, not in this PR): tune default
cost_cap_usd + prefer hold-admit over hard-reject so slices never starve agents;
supply ANTHROPIC_API_KEY to the launchd supervisor via a runtime wrapper reading the
chmod-600 api_keys file (the DM task-queue-wrapper pattern) rather than launchctl
setenv, to avoid a fail-fast crash-loop.

Implemented by the Codex agent-swarm worker (worktree
.worktrees/agent-swarm-p0-self-healing-20260607); published by Claude per direct
operator approval (Kushal, 2026-06-07). Verified: placeholders only, no real key in
any committed file.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant