Skip to content

fix(roadmap): a return request leaves room for the planner tools #3529

Closed
1 of 1 issue completed
Closed

Description

@dan-petty

Problem

The return request of the stage job adds a full earlier proposal (previous) and the problem text to the first request. PR #3523 (issue #3477) measures and bounds only the first plan request. No test measures the return request. It may pass the limit at which the run offers no tool, and then the retry run makes no tool call.

Expected

An offline measure of the return request, as the refine measure test does. If the request passes the limit, bound the earlier proposal in the request.

Source

Review finding of PR #3523, outside the acceptance criteria of #3477.

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

Proposed design

Problem statement

The stage job's return request adds the full earlier plan as previous and the problem text to the first request, both for a reply that a gate refuses and for a review repair. PR #3523 (#3477) measured and bounded only the first plan request, and no test measures the return request, so a return request can pass the limit at which the run offers no tool and the planner then makes no tool call. The fix measures the return request offline and bounds previous when the request passes the limit, keeping the problem text and the planner tools.

Acceptance criteria

Requirement: The repair return request is measured against the tool-removal limit

A test SHALL build the repair return request of the stage job at a window of 65536 tokens, count its tokens as the run hook counts them, print the count with the limit of 49152 tokens, and assert that the request stays under the limit.

Scenario: A return request with the full earlier plan

  • WHEN the stage test builds the return request of a refused reply whose previous is the full earlier plan
  • THEN the test prints the count and the limit, and the request that the planner receives counts under 49152 tokens

Requirement: The earlier plan is bounded only when the return request passes the limit

The stage job MUST bound previous in the repair return request when the full request passes the limit at which the run offers no tool, and MUST keep the full previous when it does not.

Scenario: The full previous passes the limit

  • WHEN the full earlier plan makes the repair return request pass the tool-removal limit
  • THEN the request carries a bounded previous and its measured size stays under the limit

Requirement: The problem and the tools are kept

The repair return request SHALL keep the problem text and the full planner toolset after it bounds previous.

Scenario: A bounded return request

  • WHEN the stage job bounds previous to fit the tool-removal limit
  • THEN the request still contains problem and the planner offers every tool

Requirement: Both return paths are measured and bounded

The measure and the bound SHALL cover the gate return of a refused reply and the review repair request, which both add previous and problem.

Scenario: A gate return and a review repair

  • WHEN the test builds the return request of a refused reply and the return request of a review repair
  • THEN both measured requests stay under the tool-removal limit after the bound

Requirement: The first plan request is unchanged

The change MUST NOT alter the size or the bound of the first plan request.

Scenario: The first plan request regression

  • WHEN the test suite builds the first plan request after the change
  • THEN the first plan request keeps its existing size and bound

Existing Tool Considered

tiktoken, through devops_cli.ai.context_budget.count_tokens, and pydantic-ai's PrepareTools hook are open, maintained and already dependencies: they count the tokens exactly and enforce the tool-removal limit. They lack a measure of this project's return request against that limit and a bound on the previous field inside the one request; pydantic-ai's ProcessHistory trims message history, not a JSON field of one request. The change adds no library: it reuses count_tokens, ModelMessagesTypeAdapter and truncate_to_token_limit and adds a measure test and a bound. Build cost is about 6,000 tokens and about 4 hours; keep and fix cost is about 2,000 tokens for each later change.

Key questions

  • What does the return request add to the first request?: It adds the full earlier plan as previous and the problem text as problem. The gate return (_Refused.returned) and the review repair (_repaired) both build it that way. [sources: src/devops_cli/roadmap/stage/stage.py:1085, src/devops_cli/roadmap/stage/stage.py:1691, tests/roadmap/stage/test_roadmap_stage_request.py:229, tests/roadmap/stage/test_roadmap_stage_repair_return.py:124]
  • What does the existing offline measure of the first plan request do?: tests/roadmap/stage/test_roadmap_stage_window.py counts the first request with ModelMessagesTypeAdapter.dump_json and count_tokens, and asserts that it is at most the window less a quarter for the reply and less CONST_ROADMAP_STAGE_TOOL_RESERVE_TOKENS. The refine measure at tests/roadmap/refine/test_roadmap_refine_investigation.py:306 prints the count and the limit and asserts that a large item stays under the limit. [sources: tests/roadmap/stage/test_roadmap_stage_window.py:111, tests/roadmap/stage/test_roadmap_stage_window.py:137, tests/roadmap/refine/test_roadmap_refine_investigation.py:306]
  • What is the limit at which the run offers no tool?: tool_stop(window) returns window - window // CONST_ROADMAP_INVESTIGATION_REPLY_WINDOW_SHARE, and the share is 4, so the project's measure at a window of 65,536 tokens has a limit of 49,152 tokens. The example ConfigMap sets the live analysis and stage window to 256,000 tokens, so the bound must follow the run's window rather than a fixed 49,152. [sources: src/devops_cli/roadmap/refine/refine_investigation.py:380, src/devops_cli/config/constants.py:3354, docs/CLUSTER.md:51]
  • Which open, maintained tool or library covers the need?: None covers it fully. tiktoken, through count_tokens, gives the exact token count, and pydantic-ai's ModelMessagesTypeAdapter gives the message JSON, but neither measures this project's return request against the tool-removal limit nor bounds previous; pydantic-ai's ProcessHistory trims message history, not a JSON field of one request (fetched 2026-11-13). The change reuses the existing helpers and adds a measure test and a bound. (best practice) [sources: src/devops_cli/ai/context_budget.py:90, tests/roadmap/stage/test_roadmap_stage_window.py:111, https://pydantic.dev/docs/ai/capabilities/process-history]
    • Chosen: tiktoken through count_tokens. It is open, maintained and already a dependency, and it gives the exact count that the measure and the bound need. It lacks the request shape, the tool-removal limit and the bound on previous, so the project adds those.
    • Rejected: pydantic-ai ProcessHistory. It trims the message history before each request, not the previous field inside this one request, and it gives no offline measure of the return request.
    • Rejected: A project-owned tokenizer. tiktoken already counts the tokens offline and the project already uses it; a second tokenizer adds cost and can disagree with the first.
  • How should the stage job bound the earlier proposal in the return request?: Measure the return request as the hook counts it with tool_stop(window), and bound previous only when that count passes the limit: compute the room that the limit leaves below the request without previous, and cut the text fields of previous with truncate_to_token_limit, keeping its keys, paths and summary, the problem text and the tools. Reuse count_tokens and truncate_to_token_limit; add no fixed cap that ignores the window. (best practice) [sources: src/devops_cli/ai/context_budget.py:128, src/devops_cli/roadmap/stage/stage.py:1085, src/devops_cli/roadmap/stage/stage.py:1691, openspec/specs/roadmap-stage/run-limits/spec.md:88, tests/roadmap/stage/test_roadmap_stage_window.py:137]
    • Chosen: Bound previous only when the measured request passes the limit. It follows the issue's condition, keeps the full earlier plan when it fits, and reuses the project's recorded rule that a request is measured against the tool-removal limit (run-limits spec).
    • Rejected: Always cap previous at a fixed token budget. It cuts the earlier plan even when the request fits, and it changes every repair rather than only the over-limit one.
    • Rejected: Drop previous when the request passes the limit. The planner needs the earlier plan to revise it (docs/roadmap/stage.md:90).
    • Rejected: Keep the full previous. The request stays over the limit and the run then offers no tool, so the planner cannot repair the plan.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Sub-issues

Sub-issues

1 of 1 Issues completed
Loading 1 sub-issues

Activity

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

    @dan-petty
    OwnerAuthor

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

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: scope/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P2-Medium. The return path may exceed the tool limit, but it is a secondary path and the failure is not yet confirmed in the wild.
    • Value: Medium. Prevents a silent failure where the return run makes no tool call, but the path is less frequently hit than the first plan.
    • Effort: Medium. Requires a measure test and a bound on the previous proposal, following the same pattern already built for the first request.
    • Related: fix(roadmap): a plan request leaves room for the planner tools #3477, which asks for a different change. Both bound the stage job request size against the tool-removal limit, but the candidate covers the return request and #3477 covers the first plan request.
  3. added
    priority/p2-medium
    on Nov 4, 2026
  4. devops-cli-service commented on Nov 5, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at be8d18a 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.

    • The proposal has no problem statement, no acceptance criterion with its requirement, scenario, WHEN and THEN, or no answer to the existing-tool question. State the problem, the requirements with their scenarios, and the open tool that covers the need or the cost of building it.
  5. devops-cli-service commented on Nov 7, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: Every search call failed on a connection timeout, so no external candidate could be found; the only fact I could read, tiktoken, merely counts tokens for a known encoding and neither measures this project's return request against the limit at which the run offers no tool nor bounds the earlier proposal in that request. The need is an offline measure test in the project's own suite plus a bound on previous, which follows the pattern already built for the first plan request in #3477, so no open tool or library covers it.

    Tool: none found

    Lacks:

    • An offline measure of the return request's size against the limit at which the run offers no tool
    • A bound on the earlier proposal (previous) carried in the return request
    • A test that fails when the return request passes that limit, mirroring the refine measure test
    • Knowledge of this project's stage-job request shape and tool-removal limit

    Tools considered:

    Searches run:

    • pydantic-ai trim message history token limit before request, results: 0
    • library to measure LLM prompt token count and bound context offline test, results: 0
    • pydantic-ai history processor token limit, results: 0
    • tiktoken count tokens, results: 0
    • tiktoken, results: 0
    • LLM prompt token measurement python library, results: 0
    • pydantic-ai message history trimming, results: 0
    • python prompt token budget library, results: 0
    • prompt trimming library, results: 0
    • tiktoken token counting, results: 0

    Sources:

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

  6. added
    status/ready
    and removed
    status/new
    on Nov 13, 2026
  7. devops-cli-service commented on Nov 13, 2026

    @devops-cli-service
    Contributor

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

  8. added
    owner/service
    and removed
    owner/service
    on Nov 14, 2026
  9. 12 remaining items

  10. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    Stopped at scoped checks.

    Failure class: ci_infra.
    Action taken: none.
    Action left: retry: run the item again.

    Step Status Attempts Tokens in/out Last failing command
    group 1 done 1 16407385/42959 pytest on base: tests/roadmap/stage/test_roadmap_stage_window.py
    group 2 done 1 6999135/21547 pytest on base: tests/roadmap/stage/test_roadmap_stage_window.py
    scoped checks stopped 1 0/0 -

    Reason:

    SecurityError: Prohibited dangerous environment variable override: 'PYTEST_ADDOPTS'
    

    Last message of the agent (a claim that no check verified): none.

    The item is Blocked, and the job will not run it. Fix the cause. Then comment implement: retry. The Service clears the stop on its own when a new runner image rolls out, but only if a retry can fix the class of the stop and the limits of roadmap.implement.digest_clears_per_class and roadmap.implement.digest_clears_per_item allow it.

    The job kept the commits that passed on the branch fix/3529-a-return-request-leaves-room-for on origin. The last is 513973014113606120588f041429d8662e6cd391. The pull request stays a draft. The next run continues from it, runs no group that is ticked, and runs the scoped checks again.

  11. added
    status/blocked
    and removed
    status/in-progress
    on Nov 15, 2026
  12. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    The runner Job devops-cli-implement-devops-cli-3529-b5cceb ended: succeeded.
    Image digest: sha256:98de20a7edd09701e7b226a1931ada4763199253d241daf1151b0fe6b79f2dc5

    The last lines of its log:

    Tool call: run_command, started: uv run devops ci test tests/roadmap/stage/test_roadmap_stage_window.py
    Tool call: run_command, program uv, ok.
    Tool call: run_command, started: uv run devops ci test tests/roadmap/stage/test_roadmap_stage_repair_return.py
    Tool call: run_command, program uv, ok.
    Tool call: run_command, started: uv run ruff check src/devops_cli/roadmap/stage/stage.py tests/roadmap/stage/test_roadmap_stage_window.py
    Tool call: run_command, program uv, ok.
    Tool call: edit_file, ok.
    Tool call: run_command, started: uv run ruff check src/devops_cli/roadmap/stage/stage.py tests/roadmap/stage/test_roadmap_stage_window.py
    Tool call: run_command, program uv, ok.
    Tool call: run_command, started: uv run mypy --strict src/devops_cli/roadmap/stage/stage.py
    Tool call: run_command, program uv, ok.
    Tool call: run_command, started: git status --short
    Tool call: run_command, program git, ok.
    Tool call: run_command, started: other
    Tool call: run_command, program other:1af3defd8640, refused.
    Tool call: run_command, started: ls -la .data/agent/scratch
    Tool call: run_command, program ls, ok.
    Tool call: run_command, started: git clean -fx .data/agent/scratch/probe.py
    Tool call: run_command, program git, ok.
    Tool call: read_file, ok.
    Tool call: edit_file, ok.
    Tool call: run_command, started: grep -rln verifier= tests/roadmap/stage | head ...
    Tool call: run_command, program grep, ok.
    Tool call: run_command, started: uv run devops ci test tests/roadmap/stage/test_roadmap_stage_review_rounds.py
    Tool call: run_command, program uv, ok.
    Tool call: run_command, started: uv run devops ci test tests/roadmap/stage/test_roadmap_stage_verification.py
    Tool call: run_command, program uv, ok.
    Tool call: run_command, started: uv run devops openspec check
    Tool call: run_command, program uv, ok.
    Tool call: run_command, started: git diff
    Tool call: run_command, program git, ok.
    Tool call: run_command, started: git status --short
    Tool call: run_command, program git, ok.
    Tool call: run_command, started: git log --oneline -3
    Tool call: run_command, program git, ok.
    Tool call: run_command, started: git show --stat HEAD
    Tool call: run_command, program git, ok.
    Tool call: read_file, ok.
    Failure class ci_infra. Action left: retry.
    ✓ Took 0 item(s) to a ready pull request, stopped 1.
    
  13. removed
    owner/service
    on Nov 15, 2026
  14. added
    status/planned
    and removed
    status/blocked
    on Nov 15, 2026
  15. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    Cleared the stop at scoped checks by the rule digest: the runner image changed since the stop, from sha256:98de20a7edd09701e7b226a1931ada4763199253d241daf1151b0fe6b79f2dc5 to sha256:014636e1131ac1400a333cf938c841f3ffff1b3a7deb8b63b92cb8920cd31745, and the class ci_infra of the stop is one that a new attempt can fix. The item is Planned again, and the Service takes it in the next round. The Service clears at most 1 for each class and 3 for each item by digest. A stop of another class, a new stop on this image, and a stop over a limit wait for a comment implement: retry.

  16. added
    status/in-review
    and removed
    status/planned
    on Nov 16, 2026
  17. removed
    status/in-review
    on Nov 16, 2026
  18. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-16 03: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/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