Skip to content

fix(roadmap): limit each agent run of fix-plan below the budget margin #5379

Not planned

Description

@dan-petty

Problem

One agent run of the fix-plan step (a plan run or a review run) has no time limit of its own. The time budget of #5363 (PR #5380) is checked only before each run, and it keeps a margin of 1200 s below the Job deadline for one more run. On 2026-11-13 the longest run of the #5350 attempt took 1013 s, close to that margin. A longer run would pass the Job deadline, and the attempt would end with no result line again.

The first text of this item said that the attempt stalled for 39 minutes. That was false: the full Tempo trace (12.6 MB) shows continuous work until the Job deadline. A read through the Grafana MCP proxy stops at its 10 MiB limit, so the summary showed an early end. The evidence is in the comment above.

Proposed fix

Give each agent run of fix-plan an upper limit from a setting, below the margin that the step budget keeps (nested timeouts: run limit < margin < Job deadline). When a run reaches its limit, stop it, keep the plan branch as it is, and end the attempt with the timeout result line of #5363.

Acceptance criteria

  • A test with a run that does not end finds the timeout result line before the margin ends. It fails on main (devops ci fail-to-pass).
  • A test holds the order: run limit < step margin < Job deadline of the templates.

Dependencies

Depends on #5380 (the step budget).

Alternatives check of 2026-11-28: in-use.
The repository already uses this tool.
Tool: pydantic/pydantic-ai (https://github.com/pydantic/pydantic-ai), MIT, last activity 2026-11-28, maintained.
Reason: Searches found no other maintained tool; pydantic-ai, already the project's agent framework, gives the before_model_request hook and per-request timeout that bound each fix-plan run, so only the setting, validation, docs and template check remain to build.

Covers:

  • before_model_request hook runs before every model request
  • Per-request timeout bounds one request by remaining run time
  • run_sync returns control between requests so the hook can stop a run

Lacks:

  • No built-in wall-clock limit for one whole agent run
  • No run-limit setting, validation or generated config reference
  • No timeout result line or nested template deadline check

Proposed design

Problem statement

Hold this item until a person closes #6521 after the re-architecture experiments of #6519 decide. One fix-plan run has no wall-clock limit of its own: the step checks its time budget only before each run, and it keeps a 1200 s margin below the Job deadline. The longest run of the #5350 attempt took 1013 s, so a longer run passes the deadline and the attempt ends with no result line. The fix adds roadmap.fix_plan.run_time_limit_seconds with a default of 1080 s and stops a run that reaches it with the timeout result line.

Acceptance criteria

Requirement: Per-run limit ends a fix-plan run

The fix-plan step SHALL stop one agent run when it reaches roadmap.fix_plan.run_time_limit_seconds and SHALL end the attempt with the timeout result line.

Scenario: A run past its limit writes the timeout line

  • WHEN A test runs the fix-plan step with roadmap.fix_plan.run_time_limit_seconds of 1 s and roadmap.fix_plan.time_budget_seconds of 60 s, and its fake model reply advances the clock past the run limit and asks for another request.
  • THEN The run raises RoadmapTimeBudgetError before the next request, the plan branch keeps its last commit, the result line holds result=timeout and class=timeout, and uv run devops ci fail-to-pass --base origin/main shows the test fails on main.

Requirement: A model request cannot pass the run limit

The fix-plan step MUST give each model request no more time than remains before the run limit.

Scenario: The last request gets only the remaining time

  • WHEN A test sets roadmap.fix_plan.run_time_limit_seconds to 100 s, advances the fake clock to 90 s of the run, and starts one model request.
  • THEN The step gives the request a timeout of 10 s, and a run whose remaining time is zero raises RoadmapTimeBudgetError before the request starts.

Requirement: The settings refuse a run limit at or above the budget

The settings load MUST refuse a fix-plan run limit at or above roadmap.fix_plan.time_budget_seconds.

Scenario: A run limit at the budget is refused

  • WHEN A test loads the settings with roadmap.fix_plan.run_time_limit_seconds equal to roadmap.fix_plan.time_budget_seconds.
  • THEN The load raises a validation error that names both settings, and the same test loads with a run limit 1 s below the budget.

Requirement: The generated reference lists the setting

The generated configuration reference MUST list roadmap.fix_plan.run_time_limit_seconds with its default.

Scenario: The generated docs are current

  • WHEN uv run devops docs check runs after uv run devops docs generate.
  • THEN The command exits 0 with no stale generated document, and docs/CONFIGURATION.md lists run_time_limit_seconds with the default 1080.

Requirement: The default run limit stays below the budget margin

The default fix-plan run limit MUST stay below the margin that the fix-plan budget keeps below the Job deadline.

Scenario: The default fits the margin

  • WHEN A test compares DEFAULT_ROADMAP_FIX_PLAN_RUN_TIME_LIMIT_SECONDS with the fix-plan budget margin constant.
  • THEN The run limit is below the margin, and the test fails when the default equals the margin.

Requirement: The templates hold the nested order

The k8s gate check MUST refuse a rendered roadmap CronJob whose activeDeadlineSeconds is below the fix-plan budget plus its margin.

Scenario: The rendered templates hold the nested order

  • WHEN uv run devops ci --check --only k8s renders the roadmap CronJob templates.
  • THEN The command exits 0, and it exits 1 naming the template when activeDeadlineSeconds is below roadmap.fix_plan.time_budget_seconds plus the margin.

Existing Tool Considered

The alternatives check in the issue body gives the verdict in-use for pydantic/pydantic-ai (MIT, maintained). The check lists what the library covers and what it lacks. This change uses the before_model_request hook to stop a run at its limit. It sets the timeout of each request to the remaining run time. It adds the setting, its validation, the result line and the nested-order check that the library lacks. The cost is about 30k tokens to build this code. Each later fix costs about 5k tokens. The elapsed time is 1 to 2 days.

Key questions

  • Does one fix-plan run have a wall-clock limit of its own today?: No. The step checks roadmap.fix_plan.time_budget_seconds (3600 s) before each run, and ai.request_timeout_seconds (1200 s) limits one model request. No limit covers the whole run. [sources: docs/CONFIGURATION.md, src/devops_cli/config/defaults.py:1225, src/devops_cli/config/defaults.py:151, src/devops_cli/roadmap/time_budget.py]
  • What margin does the fix-plan budget keep below the Job deadline?: 1200 s, as the issue states. The step starts a run only when that much time remains. The longest run of docs(openspec): plan #5118 Restore the Status on a claim release #5350 took 1013 s, near that margin. [sources: src/devops_cli/roadmap/time_budget.py, docs/CONFIGURATION.md]
  • Which item must be delivered before this one?: chore(roadmap): hold incremental stage and implement work #6521. A person closes chore(roadmap): hold incremental stage and implement work #6521 after the re-architecture experiments of refactor(roadmap): re-architect stage and implement on Coder #6519 decide. The step budget of fix(roadmap): fix-plan ends at the Job deadline with no result line #5363 is delivered: roadmap.fix_plan.time_budget_seconds is in the generated reference. [sources: docs/CONFIGURATION.md, src/devops_cli/config/settings.py:2063]
  • How does the step stop one agent run at its limit?: A before_model_request hook raises RoadmapTimeBudgetError when the run limit is spent. It also sets the timeout of each request to the remaining run time, so one request cannot pass the limit. (best practice) [sources: src/devops_cli/roadmap/implement/implement_limits.py, src/devops_cli/roadmap/time_budget.py, src/devops_cli/exceptions/roadmap.py:280]
    • Chosen: before_model_request hook with the remaining-time timeout. It runs before each request, it bounds the request, and the step maps the error to the timeout line.
    • Rejected: asyncio.timeout around each run. The planner calls agent.run_sync, so no event loop exists to cancel.
    • Rejected: HTTP client read timeout. It applies to each read, so a reply that keeps streaming is never stopped.
    • Rejected: The 1200 s request timeout as the only inner limit. It ends one request, not the run, so a run of several requests passes the margin.
    • Rejected: Keep the step budget only. A run that starts near the budget end passes the Job deadline, as the 1013 s run shows.
  • What default does the per-run limit take?: 1080 s. It is below the 1200 s margin, with 120 s for the push and the result line, and above the 1013 s longest run of docs(openspec): plan #5118 Restore the Status on a claim release #5350. (best practice) [sources: docs/CONFIGURATION.md, src/devops_cli/config/defaults.py:1225, src/devops_cli/config/defaults.py:151]
    • Chosen: 1080 s. It stays below the margin, keeps 120 s for the push and the result line, and stays above the 1013 s run.
    • Rejected: 1500 s. It is above the 1200 s margin, so a run at the limit passes the Job deadline.
    • Rejected: 1200 s. It equals the margin, so no time stays for the push and the result line.
    • Rejected: 900 s. It is below the 1013 s longest run of docs(openspec): plan #5118 Restore the Status on a claim release #5350, so a normal long run is cut.
    • Rejected: 3600 s. It equals the step budget, so it adds no limit below the budget.
  • Which setting holds the per-run limit?: roadmap.fix_plan.run_time_limit_seconds, in RoadmapFixPlanConfig, with the precedence of the other fix-plan settings. (best practice) [sources: src/devops_cli/config/settings.py:2063, docs/CONFIGURATION.md]
    • Chosen: roadmap.fix_plan.run_time_limit_seconds. It follows the _seconds suffix and sits in the fix-plan group with the other limits.
    • Rejected: roadmap.fix_plan.run_limit_s. The settings use _seconds for a time limit, not _s.
    • Rejected: A constant in the step code. It gives no way to tune the limit for a slow model tier.
  • Which result line ends an attempt that the per-run limit stops?: The timeout line of fix(roadmap): fix-plan ends at the Job deadline with no result line #5363, with result=timeout and class=timeout. The step maps RoadmapTimeBudgetError to the timeout class, as the stage step does. (best practice) [sources: src/devops_cli/exceptions/roadmap.py:280, src/devops_cli/roadmap/stage/stage.py, tests/roadmap/test_roadmap_limit_classes.py]
    • Chosen: The timeout line. One cause has one class, and the existing retry and label rules handle timeout.
    • Rejected: A new run-timeout class. Two classes for one cause split the job grade count and the dashboards.
    • Rejected: failed. A run limit is a time stop, not a model or check failure.

Fit

Fits in one pull request.

Suspected block

The re-architecture experiments of #6519 must decide, and a person must then close #6521 or close this item as not planned.

Dependencies

#6521

Activity

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

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    on Nov 13, 2026
  4. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor

    A lead for the cause: the worker node hawk hung at about the same time. Its last journal line in Loki is at 04:38:28Z, 10 s after the last span of this attempt (04:38:18Z). The kubelet stopped reporting at 04:40:08Z, and the node did not come back. hawk was cordoned and ran only DaemonSet pods. Check whether a request of the attempt went through hawk (a DaemonSet on that node in the path, a model tier, DNS or the pod network) and whether the call had a client timeout that should have fired.

  5. added
    owner/agent
    on Nov 13, 2026
  6. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor

    The premise of this item is false: the fix-plan attempt did not stall. No call hung, so no client timeout had to fire. I return the item to New with this evidence.

    Evidence (read on 2026-11-13 by trace ID from the Tempo API /api/v2/traces/fbef6e37a8678ee158d313142a3f044e, and from Prometheus):

    • The trace holds 7351 spans. The spans of the step process (one pod of Job fix-plan-5350, process.pid 1) continue to 05:15:34Z. The LLM gateway spans continue to 05:15:38Z.
    • The largest gap between two span ends of the step process is 531 s (04:55:10Z to 05:04:01Z). The second largest is 422 s (04:43:17Z to 04:50:19Z). Each gap is one model request in progress.
    • These two model requests are the longest of the trace. The request at 04:43:15Z took 424 s and gave 44,346 output tokens (43,649 reasoning tokens). The request at 04:55:07Z took 534 s and gave 39,729 output tokens (32,835 reasoning tokens). Both ended with the finish reason tool_call. The gateway sent HTTP 200 after about 2 s and then streamed the reply. All 217 model requests of the trace ended.
    • The attempt made 11 agent runs that ended, and one more run was in progress at the end. The runs after 04:33Z took 1013 s (04:33:25Z to 04:50:19Z), 821 s (04:50:19Z to 05:04:01Z), 500 s (05:04:10Z to 05:12:30Z) and 117 s (05:12:37Z to 05:14:34Z).
    • The pod started at 03:45:08Z (kube_pod_start_time). 5400 s after that is 05:15:08Z. The last span of the step ends 26 s later, in the termination grace period. Thus the Job deadline stopped a process that still did work.
    • The pod ran on a different worker node, not on the node that hung at 04:38:28Z (kube_pod_info). The spans of the step continue after 04:38:28Z. Thus the node failure did not stop the attempt.
    • Why the trace looked short: the Tempo search summary of this trace gives a duration of 3,172,907 ms, an end at 04:40:35Z. The full trace is 12.6 MB, and a read through the Grafana API proxy of the Grafana MCP server stops at 10 MiB. Read the trace by its ID from the Tempo API to get all spans.

    Client timeouts on origin/main: drain_events in src/devops_cli/roadmap/agent_run.py streams each model request (#2379). The read timeout of an HTTP client applies to each read, so it does not stop a reply that continues to send chunks. That is correct for these requests: each one sent chunks until it ended.

    What is left: the attempt needed more than 5400 s of work. #5363 (pull request #5380) covers this failure. With its default budget of 3600 s, the budget ends at about 04:45Z, the run in progress ends at 04:50:19Z, the step starts no new run, and it writes the result line with class timeout. One agent run has no upper limit of its own, and the longest run of this attempt (1013 s) is near the margin of 1200 s that #5380 keeps for one more run. If a limit on each agent run is necessary, write that as the new body of this item. Else close this item as covered by #5363.

  7. removed
    owner/agent
    on Nov 13, 2026
  8. changed the title [-]fix(roadmap): find the 39-minute stall of a fix-plan attempt[/-] [+]fix(roadmap): limit each agent run of fix-plan below the budget margin[/+] on Nov 13, 2026
  9. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: Searches for a library that bounds a single agent run (per-run timeouts, nested deadline budgets, streaming LLM run limits) returned only unrelated material — web-platform timer APIs (setTimeout, XMLHttpRequest.timeout), an HTTP 408 page and container images — and nothing that imposes an upper limit on one agent run of a job. The need is a change inside the project's own fix-plan runner (a per-run limit from a setting, the nested order run limit < step margin < Job deadline, stopping the run and writing the timeout result line of #5363, plus the two tests), which no external tool provides.

    Tool: none found

    Lacks:

    • An upper time limit for each agent run of the fix-plan step, taken from a setting
    • Nested timeout ordering: run limit < step budget margin < Job deadline
    • Stopping a run at its limit, keeping the plan branch as it is, and ending the attempt with the timeout result line of fix(roadmap): fix-plan ends at the Job deadline with no result line #5363
    • A test in the project's suite that an unending run yields the timeout line before the margin, and a test that holds the order of the three limits

    Searches run:

    • asyncio.timeout cancel scope per task deadline python 3.11, results: 5
    • kubernetes Job activeDeadlineSeconds nested timeout step budget, results: 5
    • python enforce per-run timeout agent run streaming LLM nested deadline library, results: 5
    • pydantic-ai run timeout usage limits request timeout, results: 5
    • timeout budget agent loop open source library python, results: 5
    • anyio fail_after move_on_after timeout cancel scope documentation, results: 5
    • pydantic-ai agent run timeout documentation, results: 5
    • python httpx read timeout streaming response not stopping long stream, results: 5
    • "step timeout" "job deadline" nested timeout kubernetes template test, results: 5
    • github pydantic-ai timeout agent run, results: 5

    Sources:

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

  10. added
    status/ready
    and removed
    status/new
    on Nov 17, 2026
  11. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

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

  12. dan-petty commented on Nov 20, 2026

    @dan-petty
    OwnerAuthor

    Frozen on 2026-11-20. The stage, implement and fix-checks jobs grade under 60%, so the owner rule asks for a re-architecture before more fixes inside the current design (tracker #6519). This item is incremental work on those jobs, so its Dependencies section now names #6521 first. Stage and implement leave this item while #6521 is open. When the experiments of #6519 decide, a person closes #6521 (this item can then continue) or closes this item as not planned.

  13. devops-cli-service commented on Nov 22, 2026

    @devops-cli-service
    Contributor

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

    Searches (10)

    Tools considered:

    Searches run:

    • pydantic-ai per-run wall clock timeout limit agent run, results: 5
    • python library enforce timeout on LLM agent run nested timeouts budget, results: 5
    • pydantic-ai UsageLimits timeout documentation agent run, results: 5
    • "pydantic-ai" request timeout model settings documentation, results: 5
    • pydantic-ai GitHub time limit per run issue timeout, results: 5
    • LLM agent framework wall-clock deadline per run budget guard library, results: 5
    • ai.pydantic.dev timeouts, results: 5
    • github pydantic pydantic-ai, results: 5
    • "before_model_request" pydantic-ai hooks, results: 5
    • pydantic-ai time budget plugin per-run deadline, results: 5

    Sources:

  14. added
    status/new
    and removed
    status/ready
    on Nov 27, 2026
  15. devops-cli-service commented on Nov 27, 2026

    @devops-cli-service
    Contributor

    Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies in the section Proposed design of the body.

  16. dan-petty commented on Nov 30, 2026

    @dan-petty
    OwnerAuthor

    Triage under #6519 (owner instruction of 2026-11-30), before the hold #6521 closes. This item adds or extends a gate, refusal, screen, cap, limit, retry, result line, shell allowlist, tool catalog or plan-shape rule of the stage, implement or fix-checks job. #6519 found that 263 of about 900 issues in four weeks added such rules and none replaced the engine. Stage now runs on stock Coder (grade 60 on 30 graded attempts), where the agent reads the repository, runs the checks in its loop and has a real shell; implement follows (#6527). The code paths that this item names have also moved. If the failure class still shows in graded attempts, file a new item from that evidence. Closed as not planned; a person may reopen it.

  17. removed
    status/new
    on Nov 30, 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/mediumpriority/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