Repository navigation
Description
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
previousis 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
previousand 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
previousto fit the tool-removal limit - THEN the request still contains
problemand 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
previousand the problem text asproblem. 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.pycounts the first request withModelMessagesTypeAdapter.dump_jsonandcount_tokens, and asserts that it is at most the window less a quarter for the reply and lessCONST_ROADMAP_STAGE_TOOL_RESERVE_TOKENS. The refine measure attests/roadmap/refine/test_roadmap_refine_investigation.py:306prints 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)returnswindow - 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 liveanalysisandstagewindow 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'sModelMessagesTypeAdaptergives the message JSON, but neither measures this project's return request against the tool-removal limit nor boundsprevious; pydantic-ai'sProcessHistorytrims 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
previousfield 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 boundpreviousonly when that count passes the limit: compute the room that the limit leaves below the request withoutprevious, and cut the text fields ofpreviouswithtruncate_to_token_limit, keeping its keys, paths and summary, the problem text and the tools. Reusecount_tokensandtruncate_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.
Activity
dan-petty commentedon Nov 4, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
fixprefix of the title gives the type.(roadmap)scope of the title gives the scope.The return path may exceed the tool limit, but it is a secondary path and the failure is not yet confirmed in the wild.Prevents a silent failure where the return run makes no tool call, but the path is less frequently hit than the first plan.Requires a measure test and a bound on the previous proposal, following the same pattern already built for the first request.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.devops-cli-service commentedon Nov 5, 2026
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.
devops-cli-service commentedon Nov 7, 2026
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:
previous) carried in the return requestTools considered:
Searches run:
Sources:
Checked on 2026-11-07. A person decides what this means for the item. The check changes no label and closes no issue.
devops-cli-service commentedon Nov 13, 2026
Status set to Ready at 4ef7c6f (see proposed design in issue body).
12 remaining items
devops-cli-service commentedon Nov 15, 2026
Stopped at scoped checks.
Failure class:
ci_infra.Action taken: none.
Action left:
retry: run the item again.pytest on base: tests/roadmap/stage/test_roadmap_stage_window.pypytest on base: tests/roadmap/stage/test_roadmap_stage_window.pyReason:
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 ofroadmap.implement.digest_clears_per_classandroadmap.implement.digest_clears_per_itemallow it.The job kept the commits that passed on the branch
fix/3529-a-return-request-leaves-room-foron origin. The last is513973014113606120588f041429d8662e6cd391. The pull request stays a draft. The next run continues from it, runs no group that is ticked, and runs the scoped checks again.devops-cli-service commentedon Nov 15, 2026
The runner Job devops-cli-implement-devops-cli-3529-b5cceb ended: succeeded.
Image digest: sha256:98de20a7edd09701e7b226a1931ada4763199253d241daf1151b0fe6b79f2dc5
The last lines of its log:
devops-cli-service commentedon Nov 15, 2026
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 classci_infraof 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 commentimplement: retry.devops-cli-service commentedon Nov 16, 2026
Released in v0.160.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.160.0
devops-cli-service commentedon Nov 16, 2026
Live since 2026-11-16 03:02 UTC