feat(pipeline): log prompt-token and cache usage per phase - #154
Merged
Conversation
Every phase logs `cost $X tools: ...`, which cannot tell a cached round
from an uncached one — the total looks reasonable either way. pi already
reports `input` / `output` / `cacheRead` / `cacheWrite` on each
`turn_end`; the pipeline dropped all four on the floor.
Sum them alongside `totalCostUsd` and render them on the same line:
[zapier research] cost $0.4970 tokens: in=1820 out=3410 \
cache-r=96400 cache-w=12200 hit=87% tools: bash=9 read=8
`hit` is cacheRead over all prompt tokens. It answers the question that
decides whether per-phase model routing is worth doing: the review loop
re-sends the same doctrine, persona and draft context every round, so a
hit near 0 on rounds 2 and 3 means each round re-pays full input price
for identical bytes.
Measurement only. No behaviour change.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Every phase logs
cost $X tools: .... That line cannot tell a cached round from an uncached one — the total looks reasonable either way.pialready reportsinput,output,cacheRead, andcacheWriteon eachturn_end. The pipeline parsed onlyusage.costand dropped the other four on the floor.This matters because the review loop re-sends the same doctrine, persona, and draft context every round. Across 53 recent guide runs, round 1 and round 2 reviews are the majority of loop time, and 36% of runs reach round 3. If the OpenRouter route serves no cache, each round re-pays full input price for identical bytes — and nothing in the current logs would show it.
What
Sum the four token fields alongside
totalCostUsd, and render them on the same log line.Same cost, opposite cache picture. Today both render identically.
hitiscacheReadover every prompt token (input + cacheRead + cacheWrite).Scope
Measurement only. No behaviour change.
This is deliberately the first step. It gates a per-phase model split —
pipeline/src/cli.ts:37currently sets one model slug for every agent slot, including the research-change judge, which is a binary classification that costs ~$0.11 and ~15s on the top-tier model. Whether routing cheaper models at the reviewers pays off depends on the cache numbers this PR exposes.Tests
npm run typecheckclean.npm test— 131/131 pass, including 7 new cases covering multi-turn summing, missingusage, non-numeric fields, outcome propagation, and the zero-division guard.🤖 Generated with Claude Code