Repository navigation
Description
Problem
The step budget counts the input tokens of every request, added together. The context is resent in each request, so the number grows much faster than the amount of new text the model reads. If the model provider caches the shared prefix, most of those tokens cost little; if it does not, they cost the full price. We do not know which is the case, and the budget makes no difference between them. In #4004 the step stopped on 8,011,119 input tokens, but the real cost of the run is not known: the project price table has no price for deepseek-v4.1-flash-1017, so the spend counters record 0.
What to find out
- Does the model provider (through OpenRouter and the LiteLLM gateway) cache the shared prefix of requests for
deepseek-v4.1-flash-1017? Check the provider documents and a measured pair of requests. Does the reply report cached tokens (prompt_tokens_details.cached_tokensor the provider field), and does the gateway keep that field in the usage that the CLI reads? - The share of cached tokens in a real implement step and in a real stage plan run.
- Whether the budget should count uncached tokens, the cost, or the number of requests, and what limit then fits an item. State the effect on the stops of the last seven days (
limit_reachedandoutput_capclasses). - The price of
deepseek-v4.1-flash-1017for the price table (input, cached input, output), so the spend counters show the real cost. Check the open price work (ai.price_overrides, fix(ai): an agent run on a hosted group is not local spend #3665) before proposing a change. - Whether the order of the request (stable text first, changing text last) matters for the cache, and whether the prompts of the implement step and the stage planner follow it.
Done when
The answers to the five points, with the evidence, and a recommendation for the budget unit and the limit are in this issue. No code change is part of this issue; file a fix issue for each recommendation.
Related: #4004, roadmap.implement.step_token_budget, roadmap.implement.item_token_budget.
Proposed design
Problem statement
The step budget sums raw input tokens. It cannot tell cached from uncached tokens, and the project has no price for deepseek-v4.1-flash-1017. The spend counters show 0, and stops do not show the real cost. This item investigates provider caching, measures the cached share, and recommends a budget unit and limit.
Acceptance criteria
Requirement: No production code
The change SHALL add only the report and the OpenSpec change, and SHALL change no production code.
Scenario: Diff has report only
- WHEN A test reads the pull request diff.
- THEN The diff contains no file under
src/.
Requirement: Provider cache evidence
The token-budget report SHALL state whether the provider caches the shared prefix and SHALL cite the provider documentation and one measured request pair.
Scenario: Cached field is recorded
- WHEN A test reads
docs/ROADMAP_TOKEN_BUDGET.md. - THEN The file names
prompt_tokens_details.cached_tokensand gives two measured usage values for one shared prefix.
Requirement: Cached-token share
The report SHALL give the cached-token share for one real implement step and one real stage plan run.
Scenario: Both shares are present
- WHEN A test reads the report.
- THEN The file gives a percentage for the implement step and a percentage for the stage plan run.
Requirement: Budget unit and limit
The report SHALL recommend one budget unit and one limit, and SHALL state the effect on limit_reached and output_cap stops from the last seven days.
Scenario: Recommendation is complete
- WHEN A test reads the report.
- THEN The file names the chosen unit, the limit, and the count of each stop class.
Requirement: Model price
The report SHALL record the input, cached input and output prices for deepseek-v4.1-flash-1017 and SHALL check ai.price_overrides #3665.
Scenario: Three prices are present
- WHEN A test reads the report.
- THEN The file lists the three prices and cites fix(ai): an agent run on a hosted group is not local spend #3665.
Requirement: Prompt order
The report SHALL state the cache-aware prompt order and SHALL say whether the implement prompt and the stage planner follow it.
Scenario: Both prompts are checked
- WHEN A test reads the report.
- THEN The file states stable text first and gives a verdict for each prompt.
Requirement: Follow-up issues
The report SHALL list one follow-up issue for each recommendation.
Scenario: Each recommendation has a link
- WHEN A test reads the report.
- THEN Every recommendation has one issue URL.
Existing Tool Considered
No alternatives check has run. LiteLLM is the open, maintained gateway. It reports usage with cached-token details and computes cost from a model price map. It lacks a price for deepseek-v4.1-flash-1017; add that price through ai.price_overrides (#3665). The change writes a report and no production code.
Key questions
- Does the provider cache the shared prefix for
deepseek-v4.1-flash-1017, and does the gateway keep the cached-token field?: OpenRouter forwards provider usage. LiteLLM keepsprompt_tokens_details.cached_tokensin its usage object. The repository does not yet confirm that this model returns the field. The report must measure one repeated-prefix request pair. [sources: src/devops_cli/roadmap/implement/implement_step.py] - What is the cached-token share in a real implement step and in a real stage plan run?: No measured share is recorded. The stage comment already reports plan tokens. The implement step records request usage. The report must give one share for each real run. [sources: CONTEXT.md, src/devops_cli/roadmap/implement/implement_step.py]
- Should the budget count uncached tokens, cost, or the number of requests, and what limit fits an item?: Count cost in USD per step and per item. Use uncached input tokens plus output tokens as the fallback when a price is missing. Set the limit from the measured seven-day stop data. Do not keep the raw input-token sum. (best practice) [sources: docs/ENV_VARS.md:127, docs/ROADMAP_WORKFLOW.md:196, src/devops_cli/roadmap/failure.py]
- Chosen: Cost in USD. It bounds spend and applies the cached-input discount.
- Rejected: Uncached input tokens. It avoids the price table, but it does not bound output spend.
- Rejected: Number of requests. It ignores context size and the cached share.
- Rejected: Raw input tokens. It overcounts cached tokens and hides the real cost.
- What are the input, cached-input and output prices for
deepseek-v4.1-flash-1017, and how does the price table take them?: The repository has no price for this model, so the spend counters record 0. The report must record the three provider prices. Add them throughai.price_overrides(fix(ai): an agent run on a hosted group is not local spend #3665), not a new table. [sources: src/devops_cli/config/settings.py] - Does the request order matter for the cache, and do the implement prompt and stage planner follow it?: Put stable text first and changing text last. The cache matches the longest common prefix. The repository does not record that either prompt follows this order. The report must check both prompts. [sources: src/devops_cli/roadmap/implement/implement_step.py, docs/ROADMAP_WORKFLOW.md]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Alternatives check of 2026-11-11: not-applicable.
Class: chore, no search.
Tool: none found.
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 informs the budget unit and limit decisions but blocks no user-facing feature.It clarifies real cost and the correct budget unit, which affects all future stop decisions.It requires checking provider docs, measuring two request pairs, inspecting gateway usage fields, and writing a recommendation.Both examine the step token budget and reference issue #4004, but #4385 inventories what fills the start context while the candidate investigates whether and how cached tokens should be counted in that budget.devops-cli-service commentedon Nov 10, 2026
Status set to Ready at 013c1f4 (see proposed design in issue body).
dan-petty commentedon Nov 11, 2026
Service data, 48 hours to 2026-11-10T23:45Z: step budget stops
This data answers point 2 and part of point 3 of this item.
Count: 4 of 8 runner Jobs stopped on
limit_reachedagainstroadmap.implement.step_token_budget. The metricdevops_cli_service_implement_failures_total{class="limit_reached"}shows 3, because a pod replacement near 14:30Z lost the #4004 increment.status/blocked, work discardedimplement: retryfinished it with 292,903 more tokens (PR #4378)status/blockedFirst and last: 11:16:34Z and 20:36:20Z on 2026-11-10. Still occurring: yes. The last stop is in the last 6 hours of the window. After the window, Job
devops-cli-runner-20261111-022552(#3462) was at about 54 requests and 3.95M input tokens, with 99.2% cache reads.Cost: 82.7 Job minutes (19m16s + 22m52s + 21m27s + 19m06s), 39,802,176 input and 177,926 output tokens in about 380 requests. The gateway spend is only USD 0.162 (0.0349 + 0.0525 + 0.0343 + 0.0402), because the cache-read share of each stopped Job was 99.0%, 98.8%, 98.6% and 99.5%.
Point 2, measured: over 48 hours,
end_user="devops-cli-job"sent 58,482,776 input tokens, and 57,672,756 of them (98.6%) were provider cache reads (litellm_provider_cache_read_input_tokens_metric_total).Root cause:
src/devops_cli/roadmap/implement/implement_limits.py:103callsbudget.add(response.usage.input_tokens). In pydantic-ai 2.59.0,UsageBase.input_tokensincludescache_read_tokensandcache_write_tokens. Each request sends the whole context again (about 100k to 140k tokens), so the budget is in effect a cap of about 60 to 120 requests, not a cap on cost or on new text. The raise from 8M to 12M (live at about 14:48Z) only moved the stop: #3429 stopped at 12,006,459 after about 120 requests. No commit on origin/main changes the budget unit.Point 3, input for the recommendation:
RequestUsage.cache_read_tokens). PR fix(ai): price the DeepSeek group and its cached input #4454 now prices DeepSeek cached input, which partly answers point 4.tailpolls of the log of one backgrounduv run devops ci testcall, and about 7.06M of its 12.0M input tokens went into that span. The issue for that cause is filed separately. With an uncached budget, such a loop would stop only atstep_time_limit_seconds.Priority: this item is P2. The stops end 50% of the implement Jobs, and 2 P2 items (#3443, #3429) stay
status/blockedbehind them. By the blocker rule (a blocker of 2 or more P2 items is P1), the evidence suggests P1 for this item or for the fix issue that it files.Queries:
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 11, 2026
The two open points of the stage planner move to #4583: the cache share of a stage plan run (point 2) and the order of the stage planner prompt (point 5).
PR #4553 replaces the report-only criteria of this item with the fix that the measurements recommend: the step budget, its ceiling and the item budget count new tokens. The PR comment of 2026-11-11 gives the answers to points 1, 2 (implement step), 3 and 4. A person decides if this replacement is accepted when the PR merges.
fix(roadmap): the step budget counts new tokens, not cached input
fix(roadmap): the step budget counts new tokens, not cached input
devops-cli-service commentedon Nov 11, 2026
Released in v0.112.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.112.0
dan-petty commentedon Nov 11, 2026
Correction to point 3 of comment 6790420886 on #4553: the 4
limit_reachedstops used 1.1% to 1.9% of the merged default step budget of 8000000 new tokens. The 9% to 15% in that comment is for the rejected default of 1000000. Found in the adversarial check of #4553.devops-cli-service commentedon Nov 11, 2026
Live since 2026-11-11 14:13 UTC