Repository navigation
Description
Problem or Motivation
The stage planner explores the repository with read tools before it writes a plan. About 7,000 search_code calls a week come from it, and the runs take 40 to 113 calls. A run of 113 calls filled the 256,000-token window (2026-11-10). The merged call budget (#4346) says the planner needs about 30 calls and shows a notice from call 40. That is a fixed rule on the call count. It does not look at what the run has found. The question "continue to explore, or write the plan now" is a closed question, and tools can extract the evidence for it: the criteria covered by the files read, the paths that the plan names and that exist, repeated reads, the share of tokens, the window that remains.
Proposed Solution & Architectural Design
Add the decision point stage.explore_stop in shadow mode only (ADR 0020).
- At fixed call-count checkpoints, a tool-made digest (counts only) is built and the decision model answers a Choice question:
exploreorwrite. - The planner does not change. The answer and the digest are recorded beside what the run did next: the extra calls, the plan, the gate that refused or passed it, and the total calls and tokens.
- The registry refuses the mode
onfor this point until a fitted cut exists. - An offline replay builds the digest and the label ("would a further call have changed the plan outcome") from the stored traces, only where the data allows it. The record states what the shadow log collects and how many runs the fit needs.
- The bar to turn the point on is set before the data: no more gate refusals than today, for fewer tool calls.
Target Subsystem
Stage planner (src/devops_cli/roadmap/stage/stage.py, stage_toolbox.py), decision points.
Existing Tool Considered
TypeSafe Jev through pydantic_ai DecisionModel, on the registry of the item before this one. The call budget of #4346 is the baseline rule.
Related: #4346, #4347, the design record item (ADR 0020), the registry item.
Standards Compliance
- I confirm this proposal aligns with AGENTS.md engineering principles (cyclomatic complexity <= 10, nesting <= 5, zero bare exceptions, tests that cover the changed lines).
- I am willing to submit a pull request implementing this feature with accompanying tests.
Dependencies
- chore(roadmap): hold incremental stage and implement work #6521 (hold: incremental work on the stage, implement and fix-checks jobs waits for the re-architecture)
Alternatives check of 2026-11-25: in-use.
The repository already uses this tool.
Tool: pydantic/pydantic-ai (https://github.com/pydantic/pydantic-ai), MIT, last activity 2026-11-25, maintained.
Reason: Searches found no library that builds the call-and-window digest, the shadow log, the offline replay or a fitted stop cut; the project's pydantic-ai DecisionModel already answers the typed explore-or-write Choice question, so it covers only that part.
Covers:
- Typed Choice answer of
exploreorwrite - One model request for each digest at a checkpoint
- Model and prompt chosen from the existing decision registry
Lacks:
- No digest of calls, repeated reads or remaining window
- No shadow log of plan, gate result and totals
- No fitted cut, and no replay that labels checkpoints
Proposed design
Problem statement
The stage planner makes 40 to 113 read tool calls before it writes a plan, and one run filled the 256,000-token window on 2026-11-10. The call budget of #4346 counts the calls only and does not look at what a run has found. This item adds the decision point stage.explore_stop in the mode shadow. At 40 tool calls and at each 20 calls after, the point builds a counts-only digest, asks the decision model explore or write, and writes one record with what the run did next. An offline replay labels each checkpoint. The planner does not change.
Acceptance criteria
Requirement: Digest at the checkpoints
The explore-stop point SHALL build one digest when a plan run reaches 40 tool calls and at each 20 calls after.
Scenario: The run reaches the first checkpoint
- WHEN A test gives the point a trace of 40 tool calls of a plan run in the mode
shadow. - THEN The point returns one digest, and the digest holds the call count 40.
Requirement: Counts in the digest
The digest SHALL hold the call count, the count of each tool, the count of distinct paths read, the count of repeated reads and the count of criteria that name a read path.
Scenario: A path is read twice
- WHEN A trace holds 40 calls, reads the path
src/app.pyat calls 1 and 2, and reads 38 other paths once. - THEN The digest holds 40 calls, 39 distinct paths and one repeated read.
Requirement: Tokens of the window
The digest SHALL hold the input tokens used and the tokens that remain in the context window of the run.
Scenario: The run has used most of the window
- WHEN A test gives the point a run with a context budget of 256,000 tokens and a trace of 200,000 input tokens.
- THEN The digest holds 200,000 tokens used and 56,000 tokens that remain.
Requirement: Answer of the decision model
The point SHALL ask the decision model the Choice question explore or write for each digest and SHALL record the answer with the digest.
Scenario: The model answers write
- WHEN The decision model returns
writefor the digest of a checkpoint. - THEN The shadow record of that checkpoint holds the answer
writeand the digest that the point sent.
Requirement: Shadow mode changes nothing
The point MUST make no change to the tool calls or to the plan text in the mode shadow.
Scenario: The same item runs in both modes
- WHEN A test plans the same item with the mode
offand with the modeshadow, on the same recorded model answers. - THEN Both runs make the same tool calls and write the same plan text.
Requirement: One record for each checkpoint
The shadow log SHALL hold one record for each checkpoint with the digest, the answer, the calls after the checkpoint, the plan, the gate result and the totals of the run.
Scenario: A run reaches two checkpoints
- WHEN A plan run reaches two checkpoints and then ends.
- THEN The shadow log holds two records, and each record holds the digest, the answer, the calls after its checkpoint, the plan, the gate result and the totals of the run.
Requirement: File of the item and append
The shadow log MUST be one JSON file for each repository and item, keyed with the plan key, and a rerun MUST append to it.
Scenario: The item runs a second time
- WHEN A plan run of an item ends and the same item runs again.
- THEN The shadow log file holds the records of both runs, and the key of each record is the
plan_keyof its run.
Requirement: Label of a checkpoint
The replay SHALL give one digest and one label for each checkpoint of a stored record that holds the calls and the plan.
Scenario: A later call reads a path that the plan names
- WHEN The replay reads a record whose plan passed the gates and whose call after a checkpoint first reads a path that the plan names.
- THEN The replay gives the digest of the calls before the checkpoint and the label
positivefor that checkpoint.
Requirement: No label without the data
The replay MUST give no label for a record that lacks the plan or the calls after the checkpoint, and MUST count it as one record that the data does not allow.
Scenario: The record lacks the plan
- WHEN The replay reads a record with no plan.
- THEN The replay gives no label for that record and counts one record that the data does not allow.
Requirement: Module states the fields and the fit count
The explore-stop module SHALL state each field of the shadow record and the count of runs that the fit needs.
Scenario: The module docstring is read
- WHEN A test imports
src/devops_cli/roadmap/stage/stage_explore_stop.pyand reads its docstring. - THEN The docstring names the digest, the answer, the later calls, the plan, the gate result and the totals, and states 200 runs with 50 for each answer.
Requirement: Bar stated before the data
The explore-stop module MUST state the bar to turn the point on before any shadow record exists.
Scenario: The module docstring states the bar
- WHEN A test imports
src/devops_cli/roadmap/stage/stage_explore_stop.pyand reads its docstring. - THEN The docstring states that the point turns on only with no more gate refusals than the baseline, for fewer tool calls.
Requirement: Default mode of the point
The mode of stage.explore_stop in roadmap.decisions SHALL be off when the settings set no mode for it.
Scenario: No mode is set
- WHEN A test loads the settings with no value for
roadmap.decisions. - THEN The mode of
stage.explore_stopisoff.
Requirement: Pending a person after the merge
The owner MUST set the mode of stage.explore_stop to shadow in the deployment config after the merge, so that the runs write shadow records.
Scenario: The owner sets the mode
- WHEN The owner sets
roadmap.decisions.stage.explore_stop: shadowin the cluster config and runsuv run devops roadmap stage --item <issue>on one item. - THEN The shadow log file of that item holds one record for each checkpoint of the run.
Existing Tool Considered
pydantic-ai (https://github.com/pydantic/pydantic-ai), MIT, maintained: the alternatives check of 2026-11-25 in the issue body gives the verdict in-use, because the repository already uses the tool. The block of that check holds what the tool covers and lacks. The proposal builds the parts that the block lists as lacking as project code in the new module src/devops_cli/roadmap/stage/stage_explore_stop.py: the call-and-window digest, the shadow log, the offline replay and the label of a checkpoint. The written cost is about 6,000 tokens to build, 1,500 tokens to keep and 500 tokens for each defect, over one day.
Key questions
- At which call counts does the point build a digest?: At 40 tool calls and at each 20 calls after: 40, 60, 80, 100 and 120. The call budget notice starts at 40, and the longest run in the issue makes 113 calls. (best practice) [sources: src/devops_cli/roadmap/stage/stage_toolbox.py, docs/adr/0020-a-decision-point-is-a-unit-of-a-workflow-with-a-resolver-chain-and-a-rule-goes-before-a-decision-model.md]
- Chosen: 40 calls, then each 20. The notice starts at 40 and the longest run makes 113 calls, so five checkpoints cover the range.
- Rejected: 30 calls, then each 20. A digest at 30 asks before the notice and adds a model call to each run.
- Rejected: Each 10 calls. The longest run asks eight times and spends eight model calls.
- What does the digest count?: Counts only: the calls, the calls by tool, the distinct paths read, the repeated reads, the criteria that name a read path, the input tokens and the window that remains. (best practice) [sources: src/devops_cli/roadmap/agent_run.py, src/devops_cli/roadmap/stage/stage.py]
- Chosen: Counts of the trace and the item. The trace holds the calls and the paths, and the item holds the criteria, so a tool computes the digest with no model.
- Rejected: The text of the files read. The digest would carry the window cost that the point is meant to save.
- Rejected: A model summary of the run. A model answer is no count and differs between runs.
- Where does the digest get the size of the window?: From the context budget of the run, so a model with another window gives other tokens that remain. (best practice) [sources: src/devops_cli/ai/context_budget.py, src/devops_cli/roadmap/stage/stage_toolbox.py]
- Chosen: The context budget of the run. Models differ in their window, and the stage job already ends a run that fills the window.
- Rejected: A constant of 256,000. A constant reports a wrong remainder for a model with another window.
- Does the shadow model call at a checkpoint change the budget of the plan run?: No. The point asks the decision model on its own request at the checkpoint and records the tokens of that request in the shadow record. The tool-call budget of the plan run counts the planner calls only. (best practice) [sources: src/devops_cli/roadmap/stage/stage_toolbox.py, src/devops_cli/roadmap/intake/intake_jev_shadow.py, docs/adr/0020-a-decision-point-is-a-unit-of-a-workflow-with-a-resolver-chain-and-a-rule-goes-before-a-decision-model.md]
- Chosen: A request of its own at the checkpoint. The shadow point records its own answer, and the tool-call budget of the planner counts the planner calls.
- Rejected: A call inside the planner budget. The budget would stop a plan because of a shadow request.
- Where does the shadow log live?: In one JSON file for each repository and item, in the directory of the plan record and keyed with
plan_key. A rerun appends to the file, and the replay reads it. (best practice) [sources: src/devops_cli/roadmap/stage/stage_plan_record.py:203, src/devops_cli/roadmap/stage/stage.py]- Chosen: A file of the item, keyed like the plan record. The plan record already keys a run by item, model, toolset and prompt version, and a file survives the run.
- Rejected: The plan record itself. A kept plan skips the run, so the record would hold no shadow data.
- Rejected: A comment on the item. A comment is public, costs a request and holds no machine-readable trace.
- How does the replay label a checkpoint?: The label is positive when a call after the checkpoint first reads a path that the plan names and the plan passed the gates. It is negative when no later call reads such a path. (best practice) [sources: src/devops_cli/roadmap/stage/stage.py, src/devops_cli/roadmap/agent_run.py]
- Chosen: A later first read of a named path, with a passed plan. The trace holds the calls and the plan holds the named paths, so the label needs no model.
- Rejected: The model answer of the checkpoint. The answer is the input of the fit, not its label.
- Rejected: The total calls of the run. A count of calls says nothing about what a further call would find.
- How many shadow records does the fit need?: At least 200 records, with 50 records for each answer, so the fit sees both answers. The module docstring states this count. (best practice) [sources: docs/adr/0020-a-decision-point-is-a-unit-of-a-workflow-with-a-resolver-chain-and-a-rule-goes-before-a-decision-model.md, src/devops_cli/roadmap/stage/stage.py]
- Chosen: 200 records, 50 for each answer. A cut fitted on one answer is no cut, and 200 records is about two weeks of stage runs.
- Rejected: The first 20 records. 20 records rarely hold both answers, and the cut would overfit.
- Rejected: No fixed count. The bar must be set before the data, so the count must be fixed.
- Which modes does
stage.explore_stopaccept in this item?: The point acceptsoffandshadow. The modeonis out of this item, and feat(roadmap): Refuse stage.explore_stop on mode without fitted cut #4410 covers the refusal ofonuntil a fitted cut exists. (best practice) [sources: src/devops_cli/roadmap/decision_point.py, docs/adr/0020-a-decision-point-is-a-unit-of-a-workflow-with-a-resolver-chain-and-a-rule-goes-before-a-decision-model.md]- Chosen: Accept
offandshadow. The item builds shadow mode only, and the planner does not change. - Rejected: Accept
onnow. No fitted cut exists, and feat(roadmap): Refuse stage.explore_stop on mode without fitted cut #4410 covers the refusal ofon.
- Chosen: Accept
- What does the point record when its model call fails at a checkpoint?: It records the checkpoint with no answer and the class of the error, and the run continues unchanged. The shadow route contains its errors in the same way, through
_JEV_FAILED. (best practice) [sources: src/devops_cli/roadmap/stage/stage.py:431, src/devops_cli/roadmap/stage/stage_jev_screen.py]- Chosen: Record the failure and continue. Shadow mode must not change the run, and
_JEV_FAILEDalready contains the errors of a Jev call. - Rejected: Fail the item. A failed shadow call would stop a plan that the mode
offwould finish. - Rejected: Retry the model call. A retry adds window cost to the run that the point measures.
- Chosen: Record the failure and continue. Shadow mode must not change the run, and
- Does this item wait on chore(roadmap): hold incremental stage and implement work #6521?: Yes. The Dependencies section of the issue names chore(roadmap): hold incremental stage and implement work #6521, and the stage job leaves out an item whose Dependencies section names an open issue. chore(roadmap): hold incremental stage and implement work #6521 is the re-architecture of the stage that the owner rule asks for. [sources: docs/roadmap/job-success.md, src/devops_cli/roadmap/stage/stage.py]
- Where does the code of the point live?: A new module
src/devops_cli/roadmap/stage/stage_explore_stop.pyholds the digest, the record, the log file and the replay.stage.pycalls it at a checkpoint and writes the record after the plan. (best practice) [sources: src/devops_cli/roadmap/stage/stage.py, src/devops_cli/roadmap/decision_point.py, docs/adr/0020-a-decision-point-is-a-unit-of-a-workflow-with-a-resolver-chain-and-a-rule-goes-before-a-decision-model.md]- Chosen: A module of its own. ADR 0020 makes a decision point a unit, and the stage module is already large.
- Rejected: Inside
stage.py. The digest, the log and the replay would grow the largest module of the job. - Rejected: Inside
stage_toolbox.py. The toolbox holds the tool budget and the model, not a stored record and a replay.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
Watched files
A commit on the default branch that changes one of these files starts the next refine round.
src/devops_cli/roadmap/stage/stage.py
Activity
dan-petty commentedon Nov 10, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
featprefix of the title gives the type.(roadmap)scope of the title gives the scope.It reduces token waste in shadow mode but does not change live behaviour until a fitted cut exists.It can cut up to 7,000 search_code calls per week once turned on, but the benefit is conditional on the fit.It needs a digest builder, a decision-point registry entry, an offline replay, and a gate comparison, but the planner itself is unchanged.Both target the stage planner call budget, but #4346 sets a fixed call limit and notice while the candidate adds a dynamic explore-or-write decision point.devops-cli-service commentedon Nov 10, 2026
Status set to Ready at 40d2b37 (see proposed design in issue body).
Moved to new items: #4410.
devops-cli-service commentedon Nov 11, 2026
Alternatives check: none
Reason: Searches for a tool that decides when an agent should stop exploring (evidence-sufficiency stopping, tool-call/token budget control, agent trace replay and offline fitting) returned no relevant project; the results were unrelated documentation and framework-usage questions, so no open, maintained tool builds the counts-only digest, writes shadow records, labels them offline or fits the cut. The only tool the issue names, TypeSafe Jev through the project's own pydantic_ai
DecisionModelinsrc/devops_cli/ai/jev.py, answers one typed Choice question and is project code, so the digest, shadow log, replay and fit stay in the repository and the item asks for no external tool or library to adopt.Tool: none found
Lacks:
stage.explore_stopthat offers onlyoffandshadowand refusesonuntil a fitted cut existsSearches run:
Sources:
Checked on 2026-11-11. A person decides what this means for the item. The check changes no label and closes no issue.
devops-cli-service commentedon Nov 18, 2026
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 (6)
Tools considered:
Searches run:
Sources:
dan-petty commentedon Nov 20, 2026
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.
devops-cli-service commentedon Nov 26, 2026
Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies and Watched files in the section Proposed design of the body.
dan-petty commentedon Nov 30, 2026
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.