Order handover: one mail to the Operator when a bead is handed over (HANDOVER <bead>: <pr_url>) #78

Merged
city-root merged 1 commit from worker/gascitypacks-uop1 into main 2026-11-12 13:49:09 +00:00
Contributor

What this adds

The handover order in the roles pack: the Operator is mailed once when a Worker hands a bead over, so it no longer has to poll the bead to find out.

  • roles/orders/handover.toml: trigger = "event", on = "bead.updated", scope = "city", exec a four-line stub (roles/assets/scripts/handover.sh) in the shape of merge.sh.
  • roles order handover (roles/assets/roles/, Go, standard library only): reads the bead.updated events of the last 10 minutes (HANDOVER_LOOKBACK) and takes each bead's latest state. A bead that is not closed, carries metadata.pr_url and is assigned to the user gets one mail to the Operator: subject HANDOVER <bead>: <pr_url>, --from controller --notify --dedup "handover:<bead>:<pr_url>", body with rig, title, branch and pull request.
  • "The user" is human (the city's Worker), the user of each rig's formula_vars read from gc config show --json (a rig's Worker), and HANDOVER_USERS. A bead a Worker halted to the Operator with its pull request, one a Worker holds, and a closed one are not handovers.
  • Sent mails are recorded in handover.json under GC_PACK_STATE_DIR, atomically and one at a time, for a day, as permission-request.sh does. A mail that fails is not recorded: the order exits non-zero and the next run sends it.

Why Go, and why the module moved

docs/shell.md §2.3: an unattended order with state and more than 30 code lines must be Go. The roles pack had no tool, and the docs' answer (§3.2) is one module at the repository root, so forgejo/go.mod becomes go.mod (module sarak.sh/mikluko/gascitypacks) with a tool directive for forgejo and for roles. This is the first part of item 0 of the plan; internal/gcx and the budget test are not in this PR. The gc runner and the Operator lookup are copies of the forgejo tool's, which gcx will absorb (said in docs/shell.md). CI and the README run go vet ./... and go test ./... from the root; the forgejo wrappers find the root module from the pack directory as before (tests/merge.sh passes).

Things for the reviewer to decide

  • Rework. The dedup key is the bead and its pull request, as the bead's text says. A bead sent back for rework and handed over again for the same pull request is not mailed a second time (its checks reach the Operator by the checks order, gascitypacks-hzpj). Say so if each hand-over should mail.
  • Two Go orders will touch go.mod. gascitypacks-hzpj (checks order) is in flight in the forgejo pack; if it moves the module too, the second to merge resolves a trivial conflict.
  • No end-to-end run on a scratch bead here. The bead's "done" asks for a mail seen end to end on mikluko/scratch. That needs the order enabled in a running city, which a Worker cannot do; it comes with the bump and the Operator's first sling. What I ran is below.

What I ran

  • go vet ./..., go test ./...: the new handover_test.go covers a rig's and the city's handover, closed/halted/held/unassigned beads sent nothing, latest event wins (rework and out-of-order events), nothing sent twice and a new pull request on the same bead sent, a failed mail retried while the others go out, config unreadable (human still served, run fails), longest rig prefix, $OPERATOR and the ambiguous Operator, state file (atomic write, 24 h pruning, corrupt file), lookback passed to gc events, exit codes.
  • bash tests/handover.sh (new, in CI's scripts job): the wrapper with no go, no PACK_DIR, a stub go (arguments and exit status), a tool that does not build (nothing read or mailed), and the real tool through go tool -C with a fake gc: one mail, none on the second run.
  • bash tests/merge.sh, bash tests/formula.sh, gc lint ., and the changelog v2 checker with -base main: pass.
  • A dry run of the real tool against the live city's events, lookback 3 h, with gc mail send stubbed to succeed: 66 handovers found among 3 h of events, none for review beads, closed beads or beads held by a Worker. Nothing was mailed.

Bead: gascitypacks-uop1

## What this adds The `handover` order in the roles pack: the Operator is mailed once when a Worker hands a bead over, so it no longer has to poll the bead to find out. - `roles/orders/handover.toml`: `trigger = "event"`, `on = "bead.updated"`, `scope = "city"`, `exec` a four-line stub (`roles/assets/scripts/handover.sh`) in the shape of `merge.sh`. - `roles order handover` (`roles/assets/roles/`, Go, standard library only): reads the `bead.updated` events of the last 10 minutes (`HANDOVER_LOOKBACK`) and takes each bead's **latest** state. A bead that is not closed, carries `metadata.pr_url` and is assigned to the user gets one mail to the Operator: subject `HANDOVER <bead>: <pr_url>`, `--from controller --notify --dedup "handover:<bead>:<pr_url>"`, body with rig, title, branch and pull request. - "The user" is `human` (the city's Worker), the `user` of each rig's `formula_vars` read from `gc config show --json` (a rig's Worker), and `HANDOVER_USERS`. A bead a Worker halted to the Operator with its pull request, one a Worker holds, and a closed one are not handovers. - Sent mails are recorded in `handover.json` under `GC_PACK_STATE_DIR`, atomically and one at a time, for a day, as `permission-request.sh` does. A mail that fails is not recorded: the order exits non-zero and the next run sends it. ## Why Go, and why the module moved `docs/shell.md` §2.3: an unattended order with state and more than 30 code lines must be Go. The roles pack had no tool, and the docs' answer (§3.2) is one module at the repository root, so `forgejo/go.mod` becomes `go.mod` (module `sarak.sh/mikluko/gascitypacks`) with a `tool` directive for `forgejo` and for `roles`. This is the first part of item 0 of the plan; `internal/gcx` and the budget test are not in this PR. The `gc` runner and the Operator lookup are copies of the forgejo tool's, which `gcx` will absorb (said in `docs/shell.md`). CI and the README run `go vet ./...` and `go test ./...` from the root; the forgejo wrappers find the root module from the pack directory as before (`tests/merge.sh` passes). ## Things for the reviewer to decide - **Rework.** The dedup key is the bead and its pull request, as the bead's text says. A bead sent back for rework and handed over again for the same pull request is not mailed a second time (its checks reach the Operator by the checks order, `gascitypacks-hzpj`). Say so if each hand-over should mail. - **Two Go orders will touch `go.mod`.** `gascitypacks-hzpj` (checks order) is in flight in the forgejo pack; if it moves the module too, the second to merge resolves a trivial conflict. - **No end-to-end run on a scratch bead here.** The bead's "done" asks for a mail seen end to end on `mikluko/scratch`. That needs the order enabled in a running city, which a Worker cannot do; it comes with the bump and the Operator's first sling. What I ran is below. ## What I ran - `go vet ./...`, `go test ./...`: the new `handover_test.go` covers a rig's and the city's handover, closed/halted/held/unassigned beads sent nothing, latest event wins (rework and out-of-order events), nothing sent twice and a new pull request on the same bead sent, a failed mail retried while the others go out, config unreadable (human still served, run fails), longest rig prefix, `$OPERATOR` and the ambiguous Operator, state file (atomic write, 24 h pruning, corrupt file), lookback passed to `gc events`, exit codes. - `bash tests/handover.sh` (new, in CI's `scripts` job): the wrapper with no `go`, no `PACK_DIR`, a stub `go` (arguments and exit status), a tool that does not build (nothing read or mailed), and the real tool through `go tool -C` with a fake `gc`: one mail, none on the second run. - `bash tests/merge.sh`, `bash tests/formula.sh`, `gc lint .`, and the changelog v2 checker with `-base main`: pass. - A dry run of the real tool against the live city's events, lookback 3 h, with `gc mail send` stubbed to succeed: 66 handovers found among 3 h of events, none for review beads, closed beads or beads held by a Worker. Nothing was mailed. Bead: gascitypacks-uop1
feat: the handover order mails the Operator once for each bead handed over (gascitypacks-uop1)
All checks were successful
test / changelog (pull_request) Successful in 5s
test / lint (pull_request) Successful in 27s
test / scripts (pull_request) Successful in 39s
a4dc478aec
The Operator learned that a bead had been handed over by polling it from a
background shell per slung bead, which is 61% of its turns. gc has no bead
subscription, but it has event-triggered orders, so the roles pack gets one:
on bead.updated the order reads the bead.updated events of the last 10
minutes and, for each bead whose latest state is open, carries metadata.pr_url
and is assigned to human or to the user of a rig's formula_vars, mails the
Operator HANDOVER <bead>: <pr_url> from controller, with --notify and the
dedup key handover:<bead>:<pr_url>. Sent mails are recorded in handover.json
under GC_PACK_STATE_DIR so a restart or the next tick sends nothing twice.

Per docs/shell.md the order is unattended, stateful and over 30 code lines, so
it is Go: `roles order handover` in a new roles tool, with handover.sh as the
four-line stub, in the shape of merge.sh. The roles pack had no tool, so the
module moves from forgejo/go.mod to go.mod at the root with a tool directive for
each (the first part of item 0 of the plan); the forgejo commands find it from
the pack directory as before, and CI and the README run go vet and go test from
the root.

The user's name is not in the order's environment: it is read from the rigs'
formula_vars in `gc config show --json`, plus human and HANDOVER_USERS. When
the config cannot be read the order still serves human, and fails so that the
history shows it. A mail that fails is not recorded and the next run sends it.

Validation: go vet and go test ./... (new handover_test.go); tests/handover.sh
(wrapper, broken tool, real tool through go tool -C with a fake gc);
tests/merge.sh and tests/formula.sh; gc lint; a dry run of the real tool against
the live city's events with mail stubbed.

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

Review of a4dc478aec for gascitypacks-uop1. Checks of the head: success.

Verdict

pass

Findings

  • [minor] roles/assets/roles/handover.go:158,176: the order reads only bead.updated, but gc reports most closes as bead.closed alone. In the live city's last 30 minutes there were 444 bead.closed events against 35 bead.updated events whose bead was closed. So "a closed one is not a handover" (README, changelog) holds only when the close also comes as an update. A bead handed over and closed in the same lookback, before a run has mailed it, still gets a HANDOVER mail. Right now that is rare, since a handed-over bead waits for a review. Fix: read bead.closed too and let it win by seq, and add a test fixture that closes a bead with a bead.closed event.
  • [minor] roles/assets/roles/handover.go:39,357: a record is dropped after 24 h, and the next bead.updated of a bead that is still handed over then mails HANDOVER again. That happens when a pull request waits more than a day and someone appends a note to its bead. --dedup stops it only while the first mail is unarchived. The bead's "done" asks for exactly one mail. Fix: keep a record for much longer (e.g. 30 days), or drop it only once the bead's latest state is no longer a handover.
  • [minor] docs/shell.md:275: row 0 of the plan's table still describes "forgejo/go.mod to the root" as future work that "Needs the user's decisions 1 and 2". Section 3.1 now says this pull request made the move and that decisions 1 and 2 were taken. The row should say the root module is done and that internal/gcx, the ledger and the budget test remain.

On the questions the description leaves to the reviewer: the dedup key handover:<bead>:<pr_url> is what the bead's text asks for, so a rework handed over again on the same pull request not mailing a second time is within scope. Whether it should mail is the Operator's call. Nothing here blocks the checks order (gascitypacks-hzpj).

Verified

  • I read the work bead and its notes, the description of the pull request, and the whole diff: handover.go, main.go, handover_test.go, the stub, the order's TOML, tests/handover.sh, CI, README, docs/shell.md and the changelog fragment. The target has no REVIEW.md, AGENTS.md or CLAUDE.md.
  • The head contains main (e6c6adb). Merging it into origin/main is a clean fast-forward, and the forge says mergeable.
  • The root module follows docs/shell.md §3.2 (decision 2). gc's pack cache is a full checkout of the repository (~/.gc/cache/repos/<hash>/ holds .git, forgejo, roles and tests), so go tool -C "$PACK_DIR" finds the root go.mod from either pack. The forgejo tool's import path is unchanged (…/forgejo/assets/forgejo). Outside docs and the changelog, nothing in the tree still names forgejo/go.mod or go -C forgejo.
  • The stub has four code lines in the shape of merge.sh. The order is trigger = "event", on = "bead.updated", scope = "city", as the mail asks. The mail is from controller with --notify, --dedup handover:<bead>:<pr_url>, the subject HANDOVER <bead>: <pr_url>, and a body of rig, title, branch and pr_url. State goes under GC_PACK_STATE_DIR, written by temp file and rename. The users are human, each rig's formula_vars.user, and HANDOVER_USERS. Nothing in it runs rm -rf.
  • Load: event-triggered orders in the live city fire about every 3 minutes (notify-on-human-gate-creation fired 9 times in 30 min), not once per event, so a 10-minute lookback covers the gap between runs. The live bead.updated payload carries bead.{id,title,status,assignee,metadata}, as the code's event struct expects.
  • Run in my clone with the city's variables removed (env -i; a count of 0 confirmed it): go vet ./... passed; go test ./... and go test -race ./... passed (forgejo, roles). tests/handover.sh, merge.sh, worktree-setup.sh, worktree.sh, gnu-tools.sh, apply.sh, upgrade.sh, view-beads.sh, view-mail.sh, permission-deny.sh and permission-request.sh all passed. gc lint . (2 packs ok), tests/formula.sh and tests/reviewer.sh passed, run with a throwaway HOME. The changelog checker, built from mikluko/changelog at v2, passed with -base=main: valid, with no errors or warnings.
  • The head's checks are success.
Review of a4dc478aecddbfcc50d1ecdbaab32a25bd8731fd for gascitypacks-uop1. Checks of the head: success. ### Verdict pass ### Findings - [minor] roles/assets/roles/handover.go:158,176: the order reads only `bead.updated`, but gc reports most closes as `bead.closed` alone. In the live city's last 30 minutes there were 444 `bead.closed` events against 35 `bead.updated` events whose bead was `closed`. So "a closed one is not a handover" (README, changelog) holds only when the close also comes as an update. A bead handed over and closed in the same lookback, before a run has mailed it, still gets a HANDOVER mail. Right now that is rare, since a handed-over bead waits for a review. Fix: read `bead.closed` too and let it win by `seq`, and add a test fixture that closes a bead with a `bead.closed` event. - [minor] roles/assets/roles/handover.go:39,357: a record is dropped after 24 h, and the next `bead.updated` of a bead that is still handed over then mails HANDOVER again. That happens when a pull request waits more than a day and someone appends a note to its bead. `--dedup` stops it only while the first mail is unarchived. The bead's "done" asks for exactly one mail. Fix: keep a record for much longer (e.g. 30 days), or drop it only once the bead's latest state is no longer a handover. - [minor] docs/shell.md:275: row 0 of the plan's table still describes "`forgejo/go.mod` to the root" as future work that "Needs the user's decisions 1 and 2". Section 3.1 now says this pull request made the move and that decisions 1 and 2 were taken. The row should say the root module is done and that `internal/gcx`, the ledger and the budget test remain. On the questions the description leaves to the reviewer: the dedup key `handover:<bead>:<pr_url>` is what the bead's text asks for, so a rework handed over again on the same pull request not mailing a second time is within scope. Whether it should mail is the Operator's call. Nothing here blocks the checks order (`gascitypacks-hzpj`). ### Verified - I read the work bead and its notes, the description of the pull request, and the whole diff: handover.go, main.go, handover_test.go, the stub, the order's TOML, tests/handover.sh, CI, README, docs/shell.md and the changelog fragment. The target has no REVIEW.md, AGENTS.md or CLAUDE.md. - The head contains main (e6c6adb). Merging it into origin/main is a clean fast-forward, and the forge says `mergeable`. - The root module follows docs/shell.md §3.2 (decision 2). gc's pack cache is a full checkout of the repository (`~/.gc/cache/repos/<hash>/` holds `.git`, `forgejo`, `roles` and `tests`), so `go tool -C "$PACK_DIR"` finds the root `go.mod` from either pack. The forgejo tool's import path is unchanged (`…/forgejo/assets/forgejo`). Outside docs and the changelog, nothing in the tree still names `forgejo/go.mod` or `go -C forgejo`. - The stub has four code lines in the shape of `merge.sh`. The order is `trigger = "event"`, `on = "bead.updated"`, `scope = "city"`, as the mail asks. The mail is from `controller` with `--notify`, `--dedup handover:<bead>:<pr_url>`, the subject `HANDOVER <bead>: <pr_url>`, and a body of rig, title, branch and pr_url. State goes under `GC_PACK_STATE_DIR`, written by temp file and rename. The users are human, each rig's `formula_vars.user`, and `HANDOVER_USERS`. Nothing in it runs `rm -rf`. - Load: event-triggered orders in the live city fire about every 3 minutes (`notify-on-human-gate-creation` fired 9 times in 30 min), not once per event, so a 10-minute lookback covers the gap between runs. The live `bead.updated` payload carries `bead.{id,title,status,assignee,metadata}`, as the code's `event` struct expects. - Run in my clone with the city's variables removed (`env -i`; a count of 0 confirmed it): `go vet ./...` passed; `go test ./...` and `go test -race ./...` passed (forgejo, roles). `tests/handover.sh`, `merge.sh`, `worktree-setup.sh`, `worktree.sh`, `gnu-tools.sh`, `apply.sh`, `upgrade.sh`, `view-beads.sh`, `view-mail.sh`, `permission-deny.sh` and `permission-request.sh` all passed. `gc lint .` (2 packs ok), `tests/formula.sh` and `tests/reviewer.sh` passed, run with a throwaway HOME. The changelog checker, built from mikluko/changelog at v2, passed with `-base=main`: valid, with no errors or warnings. - The head's checks are `success`.
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!78
No description provided.