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
Failure Classification and Targeted Recovery
Source: Self Healing Agentic Orchestrator (Suresh Babu & Agrawal 2026; author-built benchmark, no external replication). The core loop above diagnoses “failure type” loosely. The paper makes it explicit as a monitor → detect → diagnose → recover → verify control plane around the agent, and shows why it matters: a uniform recovery action (retry everything, or replan everything) mismatches many causes.- Separate detector, classifier and policy. The detector answers did it deviate?, the classifier why?, the policy what now, given the remaining budget?
- Map class → action, cheapest local fix first: timeout → retry with backoff or substitute tool; bad arguments → repair and regenerate the call; stale context → refresh retrieval; contradictory evidence → cross-check an independent source; retry storm / no progress → stop, replan from a checkpoint, or escalate. Full replanning and human escalation come last.
- Budget is a vector, not a count: retry, replanning, tool-substitution, model-escalation, latency and cost. Failed attempts still spend it.
- Verifier rejection is a failure signal. Wrong-but-plausible output raises no runtime error; only a verifier inside the loop catches it. In the paper’s semantic-fault setting, non-verifying methods returned silent wrong answers 13.2–17.6% of the time vs 0.0% with the verifier.
Ops Layer: Alert → Agent PR → Human Merge
Source: Agentic Ai Lifecycle Self Healing Ops (vendor blog, no measurements). In production operations the loop is: smart alert (dynamic baseline) → SRE agent root-cause analysis over logs/traces/deploys → remediation report → auto-created issue with telemetry → coding agent opens a PR → on-call engineer reviews and merges. The argument is that investigation and coordination, not the fix, dominate MTTR. The human stays on the merge, which is the same escalation boundary as the CI layer.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): CI lint/test stage fails → agent gets the failure output and a constrained toolset (
ReadFile, WriteFile, ListFiles, RunTests, RunLint, where the run tools reuse the project’s existing Dagger Functions) → loops fix/rerun until green → returns a diff → a second function posts it as line-anchored GitHub code suggestions. Agent never pushes or merges. The source post names no retry cap or give-up path; supply one from the budget table above.
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
- Self-Improving Agent Setup — changes the harness between runs; self-healing recovers within a run
- Confidence Aware Routing — pre-generation counterpart: route uncertain queries to RAG/larger model/human before failing
Linked pages
- Agent Harness
- Agentic CI/CD
- Agentic Sandbox Controls
- Distributed Systems
- Error Budget (Agentic)
- Error Handling Patterns
- Ralph Loop
- Scalability and Reliability
- Self-Improving Agent Setup
- Verification Pipeline
- Worktree Isolation