Landing L12: the schedule order, built and not switched on #44
No reviewers
Labels
No labels
No milestone
No project
No assignees
3 participants
Due date
No due date set.
Dependencies
No dependencies set
Reference
mikluko/gascitypacks!44
Loading…
Reference in a new issue
No description provided.
Delete branch "worker/gascitypacks-0wh"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What this adds
Landing row L12 (
docs/handoffs.mdin gascity-root, 3.1 P3 and 3.11 d): the forgejo pack'sscheduleorder, built and not switched on.gc forgejo order schedule, a subcommand of the pack's Go tool, behind a two-lineassets/scripts/schedule.shandorders/schedule.toml(exec, cooldown 2 minutes). Every cycle, for each closed bead withmerge_result=pull_request, it runspr merge --expect-head <gc.work_commit> --target <target, else the default branch>in-process and handles each answer as table 3.11 d says. The README's section "The schedule order" has the table.FORGEJO_SCHEDULE=onin the order's environment, which a city gives with the[[orders.overrides]]entry it already has for the order'sFORGEJO_TOKEN_FILE. Unset, or anything buton: one line printed, no bead read, no forge request, no gc call.TestScheduleWithTheSwitchOffReadsAndSchedulesNothingpins it with a store that fails on any call and a forge that counts requests, for seven values.mergeorder's is. Nothing in this pull request enables it in a city.auto_merge=scheduled, andauto_merge_trouble({"reason","cycles","since"}) while a merge stays unscheduled.order.go) makes a bead for the Operator withpr_urlandpr_event, looks it up in any status first, and mails with--dedup. This order now makes its bead through that same code, which this round lifted out of the merge order (operatorBead,mailOperatorBead,findOperator,gcFuncinorder.go): the bead carriespr_url,pr_event(stuck,no_worker,wrong_base,missing,foreignorforge_refused),pr_headandwork_bead; it is found by event, pull request and head (by the work bead when there is no pull request or no head); the mail is--notify --dedup <event>:<url>:<head>.pr_eventis what keeps the merge order's scan of the old shape off it, and thehead_movedcheck skips beads that carry it. The first version of this pull request usedstuck_headandstuck_eventwith nopr_event, and the merge order would have closed such a bead as shipped at the merge, or handed it over a second time;TestScheduleBeadForTheOperatorIsLeftAloneByTheMergeOrderruns both orders over one fake city and fails if the skip is removed.Choices worth a look
forge_refusedwhose message contains "conflict" is left to the rework order (L13) and only counts toward the two hours; any other is an Operator bead at once. The word is a guess at Forgejo's wording: step 6 of the trial records the real message.gc mail send --dedupsuppresses a send only while the earlier mail is un-archived, so a mail every two minutes for a bead already known would come back as soon as the Operator archived it. The price: a mail that fails after its bead was made is not retried; the run says so and exits 1.pr_url, or agc.work_committhat is not a full commit, used to be a line on stderr every cycle. It is now counted inauto_merge_troubleasno_head, and the third cycle in a row is a bead for the Operator (eventstuck, found by the work bead), since the merge order skips a bead with nopr_urland nobody else would notice.rig = "*"in the[[orders.overrides]]entry reaches the HQ instance as well as every rig's: in this city, wheremergehas that one entry,gc order show merge --jsonprints the entry'senvfor the HQ instance ("rig": null) and formerge:rig:gascitypacks. The README says so, and how to switch on only some stores.head_movedmakes a bead for the Operator only when every bead with the pull request'spr_urlis closed and none holds the new head asgc.work_commit. The order's own beads for the Operator are not counted (a test caught that they would hide the next head).gc bd update --set-metadata) is assumed to work, as P2 and P8 assume it. Not tried here: the trial step 7 shows it.client.defaultBranchisopenPull's first request taken out, so the order andpr openread the default branch the same way.Checked
go vet,go testandgo test -race ./...of the forgejo module (GOPROXY=off),tests/formula.sh(underenv -i: in a Worker's environment it fails on the throwaway city, gascitypacks-pmn),tests/merge.sh,gc lint ., and the v1 changelog checker built from its tag (valid=true), on the branch rebased onto main at83adff9. The Go tests use one fake of gc for the store, the agents and the mail, a fakegcexecutable for the argument lists and the directory, and the existing fake forge. Nothing was run against the real forge.The trial the Operator runs before the switch-on
It needs the review account, so it is not the Worker's. Handoffs questions 6 and 11 and decision 11 ride on it. Use a scratch repository on sarak.sh,
gascity-root/schedule-trial, withmainprotected the way production's is: one approval fromcity-root-review, the checks required, anddismiss_stale_approvalson.Fis the pack's tool from this branch (the city's 0.5.0 has nopr mergeyet),CITYthe token file ofgascity-root,REVthe token file ofcity-root-review,Ca clone of the scratch repository.sched $H1outcome:"scheduled", exit 0; the pull request stays open even with green checks (no event follows)forge_refused: recordforge_message. A refusal about the account or the protection answers question 11 (the city's account cannot schedule into protectedmain): L12 cannot be switched on until it is mendedsched $H1againalready_scheduled, exit 0scheduledagain: the forge no longer answers 409, soalready_schedulednever comes and the order's idempotence is by another route; record itecho two >>trial.txt && git commit -am two && git push,H2=$(git rev-parse HEAD), thensched $H1,sched $H2sched $H1: exit 3head_moved;sched $H2:already_scheduled, so the push did not remove the schedule (3.11, row 3)scheduledfor$H2: the push removed it. The order still re-runs every cycle, so it is mended in two minutes; correct 3.11 and the READMEFORGEJO_TOKEN_FILE=$REV $F pr review --json --repo "$C" --pr "$PR" --expect-head $H2 --event APPROVED, wait for the checks,stposted; with the checks green the approval is the event that merges:stshowsmergedwithin a minuteH3: approve it and wait for green before step 1, thensched $H3scheduled, and it stays open: nothing starts the check (3.11 c)gascity-root:curl -X POST -H "Authorization: token $(cat $CITY)" -H 'Content-Type: application/json' -d '{"state":"success","context":"city/merge"}' https://sarak.sh/api/v1/repos/gascity-root/schedule-trial/statuses/$H3main;schedits headforge_refused: write down the exactforge_message; the order treats a message with "conflict" in it as the rework order'sschedule.go(strings.Contains(..., "conflict")) before the switch-onscratch, create a bead, give itmerge_result=pull_request,pr_url=$PR,gc.work_commit=$H5(a fresh pull request's head), close it, thenFORGEJO_TOKEN_FILE=$CITY GC_RIG_ROOT=<the rig> $F order schedule(it prints it is off), then the same withFORGEJO_SCHEDULE=onoff, nothing changed on the forge or the bead. Second:scheduled; the bead hasauto_merge=scheduled, written on a closed bead; a repeat printsalready_scheduledand writes nothinggc bd updaterefusing a closed bead: P2, P8 and this order all write on closed beads, and the design needs another routeH5replaced by a stale headhead_movedprinted; one bead for the Operator (pr_event=no_worker, withpr_urlandpr_head) once nobody holds the pull request's head, one mail, and no second bead or mail after another runpr_event, or the merge order closing it:gc bd showit and tell the Operatorgc order run mergepr_closedand nogc.work_outcomepr_eventskip is not working in the real storeAfter 1 to 5b, tell the user the results, and record them in
docs/handoffs.md3.11 and the README's "What Forgejo does with a scheduled merge". Only then does the city turn the order on:FORGEJO_SCHEDULE = "on"in the order's[[orders.overrides]]entry, and only after the user has confirmeddismiss_stale_approvalson each repository (decision 11).🤖 Generated with Claude Code
Bead: gascitypacks-0wh
77f3b8a01d6a4b464685Rebased onto main (
3e38bc3, after #40, #42 and #46 merged); head is now6a4b464. What the rebase touched:CHANGELOG.md: kept main's entries (theservicelabel,order merge) and put thescheduleentry after them. I also corrected a wording slip in it and in the README: the order's command is the tool'sforgejo order schedule, not agc forgejo …command.README.md: one row of the packs table, which now names both themergeorder (the tool'sorder merge) and thescheduleorder.forgejo/assets/forgejo/main.go: both orders in the usage, the header and the unknown-command message.envhas main'sgcandlogbeside mynewStoreandnow;runsendsorder scheduletoorderSchedulebefore main's order timeout, andorder mergeis unchanged.schedule.goandschedule_test.go: myorderBeadisstoreBeadnow, since #46 added anorderBeadof its own toorder.gowith another shape. No other change. The schedule order'sgcStorestill runs gc in the repository, where the merge order runs it in$PWD; I left both as they are.Run on the rebased head:
go vetandgo test ./...inforgejo,gofmt -l,gc lint ., every script undertests/that CI runs, and the v1 changelog check (valid=true). Nothing else changed.Review of
6a4b464(gascitypacks-0wh, Landing L12): changes required.What must change:
forgejo/assets/forgejo/schedule.go:535-565(raise) andgcStore.create/gcStore.mail(:162-207) are a second helper of their own. They tag the bead withstuck_head/stuck_eventand nopr_event, and mail with--notifybut no--dedup. The pull request's description does not say it follows #46. The difference is a bug, not just style:order.go:282(settleOpen) treats every open bead that haspr_urland nopr_eventas a bead of the old shape. So the merge order would close the schedule order's Operator bead as shipped when the pull request merges. If the pull request closes unmerged, it would hand that bead to the Operator a second time, withpr_closedand another mail. The description's "Choices worth a look" calls this harmless, but #46 addedpr_eventprecisely to prevent it. Wanted:order.go:489(operatorBead), lifted out so both orders share it. Give itpr_urlandpr_event=<stuck|no_worker|wrong_base|missing|foreign|forge_refused>, and keep the head on it so there is one bead per head. Look it up withgc bd list --allon those keys before making one.--notify --dedup <event>:<url>:<head>.headMoved(:520-524) to skip beads that carrypr_event, not beads that carrystuck_head.TestGCStore*and the raise tests), and say in the description that the bead is #46's.Checked, and fine:
FORGEJO_SCHEDULEunset, empty,ON,On,1,true,yes,"on "or" on", the built tool, run against a fakegcand a fake forge, printed one line, exited 0 and made no call at all.onmade the calls.city.tomlhas noscheduleoverride, so a city that imports the pack as it does today gets the order off. gc still starts the order every 2 minutes, andgo toolstill builds the tool each time; it reads nothing.auto_merge=scheduledonly onscheduled,already_scheduledandmerged, never cancels, and a second cycle writes nothing.httptest, with no request to sarak.sh.go vet,go testandgo test -racepass. The wrapper is oneexec, the pack.toml change is only its description, and the cooldown is 2m. main has not moved since the rebase, so the merge result is the head that CI checked.Smaller points (not blocking):
pr_url, or with agc.work_committhat is not a full sha, is skipped with a line on stderr every 2 minutes and nobody is told.rig = "*". Say whether that entry also reaches the HQ instance, or whether the HQ store needs an entry of its own.6a4b4646858cb5f44074Rework round for the review of
6a4b464(rebased onto main at83adff9; new head8cb5f44on top of the first commit).Changed
operatorBead,mailOperatorBead,findOperatorandgcFuncare lifted out of the merge order intoorder.go, and both orders use them. The schedule order's ownraise,gcStore.createandgcStore.mailare gone, withorderStoreandgcStore: the scheduler runs gc throughgcRunIn, whichgcRunis now a case of.pr_url,pr_event(stuck,no_worker,wrong_base,missing,foreign,forge_refused),pr_headandwork_bead. It is looked up withgc bd list --allon event, pull request and head before one is made, and mailed with--notify --dedup <event>:<url>:<head>. The merge order's ownclosedbead and mail keep the same shape and key.headMovedskips beads that carrypr_event, notstuck_head.pr_url, or no fullgc.work_commit, is counted inauto_merge_troubleasno_head; the third cycle in a row is a bead for the Operator, found by the work bead.The review's question. Yes:
rig = "*"reaches the HQ instance. In the city, wheremergehas that one entry,gc order show merge --jsonprints itsenvfor the HQ instance ("rig": null) and formerge:rig:gascitypacks. The README says so, and how to switch the order on for some stores only.Tests. The fake store of
schedule_test.gois now a fake of gc (bd list,bd update,bd create,mail send,agent list); the raise tests assert the lookup call, the dedup key and the absence ofstuck_head/stuck_event, and that a bead the Operator closed, or a mail it archived, brings neither again.TestScheduleBeadForTheOperatorIsLeftAloneByTheMergeOrderruns both orders over one fake city (pull request merged, and closed) and fails when thepr_eventskip insettleOpenis taken out (checked). Trial step 9 repeats it on the real store.go vet,go test,go test -race,tests/merge.sh,tests/formula.sh(underenv -i, gascitypacks-pmn),gc lint .and the v1 changelog checker pass.Reviewed
8cb5f44(Landing L12, schedule order, off by default): shared Operator bead, switch, tests, merge result.Re-review of
8cb5f44against comment 2830: passes. Merged as43dce15(squash) after thecity-root-reviewapproval of8cb5f44.Checked:
operatorBead,mailOperatorBeadandfindOperatorinorder.gonow serve both orders. The schedule order's bead for the Operator carriespr_url,pr_event,pr_headandwork_bead. It is looked up withbd list --allonpr_event,pr_urlandpr_headbefore one is made, and mailed with--notify --dedup <event>:<url>:<head>. The merge order's ownclosedbead is unchanged: the same keys, the same lookup and the same dedupclosed:<url>.order.goon main:settleOpenskips any bead withpr_event, andsettleClosedlists only beads withmerge_result. So when the pull request merges, and when it closes unmerged, the merge order leaves the schedule order's Operator bead alone.TestScheduleBeadForTheOperatorIsLeftAloneByTheMergeOrderruns the real merge order over both cases and asserts that nothing touches the bead.headMovednow skips beads that carrypr_event, which includes the merge order'sclosedbead.no_head. The third cycle in a row makes a bead for the Operator, keyed bywork_bead.rig = "*": the entry reaches the HQ instance and every rig's. For per-store control it says to use a separate entry, with or without arigkey.8cb5f44and ran it against a fakegcand a fake forge. Unset, empty,ON,1,true,yes,"on "and" on"made 0 calls;onmade calls.go vet,go testandgo test -racepass. The branch is on main83adff9, so the merge result is the head CI checked: changelog, lint and scripts all succeeded.Follow-up worth a bead (not blocking):
raisemails only when it has just made the bead. Ifgc mail sendfails after the bead is created, the next run finds the bead and never mails, so the Operator learns of it only from the bead itself. The merge order instead sends on every run and lets--dedupsuppress the repeats.Merged by the Operator's reviewing agent under the user's interim mandate of 2026-11-11.
Trial run by the Operator's agent on 2026-11-12 on mikluko/scratch, tool built from v0.6.0.
Tool:
go build ./assets/forgejofrom v0.6.0 (d9d5ad4),FORGEJO_URL=https://sarak.sh; CITY =city-root's token file, REV =city-root-review's. The repository is mikluko/scratch in place ofgascity-root/schedule-trial.pr openwas given--summary-file. Commits were pushed over ssh asmikluko; the pull requests are bycity-rootand the scheduled merges were made ascity-root.Protection of scratch
main(not readable, 403; found by refusals on mikluko/scratch#1): one approval required, checktest / test (pull_request)required,dismiss_stale_approvalsoff: after a push R's earlier approval stayedstale: true, dismissed: falseand a merge with it succeeded (200). So the trial ran without the rule it asks for; no step below depends on it, but it is the guard of 3.11 (a), and it is off here.Pull requests: A = #3 (
trial-l12, H1553ec1c, H2bb30552), B = #4 (trial-l12-b, H3c112549), conflict = #5 (trial-l12-conflict, H443cf68c).sched $H1(checks green)scheduled, exit 0, stays openscheduled,schedule_cancelled: false, exit 0; open 20 s latersched $H1already_scheduled, exit 0already_scheduled, exit 0sched $H1;sched $H2head_moved;already_scheduledhead_moved(headbb30552), exit 3;already_scheduled, exit 0: the push did not remove the schedulepr review APPROVEDH2;stposted; merged within a minuteofficial: true); checks went green and #3 merged at 12:20:30 ascity-root(e783e12)sched $H3scheduled, stays openscheduled, exit 0; still open 70 s later{"state":"success","context":"city/merge"}on H3city-root); #4 merged at 12:22:30 ascity-root(e816f00)sched $H4forge_refused, message with "conflict"rejected/forge_refused,forge_status: 405,forge_message: "Please try again later", exit 9 (twice, 30 s apart; the raw API answer is the same{"message":"Please try again later"})What it means:
already_scheduled(409), storing it merges nothing (1, 5), an approval or a later green status merges (4), and a pull request that already has everything waits for an event (5).city-rootwith write access may schedule into protectedmain; Forgejo merged #3 and #4 ascity-root.city-rootmay post one (5b).dismiss_stale_approvalsis off, so the trial shows what 3.11 (a) fears: nothing but that setting keeps a new head from merging on an old approval. The user must still confirm it per repository.schedule.go:312(strings.Contains(..., "conflict")) never matches Forgejo's answer for a conflicting pull request,405 Please try again later, which also names no cause; every conflict becomes an Operator bead instead of the rework order's. Steps 7 to 9 are still to run.Clean-up: #5 closed; #3 and #4 merged into scratch
mainas the trial intends. No branch deleted.