Skip to content

fix(roadmap): Keep the first stage request under the window limit #6101

Closed as duplicate

Description

@dan-petty

Problem

tests/roadmap/stage/test_roadmap_stage_window.py::test_a_first_request_of_code_with_the_context_and_the_body_at_their_caps_offers_the_tools fails on main since 2b4ae1f (#6091): assert (True, False) == (True, True) at line 223. With the context and the body of code at their caps, the first request of the stage job is no longer under the limit of the window.

#6091 made the task prompt src/devops_cli/ai/tasks/roadmap_stage_change.md longer, and the reserve of the stage window does not cover the added text. Shard 2 of Tests & Coverage fails on 2b4ae1f and on each pull request that holds it, for example #6099. Shard 2 passed on f592ce7, the commit before it. The test fails the same way in a local run.

Expected behavior

The first request of a stage plan with code at the caps stays under the limit of the window, and the test passes on main.

Proposed design

Problem statement

The stage job caps its context and its body by token counts of plain text, but sends the first request as JSON, where code grows. Since #6091 the encoded first request of a plan with code at the caps no longer stays under the limit of the window. The test test_a_first_request_of_code_with_the_context_and_the_body_at_their_caps_offers_the_tools fails on main, and shard 2 of Tests & Coverage fails on each pull request that holds the commit. The fix restores the headroom that the longer task prompt took.

Acceptance criteria

Requirement: Code at the caps stays under the limit

The stage job SHALL keep the encoded first request of a plan under the limit at which the run hook offers no tool, when the context and the body hold code at their caps.

Scenario: Code at the caps

  • WHEN The context and the body hold code at their caps and the window holds 65536 tokens.
  • THEN The run offers read_spec and the encoded first request holds fewer tokens than the limit.

Requirement: Plain text keeps the full caps

The stage job SHALL keep the context and the body at their caps when plain text at the caps fits the limit.

Scenario: Plain text at the caps

  • WHEN The context and the body hold plain text at their caps and the window holds 65536 tokens.
  • THEN The request holds CONST_ROADMAP_STAGE_CONTEXT_MAX_TOKENS and CONST_ROADMAP_STAGE_BODY_MAX_TOKENS tokens.

Requirement: Plain text keeps the tool reserve

The stage job SHALL keep the encoded first request of plain text at the caps under the limit of the window minus the tool reserve.

Scenario: Reserve of plain text

  • WHEN The context and the body hold plain text at their caps and the window holds 65536 tokens.
  • THEN The encoded first request holds at most the limit minus CONST_ROADMAP_STAGE_TOOL_RESERVE_TOKENS tokens.

Requirement: A small window keeps its share

The stage job SHALL cap the context at half of the window and the body at a quarter of it when the window is smaller than the caps.

Scenario: Small window

  • WHEN The window holds 8192 tokens and the context and the body exceed their caps.
  • THEN The request holds 4096 tokens of context and 2048 tokens of body.

Existing Tool Considered

No alternatives check has run. No open, maintained tool or library covers the token budget of this stage job: the budget follows the task prompt and the caps of this repository. The change edits src/devops_cli/config/constants.py and checks src/devops_cli/roadmap/stage/stage.py, about 10 lines. It costs about 15,000 tokens to build, about 1,000 tokens a month to keep and fix, and about half a day.

Key questions

  • Why does the code case fail while the plain-text case passes?: The job counts the caps of the context and the body on plain text. It encodes the first request as JSON, where quotes, backslashes and newlines in code grow. The text that fix(roadmap): Stop plan rules that ask for config value tests #6091 added to the prompt used the headroom between the caps and the limit, so the encoded code request now reaches the limit. [sources: tests/roadmap/stage/test_roadmap_stage_window.py, src/devops_cli/ai/tasks/roadmap_stage_change.md, src/devops_cli/roadmap/stage/stage.py, src/devops_cli/config/constants.py]
  • How does the job restore the headroom that the longer task prompt took?: Shrink CONST_ROADMAP_STAGE_CONTEXT_MAX_TOKENS until the failing test passes and the plain-text test keeps the tool reserve. Keep the constant at or above 4096 tokens, the share of a window of 8192 tokens. Leave CONST_ROADMAP_STAGE_BODY_MAX_TOKENS at its value. (best practice) [sources: tests/roadmap/stage/test_roadmap_stage_window.py, src/devops_cli/config/constants.py, src/devops_cli/ai/tasks/roadmap_stage_change.md]
    • Chosen: Shrink the context cap. One constant changes, every existing test keeps its meaning, and plain text keeps the body at its cap.
    • Rejected: Trim the encoded request in the job. A new loop must not cut the share caps that the small-window test asserts.
    • Rejected: Increase the tool reserve. The test subtracts the reserve from the limit, so a larger reserve tightens the assertion and does not shrink the request.
    • Rejected: Raise the reply share. CONST_ROADMAP_INVESTIGATION_REPLY_WINDOW_SHARE also serves the investigation job, and the reply needs its room.
    • Rejected: Trim the task prompt. fix(roadmap): Stop plan rules that ask for config value tests #6091 added rules that the plan needs, and the prompt grows again.
  • Does the change add a test that ties the task prompt to the caps?: No. The failing test runs the real prompt through plan_stage, so it fails again when the prompt grows past the headroom. (best practice) [sources: tests/roadmap/stage/test_roadmap_stage_window.py]
    • Chosen: Keep the existing test. The test builds the request from the real prompt and asserts the limit, so it is the guard.
    • Rejected: Add a token-count test of the prompt. It repeats what the failing test already measures.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

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

    @dan-petty
    OwnerAuthor
    • Priority: P1-High. The test fails on main and on every pull request that holds the commit, causing CI to fail. The regression commit 2b4ae1f does not set P0: the author has no write access, and no caller attached it as evidence. A person can set P0 with the label priority/p0-critical.
    • Related: fix(roadmap): a plan request leaves room for the planner tools #3477, which asks for a different change. Both address the first stage request exceeding the window limit, but #3477 was the original fix and the candidate repairs a regression of that fix caused by a longer prompt.
  3. added
    priority/p1-high
    on Nov 17, 2026
  4. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Waiting for the alternatives check to run. The next refine round looks at the item again after the check records a verdict.

  5. dan-petty commented on Nov 17, 2026

    @dan-petty
    OwnerAuthor

    Duplicate of #6103, which #6104 fixed on main: the stage-window test passes again.

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