Skip to content

feat(routing): show cache savings in route_usage — the #9 part-3 remainder #952

Closed

Description

@dezren39

feat(routing): show cache savings in route_usage — the #9 part-3 remainder

Tracking issue for the unlanded remainder of #9 (prompt cache optimization via
compatibility.cacheFormat). Parts 1–2 of #9 have landed; this issue tracks
part 3 only, so the queue fix task can be minted under a fresh dedupe key
(the #9 fix dedupe key was consumed by completed task 2255 / PR #749).

Verified on main 01cf577 (2026-10-30, issue-sweep-rotating)

Landed (do NOT redo):

  • cache_format on route targets and pools:
    packages/schema/src/config/model-routes.ts:53,245
  • Resolver injects a target's cacheFormat as compatibility.cacheFormat
    for that resolution only: packages/core/src/model-resolver.ts:433-444,
    called per-target at :624 and :706.

Not landed:

  • No savings figure exists anywhere: grep for
    cost_saved|costSaved|savedUsd|savings over packages/ returns 0 hits.
  • packages/core/src/tool/plugin/route-usage.ts output lines print
    requests / failures / metered tokens / costUsd only — no cache tokens,
    hit ratio, or savings — even though ModelUsage totals already aggregate
    cacheRead/cacheWrite (packages/core/src/model-usage.ts:18-19,42-44).
  • SessionUsage.calculateCost already prices cache reads at the cheaper
    cost.cache.read rate (packages/core/src/session/usage.ts:22,32), so
    reported costUsd is net; the missing piece is the counterfactual
    savings: cacheRead tokens × (input price − cache-read price).

Scope

Implement part 3 only:

  • Compute per-model cache savings in ModelUsage from the same catalog
    pricing used for attempt costs; aggregate it alongside costUsd.
  • Display total USD saved plus cache hit ratio in the route_usage tool
    output (per target/pool/day lines where the data supports it).
  • First step: verify per-attempt pricing is recoverable for stored
    route_attempt rows (model identity + pricing snapshot). If it is not
    recoverable for historical rows, compute savings for new rows only and
    park with findings rather than guessing prices.

Acceptance criteria

  • route_usage output shows cache-read tokens, a cache hit ratio, and
    total USD saved via cache hits for the reported totals
    (target/pool/day granularity where rows support it).
  • Savings = cacheRead tokens × (input price − cache-read price) using
    the same catalog pricing as SessionUsage.calculateCost; a unit
    test pins the arithmetic including a zero-cache case.
  • No change to cache_format schema, resolver injection, or net
    costUsd accounting.
  • If per-attempt pricing is not recoverable for stored rows, the task
    parks with that finding instead of estimating.

Origin: #9 triage verdict by issue-sweep-rotating 2026-10-30
(comment on #9); outbox OB-2026-10-30-001 prepared the routing for this
tracking issue.

Activity

  1. added
    kind/featureNew feature or capability request
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    source/creatorFiled by the new-issue-creator job
    priority/lowNice to have; do when convenient
    app/corePackage: core (pkgs/ or apps/ in this repo)
    effort/mMedium: expected under 1 day of work
    on Oct 30, 2026
  2. dezren39 commented on Oct 30, 2026

    @dezren39
    Author

    🤖 Agent note · filed

  3. added
    queue/queuedHas a queued task in the Supabase agent queue
    work/assignedAn agent holds this item via the queue (claimed task)
    queue/claimedA queue worker has claimed the task for this item
    and removed
    queue/queuedHas a queued task in the Supabase agent queue
    on Oct 30, 2026
  4. dezren39 commented on Oct 30, 2026

    @dezren39
    Author

    🤖 Agent note · picked up

    • Agent: queue worker (repo-worker-opencode)
    • Session / ID: queue task 3836
    • Found via: queue claim
    • Task: Implement feat(routing): show cache savings in route_usage — the #9 part-3 remainder #952 part 3 only — cache savings + hit ratio in route_usage
    • Expectation: effort m; done = PR opened with unit tests pinning savings arithmetic, or park if per-attempt pricing unrecoverable for stored rows
    • Links: n/a yet
  5. 2 remaining items

  6. dezren39 commented on Oct 30, 2026

    @dezren39
    Author

    🤖 Agent note · parked

  7. dezren39 commented on Oct 30, 2026

    @dezren39
    Author

    agent-note:v1 — parked (queue task 3836, worker repo-worker-opencode, lane repo-queue-worker-shift-opencode lane A)

  8. added
    queue/claimedA queue worker has claimed the task for this item
    and removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Oct 30, 2026
  9. dezren39 commented on Oct 30, 2026

    @dezren39
    Author

    🤖 Agent note · picked up (resume — merge)

  10. added a commit that references this issue on Oct 30, 2026
  11. dezren39 commented on Oct 30, 2026

    @dezren39
    Author

    🤖 Agent note · done (merged)

  12. removed
    queue/claimedA queue worker has claimed the task for this item
    work/assignedAn agent holds this item via the queue (claimed task)
    on Oct 30, 2026
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

    app/corePackage: core (pkgs/ or apps/ in this repo)effort/mMedium: expected under 1 day of workkind/featureNew feature or capability requestpriority/lowNice to have; do when convenientsource/creatorFiled by the new-issue-creator jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions