Repository navigation
Description
Problem
The first model request of an implement step already carries about 98,000 input tokens. An item stopped on this: issue #4004, group 1, first attempt, first request 97,821 tokens (trace from devops roadmap explain 4004 --trace). The step budget roadmap.implement.step_token_budget counts the input tokens of every request, so a start context of 98,000 tokens leaves room for about 80 requests at the default of 8,000,000. We do not know what fills the start context.
What is known
- The instructions file
src/devops_cli/ai/tasks/roadmap_implement_step.mdis 8,842 bytes, about 2,200 tokens. - The step message holds the plan inputs of the group.
implement_step.pycounts the instructions and the message intokens, but the log keeps no split by part. - The tool definitions of the Coder agent are part of every request. Their size is not measured.
- The stage planner has the same shape: a plan run of feat(roadmap): Stage items whose draft plan fails the check #3387 used 6.5M input tokens in 58 requests, about 112,000 per request.
What to find out
- A table of the start context of an implement step, by part, in tokens: instructions, plan inputs (proposal, design, spec delta, tasks), the group text, kept
wip:diff, retry text, the tool definitions, anything else. - The same table for at least five implement runs of different size, and for a stage plan run.
- For each part: is it needed by the step, can it be a tool call instead (read on demand), can it be shorter, or can it be cached?
- Which part grows with the size of the change, and which is fixed.
How to measure
Count tokens per part with the existing count_tokens. Add no permanent code unless the table needs a log line; if it does, log counts only. Use runs that exist in the trace (implement.trace) and one fresh run with a fake model.
Done when
A table and a short recommendation are in this issue, with the parts ranked by tokens saved against the risk. No code change is part of this issue; file a fix issue for each recommendation.
Related: #4004 (the stop), the step budget (roadmap.implement.step_token_budget).
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-20: not-applicable.
Class: chore, no search.
Tool: none found.
Proposed design
Problem statement
The first request of an implement step carried 97,821 input tokens at issue #4004. A review on 2026-11-13 measured 25.5k median tokens for 119 groups, before the item text and the tool definitions. The step budget roadmap.implement.step_token_budget counts these tokens. No record splits the start context by part. This item measures each part, marks it fixed or growing, ranks it by tokens saved against risk, and gives one fix issue for each recommendation.
Acceptance criteria
Requirement: Start context document
The change SHALL add docs/ROADMAP_START_CONTEXT.md with a table of the start context by part, one total row and a recommendation section.
Scenario: The docs check passes
- WHEN
uv run devops ci --check --only docsruns on the pull request - THEN The check passes and reports no error for
docs/ROADMAP_START_CONTEXT.md.
Requirement: Instructions row
The instructions row MUST hold the count that count_tokens gives for src/devops_cli/ai/tasks/roadmap_implement_step.md.
Scenario: The prompt file count matches its row
- WHEN
uv run python -c "from pathlib import Path; from devops_cli.ai.context_budget import count_tokens; print(count_tokens(Path('src/devops_cli/ai/tasks/roadmap_implement_step.md').read_text()))"runs - THEN The command prints the token count that the instructions row holds.
Requirement: Tool definitions row
The tool definitions row MUST hold the count that count_tokens gives for the tools table of the prompt.
Scenario: The tools table count matches its row
- WHEN
uv run python -c "from devops_cli.ai.context_budget import count_tokens; from devops_cli.roadmap.tools import tools_table; print(count_tokens(tools_table()))"runs - THEN The command prints the token count that the tool definitions row holds.
Requirement: Six input columns
The table MUST give one column for each of five archived change folders of different size and one column for a stage plan input.
Scenario: The document names the six inputs
- WHEN
git grep -n -E 'openspec/changes/archive/|stage_change' -- docs/ROADMAP_START_CONTEXT.mdruns - THEN The command prints five different archived change paths and the stage plan input.
Requirement: Fixed and growing parts
The document SHALL mark each part as fixed or as growing with the size of the change.
Scenario: The growing mark names only the parts that grow
- WHEN
git grep -n -F 'grows with the change' -- docs/ROADMAP_START_CONTEXT.mdruns - THEN The command prints a line for the item text, the plan documents, the group text, the named-file signatures and the kept
wip:diff, and prints no line for the instructions and the tool definitions.
Requirement: Gap to the measured stop
The document SHALL state the difference between the total row and the 97,821 input tokens of issue #4004.
Scenario: The document names the gap
- WHEN
git grep -n -F '97,821' -- docs/ROADMAP_START_CONTEXT.mdruns - THEN The command prints the line that gives the difference to the total row.
Requirement: Ranked recommendation
The recommendation SHALL rank each part by the tokens that a change saves against the risk of the change.
Scenario: Each ranked part has a saving and a risk
- WHEN
git grep -n -E '^\| *[0-9]+ *\|' -- docs/ROADMAP_START_CONTEXT.mdruns - THEN The command prints one row for each ranked part, each with a token saving and a risk, and the largest saving comes first.
Requirement: Fix issue for each recommendation
The document MUST give a Conventional Commit title and a body for each recommendation.
Scenario: Each recommendation has a title of the commit form
- WHEN
git grep -n -E '^### [a-z]+\([a-z-]+\): ' -- docs/ROADMAP_START_CONTEXT.mdruns - THEN The command prints one title for each recommendation, and each printed title has the form
<type>(<scope>): <summary>.
Requirement: No permanent code
The change SHALL add no file under src/ or tests/.
Scenario: The pull request changes only documents
- WHEN
git diff --name-only origin/mainruns on the pull request branch - THEN The command prints only paths under
docs/.
Existing Tool Considered
The alternatives check of 2026-11-20 in the issue body gives not-applicable for this chore and names no tool. tiktoken, through count_tokens in src/devops_cli/ai/context_budget.py, covers the token count of each part. It lacks a split by part, and the one-off measurement of this item gives that split. The change builds no code, so it has no build cost.
Key questions
- Which function gives the exact token count of a text, offline?:
count_tokensinsrc/devops_cli/ai/context_budget.pygives the exact count with tiktoken. It raisesTokenCountErrorwhen the encoding is missing, and it never estimates a count. [sources: src/devops_cli/ai/context_budget.py:90] - Which parts of the start context does the implement step count today?:
StepInputsholds the instructions, the user message and their token counts. The step log keeps no split by part. [sources: src/devops_cli/roadmap/implement/implement_step.py] - Which inputs give the five implement sizes of different size and the stage plan input?: Pack five archived change folders of different size from
openspec/changes/archive/withContextPacker. Take the stage plan input from the stage change builder. (best practice) [sources: src/devops_cli/ai/context_packer.py:395, src/devops_cli/roadmap/step_files.py, src/devops_cli/roadmap/stage/stage_change.py]- Chosen: Five archived change folders under
openspec/changes/archive/. The repository keeps them, so the measurement runs offline and a reader can repeat it. - Rejected: The
implement.tracerecords of production runs. The records are not in the repository at the refined commit, so a step cannot read them. - Rejected: Synthetic change folders of set sizes. They do not show the real growth of a plan input.
- Chosen: Five archived change folders under
- Where does the inventory live?: Write the table and the recommendation in a new document
docs/ROADMAP_START_CONTEXT.md. (best practice) [sources: docs/ROADMAP_WORKFLOW.md, AGENTS.md]- Chosen: A new document
docs/ROADMAP_START_CONTEXT.md. The pull request delivers it, a person reviews it, and the docs check reads it. - Rejected: A comment on the issue. The pull request delivers no record, and no review reads the comment.
- Rejected: A test module that prints the table. The issue forbids permanent code.
- Chosen: A new document
- Which measure reproduces the start context without permanent code?: Give the one-off commands in the document. Each command calls
count_tokenson one part, and the reader can run it again. (best practice) [sources: src/devops_cli/ai/context_budget.py:90, src/devops_cli/roadmap/implement/implement_step.py]- Chosen: A documented sequence of one-off
uv run python -ccalls. The step counts the same parts before its first request, so a one-off call gives the same count. - Rejected: A new log line in the step. It adds code, and the issue asks for none.
- Rejected: A new
devops roadmapsubcommand. It adds permanent code, and the issue asks for none.
- Chosen: A documented sequence of one-off
- Which parts are fixed, and which grow with the change?: The instructions and the tool definitions are fixed. The item text, the plan documents, the group text, the named-file signatures and the kept
wip:diff grow with the change. [sources: src/devops_cli/ai/tasks/roadmap_implement_step.md, src/devops_cli/roadmap/implement/implement_step.py, CONTEXT.md] - Can the implement step file the fix issues itself?: No. The step writes nothing to GitHub, so a person files each fix issue from the title and the body in the document. [sources: src/devops_cli/ai/tasks/roadmap_implement_step.md, src/devops_cli/roadmap/implement/implement_step.py]
- Which part does the recommendation rank first, and what does a cut risk?: The routed rule sections rank first: the review of 2026-11-13 measured 12.9k median tokens, the largest part. A cut risks rule compliance, so the document ranks a compliance measure before the cut. The item text and the tool definitions rank next. (best practice) [sources: src/devops_cli/roadmap/step_rules.py, CONTEXT.md, src/devops_cli/ai/tasks/roadmap_implement_step.md]
- Chosen: Rank the routed rule sections first, with a compliance measure before the cut. They are the largest measured part, and the evidence does not show their value.
- Rejected: Rank the change documents first. They measured 4.2k median tokens, less than the routed sections.
- Rejected: Cut the routed sections with no measure. No measure would show a fall in rule compliance.
- For each part, is it needed by the step, can it be a tool call, can it be shorter, or can it be cached?: The change documents and the named files can be read on demand with the step's read tools. The retry text and the kept diff can be shorter. A cache lowers the cost only, because it frees no window room. (best practice) [sources: src/devops_cli/ai/tasks/roadmap_implement_step.md, src/devops_cli/roadmap/tools.py, tests/ai/spend/test_ai_spend_ledger_cache_tokens.py]
- Chosen: Read the change documents and the named files on demand. It frees window room, and the step has read tools for the files that a group names.
- Rejected: Send every plan document in the first request. This part grows with the change and keeps window room.
- Chosen: Shorten the retry text and the kept diff. A stop gives the end of the log, not the whole log.
- Rejected: Rank a prompt cache as a token saving. A cache lowers the cost, and it frees no window room.
- What waits this item?: The item waits on chore(roadmap): hold incremental stage and implement work #6521. Incremental work on the stage, implement and fix-checks jobs stops until the re-architecture of refactor(roadmap): re-architect stage and implement on Coder #6519 decides. A person then closes chore(roadmap): hold incremental stage and implement work #6521 or closes this item as not planned. (best practice) [sources: CONTEXT.md]
- Chosen: Record chore(roadmap): hold incremental stage and implement work #6521 as a dependency and keep the item. The owner rule stops incremental work on these jobs until the re-architecture decides.
- Rejected: Build the measurement now. The re-architecture changes the start context, so the numbers would not hold.
- Rejected: Close the item as not planned. A person decides that when refactor(roadmap): re-architect stage and implement on Coder #6519 reports.
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/implement/implement_step.pysrc/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.
choreprefix of the title gives the type.(roadmap)scope of the title gives the scope.It is a diagnostic task that informs future fixes but blocks no user workflow.It produces a ranked table that guides which token-saving fix to file next.It needs several trace runs, per-part token counts, and a short recommendation, but uses existing tooling.Both concern the implement step token budget, but #3568 sets the budget limit while the candidate measures what fills the start context under that limit.devops-cli-service commentedon Nov 10, 2026
Status set to Ready at 84d1570 (see proposed design in issue body).
devops-cli-service commentedon Nov 11, 2026
Alternatives check: not-applicable
Class: chore. The check makes no search and no model call for an item of this class.
Tool: none found
Checked on 2026-11-11. A person decides what this means for the item. The check changes no label and closes no issue.
dan-petty commentedon Nov 13, 2026
Start-context table and a recommendation, from the start-context review of the roadmap jobs (2026-11-13). Measured at origin/main for 119 groups of 39 items, o200k tokens, before the issue text and the tool definitions:
AGENTS.mdThe step refuses a start over the window minus 40k. The cache share of the runner Jobs is about 98%, so the cost of the start context is window room and attention, not money.
Observations, 7 days to 2026-11-13, 45 runs: shell reads of rule documents in 2 runs;
tasks.md43 calls in 20 runs; the change folder 69 calls in 26 runs.read_filepaths are not logged, so reads throughread_fileare not visible (#5460 adds a path class). The evidence shows neither a low nor a high value of the routed sections: the agent does not need to look for rules that its message already holds.Recommendation:
implement_hooks), failures of the scoped static rows, and review findings by rule on delivery pull requests (E4 of the pipeline split). The six eval properties (tests_kept,diff_scope,no_scratch,tasks_ticked,tests_pass,verify_passes) do not measure rule compliance.tasks.mdis already in the message.Two experiments for the E2 arms of the pipeline split:
conftest.pyof that folder, and the message keys that it uses. At most 200 tokens. Evidence: shellgrepin tests 253 calls in 29 of 45 runs, insrc302 calls in 29 runs; thegreptool 570 calls (paths not logged); test-folder listings 53 calls in 21 runs;devops ai repomapanddevops ai astin 0 of 45 runs. The search texts are masked, so the share of greps that look for neighbors is not known. Primary measure: grep-in-tests and test-folder listing calls for each step (needs feat(roadmap): run records give the run, step and path class of tool calls #5460). Decision rule: fewer such calls and no fall in the six properties.ls .ast-grep/rules,cat sgconfig.ymland similar: 50 calls in 18 of 45 runs, and 6 calls in 1 of 10 recent runs, after a failed ast-grep hook. The repair turn gets the lastCONST_ROADMAP_IMPLEMENT_LOG_CHARScharacters of the failed-check log. Check one recorded repair turn. If the cut removes the rule id, message and note, give them in the repair turn only, not in the start context.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.