Skip to content

fix(roadmap): a stage Job retries a provider timeout #5562

Closed

Description

@dan-petty

Problem Description

A stage Job whose model call ends in a provider timeout fails for good. It gets no retry and writes no infrastructure class.

Evidence (2026-11-13, release 0.132.1, stage Jobs started with devops k8s run-job --template stage):

Cause

  • roadmap/stage/stage_job.py maps a failed result to StageJobExit.FAILURE (exit 1). Only SIGTERM gives EVICTED (75), which the pod failure policy retries.
  • A provider timeout is a transient infrastructure failure, the same class as provider in roadmap/failure.py.

Proposed Fix

  • In the stage Job, map an attempt that ends with an infrastructure class (provider, ci_infra, a gateway timeout) to a retry exit code that the pod failure policy retries within backoffLimit.
  • Write the result line with infra=true and the class, as the in-pod path did.
  • Keep exit 1 for a plan defect, a timeout of the attempt budget, and the other classes that a retry cannot fix.
  • Check the admission policy and the podFailurePolicy of cronjob-stage.yaml. They allow 2 retries only after exit 75 or a disruption. If a new exit code is used, change both together and test them.
  • Separate item: the gateway has no fallback group for deepseek-v4.1-flash-1017, so a timeout of OpenRouter has no second route. Name this in the PR, and do not change the gateway in it.

Acceptance Criteria

  • A test with a stage attempt that ends with class provider gets the retry exit code and a result line with infra=true (devops ci fail-to-pass).
  • A test with class plan_defect keeps exit code 1.
  • The policy test (tests/gate/k8s_checks/job_admission_policy.py) admits the stage Job with the new failure policy rule.

Related

#4559, #5483, #5527 (connection resets of the deepseek pool), #5556 (the grades must read the Job lines)

Proposed design

Problem statement

A stage Job that ends with a provider timeout exits 1. The stage pod failure policy treats exit 1 as a final failure, so Kubernetes makes no new pod, and the Job writes no result line with the infrastructure class that the in-pod stage path wrote. The fix classifies the error that ends the attempt, writes the attempt's result line with its class (infra=true for a provider or infrastructure cut), and exits 75, the one code that backoffLimit: 2 and the podFailurePolicy of cronjob-stage.yaml retry; a class that a retry cannot fix keeps exit 1, and a deadline end keeps 143. A retried pod leaves the check-out in place, so it plans the same item. The gateway already holds the deepseek-v4.1-flash-1017 → deepseek-v4.1-flash fallback (#5564, released in 0.134.1), so this change names it in the PR and does not touch the gateway.

Acceptance criteria

Requirement: A provider timeout retries

A stage attempt that ends with an error whose failure class has the default action RETRY, such as provider, SHALL write the result line of the attempt and exit 75.

Scenario: The provider timeout of a stage attempt

  • WHEN run_stage_job plans an item and its model call raises an AIClientError with HTTP status 504.
  • THEN It returns exit code 75, and the captured result line holds result=failed success=false class=provider infra=true.

Requirement: Another retryable class retries

A stage attempt that ends with the class ci_infra, timeout or head_moved SHALL also exit 75 with its class on the result line.

Scenario: A clone that fails

  • WHEN run_stage_job clones the repository and the clone raises a GitOperationError.
  • THEN It returns exit code 75, and the captured result line holds class=ci_infra infra=true.

Requirement: A retried attempt keeps the check-out

A stage attempt that exits 75 for a retryable class SHALL NOT write stage.job_result or clear stage.job, so that the next pod of the Job plans the same item.

Scenario: The check-out after a provider timeout

  • WHEN A stage attempt ends with class provider and exits 75.
  • THEN The item record still holds stage.job with the Job's name and no stage.job_result, and the claim owner/service stays.

Requirement: A non-retryable failure fails

A stage attempt that ends with a class whose default action is not RETRY, such as plan_defect or oom, or with AICredentialsError, SHALL exit 1.

Scenario: A plan defect

  • WHEN The plan of the item ends with class plan_defect.
  • THEN The stage Job exits 1, and the result line holds class=plan_defect infra=false.

Requirement: The deadline end keeps its code

A stage attempt that the time budget ends SHALL exit 143 and MUST NOT exit 75, so the Job controller does not run it again with no time left.

Scenario: The time budget is spent

  • WHEN run_stage_job starts with no time left in its time budget.
  • THEN It returns exit code 143 with the result deadline, and the exit code is not 75.

Requirement: The stage policy already admits the retry code

The stage Job SHALL keep exit 75 as its only retry code, which backoffLimit: 2 and the podFailurePolicy of cronjob-stage.yaml retry and the admission policy admits, with no change to either manifest.

Scenario: The gate check of the stage Job

  • WHEN The gate check builds the stage Job from cronjob-stage.yaml and the admission policy judges it.
  • THEN The policy returns no refusal, and the podFailurePolicy fails the Job on each exit code but 75.

Existing Tool Considered

Kubernetes' Job controller covers the need: backoffLimit: 2 with a podFailurePolicy that fails the Job on each exit code but 75 already runs the pod again after exit 75 (k8s/devops/cronjob-stage.yaml:37), and the admission policy already admits exactly that rule (k8s/devops/roadmap-service/admissionpolicy.yaml:182). It lacks only the stage Job's mapping from a retryable failure class to exit 75, which run_stage_job adds; no new library is needed. alternatives is null, so no alternatives check has run.

Key questions

  • Which exit code should a stage attempt that ends with a provider timeout use?: Reuse exit code 75. It is the project's one code to try again later, and the stage pod failure policy already retries it within backoffLimit: 2. (best practice) [sources: docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md:233, k8s/devops/cronjob-stage.yaml:37, k8s/devops/cronjob-stage.yaml:43, docs/CLUSTER.md:78, openspec/specs/roadmap-stage/job/spec.md:88]
    • Chosen: Reuse exit code 75. The ADR says a roadmap process exits 75 to try again later and only exit 75 gets a retry, and the stage podFailurePolicy already excludes 75 from FailJob, so the Job controller runs the pod again with no manifest change.
    • Rejected: Add a new exit code. It needs a matching change to cronjob-stage.yaml and to the admission policy that pins the value 75, with no extra retry behavior.
    • Rejected: Keep exit code 1. The pod failure policy matches FailJob on 1, so Kubernetes makes no new pod, which is the bug.
  • Which failure classes map to the retry exit code?: The classes whose default action is RETRY in ACTION_BY_CLASS: provider, timeout, ci_infra and head_moved. The infra=true set is not the rule: it also holds oom and limit_reached, whose action is raise_limit, so they keep exit 1. AICredentialsError is never retried, as its own documentation says a retry cannot help. (best practice) [sources: src/devops_cli/roadmap/failure.py:118, src/devops_cli/roadmap/failure.py:125, src/devops_cli/roadmap/job_result.py:125, src/devops_cli/ai/client/models.py:144, src/devops_cli/roadmap/stage/stage.py:2461]
    • Chosen: The classes whose action is RETRY. The project keeps one table of the action of each class; a class that a retry fixes is exactly the class that gets 75, and a new class inherits the rule with no second list.
    • Rejected: The classes with infra=true. That set also holds oom and limit_reached, which a new pod cannot fix: their action is to raise a limit.
    • Rejected: provider and ci_infra only. It drops head_moved and timeout, whose recorded action is also a retry, and it invents a second list beside ACTION_BY_CLASS.
    • Rejected: Every class. A retry cannot fix a plan defect, a refused tool or a raised limit, and the Job would spend its two retries on it.
  • Where does the retry happen: in the stage Job or in the Service's next round?: In the stage Job, through exit 75 and the Job controller. The Service's next round would wait the class's RETRY_AFTER of one hour for a provider timeout that is often over in seconds. (best practice) [sources: k8s/devops/cronjob-stage.yaml:32, src/devops_cli/roadmap/failure.py:167, docs/CLUSTER.md:78, openspec/specs/roadmap-stage/job/spec.md:13]
    • Chosen: The Job controller retries the pod. backoffLimit: 2 and the podFailurePolicy already exist and cost no new create, and the template already makes a rerun safe by removing the branch of its own intent mark.
    • Rejected: The Service's next round after the failure wait. RETRY_AFTER waits one hour for provider and ci_infra, and the Service would also write a new Job for the item.
    • Rejected: A new Job created at once by the Service. It needs a new create path, a new wait rule and a new check-out, where exit 75 is already the lock and the retry.
  • Does the attempt that exits 75 check in on the item?: No. It writes only its result line and leaves the check-out and the claim, as the eviction end does. A check-in would record the class's failure wait, and the next pod would leave the item out for an hour and end the Job as a success with nothing planned. (best practice) [sources: openspec/specs/roadmap-stage/job/spec.md:99, openspec/specs/roadmap-stage/job/spec.md:56, src/devops_cli/roadmap/stage/stage_job.py:259, src/devops_cli/roadmap/stage/stage_job.py:426, src/devops_cli/roadmap/stage/stage_job.py:416]
    • Chosen: Leave the check-out and write only the line. The eviction end already exits 75 with the check-out in place, so the next pod knows the Job and plans the same item; the check-out is what the retry follows.
    • Rejected: Check in with the failure and exit 75. check_in writes stage.failed_at and stage.failed_class, and the next pod's selection leaves an item in its failure wait out, so the retry would plan nothing.
  • What result line should the stage Job write for a failure?: The existing line of log_job_result with result=failed, the class of the error and infra as the line computes it. infra=true holds for provider, ci_infra, oom and limit_reached; the class and the infra cut are not a new flag. (best practice) [sources: src/devops_cli/roadmap/job_result.py:157, src/devops_cli/roadmap/job_result.py:125, src/devops_cli/roadmap/stage/stage_job.py:286, docs/roadmap/job-success.md:14, docs/roadmap/job-success.md:20]
    • Chosen: Write the class with log_job_result. It is the one writer of the line, the Service's stage path already uses it through check_in, and the grade reads infra=true from it.
    • Rejected: Write no result line. The Job path then loses the class and the infrastructure cut that the Service path keeps, which is the reported gap.
    • Rejected: Write infra=true for every class that exits 75. The line's infra field means the class gives an infrastructure cut, not that the Job retried it, and the grade leaves only the infra=true attempts out of its ratio.
  • Where does the stage Job classify the error that ends the attempt?: In run_stage_job, around the clone and the plan, with failure_class_of(exc). That is where the Job's name, the check-out and the store are known, and where the deadline end already writes the line. (best practice) [sources: src/devops_cli/roadmap/stage/stage_job.py:395, src/devops_cli/roadmap/stage/stage_job.py:318, src/devops_cli/roadmap/failure.py:188, src/devops_cli/commands/roadmap.py:86]
    • Chosen: In run_stage_job. It holds the check-out, the Job's name and the line writer, and it is the unit that the offline test drives.
    • Rejected: In the command's _exit_on_failure. That context manager turns every error of the command into exit 1 with no class, and the stage rule would then live outside the stage module.
  • Do the stage CronJob and the admission policy need a new failure policy rule?: No. cronjob-stage.yaml already sets backoffLimit: 2 and a podFailurePolicy that ignores a disruption and fails the Job on each exit code but 75, and the admission policy pins exactly that rule and activeDeadlineSeconds: 10800. The gate checks already judge both. [sources: k8s/devops/cronjob-stage.yaml:37, k8s/devops/cronjob-stage.yaml:43, k8s/devops/roadmap-service/admissionpolicy.yaml:182, k8s/devops/roadmap-service/admissionpolicy.yaml:194, tests/gate/k8s_checks/stage_job.py:79, tests/gate/k8s_checks/job_admission_policy.py:466, docs/CLUSTER.md:78]
  • Should this change add a fallback model group for deepseek-v4.1-flash-1017?: No. The gateway already holds the group's fallback to deepseek-v4.1-flash through the same provider (fix(k8s): the DeepSeek gateway group gets a fallback group #5564), released in 0.134.1 (fix(k8s): the DeepSeek gateway group gets a fallback group #5565), and the issue defers the gateway to a separate item. This change names it in the PR and touches no gateway file. (best practice) [sources: k8s/llm/gateway/config.yaml:295, SECURITY.md:40, CHANGELOG.md:10]
    • Chosen: Leave the gateway unchanged. The fallback group already exists in the tree and shipped in 0.134.1, so there is nothing to add, and the gateway is outside a stage retry fix.
    • Rejected: Add a fallback group. It is already there at k8s/llm/gateway/config.yaml:295; a second change would only repeat it and mix a gateway edit into the retry fix.

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 13, 2026
  2. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor
    • Priority: P1-High. Production stage Jobs fail permanently on a transient provider timeout instead of retrying.
    • Related: feat(roadmap): stage retry time follows the failure class #4060, which asks for a different change. Both set stage retry behaviour by failure class; #4060 sets the wait time per class, the candidate sets the pod exit code so K8s retries.
  3. added
    priority/p1-high
    on Nov 13, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 14, 2026
  5. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

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

  6. added
    owner/service
    on Nov 14, 2026
  7. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    Staged: branch fix/5562-a-stage-job-retries-a-provider, draft pull request #5592. The pull request plans the item and closes no issue.

    The task groups, with the tokens of the inputs of each step, for a budget of 64000 tokens:

    1. Retry a stage attempt whose failure class a retry can help: 44429 tokens
    2. Pin the retry code of the stage Job in the gate check: 18615 tokens

    The default branch changed these paths that the plan names, after the commit that the planner read. Read the commits before you judge the plan:

    A model review of the plan found these points. They stop no draft, and a person judges them:

    • major verify_form at tasks (2): The verify command of group 2 runs devops ci test on a gate module. That module holds check_* functions, not pytest tests. The k8s row runs them through tests.gate.k8s and tests/gate/runner.py, and pytest does not collect them. The command never runs check_the_stage_job_retries_only_exit_75, and it can pass or fail whatever the check does. Evidence: "uv run devops ci test tests/gate/k8s_checks/job_admission_policy.py"

    The runs of the planner and the review made 73 model request(s), and used 4998698 input tokens and 98127 output tokens. The tool calls, in order:

    1. file_symbols({"path":"src/devops_cli/roadmap/stage/stage_job.py"})
    2. read_file({"path":"src/devops_cli/roadmap/failure.py","start_line":100,"end_line":200})
    3. read_file({"path":"src/devops_cli/roadmap/stage/stage_job.py","start_line":100,"end_line":200})
    4. read_file({"path":"src/devops_cli/roadmap/stage/stage_job.py","start_line":280,"end_line":460})
    5. read_file({"path":"src/devops_cli/roadmap/stage/stage_job.py","start_line":196,"end_line":290})
    6. search_code({"text":"run_stage_job"})
    7. read_file({"path":"src/devops_cli/commands/roadmap.py","start_line":500,"end_line":600})
    8. read_file({"path":"src/devops_cli/roadmap/job_result.py","start_line":100,"end_line":180})
    9. search_code({"text":"StageJobExit"})
    10. search_code({"text":"StageJobEnd"})
    11. read_file({"end_line":290,"path":"src/devops_cli/roadmap/stage/stage_submit.py","start_line":120})
    12. read_file({"path":"k8s/devops/cronjob-stage.yaml"})
    13. read_file({"end_line":100,"path":"src/devops_cli/roadmap/stage/stage_job.py","start_line":1})
    14. search_code({"text":"exits 75"})
    15. read_spec({"capability":"roadmap-stage/job"})
    16. read_spec({"capability":"roadmap-stage/job","requirement":"The stage Job ends with the exit code of its end and checks in"})
    17. read_spec({"capability":"roadmap-stage/job","requirement":"The stage Job writes one result line for its attempt after its check-in"})
    18. read_file({"end_line":300,"path":"tests/roadmap/stage/test_roadmap_stage_job_entry.py","start_line":230})
    19. read_file({"end_line":400,"path":"tests/roadmap/stage/test_roadmap_stage_job_entry.py","start_line":340})
    20. read_file({"end_line":160,"path":"src/devops_cli/ai/client/models.py","start_line":60})
    21. search_code({"text":"AIClientError("})
    22. read_file({"end_line":540,"path":"tests/roadmap/stage/test_roadmap_stage_refused_reply.py","start_line":470})
    23. search_code({"text":"except AIClientError"})
    24. search_code({"text":"def stage_results"})
    25. search_code({"text":"def log_stage_attempts"})
    26. read_file({"end_line":3900,"path":"src/devops_cli/roadmap/stage/stage.py","start_line":3780})
    27. search_code({"text":"model call failed"})
    28. search_code({"text":"class StageFailure"})
    29. search_code({"text":"AIClientError"})
    30. search_code({"text":"FailureClass.PROVIDER"})
    31. search_code({"text":"StageFailure("})
    32. read_file({"end_line":2470,"path":"src/devops_cli/roadmap/stage/stage.py","start_line":2395})
    33. search_code({"text":"class DevOpsCLIError"})
    34. search_code({"text":"class ServiceStoppingError"})
    35. read_file({"end_line":80,"path":"src/devops_cli/exceptions/roadmap.py","start_line":1})
    36. read_file({"end_line":70,"path":"src/devops_cli/roadmap/attempt_kill.py","start_line":20})
    37. search_code({"text":"INFRA_CLASSES"})
    38. search_code({"text":"infra"})
    39. search_code({"text":"infra="})
    40. read_file({"end_line":430,"path":"src/devops_cli/roadmap/stage/stage_submit.py","start_line":290})
    41. search_code({"text":"FailureAction.RETRY"})
    42. read_file({"path":"src/devops_cli/roadmap/stop_clear.py","start_line":185,"end_line":205})
    43. read_spec({"capability":"roadmap-stage/job"})
    44. read_spec({"capability":"roadmap-stage/job","requirement":"The stage Job ends with the exit code of its end and checks in"})
    45. read_spec({"capability":"roadmap-stage/job","requirement":"The stage Job writes one result line for its attempt after its check-in"})
    46. search_code({"text":"def _stage_job"})
    47. read_file({"path":"src/devops_cli/roadmap/stage/stage_job.py","start_line":240,"end_line":460})
    48. read_file({"path":"src/devops_cli/roadmap/stage/stage_job.py","start_line":413,"end_line":470})
    49. search_code({"text":"def check_"})
    50. search_code({"text":"def check_"})
    51. read_file({"path":"src/devops_cli/roadmap/failure.py","start_line":140,"end_line":230})
    52. search_code({"text":"k8s_checks"})
    53. read_file({"path":"tests/gate/runner.py","end_line":80})
    54. search_code({"text":"def check_"})
    55. file_symbols({"path":"tests/gate/k8s_checks/job_admission_policy.py"})
    56. read_file({"path":"tests/gate/k8s_checks/job_admission_policy.py","start_line":462,"end_line":660})
    57. search_code({"text":"tests/gate/k8s_checks/"})
    58. search_code({"text":"tests/gate/runner"})
    59. search_code({"text":"devops ci k8s"})
    60. search_code({"text":"python_functions"})
    61. search_code({"text":"python_files"})
    62. search_code({"text":"tests.gate.k8s_checks"})
    63. read_file({"path":"tests/gate/k8s.py"})
    64. search_code({"text":"\"k8s\" row"})
    65. search_code({"text":"tests.gate.k8s"})
    66. search_code({"text":"def test("})
    67. read_file({"path":"src/devops_cli/commands/ci.py","start_line":1960,"end_line":2060})
    68. search_code({"text":"def ci_k8s"})
    69. search_code({"text":"k8s_checks"})
    70. search_code({"text":"\"k8s\""})
    71. search_code({"text":"devops ci k8s"})
    72. search_code({"text":"def _python_check_cmd"})
    73. read_file({"path":"src/devops_cli/commands/ci.py","start_line":960,"end_line":1000})
    74. read_file({"end_line":830,"path":"src/devops_cli/commands/ci.py","start_line":780})
    75. search_code({"text":"CONST_GATE_ROW_SCRIPT ="})
    76. search_code({"text":"--only"})
    77. read_file({"path":"tests/gate/k8s.py"})
    78. search_code({"text":"kubectl"})
    79. search_code({"text":"python_functions"})
    80. list_files({"directory":"tests/gate"})
    81. read_file({"path":"tests/gate/k8s_render.py"})
    82. search_code({"text":"job_admission_policy"})
    83. read_file({"path":"tests/gate/runner.py"})
    84. search_code({"text":"--only k8s"})
    85. search_code({"text":"ci k8s"})
    86. read_file({"path":"src/devops_cli/roadmap/stage/stage_job.py","start_line":380,"end_line":432})
    87. read_file({"path":"src/devops_cli/roadmap/job_result.py","start_line":118,"end_line":132})
    88. read_file({"end_line":50,"path":"k8s/devops/cronjob-stage.yaml","start_line":28})
    89. read_file({"end_line":80,"path":"docs/CLUSTER.md","start_line":74})
    90. search_code({"text":"check_the_stage_job_retries"})
    91. search_code({"text":"_stage_retries"})
    92. search_code({"text":"def _stage_job"})
    93. search_code({"text":"_python_check_cmd(\"k8s\")"})
    94. search_code({"text":"\"--only\""})

    Tool calls: file_symbols=2 (empty=0), list_files=1 (empty=0), read_file=35 (empty=0), read_spec=6 (empty=0), search_code=50 (empty=9)

    The stage job read the open pull requests and their files in 1 GraphQL request(s).

  8. removed
    owner/service
    on Nov 14, 2026
  9. added a commit that references this issue on Nov 14, 2026
  10. 2 remaining items

  11. added
    status/planned
    and removed
    status/ready
    on Nov 14, 2026
  12. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/planned
    status/in-progress
    on Nov 14, 2026
  13. removed
    status/in-review
    owner/agent
    on Nov 14, 2026
  14. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-14 21:08 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