Skip to content

fix(service): the redeliver row has no limit on its requests #7920

Done

Description

@dan-petty

Problem Description

The status row redeliver (src/devops_cli/github/hook_redelivery.py) has no limit on its requests, and after a long stop it does not read all the failed deliveries.

  • One round sends one POST /app/hook/deliveries/<id>/attempts for each pending guid. No cap applies.
  • One round reads one page of 100 deliveries and moves the cursor to the newest ID. It never reads the other deliveries that came after the earlier cursor.
  • The ledger keeps no record of an accepted attempt. The row asks again each round until it reads a 2xx for the guid on that one page, or until the delivery is 3 days old.
  • A rate limit ends the round. The next round starts again at the oldest pending guid.
  • Each POST takes a place in the hourly budget of the Service (500 by default). At 7 minutes for each round, about 60 pending guids use the full budget.

A rate limit wait is obeyed in the process: the session waits 60 s or more before each of 2 resends and holds the requests of the identity until the last wait ends (#7911). The hold is in memory only. A failed round writes no success stamp, so the row is due again before 7 minutes pass, until service.max_failed_rounds stops it for that input.

Reproduction Steps

Run redeliver_failed_deliveries against the fake GitHub API of the tests, on the fix of #7911:

  1. List 100 failed deliveries and run one round.
  2. List 1,000 newer failed deliveries and run a round.
  3. Run one more round.
  4. Answer the 50th POST and each later one with 403 API rate limit exceeded for integration ID ... and no rate-limit header. Run two rounds.

Expected vs Actual Behavior

Expected: a round sends a set number of attempts at most, reads each page back to the cursor (with a page cap), and does not ask again for an accepted attempt before GitHub records its result.

Actual:

  • Step 2: 200 POSTs. The cursor moves to the newest ID. 900 new failed deliveries are never read.
  • Step 3: the same 200 POSTs again.
  • Step 4: each round sends 52 POSTs (49 accepted, then 3 refused on the 50th) and starts at the same guid.

Environment Diagnostics

devops-cli 0.264.1, Python 3.14.10, devcontainer. Offline probe with the test fake.

Alternatives check of 2026-11-30: in-use.
The repository already uses this tool.
Tool: gidgethub (https://github.com/gidgethub/gidgethub), Apache-2.0, last activity 2026-11-20, maintained.
Reason: No tool caps POST attempts per round or records accepted attempts. gidgethub waits on rate limits and iterates pages, but the row must hold the cap, cursor and ledger.

Covers:

  • Waits for the GitHub rate-limit reset
  • Iterates result pages through Link headers
  • Handles the authenticated GitHub session

Lacks:

  • No cap on POST attempts in one round
  • No page cap with a stored cursor
  • No ledger of accepted attempts
  • No suppression of a repeated POST

Proposed design

Problem statement

The redeliver row of the roadmap Service sends one POST for each pending guid and has no cap. It reads one list page and moves the cursor to the newest ID, so it skips the deliveries between the old cursor and that page. It keeps no record of an accepted attempt, so it sends the same POST again each round. This change caps the POSTs and the pages, resumes from a stored page cursor, and suppresses a POST after GitHub accepts it.

Acceptance criteria

Requirement: Round POST cap

A redeliver round SHALL send no more than 40 POST requests to /app/hook/deliveries/{id}/attempts.

Scenario: A round with more pending guids than the cap

  • WHEN The ledger holds 100 pending guids with no accepted record, and the fake session accepts each POST.
  • THEN The fake session records 40 POST requests to the attempts path, and 60 pending guids still have no last_attempt_at value.

Requirement: Page cap with stored cursor

A redeliver round SHALL read at most 12 list pages and SHALL store the next page cursor in the ledger when it reaches that cap.

Scenario: A backlog larger than the page cap

  • WHEN The ledger delivery cursor is 1000 and 1,300 newer deliveries span 13 pages of 100 entries, each page with a Link header.
  • THEN The round sends 12 GET requests, stores the page cursor for page 13, and keeps the delivery cursor at 1000.

Requirement: Backlog read to cursor

A redeliver round SHALL read each page from the stored page cursor until it reads an entry at or below the delivery cursor.

Scenario: A long stop leaves 1,000 newer deliveries

  • WHEN The ledger delivery cursor is 1000, 1,000 newer deliveries fill 10 pages, and page 11 holds delivery 1000.
  • THEN The round sends 11 GET requests, records all 1,000 deliveries in the pending set, sets the delivery cursor to the newest delivery ID, and clears the page cursor.

Requirement: Accepted attempt suppression

The redeliver row SHALL record each 2xx POST acceptance and SHALL NOT send another POST for that guid before GitHub lists a newer delivery entry for the guid or the guid passes the 3-day age limit.

Scenario: An accepted attempt waits for the GitHub result

  • WHEN A round accepts the POST for a guid and the next list holds no newer entry for that guid.
  • THEN The next round sends no POST for that guid and the ledger keeps the accepted record.

Requirement: Accepted record cleared by a newer result

The redeliver row SHALL clear the accepted record of a guid when GitHub lists a delivery for that guid with a later delivered_at value.

Scenario: GitHub records a newer failed attempt

  • WHEN The accepted record has delivered_at 10:00 and the next list holds a failed delivery for the same guid at 10:05.
  • THEN The ledger clears the accepted record and the round sends one POST for the guid.

Requirement: Accepted attempt saved before a rate limit

The redeliver row SHALL save the ledger after each accepted POST and before it sends the next POST.

Scenario: A rate limit ends a round after an accepted attempt

  • WHEN The fake session accepts 39 POSTs and then raises GitHubRateLimitError on the 40th.
  • THEN The ledger holds 39 accepted records and the next round sends no POST for those 39 guids.

Requirement: Least recently attempted first

The redeliver row SHALL choose pending guids by the oldest last_attempt_at value, then by the oldest delivery ID.

Scenario: The cap rotates over the pending set

  • WHEN The ledger holds 60 pending guids with last_attempt_at 10:00 and 40 pending guids with last_attempt_at 09:00.
  • THEN The round sends POSTs for the 40 guids with last_attempt_at 09:00, oldest delivery ID first.

Existing Tool Considered

Alternatives check in the issue body: gidgethub, verdict in-use. The check lists what gidgethub covers and what it lacks. This change keeps gidgethub for the authenticated session, the rate-limit wait and the page iteration that the check names as covered. It adds the parts that the check names as lacking, in src/devops_cli/github/hook_redelivery.py: a POST cap of 40 for each round, a 12-page cap with a stored page cursor, an accepted-attempt ledger, and the suppression of a repeated POST.

Key questions

  • Which parts of the issue remain after fix(service): redeliver once for the App with a valid JWT #7938?: The code already continues a round after a refused attempt and raises the first refusal after the last attempt. It asks the App, so only one repository reads the deliveries. The remaining parts are the POST cap, the page cap with a stored page cursor, the accepted-attempt ledger and the least-recently-attempted order. [sources: src/devops_cli/github/hook_redelivery.py, docs/SERVICE_PATTERNS.md]
  • What limit applies to POST attempts in one round?: A round sends at most 40 POST attempts. The cap is a constant in src/devops_cli/config/defaults.py. The row sends the oldest attempts first. The issue body states a budget of 500 requests in an hour. At 7-minute rounds, 40 POSTs and 12 list pages use at most 446 requests in an hour, so 40 leaves a margin. (best practice) [sources: src/devops_cli/github/hook_redelivery.py, src/devops_cli/config/defaults.py]
    • Rejected: No cap. The row spends the hourly budget and repeats attempts.
    • Rejected: 60 attempts per round. 60 POSTs and 12 pages use 617 requests in an hour, above the 500 budget.
    • Chosen: 40 attempts and 12 pages per round. 52 requests per round use at most 446 requests in an hour, below the 500 budget.
  • How does a round read each page back to the cursor?: The round reads the next page URL from the Link header of the list response. It stops when it reads an entry at or below the delivery cursor, or after 12 pages. At the page cap it stores the next page cursor in the ledger. The next round continues from that cursor. (best practice) [sources: src/devops_cli/github/hook_redelivery.py, src/devops_cli/github/session.py, src/devops_cli/roadmap/stores/github_store.py]
    • Rejected: One page only. The current row skips the deliveries after the first page.
    • Rejected: Page number query. The App hook deliveries endpoint pages by the Link header, not by a page number.
    • Chosen: Link-header cursor with a 12-page cap. It reads the backlog across rounds and bounds the list requests.
  • How does the row stop a repeated POST after an accepted attempt?: The row stores an accepted attempt for the guid with its delivery ID and delivered_at. It sends no new POST for that guid until GitHub lists a newer delivery for the guid, or the 3-day age limit passes. A newer entry clears the accepted record. (best practice) [sources: src/devops_cli/github/hook_redelivery.py, docs/SERVICE_PATTERNS.md]
    • Rejected: Keep no record. The row repeats the accepted POST each round.
    • Rejected: Suppress until the age limit. A lost or failed redelivery never gets a new attempt.
    • Chosen: Suppress until a newer delivery entry appears. GitHub records the result as a new entry, and the row decides from that result.
  • How does the row choose pending guids when more than the cap wait?: The row sends the pending guids with the oldest last_attempt_at value first, then the oldest delivery ID. The round sets last_attempt_at after each POST. This order rotates the cap over the pending set and stops starvation. (best practice) [sources: src/devops_cli/github/hook_redelivery.py]
    • Rejected: Oldest delivery ID only. The same first 40 guids use every round and later guids starve.
    • Rejected: Newest delivery ID first. Old failed deliveries wait until the age limit.
    • Chosen: Least recently attempted first. Each pending guid gets a turn within the cap.
  • When does the row save an accepted attempt?: The row saves the ledger after each accepted POST and before it sends the next POST. A rate limit then cannot cause a repeat of an accepted attempt. (best practice) [sources: src/devops_cli/github/hook_redelivery.py]
    • Rejected: Save only at round start. A rate limit loses the accepted records of the round.
    • Chosen: Save after each accepted POST. The next round sees the record and does not repeat the POST.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/bug
    source/agent
    status/new
    effort/medium
    value/high
    scope/service
    on Nov 30, 2026
  2. dan-petty commented on Nov 30, 2026

    @dan-petty
    OwnerAuthor
    • Priority: The row consumes the full hourly API budget with about 60 pending guids, degrading service capacity.
    • Related: feat(service): redeliver webhook deliveries that failed #4560, which asks for a different change. Both concern the redeliver row, but #4560 creates the feature while the candidate fixes its missing request and page limits.
  3. added
    priority/p1-high
    on Nov 30, 2026
  4. devops-cli-service commented on Nov 30, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (10)

    Tools considered:

    Searches run:

    • Python library GitHub API rate limit aware retry with attempt cap and pagination, results: 5
    • tenacity retry stop_after_attempt rate limit wait bounded retries, results: 5
    • gidgethub GitHubAPI rate limit handling getiter pagination, results: 5
    • tenacity stop_after_attempt wait_exponential retry library GitHub, results: 5
    • gidgethub python library documentation, results: 5
    • tenacity python retry library pypi, results: 5
    • github api client python secondary rate limit retry after sleep budget, results: 5
    • gidgethub readthedocs abc GitHubAPI rate limit, results: 5
    • tenacity, results: 5
    • gidgethub, results: 5

    Sources:

  5. dan-petty commented on Nov 30, 2026

    @dan-petty
    OwnerAuthor

    Note from #7925 (pull request #7938): after that change, only the row of the first repository of service.repos asks for redeliveries, so a round sends one attempt for each pending guid in total. A refused attempt (such as HTTP 422) no longer ends the round, and a rate limit or a refused identity still does. The request cap, the page limit and the record of an accepted attempt of this issue stay open.

  6. dan-petty commented on Nov 30, 2026

    @dan-petty
    OwnerAuthor

    Live evidence from the Service log on 2026-11-30, image v0.264.1, the last 40 minutes before about 21:55 UTC:

    • 462 webhook deliveries of the event check_suite had the outcome rejected. They hold only 17 delivery IDs, and one ID came 30 times.
    • The only 403 of the route for a signed, valid payload is unmanaged repository (server/routes/webhooks.py, _authenticated_payload). This is an inference from the source: the log line names no status, no reason and no repository.

    A refusal of this kind cannot succeed on a new attempt while the repository is not in service.repos, so each redelivery spends a request for nothing. v0.264.1 holds neither #7938 nor a request cap, so check which part #7938 already removes.

  7. added
    status/ready
    and removed
    status/new
    on Dec 1, 2026
  8. devops-cli-service commented on Dec 1, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  9. 14 remaining items

  10. added
    status/in-progress
    and removed
    owner/service
    on Dec 1, 2026
  11. devops-cli-service commented on Dec 1, 2026

    @devops-cli-service
    Contributor

    Stopped at fix.

    Failed check: pre-push. The end of its log:

    trim trailing whitespace................................................................Passed
    fix end of files........................................................................Passed
    check for added large files.............................................................Passed
    branch holds origin/main (docs/SDLC.md, Phase 5)........................................Passed
    devops ci (fast static checks before a push)............................................Failed
    - hook id: devops-ci-pre-push
    - exit code: 124
    
    \u2139 Quality gate root: /run/roadmap/work/model-clone
    \u2139 Executing CI quality gates concurrently...
      \u2713 pass [python_version] python version check (3.14+) (3\xb5s)
      \u2013 \\[domain] skipped: no k8s.domain or cloudflare.domain is configured, so the row read no commit
      \u2717 fail [lint] ruff check (stopped after 38s)
      \u2717 fail [format] ruff format (stopped after 39s)
      \u2717 fail [swallowed-failures] swallowed failures (ratchet of blind excepts and unread check=False) (stopped after 39s)
      \u2717 fail [uv-check] uv check (stopped after 39s)
      \u2717 fail [constructs] ast-grep scan (network constructs and working-directory reads in src, elapsed-time bounds in tests) (stopped after 39s)
      \u2717 fail [deps] deptry (stopped after 39s)
    
    devops ci (workflow checks before a push that changes a workflow)...(no files to check)Skipped
    

    Failure class: no_change_in_fix.
    Action taken: none.
    Action left: wait: wait for a person.

    Step Status Attempts Tokens in/out Last failing command
    group 1 done 1 1416781/4371 -
    group 2 done 2 3497146/17173 pytest on base: tests/github/test_hook_redelivery.py
    group 3 done 1 5190543/27505 pytest on base: tests/github/test_hook_redelivery.py
    group 4 done 1 1662107/1585 -
    fix stopped 1 154897/758 pre-push

    Reason:

    The group 0 (Make check pre-push pass) changed no file. The group may be too large or already done. Return the item for a smaller replacement of group 0, or amend the plan with a request of kind `group` that keeps the number and has fewer tasks.
    

    Last message of the agent (a claim that no check verified): The pre-push failure was a timeout (exit 124), not a code defect, and I changed no file. The six gates were each stopped after about 39 seconds. When I re-ran them with uv run devops ci --check --only lint,format,swallowed-failures,uv-check,constructs,deps, all six passed and the longest took 1m 27s. The checkout is clean. I did not run the full devops-ci-pre-push hook itself, so the job must re-run it to confirm. If it times out again, the cause is the time limit on that hook.

    The item is Blocked, and the job will not run it. Fix the cause. Then comment implement: retry. The Service clears the stop on its own when a new runner image rolls out, but only if a retry can fix the class of the stop and the limits of roadmap.implement.digest_clears_per_class and roadmap.implement.digest_clears_per_item allow it.

    The job kept the commits that passed on the branch fix/7920-the-redeliver-row-has-no-limit on origin. The last is b174a44678cca4877a56698083d7bf6fd917f738. The pull request stays a draft. The next run continues from it, runs no group that is ticked, and runs the scoped checks again.

  12. added
    status/blocked
    and removed
    status/in-progress
    on Dec 1, 2026
  13. added
    status/in-review
    and removed
    status/blocked
    on Dec 1, 2026
  14. removed
    status/in-review
    on Dec 1, 2026
  15. devops-cli-service commented on Dec 1, 2026

    @devops-cli-service
    Contributor

    Live since 2026-12-01 16:30 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p1-highscope/servicesource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions