Self-healing
How the factory detects and corrects stuck work on its own — status drift, orphaned runs, and human replies that need routing back to the right agent.
The factory spends most of its life running without anyone watching. Agents get stuck,
status fields drift out of sync with actual run state, and human responses to
[NEEDS_INPUT] need to be re-routed back to the Lead. Self-healing is the layer that
detects and corrects these conditions automatically.
This is the operator-facing overview. For the full technical spec see
../architecture/self-healing.md and
ADR 0037.
Three layers — one job each#
The factory uses three layers to cover different failure classes. Each layer owns distinct failure modes and is sized for what it actually needs to do.
| Layer | What it is | What it fixes | Runs where |
|---|---|---|---|
| D — Deterministic guard | Plain Python (cmd/operate-reconciler/) |
Status/run-state mismatches (mechanical, exact) | Outside Multica — launchd now, GKE CronJob later |
| J — LLM judgment | Multica autopilots (factory-watchdog skill) |
Wedged tasks, transient faults, meta-audit of the autopilot fleet | Inside Multica — LLM agent |
| H — Human-SLA | Multica autopilots (needs-human-requeue, stale-issue-reviewer) |
Human response routing, escalation on silence | Inside Multica — LLM agent |
Why the split? A healer that runs as a Multica LLM autopilot can itself get orphaned — the exact failure it is supposed to fix. Layer D runs as plain code outside Multica so it keeps running even when the LLM fleet is completely wedged.
Layer D — the deterministic rule table#
cmd/operate-reconciler/reconcile.py applies a table of deterministic heals on every sweep.
Each rule fires only when no agent run is active on the issue (diagnose-first — never touch
something that's working). The table started at six rows and has grown; the roster and live
enablement below track registry/factory.yaml → operate.heals (the source of truth).
| Name | Condition | Action | Status |
|---|---|---|---|
escalation_to_blocked |
[NEEDS_INPUT]/[NEEDS_UPSTREAM] present, or human-assigned with resume_to, but issue ≠ blocked |
→ blocked |
ON |
in_review_to_done |
in_review + terminal [HANDOFF]/[VERDICT] marker, no active run |
→ done |
ON |
orphan_rerun |
todo/in_progress + completed run with no status update |
→ done/blocked/rerun (re-wake only for containers) |
ON |
unblock_on_upstream_done |
blocked + every [NEEDS_UPSTREAM] upstream is done |
→ todo |
ON |
transient_rerun |
Failed run whose error matches a transient pattern (e.g. gateway 502) | rerun (re-wake) | ON |
design_before_build |
ADR 0036 phase-order — a build child precedes its design handoff | hold/reorder | ON |
mission_inherit |
A child lost a mission-level field (base branch, project) | re-propagate from the root | ON |
human_gate_label |
Human-assigned + resume_to + ¬needs-human (shapes (a) blocked, (b) in_progress) |
arm the gate: add needs-human (set blocked first for (b)) — label/status only |
ON (2026-06-27) |
gate_release |
requeued_comment_id set ∧ todo ∧ human-assigned ∧ resume_to ∧ residual pending-approval*/waiting_on |
strip residue + reassign to resume_to + [RECONCILED] |
ON (2026-06-27) |
upstream_wake |
Child carries the needs-upstream label + [NEEDS_UPSTREAM] but the Lead was never woken |
wake the Lead | ON (2026-06-28) |
stale_guard_release |
Issue auto-blocked by a reconciler escalation that no longer applies | with a [HANDOFF]: → todo → done; without: arm needs-human + resume_to |
ON |
wedged_rerun |
in_progress + run past the floor, no agent activity (judgment) |
cancel + rerun | OFF (LLM needed) |
wedged_rerun stays off because distinguishing "still working" from "wedged" requires LLM
judgment — the deterministic fast-path alone isn't safe to fire at production blast radius.
The two human_gate_* heals are the deterministic backstop for the escalation contract
(Flow 05) — see Layer H below.
Bounding — strike cap#
Every heal is bounded. Per registry/factory.yaml → operate.strike:
- 3 strikes per
(issue, heal_kind)in a rolling 24h window. - 5 strikes aggregate per issue across all heal kinds.
When a cap trips, the issue is set blocked and a [NEEDS_INPUT] is posted — the
factory escalates to a human rather than looping forever.
Master kill-switch#
operate.self_heal_enabled: false in registry/factory.yaml puts every sweep into
diagnose-and-log mode. Nothing mutates. Use this to inspect what the reconciler
would do before enabling a new heal kind.
Layer D — the phase validator (ADR 0051)#
On every sweep, the same reconciler also runs the phase validator: a structural
deliverable gate that checks whether an in_review issue actually contains the correct
artifact before it advances to done.
This exists because LLM agents sometimes post a prose stub instead of the mandated
[HANDOFF] block, or omit required fields. The validator catches this deterministically
without an LLM.
What it checks per phase class:
| Phase class | Issues | What the validator checks |
|---|---|---|
| producer | discovery, plan, design-ux, design-tech, build, fix, fix-design, onboard-build | [HANDOFF] block present + JSON-parseable; required fields (e.g. branch, pr_url for build); metadata typed correctly |
| reviewer | review-ux, review-design, review-code, qa-review | A [VERDICT-*] marker is present; verdict body validates against schemas/verdict.schema.json |
| human-gate | deploy (deployment_phase=1) | Never auto-advanced — always waits for human |
On PASS: posts [VALIDATOR] pass comment; advances in_review → done.
On FAIL: posts [VALIDATOR] fail {missing: [...]} comment; bounces in_review → todo
so the agent retries. After N bounces the strike cap escalates to needs-human.
Gated by operate.validate_enabled in registry/factory.yaml. Was staged OFF during
dogfood; now ON.
Layer H — human-SLA autopilots#
Two LLM autopilots handle the human-interaction side:
needs-human-requeue (every 30 min)
Scans issues labeled needs-human. When the assigned human has posted a reply, clears the
label and resumes the issue's metadata.resume_to assignee (status=todo) — the
escalating agent itself for a within-phase question, or the Lead for a root-level gate. It
never routes by @mention. If the SLA deadline passes with no reply, escalates to the
next tier. (On an autonomy:full mission a decidable [NEEDS_INPUT] is instead resumed
by the autonomy-resolver autopilot against its proposed_default — see
Flow 05.)
Deterministic backstop — the
human_gate_*heals. The requeue scans purely by theneeds-humanlabel, so an agent that staged a gate (blocked+ human-assigned +resume_to) but forgot the label leaves it invisible. The reconciler'shuman_gate_labelheal arms it (adds the label; for anin_progressissue it setsblockedfirst), and its dualgate_releasefinishes a half-released gate the requeue left stuck. Both live since 2026-06-27 — see the deterministic heal roster in the self-healing tech spec.
stale-issue-reviewer (daily 09:00 IST)
Handles human-assigned issues that have gone silent:
- 8h of silence → pings the owner.
- 24h → escalates with
escalatedlabel and pages the DevOps lead.
These complement Layer D: D enforces status invariants; H handles the time/SLA surface that requires knowing whether a human actually replied, which requires reading comments.
Layer J — judgment autopilots#
The factory-watchdog LLM autopilot (daily 11:00 IST) handles things Layer D can't do
deterministically:
- Meta-audit: checks the autopilot fleet for disabled/misconfigured autopilots.
- No-op-storm detection: flags autopilots firing on empty queues.
- Orphaned-scaffolding sweep: closes leftover
[fix]issues from cancelled missions. - SLO drift: flags missions that are burning beyond expected duration.
Row 5 (wedged_rerun) will eventually move here once the judgment classifier is built —
it needs LLM to distinguish "agent still producing output" from "agent stuck in a loop."
How to operate it#
Run a manual sweep (dry-run first, always)#
make operate-reconcile # dry-run — shows WOULD-heal, no mutations
make operate-reconcile-apply # APPLY — heals + validator
Or scoped to one project:
python3 cmd/operate-reconciler/reconcile.py --project <uuid> # dry-run
python3 cmd/operate-reconciler/reconcile.py --project <uuid> --apply
Continuous autopilot (10-min loop)#
make operate-autopilot # runs until Ctrl-C
Install as a persistent launchd agent (survives logout/reboot)#
sed "s|__REPO_ROOT__|$(pwd)|g" cmd/operate-reconciler/com.kapiva.yantra.operate-autopilot.plist \
> ~/Library/LaunchAgents/com.kapiva.yantra.operate-autopilot.plist
launchctl load -w ~/Library/LaunchAgents/com.kapiva.yantra.operate-autopilot.plist
Watch it:
tail -f /tmp/yantra-operate-autopilot.log
Stop / remove:
launchctl unload -w ~/Library/LaunchAgents/com.kapiva.yantra.operate-autopilot.plist
rm ~/Library/LaunchAgents/com.kapiva.yantra.operate-autopilot.plist
Read the R9 structured log#
Every evaluated heal emits a JSON line to /tmp/operate-r9.jsonl. Each line is one
heal evaluation: issue id, heal kind, outcome (applied/skipped/would_apply/error),
and the reason.
cat /tmp/operate-r9.jsonl | python3 -m json.tool | grep '"outcome"'
Enable / disable individual heal rows#
In registry/factory.yaml → operate.heals:
operate:
heals:
wedged_rerun: { enabled: true } # arm the judgment row (ensure Layer J is live first)
transient_rerun: { enabled: false } # disarm a deterministic row
Restart the autopilot after any factory.yaml change.
Kill-switch (no mutations, diagnose only)#
operate:
self_heal_enabled: false
What operators should and shouldn't do#
Do:
- Run
make operate-reconcile(dry-run) to see what the reconciler would do before a manual intervention — avoids double-healing. - Check
/tmp/operate-r9.jsonlwhen a mission appears stuck; the reconciler logs every evaluation, so you can see whether it already tried and what it found. - Set
self_heal_enabled: falseduring a manual recovery if you need to move issues around without the reconciler fighting you.
Don't:
- Manually flip issue statuses while the autopilot is running with
--apply— the reconciler will evaluate your change on its next sweep and may undo it if the state doesn't match its rules. - Arm the judgment row (
wedged_rerun) without Layer J live, or enable any heal before a clean live dry-run — heals ship OFF by default for safety (ADR 0026; high blast radius). - Modify
reconcile.pyrule logic without updatingtest_reconcile.py— the test suite is the spec; the code is the implementation.
Production target (deferred)#
Today Layer D runs on macOS via launchd. The production target is a GKE CronJob in
GKE Mumbai (the same cluster as the Memory Engine and Multica MCP). Blocked on: a
Linux multica CLI build, plus containerizing reconcile.py with a workspace-scoped
token mounted as a secret. Tracked as an open item in ADR 0037.
References#
../architecture/self-healing.md— full tech spec: owner map, gap analysis, redundancy resolution- ADR 0037 — execution plane decisions: hybrid vs all-LLM, GKE vs launchd, Activepieces gating
- ADR 0051 — phase validator: per-phase contracts, deliverable checking, staged rollout
cmd/operate-reconciler/README.md— the reconciler's own runbook (6-row table, F3, launchd install, tests)registry/factory.yaml— kill-switch, heal enablement flags, strike caps