Skip to content

feat(roadmap): Tune stage planner caps from run data #3241

Closed

Description

@dan-petty

Problem

The limits of a plan run were set by guess: 200 tool calls (CONST_ROADMAP_STAGE_TOOL_MAX_CALLS), a cap on characters for each answer, a cap on commits for git_log, a cap on files for repo_map, and a token window of 65536 (the configmap). #3223 raised the soft caps, and the owner said to remove time and token limits where possible. We do not know which of the remaining caps cut a useful answer, and which only waste tokens.

Proposed change

Use the telemetry of #3240 and the comparison of the toolsets (#3239) to set each cap from data, not from a guess.

  1. For one week of plan runs, record for each tool the share of answers that the cap cut, and whether the plan that followed cited the cut part (the quoted line or the file name was in the cut part).
  2. Raise a cap where a cut answer led to a defect, and lower it where no answer came near the cap.
  3. State each value and its evidence in the constant docstring.

Acceptance criteria

  1. Each cap has a docstring with the measured value and the date.
  2. No cap cuts more than 5% of the answers of the week, or the docstring says why.
  3. A test keeps the caps in line with the soft-cap class guard of perf(roadmap): raise the soft caps and timeouts of the jobs #3223.

Notes

Do not start before #3240 has run for a week. Cheapest route: read the metrics once, change the constants, and re-run the comparison of #3239 on 10 cases.

Related: #3223, #3239, #3240.

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

Proposed design

Problem statement

The caps of the stage planner were set by guess: 200 tool calls, 250 requests, 8,000 characters and 240 lines for each tool answer, 40 commits for git_log, 40 files for repo_map, 180 characters for each map line, and 16,000 characters for read_spec. The project cannot tell which cap cuts a useful answer. #3240 records the size of an answer after the cut, so it cannot tell a cut answer from a short one. This item adds the missing cut signal, so that a later item can set each cap from one week of data. The tuning of the caps waits on that data and on the baseline eval, so it moves to a new issue.

Acceptance criteria

Requirement: Cut flag in the tool answer

A stage planner tool that cuts its answer at a cap SHALL mark the answer with the name of that cap in its metadata, and SHALL mark no answer that a cap did not cut.

Scenario: Cut answer carries the cap name

  • WHEN the test calls a stage tool whose output is longer than CONST_ROADMAP_REFINE_TOOL_MAX_LINES lines or CONST_ROADMAP_REFINE_TOOL_MAX_CHARS characters, and calls the same tool with a short output
  • THEN the long answer holds the name of the cap in its metadata and the short answer holds none

Requirement: Commit and file caps flag a cut

The tools git_log and repo_map SHALL flag a cut when the history or the directory holds more entries than CONST_ROADMAP_STAGE_LOG_MAX_COUNT or CONST_ROADMAP_STAGE_MAP_MAX_FILES, and SHALL flag none when the entries fit.

Scenario: More commits than the cap

  • WHEN the test runs git_log on a history with one more commit than the cap, and on a history with fewer commits
  • THEN the first answer holds the flag of the commit cap and the second holds none

Requirement: Trace record keeps the cut

The record of a tool call in the run trace SHALL hold the cap that cut its answer, or no cap when none cut it.

Scenario: Trace absorbs a cut answer

  • WHEN the test absorbs messages that hold one cut tool answer and one whole tool answer
  • THEN the first call record names the cap and the second call record names none

Requirement: Cut counter

The end of a run SHALL add 1 to the counter devops_cli_roadmap_tool_cuts_total for each cut answer, with the labels tool, row, toolset and cap, and SHALL add nothing for an answer that no cap cut.

Scenario: One cut answer adds one count

  • WHEN the test calls end_run with a trace that holds one cut call and one whole call
  • THEN the counter receives one data point of value 1 with the labels of the cut call, and none for the whole call

Requirement: Counter documented

The cut counter SHALL be declared as an instrument and listed in docs/TELEMETRY.md with its labels and the meaning of a cut.

Scenario: Documentation matches the instrument

  • WHEN the documentation check compares the declared instruments with docs/TELEMETRY.md
  • THEN the check passes and the page lists devops_cli_roadmap_tool_cuts_total

Existing Tool Considered

No open, maintained tool covers the need. The alternatives check of 2026-11-05 found none. Langfuse records traces, token use and cost, but it does not attribute a cut to one cap constant of this repository. pydantic-ai-harness ToolOutputLimits limits tool output at run time for another framework and does not measure this repository's CONST_ROADMAP_STAGE_* caps. This item builds a small cut counter on the existing OpenTelemetry instruments: a metadata flag, one field of ToolCallRecord, one counter and tests. The cost is one implement run, about one working day. The later tuning item adds one week of waiting for data.

Key questions

  • Does feat(telemetry): count tool calls of the stage planner by tool and outcome #3240 already record whether a cap cut an answer?: No. end_run sends the outcome and the answer size after the cut. ToolCallRecord holds the outcome and the character count only. The cut() helper drops lines or characters and sets no flag. So a cut answer looks like a short answer in the data. [sources: src/devops_cli/roadmap/tool_metrics.py, src/devops_cli/roadmap/agent_run.py, src/devops_cli/roadmap/stage/stage_tools.py, docs/TELEMETRY.md]
  • How does a tool report that a cap cut its answer?: The tool sets a cut entry with the cap name in the mapping metadata of its ToolReturn. _outcome_of already reads mapping metadata, so the change adds one key and one field in ToolCallRecord. end_run then emits the new counter. For git_log the tool requests one more commit than the cap, as repo_map already does for files. (best practice) [sources: src/devops_cli/roadmap/agent_run.py, src/devops_cli/roadmap/stage/stage_tools.py, src/devops_cli/roadmap/tool_metrics.py]
    • Chosen: Mapping metadata key cut plus one field in ToolCallRecord. The metadata path exists and needs the smallest change. The counter uses the same labels as the other tool metrics.
    • Rejected: Infer the cut from an answer size close to the cap. A short answer near the cap looks like a cut one, and a cut by lines cannot be seen from characters.
    • Rejected: Add a marker text in the answer for the model to read. It changes what the model reads, so it changes the plan runs that the data must describe.
  • Should the change set a token window or an output-token cap?: No. The stage spec says a plan run sets no count of output tokens and the context window ends the tools. CONST_ROADMAP_STAGE_MAX_OUTPUT_TOKENS is in the REMOVED list of the limit-class test and must not return. (best practice) [sources: openspec/specs/roadmap-stage/spec.md, tests/roadmap/test_roadmap_limit_classes.py, docs/roadmap/stage.md]
    • Chosen: No token cap. The spec says the context window ends the tools, and the removed constant must not return.
    • Rejected: Add a new output-token cap. The limit-class test refuses the removed constant and the spec sets no output count.
  • Does the change wait for the baseline eval?: The cut counter is measurement only and changes no cap, so it does not wait. The change of cap values waits for the baseline, because docs/ROADMAP_WORKFLOW.md parks each cost change, including a lower cap, until the baseline passes. The tuning moves to a deferred issue. (best practice) [sources: docs/ROADMAP_WORKFLOW.md]
    • Chosen: Build the counter now and defer the tuning. The counter changes no cap and gives the data that the tuning needs.
    • Rejected: Do all of the work in this item. The tuning needs one week of data and the baseline, so the item could not finish.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/feature
    scope/roadmap
    status/new
    value/medium
    effort/low
    on Nov 2, 2026
  2. devops-cli-service commented on Nov 2, 2026

    @devops-cli-service
    Contributor

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

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P3-Low. The task depends on #3240 running for a full week and is an incremental quality improvement, not a blocker.
    • Value: Medium. Properly tuned caps reduce wasted tokens and prevent cut answers that degrade plan quality.
    • Effort: Low. The notes state the route is to read metrics once, change constants, and re-run a 10-case comparison.
    • Related: perf(roadmap): raise the soft caps and request timeouts of the jobs #3206, which asks for a different change. Both work on the same stage-planner constants in config/constants.py, but #3206 raised them in one step while the candidate tunes them from a week of telemetry data.
  3. added
    priority/p3-low
    on Nov 2, 2026
  4. devops-cli-service commented on Nov 3, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 7df9244 while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.

  5. devops-cli-service commented on Nov 5, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Tool: none found

    Lacks:

    • No searched tool measures, per tool, the share of this project's stage-planner answers that a cap cut and whether the plan cited the cut part; the week of plan-run data must come from the project's own telemetry (feat(telemetry): count tool calls of the stage planner by tool and outcome #3240).
    • LLM observability platforms such as Langfuse record traces, token usage and cost, but they do not attribute truncation to a specific cap constant or decide the cap value.
    • pydantic-ai-harness ToolOutputLimits sets per-tool truncation bands and spill/summarize actions at runtime for pydantic-ai agents; it is a different framework's output-limiting layer, not a way to measure and set this repository's CONST_ROADMAP_STAGE_* caps.
    • No tool edits the constants with a docstring stating the measured value, ISO 8601 date, cut share and evidence, or keeps them in line with the soft-cap class guard test; that work is internal to the repository.

    Searches run:

    • library to tune LLM agent tool output truncation limits from telemetry data
    • open source tool measures truncated tool responses agent token waste analytics

    Sources:

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

  6. changed the title [-]feat(roadmap): tune the tool call limits and answer caps of the stage planner from run data[/-] [+]feat(roadmap): Tune stage planner caps from run data[/+] on Nov 6, 2026
  7. dan-petty commented on Nov 6, 2026

    @dan-petty
    OwnerAuthor

    The job shortened the title of this item. The summary had 76 characters, and the limit is 60. The type and the scope stay.

    • Before: feat(roadmap): tune the tool call limits and answer caps of the stage planner from run data
    • After: feat(roadmap): Tune stage planner caps from run data
    • Source of the summary: the background model
  8. dan-petty commented on Nov 7, 2026

    @dan-petty
    OwnerAuthor

    Answer from project standards: a question for the owner. This item records the wish to remove time and token limits where possible. A separate proposal adds two bounds for the model steps of the stage, refine and alternatives rows:

    1. A total token cap for one model step, as new settings roadmap.<row>.step_token_budget (the name that roadmap.implement.step_token_budget uses), passed to pydantic-ai UsageLimits(total_tokens_limit=...).
    2. A wait limit for the model slot, service.model_call_wait_seconds, passed to Semaphore.acquire(timeout=...).

    Evidence: one stage plan used 1,494,303 input tokens in 23 requests (#3880). The wait for the model slot has no timeout today (model_call_slot, ai/client/network.py), so one slow row can hold the lane. A row deadline is not possible (the runner is called inline), so the proposal has none. The full text is in the comment on #3066.

    The proposal conflicts with the wish of this item and with the park of docs/ROADMAP_WORKFLOW.md (each cost cap waits for the baseline of #3566). It is not filed. Please answer: should these two bounds exist before the baseline passes, or not at all? If the answer is no, nothing is built.

  9. devops-cli-service commented on Nov 9, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 681529b until a person answers the questions below. Reply in a comment or edit the body, and the next refine round looks at the item again.

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

    @devops-cli-service
    Contributor

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

    Moved to new items: #4218.

  12. added a commit that references this issue on Nov 14, 2026
  13. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 14, 2026
  14. removed
    status/in-review
    on Nov 14, 2026
  15. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor
  16. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-14 15:02 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/lowpriority/p3-lowscope/roadmaptype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions