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 (track_request_spend in src/devops_cli/roadmap/agent_run.py), 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 stage planner prompt (src/devops_cli/roadmap/stage/): the system text, the tool definitions and the first user message. 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

Dependencies

Alternatives check of 2026-11-20: not-applicable.
Class: chore, no search.
Tool: none found.

Proposed design

Problem statement

Nobody knows the share of cached input tokens in a real stage plan run, or if the stage planner prompt puts the stable text first and the item text last. This item records the cache share with its time window and query, gives one verdict on the prompt order with file and line references, and links one fix issue for each recommended change. The change adds no production code.

Acceptance criteria

Requirement: Cache share recorded

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 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 that reads the gateway cache-read series over litellm_input_tokens_metric_total.

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 gh issue view 4583 --comments after the evidence comment lands
  • THEN The output shows the verdict that the stable text comes after the item text, and the file and line of the system text, the tool definitions, the first user message, CONTEXT.md, ADR 0001 to 0005 and capabilities.

Requirement: One issue for each change

The evidence comment MUST give one issue URL for each recommended change.

Scenario: Each recommended change has one linked issue

  • WHEN A person runs gh issue view 4583 --comments after the evidence comment lands
  • THEN The output holds one issue URL for the prompt reorder and one issue URL for the ADR index, and each URL opens an open issue.

Existing Tool Considered

The alternatives check of 2026-11-13 in the issue body gives not-applicable (class chore, no search) and names no tool. The counts come from tools that the repository already uses: the LiteLLM gateway cache metrics that k8s/README.md:142 documents, where the cache hit share is the cached-input series over litellm_input_tokens_metric_total, and the pydantic-ai cache_read_tokens that track_request_spend writes (src/devops_cli/ai/spend/ledger.py:947). The change builds no code, so it has no build, upkeep or fix cost. The alternatives check in the issue body holds what the tools cover and lack.

Key questions

  • What share of the input tokens of a real stage plan run comes from the provider cache?: 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; feat(roadmap): run records give the run, step and path class of tool calls #5460 adds it. A direct count exists for request 1 of feat(ci): Add ast-grep rules for RLIMIT_NPROC, O_NONBLOCK, os.killpg #1976: 10,368 of 41,597 input tokens were cache reads, about 24.9%. [sources: src/devops_cli/roadmap/agent_run.py, src/devops_cli/ai/spend/ledger.py:947, k8s/README.md:142, tests/ai/spend/test_ai_spend_ledger_cache_tokens.py]
  • Does the stage planner prompt put the stable text first and the item text last?: No. The first user message puts number, title and body first. Then come CONTEXT.md (5,448 tokens), ADR 0001 to 0005 (about 4.8k tokens) and capabilities (2,154 tokens). About 12.4k stable tokens follow the item text, so items do not share them as a cache prefix. [sources: CONTEXT.md, docs/adr/0001-github-is-the-roadmap-source.md, docs/adr/0005-review-findings-come-from-tools-not-models.md]
  • Which gateway metric gives the cached input tokens of a run?: k8s/README.md:142 names litellm_input_cached_tokens_metric_total and litellm_input_cache_creation_tokens_metric_total, and gives the cache hit share as the first series over litellm_input_tokens_metric_total. The issue body names litellm_provider_cache_read_input_tokens_metric_total. The evidence comment uses the series that the gateway exposes, and it confirms the name before it posts the query. [sources: k8s/README.md:142, tests/fixtures/dashboard_queries/ai-spend.yaml]
  • Does the stage review run share a cache prefix with the stage planner?: No. The review run sends roadmap_stage_verify.md and the review tool rules as its system text, and its request is a different payload. The stake is about $0.02 in 3 days, so this issue asks for no change to the review run. [sources: src/devops_cli/roadmap/agent_run.py]
  • Should this issue reorder the stage planner prompt itself?: No. This issue records the verdict and links one fix issue for each change. A separate issue does the reorder with an allocation table (feat(roadmap): the stage context gives each block a bound and a cut order #5469), and another replaces the five ADR files with an index (fix(roadmap): the plan context lists the ADRs in force, not ADR 0001-0005 #5465). The saving on DeepSeek is small (about $0.29 of uncached cost in 3 days); the gain is room in the item bound and attention. (best practice) [sources: CONTEXT.md, k8s/README.md:142]
    • Chosen: File one fix issue and link it. The issue asks for one fix issue for each change, and the reply on the issue names feat(roadmap): the stage context gives each block a bound and a cut order #5469 for the reorder with its allocation table.
    • Rejected: Reorder the prompt in this issue. It mixes a measurement with a prompt change and its test, and the reorder needs an allocation table and a stage eval.
    • Rejected: Keep the current prompt order. About 12.4k stable tokens follow the item text, so items share no cache prefix and the item bound loses that room.
  • Does this issue run the CONTEXT.md term-index experiment?: No. The experiment waits on feat(roadmap): the stage context gives each block a bound and a cut order #5469 and the harness of the pipeline split (E1 and E5). It runs with the same 51 stage cases: arm A gives the full text in the stable part (about 5.4k tokens), and arm B gives a term index (about 400 tokens) and read_file for the full text. It decides on paired model requests and tokens, a deterministic count of the _Avoid_ aliases of CONTEXT.md, and a non-inferiority margin set before the run. A separate issue can hold it. (best practice) [sources: CONTEXT.md]

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.

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