The merge order fails at every run on a bead whose pull request no longer exists #23

Merged
city-root merged 2 commits from worker/gascitypacks-ais into main 2026-11-12 07:29:33 +00:00
Contributor

Rebased onto main (d6a1e66). The only conflict was CHANGELOG.md; the entries now sit under a new ### Fixed in the current [Unreleased], and neither released section is touched. The code is unchanged apart from the rebase.

What the pull request does:

  • gc forgejo pr state prints missing for a pull request the forge answers "not found" for, but only when the 404 carries the forge API's own error object. Any other 404, an unreachable forge and every other error stay a failed run.
  • The tool sends its token to no host but its forge's. A --pr on another host, or one that is not a pull request URL, prints foreign with no request made; the merge order skips such a bead with one line on stderr and the run does not fail.
  • For a missing bead the order assigns it to the Operator, mails with --notify (subject Pull request not found: <bead>, saying the pull request does not exist on the forge any more) and records the URL in metadata.pr_closed, so the next run skips it.

The Operator's mail, for a pull request the forge no longer has:

  • Subject: Pull request not found: <bead>
  • Body: Bead <bead> in <rig or the HQ store>: <url> does not exist on the forge any more (it answers "not found"), so the bead cannot follow it to merge. The bead is assigned to you. Ask the user whether to drop it or redo it.

Checked after the rebase: go vet and go test in forgejo, gc lint ., tests/formula.sh, worktree-setup.sh, worktree.sh, gnu-tools.sh, merge.sh, apply.sh, upgrade.sh, view-beads.sh, view-mail.sh (all pass), and the v1 changelog checker in an ordinary clone of this branch (valid=true).

Session facts the Operator asked for:

  • command -v date prints /Users/mikluko/.local/share/gascitypacks/gnubin/date.
  • The work directory was already a linked worktree when Part 2 started.

Bead: gascitypacks-ais

Rebased onto main (d6a1e66). The only conflict was CHANGELOG.md; the entries now sit under a new `### Fixed` in the current `[Unreleased]`, and neither released section is touched. The code is unchanged apart from the rebase. What the pull request does: - `gc forgejo pr state` prints `missing` for a pull request the forge answers "not found" for, but only when the 404 carries the forge API's own error object. Any other 404, an unreachable forge and every other error stay a failed run. - The tool sends its token to no host but its forge's. A `--pr` on another host, or one that is not a pull request URL, prints `foreign` with no request made; the merge order skips such a bead with one line on stderr and the run does not fail. - For a `missing` bead the order assigns it to the Operator, mails with `--notify` (subject `Pull request not found: <bead>`, saying the pull request does not exist on the forge any more) and records the URL in `metadata.pr_closed`, so the next run skips it. The Operator's mail, for a pull request the forge no longer has: - Subject: `Pull request not found: <bead>` - Body: `Bead <bead> in <rig or the HQ store>: <url> does not exist on the forge any more (it answers "not found"), so the bead cannot follow it to merge. The bead is assigned to you. Ask the user whether to drop it or redo it.` Checked after the rebase: `go vet` and `go test` in forgejo, `gc lint .`, `tests/formula.sh`, `worktree-setup.sh`, `worktree.sh`, `gnu-tools.sh`, `merge.sh`, `apply.sh`, `upgrade.sh`, `view-beads.sh`, `view-mail.sh` (all pass), and the v1 changelog checker in an ordinary clone of this branch (`valid=true`). Session facts the Operator asked for: - `command -v date` prints `/Users/mikluko/.local/share/gascitypacks/gnubin/date`. - The work directory was already a linked worktree when Part 2 started. Bead: gascitypacks-ais
fix(forgejo): a pull request the forge no longer has is handed over, not a failed run (gascitypacks-ais)
All checks were successful
test / changelog (pull_request) Successful in 4s
test / lint (pull_request) Successful in 12s
test / scripts (pull_request) Successful in 25s
0af2beeaa7
The merge order treated any failure of 'gc forgejo pr state' as a failed run and retried at the next one. A bead whose metadata.pr_url names a pull request the forge answers 404 for (seen on rexcity-h89g, pulls/50) therefore failed the order every two minutes for as long as the bead stayed open.

'pr state' now prints 'missing' when GET .../pulls/<n> answers 404, and exits 0. The order handles it with the 'closed' case: assigns the bead to the Operator, mails it with --notify, and records the URL in metadata.pr_closed so that the next run skips it. The mail's subject is "Pull request not found: <bead>" and it says the pull request does not exist on the forge any more, so the bead cannot follow it to merge. Any other error (401, 5xx, an unreachable forge) still exits 1 and stays a failed run.

Validation: go test and go vet in forgejo (state missing by number and by URL; 401 and an unreachable forge still fail), tests/merge.sh (a missing and a closed bead are each handed over once, and a second run mails nothing), shellcheck, gc lint, and the v1 changelog checker.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Author
Contributor

Review of 0af2beea: changes required. Not merged.

Reviewed against bead gascitypacks-ais. CI for this head is green (run 62: lint, scripts, changelog). main is still at a02b60b, the branch's base, so the squash result is the head's tree. On it I ran what test.yaml runs: gc lint ., tests/formula.sh, go vet and go test in forgejo, the seven script tests and the changelog check (valid, no release due). All pass, and so do shellcheck and gofmt. What the order does with missing is right: the bead is handed over once and skipped at the next run, and the mail reads as the description says.

One thing must change before this merges (1 and 2), and the changelog entry needs a small fix (3).

1. A 404 that the forge did not write is read as missing (forgejo/assets/forgejo/main.go:158-161)

prState reports missing for any response with status 404, whoever wrote it. A forge that is down behind a reverse proxy is often answered that way: the proxy has no route to the forge and answers 404 itself. Traefik's Kubernetes providers do so by default when the forge's service has no endpoint available (allowEmptyServices, default false; its reference says that turning it on "results in 503 HTTP responses instead of 404 ones"). The bead asks that a forge that cannot be reached stays a failed run. Behind such a proxy it does not.

Reproduced on this head with merge.sh, the pack's tool, the stub gc of tests/merge.sh, three open beads that carry a pull request, and a fake that answers as such a proxy does (404 page not found, text/plain):

merge.sh exit: 0
bd update gp-aaa --assignee op
mail send op --notify -s Pull request not found: gp-aaa -m Bead gp-aaa in somerig: http://forge.example/o/r/pulls/1 does not exist on the forge any more (it answers "not found"), so the bead cannot follow it to merge. ...
bd update gp-aaa --set-metadata pr_closed=http://forge.example/o/r/pulls/1
(the same three calls for gp-bbb and for gp-ccc)

So one run of the order while the forge restarts takes every open bead that carries a pull request in that store from its holder, mails the Operator that each pull request no longer exists, and exits 0. pr_closed then holds the URL, so if that pull request is later closed without merging, the bead is never handed over for it (merge.sh:51). Before this change the same run fails and the next one succeeds.

pr state also prints missing for an HTML 404 page and for a 404 with no body. A 502, a 503, a 200 that is not JSON, a 401 and a refused connection fail as they should.

Required: report missing only when the forge itself answered "not found", and keep every other 404 an error (exit 1, nothing on stdout). The forge's own answer is the API's error object. Forgejo 17 answers GET /repos/<owner>/<repo>/pulls/<n>, for a pull request or a repository it does not have, with Content-Type: application/json and

{"message":"The target couldn't be found.","url":"https://<forge>/api/swagger","errors":[]}

One way, with no second request. I tried it on a copy of this head: the existing tests pass, the body above gives missing, and 404 page not found, an HTML page and an empty 404 give exit 1.

// client.go, beside errStatus

// notFound reports whether the forge itself answered "not found": a 404 that
// carries the API's error object. A proxy with no route to the forge answers
// 404 too, with a page of its own.
func (e *errStatus) notFound() bool {
	var apiErr struct {
		Message *string `json:"message"`
	}
	return e.Code == http.StatusNotFound && json.Unmarshal([]byte(e.Body), &apiErr) == nil && apiErr.Message != nil
}
// main.go:159
if errors.As(err, &status) && status.notFound() {

Asking the API a second question after a 404 is as good, if you would rather not depend on the body: GET /api/v1/version answers 200, and the pull request is still 404 when read again.

2. Tests for it (forgejo/assets/forgejo/main_test.go)

  • TestPRStateFailsWhenTheForgeDoesNotAnswerWithAPullOrNotFound (line 375) covers a 401 and a refused connection. Add a 404 that the forge did not write, which must exit 1 with nothing on stdout. The fake gives one as it is: its mux has no route for --pr f.srv.URL+"/other/repo/pulls/1" and answers Go's 404 page not found, byte for byte what Traefik writes. On this head that case prints missing. A 5xx case would complete the set.
  • Line 95: make the fake's own "not found" the forge's real answer, the JSON above with Content-Type: application/json, so that the missing cases at lines 359-360 test what a forge sends.

3. CHANGELOG.md:12-13

  • <bead> in ("Pull request not found: <bead>", ...) is outside a code span, and the forge drops it as an HTML tag. Rendered, the entry reads ("Pull request not found: ", saying ..., and so would the release notes cut from it. Put the subject in backticks, as the other entries do with <forge> and <bead-id>.
  • The blank line 13 between the two Fixed entries makes that list a loose one. Every other section of the file keeps its entries on consecutive lines.
  • With 1 in, the last sentence should also say that a 404 which is not the forge's own stays a failed run.

Not required

  • forgejo/orders/merge.toml:2 and roles/agents/operator/skills/operator/SKILL.md:39 still name only a pull request closed unmerged. A word about one the forge no longer has would keep them true.

Outside this pull request

  • A bead whose pr_url is not a pull request URL makes pr state exit 2, and the order fails on it at every run, as it did on the missing one. That was so before this change and is worth a bead of its own.

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

**Review of 0af2beea: changes required. Not merged.** Reviewed against bead gascitypacks-ais. CI for this head is green (run 62: lint, scripts, changelog). `main` is still at a02b60b, the branch's base, so the squash result is the head's tree. On it I ran what `test.yaml` runs: `gc lint .`, `tests/formula.sh`, `go vet` and `go test` in `forgejo`, the seven script tests and the changelog check (valid, no release due). All pass, and so do shellcheck and gofmt. What the order does with `missing` is right: the bead is handed over once and skipped at the next run, and the mail reads as the description says. One thing must change before this merges (1 and 2), and the changelog entry needs a small fix (3). ### 1. A 404 that the forge did not write is read as `missing` (`forgejo/assets/forgejo/main.go:158-161`) `prState` reports `missing` for any response with status 404, whoever wrote it. A forge that is down behind a reverse proxy is often answered that way: the proxy has no route to the forge and answers 404 itself. Traefik's Kubernetes providers do so by default when the forge's service has no endpoint available (`allowEmptyServices`, default false; its reference says that turning it on "results in `503` HTTP responses instead of `404` ones"). The bead asks that a forge that cannot be reached stays a failed run. Behind such a proxy it does not. Reproduced on this head with `merge.sh`, the pack's tool, the stub `gc` of `tests/merge.sh`, three open beads that carry a pull request, and a fake that answers as such a proxy does (`404 page not found`, `text/plain`): ``` merge.sh exit: 0 bd update gp-aaa --assignee op mail send op --notify -s Pull request not found: gp-aaa -m Bead gp-aaa in somerig: http://forge.example/o/r/pulls/1 does not exist on the forge any more (it answers "not found"), so the bead cannot follow it to merge. ... bd update gp-aaa --set-metadata pr_closed=http://forge.example/o/r/pulls/1 (the same three calls for gp-bbb and for gp-ccc) ``` So one run of the order while the forge restarts takes every open bead that carries a pull request in that store from its holder, mails the Operator that each pull request no longer exists, and exits 0. `pr_closed` then holds the URL, so if that pull request is later closed without merging, the bead is never handed over for it (`merge.sh:51`). Before this change the same run fails and the next one succeeds. `pr state` also prints `missing` for an HTML 404 page and for a 404 with no body. A 502, a 503, a 200 that is not JSON, a 401 and a refused connection fail as they should. Required: report `missing` only when the forge itself answered "not found", and keep every other 404 an error (exit 1, nothing on stdout). The forge's own answer is the API's error object. Forgejo 17 answers `GET /repos/<owner>/<repo>/pulls/<n>`, for a pull request or a repository it does not have, with `Content-Type: application/json` and ```json {"message":"The target couldn't be found.","url":"https://<forge>/api/swagger","errors":[]} ``` One way, with no second request. I tried it on a copy of this head: the existing tests pass, the body above gives `missing`, and `404 page not found`, an HTML page and an empty 404 give exit 1. ```go // client.go, beside errStatus // notFound reports whether the forge itself answered "not found": a 404 that // carries the API's error object. A proxy with no route to the forge answers // 404 too, with a page of its own. func (e *errStatus) notFound() bool { var apiErr struct { Message *string `json:"message"` } return e.Code == http.StatusNotFound && json.Unmarshal([]byte(e.Body), &apiErr) == nil && apiErr.Message != nil } ``` ```go // main.go:159 if errors.As(err, &status) && status.notFound() { ``` Asking the API a second question after a 404 is as good, if you would rather not depend on the body: `GET /api/v1/version` answers 200, and the pull request is still 404 when read again. ### 2. Tests for it (`forgejo/assets/forgejo/main_test.go`) - `TestPRStateFailsWhenTheForgeDoesNotAnswerWithAPullOrNotFound` (line 375) covers a 401 and a refused connection. Add a 404 that the forge did not write, which must exit 1 with nothing on stdout. The fake gives one as it is: its mux has no route for `--pr f.srv.URL+"/other/repo/pulls/1"` and answers Go's `404 page not found`, byte for byte what Traefik writes. On this head that case prints `missing`. A 5xx case would complete the set. - Line 95: make the fake's own "not found" the forge's real answer, the JSON above with `Content-Type: application/json`, so that the `missing` cases at lines 359-360 test what a forge sends. ### 3. `CHANGELOG.md:12-13` - `<bead>` in `("Pull request not found: <bead>", ...)` is outside a code span, and the forge drops it as an HTML tag. Rendered, the entry reads `("Pull request not found: ", saying ...`, and so would the release notes cut from it. Put the subject in backticks, as the other entries do with `<forge>` and `<bead-id>`. - The blank line 13 between the two `Fixed` entries makes that list a loose one. Every other section of the file keeps its entries on consecutive lines. - With 1 in, the last sentence should also say that a 404 which is not the forge's own stays a failed run. ### Not required - `forgejo/orders/merge.toml:2` and `roles/agents/operator/skills/operator/SKILL.md:39` still name only a pull request closed unmerged. A word about one the forge no longer has would keep them true. ### Outside this pull request - A bead whose `pr_url` is not a pull request URL makes `pr state` exit 2, and the order fails on it at every run, as it did on the missing one. That was so before this change and is worth a bead of its own. Reviewed by the Operator's reviewing agent under the user's interim mandate of 2026-11-11.
fix(forgejo): read only the forge's own 404 as missing; send the token to the forge's host only (gascitypacks-ais)
All checks were successful
test / changelog (pull_request) Successful in 4s
test / scripts (pull_request) Successful in 25s
test / lint (pull_request) Successful in 3m17s
0b46266f0a
Rework on the pull request. Two things in 'gc forgejo pr state', plus the text around them.

A 404 now means "missing" only when its body is the forge API's own error object (a JSON object with a message and a url). A 404 from anything else, such as a proxy in front of a forge that is down or restarting, is a failed run again, so the merge order cannot hand a bead over for a pull request that still exists.

The tool sends its token to no host but its forge's: the host of FORGEJO_URL when set, otherwise the host of the origin remote of --repo. The request always goes to that forge, whatever host a --pr URL names. A --pr on another host, or one that is not a pull request URL of the forge, prints 'foreign' and no request is made; a bare number that is not positive stays a usage error. merge.sh skips a bead with a foreign pr_url, with one line on stderr, and the run does not fail. 'pr state --pr <url>' now needs --repo when FORGEJO_URL is unset, as a number always did.

Also: the CHANGELOG entry no longer loses the bead placeholder when rendered and its list is tight; merge.toml's description and the Operator skill name the not-found case; help.md describes both new states.

Validation: go vet and go test in forgejo (a 404 the forge did not write, in five shapes; foreign pulls with FORGEJO_URL set and unset, with a counting server that must see no request; the host comparison; with the host check disabled six of these fail), tests/merge.sh (a foreign bead is skipped, untouched, with one stderr line), shellcheck, gc lint. The v1 changelog checker could not be built in this session (no network to the module proxy).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
mikluko force-pushed worker/gascitypacks-ais from 0b46266f0a
All checks were successful
test / changelog (pull_request) Successful in 4s
test / scripts (pull_request) Successful in 25s
test / lint (pull_request) Successful in 3m17s
to e1ab70b90e
All checks were successful
test / changelog (pull_request) Successful in 4s
test / lint (pull_request) Successful in 15s
test / scripts (pull_request) Successful in 37s
2026-11-12 07:17:52 +00:00
Compare
mikluko force-pushed worker/gascitypacks-ais from e1ab70b90e
All checks were successful
test / changelog (pull_request) Successful in 4s
test / lint (pull_request) Successful in 15s
test / scripts (pull_request) Successful in 37s
to a46f22dee4
All checks were successful
test / changelog (pull_request) Successful in 10s
test / lint (pull_request) Successful in 16s
test / scripts (pull_request) Successful in 34s
2026-11-12 07:26:42 +00:00
Compare
Author
Contributor

Review of a46f22de: passes. Merged (squash, 7ac869b).

Reviewed against bead gascitypacks-ais, at e1ab70b first and again after the rebase onto 215bcc5. The diff against main is the one reviewed at e1ab70b. Only the CHANGELOG context changed: both bullets of this pull request sit under ### Fixed in [Unreleased], after #24's, and the 0.4.0 and 0.5.0 sections are untouched. CI for this head is green (changelog, lint, scripts).

On the merge result with 215bcc5 (same tree as this head) I ran what test.yaml runs: the ten scripts under tests/ (permission-deny.sh among them), gc lint ., go vet and go test in forgejo, and the changelog check built from mikluko/changelog v1 (valid, no release due). All pass. The new tests fail against main's code, and the not-found tests also fail against this pull request's first commit.

What the order does for each state of a pull request:

  • open: nothing.
  • merged: closes the bead as shipped.
  • closed unmerged, or a 404 that carries the forge API's own error object: assigns the bead to the Operator, sends one mail with --notify, and records pr_closed, so the next run skips the bead.
  • any other 404, a 5xx (a 503 checked by hand), a 401, a timeout, or a forge that cannot be reached: a failed run, with nothing changed or mailed.
  • a pr_url on another host, or one that is not a pull request URL: foreign. One line on stderr, no request sent, and the run does not fail.

In every case the run goes on to the next bead. The earlier review's findings are all answered: only the forge's own 404 counts as missing, the token goes only to the forge's host, and the CHANGELOG, merge.toml and the Operator skill wording are fixed.

Possible follow-ups, not blocking:

  • A rig whose origin is not on the forge, with FORGEJO_URL unset, would have every bead skipped as foreign.
  • The forge answers 404 with its own error object for a repository the token cannot see, so a token that loses access to a repository would hand that rig's beads to the Operator once.

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

**Review of a46f22de: passes. Merged (squash, 7ac869b).** Reviewed against bead gascitypacks-ais, at e1ab70b first and again after the rebase onto 215bcc5. The diff against main is the one reviewed at e1ab70b. Only the CHANGELOG context changed: both bullets of this pull request sit under `### Fixed` in `[Unreleased]`, after #24's, and the 0.4.0 and 0.5.0 sections are untouched. CI for this head is green (changelog, lint, scripts). On the merge result with 215bcc5 (same tree as this head) I ran what `test.yaml` runs: the ten scripts under `tests/` (`permission-deny.sh` among them), `gc lint .`, `go vet` and `go test` in `forgejo`, and the changelog check built from mikluko/changelog `v1` (valid, no release due). All pass. The new tests fail against main's code, and the not-found tests also fail against this pull request's first commit. What the order does for each state of a pull request: - open: nothing. - merged: closes the bead as shipped. - closed unmerged, or a 404 that carries the forge API's own error object: assigns the bead to the Operator, sends one mail with `--notify`, and records `pr_closed`, so the next run skips the bead. - any other 404, a 5xx (a 503 checked by hand), a 401, a timeout, or a forge that cannot be reached: a failed run, with nothing changed or mailed. - a `pr_url` on another host, or one that is not a pull request URL: `foreign`. One line on stderr, no request sent, and the run does not fail. In every case the run goes on to the next bead. The earlier review's findings are all answered: only the forge's own 404 counts as missing, the token goes only to the forge's host, and the CHANGELOG, `merge.toml` and the Operator skill wording are fixed. Possible follow-ups, not blocking: - A rig whose origin is not on the forge, with `FORGEJO_URL` unset, would have every bead skipped as `foreign`. - The forge answers 404 with its own error object for a repository the token cannot see, so a token that loses access to a repository would hand that rig's beads to the Operator once. 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!23
No description provided.