Repository navigation
fix(advisor): log review cache writes - #196704
Conversation
Review usage logged input, cache reads and output but not cache writes. On OpenAI routes a review that misses the prompt cache reports its whole forked context as cache writes, so the log showed input=75 cacheRead=0 and looked like a review that saw no conversation. Co-authored-by: obviyus <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR adds cache-write token counts to Advisor review logs and documents provider-dependent cache-write reporting. Example: A review returns inputTokens=75, cacheReadTokens=0, cacheWriteTokens=200000, and outputTokens=6.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this collaborator-authored PR provides useful diagnostic visibility, resolves the prior documentation finding, and has no remaining actionable findings. Priority: P3 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherAdvisor requests a conversation review through the session-fork runtime, receives normalized provider usage, and writes token counts to Gateway logs. flowchart LR
A[Advisor review trigger] --> B[Session fork runtime]
B --> C[Model provider]
C --> D[Normalized usage]
D --> E[Advisor Gateway log]
Technical reviewBest possible solution: Retain the existing logging-field addition and the qualified explanation without changing fork cache identity. Do we have a high-confidence way to reproduce the issue? Source confirms that session forks return cacheWriteTokens while current-main Advisor logging omits it; no target code was executed. Is this the best way to solve the issue? Adding the available field at the existing logging owner is the smallest complete fix, and the revised documentation correctly conditions cache-write reporting on provider usage. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 920338823f7b. Provenance checked
TestingProof path: unit tests only. SecurityNone. EvidenceWhat I checked:
PR surfaceSource 0, Docs +3. Total +3 across 2 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed November 10, 2026, 10:05 AM ET / 15:05 UTC (Revision 2). |
Co-authored-by: obviyus <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
* fix(advisor): log review cache writes Review usage logged input, cache reads and output but not cache writes. On OpenAI routes a review that misses the prompt cache reports its whole forked context as cache writes, so the log showed input=75 cacheRead=0 and looked like a review that saw no conversation. Co-authored-by: obviyus <[email protected]> * docs(advisor): qualify cache-write reporting by provider usage Co-authored-by: obviyus <[email protected]> --------- Co-authored-by: obviyus <[email protected]>
What Problem This Solves
Advisor's review usage log omits cache writes. On the team Gateway (OpenAI
gpt-6.1-solroute), 46 of 205 reviews since this morning logged:That reads like a review that saw no conversation. The same sessions' normal turns show about 200k cached prompt tokens, and the review prompt alone is about 1,400 characters.
Why
mapResponsesTerminalUsagesubtracts bothcached_tokensandcache_write_tokensfrom OpenAI'sinput_tokens. A review that misses the provider cache therefore reports its forked context ascacheWrite. The plugin already receivescacheWriteTokens(LlmCompleteUsage) but didn't log it.Misses happen because reviews omit the conversation's prompt-cache key by design since #182844 (forks rebuild context independently). On OpenAI that makes cache affinity best-effort:
cacheRead=0)openai/gpt-6.1-solChange
cacheWritewith the other review usage fields.No behavior change. Whether to restore cache affinity for forks is left as a separate decision.
Evidence
packages/ai/src/providers/openai-responses-terminal-usage.tsandsrc/gateway/server-plugin-subagent-runtime.ts(cacheWriteTokens: value.cacheWrite).cacheWritevalue on a miss. This change is what makes that visible. I'll confirm on the next team release.extensions/advisortests (10) pass; oxlint and oxfmt clean.