Skip to content

fix(roadmap): stage retries a refused plan with no cap #4491

Closed

Description

@dan-petty

Problem Description

The stage job takes the same refused items again and again, with no limit. A plan that the deterministic gates refuse two times ends the item with RoadmapStageError: The change fails its checks, also after a second try. The item then gets the failure class plan_defect. The stage job holds the item for 6 hours only, and then takes it again. Nothing counts the attempts, and nothing returns the item to New.

The cause in the code (origin/main 0ac2f76):

  • RETRY_AFTER in src/devops_cli/roadmap/failure.py:161 sets FailureClass.PLAN_DEFECT to timedelta(hours=6).
  • _Judge._failed_lately in src/devops_cli/roadmap/stage/stage.py:614 reads only stage.failed_at and stage.failed_class. It holds the item until failed_at + retry_after.
  • StageRecordKey in src/devops_cli/roadmap/stores/store.py:217 has no failure count.
  • The stage job returns a refused reply to the model one time only (CONST_ROADMAP_STAGE_GATE_RETURNS = 1, src/devops_cli/config/constants.py:3293, used near src/devops_cli/roadmap/stage/stage.py:1183).
  • priority_order puts the same high-priority items first, so each 3-item round takes them again after 6 to 11 hours.
  • The row breaker in src/devops_cli/roadmap/run.py counts only failed rounds in a row, and new input runs the row at once. After 06:20Z on 2026-11-10, staged rounds came between the failed rounds, so the breaker did not trip again.

The loop holds the one model lane. Stage error rows took 71,951 s (about 20 h) of the lane in 48 hours, about 56% of its busy time. The refine, intake and alternatives rows wait behind it. 157 Ready items wait in devops-cli.

Some refusals are gate false positives, and other issues cover them: #4463 (trace gate citation forms) and #4467 (module-test and caller gates). This issue covers only the missing limit on attempts.

Reproduction Steps

  1. Query Loki from 2026-11-08T23:45Z to 2026-11-10T23:45Z: {namespace="devops", app_kubernetes_io_name="roadmap-service"} |= "Service job execution failed" |= "the stage job failed for".
  2. Parse the RoadmapStageError text of each item in each failed round.
  3. Count the failures of each item and the time between them.
  4. Read RETRY_AFTER in src/devops_cli/roadmap/failure.py and _failed_lately in src/devops_cli/roadmap/stage/stage.py. No code counts the attempts.

Expected vs Actual Behavior

Expected: after a set number of plan_defect failures (for example 3), the stage job stops taking the item. It returns the item to New with the refused gate sentences as evidence, as AGENTS.md rule 2 says (devops roadmap return). The other Ready items then get the lane. The count resets when the item body changes or when a person sets it Ready again.

Actual: the stage job takes the same items every 6 to 11 hours with no limit.

Still occurring: failed rounds at 18:33, 20:24 and 21:11Z on 2026-11-10, and the last refused reply at 23:18Z.

Items in the loop: #3076, #3387, #3388, #3389, #3398, #3407, #3416, #3423, #3447, #3453, #3532, #3576, #3577, #3592, #3599, #3612, #3634, #3637, #3642, #4028, #4043.

Environment Diagnostics

  • DevOps CLI Version: 0.110.0 (the live roadmap-service pod)
  • Python Version: 3.14
  • OS & Architecture: Linux x86_64
  • Execution Environment: Roadmap Service (the stage row in the cluster)

Logs, Traces, or Terminal Output

# Loki, 2026-11-08T23:45Z to 2026-11-10T23:45Z
{namespace="devops", app_kubernetes_io_name="roadmap-service"} |= "Service job execution failed" |= "the stage job failed for"
# 47 rounds, 141 item failures, 81 RoadmapStageError on 44 items

# Prometheus, lane time of the stage row
devops_cli_roadmap_row_seconds{row="stage", repo="dan-petty/devops-cli"}
# error rows: 47 rows, 71,951 s, mean 1,531 s; success rows: 17,582 s
sum by (lane) (devops_cli_service_job_seconds_total)
# model lane busy 127,932 s, 74% of 48 h, 99.3% of the last 6 h

RoadmapStageError: The change fails its checks, also after a second try: Group 1 changes `src/devops_cli/lang/en/messages.py` and names no existing test of that module. ...

Related: #4204 (closed: refused-reply logs, no cap), #4411 (model study), #3398 (replay score before a gate merges; it is itself in the loop), #4463, #4467.

Pre-Submission Checklist

  • I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
  • I have checked existing issues and pull requests to ensure this is not a duplicate.

Proposed design

Problem statement

The stage job retries an item after each deterministic gate refusal with no limit. This holds the model lane and delays refine, intake and alternatives. The change adds a cap of 3 plan_defect failures per item and returns the item to New with the refused gate sentences. The count resets on a body edit or a later Ready set by a person.

Acceptance criteria

Requirement: Plan defect count

The stage job SHALL record each plan_defect failure of an item in the item's job record.

Scenario: Third plan defect is recorded

  • WHEN The stage job records a third plan_defect failure for one item.
  • THEN The item's job record holds the plan_defect count 3 and the body hash of the failed body.

Requirement: Cap at three

The stage job MUST stop selecting an item after 3 plan_defect failures on the same body.

Scenario: Fourth attempt is refused

  • WHEN An item has 3 plan_defect failures on its current body and the stage job selects it again.
  • THEN The stage job selects no fourth attempt and returns the item to New.

Requirement: Return to New with evidence

The stage job SHALL return a capped item to New with the refused gate sentences as the comment evidence.

Scenario: Capped item returns with gate text

  • WHEN The stage job returns an item after the plan_defect cap.
  • THEN The status write sets New and the comment holds each refused gate sentence from the item's refused reply record.

Requirement: Body edit reset

The stage job MUST treat a plan_defect count as zero when the item body hash differs from the recorded hash.

Scenario: Edited body starts a new count

  • WHEN An item has a recorded plan_defect count for one body hash and its body hash changes.
  • THEN The stage job selects the item and the next plan_defect failure records a count of 1.

Requirement: Ready reset

The stage job MUST clear the plan_defect count when it returns the item to New, so a later person setting it Ready starts at zero.

Scenario: Ready after a return

  • WHEN The stage job returned an item to New after the cap and a person sets it Ready again.
  • THEN The item has no plan_defect count and the stage job selects it.

Requirement: Other failure classes

The stage job MUST keep the RETRY_AFTER wait for a failure class other than plan_defect and MUST not count it toward the cap.

Scenario: Provider failure does not count

  • WHEN The stage job records a provider failure for an item with a plan_defect count of 2.
  • THEN The plan_defect count stays 2 and the item waits for the provider retry time.

Requirement: Successful stage reset

The stage job SHALL clear the plan_defect count when it stages the item.

Scenario: Staged item clears count

  • WHEN The stage job stages an item that holds a plan_defect count.
  • THEN The item's job record holds no plan_defect count.

Existing Tool Considered

No alternatives check has run. No open, maintained tool or library covers an item-level retry cap inside this roadmap stage job. The change builds on the existing job record, return path and refused-reply record. Written cost: 30k tokens to build, 10k tokens to keep and fix each year, and 1 day elapsed.

Key questions

  • Which failures count toward the cap?: Only plan_defect failures count toward the cap. A provider, parser, ci_infra or head_moved failure keeps its existing wait and does not increase the count. (best practice) [sources: src/devops_cli/roadmap/failure.py:161, docs/roadmap/stage.md:83]
  • Where does the stage job store the count?: The stage job stores the count in the item's job record under a new StageRecordKey member. It stores the body hash in a second member next to stage.failed_at and stage.failed_class. (best practice) [sources: src/devops_cli/roadmap/stores/store.py:217, src/devops_cli/roadmap/stage/stage.py:614, src/devops_cli/roadmap/body_hash.py]
    • Chosen: Job record key. It survives a Service restart, is per item, and matches the existing stage failure fields.
    • Rejected: In-memory ledger. A restart loses the count and the loop returns.
    • Rejected: Separate per-item file. It adds a store and a cleanup path for one integer.
  • What is the cap?: The cap is 3 plan_defect failures on the same body. A fixed constant holds the cap, as CONST_ROADMAP_STAGE_GATE_RETURNS holds the gate return limit. (best practice) [sources: src/devops_cli/config/constants.py:3293, docs/roadmap/stage.md:83]
  • How does the stage job return the item to New?: The stage job uses the existing roadmap return path that devops roadmap return uses. It writes the status New and the evidence comment in one item write. It adds no new command. (best practice) [sources: AGENTS.md, .agents/skills/devops-roadmap/SKILL.md:13, src/devops_cli/roadmap/stage/stage.py, src/devops_cli/roadmap/stores/store.py]
    • Chosen: Reuse roadmap return. AGENTS.md rule 2 names devops roadmap return, and one write path avoids a partial status.
    • Rejected: Add a stage-specific return command. It duplicates the existing return behavior and its tests.
    • Rejected: Only stop selecting the item. The item stays Ready and no other job can act on it.
  • What evidence goes into the return comment?: The return comment holds the gate sentences from the existing refused reply record at roadmap/stage/<owner>/<repo>/<n>.refused.json. The job masks and bounds each sentence. (best practice) [sources: k8s/README.md:698, src/devops_cli/roadmap/stage/stage.py, src/devops_cli/lang/en/messages.py]
    • Chosen: Use the refused reply record. The record already holds the refused replies and their problems until the item is staged.
    • Rejected: Re-run the gates to collect evidence. A re-run costs a model call and may give different text.
    • Rejected: Comment only the failure count. AGENTS.md rule 2 asks for the evidence that the premise fails.
  • When does the count reset?: The count clears when the body hash differs, when the stage job returns the item to New, and when a stage run stages the item. A person who sets Ready after that return starts at zero. (best practice) [sources: src/devops_cli/roadmap/body_hash.py, src/devops_cli/roadmap/stage/stage.py:614, docs/roadmap/stage.md:83]
    • Chosen: Body hash plus return and success clear. It covers the two reset cases in the issue without a new timeline read.
    • Rejected: Body hash only. A person setting Ready again would still hit the old count.
    • Rejected: Time window only. A slow loop would still hold the lane.
  • Does this change the row breaker or the gate false positives?: No. This item adds the per-item cap only. The row breaker stays as it is, and fix(roadmap): the trace gate refuses valid citation forms #4463 and fix(roadmap): the module-test and caller gates refuse correct plans #4467 cover the gate false positives. (best practice) [sources: src/devops_cli/roadmap/run.py, src/devops_cli/roadmap/failure.py:161]
    • Chosen: Per-item cap only. The issue states this scope, and the cap stops the loop without a breaker change.
    • Rejected: Also change the row breaker. The breaker counts failed rounds, not item attempts, and the issue leaves it out.
    • Rejected: Also fix gate false positives. Other issues own the trace and module-test gates.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    scope/roadmap
    status/new
    value/high
    effort/medium
    on Nov 11, 2026
  2. dan-petty commented on Nov 11, 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: P1-High. The loop consumes 56% of the model lane and blocks 157 Ready items for over 48 hours.
    • Value: High. Unblocking the lane lets 157 waiting items progress through refine, intake and alternatives.
    • Effort: Medium. Requires adding a failure count to StageRecordKey, checking it in _failed_lately, and returning the item to New; spans three files but the logic is bounded.
    • Related: feat(roadmap): stage retry time follows the failure class #4060, which asks for a different change. Both touch the stage retry mechanism in failure.py and stage.py, but #4060 sets the wait time per failure class while this candidate adds a count limit that stops retries entirely.
  3. added
    priority/p1-high
    on Nov 11, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 11, 2026
  5. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

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

  6. added
    owner/agent
    status/in-review
    and removed
    status/ready
    on Nov 11, 2026
  7. removed
    status/in-review
    owner/agent
    on Nov 11, 2026
  8. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-11 14:13 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/roadmapsource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions