Repository navigation
Description
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):
devops-cli-stage-devops-cli-2594-6070e1(refactor(review): Pass AGENTS.md to the review prompt and set digest #2594) failed at 22:17:17Z after 26 min.devops-cli-stage-devops-cli-2713-9b5216(refactor(security): Remove the unused fallback path from the scanner base class #2713) failed at 22:18:56Z after 27 min.- Each printed
AIClientError: LLM_INFERENCE_ERROR, timeout (HTTP 504 Gateway Timeout)and exited 1. The pod failure policy matchedFailJob(exit code 1 is not 75), so Kubernetes made no new pod. - At the same seconds, the gateway logged
litellm.Timeout: Timeout Error: OpenrouterException - A Timeout OccurredandNo fallback model group found for lookup_groups=deepseek-v4.1-flash-1017(a mid-stream fallback error). - No result line for these attempts is in Loki. The Service in-pod stage path wrote
class=provider infra=truefor the same kind of failure (feat(ci): Add ast-grep rules for RLIMIT_NPROC, O_NONBLOCK, os.killpg #1976 at 0.132.1), so it did not count against the job. The Job path loses that class.
Cause
roadmap/stage/stage_job.pymaps a failed result toStageJobExit.FAILURE(exit 1). Only SIGTERM givesEVICTED(75), which the pod failure policy retries.- A provider timeout is a transient infrastructure failure, the same class as
providerinroadmap/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 withinbackoffLimit. - Write the result line with
infra=trueand 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
podFailurePolicyofcronjob-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
providergets the retry exit code and a result line withinfra=true(devops ci fail-to-pass). - A test with class
plan_defectkeeps 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_jobplans an item and its model call raises anAIClientErrorwith 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_jobclones the repository and the clone raises aGitOperationError. - 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
providerand exits 75. - THEN The item record still holds
stage.jobwith the Job's name and nostage.job_result, and the claimowner/servicestays.
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_jobstarts 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.yamland the admission policy judges it. - THEN The policy returns no refusal, and the
podFailurePolicyfails 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
podFailurePolicyalready excludes 75 fromFailJob, 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.yamland to the admission policy that pins the value 75, with no extra retry behavior. - Rejected: Keep exit code 1. The pod failure policy matches
FailJobon 1, so Kubernetes makes no new pod, which is the bug.
- 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
- Which failure classes map to the retry exit code?: The classes whose default action is
RETRYinACTION_BY_CLASS:provider,timeout,ci_infraandhead_moved. Theinfra=trueset is not the rule: it also holdsoomandlimit_reached, whose action israise_limit, so they keep exit 1.AICredentialsErroris 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 holdsoomandlimit_reached, which a new pod cannot fix: their action is to raise a limit. - Rejected:
providerandci_infraonly. It dropshead_movedandtimeout, whose recorded action is also a retry, and it invents a second list besideACTION_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.
- Chosen: The classes whose action is
- 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_AFTERof 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: 2and thepodFailurePolicyalready 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_AFTERwaits one hour forproviderandci_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.
- Chosen: The Job controller retries the pod.
- 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_inwritesstage.failed_atandstage.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_resultwithresult=failed, the class of the error andinfraas the line computes it.infra=trueholds forprovider,ci_infra,oomandlimit_reached; the class and theinfracut 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 throughcheck_in, and the grade readsinfra=truefrom 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=truefor every class that exits 75. The line'sinfrafield means the class gives an infrastructure cut, not that the Job retried it, and the grade leaves only theinfra=trueattempts out of its ratio.
- Chosen: Write the class with
- Where does the stage Job classify the error that ends the attempt?: In
run_stage_job, around the clone and the plan, withfailure_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.
- Chosen: In
- Do the stage CronJob and the admission policy need a new failure policy rule?: No.
cronjob-stage.yamlalready setsbackoffLimit: 2and apodFailurePolicythat ignores a disruption and fails the Job on each exit code but 75, and the admission policy pins exactly that rule andactiveDeadlineSeconds: 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 todeepseek-v4.1-flashthrough 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
dan-petty commentedon Nov 13, 2026
Production stage Jobs fail permanently on a transient provider timeout instead of retrying.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.devops-cli-service commentedon Nov 14, 2026
Status set to Ready at ffce5d9 (see proposed design in issue body).
devops-cli-service commentedon Nov 14, 2026
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:
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:
src/devops_cli/roadmap/job_result.py: 9de03b4 docs(ai): add the agentic jobs guideline and the job decisions (docs(ai): add the agentic jobs guideline and the job decisions #5489)docs/CLUSTER.md: 3f08f8a docs(k8s): add the Kubernetes guideline and the capacity decisions (docs(k8s): add the Kubernetes guideline and the capacity decisions #5492)A model review of the plan found these points. They stop no draft, and a person judges them:
verify_format tasks (2): The verify command of group 2 runsdevops ci teston a gate module. That module holdscheck_*functions, not pytest tests. Thek8srow runs them throughtests.gate.k8sandtests/gate/runner.py, and pytest does not collect them. The command never runscheck_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:
file_symbols({"path":"src/devops_cli/roadmap/stage/stage_job.py"})read_file({"path":"src/devops_cli/roadmap/failure.py","start_line":100,"end_line":200})read_file({"path":"src/devops_cli/roadmap/stage/stage_job.py","start_line":100,"end_line":200})read_file({"path":"src/devops_cli/roadmap/stage/stage_job.py","start_line":280,"end_line":460})read_file({"path":"src/devops_cli/roadmap/stage/stage_job.py","start_line":196,"end_line":290})search_code({"text":"run_stage_job"})read_file({"path":"src/devops_cli/commands/roadmap.py","start_line":500,"end_line":600})read_file({"path":"src/devops_cli/roadmap/job_result.py","start_line":100,"end_line":180})search_code({"text":"StageJobExit"})search_code({"text":"StageJobEnd"})read_file({"end_line":290,"path":"src/devops_cli/roadmap/stage/stage_submit.py","start_line":120})read_file({"path":"k8s/devops/cronjob-stage.yaml"})read_file({"end_line":100,"path":"src/devops_cli/roadmap/stage/stage_job.py","start_line":1})search_code({"text":"exits 75"})read_spec({"capability":"roadmap-stage/job"})read_spec({"capability":"roadmap-stage/job","requirement":"The stage Job ends with the exit code of its end and checks in"})read_spec({"capability":"roadmap-stage/job","requirement":"The stage Job writes one result line for its attempt after its check-in"})read_file({"end_line":300,"path":"tests/roadmap/stage/test_roadmap_stage_job_entry.py","start_line":230})read_file({"end_line":400,"path":"tests/roadmap/stage/test_roadmap_stage_job_entry.py","start_line":340})read_file({"end_line":160,"path":"src/devops_cli/ai/client/models.py","start_line":60})search_code({"text":"AIClientError("})read_file({"end_line":540,"path":"tests/roadmap/stage/test_roadmap_stage_refused_reply.py","start_line":470})search_code({"text":"except AIClientError"})search_code({"text":"def stage_results"})search_code({"text":"def log_stage_attempts"})read_file({"end_line":3900,"path":"src/devops_cli/roadmap/stage/stage.py","start_line":3780})search_code({"text":"model call failed"})search_code({"text":"class StageFailure"})search_code({"text":"AIClientError"})search_code({"text":"FailureClass.PROVIDER"})search_code({"text":"StageFailure("})read_file({"end_line":2470,"path":"src/devops_cli/roadmap/stage/stage.py","start_line":2395})search_code({"text":"class DevOpsCLIError"})search_code({"text":"class ServiceStoppingError"})read_file({"end_line":80,"path":"src/devops_cli/exceptions/roadmap.py","start_line":1})read_file({"end_line":70,"path":"src/devops_cli/roadmap/attempt_kill.py","start_line":20})search_code({"text":"INFRA_CLASSES"})search_code({"text":"infra"})search_code({"text":"infra="})read_file({"end_line":430,"path":"src/devops_cli/roadmap/stage/stage_submit.py","start_line":290})search_code({"text":"FailureAction.RETRY"})read_file({"path":"src/devops_cli/roadmap/stop_clear.py","start_line":185,"end_line":205})read_spec({"capability":"roadmap-stage/job"})read_spec({"capability":"roadmap-stage/job","requirement":"The stage Job ends with the exit code of its end and checks in"})read_spec({"capability":"roadmap-stage/job","requirement":"The stage Job writes one result line for its attempt after its check-in"})search_code({"text":"def _stage_job"})read_file({"path":"src/devops_cli/roadmap/stage/stage_job.py","start_line":240,"end_line":460})read_file({"path":"src/devops_cli/roadmap/stage/stage_job.py","start_line":413,"end_line":470})search_code({"text":"def check_"})search_code({"text":"def check_"})read_file({"path":"src/devops_cli/roadmap/failure.py","start_line":140,"end_line":230})search_code({"text":"k8s_checks"})read_file({"path":"tests/gate/runner.py","end_line":80})search_code({"text":"def check_"})file_symbols({"path":"tests/gate/k8s_checks/job_admission_policy.py"})read_file({"path":"tests/gate/k8s_checks/job_admission_policy.py","start_line":462,"end_line":660})search_code({"text":"tests/gate/k8s_checks/"})search_code({"text":"tests/gate/runner"})search_code({"text":"devops ci k8s"})search_code({"text":"python_functions"})search_code({"text":"python_files"})search_code({"text":"tests.gate.k8s_checks"})read_file({"path":"tests/gate/k8s.py"})search_code({"text":"\"k8s\" row"})search_code({"text":"tests.gate.k8s"})search_code({"text":"def test("})read_file({"path":"src/devops_cli/commands/ci.py","start_line":1960,"end_line":2060})search_code({"text":"def ci_k8s"})search_code({"text":"k8s_checks"})search_code({"text":"\"k8s\""})search_code({"text":"devops ci k8s"})search_code({"text":"def _python_check_cmd"})read_file({"path":"src/devops_cli/commands/ci.py","start_line":960,"end_line":1000})read_file({"end_line":830,"path":"src/devops_cli/commands/ci.py","start_line":780})search_code({"text":"CONST_GATE_ROW_SCRIPT ="})search_code({"text":"--only"})read_file({"path":"tests/gate/k8s.py"})search_code({"text":"kubectl"})search_code({"text":"python_functions"})list_files({"directory":"tests/gate"})read_file({"path":"tests/gate/k8s_render.py"})search_code({"text":"job_admission_policy"})read_file({"path":"tests/gate/runner.py"})search_code({"text":"--only k8s"})search_code({"text":"ci k8s"})read_file({"path":"src/devops_cli/roadmap/stage/stage_job.py","start_line":380,"end_line":432})read_file({"path":"src/devops_cli/roadmap/job_result.py","start_line":118,"end_line":132})read_file({"end_line":50,"path":"k8s/devops/cronjob-stage.yaml","start_line":28})read_file({"end_line":80,"path":"docs/CLUSTER.md","start_line":74})search_code({"text":"check_the_stage_job_retries"})search_code({"text":"_stage_retries"})search_code({"text":"def _stage_job"})search_code({"text":"_python_check_cmd(\"k8s\")"})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).
docs(openspec): plan #5562 Retry a stage attempt on a provider timeout
2 remaining items
docs(openspec): address shepherd review findings for #5562
docs(openspec): align criteria with issue acceptance criteria in #5562
docs(openspec): plan #5562 Retry a stage attempt on a provider timeout (
devops-cli-service commentedon Nov 14, 2026
Released in v0.142.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.142.0
devops-cli-service commentedon Nov 14, 2026
Live since 2026-11-14 21:08 UTC