merge-queue reads only what a delivery says changed #16

Merged
merge-queue merged 1 commit from forgejo-56-mq-reads into main 2026-11-18 20:13:54 -08:00
Owner

Work package: https://openproject.home.romaine.life/wp/FORGEJO-56

merge-queue was Forgejo's busiest client: 594 requests in about 70 seconds tonight (241 open-PR lists, 217 repository reads, 52 status reads, 50 timelines, 24 compares). Every delivery, each CI job on any repository included, brought a full look at its repository.

Removed: the full read per delivery (repository, every open pull request, every queued one's timeline and statuses).

Added:

  • model.go: what the last look read of each repository (the repository, its queued pull requests, each one's label time and head statuses, and heads found up to date with their base), and what each delivery marks changed.
  • A delivery brings a look only when it touches the queue. A pull request event looks if the PR is queued, was, or left. A run or job looks if its commit is a queued head. A push looks if it is to a queued PR's base. The queue's own commit_status never looks. The look then reads only what was marked: that PR, its timeline when its labels changed, and that head's statuses.
  • The repository is taken from the delivery, which Forgejo sends whole. A head found up to date isn't compared again until a push to the base or a landing.
  • Lists stop at X-Total-Count instead of reading an empty last page.
  • A look that fails drops what it kept. While nothing is held of a repository (its first delivery, or the first since a failed look), any delivery brings a look that reads it whole, so a queued PR whose look failed on a 503 lands on the next event of any kind.
  • Metrics: merge_queue_webhook_looked_total and merge_queue_webhook_dropped_total by event, and merge_queue_forgejo_requests_total by method.

Left alone: every decision rule in the README, the startup read, one look per repository at a time, and the retry after a failed look. Its own status writes are read back once by the next look, so the hand-back rerun keeps comparing against Forgejo's times.

What this trades: a lost delivery is no longer repaired by the next unrelated event, only by the next one touching that PR, a failed look, or a restart. A lost push to the base could let the front merge without being updated first; Forgejo's branch protection still guards that.

Tested: go test passes. The existing decision tests are unchanged except that they deliver real payloads. New tests in reads_test.go cover: a job after a failed look reads the repository whole and lands the PR (TestAJobAfterAFailedLookReadsTheRepositoryWholeAndLands, which fails without the fix); a job on an unqueued head, a repository with nothing queued, an unrelated push, an unqueued PR and the queue's own status all make zero requests; a job on a queued head reads only that head's statuses; the label added and removed by its event; a push to the base updating the front; the repository taken from the event; and lists stopping at the total. The image's --self-test passes.

Expected rate from tonight's measured events: the drops cost nothing, and a job on a queued head costs one status read, coalesced per repository. That is at most about 0.75 requests a second at tonight's peak job rate, against about 8.5 measured.

🤖 Generated with Claude Code

Work package: https://openproject.home.romaine.life/wp/FORGEJO-56 merge-queue was Forgejo's busiest client: 594 requests in about 70 seconds tonight (241 open-PR lists, 217 repository reads, 52 status reads, 50 timelines, 24 compares). Every delivery, each CI job on any repository included, brought a full look at its repository. Removed: the full read per delivery (repository, every open pull request, every queued one's timeline and statuses). Added: - `model.go`: what the last look read of each repository (the repository, its queued pull requests, each one's label time and head statuses, and heads found up to date with their base), and what each delivery marks changed. - A delivery brings a look only when it touches the queue. A pull request event looks if the PR is queued, was, or left. A run or job looks if its commit is a queued head. A push looks if it is to a queued PR's base. The queue's own `commit_status` never looks. The look then reads only what was marked: that PR, its timeline when its labels changed, and that head's statuses. - The repository is taken from the delivery, which Forgejo sends whole. A head found up to date isn't compared again until a push to the base or a landing. - Lists stop at `X-Total-Count` instead of reading an empty last page. - A look that fails drops what it kept. While nothing is held of a repository (its first delivery, or the first since a failed look), any delivery brings a look that reads it whole, so a queued PR whose look failed on a 503 lands on the next event of any kind. - Metrics: `merge_queue_webhook_looked_total` and `merge_queue_webhook_dropped_total` by event, and `merge_queue_forgejo_requests_total` by method. Left alone: every decision rule in the README, the startup read, one look per repository at a time, and the retry after a failed look. Its own status writes are read back once by the next look, so the hand-back rerun keeps comparing against Forgejo's times. What this trades: a lost delivery is no longer repaired by the next unrelated event, only by the next one touching that PR, a failed look, or a restart. A lost push to the base could let the front merge without being updated first; Forgejo's branch protection still guards that. Tested: `go test` passes. The existing decision tests are unchanged except that they deliver real payloads. New tests in `reads_test.go` cover: a job after a failed look reads the repository whole and lands the PR (`TestAJobAfterAFailedLookReadsTheRepositoryWholeAndLands`, which fails without the fix); a job on an unqueued head, a repository with nothing queued, an unrelated push, an unqueued PR and the queue's own status all make zero requests; a job on a queued head reads only that head's statuses; the label added and removed by its event; a push to the base updating the front; the repository taken from the event; and lists stopping at the total. The image's `--self-test` passes. Expected rate from tonight's measured events: the drops cost nothing, and a job on a queued head costs one status read, coalesced per repository. That is at most about 0.75 requests a second at tonight's peak job rate, against about 8.5 measured. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
merge-queue reads only what a delivery says changed (FORGEJO-56)
All checks were successful
Suite cluster-service / scope (pull_request) Successful in 5s
Suite cluster-service / check-image (pull_request) Successful in 15s
Suite default / scope (pull_request) Successful in 5s
Suite go / scope (pull_request) Successful in 5s
Suite cluster-service / scope (push) Has been skipped
Suite cluster-service / check-manifests (push) Has been skipped
Suite cluster-service / check-image (push) Has been skipped
Suite cluster-service / publish (push) Has been skipped
Suite cluster-service / reused-checks (push) Has been skipped
Suite default / check-fetches (pull_request) Has been skipped
Suite default / check-rules (pull_request) Has been skipped
Suite go / check-test-windows (pull_request) Has been skipped
Suite go / check-services (pull_request) Has been skipped
Suite cluster-service / check-manifests (pull_request) Has been skipped
Suite cluster-service / publish (pull_request) Has been skipped
Suite default / reused-checks (pull_request) Successful in 6s
Suite go / reused-checks (pull_request) Successful in 5s
Suite go / check-format (pull_request) Successful in 7s
Suite go / check-test-linux (pull_request) Successful in 11s
Suite cluster-service / reused-checks (pull_request) Successful in 5s
6cd27c3352
nelson force-pushed forgejo-56-mq-reads from 6cd27c3352
All checks were successful
Suite cluster-service / scope (pull_request) Successful in 5s
Suite cluster-service / check-image (pull_request) Successful in 15s
Suite default / scope (pull_request) Successful in 5s
Suite go / scope (pull_request) Successful in 5s
Suite cluster-service / scope (push) Has been skipped
Suite cluster-service / check-manifests (push) Has been skipped
Suite cluster-service / check-image (push) Has been skipped
Suite cluster-service / publish (push) Has been skipped
Suite cluster-service / reused-checks (push) Has been skipped
Suite default / check-fetches (pull_request) Has been skipped
Suite default / check-rules (pull_request) Has been skipped
Suite go / check-test-windows (pull_request) Has been skipped
Suite go / check-services (pull_request) Has been skipped
Suite cluster-service / check-manifests (pull_request) Has been skipped
Suite cluster-service / publish (pull_request) Has been skipped
Suite default / reused-checks (pull_request) Successful in 6s
Suite go / reused-checks (pull_request) Successful in 5s
Suite go / check-format (pull_request) Successful in 7s
Suite go / check-test-linux (pull_request) Successful in 11s
Suite cluster-service / reused-checks (pull_request) Successful in 5s
to 8016bc6316
All checks were successful
Suite default / check-fetches (pull_request) Has been skipped
Suite go / check-services (pull_request) Has been skipped
Suite go / check-format (pull_request) Successful in 49s
Suite default / scope (pull_request) Successful in 40s
Suite default / reused-checks (pull_request) Successful in 43s
Suite cluster-service / scope (push) Has been skipped
Suite cluster-service / check-manifests (push) Has been skipped
Suite cluster-service / check-image (push) Has been skipped
Suite cluster-service / publish (push) Has been skipped
Suite cluster-service / reused-checks (push) Has been skipped
Suite cluster-service / scope (pull_request) Successful in 38s
Suite go / scope (pull_request) Successful in 38s
Suite cluster-service / check-manifests (pull_request) Has been skipped
Suite default / check-rules (pull_request) Has been skipped
Suite cluster-service / publish (pull_request) Has been skipped
Suite go / check-test-windows (pull_request) Has been skipped
Suite go / check-test-linux (pull_request) Successful in 1m21s
Suite go / reused-checks (pull_request) Successful in 34s
merge-queue landed on main
Suite cluster-service / check-image (pull_request) Successful in 2m17s
Suite cluster-service / reused-checks (pull_request) Successful in 31s
2026-11-18 20:10:16 -08:00
Compare
merge-queue deleted branch forgejo-56-mq-reads 2026-11-18 20:13:54 -08:00
Sign in to join this conversation.
No reviewers
No labels
queue
No milestone
No project
No assignees
1 participant
Notifications
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
romaine-life/merge-queue!16
No description provided.