User guide: contents

6. Automate with watchers

A watcher checks GitHub on a schedule and starts runs by itself — as long as the Foundry is running (see Keep it running). GitHub access uses the gh CLI's login.

To see and change watchers, switch to the Admin view, choose Administration in the sidebar, then Watchers under Operations. A repository's own page (Repositories in the sidebar, then the repository) has a Watchers section too.

The Watchers page: watchers grouped by repository, and the monitor under "The Foundry itself"

Sources#

SourceStarts a run when…Default flow
Issuesan open issue has the trigger labelissue-gitflow (or issue-plan / issue-code-daily for the human-in-the-loop pipeline)
Scheduleit is time (every N, or once a day at a set time)release-daily
Monitornever — it checks the Foundry itself and records problems (see The monitor)none
Review commentssomeone comments on a Foundry PR (branch factory/*)none shipped — name your own flow
CI failuresthe latest CI run of a workflow on the default branch failednone shipped — name your own flow

The form of + Add watcher: repository, flow, label and the option groups

For a schedule, the text becomes the run's task. Intervals: 30s, 5m, 1h, 7d; or set Once a day at 17:00 with a time zone.

Schedule runs have their own lane. A run a schedule watcher starts (the daily release, the daily report) uses no story slot and goes before queued stories, also when a helper's cap or the usage limit holds back new stories: these runs use no agent, so they cost nothing; their only load is one test run, which still waits for a free test slot. One schedule run works at a time on the whole machine, in the order they were queued. A spent daily budget of the watcher's owner still holds them. A daily run belongs to the day it was queued for: a release that waited in the queue past midnight still counts for the day before, so the next day gets its own release. A schedule run that has not started an hour after its time shows a late warning on Today and in the health line, with the reason it waits; the warning goes away when the run starts. A run that was never queued keeps its warning until the next day's time.

Build release files after each release. A schedule watcher has the checkbox Build release files after each release (option release_build, default off). When it is on, the watcher looks at the head of main at every check, and at least every 5 minutes. A new commit that has a recipe (the file .factory/release-build.yaml at the commit, or the recipe stored in the Foundry settings) gives one release-build run of the newest commit on main, which then uploads the files to a draft release (see Build release files on this machine). A new commit without a recipe is only recorded: nothing is built. The first check after you switch the option on only remembers the current commit, so nothing is built for it. Several moves before a build starts give one build, of the newest commit; a queued build is never cancelled. A commit is never built twice, also after a restart: the record is in release-builds/ in the data folder. A failed build is not retried; start it by hand. A build you start by hand does not count as recorded, so the watcher may build that commit once more. Switching the option off and on keeps the record, so a commit pushed meanwhile is built at the next check.

Options of an issues watcher. The form has three groups, collapsed by default; each control shows its default and one sentence on what it does. Only issues watchers show them.

  • Labels: labels that go first (default bug), a text for each status label (working, done, needs info, waiting, failed; default is the Foundry's own name), and labels to remove when a run succeeds.
  • Dependencies: wait for dependencies (default on), labels that count as done, a pause while a pull request whose branch starts with a text is open (cleared by an empty field), and one run at a time (default off).
  • Comments: a status comment (default on), a comment when a run fails (default on), a questions check (a flow run once over all new issues before any starts; default none), and answer questions automatically (default off). It means the Foundry answers its own questions with its recommendations, at most twice per issue; after that a person answers.

A field that is cleared is removed from the watcher, so the default applies. A value the server refuses is shown at its field with the server's message. The same options work for a watcher of a repository and for one still in config.yaml.

Reference repositories#

A run sees only its own checkout. When an issue depends on routes, file formats or names that live in another repository, a watcher can give its runs a read-only copy of that repository, so the planner and the coder look the facts up there instead of stopping with a question only you can answer.

  • Set it. In the form, the group Reference repositories (every source except the monitor) takes reference_repos: a list of owner/name, at most 10. The option reference_private_ok (default off) allows a private reference (see below). In config.yaml the same two keys are written under the watcher; through the API they are reference_repos and reference_private_ok in the watcher's body.

  • Which repositories. Only repositories already added to the Foundry, that the watcher's owner can see. The watcher's own repository is refused. A refused name is answered with reference_repos: … and the reason.

  • Where. Before a run's steps start, and again before each resume, each reference is cloned read-only, shallow, from the newest commit of its default branch, to <run folder>/reference/<owner>-<name> (lower case, for example reference/acme-lib). The copy sits next to the checkout, so it is never part of the pull request.

  • The commit is in the history. The run's run.json has a references list (the newest 50 preparations, each with the repository, the time, the commit, the folder and held — sandbox or file modes, what keeps the copy read only — or the reason it was skipped), and the run log has the same lines.

  • What the agents are told. Each agent step starts with a block that lists the copies with their commits and says they are for reading only. A fact the agent finds there is not a question for the owner: it must not be asked as an owner_action.

  • Read only. The copy has no remote, so it cannot be pushed. Its files are read-only and its folders cannot be entered for writing (.git included). Claude's Edit and Write tools are denied there, and on macOS the sandbox refuses writes and chmod there. In a sandboxed run nothing the run does can change the copy. In an admin's run without the sandbox a shell step can change it, and the check below removes it. Nothing the run does can commit the copy or put it in the pull request.

  • Checked before each agent step. Before each agent step, every copy of the run is checked against its commit: its HEAD must be that commit, git status must be clean (ignored files included) and the file modes must be unchanged. A copy that changed is removed, the step's reference block leaves it out, and the run log says ! reference <owner>/<name>: removed — it was changed during the run. The run goes on. The check does not look at .git/config or the refs, so a shell step in an admin's run can still add a remote to a copy before the check removes it.

  • Removed. The copies are deleted when the run ends, also when it waits or stops. If a crash leaves one behind, scf clean unlocks and removes it.

  • Skipped, not failed. A reference that cannot be used does not fail the run. The run log says ! reference <owner>/<name>: skipped — <reason> and the run goes on. Reasons:

    • it could not be fetched;
    • the run's owner cannot use it;
    • a policy refuses access to it;
    • the privacy rule below refuses it;
    • a user's run has no OS sandbox (see below).
  • Privacy. What a reference teaches the agent can end up in issue comments, the pull request or commits, so a reference is used only when it is safe for the target:

    • a public reference is always used;
    • a private one (or one whose visibility cannot be told) is used only when the target repository is known to be private, or reference_private_ok is on.

    A 404 from GitHub does not count as proof that a repository is private. The privacy check runs again at every start and resume.

  • Who gets a copy. A run with the OS sandbox gets copies. An admin's run without the OS sandbox (for example one in the default workspace) gets them too: file modes hold them, and they are checked before each agent step. A user's run without the OS sandbox (sandbox.user_runs: off) skips every reference, because a shell step could make the copy writable again.

  • Off by default. Without reference_repos, nothing changes: no copy, no block in the prompts, and no references in run.json.

The Watchers page (admins)#

Only admins see the Watchers page. No watcher name or status shows anywhere else. A user sees the runs a watcher started on their repository under Changes, without the watcher's name.

  • From the repository. The heading of each repository group is a link to the repository view (#/repos/<id>). Its Watchers section lists the watchers of that repository, with + Add watcher and, per watcher, Enable or Disable, Edit and Delete (Delete asks first). If the server refuses a change, its sentence is shown.
  • By repository. Watchers are grouped by connected repository. Each group shows the repository's owner (with a "blocked" mark when the owner is blocked). Runs of a watcher belong to that owner.
  • + Add watcher. Choose the repository from a list, then the flow, the labels and the other options. There is no owner field: the repository's owner is used. Repositories that cannot have a watcher (a deploy key, or not on GitHub) are listed as not available, with the reason.
  • Variables. The form shows one field per variable the chosen flow describes, with its label, help and default (as the placeholder): a number field with its range, a switch, a text box, a list or a choice. Changing the flow changes the fields. A field left at its default is not stored. Variables the flow does not describe go in the box "Variables for each run", one name=value per line; a described variable typed there moves to its field when the form opens. agent_env is a list of KEY=value pairs and may hold secrets.
  • Edit, enable, disable, delete. These change the watcher at once. Options the form does not show are kept when you edit. If the server refuses a change, its sentence is shown as it is.
  • One watcher. The list is compact: the id (a link to #/watchers/<id>, crumbs Administration › Watchers › <id>), the state mark, what it does, the last successful check and a problem line. The watcher's page has the next steps, notes, error details and recent activity; for the monitor also the bug-story switch and the findings. Check now, Edit and Enable or Disable are together; Delete is alone in a Danger group. List rows have no Delete button.
  • The monitor stays on the page, under "The Foundry itself". The built-in monitor is marked built in, has no Delete, and is saved in config.yaml only once you edit it; turn it off with monitor.enabled on the Problems page. A monitor you added to config.yaml is still saved there. If only the monitor cannot be loaded, the watchers are still shown and the monitor card says so, with Retry.
  • While it works. The page shows a grey skeleton while it loads. Check now shows "Checking…" next to its own button. Delete asks first in a dialog. If a reload fails, the list stays and a line says when it was last updated, with Retry. The same holds for Users and Problems.
  • From config.yaml. A watcher that is still in config.yaml (for example while there is no admin account, or at the connection limit) shows read-only with a note, and Check now. A watcher whose repository is gone can only be deleted.

Watchers of a repository (API)#

The page uses these routes. A watcher stored for a connected repository has the same options as one in config.yaml, except github_repo and owner: they come from the repository. The source monitor is not allowed.

  • Routes: GET and POST /api/admin/repos/:id/watchers, and PUT and DELETE /api/admin/repos/:id/watchers/:wid. A user gets 403. Changes go to the log. A change starts, stops or restarts the watcher at once. A described variable whose value does not fit its kind or range is refused (400, the message names the variable, as vars.<name>: …); a stored value that is already out of range still runs and is refused only when the watcher is saved again. GET /api/admin/repos adds a watcherProblem sentence to a repository that cannot have a watcher.
  • Pause and resume: POST /api/watchers/:id/pause and POST /api/watchers/:id/resume (admins; scf watchers pause <id>, scf watchers resume <id>) do what Disable and Enable do on the Watchers page: a paused watcher checks nothing and starts no new run, and runs that are queued or going on go on. The answer is { id, repoId, github_repo, enabled, state } and does not include the watcher's other settings. An unknown id gives 404. A watcher kept in config.yaml (the monitor) or one whose repository is gone gives 409; change the monitor in the settings. A real change writes a repo-change audit line, "watcher <id>: paused" or "watcher <id>: resumed". A service account needs each route in its scope on its own: pause does not give resume.
  • Which repositories: GitHub only, with the sign-in none (the owner is an admin), github-token or github-app. ssh-deploy-key, https-token and other addresses are refused.
  • The id is unique on the whole install, in the store and in config.yaml together. A duplicate is refused.
  • Runs belong to the repository's owner, so they show under Changes for that user.
  • Lists: GET /api/watchers also shows stored watchers, with their repoId. A stored watcher that cannot run shows a problem sentence.
  • Blocked owner: while the owner is blocked, the watchers of their repositories are paused. They check nothing and start nothing, and the list shows "paused: the owner is blocked". Unblocking starts them again, without a restart. This also works for scf user block and scf user unblock: the server sees it within its usual sweep. Runs that are already going are not touched.
  • Removed with their repository: when a repository is removed (by id or by name), or its owner is deleted, its stored watchers are stopped and removed in the same step. The audit log says so. A watcher found at start whose repository is gone is removed and logged.
  • Transfer: a transferred repository keeps its watchers. They run for the new owner, and new runs belong to the new owner.
  • Sign-in: a stored watcher talks to GitHub with its repository's own credential: the stored token, a GitHub App token limited to that repository, or the server's own gh login for the method none. With a token or the app, the server's login is never used, so one repository's watcher cannot see another. The same credential is used for the actions on its items under Your turn on the admin's Today. Watchers in config.yaml keep using the server's login.
  • When the sign-in does not work (missing, unreadable or refused, or the owner of a none repository is no admin), the watcher makes no GitHub call and its status says so in a plain sentence. It works again by itself at the next check once you fix the credential.
  • Status comments: a status comment is only edited by the account that wrote it. When a watcher's account changes (for example a new token of another account), it posts a new status comment and the old one stays as it is on open issues.
  • Request limit: a repository token or app has its own GitHub request limit. The limit the Foundry shows is that of the server's own login and the bot.

Watchers move from config.yaml to their repositories#

When the server starts after the update, every watcher in config.yaml except the monitor moves to the repository store. Nothing to do — it happens by itself.

  • Same watcher. Its id, options and enabled state stay the same, so run history, status comments and labels on GitHub keep matching. A repository name with capital letters (Acme/App) keeps its spelling.
  • Repository not connected yet: it is connected for the first admin with the method none. The admin pages show it as none (legacy): the watcher uses the server's own gh login, as before.
  • Repository already connected (for example by a user): it keeps its owner and method, and the watcher is attached to it. If that method cannot run a watcher (a deploy key, or none owned by someone who is no admin), the watcher moves but is disabled. The log and the Watchers page say why.
  • The owner option goes away. The repository's owner owns the runs. If the option named another account, the log says so.
  • The backup. Before it changes config.yaml, the Foundry copies it to config.yaml.before-watcher-move-<date>-<time> next to it. The moved watchers are then removed from config.yaml; the rest stays the same. Comments in the file are lost, so use the backup to see them. The log names every moved watcher.
  • No admin account yet: nothing moves. The watchers keep running from config.yaml and move at a later start, once an admin exists.
  • At the connection limit (50 per account): the remaining watchers stay in config.yaml and the log says so.
  • Safe to repeat. If the server stops halfway, the next start finishes the move without duplicates. A watcher you add to config.yaml by hand later moves at the next start. A watcher whose stored copy differs, or whose id is used twice in the file, stays in the file and is logged.
  • After the move, saving config.yaml through PUT /api/config with a new or changed watcher other than the monitor is refused, with a sentence that points to the Watchers page. Add and edit watchers there.
  • scf watch works as before, with the server's own login.

Going back. Stop the server, copy the backup over config.yaml, and delete the moved watchers on the Watchers page first (or remove them from repo-watchers.json in the data folder). Otherwise the next start moves them again.

The watchers are kept in repo-watchers.json in the data folder.

GitHub CI on develop and main#

For every repository with an enabled issues watcher on GitHub, the Foundry reads the newest finished GitHub Actions runs of the develop and main branches. Local projects are not read. You need no setting for this.

  • How often. At most once every 15 minutes per repository, however many watchers it has. The read runs at the next watcher check after that wait. A quiet repository costs two requests per read, one per branch. A new red workflow costs two more (its failed job and the job's log).
  • What counts. Runs of pull requests, and runs that were cancelled, skipped or neutral, are left out. Runs are grouped by workflow.
  • Red. A workflow is red on a branch when its two newest counted runs both failed, timed out or did not start. One red run is not enough.
  • One bug story. For each red workflow the Foundry makes one issue in the repository, titled GitHub CI fails: <workflow> on <branch>. It names the failing job and step and ends with the last 40 lines of the job's log (at most 4,000 characters). A third red check makes no second story. The story carries the watcher's build label, so it is built like any other story, and it starts at once when the watcher has a free slot.
  • A story is made once. Before the Foundry creates a story, it looks for the story's hidden marker among the repository's issues. A crash in the middle does not leave a second story behind.
  • Closed when green. When the newest counted run of that workflow is green on every branch the story names, the Foundry adds one comment and closes the story as completed. If you close the story while the workflow is still red, no new story is made; once it is green, the Foundry forgets the entry.
  • A red main asks you. While main is red for a workflow, Your turn shows one item, "Fix the GitHub CI workflow that fails on the main branch". There is one such item per repository and workflow, and it goes away when main is green again.
  • Repair log. Making and closing a story each write one ci-bug-story line, listed under Automatic repairs in the daily digest.
  • The page. The repository's page has a GitHub CI section: each watched branch with its red workflows, the open story with a link, and when CI was last read. It shows the stored state only, so opening the page does not call GitHub. Only the repository's owner or an admin can read it (GET /api/repos/:id/ci, listed in the API table of chapter 7).
  • Text from GitHub is untrusted. The log is cleaned and secrets are removed. Where the Foundry cannot be sure of that, the story is made without a log. Words that would add a hidden marker or a "depends on" or "blocked by" line to the story are broken up.
  • Autonomy. When the flow's autonomy level does not let a story be pushed, no story is made. The page shows the reason instead.
  • Failures. A failed read is written to the server log, and the watcher's check goes on as before. Every GitHub call has a time limit.
  • Known limit. When a red workflow is deleted, its story stays open until someone closes it by hand, and the main item stays until the workflow reports green.

The state is kept in ci-watch.json in the data folder.

More in this chapter

Improve this page on GitHub