Landing L9: the merge order records a merge on both shapes of bead, in Go #46
No reviewers
Labels
No labels
No milestone
No project
No assignees
2 participants
Due date
No due date set.
Dependencies
No dependencies set
Reference
mikluko/gascitypacks!46
Loading…
Reference in a new issue
No description provided.
Delete branch "worker/gascitypacks-hdo"
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?
Landing L9 (HQ ticket root-ons.17,
docs/handoffs.mdin gascity-root, rows 2.4, 3.2, 3.4, 3.7 e and f, P7 and decision 9, option A): the merge order handles both shapes of a bead, and it is the first script of this repository to move to Go.What changed
forgejo order merge, a new subcommand of the forgejo tool (forgejo/assets/forgejo/order.go), is the order's logic.assets/scripts/merge.shis now a wrapper that checksgois onPATHand execsgo tool -C "$PACK_DIR" forgejo order merge.pr_url): unchanged. Same listing, samegc.work_outcome=shippedthenbd close --force --reason "Pull request merged: <url>", same hand-over to the Operator (assignee,--notifymail with the same subjects and text,pr_closed), same foreign skip line, same exit status. No mail at a merge, as before.merge_result=pull_request, listed by--status closed --has-metadata-key merge_result):merge_result=mergedandmerged_shaon every bead that carries the pull request's URL, and one mail to the Operator per merge (--notify --dedup merge:<url>);merge_result=closedon every bead, one bead for the Operator per pull request (P7: open, assigned to it,pr_url,pr_event=closed, the beads in its description) and one mail (--notify --dedup closed:<url>).pr stateruns on (fetchPull, whichpr statenow calls too): the same URL resolution, token handling,missingandforeign, and the same error for a merged pull request with no merge commit. Once per pull request per run, for both shapes. It makes no request for the checks or reviews, which the order does not use; I did not shell out topr state --jsonfor that reason (3 requests a bead every 2 minutes, and a failing checks lookup would hold a merge record).GC_RIG_ROOT, elseGC_CITY_PATH, elseGC_CITY;GC_RIGnames the rig in the mail, "the HQ store" otherwise;OPERATORor the one city-scoped agent namedoperator.[Unreleased], and the order's description.Old test to new test
tests/merge.shtested the script with stubs ofgcandgo. Each of its cases is a Go test inforgejo/assets/forgejo/order_test.go, with a fakegc(a store of beads that answersbd list,show,update,close,create,mail sendandagent list, and refuses a close of an assigned bead without--forceas gc does) and the forge behindhttptest:tests/merge.shheldandfree: a merged pull request closes the bead as shipped, whoever holds it, withgc.work_outcome=shippedTestMergeOrderClosesAnOpenBeadWhoseMergedPullRequestMergedpending: an open pull request leaves the beadTestMergeOrderLeavesABeadWhosePullRequestIsOpengoneandshut: assigned to the Operator,pr_closedrecorded, one mail each with its subject and textTestMergeOrderHandsABeadWhosePullRequestClosedToTheOperator(the mails are compared whole)alien: one line on stderr, the bead untouched, nopr_closed, the run does not failTestMergeOrderSkipsAForeignPullRequestWithALine(also: no request to the forge)TestMergeOrderHandsOverNothingTwiceCases the script had and the old test did not, now tested: the Operator looked up only when needed, and from the one city-scoped
operator(TestMergeOrderResolvesTheOperatorLazily,TestMergeOrderEndsTheRunWhenItCannotResolveTheOperator); a failure on one bead does not stop the others and the run exits 1 (TestMergeOrderTriesEveryBeadAndFailsTheRun,TestMergeOrderFailsTheRunWhenItCannotReadAPullRequest); the mail names the rig (TestMergeOrderMailNamesTheRigOfTheInstance). New cases cover the new shape: every bead of a pull request, one mail per merge, one bead for the Operator per pull request even over two runs and a closed Operator bead, a failed mail or record retried without a second mail, both shapes of one pull request, settled beads left alone, rows with no metadata read throughbd show, and the Operator's own bead not taken for the old shape. I checked that the last and the dedup tests fail when their guard is removed.tests/merge.shnow tests the wrapper: a missinggo, a missingPACK_DIR, the exact command it execs and its exit status, a pack whose tool does not build (non-zero, the compiler's errors, nogccall), and the real pack found throughgo tool -Cand run where the order was started.Behaviour of the old script I could not reproduce exactly
go toolcall per bead; the order reads a pull request once per run. Same answers, fewer requests.merge: <bead>: <gc's message>. The state-read failure line keeps its text and now ends with the cause (merge: <bead>: cannot read the state of <url>: <cause>) where the tool's own error was a separate line.gc,goandjqonPATH. The wrapper checksgo; a missinggcfails with the exec error asmerge: ...: executable file not found;jqis no longer used by the order.bd list).unexpected statebranch is kept, but cannot be reached: the tool answers one of five states.Why the swap is safe in the middle of a cycle, and what a city sees if the tool cannot be built
Each run of the order is its own process, started by the supervisor every 2 minutes.
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 apply order moved the city goes on with what it built, and a run that begins after builds the new; gc's pack cache holds a checkout of each locked commit (docs/shell.mdsection 5, read there, not run), so a run sees the old files or the new, not a mixture. The two versions read and write the same markers:pr_closedandgc.work_outcomeare unchanged, and each bead's marker (pr_closedormerge_result) is the last write concerning it, so a run of either version 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; one that was not waits).If the tool cannot be built where the order runs,
go toolprints the compiler's errors and exits non-zero before the tool starts, so before anything is read or written: the run fails with them on stderr, closes nothing, and the next run tries again; a missinggofails withmerge: go is not on PATH.tests/merge.shruns this against a pack whose tool does not compile and checks thatgcis not called. I did not run it under the supervisor, and I do not know what, besides gc's record of a failed order run, tells the Operator: nothing in this change mails for a failed build.Decisions for the review
pr_eventis a key of my choosing for the Operator's bead (P7 names the eventclosedand the fieldspr_urland a reason, and no key). L12 and L13 will make beads of the same kind (stuck,round_cap); they can takepr_eventas it is, or the name can change here first.missing(the forge answers "not found") is treated like one closed unmerged for the new shape:merge_result=closed, one Operator bead and mail, with "not found" in the wording. The design listsclosedonly.merge_resultof any value) each cycle, as the ticket says (3.7 f). The list grows without bound; narrowing it with--metadata-field merge_result=pull_requestis a follow-up that needs to be tried on a scratch bead first (I tried nothing on live beads). Filed as a bead.How I verified it
go vet,go test(GOPROXY=off, from the module cache),bash tests/merge.sh,gc lint ., and the changelog check built from mikluko/changelog v1.6.0 in an ordinary clone of this branch:valid=true. Nothing was run against live beads or sarak.sh. One slip to report: my first run of the newtests/merge.shinherited this session'sGC_BINand so called the realgcfor two read-onlybd lists and then failed on the repository lookup before any request or write; the test now clears the variables that could reach a real store and names its owngc.Bead: gascitypacks-hdo
Reviewed
47a0e20dc6: forgejo order merge against the old merge.sh case by case, go vet/test/-race, tests/merge.sh old and new, gc lint, changelog check.Reviewed head
47a0e20(the merge result equals it; main had not moved pastb3474d4). Merged as3e38bc3.Checked:
forgejo order mergeagainstmerge.shon main, case by case: the listing, the merged close (gc.work_outcome=shipped, thenbd close --force --reason "Pull request merged: <url>", no mail), the hand-over (assignee,--notifymail with the same subject and text,pr_closed), open, foreign, a missingpr_url, forge errors (the run fails and closes nothing), the Operator resolved lazily and the run ended when it cannot be resolved. Running twice, and a run that dies halfway, for both shapes: the dedup keys, the Operator's bead looked up in any status before it is made, the records written after the mail.bdv1.3.4 source: repeated--metadata-fieldflags are combined with AND (a map), andbd list --jsonrows carrymetadata.tests/merge.shagainst the old script, and the newtests/merge.sh,go vet,go testandgo test -race(GOPROXY=off),gc lint ., and the changelog check (mikluko/changelog v1.6.0): all pass.Differences from the old script that the description does not list:
pr state, which answeredmerged, so the bead was closed. Now the run fails on that bead every cycle and the bead stays open (TestMergeOrderFailsForAMergedPullRequestWithNoMergeCommit). This errs on the safe side, but it is a change.pr_eventset is not treated as the old shape.pr_url) as an old-shape bead: it reassigns that bead and mails once more.Not checked: a run under the supervisor; the claim that gc's pack cache keeps one checkout per commit (so a run never builds from a mixture of old and new files); gc's in-process
bd(only the bd source).Follow-ups: narrow the closed-bead listing (filed by the author); decide on the
pr_eventkey name before L12 and L13.Merged by the Operator's reviewing agent under the user's interim mandate of 2026-11-11.