Skip to content

chore(roadmap): measure the cache share of a stage plan run #4583

Open

Description

@dan-petty

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):

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

  1. Measure the cache share of one or more real stage plan runs. The CLI records cache_read_tokens of each agent run (agent_run.py in src/devops_cli/roadmap/ calls track_request_spend, and the stage agent runs through it), and the gateway metrics litellm_provider_cache_read_input_tokens_metric_total and litellm_input_tokens_metric_total give the same counts for each end user. Give the share as a percentage, with the time window and the query.
  2. Read the prompt of the stage agent, which runs on the stock Coder (build_stage_agent in src/devops_cli/roadmap/stage/stage_agent.py): the instructions (src/devops_cli/ai/tasks/roadmap_stage_coder.md), the tool definitions of Coder and the first user message (_request in src/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.
  3. 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 --comments after 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_total by litellm_input_tokens_metric_total. The output also shows the per-run cache_read_tokens from track_request_spend as 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 --comments after 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 of Coder from src/devops_cli/roadmap/stage/stage_agent.py, and the first user message in src/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 --comments after 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_total for cached input tokens and litellm_input_tokens_metric_total for input tokens. The evidence comment confirms both series on the gateway before it posts the query. It also cross-checks the per-run cache_read_tokens from track_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_tokens that track_request_spend writes 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_tokens to 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_user and model, not the item. A cross-check ties the window to the 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.md and the stock Coder tool 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

  1. added
    type/chore
    source/agent
    scope/roadmap
    status/new
    value/medium
    effort/low
    on Nov 11, 2026
  2. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/chore. The chore prefix of the title gives the type.
    • Scope: scope/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P3-Low. This is an informational measurement with no user-facing change and no blocking effect.
    • Value: Medium. The result tells the team whether the stage planner pays full input price, which guides future cost decisions.
    • Effort: Low. The task reads existing metrics and one prompt file, then writes a comment; no code change is needed.
    • Related: chore(roadmap): count cached tokens in the step budget #4387, which asks for a different change. 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.
  3. added
    priority/p3-low
    on Nov 11, 2026
  4. devops-cli-service commented on Nov 13, 2026

    @devops-cli-service
    Contributor

    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.

  5. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor

    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_total has no cache_read type (#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, title and body first. Then come CONTEXT.md (5,448 tokens), ADR 0001-0005 (about 4.8k) and capabilities (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:

    Experiment for CONTEXT.md, after #5469, in the harness of the pipeline split (E1 and E5) with the same 51 stage cases:

    • Arm A: the full text in the stable part (about 5.4k). Arm B: a term index (about 400 tokens), and read_file for the full text.
    • Primary measure: model requests and tokens for each case, paired.
    • Secondary measure: a deterministic count of the _Avoid_ aliases of CONTEXT.md (66 _Avoid_ lines) in the plan text. The stage eval has no defect type for term drift.
    • Screen: the eval score, with a non-inferiority margin set before the run.
    • Decision rule: arm B passes only with no rise of the alias count and a score inside the margin.
    • Note: the planner read CONTEXT.md with a tool in 0 of 54 items. That does not show that the text is unused, because the request gives it.
  6. added
    status/ready
    and removed
    status/new
    on Nov 19, 2026
  7. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  8. dan-petty commented on Nov 20, 2026

    @dan-petty
    OwnerAuthor

    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.

  9. added
    status/new
    and removed
    status/ready
    on Nov 28, 2026
  10. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    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.

  11. devops-cli-service commented on Nov 29, 2026

    @devops-cli-service
    Contributor

    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.

  12. added
    status/ready
    and removed
    status/new
    on Dec 1, 2026
  13. devops-cli-service commented on Dec 1, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p3-lowscope/roadmapsource/agentstatus/readytype/chorevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions