13. Self-repair (for admins)
The Foundry can find problems of its own, write them up, fix them and check that the fix worked. This chapter is the overview; the details are in chapter 6.
The loop: the monitor finds a problem that lasts → it writes one bug story on GitHub → the
issue watcher builds that story first → as a hotfix it goes to main and develop → the
monitor reads the fix commit and, once the running Foundry has it, watches for 24 hours → no
more problem: the story gets "Not seen since the fix.".
It is off by default. Nothing here starts until an admin does the five steps in Switch it on and off.
You work with self-repair in the Admin view. Open Administration in the sidebar. Under Operations you find Problems (the findings, with Try again and Mute) and Watchers (the monitor's card). The switches for hotfixes and self-update are under System → Settings, in the Safety section.

What the monitor looks for#
These are the names as they appear in the log and in mutes. The thresholds are in the table in chapter 6.
Each detector and each automatic repair has a class: fixes alone (the Foundry does it by itself) or asks you first (it shows the problem and waits for you). The Problems page shows the class in its detectors table and lists the automatic repairs above it.
The rule, in two sentences: the Foundry fixes a problem alone when the fix can be undone and touches
only its own work. It asks you first for governance, security, secrets, force pushes, deleting data,
merging or releasing to main, spending limits and turning a check off, except where you already
agreed by turning on Hotfixes, the daily release or automatic demotion. One exception to the secrets
rule and to rewriting commits: a push that the secret scan blocks only because of values shaped like
secrets in test files is repaired alone, once per run (see test-values-faked in the table below).
| Detector | Class | What it finds |
|---|---|---|
restart-loop | fixes alone | the same run is resumed again and again (critical) |
watcher-error | fixes alone | a watcher's checks fail one after the other (major) |
github-limit | fixes alone | GitHub's request limit is hit or nearly used up (critical or major) |
watcher-silent | fixes alone | an enabled watcher finished no check (critical) |
unexplained-failure | fixes alone | a run failed with an error no rule explains (minor) |
stuck-run | fixes alone | a running run wrote nothing to its log for too long (major) |
same-step-failing | fixes alone | the same step ended runs as failed for different issues (major) |
label-mismatch | fixes alone | an issue's status label does not match its newest run (major) |
waiting-unlisted | fixes alone | an open issue has a waiting label, but Needs you does not list it (minor) |
held-unknown | fixes alone | a watcher keeps a story back for no known reason (major) |
long-wait | fixes alone | a story waited longer than wait_hours (6) without starting; time spent waiting for a person does not count; the finding names what it waits for (minor) |
dead-chain | asks you first | open stories wait for an issue that will never be built; the owner decides (minor) |
orphan-lock | fixes alone | a lock is held by a run that is not running (major). The server frees such markers and locks itself, at start and every minute |
queue-stalled | fixes alone | jobs are queued, slots are free, and nothing starts (critical). It stays quiet while a restart or drain holds new work back on purpose; restart-overdue reports that wait instead |
restart-overdue | fixes alone | a restart or drain waits too long: a new version is installed, or the server drains for a moved data folder, a changed setting or its health while ready work is held back. It names the run it waits for (major) |
monitor-blind | fixes alone | a measure that should always move (runs started while work is ready, watcher checks, server log lines) stood still for monitor_blind.minutes and no detector that covers it reports anything. The monitor writes the state of every detector to the server log and runs them again; after a second failure in a row, repair-failed asks you (major) |
develop-red | fixes alone | the tests after merges into develop fail for several different stories in a row (critical) |
slow-step | fixes alone | a step took much longer than usual (not counting waits for a test slot), and did so clearly more often than its usual times show: at least times more slow visits than expected and more than twice the expected number. Needs at least 10 usual times for the step (minor) |
slow-test-file | fixes alone | one test file of the report_to repository took more than 10% of the test suite's time on each of the last 3 days (major). Its story gets only the enhancement label, so it is built only after you add your build label |
test-leftovers | asks you first | the tests of a repository left processes running in 3 runs in a row; fix the tests so they end what they start (minor) |
policy-service-failure | fixes alone | policy decisions said the policy was unavailable or invalid (major) |
evidence-finalization | fixes alone | a run ended but its evidence has no evidence.json, or its stream stopped (major) |
step-latency-p95 | fixes alone | the p95 of a step's durations is above the limit (minor) |
repeated-tool-denial | asks you first | the same tool was refused again and again; the fix is a change to allowed_tools (minor) |
abnormal-output | fixes alone | a step wrote far more output than is usual for that step (minor) |
self-update | asks you first | an update failed; the checkout may need repairing by hand (major or critical). After the third failed try of one commit, when the last try failed in the tests, the self-update files its own bug story for that commit, naming the failing tests. The monitor's finding asks you first: while it has no story, Approve in Your turn makes it |
memory-growth | fixes alone | the server's memory stayed above server.memory_limit_mb; it restarts at the next safe moment (major) |
skill-source-check | asks you first | a scheduled check of a skill source ended with PROBLEM. It is dormant until that check is switched on |
repair-failed | asks you first | an automatic repair failed twice in a row for the same thing (major) |
test-suite-slow | fixes alone | a full run of the Foundry's own tests took more than twice the median of the runs before it (major) |
load-sensitive-test | fixes alone | a test file of the Foundry failed in a full run and passed on its own (major) |
detector-failed | fixes alone | a detector crashed, so its problem is not checked (the monitor needs a fix) |
ci-main-red | asks you first | a GitHub CI workflow failed twice in a row on main of a watched repository (major) |
The automatic repairs the Foundry does today:
| Repair | Class | What it does |
|---|---|---|
retry-after-time-limit | fixes alone | a story run that ran out of time stops instead of failing, and the watcher starts it again |
bug-story | fixes alone | a problem that lasts gets one bug story on GitHub, which the watcher builds first |
lower-autonomy | fixes alone | with automatic demotion on, a new qualifying serious finding lowers the named component by one autonomy level |
start-service | fixes alone | a managed service that is not running is started again |
safe-restart | fixes alone | after a new version, a moved data folder or a changed setting, the server restarts once no run is active |
restart-wedged-server | fixes alone | when the queue or the watchers stand still while work is ready, the watchdog restarts the server, at most once an hour; a second restart within 24 hours asks you instead (see "The watchdog" under Helper processes) |
correct-labels | fixes alone | an issue's status label that does not match its newest run is corrected |
completed-dependency | fixes alone | a dependency on an issue closed as completed counts as done |
memory-restart | fixes alone | when the server's memory stays above its limit, it restarts at the next safe moment |
hotfix-merge | fixes alone | with Hotfixes on, a bug story is merged into main and then into develop. Any other merge to main asks you first |
rerun-detectors | fixes alone | when a measure stands still and no detector reports it, the monitor logs the state of every detector and runs them again |
retry-load-sensitive-test | fixes alone | in a self-update, a failed test file runs again on its own, and a load-sensitive one does not fail the update |
unread-dependency | fixes alone | a dependency on an issue of another repository that cannot be read, but is known to be closed, counts as done |
ci-bug-story | fixes alone | a GitHub CI workflow that is red twice in a row on develop or main of a watched repository gets one bug story, closed again when it is green (see GitHub CI on develop and main) |
test-values-faked | fixes alone | the push secret scan blocked a run's push, and every hit is a secret-shaped value in a test file of a commit not pushed yet: the values are replaced by fake ones and the push is tried again, once per run (see below) |
develop-kept-moving | asks you first | when develop moved three times before a gitflow run could push it, the run waits for a quiet moment and tries once more; if develop moves again, the run stops and asks you (see "develop keeps moving" under Branches: gitflow) |
Test values after a blocked push. Coding agents are told to use only https://example.invalid/...
or clearly fake placeholders in tests. When an agent still writes a secret-shaped value into a test, the
push is blocked and the run would wait for you. The Foundry then repairs it alone, only when all of these hold:
the blocked push has only hits in test files (a path under test/, tests/, __tests__/, spec/ or
specs/, or a name with .test. or .spec.); the commits that hold them are not on the remote; and it is the
first such repair of the run. It replaces each value with a fake placeholder, rewrites only those unpushed
commits (never a force push of commits already on the remote), checks the result, and pushes again. The
digest gets one line for it. The Foundry never prints the value. A hit outside a test file, or a second block
after the repair, stops the run with the sentence "The secret scan blocked the push", and a notice asks you
to remove the values or allow a false positive. This is the one exception to the rule that secrets are
ask: it is only for test files and only for commits that are not pushed.
Each automatic repair writes one line to monitor-repairs.jsonl in the data folder when it runs: what
it did, where, and the result (done or failed). The text is cleaned before it is written, so
other repositories, people, e-mail addresses, paths and keys are not kept. The daily digest lists these
lines under Automatic repairs (see Helper processes, where the digest is described).
The repairs that failed in a row are counted in monitor-repair-state.json in the data folder, not in the
log (the log rotates, and lost history must not look like a success). A repair of the same thing that
succeeds ends the count. A line that could not be counted there is counted at the next check. Repair log
lines written before this change have no subject and are not counted.
What a bug story looks like#
One GitHub issue with the labels bug and the build label of the repository's issue watcher. A
fixed template writes it, with no AI. It has nine headings: What happened; Since when and how
often; Effect on work; Evidence; What should happen instead; How to see it again; Where to look in
the code; Acceptance criteria; About this story.
- Hidden marker. A comment line
<!-- claude-factory monitor=… -->tells the monitor that the story exists, so it is made only once, also when the findings file is lost. - Cleaning. Other repositories, people, e-mail addresses, folders, links and keys are removed. Log lines are left out unless every word is on a fixed list.
- When. Critical and major problems: after 2 checks in a row. Minor: after 3 different days. A problem with a story at the second check is the goal; see the table at the end.
How bug stories go first#
A story with a bug label is built before all other work, and it does not count against
max_per_tick. Other issues say "waiting — a bug story goes first". Details:
Bug stories go first.
The hotfix path#
With Hotfixes on, the story is built on hotfix/<issue>-… from main, tested, merged into
main, then main is merged into develop. The monitor reads the fix commit from the run. Details:
Branches: gitflow.
The guard rails#
- Off by default. No
report_to, no stories. - Cleaning. Nothing private leaves in a story or a comment.
- Only once. One open story per problem; the hidden marker finds it again.
- Limits. 3 stories a day, 1 per check.
- Quiet time. No story in the first
cooldown_minutesafter a server start. - Circuit breaker. A flood of new problems, or 3 failed fixes in a row, stops all stories (the circuit breaker).
- Never a story about a story. Runs that build a bug story are never a finding.
- Two tries. After two stories that did not fix it, a person decides.
- Mutes. An admin can mute a detector or a finding (mutes).
mainonly through the built-in flow. Only the unchangedissue-gitflowmay pushmain, and only after the tests on the merge result. A feature run cannot.
Switch it on and off#
On, in five steps:
- Add the monitor watcher (source The Foundry itself) under Administration → Watchers.
- Set
monitor.report_toto the repository for the stories. - Have an
issue-gitflowwatcher for that repository, so the stories get built. - Switch on Hotfixes under Administration → Settings, in the Safety section.
- Switch on Self-update in the same section, so the running Foundry gets the fix.
What "off" stops:
- No monitor watcher (removed or disabled): no checks, no findings, no stories, no comments.
- No
report_to, orscf monitor off: findings are still recorded, but no story and no comment (the off switch). - Stories that already exist still carry the build label. The issue watcher keeps building them, so also disable that watcher or remove the label to stop the work.
- Hotfixes off: a bug story is built as a normal feature.
- Self-update off: the monitor waits for the next server start, or
fix_wait_days.
When it says "needs you"#
- Two stories did not fix it. No third is made. Read both stories, fix the cause by hand, then press Try again at the finding on the Problems page, or mute the finding.
- The breaker stopped stories. Look at what went wrong first, then switch stories on again
(Switch bug-fix changes on on the monitor's card on the Watchers page, or
scf monitor on). - The fix failed. The run of the bug story failed. Open the run, fix the cause, and resume it, or remove the label and build the story as a feature.
developis behind after a hotfix. The fix is onmain, butdevelopcould not take it. Mergemainintodevelopby hand and resolve the conflicts.developkept moving. A gitflow run's work is kept on its feature branch (feature/<issue>-…), not lost. Check thatdevelopis quiet, then resume the run: it waits for a quiet moment and tries once more. The item is marked done when the work lands.
The incidents that are replayed in tests#
tests/self-repair-incidents.test.ts replays four real cases with the real parts and a fake GitHub.
Each one makes its story at the second check at the latest, builds it first, takes it to main,
and ends with "fixed" after 24 hours of normal work.
| Incident | Detector | What the test proves |
|---|---|---|
| Runs that step aside are resumed again and again | restart-loop | Story "Runs that step aside are restarted in a loop" |
| The watchers use up GitHub's request limit | github-limit | The story is made while the limit is used up, and fixed after it resets |
| Every run fails at the tests before the change | same-step-failing | The story's hotfix brings the fix; the next story passes |
| A label says working, the run has failed | label-mismatch | A major problem: its story comes after 2 checks |
tests/self-repair-rules.test.ts proves the five rules: nothing private in any story, one open
story per problem, the circuit breaker stops a flood, a feature run cannot reach main, and with
the monitor off nothing is created.