Self-Healing Loop
A harness pattern where an autonomous agent detects its own failures, attempts bounded repair, and falls back to rollback + escalation when repair budget is exhausted. The complement to the Ralph Loop (which handles continuation past stopping points) — self-healing handles recovery from failure within each iteration.Core Loop
Failure Signature Detection
Repeating the same failed patch is the most common infinite-loop failure mode. The harness tracks failure signatures:Retry Budget by Failure Type
Different failures warrant different budgets:
Destructive operations (migrations, deploys) get lower budgets than reversible ones (test patches, lint fixes).
Rollback Protocol
When retry budget is exhausted:- Revert to last known-good state —
git reset --hard <last_green_sha>or redeploy last passing image - Write machine incident note — structured file capturing: failure type, retry count, failure signatures seen, diff that was attempted, timestamp
- Signal escalation — set a flag/file the outer harness monitors; stop the loop; do not continue building
Guardrails (Non-Negotiable)
These are enforced by the harness, not by the agent’s discretion:- Max retries per session: total cap across all failures (e.g., 10); prevents budget exhaustion attacks
- Diff size cap: reject any single patch > N lines changed — forces the agent to patch incrementally, not rewrite
- No auto-destructive migrations: schema drops, column renames, table truncations must be human-approved; the loop can propose but not execute
- Stop on repeated same-failure signature: hook blocks execution if signature hash already seen in this session
- Timeout per iteration: each repair attempt has a wall-clock timeout; prevents stuck builds
Composition with Ralph Loop
The ralph-loop is the outer driver; self-healing is the inner recovery mechanism:Observability Requirements
The self-healing loop must produce machine-readable output the outer harness can monitor:loop-state.json— current task, iteration, retry count, last failure typeincidents/YYYY-MM-DD-HH-MM.md— structured rollback records- Exit codes — 0 (success), 1 (rollback, needs human), 2 (budget exhausted, escalate immediately)
Reference Implementations
Dagger handles the “analyze and patch” half; ArgoCD handles the “rollback on deploy failure” half; Windmill provides the retry scheduling primitive that both can use.
Dagger flow (AI-driven CI layer): detect failure → agent analyzes log → patches code scoped to relevant file → reruns only the failing gate (not full suite) → posts reviewed diff to PR; agent does not auto-merge.
ArgoCD rollback (deploy layer):
When Self-Healing Fails
Self-healing loops fail in predictable ways:Related Pages
- Ralph Loop — outer continuation driver; composes with self-healing
- Agent Harness — harness component model; loop guardrails live here
- Agentic CI/CD — CI as external watchdog; gate sequence that triggers self-healing
- Verification Pipeline — the verification layer whose failures trigger self-healing
- Agentic Sandbox Controls — isolation required for safe autonomous operation
- Worktree Isolation — isolates each repair attempt’s filesystem changes