Skip to content

fix(roadmap): stage_ready backs off after a failed check #3671

Closed

Description

@dan-petty

Problem

The row stage_ready reads a draft with a failed check in each round, and a failed check does not change until a push or a new run. Evidence from #3497, in the window 2026-11-03T15:05Z to 2026-11-04T15:05Z:

  • The row spent 1841 requests in one repository. The 3 open drafts of the Service in that repository each have 1 failed and 2 cancelled check runs.

The code at origin/main f6d57ec:

  • _settle reads the pull request and its check runs for each draft (src/devops_cli/roadmap/stage_ready.py:89).
  • k8s/README.md (the stage_ready item) says that the row is due every 3 minutes and that a waiting draft costs 2 requests a round (12 an hour). 2 requests each 3 minutes give 40 an hour, so that document needs a correction with this change.

Expected

After the row sees a failed check on a draft, it waits before it reads that draft again. The wait starts short and grows to a limit, and it ends when the head of the pull request changes or when a webhook event for that pull request arrives. A draft with a running check keeps the current cadence.

The refine plan on #3497 proposes an exponential backoff from 15 minutes to 60 minutes, with the next read time in the job record. The plan of this item confirms these values.

Acceptance criteria

  • A test: a draft with a failed check backs off, and the test holds the interval.

Existing tool considered

The job record already keeps the state of the row. A small backoff calculation in the row needs no library. tenacity is a dependency, but it wraps a call in one process, and this wait must stay across rounds and restarts.

Related

Split from #3497, which holds the evidence. It holds criterion 7 of that issue.

Related: #3497, #2865, #2867

Source: #3497

Alternatives check of 2026-11-08: none.
Tool: none found.

Proposed design

Problem statement

The stage_ready row reads a draft with a failed check in each 3-minute round. A failed check does not change until a push or a new run, so the row spends GitHub requests with no result; one repository spent 1841 requests on the row in one day, and the three open drafts there each hold one failed and two cancelled check runs. The row also states 12 requests an hour for a waiting draft, but 2 requests each 3 minutes is 40 an hour. The change records a next read time in the item job record, backs off from 15 minutes to 60 minutes, and clears the wait on a new head; the row keeps its pull request read in each round, so a push clears the wait with no webhook. The stage_ready item of docs/CLUSTER.md states the new cost.

Acceptance criteria

Requirement: A failed check records a 15-minute wait

The stage_ready row SHALL record stage_ready.failed_sha, stage_ready.backoff_minutes and stage_ready.next_read_at in the item job record when a draft head has a failed check and the record holds no wait for that head.

Scenario: First failed read of a head

  • WHEN the row reads a draft whose head SHA has a failed check and the record holds no stage_ready.failed_sha
  • THEN the record holds stage_ready.failed_sha equal to the head SHA, stage_ready.backoff_minutes of 15 and stage_ready.next_read_at 15 minutes after the read.

Requirement: The wait skips only the check-runs read

The row SHALL read the pull request of a waiting draft in each round and SHALL make no check-runs request before stage_ready.next_read_at.

Scenario: A waiting draft costs one request a round

  • WHEN a round runs while the record holds a stage_ready.next_read_at in the future and the pull request head SHA equals stage_ready.failed_sha
  • THEN the round sends GET pulls/<n> for that draft and sends no GET commits/<sha>/check-runs.

Requirement: Repeated failures double the wait to 60 minutes

The row SHALL double stage_ready.backoff_minutes after each later failed read of the same head SHA, up to 60 minutes.

Scenario: The wait stops at 60 minutes

  • WHEN the row reads the same failed head at the end of each recorded wait, from 15 minutes after the first failed read
  • THEN the record holds stage_ready.backoff_minutes 15 after the first read and 30, 60, 60 and 60 after the four later reads.

Requirement: A changed head clears the wait

The row SHALL clear the wait and read the check runs at once when the head SHA of the pull request differs from stage_ready.failed_sha.

Scenario: A push resets the wait

  • WHEN the row reads a draft whose head SHA differs from stage_ready.failed_sha while the record holds a next_read_at in the future
  • THEN the round sends GET commits/<new-sha>/check-runs at once, and a failed check records a wait of 15 minutes.

Requirement: A running check keeps the normal cadence

The row SHALL read the check runs of a draft that has a running check in every round and SHALL record no wait for that head.

Scenario: A running check is read each round

  • WHEN the row reads at stage_ready.next_read_at a draft whose check runs include a running check
  • THEN the record holds no stage_ready.next_read_at, and the next round sends GET commits/<sha>/check-runs for that draft.

Requirement: A cancelled check keeps the normal cadence

The row SHALL keep the 3-minute cadence for a draft whose checks are cancelled and include no failed check.

Scenario: A cancelled check is read each round

  • WHEN the row reads a draft whose check runs include a cancelled check and no failed check
  • THEN the record holds no stage_ready.next_read_at, and the next round reads the check runs of that draft.

Requirement: A passing head marks the draft ready

The row SHALL clear the wait and ask draft_readiness to mark the draft ready when every check of the head has passed.

Scenario: A passing head clears the wait

  • WHEN the row reads the check runs at stage_ready.next_read_at and every check has passed
  • THEN the row marks the pull request ready and the record holds no stage_ready.next_read_at.

Requirement: The wait survives a restart

The row SHALL take the wait from the item job record on the issue, so that a Service restart keeps it.

Scenario: A restart keeps the wait

  • WHEN a Service restart occurs while the record holds a stage_ready.next_read_at in the future
  • THEN the first round after the restart sends no check-runs request for that draft before the recorded time.

Requirement: The stage_ready item states the new cost

The stage_ready item of docs/CLUSTER.md SHALL state the cost of a draft whose checks run, the cost of a draft that waits after a failed check, the 15-to-60-minute wait, and that only a failed check starts the wait.

Scenario: The item cost matches the cadence

  • WHEN a reader opens item 18 of the Roadmap service section of docs/CLUSTER.md
  • THEN the item states 2 requests a round and 40 an hour at the 3-minute interval for a draft whose checks run, 1 request a round for a draft that waits after a failed check, plus 2 requests for each recorded wait, waits of 15, 30 and 60 minutes, and that a cancelled, running or absent check keeps the 3-minute cadence.

Existing Tool Considered

The alternatives check of 2026-11-08 gave the verdict none: no open, maintained tool covers the need. It considered tenacity (Apache-2.0, last activity 2026-10-07) and backoff (MIT, last activity 2022-10-05). Both retry one call inside one process. Neither keeps a next-read time in the GitHub issue job record, skips a later poll round after a restart, or ends the wait on a changed head SHA. A scheduler with its own persistent store would add a second copy of the row state, which the issue job record already holds (ADR 0016). The change builds a small calculation in src/devops_cli/roadmap/stage/stage_ready.py and three record fields in src/devops_cli/roadmap/stores/store.py. The cost is about 70 lines of code, about 90 lines of tests, about 7,000 tokens to build, keep and fix, and about 3 hours of elapsed time.

Key questions

  • Which document holds the stage_ready item, and what does it state for a waiting draft?: docs/CLUSTER.md, item 18 of the Roadmap service section at line 49, holds the stage_ready item. It states that the row is due every 3 minutes and that a waiting draft costs 2 requests a round (12 an hour). The two values do not agree: 2 requests each 3 minutes is 40 an hour. k8s/README.md is the Service guide for the cluster and holds no stage_ready item. [sources: docs/CLUSTER.md:49, k8s/README.md]
  • Where does the row keep the next read time and the wait?: In the item job record in the issue body, under stage_ready.failed_sha, stage_ready.backoff_minutes and stage_ready.next_read_at. The record already holds stage.pr and stage.ready, and it survives a Service restart (ADR 0016). (best practice) [sources: src/devops_cli/roadmap/stores/store.py:227, docs/adr/0016-labels-hold-the-roadmap-items-fields.md:19, docs/CLUSTER.md:49]
    • Chosen: Item job record. The record already keeps the row state, and the Service reads it again after a restart.
    • Rejected: A new file on the Service volume. It adds a second source of the row state and needs its own cleanup (ADR 0016).
    • Rejected: An in-memory cache. A restart loses the wait.
  • Which check result starts a wait?: A check that ended as failed. A running check keeps the 3-minute cadence, a cancelled check keeps it too, and a head whose checks all passed goes to draft_readiness. (best practice) [sources: src/devops_cli/github/check_verdict.py:88, src/devops_cli/roadmap/stage/stage_ready.py:142, docs/CLUSTER.md:49]
    • Chosen: A failed check only. The issue names a failed check, and each draft in the evidence holds one.
    • Rejected: A failed or a cancelled check. A cancelled check also does not change, but the issue asks for a failed check only; a cancelled-only draft keeps the cadence.
    • Rejected: Any check that exit_code 1 covers (failed, cancelled or unread). exit_code conflates the three, and an unread check is a read error, not a stable failure.
    • Rejected: Any check that has not passed, including running. A running check can finish with no push, so the row must keep the current cadence.
  • What is the wait sequence and the cap?: 15 minutes on the first failed read of a head, then 30, then 60. The wait stays at 60 minutes. The body of this issue records that the refine plan on fix(service): the rows stop repeating reads that find no change #3497 proposes an exponential backoff from 15 to 60 minutes and that the plan of this item confirms these values; fix(service): the rows stop repeating reads that find no change #3497 (fetched 2026-11-14) shows criterion 7 moved to fix(roadmap): stage_ready backs off after a failed check #3671, and docs/CLUSTER.md:49 holds the 3-minute cadence. (best practice) [sources: docs/CLUSTER.md:49, https://github.com/fix(service): the rows stop repeating reads that find no change #3497]
  • Does the wait stop the pull request read?: No. The row reads the pull request (GET pulls/<n>) in every round and compares head.sha with stage_ready.failed_sha. It skips only the check-runs read. A waiting draft then costs 1 request a round, not 2. (best practice) [sources: src/devops_cli/roadmap/stage/stage_ready.py:135, docs/CLUSTER.md:49]
    • Chosen: Keep the pull request read each round. The row sees a push at the next round, and the wait costs one request a round.
    • Rejected: Skip both reads until the next read time. The review of the plan found that a push then waits up to 60 minutes.
    • Rejected: Skip both reads and wait for a webhook clear. No pull_request scoped update exists, so the clear has no path (ADR 0017). That part is deferred.
  • How does a new head clear the wait?: The row reads the pull request in each round. When head.sha differs from stage_ready.failed_sha, the row clears the wait and reads the check runs at once. (best practice) [sources: src/devops_cli/roadmap/stage/stage_ready.py:135, docs/CLUSTER.md:49]
    • Chosen: Compare the head SHA in each round. The row already reads the pull request, so the check costs no extra request.
    • Rejected: Clear the wait only on a webhook event. The Service has no pull_request scoped update, so this path is deferred to a new issue.
  • Which function decides that a check failed?: A new pure helper _check_state in stage_ready.py classifies the check runs as passed, running, failed, cancelled, unread or none from CheckVerdictSummary.fail_count, cancel_count, pending_count, unread_count and reports_nothing. Only failed starts a wait; draft_readiness stays the one gate that decides readiness. (best practice) [sources: src/devops_cli/github/check_verdict.py:88, src/devops_cli/roadmap/stage/stage_ready.py:142, src/devops_cli/roadmap/implement/implement_pull.py:210, openspec/specs/roadmap-stage/ready/spec.md:74]
    • Chosen: A new helper _check_state. The row needs the reason, and the readiness gate keeps its one job.
    • Rejected: A reason from draft_readiness. draft_readiness returns a Readiness whose exit_code 1 covers failed, cancelled and unread, so it cannot say which; four call sites change.
    • Rejected: A second read of the check runs in the row. A second read costs a request and can see another state.
  • Does the wait survive a Service restart?: Yes. The record lives on the issue, and the row reads it again at each round. [sources: docs/adr/0016-labels-hold-the-roadmap-items-fields.md:19, src/devops_cli/roadmap/stores/store.py:227, docs/CLUSTER.md:49]
  • Does the change fit in one pull request?: The backoff and the documentation fit in one pull request. The webhook clear does not: SCOPED_UPDATES holds issues events only (ADR 0017), so a pull_request or check_run delivery has no scoped update. The review of the plan refused the two parts in one pull request, so the webhook clear goes to a new issue. (best practice) [sources: src/devops_cli/roadmap/run.py:1153, docs/adr/0017-each-subscribed-webhook-event-runs-the-update-scoped-to-it.md:18, openspec/specs/roadmap-scoped-updates/spec.md:19]
    • Chosen: Split the webhook clear from the backoff. The review of the plan asks for this split, and the backoff is safe with the pull request read kept.
    • Rejected: One pull request for both parts. The review refused it: the webhook clear needs a scoped update that does not exist.
    • Rejected: Raise the effort and keep one pull request. The missing scoped update is a change of the router, not more work in the row.
  • What does the stage_ready item state for the cost?: 2 requests a round, or 40 an hour at the 3-minute interval, for a draft whose checks run. 1 request a round, or 20 an hour, for a draft that waits after a failed check, plus 2 requests for each recorded wait. Waits of 15, 30 and 60 minutes. A cancelled, running or absent check keeps the 3-minute cadence. (best practice) [sources: docs/CLUSTER.md:49, src/devops_cli/roadmap/stores/github_store.py:894]
    • Chosen: State 40 and 20 an hour with the wait. 2 requests each 3 minutes is 40 an hour, and the waiting draft makes one request a round.
    • Rejected: Keep 12 an hour. 12 an hour does not follow from 2 requests each 3 minutes.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    on Nov 5, 2026
  2. added
    type/bug
    scope/roadmap
    status/new
    value/medium
    effort/low
    on Nov 5, 2026
  3. dan-petty commented on Nov 5, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: scope/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P2-Medium. It wastes API requests but does not break functionality.
    • Value: Medium. It reduces wasted API calls without changing user-facing behaviour.
    • Effort: Low. A small backoff calculation in the row needs no new library.
    • Related: fix(roadmap): one failed item does not suspend the stage row #3493, which asks for a different change. Both address failed checks in the stage row, but 3493 stops one item from suspending the row while this item adds read backoff after a failed check.
  4. added
    priority/p2-medium
    on Nov 5, 2026
  5. added
    status/ready
    and removed
    status/new
    on Nov 7, 2026
  6. devops-cli-service commented on Nov 7, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 0550497 (see proposed design in issue body).

  7. devops-cli-service commented on Nov 8, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: The searches turned up only general in-process retry libraries (tenacity, backoff), which wrap one call inside one process and cannot hold a next-read time in the item job record or skip a later poll round after a restart. No tool covers a backoff that lives in the GitHub issue job record, resets on a changed head SHA and clears on a pull_request webhook event, so the small calculation in stage_ready.py is the right shape.

    Tool: none found

    Lacks:

    • No tool keeps the wait in the GitHub issue job record across Service rounds and restarts
    • No tool ends the wait on a changed head SHA or a pull_request webhook event
    • In-process retry libraries cannot skip a future poll round of a long-lived row
    • A scheduler with its own persistent store would add a second source of row state, which the project's records reject

    Tools considered:

    Searches run:

    • python-backoff retry library in-process only no persistence, results: 5
    • python library persistent exponential backoff state across process restarts, results: 5
    • tenacity Python retry library github jd tenacity, results: 5
    • APScheduler persistent job store SQLAlchemy schedule delayed job across restarts, results: 5
    • "tenacity" retry library README stop after attempt wait exponential, results: 5
    • apscheduler pypi package persistent jobstore documentation, results: 5

    Sources:

    Checked on 2026-11-08. A person decides what this means for the item. The check changes no label and closes no issue.

  8. dan-petty commented on Nov 14, 2026

    @dan-petty
    OwnerAuthor

    Cannot build as low effort in one safe pull request: the design needs a pull_request scoped update that does not exist (SCOPED_UPDATES holds issue events only, ADR 0017), so the webhook clear requirement has no path. Without that clear the row cannot see a new head before the 60-minute wait ends, and the changed-head reset cannot work. The backoff alone would trap a draft after a push. Split the webhook clear (payload model, scoped update, store clear, tests) from the backoff, or raise the effort.

  9. 15 remaining items

  10. added
    status/in-progress
    and removed
    status/ready
    on Nov 16, 2026
  11. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    Contributor

    The runner Job devops-cli-implement-devops-cli-3671-656474 ended: succeeded.
    Image digest: sha256:d1c0e4299edebb4b31ade10343b7ac00ee0a875023756932aa25ad9aebca241a

    The last lines of its log:

    # Implement plan for dan-petty/devops-cli
    
    ## Left out
    - #3671 fix(roadmap): stage_ready backs off after a failed check: Its plan pull request #5993 is ready for review and awaiting merge.
    ✓ Took 0 item(s) to a ready pull request, stopped 0.
    

    Failure class: ci_infra.
    Action taken: none.
    Action left: retry: run the item again.

    The Job left this item without a result. The item is Blocked. When a retry can fix the class of the stop, the Service starts a new Job in the next round. The limit is roadmap.implement.continuations_per_item, and the comment of that round says so. If no continuation is left, fix the cause. Then comment implement: retry. A new runner image also clears the stop. This holds only if a retry can fix the class of the stop. The limits of roadmap.implement.digest_clears_per_class and roadmap.implement.digest_clears_per_item must also allow it.

  12. added
    status/blocked
    status/ready
    and removed
    owner/service
    status/in-progress
    status/blocked
    on Nov 16, 2026
  13. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    Contributor

    Cleared the stop at job by the rule continue: the runner Job devops-cli-implement-devops-cli-3671-656474 ended without a result. The class ci_infra of the stop is one that a new attempt can fix. This is continuation 1 of 4 for this item. The item is Ready again. The Service takes it in the next round. The new Job takes the branch from origin, so it keeps the work that the run pushed there.

  14. dan-petty commented on Nov 16, 2026

    @dan-petty
    OwnerAuthor

    Done by #5906: the row watch has the 30-minute failed-head backoff of this issue (src/devops_cli/roadmap/watch_row.py:338, docs/CLUSTER.md:49), and tests/roadmap/test_roadmap_watch_row.py:158 holds it. The plan #5993 closed as stale (verdict Issue changed). The REST-fallback order defect that a vet found is filed as its own item.

  15. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    Contributor

    Plan pull request #5993 closed with no merge. The job waits for an edit of the text of this item, or for a commit that changes a file that the reason names.

    The reason, from the last comment of dan-petty on the pull request:

    Verdict: Issue changed (verdict/issue-changed). Closed with no merge.

    • feat(roadmap): one watch row for plan and delivery PRs #5906 removed the row stage_ready. The row watch replaced it and already has a 30-minute failed-head backoff for fix(roadmap): stage_ready backs off after a failed check #3671 (docs/CLUSTER.md:49, src/devops_cli/roadmap/watch_row.py:338). tests/roadmap/test_roadmap_watch_row.py:158 holds that interval, so the acceptance criterion of fix(roadmap): stage_ready backs off after a failed check #3671 is met on main.
    • A growing wait saves no request: ADR 0021 section 8 gives one GraphQL query for each repository in each tick, and the test at test_roadmap_watch_row.py:161-170 asserts 2 GraphQL requests in 2 ticks while the backoff is on. The plan's design.md says the same, and the plan shortens the first wait from 30 to 15 minutes.
    • The one real cost defect is elsewhere: in the REST fallback, read_check_runs (watch_row.py:514) runs before the backoff test (watch_row.py:304-310). That is filed as its own item.
  16. removed
    status/ready
    on Nov 16, 2026
  17. added
    status/new
    and removed
    status/new
    on Nov 16, 2026
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/lowpriority/p2-mediumscope/roadmapsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions