Landing L9: the merge order records a merge on both shapes of bead, in Go #46

Merged
city-root merged 1 commit from worker/gascitypacks-hdo into main 2026-11-12 10:53:34 +00:00
Contributor

Landing L9 (HQ ticket root-ons.17, docs/handoffs.md in 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.sh is now a wrapper that checks go is on PATH and execs go tool -C "$PACK_DIR" forgejo order merge.
  • Old shape (an open bead with a pr_url): unchanged. Same listing, same gc.work_outcome=shipped then bd close --force --reason "Pull request merged: <url>", same hand-over to the Operator (assignee, --notify mail with the same subjects and text, pr_closed), same foreign skip line, same exit status. No mail at a merge, as before.
  • New shape (closed, merge_result=pull_request, listed by --status closed --has-metadata-key merge_result):
    • merged: merge_result=merged and merged_sha on every bead that carries the pull request's URL, and one mail to the Operator per merge (--notify --dedup merge:<url>);
    • closed unmerged, or missing: merge_result=closed on 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>).
  • The pull request is read in process with the code pr state runs on (fetchPull, which pr state now calls too): the same URL resolution, token handling, missing and foreign, 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 to pr state --json for that reason (3 requests a bead every 2 minutes, and a failing checks lookup would hold a merge record).
  • The instance for the HQ store works as it did: the store comes from GC_RIG_ROOT, else GC_CITY_PATH, else GC_CITY; GC_RIG names the rig in the mail, "the HQ store" otherwise; OPERATOR or the one city-scoped agent named operator.
  • README section "The merge order", CHANGELOG entries under [Unreleased], and the order's description.

Old test to new test

tests/merge.sh tested the script with stubs of gc and go. Each of its cases is a Go test in forgejo/assets/forgejo/order_test.go, with a fake gc (a store of beads that answers bd list, show, update, close, create, mail send and agent list, and refuses a close of an assigned bead without --force as gc does) and the forge behind httptest:

Case of tests/merge.sh Go test
held and free: a merged pull request closes the bead as shipped, whoever holds it, with gc.work_outcome=shipped TestMergeOrderClosesAnOpenBeadWhoseMergedPullRequestMerged
pending: an open pull request leaves the bead TestMergeOrderLeavesABeadWhosePullRequestIsOpen
gone and shut: assigned to the Operator, pr_closed recorded, one mail each with its subject and text TestMergeOrderHandsABeadWhosePullRequestClosedToTheOperator (the mails are compared whole)
alien: one line on stderr, the bead untouched, no pr_closed, the run does not fail TestMergeOrderSkipsAForeignPullRequestWithALine (also: no request to the forge)
the second run hands over nothing again TestMergeOrderHandsOverNothingTwice

Cases 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 through bd 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.sh now tests the wrapper: a missing go, a missing PACK_DIR, the exact command it execs and its exit status, a pack whose tool does not build (non-zero, the compiler's errors, no gc call), and the real pack found through go tool -C and run where the order was started.

Behaviour of the old script I could not reproduce exactly

  • The script made one go tool call per bead; the order reads a pull request once per run. Same answers, fewer requests.
  • gc's own stderr (for example its "served in process" line) went to the order's stderr before; the tool captures it and shows it only when a call fails, as 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.
  • A run is limited to 10 minutes; the script had none.
  • The script checked for gc, go and jq on PATH. The wrapper checks go; a missing gc fails with the exec error as merge: ...: executable file not found; jq is no longer used by the order.
  • A run with no open bead to settle used to end there; it now also lists the closed beads (a second bd list).
  • The script's unexpected state branch 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.md section 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_closed and gc.work_outcome are unchanged, and each bead's marker (pr_closed or merge_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 tool prints 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 missing go fails with merge: go is not on PATH. tests/merge.sh runs this against a pack whose tool does not compile and checks that gc is 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_event is a key of my choosing for the Operator's bead (P7 names the event closed and the fields pr_url and a reason, and no key). L12 and L13 will make beads of the same kind (stuck, round_cap); they can take pr_event as it is, or the name can change here first.
  • A pull request that is 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 lists closed only.
  • The mail for a merge goes before the records, with a dedup key, so that a mail that fails does not lose the merge's mail: a bead leaves the order's list when its record is written. A duplicate is possible only when a record fails after the mail and the Operator archived the mail before the next run.
  • The order lists every settled closed bead (merge_result of any value) each cycle, as the ticket says (3.7 f). The list grows without bound; narrowing it with --metadata-field merge_result=pull_request is 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 new tests/merge.sh inherited this session's GC_BIN and so called the real gc for two read-only bd 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 own gc.

Bead: gascitypacks-hdo

Landing L9 (HQ ticket root-ons.17, `docs/handoffs.md` in 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.sh` is now a wrapper that checks `go` is on `PATH` and execs `go tool -C "$PACK_DIR" forgejo order merge`. - **Old shape** (an open bead with a `pr_url`): unchanged. Same listing, same `gc.work_outcome=shipped` then `bd close --force --reason "Pull request merged: <url>"`, same hand-over to the Operator (assignee, `--notify` mail with the same subjects and text, `pr_closed`), same foreign skip line, same exit status. No mail at a merge, as before. - **New shape** (closed, `merge_result=pull_request`, listed by `--status closed --has-metadata-key merge_result`): - merged: `merge_result=merged` and `merged_sha` on every bead that carries the pull request's URL, and **one** mail to the Operator per merge (`--notify --dedup merge:<url>`); - closed unmerged, or missing: `merge_result=closed` on 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>`). - The pull request is read in process with the code `pr state` runs on (`fetchPull`, which `pr state` now calls too): the same URL resolution, token handling, `missing` and `foreign`, 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 to `pr state --json` for that reason (3 requests a bead every 2 minutes, and a failing checks lookup would hold a merge record). - The instance for the HQ store works as it did: the store comes from `GC_RIG_ROOT`, else `GC_CITY_PATH`, else `GC_CITY`; `GC_RIG` names the rig in the mail, "the HQ store" otherwise; `OPERATOR` or the one city-scoped agent named `operator`. - README section "The merge order", CHANGELOG entries under `[Unreleased]`, and the order's description. ## Old test to new test `tests/merge.sh` tested the script with stubs of `gc` and `go`. Each of its cases is a Go test in `forgejo/assets/forgejo/order_test.go`, with a fake `gc` (a store of beads that answers `bd list`, `show`, `update`, `close`, `create`, `mail send` and `agent list`, and refuses a close of an assigned bead without `--force` as gc does) and the forge behind `httptest`: | Case of `tests/merge.sh` | Go test | |---|---| | `held` and `free`: a merged pull request closes the bead as shipped, whoever holds it, with `gc.work_outcome=shipped` | `TestMergeOrderClosesAnOpenBeadWhoseMergedPullRequestMerged` | | `pending`: an open pull request leaves the bead | `TestMergeOrderLeavesABeadWhosePullRequestIsOpen` | | `gone` and `shut`: assigned to the Operator, `pr_closed` recorded, one mail each with its subject and text | `TestMergeOrderHandsABeadWhosePullRequestClosedToTheOperator` (the mails are compared whole) | | `alien`: one line on stderr, the bead untouched, no `pr_closed`, the run does not fail | `TestMergeOrderSkipsAForeignPullRequestWithALine` (also: no request to the forge) | | the second run hands over nothing again | `TestMergeOrderHandsOverNothingTwice` | Cases 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 through `bd 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.sh` now tests the wrapper: a missing `go`, a missing `PACK_DIR`, the exact command it execs and its exit status, a pack whose tool does not build (non-zero, the compiler's errors, **no `gc` call**), and the real pack found through `go tool -C` and run where the order was started. ## Behaviour of the old script I could not reproduce exactly - The script made one `go tool` call per bead; the order reads a pull request once per run. Same answers, fewer requests. - gc's own stderr (for example its "served in process" line) went to the order's stderr before; the tool captures it and shows it only when a call fails, as `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. - A run is limited to 10 minutes; the script had none. - The script checked for `gc`, `go` and `jq` on `PATH`. The wrapper checks `go`; a missing `gc` fails with the exec error as `merge: ...: executable file not found`; `jq` is no longer used by the order. - A run with no open bead to settle used to end there; it now also lists the closed beads (a second `bd list`). - The script's `unexpected state` branch 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.md` section 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_closed` and `gc.work_outcome` are unchanged, and each bead's marker (`pr_closed` or `merge_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 tool` prints 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 missing `go` fails with `merge: go is not on PATH`. `tests/merge.sh` runs this against a pack whose tool does not compile and checks that `gc` is 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_event` is a key of my choosing for the Operator's bead (P7 names the event `closed` and the fields `pr_url` and a reason, and no key). L12 and L13 will make beads of the same kind (`stuck`, `round_cap`); they can take `pr_event` as it is, or the name can change here first. - A pull request that is `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 lists `closed` only. - The mail for a merge goes before the records, with a dedup key, so that a mail that fails does not lose the merge's mail: a bead leaves the order's list when its record is written. A duplicate is possible only when a record fails after the mail and the Operator archived the mail before the next run. - The order lists every settled closed bead (`merge_result` of any value) each cycle, as the ticket says (3.7 f). The list grows without bound; narrowing it with `--metadata-field merge_result=pull_request` is 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 new `tests/merge.sh` inherited this session's `GC_BIN` and so called the real `gc` for two read-only `bd list`s 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 own `gc`. Bead: gascitypacks-hdo
feat(forgejo): the merge order in Go, settling both shapes of a bead (gascitypacks-hdo)
All checks were successful
test / changelog (pull_request) Successful in 4s
test / lint (pull_request) Successful in 20s
test / scripts (pull_request) Successful in 42s
47a0e20dc6
Landing L9 (HQ ticket root-ons.17) and the first script to move under the
user's direction of 2026-11-12 that this pack's logic is tested Go, not
shell. The merge order's logic becomes `forgejo order merge`, a subcommand of
the forgejo tool, and forgejo/assets/scripts/merge.sh a four-line wrapper
that execs it.

The order now handles both shapes of a bead. An open bead with a pr_url is
settled exactly as the script did (same close, same reason, same mails, same
pr_closed marker). A bead closed at the pull request's opening, with
merge_result=pull_request (listed by --status closed --has-metadata-key
merge_result, handoffs 3.7 f), gets merge_result=merged and merged_sha on it
and on every bead of its pull request, with one mail to the Operator per
merge; a pull request closed unmerged or gone gets merge_result=closed, one
bead for the Operator per pull request (P7) and one mail. The pull request is
read in-process with the code pr state runs on, once per run, without its
checks and reviews.

Decisions worth a look in review: the mail for a merge goes before the
records, with a dedup key, because a bead leaves the list when its record is
written; the Operator's bead is searched for in any status before one is made
(metadata pr_event=closed and pr_url), so a run that failed after making it
makes no second; and a bead that carries pr_event is skipped by the scan of
the old shape, which would otherwise take the Operator's own bead, open and
with a pr_url, for work that follows its pull request.

Validation: every case of tests/merge.sh is a Go test with a fake of gc and
the forge behind httptest (the mapping is in the pull request); tests/merge.sh
now tests the wrapper, including a pack whose tool does not build (non-zero
exit, no gc call). go vet, go test, gc lint.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
city-root-review left a comment

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 47a0e20dc67d87d5a86a8a9669fb771e2d33af82: 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.
Author
Contributor

Reviewed head 47a0e20 (the merge result equals it; main had not moved past b3474d4). Merged as 3e38bc3.

Checked:

  • forgejo order merge against merge.sh on main, case by case: the listing, the merged close (gc.work_outcome=shipped, then bd close --force --reason "Pull request merged: <url>", no mail), the hand-over (assignee, --notify mail with the same subject and text, pr_closed), open, foreign, a missing pr_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.
  • bd v1.3.4 source: repeated --metadata-field flags are combined with AND (a map), and bd list --json rows carry metadata.
  • Ran the old tests/merge.sh against the old script, and the new tests/merge.sh, go vet, go test and go 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:

  • Old shape: a pull request the forge reports merged with no merge commit. The old script used plain pr state, which answered merged, 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.
  • An open bead with pr_event set is not treated as the old shape.
  • If the old import is put back, the old script treats an Operator bead of the new shape (open, with 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_event key name before L12 and L13.

Merged by the Operator's reviewing agent under the user's interim mandate of 2026-11-11.

Reviewed head 47a0e20 (the merge result equals it; main had not moved past b3474d4). Merged as 3e38bc3. Checked: - `forgejo order merge` against `merge.sh` on main, case by case: the listing, the merged close (`gc.work_outcome=shipped`, then `bd close --force --reason "Pull request merged: <url>"`, no mail), the hand-over (assignee, `--notify` mail with the same subject and text, `pr_closed`), open, foreign, a missing `pr_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. - `bd` v1.3.4 source: repeated `--metadata-field` flags are combined with AND (a map), and `bd list --json` rows carry `metadata`. - Ran the old `tests/merge.sh` against the old script, and the new `tests/merge.sh`, `go vet`, `go test` and `go 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: - Old shape: a pull request the forge reports merged with no merge commit. The old script used plain `pr state`, which answered `merged`, 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. - An open bead with `pr_event` set is not treated as the old shape. - If the old import is put back, the old script treats an Operator bead of the new shape (open, with `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_event` key name before L12 and L13. Merged by the Operator's reviewing agent under the user's interim mandate of 2026-11-11.
Commenting is not possible because the repository is archived.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
mikluko/gascitypacks!46
No description provided.