Repository navigation
Description
Problem or Motivation
#4387 asked five questions about the token budget and the provider cache. PR #4553 answers three of them for the implement step and makes the step budget count new tokens. Two points of #4387 are open for the stage planner (devops roadmap stage):
- Point 2: the share of cached input tokens in a real stage plan run. PR fix(roadmap): the step budget counts new tokens, not cached input #4553 measured the implement step (98.6% cache reads in the runner Jobs) and the Service row
refine(about 79%), but not a stage plan run. - Point 5: whether the prompt of the stage planner puts the stable text first and the changing text last, so that the provider cache serves the shared prefix. PR fix(roadmap): the step budget counts new tokens, not cached input #4553 did not check the order of the stage planner prompt.
Without these two answers, nobody knows if the stage planner pays the full input price on each request, and if a change of its prompt order makes its runs cheaper.
Proposed Solution & Architectural Design
- Measure the cache share of one or more real stage plan runs. The CLI records
cache_read_tokensof each agent run (agent_run.pyinsrc/devops_cli/roadmap/callstrack_request_spend, and the stage agent runs through it), and the gateway metricslitellm_provider_cache_read_input_tokens_metric_totalandlitellm_input_tokens_metric_totalgive the same counts for each end user. Give the share as a percentage, with the time window and the query. - Read the prompt of the stage agent, which runs on the stock
Coder(build_stage_agentinsrc/devops_cli/roadmap/stage/stage_agent.py): the instructions (src/devops_cli/ai/tasks/roadmap_stage_coder.md), the tool definitions ofCoderand the first user message (_requestinsrc/devops_cli/roadmap/stage/stage_job_phases.py). State if the stable text comes first and the text of the item comes last. Give one verdict: follows the order, or does not follow it, with the file and the line of each part. - If the order does not follow the rule, or the share is much lower than the implement step, file one fix issue for each change. Otherwise close this issue with the evidence in a comment.
No production code is part of this issue.
Acceptance:
- A comment on this issue gives the cache share of a stage plan run as a percentage, with its source.
- A comment on this issue gives the verdict on the prompt order of the stage planner, with file and line references.
- Each recommended change has one issue URL.
Target Subsystem
roadmap stage (planner), AI gateway usage metrics.
Existing Tool Considered
The LiteLLM gateway metrics and the pydantic-ai usage fields (cache_read_tokens) already give the counts. The item needs no new tool.
Source: points 2 and 5 of #4387, left open by PR #4553.
Source: #4553
Alternatives check of 2026-11-30: not-applicable.
Class: chore, no model call.
Tool: none found.
Proposed design
Problem statement
The stage planner may pay the full input price on each request. This item records the cache share of a real stage plan run with its time window and query. It gives one verdict on the prompt order with file and line references. It links one fix issue for each recommended change. It adds no production code.
Acceptance criteria
Requirement: Cache share evidence
A comment on issue #4583 MUST give the cache-read share of a real stage plan run as a percentage, with its time window and its query.
Scenario: The evidence comment shows the share, the window and the query
- WHEN A person runs
devops gh issue view 4583 --commentsafter the evidence comment lands - THEN The output shows the share as a percentage, the time window, and the query. The query divides
litellm_provider_cache_read_input_tokens_metric_totalbylitellm_input_tokens_metric_total. The output also shows the per-runcache_read_tokensfromtrack_request_spendas the cross-check.
Requirement: Prompt order verdict
A comment on issue #4583 MUST give one verdict on the prompt order of the stage planner, with the file and line of each part.
Scenario: The verdict names each prompt part and its location
- WHEN A person runs
devops gh issue view 4583 --commentsafter the evidence comment lands - THEN The output shows one verdict on the order. It gives the file and line of the system prompt in
src/devops_cli/ai/tasks/roadmap_stage_coder.md, the tool definitions ofCoderfromsrc/devops_cli/roadmap/stage/stage_agent.py, and the first user message insrc/devops_cli/roadmap/stage/stage_job_phases.py.
Requirement: Fix issue links
The evidence comment MUST give one issue URL for each recommended change.
Scenario: Each recommended change has one linked issue
- WHEN A person runs
devops gh issue view 4583 --commentsafter the evidence comment lands - THEN The output shows one issue URL for each recommended change. Each URL opens an open issue.
Existing Tool Considered
The alternatives check of 2026-11-30 in the issue body gives not-applicable and names no tool. The issue body names the existing LiteLLM gateway metrics and the pydantic-ai usage field cache_read_tokens. The item adds no code, so it has no build, upkeep or fix cost. The gateway series give the aggregate counts by end user and model. The per-run cache_read_tokens from track_request_spend gives the cross-check.
Key questions
- Which gateway series give the cached input tokens and the input tokens of a stage plan run?: The issue body names
litellm_provider_cache_read_input_tokens_metric_totalfor cached input tokens andlitellm_input_tokens_metric_totalfor input tokens. The evidence comment confirms both series on the gateway before it posts the query. It also cross-checks the per-runcache_read_tokensfromtrack_request_spend. [sources: k8s/devops/dashboards/ai-spend.json, openspec/specs/gateway-caller-telemetry/spec.md, src/devops_cli/roadmap/agent_run.py] - How will the evidence comment measure the cache share of a real stage plan run?: Use the gateway metrics for the run window and cross-check them with the per-run
cache_read_tokensthattrack_request_spendwrites to the ledger. Report the share as a percentage, with the time window and the query. The gateway series give the aggregate counts for the window. The ledger gives the per-run count to confirm them. (best practice) [sources: src/devops_cli/roadmap/agent_run.py, src/devops_cli/ai/spend/ledger.py, tests/ai/spend/test_ai_spend_ledger_cache_tokens.py]- Chosen: Gateway metrics with a ledger cross-check. The gateway series give the aggregate counts for the window. The ledger gives the per-run
cache_read_tokensto confirm them. - Rejected: Ledger records only. The ledger holds per-run counts. It does not give the gateway aggregate for the same window.
- Rejected: Gateway metrics only. The gateway series carry
end_userand model, not the item. A cross-check ties the window to the run.
- Chosen: Gateway metrics with a ledger cross-check. The gateway series give the aggregate counts for the window. The ledger gives the per-run
- Does the stage planner prompt put the stable text first and the item text last?: No, not fully. The system prompt
roadmap_stage_coder.mdand the stockCodertool definitions are stable and come first. The first user message starts with the item number, title and body. Stable context follows the item, so that context is not a shared prefix. [sources: src/devops_cli/ai/tasks/roadmap_stage_coder.md, src/devops_cli/roadmap/stage/stage_agent.py:216, src/devops_cli/roadmap/stage/stage_job_phases.py] - Should this issue reorder the stage planner prompt itself?: No. This issue records the verdict and files one fix issue for each recommended change. A prompt reorder is a separate change with its own before/after check. The evidence comment links the fix issue. (best practice) [sources: docs/ROADMAP_WORKFLOW.md, src/devops_cli/ai/tasks/roadmap_stage_coder.md]
- Chosen: File one fix issue and link it. The issue asks for one issue for each recommended change. A prompt change needs its own before/after check.
- Rejected: Reorder the prompt in this issue. It mixes a measurement with a prompt change. The reorder needs its own before/after check.
- Rejected: Keep the current prompt order. The item text comes before the stable context. The stable context after the item is not a shared prefix.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 11, 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.This is an informational measurement with no user-facing change and no blocking effect.The result tells the team whether the stage planner pays full input price, which guides future cost decisions.The task reads existing metrics and one prompt file, then writes a comment; no code change is needed.Both track cached tokens in the roadmap stage area, but #4387 asks for a budget count while this candidate asks for a one-time cache-share measurement and prompt-order verdict.fix(roadmap): the step budget counts new tokens, not cached input (#4553
devops-cli-service commentedon Nov 13, 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-13. A person decides what this means for the item. The check changes no label and closes no issue.
dan-petty commentedon Nov 13, 2026
Answers from the start-context review of the roadmap jobs (2026-11-13):
Point 2, the cache share. DeepSeek read 96-98% of the stage and implement input from its cache in the 3 days to 2026-11-13. This is an estimate from the spend divided by the price, because
devops_cli_ai_tokens_totalhas nocache_readtype (#5460 adds it). On request 1 of #1976, 10,368 of 41,597 input tokens were cache reads.Point 5, the order. The user message puts
number,titleandbodyfirst. Then comeCONTEXT.md(5,448 tokens), ADR 0001-0005 (about 4.8k) andcapabilities(2,154). So about 12.4k stable tokens come after the item text, and items do not share them as a cache prefix. The uncached cost of that is about 3.8M tokens in 3 days, about $0.29.Verdict: a reorder saves little money on DeepSeek. The gain is room in the item bound and attention. Rule for each new block:
roadmap_stage_verify.mdand the review tool rules, and its request is a different payload. The stake is about $0.02 in 3 days.Experiment for
CONTEXT.md, after #5469, in the harness of the pipeline split (E1 and E5) with the same 51 stage cases:read_filefor the full text._Avoid_aliases ofCONTEXT.md(66_Avoid_lines) in the plan text. The stage eval has no defect type for term drift.CONTEXT.mdwith a tool in 0 of 54 items. That does not show that the text is unused, because the request gives it.devops-cli-service commentedon Nov 19, 2026
Next step: the stage job writes the plan of the item. See the section Proposed design of the body.
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 28, 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.
devops-cli-service commentedon Nov 29, 2026
Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies in the section Proposed design of the body.
devops-cli-service commentedon Dec 1, 2026
Next step: the stage job writes the plan of the item. See the section Proposed design of the body.