- Go 63.8%
- Shell 33.7%
- jq 2.5%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .changelog | ||
| .forgejo/workflows | ||
| docs | ||
| forgejo | ||
| internal | ||
| roles | ||
| tests | ||
| .gitignore | ||
| CHANGELOG.md | ||
| go.mod | ||
| README.md | ||
| REVIEW.md | ||
gascitypacks
Gas City packs for the city root: a roles pack, which defines the agents the city runs, and a forgejo forge pack, which opens pull requests on a Forgejo instance and follows them to merge.
| Pack | Directory | What it carries |
|---|---|---|
roles |
roles/ |
the Operator, the Worker, which runs for each rig and for the city, and the Researcher, a pool of the city, their role skills and the shared skills city and contact, the Worker's formula mol-worker-work, the apply, upgrade, permission-request, handover and failures orders, and the permission deny, gnu check, version, worktree setup, worktree check, worktree branch, view beads, view mail, waiting and nudge commands, and the roles tool in Go that the handover and failures orders and version start |
forgejo |
forgejo/ |
the commands pr open, pr state (with --json), pr merge, pr review and pr comment, the merge order (which is the tool's order merge), the checks order (the tool's order checks: one mail to the Operator when a pull request's checks settle), the schedule order (the tool's order schedule, off until a city switches it on), the review order (the tool's order review, off the same way), the Reviewer, an agent that reviews one head of a pull request, for each rig and for the city's own repository, with its formula mol-forgejo-review, and the Go tool behind the commands |
Importing
A city imports both packs at the city level and for each rig, and binds the forgejo pack as forgejo. The Worker's formula runs gc <forge> pr open, and forge defaults to that binding: a rig that binds the pack under another name sets formula_vars = { forge = "<name>" }.
[imports.roles]
source = "https://sarak.sh/mikluko/gascitypacks.git//roles"
[imports.forgejo]
source = "https://sarak.sh/mikluko/gascitypacks.git//forgejo"
The forgejo pack's commands and its merge, schedule, checks and review orders read the Forgejo API token from FORGEJO_TOKEN_COMMAND or FORGEJO_TOKEN_FILE, and need go, git and jq on the supervisor's PATH.
Where the token comes from
FORGEJO_TOKEN_FILEnames a file whose trimmed content is the token.FORGEJO_TOKEN_COMMANDis a command, run withsh -c, whose trimmed stdout is the token. When it is set it wins overFORGEJO_TOKEN_FILE, and a command that fails (or prints nothing) is an error: the tool does not fall back to the file. The command runs in the pack's directory (the tool starts asgo tool -C "$GC_PACK_DIR") with the environment of the process that started the tool, so give it absolute paths, and any variable it needs (a secret store's address, say) in the same environment as the variable itself. The pack knows nothing of where a command gets the token: a city that keeps its secrets in a store sets the command that prints it, asFORGEJO_TOKEN_COMMAND = "bao kv get -mount=agents -field=token forgejo/city-root", and the pack stays agnostic of the store. A command that fails is reported with its stderr, cut to 300 bytes, and never with its stdout.
Either is set where FORGEJO_TOKEN_FILE was: in [workspace.env] for every agent session, in the [[orders.overrides]] entry of each exec order, which does not receive workspace.env, and in an agent's own env for that agent alone. An agent's env wins over the workspace's for each variable, but the command wins over the file wherever each is set: an agent whose env sets FORGEJO_TOKEN_FILE while [workspace.env] sets FORGEJO_TOKEN_COMMAND reads the workspace's command. A city that moves to the command moves every place that names the token to it, the Reviewer's patch included, or sets its own FORGEJO_TOKEN_COMMAND in the agent that has a token of its own.
gc forgejo token prints the token as the tool reads it, for the one caller that must put it in a request of its own: the Reviewer's formula, which sends -H "Authorization: token $(gc forgejo token)" and so cannot disagree with the tool about where the token is. It is the only reader of the token that is not the tool. The doctor accepts either variable: with the command set it runs it once and checks that it exits 0 and prints something, never showing what it printed, and otherwise checks that the file is readable.
The upgrade order runs gc import upgrade on the city repository's origin/main every ten minutes. When an import moved, it validates the result as apply does, pushes it to the branch upgrade/packs as the city's git identity, and opens the one pull request for that branch with gc forgejo pr open (UPGRADE_FORGE names the forge pack's binding when it is not forgejo). It moves an import that follows the releases with a semver version, and never a sha: pin, so a city that pins by sha: gets no pull request from it. The supervisor's git needs write access to the city's origin. The order's commit is not signed: it is made with commit.gpgsign=false, whatever the supervisor's global git configuration says, so a configuration that signs every commit cannot make the order depend on a signing agent the supervisor cannot reach. The order needs FORGEJO_TOKEN_FILE too, which exec orders do not receive from workspace.env: give it to the order as the city does for merge, with an [[orders.overrides]] entry named upgrade.
The two orders fetch through one command. apply and upgrade both fetch origin/main into the city repository, and they fire together now and then (every 5.5 and every 10.5 minutes). Git lets only one of two concurrent fetches that find the branch moved update refs/remotes/origin/main; the other fails with "cannot lock ref", or "Unable to create … .lock: File exists" while the first still holds the lock, though the first has done what it wanted. Both orders therefore call roles git fetch <repo> <branch> (roles/assets/roles/fetch.go, tested beside it), which runs git fetch origin <branch> and, for a failure that says one of those two things, runs it again, up to five tries in all, 0.2 to 0.6 seconds apart at random so that two fetches that collided do not collide again on the same beat. By then the ref is where the first fetch put it and the second has nothing left to do. Any other failure fails at once, and a lock still lost after the fifth try fails too (a stale .lock file left by a killed process is that case): the command prints git's own words on stderr and exits 1, and the order mails the Operator as it always did. The orders retry and do not take a lock of their own because a lock shared by two scripts needs a rule for a stale lock left by a run killed outright, and a retry also covers a fetch the user or a Worker runs in the city directory, which no lock of the orders could. Both orders need go on the supervisor's PATH for it, as apply did for roles changelog install.
Permission mode
The Worker and the Reviewer set no permission_mode: they take the city's provider default, the option_defaults of the city's [providers.claude] or [providers.acp] (or a [[patches.agent]] entry for one agent). Before this change both agents pinned permission_mode = "unrestricted", which gc maps to --dangerously-skip-permissions, in every city that imported them. The Operator pins permission_mode = "auto-edit" (--permission-mode acceptEdits) in place of unrestricted, in every city that imports the roles pack.
A city that sets nothing gets gc's builtin default for the provider, which at the city's gc pin (6bd609f) is unrestricted for the claude profile (internal/worker/builtin/profiles.go, as the city's brief for this change reads it; this pack's tests do not check gc's source), so that city runs the same flag as before for the Worker and the Reviewer. A city that sets a mode of its own, such as full-auto (--permission-mode dontAsk), now has it apply to the Worker and the Reviewer too, where before their pin overrode it. A city that wants the old mode for them alone patches them:
[[patches.agent]]
rig = "*"
name = "roles.worker"
option_defaults = { permission_mode = "unrestricted" }
Under --dangerously-skip-permissions Claude Code tells the model to do its work through Bash, and a Worker then reads with cat and sed -n and writes by heredoc. The Worker's skill and the Reviewer's prompt say to use Edit, Read and Write for files instead, and that a call the session's allow rules do not cover comes back as a refusal, which is not the end of the run. In a mode that never prompts (dontAsk), a call no allow rule covers is denied in the session and not held by gc for an answer, so the Operator's permission-request mail has nothing to report.
The Operator runs in auto-edit, not in the city's default, because it is the one agent that talks to the user: under acceptEdits a call that no allow rule covers prompts the user in the Operator's tab, and AskUserQuestion keeps working, which dontAsk would deny. With the city's allow list (the permissions of the settings file gc passes to every claude session) the Operator is prompted only for a call the list does not cover. A city that wants the Operator in another mode patches it, as above, with name = "roles.operator".
The Researcher pins permission_mode = "full-auto" (--permission-mode dontAsk) in every city that imports the roles pack, whatever the city's default: the user's brief for the role is full-auto with an allow list and never a mode that asks nothing, so a call that no allow rule permits is refused and nothing prompts. The Researcher has its own section.
Reading a pull request's state
gc forgejo pr state --repo <worktree> --pr <url|number> prints one word. With --json it prints one JSON object on one line, the contract that the pieces of Landing (the scheduled merge, the review command, the checks order) read a pull request through. The merge order reads the state with the same code, without the checks and the reviews it has no use for.
gc forgejo pr state --json --repo <worktree> --pr <url|number>
The object has these fields, always all of them. schema_version is "1". A field is never removed, renamed or given another meaning without a new schema_version; a field may be added to version 1, and mergeable and reviews were. An older caller reads the same object, with two fields it does not know and ignores, and schema_version stays "1" for that reason; every field it reads keeps its name and meaning. One thing differs for it, and it is not a field: with --json the command now makes the requests for mergeable and reviews, and exits 1 with nothing on stdout when the reviews cannot be read (any error of their requests, a page that cannot be decoded) or when the forge gives an open pull request no mergeable field. The command of #34 printed its object in those cases, since it asked for neither. A caller that took any object as success handles the exit status; without --json nothing is asked beyond the pull request itself, and nothing changes. A caller that needs mergeable or reviews checks that they are present, since a tool from before them prints neither.
| Field | Type | Meaning |
|---|---|---|
schema_version |
string | "1" |
state |
string | open, merged, closed (closed without merging), missing or foreign |
head |
string or null | the head commit of the pull request, a full SHA |
base |
string or null | the name of the base branch |
merge_commit |
string or null | the commit the merge made on the base branch: never null for merged, always null for the other states |
checks |
object or null | whether the checks of head have completed, and with what result |
mergeable |
string or null | mergeable, not_mergeable or draft for an open pull request, null for the other states: what the forge says of the conflict check |
reviews |
array or null | every review of the pull request, oldest first: one object each |
checks is {"state": …, "completed": …}: state is one of not_started, pending, success, failure, none, and completed is a boolean, true exactly for success, failure and none.
What it prints for each state of a pull request:
state |
The forge answers | head |
base |
merge_commit |
checks |
mergeable |
reviews |
|---|---|---|---|---|---|---|---|
open |
the pull request, open | the head SHA | the base branch | null | the head's checks | mergeable, not_mergeable or draft |
the list, [] for none |
merged |
the pull request, merged | the head SHA | the base branch | the merge commit | the head's checks | null | the list |
closed |
the pull request, closed and not merged | the head SHA | the base branch | null | the head's checks | null | the list |
missing |
"not found" in the forge's own error object | null | null | null | null | null | null |
foreign |
nothing asked: the --pr is on another host, or is no pull request URL |
null | null | null | null | null | null |
An open pull request whose head the forge does not name is an error, and the other states leave head and checks null then (their reviews are still read: they do not depend on the head). An open pull request for which the forge gives no mergeable field is an error too, as one with no head is. A merged pull request for which the forge names no merge commit is an error too: the command exits 1 with nothing on stdout, so a caller that reads merge_commit of a merged pull request never has to handle null. Without the merge commit it is not known what landed on the base branch, so the caller retries later or stops and asks a person.
What it prints for each outcome of the head's checks:
checks.state |
completed |
When |
|---|---|---|
not_started |
false | the head has no status and no run yet, and its tree holds a workflow file: the forge has not started the run |
pending |
false | a status is pending, or a run is waiting, running or blocked |
success |
true | every status is success and every run is success or skipped |
failure |
true | nothing is pending, and a status is failure, error, warning or a value the tool does not know, or a run is failure, cancelled or a value the tool does not know |
none |
true | the head has no status, no run and no workflow file: there is nothing to wait for, and nothing passed |
none is not a pass: a consumer that wants a green head asks for success.
How the tool reads the checks, for a head H:
- Statuses. The latest status of every context of
H, all pages of them: it reads pages of 50 until one is not full, since the forge'stotal_countin the combined status is the length of the page and not the number of contexts. The tool judges them itself and does not read the forge's combinedstate, which ranks a failure above a pending status and so would call the checks complete while a context is still running. - Runs. The workflow runs for
H(GET /repos/{owner}/{repo}/actions/runs?head_sha=H). Runs that name another commit are dropped, for a forge that ignores the filter. A run that isblocked, as one waiting for the approval of a fork's pull request is, counts as unfinished: it has not run. - No workflow, or one that has not started. With no status and no run, the tool looks for a workflow file in the tree of
H, in the first of.forgejo/workflows,.gitea/workflowsand.github/workflowsthat exists, the order the forge reads them in. A.yamlor.ymlfile there makes the headnot_started; none makes itnone. The forge creates a push's runs a moment after the push, andnot_startedis that moment. The tool cannot tell it from a workflow that never triggers for a pull request (one withon: push: branches: [main]alone) and so never produces a run: such a head staysnot_started, and a consumer that must not wait for ever sets its own limit.
The rules of the other forms of pr state hold here: only the forge's own "not found" for the pull request is missing (a 404 of the reviews list, the checks or the workflow files is an error); a 5xx, a timeout, a bad token, a 404 that came from a proxy and not from the forge, or any other answer the tool cannot read is an error, with exit status 1 and nothing on stdout, never a state; a --pr on another host, or one that is no pull request URL, is foreign and no request is made; and the token goes to the forge's host only, the host of FORGEJO_URL when it is set, otherwise the host of the worktree's origin.
Without --json the output is what it was: the state word, and no request but the pull request's own.
mergeable
For an open pull request, mergeable says what the forge answers to "can it be merged":
mergeable |
The forge's pull request has | What it tells a caller |
|---|---|---|
mergeable |
mergeable: true |
no conflict with the base, the forge's conflict check has finished, and it is no draft. It is the one value that says the pull request is clean. |
not_mergeable |
mergeable: false, draft: false |
one of three things, and the forge does not say which: the pull request conflicts with its base; the forge is still checking, as it is for a moment after every push; or the check itself failed. |
draft |
draft: true |
the forge calls a draft (a work-in-progress title) not mergeable whatever its conflicts, so nothing is known of them. |
| null | any | the state is not open: whether a closed or merged pull request conflicts is of no use. |
The forge's pull request carries mergeable as a bare boolean, and, in Forgejo 17.0.1 (read in its source, below), the boolean is false while the conflict check is checking, for a conflict, and for an error, and the status that tells them apart is not in the API's answer (services/convert/pull.go:89, models/issues/pull.go:887-895; Status is not a field of PullRequest, modules/structs/pull.go:10-60). So the tool cannot give "still checking" a value of its own, and it does not pretend to: it never says a conflict or a clean pull request where the forge has not, and not_mergeable is the whole of what it knows. The checks of a head are different: they have not_started and pending, from reads the forge answers.
What a caller does with not_mergeable: it takes it as "not mergeable now", never as "conflicts". To act on a conflict it reads the pull request again, and treats the conflict as real only when not_mergeable still stands for the same head on a later read, a few minutes after the head last changed (the forge's check runs in a queue and takes seconds); the caller sets the delay, and a head that changes in between starts it again. Until then it waits. mergeable can be trusted as it stands.
reviews
reviews is every review the forge lists for the pull request, oldest first (the forge's own order, by creation time and id), each as an object:
| Field | Type | Meaning |
|---|---|---|
id |
number | the forge's id of the review |
account |
string or null | the login of the account that gave it; null for a review requested of a team |
team |
string or null | the name of the team a review was requested of, which the forge gives in place of an account; null for a review of an account |
state |
string | approved, request_changes, comment, pending, request_review, or unknown when the forge gives none; any other value the forge may have is passed on in lower case |
commit |
string or null | the commit the review was given on, a full SHA |
body |
string | the text of the review, "" for none |
official |
boolean | the forge's word that the review counts for the branch protection: its account may approve under the rule on the base branch, and it is the latest approval or request for changes that account gave |
stale |
boolean | the forge's word that a push changed the diff since the review |
dismissed |
boolean | the forge's word that the review was dismissed, by a person or, when the rule has dismiss_stale_approvals, by a push |
submitted_at |
string or null | the time the forge gives, as it writes it |
A pending review is a draft: the forge shows it to its own author and to an administrator, so for a token that is no administrator's it is only ever the token's account's own. The list holds no review the tool made up or dropped, and the tool puts no judgement in it: a caller decides.
Deciding from the reviews
Under the city's branch protection, main needs one approval from the whitelisted account city-root-review, a "request changes" review blocks until it is dismissed, and a push dismisses the approvals of the earlier head. The forge's counts, which the tool reads from its source below, are:
- an approval counts when it is
approved,officialand notdismissed, and, when the rule hasignore_stale_approvals, notstale(models/issues/pull.go:906-922); - a review blocks when it is
request_changes,officialand notdismissed, whatever its commit and whether it is stale (models/issues/pull.go:924-941, when the rule hasblock_on_rejected_reviews).
So, for the current head H (the object's head):
- An approval of
Hthat counts: a review withaccountequal to the review account,stateapproved,officialtrue,dismissedfalse andcommitequal toH. The commit comparison is the caller's own, stricter than the forge's: a push that leaves the diff as it was (a rebase onto a base that did not change the files, a new message) marks nothing stale and dismisses nothing, so the forge still counts an approval of the earlier head for the new one; the object shows that approval with acommitthat is notH, and a caller that wants the head reviewed does not count it. Thestaleflag is not used. - A blocking review stands: a review with
staterequest_changes,officialtrue anddismissedfalse, of any commit and any account that is official. A later approval from the same account ends it by itself: when an account gives a new approval or request for changes, the forge clearsofficialon every earlier review of that account (models/issues/review.go:423-426), so the request showsofficial: falsefrom then on, and a request that showsofficial: trueis the account's latest.
As jq programs, which read the object on stdin and print true or false (they work in jq 1.6 and later, and the tests run them on every case below):
# an approval of the current head from $acct that counts
jq --arg acct city-root-review '(.head // "") as $h | .state == "open" and $h != "" and any(.reviews[]?; .account == $acct and .state == "approved" and .official and (.dismissed | not) and .commit == $h)'
# a blocking review stands
jq 'any(.reviews[]?; .state == "request_changes" and .official and (.dismissed | not))'
What the object says in the cases a caller meets (the first column is the pull request as the forge has it, with H its head and E an earlier head):
| The pull request | mergeable |
reviews |
Approval of H that counts |
Blocking review |
|---|---|---|---|---|
| no review | mergeable |
[] |
no | no |
city-root-review approved H |
mergeable |
one approved, official true, commit H |
yes | no |
it approved E, the push dismissed it (dismiss_stale_approvals) |
mergeable |
one approved, official true, stale true, dismissed true, commit E |
no | no |
it approved E, and the forge neither dismissed it nor calls it stale (a push that left the diff as it was) |
mergeable |
one approved, official true, commit E |
no: the commit is not H |
no |
it requested changes on H |
mergeable |
one request_changes, official true, commit H, with its body |
no | yes |
it requested changes on E, then a push |
mergeable |
one request_changes, official true, stale true, commit E |
no | yes: the forge's rule ignores the commit |
| the request for changes was dismissed | mergeable |
one request_changes, official true, dismissed true |
no | no |
it requested changes on E and then approved H |
mergeable |
the request with official false, then the approval with official true |
yes | no |
| an approval from an account the rule does not name, and a comment | mergeable |
an approved with official false, a comment |
no | no |
| the forge is still checking mergeability, or the pull request conflicts | not_mergeable |
whatever the reviews are | by the reviews | by the reviews |
| a draft | draft |
whatever the reviews are | by the reviews | by the reviews |
What a caller cannot know from the output:
- The whitelist and the rule itself. The branch protection is not readable with the city's token (the forge asks for admin), so the tool does not know who the whitelist names, whether
dismiss_stale_approvals,ignore_stale_approvalsandblock_on_rejected_reviewsare on, or how many approvals are required.officialis the forge's own judgement of the whitelist, made when the review was given: a change of the whitelist later is not applied to reviews already given (IsOfficialReviewer,models/issues/review.go:259-288). The caller names the account it trusts (city-root-review), and the forge checks the rule again at merge time, so a wrong guess here makes a caller wait or act early, never merge what the protection forbids. - Whether the forge will merge. An approval that counts and
mergeabledo not say the checks are green (checksdoes), nor that the forge's own merge check has run since (docs/handoffs.md3.11 in the city's repository has what starts it). - Why a pull request is
not_mergeable, as above. - Other accounts' pending reviews. The forge does not list them to the city's token, and they block nothing.
How the tool reads the reviews, for pull request N:
- The request.
GET /repos/{owner}/{repo}/pulls/{N}/reviews?page=P&limit=50, which answers a bare array, no wrapper and no total in its body (routers/api/v1/repo/pull_review.go:27-109, Forgejo 17.0.1). It is read for every state the forge has a pull request for, and for no other. - Every page. The forge pages the list by database row (50 at most, 30 by default:
modules/setting/api.go:24-25,services/convert/utils.go:15-22; ordered by creation time and id:models/issues/review_list.go:122-133) and then drops, from each page, the pending reviews of accounts other than the token's (services/convert/pull_review.go:64-76). A page can be shorter than the page size without being the last, and one holding nothing but other accounts' pending reviews is empty. The page's length is not a total here, as thetotal_countof the statuses is not; the forge'sX-Total-Countheader is the number of rows, pending ones included (CountReviews,pull_review.go:95-107), and so is the only total. So the tool does not stop on a short page: it stops at a page that is empty and, when the header is there, only when the rows read so far have reached the header's total; so it makes one request more than there are non-empty pages, and a pull request with 120 reviews takes four. The rows are counted in two stages, because a page that lost rows to the filter does not show how many it held, and a forge may cap a page below the 50 asked for (MAX_RESPONSE_ITEMS). First at the fewest rows a page can have held, the most reviews any page returned: a page never holds more rows than the page size, so a count that reaches the total at that floor has reached it at the forge's size too, and the usual read needs no other request. Only when the floor falls short of the total does the tool ask the forge for its page size, once, withGET /api/v1/settings/api(max_response_items,routers/api/v1/settings.go, Forgejo 17.0.1), and count atmin(50, max_response_items). A failure of that request, or an answer with nomax_response_items, is an error of the reviews (exit 1, nothing on stdout), never a guess at the page size. More than 20 pages is an error, and the page is the forge's: on a forge that caps a page at 20 rows, 400 reviews are the most the tool reads before it fails, and it never ends the read short without saying so. - How this is known. From the forge's source at the tag
v17.0.1, which sarak.sh runs, read at the lines cited above; not by trying it on a real pull request. The fake forge of the tests answers as that source does: a bare array, oldest first, 30 by default and at most the page cap (50 unless a test sets a lowerpageCap),X-Total-Countof all the rows, then the other accounts' pending reviews dropped from the page, an empty array past the end; and it answers/settings/apiwith the cap asmax_response_items, in the shape the forge's source gives.
Scheduling a merge
No agent merges. gc forgejo pr merge asks the forge to merge one head of a pull request, and Forgejo lands it as the account whose token the command uses, once the repository's required checks have passed and the review account has approved: the rules the user set on each repository's main, which the forge enforces and the command does not read.
gc forgejo pr merge [--json] --repo <worktree> --pr <url|number> --expect-head <sha> --target <branch>
gc forgejo pr merge [--json] --repo <worktree> --pr <url|number> --cancel
--pr is named as pr state names it. --expect-head is the full SHA of the head the caller reviewed, and --target the base branch the pull request must be onto. The request to the forge is POST /repos/{owner}/{repo}/pulls/{n}/merge with {"Do": "squash", "head_commit_id": <expect-head>, "merge_when_checks_succeed": true}. The client rules of pr state hold: only the forge's own 404 is missing, a 5xx, a timeout, a bad token or an answer the tool cannot read is an error (exit 1, nothing on stdout) and never an outcome, a --pr on another host is foreign and gets no request, and the token goes to the forge's host only.
What it does and prints
The command checks the pull request first and calls the merge endpoint only when every check passes. The checks run in the order of this table, and the first that fails decides.
| Case | Exit | outcome |
reason |
stderr says |
|---|---|---|---|---|
the --pr is on another host, or no pull request URL (no request is made) |
8 | refused |
foreign |
the --pr is not a pull request of the forge |
| the forge answers "not found" in its own error object | 7 | refused |
missing |
the pull request does not exist |
| the pull request is merged or closed | 4 | refused |
not_open |
it is merged (closed), not open |
its head is not --expect-head |
3 | refused |
head_moved |
the head it has, and the expected one |
its base is not --target |
5 | refused |
wrong_base |
the base it has, and the target |
| the head has no diff against the base (no changed file, no addition, no deletion) | 6 | refused |
no_diff |
there is no diff |
| the forge reports no head, or no diff statistics | 1 | an error: nothing on stdout | ||
the forge took the request (201) and the head is still --expect-head |
0 | scheduled |
null | |
| the forge took the request and the pull request is merged at that head by the time the command reads it again | 0 | merged |
null | |
the pull request already has a scheduled merge (409, "already scheduled to auto merge") and its head, read again, is still --expect-head |
0 | already_scheduled |
null | |
| the same, and the head moved, or the pull request closed, before the command read it again | 3 or 4 | refused |
head_moved or not_open |
the schedule is not the command's, so it stands; schedule_cancelled is false |
| the same, and reading the pull request again failed | 1 | an error: the head is not confirmed, and the schedule stands | ||
the forge refuses the request with a 405 or a 409 that is not the above (a pull request that is not mergeable, a work-in-progress title, an account that may not merge; a pull request that is not mergeable is a conflict with the base, a conflict check still running or a conflict check that failed, which the forge answers alike with Please try again later: below) |
9 | rejected |
forge_refused |
the forge's status and message |
| the forge took the request and the head moved, or the pull request closed, before the command read it again | 3 or 4 | refused |
head_moved or not_open |
the schedule is cancelled again; schedule_cancelled is true |
| the same, and cancelling the schedule failed | 1 | an error: the schedule may still stand | ||
| the forge took the request and reading the pull request again failed | 1 | an error: the head is not confirmed, and the command cancels the schedule it made (failing closed); when that fails too, the error says the schedule may still stand |
With --json the command prints one object on one line, a refusal too, with exit status as above. Without it, it prints the outcome word and a refusal prints nothing on stdout. The object has these fields, always all of them; schema_version is "1", and a field is never removed, renamed or given another meaning without a new version.
| Field | Type | Meaning |
|---|---|---|
schema_version |
string | "1" |
outcome |
string | scheduled, already_scheduled, merged, cancelled, not_scheduled, refused or rejected |
reason |
string or null | for refused and rejected: head_moved, not_open, wrong_base, no_diff, missing, foreign or forge_refused |
state |
string or null | the pull request's state as the command read it: open, merged, closed, missing or foreign |
head, base |
string or null | the head commit and the base branch the forge reported |
merge_commit |
string or null | for merged |
forge_status, forge_message |
int or null, string or null | for rejected: the forge's answer |
schedule_cancelled |
boolean | true when the command scheduled the merge and took it back |
Exit statuses 1 (a failure) and 2 (a mistake in the command line) are as in every command of the pack, and 3 to 9 are the refusals above, one each. A caller tells the refusals apart by the exit status or by reason.
What a caller does with the answers:
- Exit 1 is a failure to retry, not an outcome: a 5xx or a timeout. The caller asks again later; the command is safe to repeat.
- Exit 9 with
Please try again lateris not a conflict by itself. The forge answers a pull request that conflicts with its base, one whose conflict check is still running and one whose conflict check failed with the same 405 (CheckPullMergeableinservices/pull/check.go, Forgejo 17.0.1: it testsCanAutoMergebeforeIsChecking, so a pull request still being checked isErrNotMergeableState, whichMergePullRequestanswers with 405). A caller asks again, and reads the pull request'smergeable(seemergeable) before it takes the refusal for a conflict. The schedule order does that. no_diffis not proof that the pull request is empty. The forge computes the statistics when it renders the pull request, logs a failure of that computation and leaves them at zero (services/convert/pull.go,ToAPIPullRequest:GetShortStatfails, andchanged_files,additionsanddeletionsstay 0), so a transient error on the forge reads as no diff, and the command cannot tell the two apart. A caller does not close a pull request onno_diffalone: it asks again, and acts only when the answer repeats.- A caller re-runs the command, and does not trust one answer to hold. Two callers at once can leave one told
already_scheduledwhile the other, having seen the head move, cancels the only schedule. The command is safe to repeat: the caller that was toldalready_scheduledruns it again the next time round, and schedules again if the schedule is gone.
--cancel
gc forgejo pr merge --cancel --repo <worktree> --pr <url|number> is DELETE /repos/{owner}/{repo}/pulls/{n}/merge: the forge removes the pull request's scheduled merge, whoever scheduled it, if the token's account may merge (otherwise it answers 403, which is an error here). It prints cancelled, or not_scheduled when the forge answers 404 for a pull request that exists and has no scheduled merge, both with exit status 0, so a caller can cancel without knowing whether a merge is scheduled. A missing or foreign pull request is the refusal missing or foreign. --cancel takes neither --expect-head nor --target.
What Forgejo does with a scheduled merge
Read from the source of Forgejo 17.0.1, the version https://sarak.sh/api/v1/version reports (tag v17.0.1, commit 363f3dc30beef902b187af5a5244ff7af44901e6, on codeberg.org/forgejo/forgejo), and not tried on a real pull request: routers/api/v1/repo/pull.go (MergePullRequest, CancelScheduledAutoMerge), models/pull/automerge.go, services/automerge/automerge.go, services/shared/automerge/automerge.go, services/automerge/notify.go, services/pull/check.go and services/convert/pull.go. The test's fake forge answers as these functions do.
- A schedule is one row per pull request, and holds no head. The table
pull_auto_mergehas the pull request, the account that scheduled it, the merge style, the message and whether to delete the branch; no commit.MergePullRequestpasseshead_commit_idto the merge only on the path that merges at once, and withmerge_when_checks_succeedit stores the schedule and answers201with an empty body, before it looks athead_commit_id. So the forge does not enforce--expect-headon a schedule. The command sends it all the same, and reads the pull request again after the201: a head that moved between its first read and the forge's answer has its schedule cancelled again (schedule_cancelled). - A push does not remove the schedule. Searching the whole tree, the schedule is deleted by
DELETE .../mergeand its twin in the web UI (RemoveScheduledAutoMerge), by the merge itself just before it merges, by the web UI when it schedules a pull request again (the API answers409instead), when a push merges the pull request (routers/private/hook_post_receive.go,handlePullRequestMerging), and when its repository or account is deleted. A push to the head branch calls none of them:AddTestPullRequestTaskinservices/pull/pull.godismisses stale approvals there (when the branch rule hasdismiss_stale_approvals) and queues the checks, and leaves the schedule. A scheduled merge therefore survives a push, and merges whatever head the pull request has when the conditions are met: its queue item carries the commit the event named, and is dropped, with a warning in the log, when that is no longer the head. The dismissed approval of the old head means the new head needs its own approval and its own passing checks before it merges. The forge does not say which head a schedule was made for, and neither the pull request object nor its timeline carries it, so the command cannot tell a schedule for this head from one for an earlier head. A second request answers409, and the command reportsalready_scheduled. A caller that wants a schedule made for the head as it stands cancels first and schedules again. - The merge request never merges at once. With
merge_when_checks_succeedthe forge runs its mergeability check for the account (CheckPullMergeable, which skips the branch protection rules for this kind of request, so a missing approval or check does not refuse it: it answers404for a closed pull request and405for a merged one, a work-in-progress title, a pull request that is not mergeable (a conflict with the base, a conflict check still running, or one that failed:Please try again laterfor all three, since the check ofCanAutoMergecomes before the one ofIsChecking, soErrIsCheckingis never returned there) or an account that may not merge), stores the schedule and answers201, whatever the state of the checks and of the approvals. The forge starts its merge check on a commit status, on an approving review, on a dismissed review, and after the check of a pull request's mergeability that a push or a change of the base branch starts (services/repository/commitstatus/commitstatus.go,services/automerge/notify.go,services/pull/check.go). It does not start one when the schedule is stored. The outcomemergedis the case in which one of those events had merged the pull request by the time the command read it again. A pull request that already has its checks and its approval when it is scheduled stays open until one of those events comes, such as a new status, a review or a push; a caller that seesscheduledon a pull request that has everything has to wait for that or ask the user. - The merge is made as the account that scheduled it, with the merge style stored (
squash), after the forge has checked branch protection again for the head it has (CheckPullMergeable), so a required approval or check the head lacks keeps it from merging. DELETE .../mergeanswers204and removes the schedule when the token's account scheduled it, or may merge;403for an account that may not;404when there is no schedule (and for a missing pull request). The forge records a comment on the pull request for the schedule and for the cancel.- The diff the command checks is
changed_files,additionsanddeletionsof the pull request object, the statistics of the head against the merge base that the forge computes for an open pull request. A forge that leaves them out is an error, not a pull request with no diff.
The schedule order
The schedule order is the clock of the scheduled merge. Every two minutes it reads the closed beads whose merge_result is pull_request, and for each one runs what gc forgejo pr merge --expect-head <the bead's gc.work_commit> --target <the bead's target> runs, in the same process (forgejo order schedule is the Go behind it; assets/scripts/schedule.sh only starts it). A bead with no target is onto the default branch of its repository. It runs for every such bead every cycle, not once, because the forge does not say whether a schedule stands and the command is safe to repeat; it never cancels one. It is built and not switched on.
Turning it on
One switch: FORGEJO_SCHEDULE=on in the order's environment. Anything else, including no variable, is off, and with it off the order prints one line and exits 0 before it reads a bead, asks the forge for anything, or calls gc. The environment is the order's [[orders.overrides]] entry in the city's city.toml, the one that already gives the order FORGEJO_TOKEN_FILE (exec orders do not receive workspace.env):
[[orders.overrides]]
name = "schedule"
rig = "*"
env = { FORGEJO_TOKEN_FILE = "/path/to/token", FORGEJO_SCHEDULE = "on" }
An instance for the HQ store is the pack imported at the city level, as the merge order's is; one for each rig is the import in that rig. The entry above, with rig = "*", reaches both: in the city that runs the merge order with one such entry and no other, gc order show merge --json prints the entry's env for the instance of the HQ store ("rig": null) and for each rig's (merge:rig:<rig>). To turn the order on for some stores and not others, give FORGEJO_SCHEDULE in entries of their own: an entry with rig = "<rig>" for a rig, and one with no rig key for the HQ store, and leave it out of the entry of rig = "*". Do not turn it on before dismiss_stale_approvals is confirmed on main of the repository: a scheduled merge holds no head, and that setting is what keeps a head pushed after its approval from merging on the approval of the one before.
What it does with each answer
What pr merge says |
The order |
|---|---|
scheduled, already_scheduled, merged |
writes auto_merge=scheduled on the bead the first time, and removes auto_merge_trouble. Never cancels, and does not schedule again "to refresh" |
head_moved (3) |
nothing: the new head's bead comes from its Worker's close. When no bead of the pull request holds the pull request's head (every bead with its pr_url, except a bead made for the Operator (pr_event) or a review bead (review_head), is closed and none has the head as its gc.work_commit), someone pushed it and nobody is on it: one bead for the Operator |
not_open (4) |
nothing: the merge order's |
wrong_base (5), missing (7), foreign (8) |
one bead for the Operator for the pull request and head |
no_diff (6) |
nothing is closed on it alone. The count of cycles in a row goes in auto_merge_trouble, and the third is a bead for the Operator |
forge_refused (9) |
the order does not read the words of the refusal: Forgejo 17.0.1 answers a pull request that conflicts with its base 405 "Please try again later", and the word "conflict" is nowhere in it. It reads the pull request instead, with the code of pr state and its mergeable. not_mergeable is a conflict, or a conflict check the forge has not finished, or one that failed, and the forge's boolean does not say which, so the order takes the three as one: it is the rework order's trigger, and here it only counts toward the two hours (auto_merge_trouble with the reason not_mergeable, no bead for the Operator), and the next cycle asks again, so a check that was still running ends with the merge scheduled and the record gone. mergeable or draft is no conflict as far as the forge knows: one bead for the Operator, forge_refused. A pull request that is not open when read is left to the next cycle; one that cannot be read is retried, and counts toward the two hours |
| a 500 from the forge (it is still working out mergeability) | retried next cycle; the third in a row is a bead for the Operator |
| any other failure | retried next cycle; the run exits 1 |
Whatever the reason, a merge not scheduled for two hours is a bead for the Operator. auto_merge_trouble is JSON on the bead, {"reason", "cycles", "since"}: cycles counts the cycles in a row with the same reason, since is the first cycle of the streak.
A bead with no pr_url, or whose gc.work_commit is not a full commit, has nothing to schedule: the order counts it in auto_merge_trouble as no_head, and the third cycle in a row is a bead for the Operator (the merge order skips a bead with no pr_url, and the review order waits for a schedule, so nobody else would notice).
A bead for the Operator is the one the merge order makes for a pull request closed unmerged, made by the same code (operatorBead in order.go): open, assigned to the Operator, with the metadata pr_url, pr_event and pr_head, and work_bead. pr_event is stuck, no_worker, or the reason of the refusal (wrong_base, missing, foreign, forge_refused); pr_head is the head it is about. The order searches the store, in any status, for a bead with the same pr_event, pr_url and pr_head (for a bead with no pull request or no head, the same work_bead instead) and makes one only when there is none, so a head and an event get one, and a bead the Operator has closed is not made again. Only a bead it has just made is mailed, with --notify and --dedup <event>:<url>:<head>: the dedup holds until the Operator archives the mail, so a mail sent every cycle would come back when it was read. pr_event is what makes the merge order's scan of the old shape skip the bead, whatever its pr_url and its pull request's state, and what makes the head_moved check of this order skip it too. The Operator is $OPERATOR when set, else the one city-scoped agent named operator.
The run prints a line for each bead and exits 1 when something the next run may mend failed (the list, a write, the Operator, a failure of the command): it goes on to the next bead.
The trial before the switch-on
Nothing here has been tried on a real pull request. The trial needs the review account, and is run by the Operator, on a scratch repository on sarak.sh, before FORGEJO_SCHEDULE=on is set. It is in the description of the pull request that added this order.
Posting a review
gc forgejo pr review posts one review on one head of a pull request, as the account whose token the command uses, and checks that the forge recorded it as asked. The Reviewer of Landing posts its verdict through it, and the Operator's reviewing agents do until the Reviewer exists. A review is for one head: the command never reviews a head it was not given.
gc forgejo pr review [--json] --repo <worktree> --pr <url|number> --expect-head <sha> --event <APPROVED|REQUEST_CHANGES> [--body-file <path>]
--pr is named as pr state names it. --expect-head is the full SHA of the head the caller reviewed, and the review is posted on that commit (commit_id) and on no other. --event is APPROVED or REQUEST_CHANGES, in any case; any other event is a mistake in the command line, as the forge's COMMENT and its pending review are not verdicts. --body-file is read as pr open reads --summary-file, relative to $PWD, and its text is trimmed. An approval needs no body; a request for changes does. The request to the forge is POST /repos/{owner}/{repo}/pulls/{n}/reviews with {"event": …, "body": …, "commit_id": <expect-head>}. The client rules of pr state hold: only the forge's own 404 is missing, a 5xx, a timeout, a bad token or an answer the tool cannot read is an error (exit 1, nothing on stdout) and never an outcome, a --pr on another host is foreign and gets no request, and the token goes to the forge's host only.
What it does and prints
The command reads the pull request, the token's account and the pull request's reviews first, posts only when every check passes, and reads the reviews back after it posts. The checks run in the order of this table, and the first that fails decides.
| Case | Exit | outcome |
reason |
stderr says |
|---|---|---|---|---|
the --pr is on another host, or no pull request URL (no request is made) |
8 | refused |
foreign |
the --pr is not a pull request of the forge |
the event is REQUEST_CHANGES and the body is empty or blank (no request is made) |
11 | refused |
empty_body |
a request for changes needs a body |
| the forge answers "not found" in its own error object | 7 | refused |
missing |
the pull request does not exist |
| the pull request is merged or closed | 4 | refused |
not_open |
it is merged (closed), not open |
its head is not --expect-head |
3 | refused |
head_moved |
the head it has, and the expected one |
| the forge reports no head, or no author, or no login for the token | 1 | an error: nothing on stdout | ||
| the pull request's author is the account of the token (compared without regard to case) | 10 | refused |
own_pull_request |
the forge lets nobody review their own pull request |
the account's latest approval or request for changes is this event, on this head, not dismissed, and the forge counts it (official) |
0 | already_reviewed |
null | nothing is posted |
the same, and it does not stand as below for another reason than official (it is stale, say) |
12 | not_recorded |
not_recorded |
what is wrong; nothing was posted |
the same, and it is not official (the forge does not count it), not stale |
nothing yet: the command goes on to post the review again, as the rows below say | |||
| the forge took the review (200) and stored it as asked | 0 | posted |
null | |
| the forge refuses the review with a 422 (which it also answers for a review of the account's own pull request and for a request with no body, which the command has refused before it asks) | 9 | rejected |
forge_refused |
the forge's status and message |
| the forge took the review and stored it otherwise than asked, or did not list it, or left a request blocking an approval was to end | 12 | not_recorded |
not_recorded |
what is wrong; after a review that did not count was found, and the new one does not count either, both reviews' ids |
| any other answer to the review request, or reading the review back failed | 1 | an error: the review may be on the forge |
A review stands as asked when the forge's list, read after the post, has it with: the account of the token, the state asked (approved or request_changes, so not pending, not comment), the commit --expect-head, official true (the forge counts it for the branch protection), stale false and dismissed false; and, for an approval, no request_changes review of the same account that is official and not dismissed. Everything short of that is not_recorded, with the review as the forge stored it in review, or null if the forge does not list it. The command does not undo it, and it is no success: the caller reads review and decides. A caller does not post again on exit 12 without having read why, since a repeat posts another review of the same kind, except as the next paragraph says, where the command itself does it.
"Asked again" is decided by the account's latest approval or request for changes in the list, in the forge's order: when it is this event on this head and not dismissed, nothing is posted and the command prints already_reviewed. A review of another event, another head, another account, or a dismissed one is not that review, and the command posts. A comment or a pending review is neither: it is not a verdict.
A review the forge does not count is posted again. When that latest review is this event on this head, not dismissed and not stale, but official is false, the command does not say already_reviewed: nothing a caller can rely on is there, and nothing short of a new review mends it, since dismissing one takes a repository admin and a push is not the caller's to make. This is the case of an approval made before the rule on the base branch named the account (official is computed when the review is made, and the forge does not recompute it when the rule changes). The command posts the review again and reads it back as it always does. If the forge counts the new review, the outcome is posted and review is the new one. If the new review is not counted either (the rule still does not name the account), the outcome is not_recorded, exit 12, review is the new review, and the message names the earlier one too (the earlier review 255 of the same head did not count either). The old review stays in the forge's list as it was; the new one makes it no longer the account's latest. The same holds for a REQUEST_CHANGES review: the forge computes official for it by the same rule, so an account the rule does not name can end with an uncounted request for changes on the head, and the command posts that again in the same way. A review that is stale is not posted again: it stays not_recorded with nothing posted, as before. A caller whose account is never counted therefore posts one more review on each run, and each ends in exit 12.
With --json the command prints one object on one line, a refusal too, with exit status as above. Without it, it prints the outcome word and a refusal prints nothing on stdout. The object has these fields, always all of them; schema_version is "1", and a field is never removed, renamed or given another meaning without a new version.
| Field | Type | Meaning |
|---|---|---|
schema_version |
string | "1" |
outcome |
string | posted, already_reviewed, refused, rejected or not_recorded |
reason |
string or null | for refused, rejected and not_recorded: foreign, empty_body, missing, not_open, head_moved, own_pull_request, forge_refused or not_recorded |
state |
string or null | the pull request's state as the command read it: open, merged, closed, missing or foreign; null for empty_body, where it read nothing |
head |
string or null | the head commit the forge reported |
account |
string or null | the login of the account the token belongs to, null where the command stopped before it asked |
event |
string | what the command was asked to post: approved or request_changes |
review |
object or null | the review as the forge lists it, in the shape of reviews in pr state --json: for posted and not_recorded the one the command posted (null if the forge does not list it), for already_reviewed the one it found, and for not_recorded after a find, that one |
lifted |
list of numbers | for an approval that was posted: the ids of the account's earlier requests for changes that blocked before and do not after. Never null; empty otherwise |
forge_status, forge_message |
int or null, string or null | for rejected: the forge's answer |
Exit statuses 1 (a failure) and 2 (a mistake in the command line) are as in every command of the pack, and 3 to 12 are the refusals and failures above, one each, shared with pr merge where the reason is the same (3, 4, 7, 8, 9). A caller tells them apart by the exit status or by reason.
Does an approval of a newer head lift the account's earlier request for changes?
Yes, by itself, and the command dismisses nothing. This is question 7 of the city's docs/handoffs.md (section 4), settled from the source of Forgejo 17.0.1 (tag v17.0.1, commit 363f3dc30beef902b187af5a5244ff7af44901e6, on codeberg.org/forgejo/forgejo), not tried on sarak.sh:
- A request blocks while it is official and not dismissed, whatever its commit.
MergeBlockedByRejectedReviewcounts the reviews of the pull request with type reject,officialtrue anddismissedfalse, when the rule hasblock_on_rejected_reviews(models/issues/pull.go:923-939). A push does not end one:DismissApprovalReviewsdismisses reviews of type approve only (services/pull/review.go:443-449, called fromservices/pull/pull.go:395-408), so a request on an earlier head keeps blocking after the author's rework push. - A new approval or request clears
officialon every earlier review of the same account, in the same transaction that stores it:UPDATE review SET official=false WHERE issue_id=? AND reviewer_id=?(models/issues/review.go:424, for a review made fresh, and:454, for one made from the account's pending review), run for the types approve and reject, whether or not the new review is official itself.SubmitReviewis what the API'sCreatePullReviewcalls (routers/api/v1/repo/pull_review.go:432-554,services/pull/review.go:384-440). So the earlier request stays in the list asrequest_changes,officialfalse,dismissedfalse, and blocks nothing. - Dismissing takes a repository admin.
DismissPullReviewandUnDismissPullReviewcheckctx.IsUserRepoAdmin()first (routers/api/v1/repo/pull_review.go:1102-1105, routes atrouters/api/v1/api.go:1053-1054); the web form is behindreqRepoAdmin(routers/web/web.go:1451). An account that is no repository admin gets a 403 for a dismissal; whether the review account is one is not something the city's token can read.
So the command has no dismissal to make, and makes none. It checks the outcome instead: after an approval, any request for changes of the account that is still official and not dismissed makes the outcome not_recorded with the message that dismissing it takes an admin, which is what a forge that did not clear it (not Forgejo 17.0.1, by its source) would show; the id of each request the approval ended is in lifted. A request by another account is not the command's to lift or to report. What the source does not say is whether sarak.sh runs exactly the tagged source, and whether the review account is a repository admin, which the city's token cannot read: the trial in the pull request that added this command has the Operator run it.
How the forge answers, and what the tool reads of it
Read from the source of Forgejo 17.0.1: routers/api/v1/repo/pull_review.go (CreatePullReview, preparePullReviewType), services/pull/review.go (SubmitReview), models/issues/review.go (SubmitReview, IsOfficialReviewer), models/git/protected_branch.go (IsUserOfficialReviewer) and services/convert/pull_review.go. The test's fake forge answers as these functions do.
- Own pull request. An approval or a request for changes by the pull request's author answers
422("approve your own pull is not allowed", "reject your own pull is not allowed"). The command asksGET /userfor the token's account and the pull request for its author and refuses before it posts. - No body. A request for changes with a blank body answers
422("review event REQUEST_CHANGES requires a body"); an approval needs none. - Stored on
commit_id. The forge stores the review on the commit it is given, andstaleis true when that is not the head and the diff of the two differs (services/pull/review.go:390-413). A push between the command's read and the forge's post therefore gives a stored review on--expect-headthat is stale or not, by the diff; a stale one isnot_recorded. officialis whether the account may review under the rule on the base branch: the rule's approvals whitelist when it has one, write access when it does not (models/issues/review.go:259-288,models/git/protected_branch.go:176-203), computed when the review is made and only for approve and reject. An approval the rule does not count is stored withofficialfalse: the command calls itnot_recorded, and when it finds one already there it posts the review again (see "A review the forge does not count is posted again").- A pending review of the account is turned into the submitted review by the forge and keeps its id; the command identifies its review by the id the forge answers with.
- The list is read as
pr state --jsonreads it: every page, oldest first.
Commenting on a pull request
gc forgejo pr comment posts one comment on a pull request, as the account whose token the command uses. The Worker's note that a round of rework is done goes through it, and so does any other comment an agent leaves on a pull request: no agent calls the forge with curl for one.
gc forgejo pr comment [--json] --repo <worktree> --pr <url|number> --body-file <path>
--pr is named as pr state names it. --body-file is read as pr open reads --summary-file, relative to $PWD, and its text is trimmed; a body with nothing in it is a mistake in the command line (exit 2), refused before any request. The command reads the pull request first, so that a number which names a plain issue of the repository gets no comment, and then makes the request POST /repos/{owner}/{repo}/issues/{n}/comments with {"body": …}, the forge's way to comment on a pull request. A comment is not a review: it carries no verdict, blocks nothing and belongs to the pull request, not to a head of it, so a pull request that is merged or closed takes one too. The client rules of pr state hold: a 5xx, a timeout, a bad token or an answer the tool cannot read is an error (exit 1, nothing on stdout), and the token goes to the forge's host only.
It prints the comment's URL. With --json it prints one object on one line: schema_version ("1"), id and url. A forge answer that is not a 201 or names no comment is a failure, not a success: the comment may be there, and the command does not say it is. The exit status follows the other commands: 0 posted, 1 a failure, 2 a mistake in the command line, 7 the pull request does not exist and 8 --pr is no pull request of this forge (a refusal prints nothing on stdout, with --json too).
The merge order
Every two minutes the merge order settles the beads of its store that carry a pull request. A rig's store has an instance, and so has the HQ store. The run is order merge, a subcommand of the Go tool and not a gc command, with its tests in Go; forgejo/assets/scripts/merge.sh, the order's exec, is the one line that starts it, as go tool -C "$PACK_DIR" forgejo order merge.
A bead has one of two shapes, and the order handles both:
| Shape | Listed by | The pull request merged | Closed unmerged, or not on the forge | Open, or on another forge |
|---|---|---|---|---|
open bead with a pr_url: a Worker's hand-over to the user |
gc bd list --has-metadata-key pr_url --status open,in_progress,blocked |
sets gc.work_outcome=shipped, then gc bd close --force --reason "Pull request merged: <url>", whoever holds the bead; no mail |
assigns the bead to the Operator, mails it with --notify ("Pull request closed unmerged: ", or "Pull request not found: "), then sets pr_closed=<url>, so a pull request is handed over once; a pr_closed that is the URL is skipped |
open: nothing. Foreign: one line on stderr, merge: <bead>: <url> is not a pull request of this forge, skipped, and the run does not fail |
closed bead with merge_result=pull_request: a bead closed when its pull request opened |
gc bd list --has-metadata-key merge_result --status closed, then the beads whose merge_result is pull_request |
writes merge_result=merged and merged_sha=<the merge commit> on every bead of the pull request, and mails the Operator once for the merge |
writes merge_result=closed on every bead of the pull request (merge_result=missing when the forge does not have it), makes one bead for the Operator and mails it once for the pull request |
the same |
A bead of the old shape is closed at the merge with no mail, as it always was. A bead of the new shape is settled once: the order lists only pull_request, so a bead that carries merged, closed or missing is left alone. Beads of the one pull request are the beads that carry its URL, a work bead and each rework bead; a pull request is read from the forge once in a run, for the beads of both shapes.
Who the mail is from. Every mail an order of this pack sends, and of the roles pack, passes --from controller: without --from, and with none of GC_SESSION_ID, GC_ALIAS and GC_AGENT in an order's environment, gc mail send writes human, the user's own mailbox. At gc's pin a --from must be a live session, a configured named session, human or controller, so an order cannot name itself: the mail log reads controller → operator, and the subject says what it is about.
The mail for a merge goes to the Operator with --notify and --dedup merge:<url>, before the records are written: a bead leaves the order's list when its record is written, so nothing else says the Operator was not told. A mail that fails leaves every bead of the merge for the next run; a record that fails leaves that bead, and the dedup key keeps the next run from mailing the merge again unless the Operator archived the mail in between.
The bead for the Operator (one per pull request that closed unmerged or is gone, the design's P7) is made before the beads are written: the order searches the store, in any status, for a bead with pr_event=closed and the pull request's pr_url, and makes one only when there is none, so a run that failed after making it makes no second. It is open and assigned to the Operator, titled "Pull request closed unmerged: " (or "Pull request not found: "), with the metadata pr_url and pr_event=closed, and the beads of the pull request in its description. The mail (--notify, --dedup closed:<url>) names it. A bead that carries pr_event is the order's own: the scan of the old shape skips it, whatever its pr_url and its pull request's state. So does a bead that carries review_head, a review bead of the review order or of the Operator's script: it is open and has a pr_url too, and the order would otherwise close it as shipped, or hand it to the Operator, when its pull request merged or closed.
History is not news: the baseline. A store the order has never run in holds beads of pull requests that ended before the order came: rexcity's first run, on 2026-11-12, found 29 that another city had closed days before, and told the Operator of each. The order tells such a pull request from one of its own time by the run it first sees it in. The first run in a store is its baseline: it finds no closed bead with pr_event=baseline (gc bd list --all --metadata-field pr_event=baseline). In that run, a pull request of the closed shape that has ended (merged, closed unmerged, gone) is history: its beads get merge_result=merged (with merged_sha), closed or missing as it ended, one line on stderr says so, and no bead or mail is made. At the end of the run the order makes the marker, one bead titled "Merge order: first run in this store", closed, whose description says how many it found of each kind; every later run finds it and tells the Operator of each pull request that ends. What this cannot hide: a pull request that is open at the baseline is not settled by it, so when it closes unmerged in a later run the Operator is told; a pull request the baseline run could not read is left as it is and is news when it ends, so a forge that fails at the baseline costs one bead that lists them (below) and never a silent settlement; and a marker that cannot be made fails the run, and the next run is a baseline again. What it does hide is a pull request that closed unmerged in the minutes before the order's first run in a store, which no earlier run could have told the Operator of. It also depends on the marker staying: it is an ordinary closed bead, and if a cleanup or compaction of closed beads, or a person, removes it, the next run is a baseline again and settles quietly whatever ended since the previous run, so leave it closed and in the store. The old shape is not history: an open bead with a pr_url is a bead somebody is waiting on, and is handed over whenever its pull request is found closed.
A 404 is not "closed". The forge answers "not found" in its own error object for a pull request it does not have; a "not found" without that object (a proxy, a load balancer, a forge that is restarting) is an error and has always been. But Forgejo answers the same "not found" for a pull request in a repository the token cannot read, so before the order calls a pull request gone it reads the repository (GET /repos/<owner>/<repo>): when that answers, the pull request is missing; when that is "not found" as well, or fails, the pull request is unread (merge: <bead>: cannot read the state of <url>: …), the run fails, and nothing is settled on it. A pull request that is missing is recorded as merge_result=missing on its beads, never closed, which means a person closed it unmerged. For a bead of the closed shape that is news (in a run after the baseline), the Operator's bead is titled "Pull request not found: " as before. gc forgejo pr state is unchanged: it prints missing on the forge's own "not found" and does not read the repository.
One run cannot flood the Operator. A run that would tell the Operator of more than three pull requests of one kind (merged, closed unmerged, not found) tells it in one: for closed unmerged and not found, one bead, assigned to the Operator, with pr_event=closed_batch or missing_batch and pr_batch=<a hash of the URLs>, whose description lists each pull request with its beads, and one mail that names it (--dedup <event>:<hash>); for merges, one mail that lists them. Up to three, each has its bead and mail as before. The same holds for the old shape (open beads that carry a pr_url): in a run that finds more than three of them whose pull requests closed unmerged, or more than three whose pull requests are gone, the order still assigns each of those beads to the Operator and records its pr_closed, but sends one mail for the kind, which lists the beads with their pull requests (--dedup handover:<hash of the URLs>), in place of one mail for each. Up to three of a kind, each bead has its own mail as before. If a bead's update fails after the mail, the bead is left for the next run, which hands over what remains, with a mail of its own. The bead is made once for one set: a run that fails after making it finds it by pr_batch and makes no second; the pull request whose records were not written is, in the next run, one of a kind that has only itself and gets a bead of its own, which is the one duplicate a failed write can cost.
The beads an earlier version recorded as closed. The 29 beads of rexcity that carry merge_result=closed for pull requests the forge does not have are corrected by the order itself: its baseline run rereads the beads recorded as closed (gc bd list --metadata-field merge_result=closed --status closed), reads each pull request once, and writes merge_result=missing on those the forge does not have, with no mail. A bead whose pull request did close, or merge, or cannot be read, is left as it is. Only the baseline run does it, so a later run makes no request for a settled bead. The baseline run of every store is the first run after the version that has it is imported, since no earlier version left the marker.
What it reads. The pull request is read the way pr state reads it: the same resolution of --pr (the forge named by FORGEJO_URL, else the origin remote of the order's repository), the same token handling (FORGEJO_TOKEN_COMMAND or FORGEJO_TOKEN_FILE, sent to the forge's host only), the same missing and foreign, and the same refusal of a merged pull request for which the forge names no merge commit. It makes the one request for the pull request, and none for the checks or the reviews. The order's repository is the first of GC_RIG_ROOT, GC_CITY_PATH and GC_CITY that is set, which is how the supervisor starts an order of a rig or of the city; GC_RIG names the rig in the Operator's mail ("the HQ store" for the city's instance); OPERATOR names the Operator when it is set, else the one agent named operator that no rig owns, looked up only when something has to be handed over; GC_BIN names gc, which otherwise is the one on PATH. gc runs in the directory the order was started in, where it finds the store.
When it fails. The order tries every bead, reports each that it could not settle on stderr as merge: <bead>: <what>, and exits 1. A foreign pull request is no failure. When the Operator cannot be resolved while a bead has to be handed over, the run ends at once, as it did. Nothing is half-done in a way the next run cannot finish, since each write is one gc call and each bead's marker (pr_closed, or merge_result) is the last write that concerns it.
How a change to the order reaches a running city. The apply order fast-forwards the city to the merged import, and the order's next run uses the new pack. Each run is its own process: go tool -C "$PACK_DIR" builds the tool from the files of one pack directory and runs the result, so a run that began before the swap goes on with the code it was built from, and a run that begins after it builds the new. gc's pack cache holds a checkout of each locked commit (docs/shell.md, section 5, read it there), so a run sees the old files or the new, never a mixture. The two versions read and write the same markers (pr_closed, gc.work_outcome), so a run of one after a run of the other settles what is left, and putting the old import back loses nothing; a bead of the new shape that was recorded stays recorded, and one that was not is waited for until the order handles it again. If the tool cannot be built where the order runs (a Go older than the go line of go.mod, or a pack directory that is damaged), go tool prints the compiler's errors and exits non-zero before anything is read or written: the run fails with them on stderr and settles nothing, and the next run tries again. A city with no go on PATH fails the same way, with merge: go is not on PATH.
The checks order
Every two minutes the checks order tells the Operator when the checks of an open pull request's head settle, so that nobody polls the forge for it. A rig's store has an instance, and so has the HQ store, as for merge. The run is order checks, a subcommand of the Go tool, with its tests in Go (checks_order.go); forgejo/assets/scripts/checks.sh, the order's exec, is the one line that starts it.
For each bead of its store that follows a pull request it reads the pull request, and when that is open, the checks of its head as pr state --json reads them (checks.state). Settled means success or failure: no status is pending and no run for the head is waiting, running or blocked. A head whose checks are not_started, pending or none is left, and so is a pull request that is merged, closed, gone or foreign (the merge order's). When the head is settled and the order's record of the bead is not that head with that state, it mails the Operator, with --from controller --notify:
| subject | CHECKS <bead>: <success|failure> <pr_url> |
| body | the pull request, the store, the head's SHA, and one line - <context>: <status> for each commit status, then the count of workflow runs by status |
--dedup |
checks:<bead>:<sha> |
Which beads. The two shapes of the merge order: open, in progress or blocked beads with a pr_url (a Worker's hand-over), and closed beads with merge_result=pull_request. A bead that carries pr_event (the order's own, for the Operator) or review_head (a review bead, which is not work that follows the pull request) is skipped. A pull request is read once in a run, and a head's checks once, for all the beads that carry them; each bead has its own mail, since the subject names the bead.
What it remembers. The last head and state it settled for each bead, in checks-<rig>.json (checks-hq.json for the HQ store) under GC_PACK_STATE_DIR, else $GC_CITY_RUNTIME_DIR/packs/forgejo, else <city>/.gc/runtime/packs/forgejo; written atomically, by a temporary file and a rename, and with the beads that left the list forgotten. A new head is a new mail, whatever its state. The same head whose checks run again and change state (from failure to success, or the other way) is a new mail too, but its dedup key is the same as the first mail's: while the Operator has not archived the first, gc mail send suppresses the second and exits 0. The order sends with --json, reads the answer (count 0 with already_done is a suppressed send), and records a bead only when its mail was sent. So the change is held back, not lost: each run asks for it again (the log says held back), and the run after the Operator archives the first mail delivers it. A head whose state changes twice while the first mail is live, back to the state that mail told, owes nothing. The record is written after the mail is sent, so a mail that fails is tried again by the next run; a record that fails to write fails the run, and the next run's mail is held back by the dedup key until the Operator archives the first, which makes that one head's mail a second time, once. A state file that does not decode fails the run with nothing mailed: it is not taken for an empty one.
One run cannot flood the Operator. More than three beads owed in one run (the first run in a store, or the forge back from an outage) are one mail, CHECKS: <n> pull requests settled (<store>), that lists each bead with its state, pull request and head (--dedup checks:batch:<hash of the bead:head pairs>), and every one of them is recorded.
What it needs. The same as merge: FORGEJO_TOKEN_FILE in the order's environment (exec orders do not receive workspace.env, so a city gives it with an [[orders.overrides]] entry named checks, as for merge and schedule), go, git and gc on the supervisor's PATH. The order's repository, GC_RIG, OPERATOR and GC_BIN are read as the merge order reads them. It fails, with every bead tried, on stderr as checks: <bead>: <what>, when a pull request or its checks cannot be read, a mail cannot be sent, or the Operator cannot be resolved.
The Reviewer
The Reviewer, forgejo.reviewer, is the pack's agent for the review of a pull request: one for each rig that imports the pack and one for a city that imports it at the city level (the city's Reviewer, below), a pool that is empty until a review bead is routed to it, one session at a time unless the city allows more (more than one Reviewer, below), on an acp box, in the city's permission mode (Permission mode). It works one review bead into one verdict on the forge, as the Worker works a bead into a pull request, and its formula mol-forgejo-review is one step of five parts that it holds from the claim to the close. It is a port of rexcity's mol-forgejo-pr-review less its wait for the checks: no agent waits, and a review starts only once the head's checks have completed, whatever their result.
The review bead carries three keys, pr_url, review_head (the full SHA the review is for) and work_bead (the bead the pull request answers: it is the requirement). Its labels are service and review, and it carries review_round as well, which the review order puts there (row L15 of the city's docs/handoffs.md). The Reviewer writes only on this bead, and mails the Operator twice over: its verdict (REVIEW <work bead>: <pass|fail|void> <pr_url>, Part 5) and a halt. It never changes the work bead, never pushes, never merges and runs no gc command that changes a city or a rig.
| Part | What it does |
|---|---|
| 1 | Primes, derives the review bead from the input convoy, checks the three keys, and goes on to Part 5 when review_verdict is already there. Otherwise it takes the bead with gc forgejo review take, which writes its claim on the bead and voids the bead when another review bead holds the same head (see more than one Reviewer) |
| 2 | Makes a clone of its own under its work directory, fetches refs/pull/<n>/head, reads the pull request with gc forgejo pr state --json, and voids the bead (review_verdict=void, review_reviewed the head the bead named, a note, nothing posted) when the pull request is not open or its head is not review_head. It halts when the checks have not completed. When the account of its token has a review of the head on the forge already, it goes straight to Part 5 |
| 3 | The review itself, as the Operator's reviewing agents make it: the work bead and the pull request's description (jq -r .body on its own), the whole diff, REVIEW.md, AGENTS.md, CLAUDE.md and README.md read from the target branch and never from the pull request, the head merged into the current target in the clone (a pull request that does not merge cleanly gets REQUEST_CHANGES saying it needs a rebase), what the repository's workflows run, with the city's variables removed (env -i), and the head's own checks, whose failing log it reads and reports: a failed check is never approved |
| 4 | Reads the pull request once more, voids when the head moved, asks review take again, looks for a review of the head by its own account already on the forge, and posts the review with gc forgejo pr review --expect-head: APPROVED, or REQUEST_CHANGES with the findings as the body |
| 5 | Reads its own review of the head back from the forge and writes review_verdict (pass for an approval, fail for a request for changes), review_reviewed (the head) and review_url with a note, then mails the Operator REVIEW <work bead>: <verdict> <pr_url> (--notify, with --dedup review:<review bead>:<head> so that a restart does not stack a second), closes the bead with the work outcome no-op and the step as passed, and exits. A failed mail halts it with the bead still open |
A restart posts nothing twice. The verdict is written only after the review is on the forge, and Part 5 reads it from the forge, so a Reviewer that died between the post and the write finds its own review of the head (Part 2) and records that one. gc forgejo pr review also posts nothing for the same event on the same head by the same account, unless that review is one the forge does not count, which it posts again.
What it needs of the city. gascity-root's pack.toml patches the Reviewer of every rig: the acp provider, the model and effort the pin check demands of every agent (scripts/check-pins.sh fails an agent with neither), max_active_sessions = 1, and the review account's token file as FORGEJO_TOKEN_FILE (or a FORGEJO_TOKEN_COMMAND that prints it, which a city whose workspace sets its own command must use, as above), which no other agent's environment names (they keep the city's, from workspace.env; an agent's env wins over it):
[[patches.agent]]
rig = "*"
name = "forgejo.reviewer"
provider = "acp"
max_active_sessions = 1
option_defaults = { model = "claude-opus-5-5", effort = "high" }
env = { FORGEJO_TOKEN_FILE = "/Users/mikluko/.config/gascity-root/forgejo-review-token" }
An import of this pack that carries the Reviewer, without that patch, fails scripts/check-pins.sh for each rig, so the patch goes in the pull request that bumps the import.
How a review bead reaches it is not settled: the formula is poured by gc sling <rig>/forgejo.reviewer <bead>, which routes the bead and starts the workflow. A review bead that is only assigned to the Reviewer has no workflow behind it, and the Reviewer's prompt then has it hand the bead to the Operator (--assignee roles.operator --status open), mail the Operator that it was assigned and not slung, and only then run gc runtime drain-ack: gc refuses the acknowledgement of a session that still holds a bead it claimed, which left the first such session up and holding the rig's one seat (gascitypacks-imy). The Reviewer is a pool and no named session, so a bead routed to it wakes a session the way a bead routed to the Worker does, and no assignee string has to wake a named one; the review order slings the bead.
What is Claude Code's, and what is not. The formula is plain text with gc, git, curl and jq commands, and an agent that runs commands and reads a step through gc bd show can follow it with another model or another ACP adapter. The parts that are Claude Code's own are in the city's provider and patch: permission_mode, model and effort are options the claudeacp adapter takes, and a different adapter takes its own; and the size of the step, which tests/reviewer.sh keeps under the 28000 characters that a Bash call of Claude Code shows inline (its limit is 30000).
What is not there yet. The check of the review bead's schema, row L7, does not exist: Part 1 marks the place and checks the three keys by hand.
Its clone stays under its session's work directory, .gc/agents/<rig>/forgejo.reviewer-<n>/review-<bead> (the city's, .gc/agents/forgejo.reviewer-<n>/review-<bead>), after the review, as the Reviewer removes nothing with rm -rf; the Operator clears the old ones. Before the Reviewer was a pool the directory was .gc/agents/<rig>/reviewer, and the clones in it are left where they are.
More than one Reviewer
A rig's Reviewer is one session by default, and it is the queue: a review takes minutes (the clone, the checks, the whole diff), so the pull requests that wait for one session wait in a line. The pack's default stays one, and a city may allow more.
What makes it safe. Everything a review keeps belongs to the session or to the review bead, never to the rig:
- The clone and the scratch files. The work directory names the session,
.gc/agents/<rig>/forgejo.reviewer-<n>(work_dirends in{{.AgentBase}}, as the Worker's does), and the clone, its.body.mdand its.diffare named for the review bead,review-<bead>, inside it. Two sessions share no directory, and one session that reviews two beads one after the other shares no file between them. The formula writes nowhere else, and names no fixed path: the/tmp/rexcity-review-state.shthat a review of rexcity sourced is a file of rexcity's own review formula (mol-forgejo-pr-review, which this one is a port of), and this formula has no such file. What was fixed for the rig was the work directory,.gc/agents/<rig>/reviewer, which every session of the rig started in. A repository whose tests a review runs may keep fixed paths of its own, which are that repository's to make safe. - One session for one review bead.
gc hook --claimclaims the step bead with a compare-and-swap on its assignee, so two sessions cannot hold one step, andgc slingrefuses a bead that already has a live workflow unless--forceis given. - One review for one head of one pull request. Two review beads for the same
pr_urlandreview_headare two beads and two workflows, and nothing in gc ties them.gc forgejo review takedoes: a session writes its claim on its own bead (the statusin_progress,review_step,review_claimed), reads the claims of the review beads in progress for the same head, and reviews only when its own is the earliest (the lower bead id breaks a tie). The other session writesreview_verdict=voidon its bead with a note naming the bead that holds the head, and the formula closes it with nothing posted. The claim is written before the others' are read, so two sessions that begin together nearly always agree: the claim's time is read from the session's own clock before the write that records it, so two sessions can each miss the other's claim for about the length of onegc bd update, and both take. The formula asks again in Part 4, before it posts, for a claim that came in during the review. That second ask does not see a rival that has already closed with its verdict (a closed bead holds nothing), so Part 4 then looks for a review of the head by the Reviewer's own account on the forge, as Part 2 does, and records that one instead of posting a second. A bead that halted (open again), a closed one, and one with a verdict hold nothing. A review of an older head of the same pull request is void by Part 2 (the head moved) and by Part 4's second read, as before. - The forge.
gc forgejo pr reviewposts nothing for the same event on the same head by the same account twice (a review the forge does not count is posted again, and then it is the new one that is read back), and the review is read back from the forge before the verdict is written, as before.
How a city sets the number. The Reviewer is a pool of one session, max_active_sessions = 1 in its agent.toml, with min_active_sessions = 0 (it starts empty and is started by the beads routed to it). The number is the agent's max_active_sessions, which a city sets by patching it, for the rig's Reviewers and the city's own at once with rig = "*" (the patch of the city's Reviewer already has one):
[[patches.agent]]
rig = "*"
name = "forgejo.reviewer"
max_active_sessions = 3
The pack has no [[named_session]] for the Reviewer for that reason: gc clamps the demand of a template that backs an on_demand named session to one session ("An on_demand named-session backing template is a singleton", cmd/gc/build_desired_state.go), however high the agent's max_active_sessions, so a pack that kept one would make the number inert. The agent is a pool, and a bead is routed to it as to the Worker's: gc sling <rig>/forgejo.reviewer <bead>.
What else a city raises with it. The agent's cap is one of three, and the lowest decides:
- The rig's cap,
max_active_sessionsof its[[rigs]]entry, which counts every agent of the rig: its Workers, its control dispatcher and its Reviewers. A rig with a cap of 6 for 4 Workers, the dispatcher and one Reviewer has no room for a second Reviewer until the cap goes to 7. - The city's cap,
max_active_sessionsof[workspace], which counts every session of the city, the rigs' and the city's own agents. - The agent's, above. The city's own Reviewer, which has no rig, is held by the city's cap and its own.
What each session costs. Every session of every agent in a city draws on one account's usage limit: a Reviewer that runs on Opus at high effort reads a whole change and runs its checks, and that is the most expensive thing a pull request costs. N Reviewers on N beads spend that N times as fast, and nothing is saved in tokens: the queue is shorter and the limit is reached sooner. Two Reviewers is the first step, and the number to start from; a city sets more once it has seen what two cost.
The city's Reviewer
The city's own repository, gascity-root, is no rig, so a rig's Reviewer cannot review it. A city that imports the pack at the city level gets a second Reviewer pool from the same agent (it has no scope, as the Worker has none), forgejo.reviewer with no rig. It runs the same formula, mol-forgejo-review, through the same tool, gc forgejo pr state and pr review, and is held to the same rules. It never merges: a merge of gascity-root is applied to the live city within minutes and can restart sessions, so the Operator keeps the merge.
What differs for a repository that is no rig:
| A rig's Reviewer | The city's Reviewer | |
|---|---|---|
| Its beads | the rig's store | the HQ store (the review bead is routed to it as gc sling forgejo.reviewer <bead>, with no rig in its name) |
| The repository, and its target branch | the rig's checkout, GC_RIG_ROOT, names it by its origin, and pr state names the target branch (base) |
the city's checkout, GC_CITY_PATH, which has no rig: Part 2 reads ${GC_RIG_ROOT:-$GC_CITY_PATH}. A pull request that is not of that origin is refused (NOT THIS REPOSITORY'S PULL REQUEST, a halt); base is the target as for a rig |
| Where it clones | .gc/agents/<rig>/forgejo.reviewer-<n>/review-<bead> |
.gc/agents/forgejo.reviewer-<n>/review-<bead>: the agent's work_dir leaves the rig segment out when Rig is empty, as the Worker's does |
Where REVIEW.md and the rest come from |
REVIEW.md, AGENTS.md, CLAUDE.md and README.md of the target branch, read from the clone with git show, never from the pull request |
the same. gascity-root has no REVIEW.md: its AGENTS.md carries what the Operator's reviewing agents were told by hand, and the formula reads it from the target |
| What it runs on the merge result | what the workflows of the merged tree run, and the Quality Gates of its AGENTS.md |
the same: the steps of gascity-root's .forgejo/workflows/test.yaml, and the three gates of its AGENTS.md, each with --city "$CLONE" (a gc command on the clone without it answers for the live city, whose files gc import rewrites) |
The formula has one hook for all of this, in Part 3: what the target's own AGENTS.md or CLAUDE.md names as its quality gates, run as written on the merge result by a Reviewer of any repository, provided the command writes nothing outside the clone. The rules about scratch files and rm of the Reviewer's formula (gascitypacks-mkr) are the one agent's, so they hold for the city's Reviewer without a second text.
What gascity-root has to say. Nothing new, where it already patches the rigs' Reviewer as above does: a [[patches.agent]] entry with rig = "*" reaches the city's agent of that name as well as every rig's (resolved in a throwaway city: the city's forgejo.reviewer and the rig's both come out with the acp provider, max_active_sessions = 1, the pinned model and effort, and FORGEJO_TOKEN_FILE set to the review account's token file, in these two agents' env and no other's, and scripts/check-pins.sh passes). A city that wants the city's Reviewer to differ, another model or another token, adds an entry of its own with no rig key, which wins over the * one for the city's agent alone:
[[patches.agent]]
name = "forgejo.reviewer"
option_defaults = { model = "claude-opus-5-5", effort = "high" }
env = { FORGEJO_TOKEN_FILE = "/Users/mikluko/.config/gascity-root/forgejo-review-token" }
A city whose patch names a rig, and not *, has the city's Reviewer fail scripts/check-pins.sh until it patches it.
tests/reviewer.sh resolves the agent in a throwaway city with a rig, as the rig's and the city's, once as the pack ships it and once with a city's patch of three sessions, renders the prompt of each, renders the work directory for two sessions, runs the lines of Part 2 that compare a pull request with the origin of the checkout the Reviewer reads, compiles the formula, checks its safety rules in its text (no push, no merge, no write to a bead but the review bead and the step, the token read only inside an Authorization header, every git command in the clone) and its order (the verdict before the close, the close before the step's close, nothing after the acknowledgement), and runs the lines that read and write the bead against a stub gc and curl.
The review order
The review order is what starts a review. Every three minutes it looks, in its own store (a rig's, or the HQ store), for the beads that hand a pull request over, and for each pull request whose head's checks have completed it makes the review bead of that head and slings it to the rig's Reviewer, once. It is the first half of what a script in the Operator's session did: it waits for no check, and no agent waits for it. The run is order review, a subcommand of the Go tool, with its tests in Go; forgejo/assets/scripts/review.sh is the one line that starts it. It is built and not switched on.
The conditions, taken in this order, the cheapest first. A bead that fails one is left for the next run, with a line on stderr:
- The rig has a Reviewer.
<rig>/forgejo.revieweris ingc agent list, orFORGEJO_REVIEWERnames one. The HQ store's instance looks for none by name: the city's own Reviewer,forgejo.reviewerwith no rig (row L16, above), is asked for only whereFORGEJO_REVIEWER=forgejo.revieweris set for that instance. Without it the instance logs that and does nothing. - The schedule order has marked the bead,
auto_merge=scheduled(rule 6 of the city'sdocs/handoffs.md): an approval that came before the schedule would have nothing to start the merge. A bead whose merge cannot be scheduled for two hours is the schedule order's bead for the Operator (stuck); this order asks for no review of it meanwhile. This condition is a setting, below. - The pull request is open, and the bead is the head's bead. A merged, closed or missing pull request is the merge order's; a foreign one is skipped with a line. In the new shape the bead holds the head it handed over (
gc.work_commit), and the order takes it only while that is the pull request's head: a bead of an earlier head is not asked about a later one, whose own bead comes from its Worker's close. - The head's checks have completed, whatever the result:
checks.completedofpr state --json, which issuccess,failureornone(nothing to wait for). Apendinghead is left. A head stillnot_startedis left too, and the order writes the first sighting on the bead asreview_wait({"head","since"}); after half an hour of its own (reviewStartLimit) it makes a bead for the Operator,pr_event=checks_not_started, once per pull request and head, by the same code as the schedule order's (operatorBead), and mails it with--notify. A runner that is down, or a workflow that never triggers, is the usual cause.review_waitis removed once the review of the head is asked for, whether this run made the bead, slung one it had made, or found one made by another actor. - There is no review bead for that pull request and head, in any status:
gc bd list --allbypr_urlandreview_head. The Operator's script looks the same way before it makes one, so neither asks for a head twice. A restarted order, a second instance and a push that changes nothing make no second bead.
The review bead is what the Reviewer's formula reads, and what the beads made so far carry: the title Review <pull request URL> at <head, 7 characters>, the labels service and review, and the metadata pr_url, review_head (the full SHA), work_bead (the bead that hands the pull request over) and review_round, the count of the review beads of the pull request, any status, plus one. The order adds one key, review_made_by=review-order. It makes the bead unassigned, reads it back (gc bd show) and checks the labels and every key (this stands where the handoff check of row L7 will; it does not exist yet), and only then runs gc sling <rig>/forgejo.reviewer <bead>, which routes it and starts mol-forgejo-review. A bead that fails the check is left, unslung, and fails the run. A bead the order made and could not sling is open with no gc.execution_routed_to: the next run slings it, and makes no second one. A bead it did not make is slung too, but only once it has been left: a review bead of the head (pr_url and review_head) that carries the labels service and review, is open, has no gc.execution_routed_to and no assignee, does not carry the label parked, and was created ten minutes ago or more (reviewStrandedAfter, created_at). A parked bead is held back on purpose, as the city's rule has it, and the order does not override the hold. A bead of the Operator's script that is open and not yet slung is younger than that and is left alone, since a second sling would race the script's; one the script never slung (gascitypacks-4oxn, six hours without a review) is slung by the first run after it turns ten minutes old, and the log says so. A bead with no created_at is never taken. A bead the order leaves is logged with the reason it was left: too young, not labelled service and review, parked, or of unknown age.
Both shapes of a handover. The order tells them apart by what the bead is:
| Shape | The bead | Its head | The schedule condition |
|---|---|---|---|
| new | closed, merge_result=pull_request, with pr_url and a full gc.work_commit (gc bd list --status closed --metadata-field merge_result=pull_request) |
the bead's own, which must be the pull request's | holds: auto_merge=scheduled |
| old | open, with pr_url, and none of merge_result, pr_event (a bead for the Operator), review_head or the labels service and review (a review bead), and no worker_session (a Worker unsets it at the handover, and sets it again when it takes the bead back for rework) (gc bd list --status open --has-metadata-key pr_url) |
the pull request's, read from the forge | never met: the schedule order acts only on the new shape, so a city that keeps the condition reviews no pull request of the old shape |
Today's rigs hand over in the old shape. Until rows L8 and L11 change the Worker's hand-over, the order starts nothing in today's city unless the condition is turned off.
Turning it on
Two variables in the order's environment, which is the order's [[orders.overrides]] entry in the city's city.toml, beside FORGEJO_TOKEN_FILE (exec orders do not receive workspace.env):
| Variable | Effect |
|---|---|
FORGEJO_REVIEW=on |
the switch. Anything else, including no variable, is off, and with it off the order prints one line and exits 0 before it reads a bead, asks the forge for anything or calls gc |
FORGEJO_REVIEW_NEEDS_SCHEDULE=off |
drops condition 2, the schedule. Anything else, including no variable, keeps it: a typo keeps the stricter rule |
With the schedule order on (FORGEJO_SCHEDULE=on, which also needs the forge's setting of decision 11):
[[orders.overrides]]
name = "review"
rig = "*"
env = { FORGEJO_TOKEN_FILE = "/path/to/token", FORGEJO_REVIEW = "on" }
While the schedule order is off, as it is today, the same entry with FORGEJO_REVIEW_NEEDS_SCHEDULE = "off" as well. A review is then asked for every pull request whose head's checks have completed, of either shape, with no scheduled merge behind it: the Reviewer posts its verdict, and the user merges. Without that variable a city that has not switched the schedule order on has no bead the review order will take.
Entries per rig work as for the schedule order: an entry with rig = "<rig>" turns it on there only, and rig = "*" reaches the HQ store's instance too, which does nothing without FORGEJO_REVIEWER. To review the city's own pull requests, give the HQ instance a separate entry, with no rig key and FORGEJO_REVIEWER = "forgejo.reviewer" in its env, beside the rig = "*" one. The order also takes FORGEJO_REVIEWER (an address, for a pack bound under another name), OPERATOR and GC_BIN. It needs the token (FORGEJO_TOKEN_COMMAND or FORGEJO_TOKEN_FILE) to read the pull request and its checks, and writes nothing to the forge.
What it prints, and how it fails
A line for each bead it leaves or acts on, review: <bead>: <what>, on stderr. It tries every bead, exits 1 when one could not be settled (the list, the forge, a write, the Operator, the check or the sling), and exits 0 otherwise.
The trial before the switch-on
Nothing here has been tried in the live city. The trial is the Operator's, on one rig, with no schedule order:
- Give that rig's instance the entry above, with
rig = "<rig>",FORGEJO_REVIEW = "on"andFORGEJO_REVIEW_NEEDS_SCHEDULE = "off", and check thatgc order show review --jsonprints theenvfor it. - Stop the Operator's own review script, so that two do not run.
- Have a Worker open a pull request in that rig, and wait for its checks.
gc order run review --rig <rig>runs the order once and its stderr says what it left and why; or wait for its cooldown. - Look for the review bead:
gc bd list --label review --metadata-field pr_url=<url>. It has the five keys and the labels, agc.execution_routed_tothat is the Reviewer, andreview_round=1; the Reviewer's session starts on it and runsmol-forgejo-review. No mail "assigned, not slung" arrives. - Run the order again: no second bead. Push to the pull request: once its checks complete, a second bead for the new head,
review_round=2, and the first is void when the Reviewer reaches it. - Open a pull request whose workflows cannot start (stop the runner): after half an hour, a bead
Checks not started: <url> at <head>for the Operator, and one mail. - When all of it holds, give the other rigs the entry. Taking
FORGEJO_REVIEW_NEEDS_SCHEDULEoff the entry comes after the schedule order has had its own trial.
The city's Worker
The Worker has no scope, so a city that imports roles at the city level gets a Worker pool of its own, roles.worker, beside each rig's <rig>/roles.worker. It works the beads of the HQ store, in worktrees of the city repository under <city>/.gc/worktrees/worker, and opens its pull requests on that repository's default branch. The city directory stays on origin/main, where the apply order keeps it.
- Route an HQ bead with
gc sling roles.worker <bead>, from outside a rig's directory: inside one, gc reads the bare name as that rig's Worker.default_sling_targetis a[[rigs]]key, so the HQ store has none. - The pool runs 0 to 2 sessions, as a rig's does. A
[[patches.agent]]entry namedroles.workerwith norigkey changes the city's pool alone, for examplemax_active_sessions = 1. A patch withrig = "*"reaches the city's Worker and every rig's. - A sling to the city's Worker has no rig behind it, so no
formula_varsapply:forgetakes its default, anduser, who takes the bead once its pull request is open, takes its default,human, which is a rig's default too.
The Researcher
The Researcher, roles.researcher, is a pool of the city: scope = "city", so gc sling roles.researcher <bead> takes a bead of the HQ store or of any rig's, and its sessions count against the city's cap and no rig's. It runs 0 to 2 sessions on an acp box, fresh at each wake, claims with gc hook --claim --drain-ack --json, and works in .gc/agents/researcher. Its permission mode is full-auto, which gc maps to Claude Code's dontAsk: a call that no allow rule permits is refused and nothing prompts. It never runs in a mode that asks nothing. Its formula is mol-researcher-work and its skill is researcher; the formula has its own section.
What its session may call is the agent's own .claude/settings.json, roles/agents/researcher/overlay/per-provider/claude/.claude/settings.json. gc starts every Claude session of the city with one --settings <city>/.gc/settings.json, the city's list, and has no setting that gives one agent another file in its place. The way for a pack to give one agent a list of its own is the agent's overlay: gc copies overlay/per-provider/claude/ into the agent's work directory (the Operator's .claude/settings.json is one), where Claude Code reads it as the project's settings and merges it with the city's. By Claude Code's documented rule the merge is a union of the allow lists and of the deny lists, and a deny beats any allow. So an agent can add to the city's list and can take a tool away only by denying it: leaving a tool out of the agent's own allow takes nothing away while the city's list has it. The city's list has Agent, Edit and Write, and the Researcher starts no sub-agent and changes no file of a checkout, so its overlay denies Agent, Edit, Write and NotebookEdit, and allows the tools it calls: Bash, Read, Glob, Grep, Skill, WebFetch, WebSearch, TodoWrite, ToolSearch, and two of Perplexity's (below). A scratch note is written through Bash. Bash stays as the city has it, and the trial found that no rule of an allow list can keep it to commands that read.
Perplexity. The Researcher has one MCP server that no other agent has, Perplexity's official one, @perplexity-ai/mcp-server, pinned to 1.3.0. It is the file roles/agents/researcher/mcp/perplexity.toml: gc reads an agent's own mcp/ directory for that agent alone, so gc mcp list --agent roles.researcher shows perplexity, and the same command for the Worker or the Operator shows none. An acp session receives its servers in its session/new request, in-band, and claudeacp hands them to claude as --mcp-config '{"mcpServers":{"perplexity":{...}}}'. So the Researcher's session starts sh -c with one line that reads the key (below) and ends in PERPLEXITY_API_KEY=$k exec npx -y @perplexity-ai/mcp-server@1.3.0, with no env entry of its own, and the server's tools are mcp__perplexity__perplexity_search, …_ask, …_research and …_reason. The allow list names the first two and nothing else of Perplexity: under full-auto what no rule allows is refused, so perplexity_research (slow, expensive, and it does the role's own work) and perplexity_reason are off. Perplexity finds; it is not a source, and the role skill's rule for that is a change of its own.
The key comes from the session's environment, read when the server starts, and is written into no tracked file. The pack names no city and no path: it reads two variables, and the city sets one of them.
PERPLEXITY_API_KEY_COMMAND, when it is set and not empty, is run withsh -c, and its standard output is the key (a trailing newline is dropped). A city that keeps its secrets in a vault gives the command that reads it. The file is not read in that case: a command that fails is a failed start, never a fall back.- Otherwise
PERPLEXITY_API_KEY_FILEnames a file that holds the key.
With neither variable set, with a command that fails or prints nothing, with a file that is missing or empty, the start ends with a message on standard error and the session carries on without Perplexity. There is no default path: the file the pack read before, ~/.config/gascity-root/perplexity-token, is read only by a city that names it in PERPLEXITY_API_KEY_FILE. A city sets the variables in the env of a [[patches.agent]] entry for roles.researcher; the server is started by claudeacp in the session's environment, which no test of this repository shows, so the city's own change checks it with a Researcher session that calls perplexity_search:
[[patches.agent]]
name = "roles.researcher"
env = { PERPLEXITY_API_KEY_COMMAND = "<a command that prints the key>" }
# or: env = { PERPLEXITY_API_KEY_FILE = "/path/to/perplexity-token" }
The line is one sh -c string in the TOML file, one if and a check that the key is not empty, with no parse, not a script of its own, and go test ./internal/budget does not count it. npx has to be on the session's PATH.
tests/researcher.sh resolves the agent in a throwaway city (gc config show --json gives its scope, session, pool size, mode, work directory and the overlay directory it takes), renders its prompt and the Operator's with gc prime, and merges the overlay's rules with the city's list as it stands to show that a call of Agent, Edit or Write is not permitted. It runs gc mcp list --agent for the Researcher, which shows the one server, pinned, with no key in its definition, and for the Worker and the Operator, which show none, and checks that the allow list grants nothing of Perplexity beyond search and ask. It also runs the server's line under sh -c with a stub npx and made-up keys, for the command, the file, both, neither, a failing command, and an empty or missing key. What it does not show is Claude Code refusing a call: that was tried in a session, and the trial says what it found.
The Researcher's formula
mol-researcher-work is the Worker's shape with no worktree, no branch and no pull request: one step of five parts, claimed by the session that works it and held in progress until its last part, so that one routed bead costs one session. The parts are read the bead and mark it taken (the claim mark of mol-worker-work, worker_session and worker_step, so that gc roles view beads shows the bead as worked), scope the question, investigate, check, and post. It is mostly instruction; the skill researcher holds the rules of how it reads and what it hands back, and the step holds the parts, their order and their commands.
The Researcher's output is a comment on its own bead, headed [research-<bead id>], and the bead is closed once, by the Researcher, when the comment is posted. The writes go in one order: the comment, gc.work_outcome=no-op and gc.work_verification on the bead, the bead's close with the reason Findings posted: [research-<bead id>], the step's close, gc runtime drain-ack. The bead gets no branch, pr_url or merge_result, so the merge order and the landing orders never see it. A restart counts the bead's comments before it posts, and posts nothing when the heading is there. It halts, and does not close, a bead that is no question or a decision or a change: the bead goes open to the Operator with a halt_reason, the Operator is mailed (the one mail the role sends), and the step is closed as failed. The Researcher cannot load the Worker's worker-halt, which is a skill of the Worker's own agent and detaches a worktree it has none of, so the commands of the halt are in the step.
It changes no file of any checkout, runs no git command but git clone into its scratch directory (a directory made with mktemp -d, which it leaves where it is), slings nothing, starts no sub-agent and runs no rm; the Edit and Write tools are denied to it, so a file is written with a heredoc. Its bash blocks are 24 code lines, under the 60 that docs/shell.md allows a formula in all (the Worker's has 163), so the formula needs no Go tool.
tests/researcher-formula.sh compiles it in a throwaway city and holds it to this: a single step of five parts and Halting, the step closed as passed once and as failed only by a halt, the order of the writes, the drain acknowledgement last, no git command but a clone, no rm, no sling, no write to a bead but the work bead and the step, the one mail, the size of the step (under 9000 characters, and under the 28000 a Bash call keeps), and the bash blocks under 60 code lines. It also runs the lines that read and write the beads against a stub gc: the claim mark, the count, the post, the outcome and the close, the step's close, a restart that posted already, and the halt.
The trial by hand
The first act of the formula's build was to try in a session what the design (docs/researcher.md in gascity-root, 3.3 and decision 4) takes as given. It was run on 2026-11-12 with Claude Code 2.1.322, claudeacp 0.5.0 (the city's, .gc/bin/claudeacp) and gc's source at the city's pin 6bd609f, by claude started as the acp box starts it (--output-format stream-json --input-format stream-json --permission-prompt-tool=stdio --permission-mode dontAsk --settings <city>/.gc/settings.json, the setting sources user,project,local) in a work directory with the Researcher's overlay as its project settings, in a config directory of its own. A Worker's session is not logged in to run a model from a nested claude, so the API was a scripted stand-in on localhost (ANTHROPIC_BASE_URL) that answered each request with the next tool call of a list: what is tried is Claude Code's own permission engine and nothing of the model's.
- The Agent tool is refused under
full-auto, and nothing prompts. With the city's list, which allowsAgent, and the Researcher's overlay, which denies it, a call ofAgentcame back asNo such tool available: Agent. Agent is disabled for this session, in subagents as well as here.A deny takes the tool out of the session: it is not on the list the model is given.Edit,WriteandNotebookEditcame back the same. No permission request was sent. The same holds when the workspace is not trusted: Claude Code then ignores theallowentries of the project's settings ("this workspace has not been trusted") and keeps itsdenyentries, so the denies hold and what the Researcher is allowed comes from the city's list. dontAskrefuses what no allow rule permits, and a prompting mode asks. With no allow rule,Bashoftouch findontAskcame back as "Permission to use Bash has been denied because Claude Code is running in don't ask mode", and the file was not made; indefaultmode the same call went to the permission prompt tool (the request failed there only because the trial had closed its stdin).- The allow list's tool names are the ones the box calls. claudeacp runs the
claudeon the machine and does not change its tools (claudeacp/README.md, "claude's tools run on the machine, as in the terminal"): the transcripts of the city's Workers on acp boxes nameBash,Read,SkillandMonitor(andEditandWrite, which the user's brief forroot-5n7counts for the Workers of 2026-11-11 and 12), as in a terminal. The trial ranclaudeitself and not claudeacp, so it shows that the names are Claude Code's and what a deny of them does, and the README of claudeacp says that it changes none. - claudeacp accepts
full-auto. The city's acp sessions run asrexcity acp -- claudeacp --permission-mode dontAsk --effort high --model <model> --settings <city>/.gc/settings.json, and theclaudeunder claudeacp receives--permission-mode=dontAsk: claudeacp 0.5.0 takes the options of gc's acp command line and passes the mode on. gc's source at the city's pin mapsfull-autoto--permission-mode dontAsk(internal/worker/builtin/profiles.go:295). - An allow list cannot limit
Bashto commands that only read. Three things were tried. With the city's list as it is (it allows a bareBash, and the lists of the city and of the overlay are merged as a union), an overlay that allows onlyBash(git log:*),Bash(grep:*)and the like changed nothing:touch,sh -c 'touch f',echo x > fandgit log --output=fall ran. With the overlay's list alone, as if the city's had noBash,touch,sh -cand the redirect were refused andgit log,cat,grepandlsran, butgit log -1 --output=fran too and wrote the file, since an allowed prefix allows every flag of it. A deny list of the writers (Bash(touch:*),Bash(rm:*),Bash(git push:*),Bash(sed -i:*),Bash(tee:*)) refusedtouchand nothing else that writes:sh -c, the redirect andgit log --outputran. So the grant toBashis the city's, a deny narrows it only by naming commands, and the role's rule that it changes no file of a checkout and runs no git command that writes is held by the formula and the skill and not by the allow list. The Researcher's overlay allows bareBashand says no more.
What the trial did not try: a Researcher against a real model (a model that is given a refusal and goes on another way), the whole path of a bead (sling, claim, comment, close) and a comment of 100,000 characters, which are the release trial of build bead 5.
Worker pools
A pool of any size works each routed bead on one Worker, in one worktree, as one session from the claim to the hand-over. mol-worker-work is a single step with six parts, which a Worker claims and holds in progress until its last part closes it. A pool of five with one routed bead starts one session; with five beads, five.
The formula is one step because gc restarts a Worker session when a step of a workflow closes. gc hook --claim pins the open steps of the claimed step's gc.continuation_group to the claiming session, so when a step closes the next one is that session's assigned work, and not the bead its row is processing. gc's fresh cycle reads that as work needing a new conversation: for a pool agent with wake_mode = "fresh" it stops the session and starts another for the next step, with none of the context the first one had (compute_awake_set.go:585-587, reconcile_arms_fresh_cycle.go:29-78 at the city's gc pin, 6bd609f; the city runs the v2 reconciler). The same hand-off leaves the session's row asleep while its work is assigned, and pool_desired_state.go:455-491 plans a clean session for that work, which finds the work already assigned to the session that is restarting and drains. A probe of gc's demand count that is some seconds old can also start a session for a step that was claimed and closed in between (demand_claimed_work.go). With one step, claimed by the session that works it, no second bead is assigned to the session: a run has no boundary to cycle on.
Part 2 first runs gc roles worktree setup, which makes the Worker's directory a linked worktree when it is not one: gc's ACP runtime runs no pre_start (the Worker's own call of the same script, for the boxes that do), and gc creates the work_dir itself as a plain directory under the city's checkout. A Worker on a machine that has never run one thus makes its own worktree, of its rig's repository or of the city's, at origin/<base_branch>, and halts the bead, leaving the checkout alone, if it cannot.
The same gap holds for what Claude Code reads when a session starts: a seat's first session starts in that plain directory, before the worktree exists, and reads its context from the city's checkout above it, not from the repository's. Every later session of the seat starts in the worktree and reads the right ones. Part 2 therefore has the Worker read the repository's AGENTS.md and CLAUDE.md itself, once it is on the branch. The repository's .claude/ settings are read at session start only, and no formula can fix that: it takes the worktree to exist before the session starts, which on gc's ACP runtime is a change to the provider's acp_command in the city, where it can run gc roles worktree setup before it starts the adapter.
Two guards hold when a Worker dies all the same and gc releases the step to the pool:
- Parts 3 to 6 first run
gc roles worktree check, which exits 1 unless the worktree is on the bead's branch (worker/<bead-id>, ormetadata.branchfor a bead with a pull request). The part then halts the bead with that line ashalt_reason, before running anything on the tree it has. - Part 2 takes the branch with
gc roles worktree branch, and a halting Worker detaches its worktree, so a halted or dead run's worktree, which still has the branch checked out, does not keep every other Worker off the bead: the branch is detached there, files and commits left for the Operator, and taken by the Worker that has the bead.
A Worker whose session restarts mid-step claims the step again, runs Part 1 again because its context is new, and reads the worktree and the branch to see which of the other parts are done, instead of running Part 2, which resets the branch. A Worker goes from one part to the next without ending its turn.
The step is small, and its reference material is in skills. A Worker reads the step's text again and again: it is one bead of the store, shown whole by gc bd show, and the review of 2026-11-12 measured 45 percent of a session as orientation before the first edit, with the step read 111 times at the limit of a Bash call's inline output. The step, one text of about 7700 characters, holds what every run needs in order to act next: the parts, their order and their commands. It begins by telling the Worker to read the work bead, its description and notes, and to open a design document only at the lines the bead names. What only some runs need is in four skills of the Worker, which a part names where it calls for them, and which gc internal materialize-skills puts in an acp Worker's directory with worker:
| Skill | Named by | Holds |
|---|---|---|
worker-rework |
Part 1, for a bead with metadata.pr_url |
what a round that comes back asks: read the reviews and the halt reason, continue metadata.branch, rebase on a conflict, skip Part 3 |
worker-worktree |
Part 2 | what gnu check, worktree setup, worktree branch and worktree check do, why no git runs before setup on a box that runs no pre_start, and what each failure means |
worker-gates |
Parts 3 and 5 | where the gates are when the rig names none, that they are read-only, and the search-first report of a failure that is on the base branch |
worker-halt |
Halting | the commands of a halt: the bead to the Operator with the reason, the mail, the detach in a linked worktree (skipped by a halt from Part 2's gnu check or worktree setup, before the directory is a worktree), the step closed as failed, the drain acknowledged |
tests/formula.sh keeps the step under 8000 bytes, checks that each skill the step names exists, is materialized for roles.worker and holds the rules that were in the step, and runs the halt's commands from worker-halt against a stub gc. Part 1 prints WORK_BEAD_ID and BRANCH once, and a Worker writes them into the commands of later parts as literals, since each Bash call starts without its variables.
A Worker claims with gc hook --claim --drain-ack --json, in its nudge and in its skill. A seat that finds nothing to claim then tells gc, which stops it. A seat that only ends its turn stays alive, and gc keeps counting it as capacity for the next bead, which it never wakes to claim. A claim that fails is not an empty answer: it exits non-zero (2, with GC_HOOK_STORE_UNAVAILABLE on stderr, when the bead store gives no answer), prints no JSON or prints "ok":false. A seat that took that for a wait ended its turn, was woken by gc's reminders to try again, and held a seat of the pool for forty minutes. The Worker's skill and the Reviewer's prompt now make it a halt: mail the Operator once (--dedup claim-failed:$GC_TEMPLATE, || true since mail may be down too), then gc runtime drain-ack, and gc starts a fresh session when there is work again.
tests/formula.sh compiles the formula with gc and checks all of this, and tests/worktree.sh the three commands.
Handing over
A Worker never waits for CI. Once its pull request is open it records the branch and pr_url, gives the bead to the user and exits, whatever the bead's "done" says about checks: it does not watch a run or push fixes for a failing one, while fixing what a review sent back is the work. The checks on the forge are the reviewer's gate, a review starts only when they have completed, whatever their result, and a pull request whose checks fail comes back as rework. What a Worker can run before it pushes, the formula's pre-flights and its self-review, stays its job. The rule is in the Worker's skill and in the last part of mol-worker-work, Part 6.
Two more rules of the Worker's skill hold before it pushes, and tests/formula.sh holds the skill to both: every sentence it wrote that states a fact about the code (in the README, the docs, a comment, its changelog fragment and the pull request's description) is checked against the commit it pushes, after its last change; and for each test it added or changed it undoes the change the test is for, sees the test fail, and restores the change. The pull request's description says it did, and names any test it could not do it for.
The handover order
The Operator does not watch a bead to learn that it has been handed over: the handover order mails it. It runs on the bead.updated event, reads the bead.updated events of the last 10 minutes (HANDOVER_LOOKBACK), and for each bead whose latest state is open, carries metadata.pr_url and is assigned to the user, mails the Operator once:
- Subject
HANDOVER <bead>: <pr_url>, sent fromcontrollerwith--notifyand--dedup "handover:<bead>:<pr_url>". Body: the rig (by the bead's id prefix, orcity), the title, the branch and the pull request. - The user is
human, always: the formula'suserdefaults to it, so every Worker, of a rig or of the city, hands a bead tohuman, and what waits on the user is the open beads assigned tohumanin any store (gc beads list --assignee human --status open). The order also takes theuserof each rig'sformula_varsand the names inHANDOVER_USERS(separated by commas), so a handover to a name a city has not yet moved tohumanis still mailed. A city that setsuserin a rig'sformula_varsmust delete it from itscity.toml(this city's does today) and reassign the beads open on that name tohuman; until then its Workers hand beads to that name, and they are not on the list. A bead a Worker halted to the Operator, one a Worker holds, and a closed one are not handovers, whatever they carry. - Once: the mails sent are recorded in
handover.jsonunder the pack's state directory (GC_PACK_STATE_DIR), for a day, so a restart, or the next tick that reads the same event, sends nothing. The key is the bead and its pull request: a bead handed over again for the same pull request, after rework, is not mailed again, and its checks reach the Operator another way. A mail that failed is not recorded, the order exits non-zero and the next run, whose lookback holds the event, sends it.
The run is order handover, a subcommand of the roles pack's Go tool, with its tests in Go (roles/assets/roles); roles/assets/scripts/handover.sh, the order's exec, is the one line that starts it. The tool and the forgejo tool are one module, at the repository root.
The failures order
gc records each run of an order that failed as an order.failed event, and each that went through as an order.completed one, both with the order's name and scope as the subject (merge:rig:rexcity, nudge), and nothing read them: a forge that answered 503 made the merge order of one rig fail 128 times in a day, and the Operator heard of none. The failures order reads them and mails the Operator twice for an incident:
- Subject
ORDER FAILING <order>: <n> runs in a row, once, when the order has failed three runs in a row (FAILURES_STREAK). Sent fromcontrollerwith--notifyand--dedup "order-failing:<order>:<seq of the streak's first failure>". Body: the order, the number of failed runs, the times of the first and the last, and the end of the last error, at most 2000 bytes. The orders of the city run every 2 to 10 minutes, so three is 6 to 30 minutes of failure: a run that fails once and then goes through tells nobody. - Subject
ORDER RECOVERED <order>, once, when an order the Operator was told about runs again. Sent fromcontroller, without--notify, since nothing is left to do, with--dedup "order-recovered:<order>:<seq of the run>". A streak that ended before it reached three is forgotten and mails nothing.
Each order, with its scope, is counted apart. A failure after the order ran again and before the recovery mail was sent is the same incident: the count goes on from the incident's first failure (the recovery mail's "Failed runs in the incident" counts them all, with the first failure's time), and the Operator is told once that it runs again, when it does.
The order has scope = "city", like apply, upgrade and handover: the pack is imported at the city level and in each rig, and an order with no scope runs once per import, which would read the same city-wide events that many times, mail each incident that many times and write failures.json at the same time. The order is on a five-minute cooldown, not on the order.failed event: a mail that an order runs again has no failure to wait for, and an order on order.completed would start a run for each of the thousands of runs a day. It reads the events of the last two hours (FAILURES_LOOKBACK) and counts those above a cursor, the highest sequence it has read, in failures.json under the pack's state directory (GC_PACK_STATE_DIR), with each streak and whether the Operator was told; so an event is counted once however long the lookback, and the streak of an order that runs once a day is kept across days. A streak that never reached three and has not failed for a week is dropped. A run more than the lookback after the last (a city stopped for longer) says so on stderr: the failures between are not counted. A mail that failed is not recorded as sent: the order exits non-zero and the next run sends it.
The run is order failures, a subcommand of the roles pack's Go tool (roles/assets/roles/failures.go), with its tests in Go; roles/assets/scripts/failures.sh, the order's exec, is the one line that starts it, and tests/failures.sh tests that line.
What waits on an agent
Two commands of the roles pack answer what waits on an agent, and nudge it once. roles is the binding of the import. A bead waits on an agent when it is assigned to it and not closed: open, in_progress, blocked and deferred count alike, so a bead the Operator took for itself waits as much as one a Worker's halt put on it. It is read in the HQ store and in the store of every rig, from gc rig list.
| Command | Does |
|---|---|
gc roles waiting [--json] [agent] |
prints the beads that wait on the agent, one for a line (id, status, store and title, separated by tabs), or with --json one object on one line: schema_version ("1"), agent, count and beads, a list of {"id", "store", "status", "title"}. Nothing is printed when none waits |
gc roles nudge [agent] |
when at least one bead waits and no nudge to the agent's session is pending or in flight (gc nudge status), sends one nudge with gc session nudge: <n> bead(s) wait on you: <ids>, the ids of the first five and and more after them when more wait. Otherwise sends nothing, and says which on stdout |
The agent is $OPERATOR, else the one city-scoped agent named operator, when none is named. Both commands take gc's --city <dir>, which wins over GC_CITY_PATH and GC_CITY, and give it to every gc call they make, so the HQ store is the one of that city whichever rig the caller stands in. With neither of them set the commands exit 1 (no city to read) and read nothing: left to gc, the HQ store would be the store of the directory the caller stands in, a rig's from inside one, and that rig would be counted twice. A session or an order of the city has GC_CITY_PATH.
A store that cannot be read is an error, never an empty answer. Both commands read every store, and nudge reads the nudge queue too, before they decide. When any of them cannot be read, the command exits 1 and names each one on stderr (reading the <rig> store: ..., reading the nudge queue of <agent>: ...); waiting prints nothing on stdout, and nudge sends no nudge, not even for the stores it could read, since an unreadable store reads as "nothing waits" for as long as it is down. A queued nudge or an empty answer does not hide a failure: the stores are read in every run. A command line the tool does not read exits 2 with the usage. The Go tests carry the cases that the review of the city's first script of this order (gascity-root#44) found: the HQ store failing, a rig in the middle failing, the last rig failing, a failing gc nudge status, each with and without beads in the other stores.
The city's operator-nudge order. The order is the city's own (orders/operator-nudge.toml, a cooldown of five minutes), and its script becomes one line:
exec gc roles nudge
in place of the 18 lines of scripts/operator-nudge.sh, whose logic (the queue gate, the loop over the rigs, the counting and the line) is the tool's now. The commands are in the release after 0.8.0, which this change's fragment makes 0.9.0 (an Added note is a minor version below 1.0). The city's constraint on [imports.roles] does not reach it, as a caret constraint on a 0.x version stops below the next minor: the pull request in gascity-root that makes the script that one line also moves the constraint to ^0.9 and the pin in packs.lock, and so does not merge before the release is cut.
How the Operator learns that an order keeps failing. From the failures order (see "The failures order" above): an unreadable store fails the operator-nudge order every five minutes, and after three failed runs in a row the Operator is mailed ORDER FAILING operator-nudge, and ORDER RECOVERED operator-nudge when it runs again. Before that order landed nothing of the city read order.failed events: in the 24 hours up to 2026-11-12 15:35 the city's log held 138 of them, 128 the merge order of one rig reading a forge that answered 503, and the Operator heard of none.
Pane views
Two commands of the roles pack are for a terminal pane beside the Operator. Each runs until it is killed, starts in the city directory and fits a pane of any width; --once draws one frame and exits. roles is the binding of the import.
| Command | Shows |
|---|---|
gc roles view beads [--rig <name>] |
the city's beads, or one rig's, redrawn in place every three seconds: first what is in flight, with a Worker, in review, in rework and approved, then what waits on the user or the Operator, what is queued, a count of the rest for each rig and of what is parked, and the last five beads closed |
gc roles view mail |
the city's mail as a log: what was sent, read, marked read and archived in the last hour, then each such event as it happens |
view beads shows one rig where it is given --rig <name> or is started in the rig's directory (or below it), and every rig anywhere else, the city directory included. A rig's tab runs gc roles view beads --rig <rig>, which needs no particular directory.
What view beads tells of a bead in flight comes from four signs, each one a rule of the packs: the claim mark of mol-worker-work (in_progress with worker_session and no assignee) is a bead with a Worker; an open review bead of the Reviewer (label review, work_bead naming the bead, no review_verdict) is a bead in review; a pull request the bead has already, with a Worker or the pool on it again, is rework; and a review_verdict of pass or fail on a review bead that is later than the work bead's last change is approved or sent back. A bead assigned to the user that none of these holds is waiting on the user. The verdicts of review beads that are closed are read from gc events --type bead.closed --since 24h, so a verdict older than a day is no longer known to the view.
The user is human, to whom the Worker's formula gives a bead when no user is named, and, for a city that has not yet moved its rigs to human, formula_vars.user of the rigs in city.toml, which view beads reads with gc config show. Both commands need jq on the supervisor's PATH. view beads reads gc beads list through the supervisor's bead cache, which can lag the stores: GC_NO_API=1 reads the stores directly, more slowly. view beads reads the beads closed in the last day, and with them the verdicts of the review beads, every 300 seconds, and at once when a bead leaves the list: VIEW_CLOSED_INTERVAL sets the interval, in seconds. NO_COLOR, or an output that is not a terminal, turns the styling off.
The changelog tool
A Worker and a reviewing agent run the changelog checker before a pull request, and the city installs it once for all of them: the apply order has the roles tool build sarak.sh/mikluko/changelog at a version the city pins and put it in REX_BIN_DIR (<city>/.gc/bin, on every agent's PATH) as changelog, next to rexcity.
The pin is a file of the city repository, changelog.pin, one line of module@version, as gc.pin holds the gc commit the city runs:
sarak.sh/mikluko/changelog/v2@v2.0.1
It is a file, and not a pack import, because the checker is a Go command and no pack, and not a setting of this pack, because a bump of the tool would then need a release of the pack. The apply order reads it in the incoming checkout, as it reads packs.lock. A city with no changelog.pin gets no tool and no failure. The module path carries the major version (/v2), so a new major is a new pin line, not a surprise. The pin must be v2.0.1 or newer: v2.0.0 reads HEAD of a linked worktree from the main checkout, so in a Worker's worktree it reports the wrong latest-tag (changelog-nx4, fixed in v2.0.1).
When it builds. When origin/main has moved and the changelog in REX_BIN_DIR is not the pinned build: missing, or reporting another module or version (read from the binary's build information, as go version -m shows it). So a pin that moved builds, a pin that did not move and a binary that is there builds nothing, and a binary deleted by hand comes back at the next run that finds origin/main moved. The logic is a command of the roles pack's Go tool, roles changelog install <pin-file> <bin-dir> (roles/assets/roles/changelog.go, tested beside it), and apply.sh only calls it, in three lines (docs/shell.md asks of a script over its thresholds that its logic be a command of the tool and its stub at most four lines). The command runs go install <module>/cmd/changelog@<version> with GOBIN set to a temporary directory in REX_BIN_DIR and moves the result into place only when the build succeeded: go checks the module's hash against its checksum database, as for any module. It is safe to run on every apply: with no pin, or the pinned build in place, it builds nothing and prints nothing.
When it fails. A build that fails, or a pin that is not module@version, mails the Operator (from controller, once for each incoming commit while the mail is unarchived) and stops the run before the city directory moves: the old changelog stays, and so does the city, and the next run tries again. go install takes the module and its dependencies from go's module cache, or from its proxy. A machine whose go cannot reach the proxy builds the tool only when go's module cache already holds that version and its dependencies, as the user's Mac does for changelog v2.0.0 and v2.0.1. Where it does not, the mail carries go's own error and the command to run by hand on a machine that can reach the proxy, GOBIN=<city>/.gc/bin go install <module>/cmd/changelog@<version>: the next run finds the pinned build there and goes on. The other way out is a GOPROXY in the supervisor's environment that serves the module.
The pin and CI. CI runs the moving tag v2 of the actions/validate action, and the pin is one release of it, so the pin can fall behind the tag: a note that the newer checker rejects passes the Worker's local check and fails CI, and the pull request comes back as rework. The pin is bumped by hand, in the city repository, when a release of the checker changes what it accepts; the upgrade order does not propose it, since it moves packs.lock imports and the checker is none. Whether it should is for the order's move to Go (docs/shell.md, section 5, item 3), which can read the module's tags.
What a Worker does. It runs changelog -base main from its worktree's root, from PATH, and builds no checker of its own. Where changelog is not on PATH it does not build one: it runs no check, says so in the pull request's description, and mails the Operator that the city has no changelog tool, so that the pin or the install is put right (one mail for the whole city, --dedup changelog-missing, while the Operator has not archived it). The Reviewer, which sends no mail but its verdict's and a halt's, says in its review that it did not run the check. The forge's check is the gate in any case.
macOS hosts
On macOS, date and sed are BSD's, and the CI runs the scripts and tests of these packs on Linux, where they are GNU's. A host that runs Workers needs Homebrew's coreutils and gnu-sed, with gdate and gsed on the supervisor's PATH:
brew install coreutils gnu-sed
A Worker checks for them first, in Part 2 of mol-worker-work, before it touches the worktree. When one is missing, the Worker halts the bead: its halt_reason names the missing tools and the brew install that fixes them, and the bead goes to the Operator. Install the tools, then ask the Operator to sling the bead again.
Where the tools are installed, a Worker's date and sed run as GNU's. A Worker's PATH names $HOME/.local/share/gascitypacks/gnubin, where two links are kept: date to gdate and sed to gsed. The Worker's start makes them where a box runs one, and gc roles gnu check makes them again before it checks, so a Worker on a box that runs no start, such as an acp box, has them all the same. gc puts its own directory ahead of that one, but it holds no date or sed, so the order between them does not matter; what matters is that the shim directory comes before the system's. Only a Worker's PATH changes: the supervisor, the orders it runs, the Operator and your own shells keep the BSD tools, so the scripts of an order must work with the BSD tools as well as the GNU ones. On Linux the directory does not exist and nothing changes.
The required tools are one list, in gnu-tools.sh: add a row there to require another.
Shell and Go
docs/shell.md inventories the shell in this repository, states the rule for when a script has to be a Go program, says where the roles pack's Go lives, and plans the moves. The user adopted the rule on 2026-11-12 (the Moderate variant). A change that adds a script, or grows one, is held to it; REVIEW.md and the Worker's skill say how.
The Go module. The repository is one Go module, sarak.sh/mikluko/gascitypacks, with its go.mod at the root, so that the two packs' tools share code:
| Path | What it is |
|---|---|
forgejo/assets/forgejo |
the forgejo pack's tool, which its commands and its merge and schedule orders start |
roles/assets/roles |
the roles pack's tool: the handover order, and the command version (gc roles version) |
internal/gcx |
what both tools share; so far the lookup of the city's Operator |
internal/budget |
the test of the rule, below |
A command or an order starts a tool as go tool -C "$GC_PACK_DIR" <tool> ... ($PACK_DIR in an order), from the pack's own directory: go looks in the parent directories for go.mod, and gc's pack cache holds a checkout of the whole repository for each locked commit, so the file is there at run time. The module has no dependency, so building needs no network and no module cache. tests/pack-cache.sh runs the wrappers from a copy of the checkout made as the cache makes one, with GOPROXY=off, GOTOOLCHAIN=local and empty build and module caches, and through gc.
The budget test. go test ./internal/budget measures the units of shell (an order's script, a command's run.sh, a script a pre_start names, each with every script of the repository that it sources or execs, and the bash blocks of each formula) with the counts of the document's Appendix A, and compares them with the ledger, docs/shell-ledger.txt: the units that exist and break the rule, with the measures they had when they were listed. A unit over a threshold that is not in the ledger, a unit of the ledger that grew, and a line of the ledger for a unit that is gone or no longer over a threshold are what it would fail on, and it prints each of them with the numbers. For one release it only prints them: the lint job runs it as its own step, go test -v -run TestShellBudget ./internal/budget, and passes whatever it finds. SHELL_BUDGET=fail in its environment makes it fail. go test ./internal/budget -run Units -v -args -units prints the measures of every unit, in the ledger's format.
One script has moved, as the first piece of Landing to be written in Go: the merge order, whose logic is the forgejo tool's order merge and whose merge.sh is a four-line stub. A new order is written in Go from the start: the handover order is the first of the roles pack's, in the roles tool.
Checks
gc lint .
go vet ./...
go test ./...
Releases
A pull request notes its change in a file of its own in .changelog/, a fragment, and never edits CHANGELOG.md: pull requests that each added a line under [Unreleased] collided on it. A fragment holds level-3 type headings and the notes under them, as they would read under [Unreleased], and nothing else:
### Fixed
- The parser no longer reads a fenced heading as an entry.
Name the file for the change, as retry-budget.md: the release folds fragments in name order. A change with nothing notable gets no fragment, and then test / changelog fails the pull request with missing-fragment. Version 2 of the checker (sarak.sh/mikluko/changelog, the actions/validate@v2 step of the changelog job) checks three things that version 1 did not: missing-fragment (a pull request adds a fragment its merge base with the target lacks, or a note the changelog there lacks, as a release does), fragment-form (each file in .changelog/ is a fragment) and fragments-release (the fragments would release without a finding). It checks the format of CHANGELOG.md as version 1 did. To run it before pushing, from a checkout that has the tags and the target branch (in a city, changelog is on every agent's PATH, as the changelog tool says):
changelog -base main
# without the city's build:
go run sarak.sh/mikluko/changelog/v2/cmd/changelog@latest -base main
A release is a pull request that turns the pending notes into a version section, ## [X.Y.Z] - YYYY-MM-DD, of CHANGELOG.md. Cut it on a branch from main with:
go run sarak.sh/mikluko/changelog/v2/cmd/changelog@latest release
The command folds every fragment of .changelog/ into [Unreleased] and deletes the files, renames [Unreleased] to the version its notes call for (major for a note that opens with **Breaking:**, which below 1.0.0 is minor; minor for any type but Fixed and Security; patch otherwise) dated today in UTC, and opens an empty [Unreleased] above it. -version X.Y.Z names the version instead, and -date YYYY-MM-DD the date. A note already under [Unreleased] is released with the fragments. The release pull request holds that one change: CHANGELOG.md with the new section and the deleted fragments. The date is the day the pull request merges, so set -date, or edit the heading, when it merges on another day: test / changelog fails an undated entry and, once the tag exists, an entry dated another day than the tag. The release pull request adds no fragment, and the check lets it through because it writes notes into CHANGELOG.md.
When the pull request merges, the release workflow, which runs only for a push to main that changes CHANGELOG.md, reads the changelog with the same validate action and, when the newest entry names a version no tag names yet, creates the tag vX.Y.Z on the commit that landed on main, and the Forgejo release of that tag with the section as its notes. A merged pull request that carries only a fragment does not change CHANGELOG.md, so it starts nothing, and every other push to main cuts nothing. Running the workflow by hand on main repeats a run that failed.
One tag covers both packs. An import of either follows the releases with version = "^0.N" in its [imports.roles] or [imports.forgejo] table: version is a semver constraint over this repository's tags, and sha:<commit>, with the full hash of a commit, pins one commit instead.