User guide: contents

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.

The Problems page in the Admin view, with the monitor's findings and their buttons

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).

DetectorClassWhat it finds
restart-loopfixes alonethe same run is resumed again and again (critical)
watcher-errorfixes alonea watcher's checks fail one after the other (major)
github-limitfixes aloneGitHub's request limit is hit or nearly used up (critical or major)
watcher-silentfixes alonean enabled watcher finished no check (critical)
unexplained-failurefixes alonea run failed with an error no rule explains (minor)
stuck-runfixes alonea running run wrote nothing to its log for too long (major)
same-step-failingfixes alonethe same step ended runs as failed for different issues (major)
label-mismatchfixes alonean issue's status label does not match its newest run (major)
waiting-unlistedfixes alonean open issue has a waiting label, but Needs you does not list it (minor)
held-unknownfixes alonea watcher keeps a story back for no known reason (major)
long-waitfixes alonea 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-chainasks you firstopen stories wait for an issue that will never be built; the owner decides (minor)
orphan-lockfixes alonea 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-stalledfixes alonejobs 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-overduefixes alonea 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-blindfixes alonea 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-redfixes alonethe tests after merges into develop fail for several different stories in a row (critical)
slow-stepfixes alonea 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-filefixes aloneone 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-leftoversasks you firstthe 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-failurefixes alonepolicy decisions said the policy was unavailable or invalid (major)
evidence-finalizationfixes alonea run ended but its evidence has no evidence.json, or its stream stopped (major)
step-latency-p95fixes alonethe p95 of a step's durations is above the limit (minor)
repeated-tool-denialasks you firstthe same tool was refused again and again; the fix is a change to allowed_tools (minor)
abnormal-outputfixes alonea step wrote far more output than is usual for that step (minor)
self-updateasks you firstan 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-growthfixes alonethe server's memory stayed above server.memory_limit_mb; it restarts at the next safe moment (major)
skill-source-checkasks you firsta scheduled check of a skill source ended with PROBLEM. It is dormant until that check is switched on
repair-failedasks you firstan automatic repair failed twice in a row for the same thing (major)
test-suite-slowfixes alonea full run of the Foundry's own tests took more than twice the median of the runs before it (major)
load-sensitive-testfixes alonea test file of the Foundry failed in a full run and passed on its own (major)
detector-failedfixes alonea detector crashed, so its problem is not checked (the monitor needs a fix)
ci-main-redasks you firsta GitHub CI workflow failed twice in a row on main of a watched repository (major)

The automatic repairs the Foundry does today:

RepairClassWhat it does
retry-after-time-limitfixes alonea story run that ran out of time stops instead of failing, and the watcher starts it again
bug-storyfixes alonea problem that lasts gets one bug story on GitHub, which the watcher builds first
lower-autonomyfixes alonewith automatic demotion on, a new qualifying serious finding lowers the named component by one autonomy level
start-servicefixes alonea managed service that is not running is started again
safe-restartfixes aloneafter a new version, a moved data folder or a changed setting, the server restarts once no run is active
restart-wedged-serverfixes alonewhen 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-labelsfixes alonean issue's status label that does not match its newest run is corrected
completed-dependencyfixes alonea dependency on an issue closed as completed counts as done
memory-restartfixes alonewhen the server's memory stays above its limit, it restarts at the next safe moment
hotfix-mergefixes alonewith Hotfixes on, a bug story is merged into main and then into develop. Any other merge to main asks you first
rerun-detectorsfixes alonewhen a measure stands still and no detector reports it, the monitor logs the state of every detector and runs them again
retry-load-sensitive-testfixes alonein a self-update, a failed test file runs again on its own, and a load-sensitive one does not fail the update
unread-dependencyfixes alonea dependency on an issue of another repository that cannot be read, but is known to be closed, counts as done
ci-bug-storyfixes alonea 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-fakedfixes alonethe 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-movingasks you firstwhen 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_minutes after 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).
  • main only through the built-in flow. Only the unchanged issue-gitflow may push main, and only after the tests on the merge result. A feature run cannot.

Switch it on and off#

On, in five steps:

  1. Add the monitor watcher (source The Foundry itself) under Administration → Watchers.
  2. Set monitor.report_to to the repository for the stories.
  3. Have an issue-gitflow watcher for that repository, so the stories get built.
  4. Switch on Hotfixes under Administration → Settings, in the Safety section.
  5. 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, or scf 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.
  • develop is behind after a hotfix. The fix is on main, but develop could not take it. Merge main into develop by hand and resolve the conflicts.
  • develop kept moving. A gitflow run's work is kept on its feature branch (feature/<issue>-…), not lost. Check that develop is 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.

IncidentDetectorWhat the test proves
Runs that step aside are resumed again and againrestart-loopStory "Runs that step aside are restarted in a loop"
The watchers use up GitHub's request limitgithub-limitThe story is made while the limit is used up, and fixed after it resets
Every run fails at the tests before the changesame-step-failingThe story's hotfix brings the fix; the next story passes
A label says working, the run has failedlabel-mismatchA 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.


Improve this page on GitHub