Skip to content

feat(pipeline): log prompt-token and cache usage per phase - #154

Merged
walker-tx merged 1 commit into
mainfrom
walker/faster-runners
Aug 11, 2026
Merged

feat(pipeline): log prompt-token and cache usage per phase#154
walker-tx merged 1 commit into
mainfrom
walker/faster-runners

Conversation

@walker-tx

Copy link
Copy Markdown
Member

Why

Every phase logs cost $X tools: .... That line cannot tell a cached round from an uncached one — the total looks reasonable either way.

pi already reports input, output, cacheRead, and cacheWrite on each turn_end. The pipeline parsed only usage.cost and 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.

[zapier research] cost $0.4970 tokens: in=1820 out=3410 cache-r=96400 cache-w=12200 hit=87% tools: bash=9 read=8
[zapier research] cost $0.4970 tokens: in=110420 out=3410 cache-r=0 cache-w=0 hit=0% tools: bash=9 read=8

Same cost, opposite cache picture. Today both render identically.

hit is cacheRead over 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:37 currently 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 typecheck clean. npm test — 131/131 pass, including 7 new cases covering multi-turn summing, missing usage, non-numeric fields, outcome propagation, and the zero-division guard.

🤖 Generated with Claude Code

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>
@walker-tx
walker-tx merged commit 030ac85 into main Aug 11, 2026
1 check passed
@walker-tx
walker-tx deleted the walker/faster-runners branch August 11, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant