User guide: contents

Keep it running

Watchers only run while scf ui (or scf serve) runs. When a new version of Spaghetti Code Foundry is built (npm run build), the running server restarts itself as soon as no run is active — no need to stop and start it. To keep the Foundry running in the background on macOS, also after a restart of your Mac:

scf service install     # uninstall | status

If you installed the service before, run scf service install once. It replaces the old com.claude-factory.server agent with com.spaghetti-code-foundry.server, and puts the old one back if the new one can't start.

The model analyst#

A separate process that reads your own runs every 6 hours and says, per step, how the model does and whether another level fits the work. It reads run files and writes a report, and it does not need the server. By default it only advises; with self-tuning on it changes the model or effort of a step by itself (see below).

scf analyst install     # run every 6 hours as its own macOS login agent; the first time now
scf analyst run         # write a report now (--no-web: do not look up published figures)
scf analyst report      # print the last report
scf analyst status      # uninstall removes the agent
scf analyst auto on     # let it change models and efforts by itself; auto off: only advise
scf analyst reset       # put back everything it changed

The report is analyst/report.md in the data folder; the same advice as data is in analyst/latest.json. It looks at the last 14 days and needs 20 visits of a step before it says anything; visits stopped by a usage limit do not count towards the 20. Per step and model it shows how often the step worked, ran into its time limit, was repaired by a fix_* step, or was sent back by a review, and its share of all tokens. From that:

  • Try a lower level. The step works nearly always and its work is rarely repaired. The advice is one effort level down when the step runs on high or above, otherwise the next smaller model. For a review: almost none of the reviews led to a change, and the review step itself works at least 97% of the time.
  • Try a higher level. The step fails or its work is repaired often. A review step that fails 15% of the time or more is treated the same way: it is never advised to go lower.
  • Time limit, not model. 5% or more of the visits ran into the time limit. A stronger model is usually slower, so look at the limit and the size of the work first.
  • Look at this. The step got clearly worse in the last two days.

Visits stopped by a usage limit are not counted against a model. The advice rests on what happened, not on a trial of the other model. Self-tuning does that trial.

Self-tuning (scf analyst auto on; off by default). At every check the analyst may start a trial: it takes the advice with the largest token share that says "effort …" or names a Claude model, and sets it for that step. There is one trial per flow at a time, so the effect of a change can be told apart. The change is written to analyst/overrides.json; the engine reads that file at the start of every agent step, so it takes effect at the next step, also in a run that is under way. No flow file is changed.

Some advice stays advice, and the report says why under "Advice not tried by itself":

  • Another model is only tried when the published figures (see below) hold at least one figure for that model. The analyst makes the name of the next level from the name of the current one, and this is its check that such a model exists. With --no-web, or before the first lookup worked, no model is tried. Effort changes need no figure.
  • A review none of whose reviews led to a change. A trial of it could not be judged.
  • A step inside a sub-flow.
  • A change back to what the flow itself says. scf analyst reset does that.

What the analyst set never wins over you:

  • A router rule of yours for the step wins, for the model and for the effort.
  • The override follows the flow. It stores what the flow said for the step (model and effort) when the analyst set it, and applies only while the flow still says that. When you edit the step's model or effort, your edit counts from the next step on.
  • Only the model is replaced. The step keeps its agent and its provider, so a step on a local model or on a proxy stays there. The model of a step that does not run on Claude Code is never changed.

A trial is judged on the visits since it started, against the numbers of the step before it:

  • After 20 visits a lower level is kept unless the step does worse: it works more than 5 points less often, its work is repaired more than 10 points more often, it times out more than 5 points more often, or reviews send its work back more than 15 points more often. For a review step: unless it leads to a change less than half as often as before.
  • A higher level is kept only when the step works at least 5 points more often or is repaired at least 10 points less often. Otherwise it is not worth its tokens and is put back.
  • After 8 visits a trial that works 25 points less often is stopped at once.
  • A trial with fewer than 20 visits in 7 days is put back.

A change that was put back is not tried again for 30 days, and a step is left alone for 3 days after any trial. The run log of a step says "set by the analyst" when an override applied. The report lists what is set now, what happened at this check, and the last ten trials; analyst/tuning.json holds the full record, and it owns the overrides: an entry in overrides.json that no running or kept trial stands for is removed at the next check, so do not add entries by hand. scf analyst auto off stops new trials and keeps what is set. scf analyst reset removes it all and ends the running and the kept trials as "put back", so the same changes are not tried again for 30 days.

Published figures. Once a week the analyst asks Claude Code (with the Claude sign-in of this machine) for published scores, prices and speeds of the models you use and the levels next to them, and keeps them in analyst/reference.json with the source of each figure. Figures a third party measured itself are used as they are. Figures from the makers, and figures whose origin is not given, are lowered by a tenth. They are only used to hold back advice for a smaller model that scores far lower, and to know that a model exists before it is tried; your own runs always decide. Coding scores are only compared when both name the same test. That session has the two web tools (search and fetch) and no others, no MCP servers, none of your personal or project settings, and runs in an empty temporary folder. When the search fails or finds nothing, the earlier figures are kept and it is tried again a day later. On Linux, run scf analyst run from cron.

The command line for a running Foundry#

Everything the web interface does goes through the server's API, and every call of that API is also a command. These commands talk to the running Foundry, with your account and its rights. (The older commands such as scf run, scf resume and scf user work on the files of the data folder and need no server; they are unchanged.)

scf login                 # asks for your e-mail address and password; --server names another Foundry
scf whoami                # who is signed in, and where
scf runs list --status failed
scf turn list             # what waits for you
scf repos                 # an area without an action lists its commands
scf flows --help          # flows, blocks and monitor: without an action they are the older file commands
scf runs list --help      # the options of one command
scf logout

Signing in. scf login uses the same accounts as the web interface. The password is typed without echo, sent to the server and not kept. What is kept is the session, in cli-session.json in the data folder, readable by your user only. It ends after 7 days, at scf logout, or when the account's password changes. A script can pipe the password in as one line; without --email it pipes two lines, the e-mail address and then the password. Only a Foundry on this machine (localhost, 127.0.0.1, [::1]) is reached over plain http. Any other address is reached over HTTPS: --server foundry.example.com means https://, and an http:// address of another machine is refused, so the password never travels in clear text. A redirect is not followed; the command says where the server points to and stops.

The areas.

AreaWhat it covers
runsList, show, start, answer, approve, reject, resume, cancel and archive runs; a step's log and the diff
turnWhat waits for you, and answering it: answers, defaults, approve, reject, retry
board, findThe board, the next steps, what changed since a time; search
reposYour repositories: add, sign-in method, test the connection, remove
refineRefinement sessions: story drafts, suggestions, reviews, the publish plan, publishing
askAsk Foundry: ask a question, try again, stop; rate an answer (feedback); your conversations (list, show, complete with --resolved, archive, restore, delete); what a page context is worth (context); the usage and quality numbers (admin)
flows, blocksList, show, check, save and remove flows and blocks
settings, providersThe settings file; the AI tools and model providers
monitorThe self-monitor: findings, mutes, bug stories
users, admin, auditAccounts and their limits, all repositories and their watchers, the audit log (admin)
account, secretsYour own password; your stored secrets
watchers, serverWatchers; server information, queue, statistics, clean-up

What every command has.

  • --json prints the server's answer as it is, for scripts. Without it you get a table or a few lines.
  • --data '{…}' or --data @file.json adds fields to the call that have no option of their own. It only adds: a field that an option, an argument or the command itself sets is refused, and so is a field that another command asks about first (the role in scf users set, the sign-in method in scf repos add). A command that only reads takes no --data.
  • Text that starts with - goes after --: scf flows save my-flow --scope repo -- "$(cat my.yaml)".
  • --server <address> talks to another Foundry (sign in there first).
  • --as <account id> reads as that user would, for an admin who started scf admin view-as.
  • Exit code 0 means done; 4 means not signed in or not allowed (also for scf whoami); 1 is any other refusal by the server. Errors are printed on standard error; with --json the server's whole refusal is printed there as JSON.
  • A call may take two minutes (a sign-in half a minute); then the command gives up. An answer that is not from a Foundry counts as an error, whatever its status.

Safety.

  • A command that deletes or replaces something asks you to type yes. --yes answers for you; without a terminal and without --yes it stops. scf flows save and scf blocks save ask only when a file with that name is there already; scf users add asks only for --role admin.
  • A password, token or other secret is never an option or an argument: the command asks for it without echo (or reads one line of standard input each, in the order it would ask), so it is not in your shell history. Given inline in --data it is refused, for every command (the fields token, password, secret, current, key, privateKey); in a file (--data @file) it is accepted, unless the field is one the command does not let --data set.
  • An argument that becomes part of the address (an id, a name) cannot be . or .. and cannot contain / or \.
  • scf settings set sets all settings: a setting you leave out goes back to its default, so it insists on --data. The Slack webhook is the exception: it stays unless you give notify.slack_webhook: null, which removes it. Start from scf settings show --json; it does not show the webhook, only notify.slack_webhook_set.

Any call directly. scf api routes [word] lists every call the server knows and who may make it; scf api GET runs (or POST, PUT, PATCH, DELETE) makes one. A body is sent only with --data: without it nothing is sent, so add --data '{}' for a call that wants an empty one. DELETE, PUT and PATCH ask you to type yes first (--yes answers; without a terminal and without --yes they stop). One call has no command: the live event stream of a run, which never ends; scf api refuses it too.

Helper processes#

Six small processes that run beside the Foundry, each started by macOS by itself once installed. They read the data folder and write their results in their own folder there. Two of them also set something outside it: the governor and the limits helper each keep their cap on the runs at once in a file of their own in governor/caps/, and the governor writes test-slots/cap. None needs the server, and the server does not need them. Every one has the same commands:

scf governor install    # also: flaky, limits, blockage, digest, housekeeping, watchdog
scf governor run        # one check now
scf governor report     # the last result
scf governor status     # uninstall removes it and what it set

status says "installed" only when macOS really runs the helper. "Installed but not loaded" means the file is there and nothing runs: run install again.

HelperRunsWhat it does
governorevery minuteLowers the number of runs at once while the machine is overloaded, and raises it again when it is calm.
flakyevery 6 hoursFinds tests that fail in unrelated stories or pass only on a retry.
limitsevery hourSays when the weekly Claude and Codex limits are reached at the current pace.
blockageevery hourFinds the stories that hold up the most others, and says when run slots are empty.
digestdaily at 07:30One short report: what was done, what failed, what waits for you.
housekeepingevery 3 hoursRecords the memory of the system's file-change tracker and of the Foundry server, and once a night removes the workspaces of old runs.
watchdogevery 5 minutesRestarts the server when its queue or its watchers stand still while work is ready (see "The watchdog" below).

The watchdog (#961). The server writes heartbeat.json in the data folder every 30 seconds: when the queue last moved, when a watcher last finished a check, when the log was last written, and whether work is ready. The watchdog reads that file from outside the server. It acts only when work is ready and one of these has stood still longer than its limit:

  • the queue has not moved (watchdog.pump_minutes, default 30 minutes);
  • no watcher has finished a check (watchdog.watcher_minutes, default 30 minutes, and never less than three times the shortest watcher interval);
  • the server has written no heartbeat for that long (also watchdog.pump_minutes).

Then it restarts the server's login agent (com.spaghetti-code-foundry.server) with launchctl kickstart -k, as an automatic repair. It restarts at most once an hour. A second restart within 24 hours does not happen: the watchdog asks you instead, with a desktop notice that says to look at the server. The watchdog does not restart while a push, merge or release step runs (the same steps as a restart at a safe moment, see Your turn), or while the self-update installs a new version (building and testing do not hold it back). Then it asks you once, and the notice names the run and the step. The server and the watchdog hand over through two small files in the data folder, restart-guard.json and restart-intent.json. A process that is not the server's login agent is never restarted. The watchdog writes its last result to watchdog/report.md, and its events to watchdog/events.log. scf watchdog report shows the last result. The limits are in System → Settings, in the Watchdog card.

Caps on the runs at once. The governor and the limits helper can each lower the number of runsThe governor and the limits helper can each lower the number of runs at once for a while. The lowest cap that still holds counts, never above the configured number. A cap of 0 lets no new run start, not even an architect run or a schedule chore; it is set only by the governor, when governor.floor is 0. A cap holds back new runs only: work that runs is never stopped, and a run that already started and is resumed (after a restart, an answer or a pause) is not held back, because it may hold the turn to merge that others wait for. A new run that waits only for a cap is marked so in the queue (capped, and the queue names the cap), and the monitor does not report it as a queue that stands still. While a cap holds jobs back, the queue looks again every 30 seconds, so a cap that ends starts the waiting runs even when no run ends.

The load governor. Every minute it reads the load average per core, the CPU in use, the memory pressure, the heat and the swap, and, when it can, the CPU of your other programs (see "Who uses the CPU" below). When it has that measurement, it works out how many runs fit next to your other programs and moves the cap one step per check towards that number:

  • Runs that fit = (cores − cores used by other programs − governor.reserve_cores) ÷ cores one run uses, rounded down, and never below 0. governor.reserve_cores is 2 by default. One run uses the mean of the learned figures of the repositories of the active and queued runs; a repository with no learned figure counts as the mean of the others, and a run is taken to use at least 0.25 cores.
  • Down: one run fewer when the cap is above the runs that fit, and its runs use more than the free cores plus 0.5 cores, for three checks in a row. The load alone does not lower the cap.
  • Up: one run more after five calm checks (see below), and only when the runs that fit are more than the cap.

The cap never goes below governor.floor (by default half the configured number, at least 2; 0 means no run may start).

Without the measurement (the first check, a failed ps, no learned figure yet) the cap follows the load instead, and the rules are the same as before: it allows one run fewer per check, down to governor.floor, only on sustained load: the 5-minute load is above 2.5 per core, or the 1-minute load has been above 2.5 for three checks in a row. A spike of a minute or two (a test suite, a build) does not lower the cap. Memory pressure "warning" alone does not lower it either: macOS reports it for hours on a full but idle machine. It counts only with a load above 2.5 per core.

CPU, heat and swap. The load average also counts threads that only wait (on macOS), so the governor reads three more signals. The busy share is the part of the CPU time, over all cores, that was not idle since the last check (from the idle time per core; the first check has none). Its rules:

  • From the second check on, a load above 2.5 per core counts only when at least 80% of the CPU is busy. A high load on an idle CPU alone lowers nothing, with or without the measurement, and it does not start the sustained-load count. The first check has no busy share, so the load rules alone apply then.
  • From the second check on, a load above 4 per core, which allows only one test run at a time, also needs the busy CPU.
  • A load in the band (above 1.2 and up to 2.5 per core) is calm when at most 50% of the CPU is busy. A busy CPU (80% or more) stops the calm count, even with a low load.
  • A throttled machine counts as loaded: pmset -g therm shows a CPU speed limit below 100%, or a thermal warning level. A machine that is swapping counts as loaded: the swap in use (sysctl -n vm.swapusage) grew by more than 64 MB since the last check. Swap in use that does not grow does not count, because macOS keeps swap on an idle machine. Throttling or swapping stops the calm count.
  • Throttling or swap growth in three checks in a row lowers the cap by one run, after the usual pause. The change line in governor/changes.log names the reason, for example "throttled: CPU speed limit 80%" or "swapping: swap grew by 120 MB".

A signal that cannot be read (not macOS, pmset or sysctl missing or failing, too slow) is left out, and the rules above apply as they did before. These thresholds are built in; they are not set in the configuration.

Two cases act at once, even during a pause: memory pressure critical, and a 1-minute load above 4 per core while the CPU is at least 80% busy. Above 4 per core, or under critical memory pressure, only one test run works at a time. These apply with and without the measurement.

Workers per test run. While the machine is loaded (the 1-minute or the 5-minute load above 2.5 per core, or one of the emergencies above), the governor also limits the workers of each test run. A test run gets a quarter of the cores, at least 2: on a 16-core machine, 4 workers. The command gets SCF_TEST_WORKERS (vitest) and -Dorg.gradle.workers.max (Gradle, added to GRADLE_OPTS and JDK_JAVA_OPTIONS; the command line is not changed). The number stays while the load is between 1.2 and 2.5 per core, and it goes when the 1-minute and the 5-minute load are both 1.2 per core or less. A limit you set yourself is never raised: SCF_TEST_WORKERS from 1 up to the number stays, and the Gradle setting is left out when your own one (command line, GRADLE_OPTS, JAVA_OPTS, gradle.properties) is that number or lower. The governor's worker file counts for 4 minutes after its last check, like the cap on test runs; with no file nothing changes. scf governor report and the "limits now" line show it.

After the cap moved, the governor pauses: no further step down for 3 minutes, and no step up for 10 minutes. Only an emergency breaks the pause. It still moves one step at a time. Each step down in the last hour makes that wait 10 minutes longer: after two step downs, 30 minutes. Once the step downs are more than an hour old, the wait is 10 minutes again.

After five calm checks in a row (1.2 per core or less, on the 1-minute and the 5-minute load) it allows one more run, until the configured number is back. A load in between (above 1.2 and up to 2.5 per core) is not calm: it never allows a run more, so a machine that stays busy keeps its cap. The last step back to the configured number also needs the 15-minute load below 1.2 per core, so the cap stays below the configured number until the machine has been quieter for a quarter of an hour. The wait above applies to every step up. These values are built into the governor; they are not set in the configuration.

Every change is a line in governor/changes.log. scf governor status says how many times the governor changed the limits today, and the health line shows the same count when it is above 0. The daily digest mentions the changes only when there were more than 20 in the last 24 hours. Its "Machine load" part also says how long the runs at once were below concurrency in the last 24 hours, with the lowest value and the two main reasons, for example "the runs at once were below 4 for 2 h 10 min in the last day (lowest 2): memory pressure 1 h 5 min, high load 50 min". A day without a cap has no such line. The governor's limits end by themselves four minutes after the last check — the cap on runs, the cap on test runs, the workers per test run, and what the governor remembers — so a governor that stops can never hold the Foundry down, and the first check after the machine slept starts fresh. The step downs of the last hour are part of what it remembers, so after a pause of more than four minutes they are forgotten and the wait before a step up is 10 minutes again. scf governor reset takes them away at once. The daily release check asks for a test slot like every test run, and never runs without one: it waits up to 90 minutes (FACTORY_TEST_SLOT_WAIT_SEC, default 5400). If no slot comes free, the check is postponed to the next daily run: nothing is changed and the log says POSTPONED: with the reason.

The Load governor card (admins). The Overview page (Administration, then Overview under Operations) shows the governor's last result on one card. It has the runs at once now, out of concurrency, and each cap that holds with its reason. Below that are the free cores, with the runs that fit next to your other programs once a run's use is learned; the load of other programs, with the top five programs by name; the Foundry's own load (runs, test runs and the server with its helpers); and a step chart of the runs at once over the last 24 hours. "Show as list" gives the same steps as a table with the reason of each. The time below concurrency and its reasons are shown above the chart. A result older than four minutes shows the caps that still hold, but no measurements. With no result the card says so and names scf governor install. The card reads files only: the last result (governor/latest.json), the caps that have not ended, and the change log.

Paused test runs. Under sustained overload the governor pauses test runs beyond the first. It does so at once when memory pressure is critical, and when the 1-minute load is above testsHigh (4 per core) for three checks in a row. Then all test runs but one stop, and the run that holds the first test slot goes on. A paused run shows "paused: machine overloaded since HH:MM" on its page, and its log says it was paused. The pause ends when the memory pressure is no longer critical and the load is at or below high (2.5 per core); the paused runs then go on by themselves. Paused time does not count against a test run's time limit. Agent steps are never paused in the middle of a model call, and the monitor does not report a paused run as stuck. Cancelling a paused run, or reaching its time limit, stops it at once. The pause is also taken away by itself four minutes after the governor last wrote it, so a governor that stops cannot leave a test run frozen. One exception: an agent's own test command has its own time-out, which a very long pause can still reach; the test is then stopped and the agent can run it again.

Who uses the CPU. Each check also measures how much CPU the Foundry uses and how much other programs use. The Foundry's share is the step processes of the active runs (including the processes that a step started and left its process group), the test slots, and the server with its helpers. Everything else is other programs. The governor learns how much CPU one run uses, separately for each repository, from these measurements, and keeps that figure across checks. The learned figure is kept by a reset too. The measurement sets the target the cap moves towards (see "The load governor" above). The cause is written after the change in governor/changes.log, for example … — the Foundry uses 3.2 cores, other programs use 6.1 cores (top: Xcode 3.1, node 1.4); 4 runs fit. Only the base name of a program is kept, in the data folder; program names never go to GitHub. scf governor report shows the same figures as "now" and "a run uses about", with the runs that fit after "now", when the last check is under 4 minutes old. The last check is in governor/latest.json. A check gives no figures on its first run, after a long gap, or when ps fails or takes too long; the limits then follow the load, as described above.

Unreliable tests. A test is listed when it failed, or passed only on a retry, in at least three different stories of one repository in the last 7 days: one story can break its own test, several cannot. A run without an issue is not a story. Where it can see them:

  • A test that failed in a test log (Vitest and Gradle output).
  • A test that failed and passed when the flow ran the tests once more: the flows keep the first log as tests.first.log for that.
  • A test that Vitest retried by itself — only when the test command uses --reporter=verbose. Vitest's default reporter prints nothing for a test that passed on a retry.

The report names a likely cause when the error of that test shows one (a port in use, a time limit, a full disk), and says whether the test was also seen to pass. With scf flaky auto on it makes one bug story per test file and repository through the GitHub sign-in of this machine, at most 2 per check and never twice for the same file. A story is made only when at least one listed test of the file was also seen to pass in those 7 days (on a retry, on the second run, or named as passed in a verbose log); a test that never passes is broken, not unreliable, and stays in the report only. Off by default. The report also ends with a list of the load-sensitive test files of the Foundry's own suite (see Self-update), with how often each was seen; scf flaky report shows that list as it is now.

Usage limits. The weekly limits are not published, so the forecast needs one reading from you:

scf limits set claude 34 2026-10-19T23:00     # 34% used now; the week resets then (local time)

A reset without a time zone is local time, also a date alone (midnight). A reset more than 7 days ahead is refused. From the tokens used since the reset and that share it works out the size of the week, and from the pace of the last 24 hours when the limit is reached. It is an estimate: it holds while the mix of work stays about the same, and a reading below 5% is too coarse. With scf limits auto on it lowers the runs at once so that the limit lasts until the reset — down to 1 if needed, lower than the governor goes. It works from the number of runs that are allowed at that moment, lowers its cap as far as needed in one check, and raises it by one per check at most. The cap ends by itself two hours after the last check. Off by default.

With governor.usage_percent: 80, scf limits auto on and a reading, the threshold works on its own: once about 80% of a week is used, runs at once go down to 1 (or to governor.floor when that is set and higher) until the reset, and the report says that this is the reason. Not set, only the forecast slows down; a threshold that is set but not yet reached changes nothing.

What holds work up. It follows two kinds of waiting: a story that stepped aside for files another run holds, and a story that waits for one it depends on (from the service log of the last 6 hours, until the log shows that the story started or ended). The report lists the stories at the root, the number they hold up through the chain, and their state; stories are named with their repository. Stories that wait for each other in a circle are listed first, as one entry: that never ends by itself. A run that says "running" while its process is gone is shown as interrupted. The report says so when run slots are empty while stories wait.

Housekeeping. Every run installs and deletes very many small files, and macOS keeps track of every change. On a machine that runs for days, the system's file-change tracker (fseventsd) once grew to tens of gigabytes this way and left too little memory for the work. So every 3 hours this helper writes one line to housekeeping/memory.log with the memory of fseventsd and of the Foundry server. Above 8 GB for the tracker or 6 GB for the server it sends one notification that day, and the digest names it. The tracker only shrinks with a restart of the machine. Once a night, at the first check after 03:00, it removes the workspaces of runs that ended more than 2 days ago, as scf clean --older-than 2 does: run records, logs and branches stay, and active or paused runs are not touched.

Old runs move to runs-archive/. Right after the clean-up, once a night, housekeeping moves old runs out of runs/ into runs-archive/ in the data folder, one folder per run (runs-archive/<run id>/, the same layout). Nothing is deleted. A succeeded or cancelled run moves when it ended more than runs_archive_days days ago (default 30). A failed or stopped run moves only when it is more than 90 days old. Waiting, running, queued and other unfinished runs never move, and neither does the newest run of each issue, pull request or chore, so the watchers still see it. A moved run still opens by its id (the run page at #/runs/<run id>, GET /api/runs/:id). It is in no list, not in the Archived view and not in the run index. It is read only: resume, answer, cancel, archive, approve, reject and the check calls answer 409 (RUN_IN_ARCHIVE). Runs that were moved to runs-archive/ by hand, with the same layout, open the same way. The digest and housekeeping/memory.log name the number of runs moved.

The digest. For the last 24 hours, from the newest run of each story: done, split into smaller stories, failed (with the reason) and in progress; what waits for you is listed however old it is, and so are runs that were interrupted (they say "running", but their process is gone). Runs the server archived by itself because a later release of the same repository succeeded are listed under Archived by itself, newest first, with no limit; that section covers the last 24 hours and reads every runs folder. Below that come a few lines from the other helpers and the analyst; a result of a helper that is older than 26 hours is left out. When a story had automatic retries after a time limit, the digest adds a section Automatic retries after a time limit: how many stories, how many retries started, and how many of those finished, were split, failed or are still open. A retry that was cancelled while it waited is not counted, and a retry that ends in a later digest counts in the digest of the day it ended. Without retries there is no such section. The digest also has an Automatic repairs section: one line for each automatic repair of the last 24 hours, newest first, with what it did, where, and whether it was done or failed. These repairs need no answer from you, so they add nothing to Waits for you. The lines come from monitor-repairs.jsonl in the data folder (at most 256 KB, then the older half is kept as monitor-repairs.1.jsonl); a damaged or missing file gives an empty section. It is digest/report.md, and one file per day, named by the local date; a desktop notification gives the counts.

Self-update#

Off by default, because it lets merged code run on this machine without a person looking. For a Foundry that runs from a git checkout of its own repository. Switch it on in Settings (Admin view: Administration, then Settings under System), section Safety, with the checkbox Self-update, and name the repository in Repository the Foundry may update from (self_update: { enabled: true, repo: owner/name } in config.yaml). After upgrading, stop and start the Foundry once, so that it can go back after a bad update.

Update channels. The setting Update channel (self_update.channel) picks which commits this Foundry takes:

  • early follows the newest commit of main, as before. After each commit has run for 24 hours of running time without a rollback and without a finding from the monitor about the Foundry itself (policy service failure, evidence not finalized, or a slow step), it publishes a signed "good" note for that commit. A rollback or such a finding publishes a "bad" note. Running time counts only while the monitor is up and its last good check is recent; a gap longer than 2 minutes does not count.
  • stable takes only the newest commit of main that has a good note and no bad note. A commit marked bad is skipped, and the Foundry waits for the next commit with a good note. The health line says "this Foundry takes the stable channel" while it waits.
  • automatic (the default when the setting is not set) is early when the GitHub login of the Foundry can push to self_update.repo, and stable otherwise. A login that can push is the one that can start the workflow that publishes the notes.

The notes are signed with GitHub build attestation by the workflow .github/workflows/release-note.yml of the repository, and kept as assets of the prerelease update-notes. The workflow must be on main before any note can be published. A stable install checks the note again right before an install. An install whose login cannot push now takes only commits with a good note: set self_update.channel: early in config.yaml to keep the old behaviour.

To mark a commit bad by hand, for example after a release that broke in a way no check catches, run scf update mark-bad <commit> (7 to 40 hex characters). It asks the workflow for a bad note; the note appears on update-notes within a few minutes. A bad note always wins over a good note for the same commit.

Every 5 minutes it checks, in this order, and stops at the first reason that applies (the health line shows it):

  1. The record self-update.json can be read, and no earlier go-back failed.
  2. The Foundry runs from a git checkout, under the supervisor (scf ui / scf serve, or the service).
  3. The origin of the checkout is the repository in the setting.
  4. main can be read from GitHub. Nothing new: nothing to do.
  5. The checkout is on main and has no local changes (untracked files count). Only then does it fetch.
  6. The same commit did not fail after its last try. It waits for a newer commit. (A failed try is tried again 20 minutes later, up to 3 tries in all; the wait is shown in the health line. A commit whose start failed once is tried again when the machine is calm, see below; after a second failed start it waits for a newer commit.)
  7. The checkout can fast-forward to main.

Then it builds and tests the new commit in a separate folder (npm ci, npm run build, npm test). The tests take a test slot like the tests of stories: the number of test slots is the test_slots of the enabled watchers (2 when none is set). They never run without a slot: they wait up to 90 minutes for a free one. If none comes free, the tests are postponed: the health line says the update is waiting because its tests did not start, the log says how long they waited, and it is not a failed try. The next try comes at a later check. Their own 2-hour limit starts when they start, and a run that hits it counts as a failed try (the log says the tests ran out of time). If the tests fail, they run again after 20 minutes, up to 3 tries in all, and the health line says which try it is. A failed set-up of the build folder, a failed install (npm ci) or a failed build is tried again the same way: the 3 tries are shared by all stages of one commit, and each try first removes a leftover build folder (even one left locked) so that it starts clean. The log and the health line name the stage and the try, for example "failed at install (try 2 of 3)". The log and the health line after a third failure in the tests name the failing tests (at most 20 are kept). When the third try of one commit fails in the tests, it also files one bug story for that commit, titled as the monitor's self-update story, with the failing tests. A failure in set-up, install or build at the third try gets the finding only. You do not need a monitor watcher for the story. It goes to monitor.report_to if that is set, else to the repository the self-update names. A try that ran out of time counts the same. If the story cannot be filed (for example GitHub does not answer), it is tried again after 5 minutes, then after 10, 20 and so on, up to 6 hours apart; the wait survives a restart. If bug stories are switched off, the finding is muted, or the state file monitor-guard.json cannot be read, the story waits and is checked every 5 minutes. The service log says when a story is filed or waits. A commit gets one story, and a later failed commit does not replace it. Until the last try ends, the old version keeps running; a failure after the last try gets a monitor finding. The monitor shows the same failure as a finding that asks you first (see "The monitor: the Foundry checks itself"): its own check files no story. It takes up the story above when that is in monitor.report_to; while the finding has none there, Approve in Your turn makes or takes up the story. The story names the failing tests (at most 20), with private data removed; a name that cannot be cleaned with certainty is left out, and the story says so. A further failure of the same commit files no second story; a new commit given up in the tests files a new one. A commit whose tests fail once or twice files no story. When all pass, no new runs start (queued runs wait and start after the restart), the watchers keep checking and queue their work, and the server restarts when the active runs are done. If the runs take longer than restarts.drain_limit_minutes (default 60), the restart switches to a restart at a safe moment (see Longest wait for a restart in section 7): the other runs stop and resume after the update's restart, and if the update has not restarted the server about 5 minutes later (not counting the build and the install), the safe-moment restart does it.

The tests run under the silence watchdog: a run with no output for test_silence_minutes is stopped and run once more, and a second silence is a failed try. Waiting for a test slot is not silence. The Foundry keeps the working time of every attempt that ends by itself (test-runs/ in the data folder, the newest 300 runs). When a run takes more than twice the median of the runs before it, the monitor reports test-suite-slow with the slowest files.

Before a failed try counts, the failing test files of that run (at most 5, and only when the log says for certain that these are all) are run on their own, one at a time, within 10 minutes each. A file that passes alone twice is marked load-sensitive: it fails when the machine is busy. Once marked, one pass alone is enough while the mark is up to 7 days old. When every failing file passes alone, the tests count as passed and the update goes on. A file that still fails alone, a hung run, or a log that does not say which files failed is a failed try as before. A load-sensitive file does not fail an update by itself; the monitor files a load-sensitive-test finding for it.

Main moves on. When main gets a newer commit while a tested update waits for the runs, the tested commit is not thrown away. If the new main still contains it, the tested commit is installed first (the log says so once), and the newer commit is built and tested after the restart. If main no longer contains it (for example after a force-push), the Foundry waits for the runs to finish, restarts without that update, and builds the new commit after the restart. Nothing new is built or tested while the runs are paused. A commit whose start failed is not installed first: the newer commit is built and tested instead.

While it builds and tests, the watchdog and the other restarts run as usual, and the install in place makes them wait. A health or memory restart at a safe moment waits for the build and the tests too, for up to 45 minutes, and then installs the tested update in the same restart: the log says "this is also the restart for health". If a tested update is saved and not yet installed, that restart takes one new look at it first (waiting at most 5 minutes). Once a health restart is asked for, no new build starts; the update is built and tested after that restart. If the 45 minutes run out, the restart goes ahead without the update. A restart that comes during the build or the tests (other than these) stops that try: the try is not counted as failed, and the same commit is tested again after the restart.

Stuck runs. While the update waits, the health line and Today name the runs that look stuck, and the server log lists them once per change. A run is stuck when it waits for a code area (a lock another run holds), or when nothing in its run folder or logs/ has changed for 30 minutes and no step has started or resumed in that time. A test run that writes its tests.log is not stuck. When every active run is stuck, the update does not wait for them: it interrupts them, waits up to 60 seconds for them to end, and then installs. A run that the update interrupts is shown as stopped for an update or a restart, with the note that it goes on after the restart (not as a failure), and its watcher resumes it after the restart. If they have not ended after 60 seconds, nothing is installed and the update waits again. Right before the install it checks everything again, including the tip of main. It never updates from a branch other than main or from another repository.

Skipped tests. When the daily release check (release-daily) already passed the same tests on the same code, self-update does not run them again. The log then says self-update: <sha> is not tested again: the release check passed these tests on this code (run <id>, <time>); install and build still run. It skips only when all of these hold: the release check recorded a green run on the same tree in the data folder (tested-v2/), the record has exactly the form the check writes, and the record's test command is accepted. A command is accepted when it is the updater's own test step (npm test, or npm ci && npm test when node_modules was missing), or the project's configured test command (the watcher's test_cmd, or test_cmd in .claude-factory/config.yaml of the code) as long as it runs the updater's step exactly once and joins it only with an install or a build (npm ci, npm install, npm run build, at most 4 parts). A trivial command (true, exit 0, an empty command) is refused, and so is a command that runs only part of the suite. Records in the older tested/ folder are not read, so those tests run again once. Every other case runs the tests as usual: a story's older record, another tree, no detected command, an unreadable record, or a record made with another command. The log says which reason applies ("no record for this tree", "record made with another command: …"). Only the release check's record counts. The release check and self-update use the same folder: the server gives every step FACTORY_TESTED_DIR, so a run in another workspace or with --runs-dir writes where self-update reads. Anything that can write tested/ in the data folder can make self-update skip its tests, so keep that folder as private as the rest of the Foundry.

A new server that reports its start-up progress is not judged by a fixed time. It reports each start-up stage and a heartbeat every 5 seconds until the start is over, so a slow but healthy start is not rolled back: the supervisor waits while the progress keeps coming. It stops the new version when no progress has come for 90 seconds (the log names the stage it reached, for example "stopped making progress at stage 'index'"), or when the start has taken 10 minutes in all; a progress message after those 10 minutes does not save the start. A server that reports no progress is judged as before: 3 minutes on a quiet machine, and longer when the machine is busy (30 seconds more for each unit of load per core above 1, at most 10 minutes). The server answers the health check before its start-up work. It asks itself /api/ready every 5 seconds (for up to 10 minutes), and one answer confirms the start, so one missed answer does not undo the update. The start-up work (status comments, issue lists, services) waits for this, at most 60 seconds. A new version starts with its runs and watchers held: no queued or resumed run starts and no watcher starts until the start is confirmed, however long that takes. If the new server stops or does not confirm in its time, the supervisor puts the previous version back and reports it (the monitor finding is critical). A record that cannot be read is not treated as healthy: the supervisor keeps watching, logs self-update: the record could not be read, and gives the start at least 30 seconds more once the record can be read again. A confirm and a rollback cannot both happen: the first one to take the claim for the install wins. A commit whose start failed once is installed again when the machine is calm (the load governor's rule, shown in the health line as "it did not start in time on a busy machine"). Only a second failed start blocks the commit; the health line then says so and waits for a newer commit on main. An install that was cut off is finished or undone at the next start.

To try a blocked commit again, run scf update retry (or scf update retry <commit>, with at least 7 characters of it). It clears the failed mark of that commit only, and the next check builds, tests and installs it (within 5 minutes). Nothing is changed when the failed update is another commit, when an install is not finished, or when the checkout cannot go back. A retry needs the supervisor that guards a second start, so after upgrading, stop and start the Foundry once (see above); until then the update waits for that restart. If you switch the setting off while an update waits, the server restarts on the unchanged version when the runs are done.

The supervisor's own code. When an update also changes the supervisor's files, the server restarts once more when its active runs are done (no new runs start meanwhile). The new supervisor then takes over in the same process: the supervisor keeps its process id, and the server runs on as before. If the new supervisor does not get ready within 30 seconds, or it stops, the running supervisor carries on with the old code, and the log says so. The log shows the supervisor's version (commit and code) at start and after each update, next to the server's version; GET /api/health shows the same as supervisor. An install made before this change runs the old supervisor until you stop and start the Foundry once.

A side-by-side start. When the installed build supports it, a new version starts next to the running server and the old server keeps serving on its port until the new one is ready. The new version starts on a free port in a read-only warm-up mode. When it is ready, the old server stops at a safe moment (no push, merge or release step runs and the updater is not installing), and the new one takes over the port and starts its work. Runs that were waiting go on as after a normal restart. If the new version does not get ready (it exits, stops making progress, or takes longer than 10 minutes), it is stopped, the old server keeps serving on its port, and the attempt counts as a failed start: it is tried again when the machine is calm, and a second failed start waits for a newer commit, as described above. A build without warm-up support, or a supervisor that does not answer within 5 seconds, uses the stop-and-start restart as before.

When the health line says "Self-update is stopped", the checkout needs a person: run git status, npm ci, npm run build, then delete self-update.json in the data folder. Going back does not undo changes the bad version made in the data folder.


Improve this page on GitHub