fix(kiro): keep unreported cache counters unknown instead of zero (#4546) - #4588
Conversation
) Kiro coerced an absent cacheReadInputTokens or cacheWriteInputTokens to 0 and then recorded it as a measured value. Every other usage path omits what it has no reading for, and cacheHitRate is null when unobserved, so this was the one place a silent provider looked like a total cache miss - the exact signal needed to tell whether a routing change preserved the prompt cache. Absence is now unknown; a malformed counter is still a malformed event, and the bridge wire still emits its zero default for strict clients.
|
✅ Deterministic PR hygiene checks passed. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe Kiro adapter now preserves absent cache-token counters as unknown. It still rejects malformed reported counters. New stream tests cover both behaviors. ChangesKiro token usage
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~15 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to The change preserves unknown cache usage, validates reported counters, and maintains the existing bridge output contract. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e9b5e10cc2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const cacheRead = optionalTokenCount(eventType, usage, "cacheReadInputTokens"); | ||
| const cacheWrite = optionalTokenCount(eventType, usage, "cacheWriteInputTokens"); |
There was a problem hiding this comment.
Synchronize the owned adapter documentation
This changes src/adapters/kiro-events.ts's usage-event contract from measured zeroes to omitted cache counters, but the commit leaves every structure document mapped to src/adapters/ unchanged. That leaves the repository's architecture source of truth without the new Kiro telemetry invariant; update the applicable owned documentation and its coverage reference in the same change.
AGENTS.md reference: src/AGENTS.md:L11-L11
Useful? React with 👍 / 👎.
리뷰 · 우선순위 68 / 80지금 이 PR( 라인 - 경로/심볼 - 경로/심볼 - Verification이 로컬 스위트·타입체크·install을 안 돌렸다고 명시합니다. 이 시각 기준 hygiene/changes/gates/docker/keyring/api usage/storage 등은 초록이고, test 샤드·macos·npm-global macos는 pending입니다. 머지 증거는 이 헤드 SHA의 호스트 CI 전부 초록뿐입니다. 회귀 핀은 위 두 테스트에 있습니다. 메인테이너의 판단이 필요한 지점
너의 추천 이 댓글은 grok-bot이 작성했습니다 |
Summary
Kiro coerced an absent
cacheReadInputTokensorcacheWriteInputTokensto0and then recorded it as a measured value, so a turn where the provider reported nothing about caching was indistinguishable from a turn that missed the cache entirely.That distinction is the one needed to tell whether a routing change preserved a prompt cache. It is also the only place this happened:
OcxUsageomits cache fields it has no reading for, andcacheHitRateisnullwhen unobserved, so every other path already keeps unknown as unknown. #4546 had to be diagnosed from a token bill rather than a dashboard, and this is one of the reasons the dashboard could not have shown it.Absence is now unknown. A malformed counter is still a malformed event — only a missing key is unknown — and an unreported counter still contributes nothing to
inputTokens, which is a different statement from claiming it was measured as zero.The wire contract is unchanged.
responsesUsageinsrc/bridge.tsstill emitscached_tokenswith its zero default, which is deliberate and load-bearing: strict Responses clients deserializeinput_tokens_detailsas a required field, and omitting it turns a successful turn into a hard exit afterresponse.completed. This changes what OpenCodex records, not what it sends.Follow-on to #4580, from the same plan unit
devlog/_plan/260914_cost_guard_stabilization/(see080_codex_cache_reinforcement.md).Verification
tests/providers/kiro/kiro-stream.test.ts: atokenUsagepayload with no cache keys leaves all three cache fields absent whileinputTokensstays correct, and a negativecacheReadInputTokensstill throws. The existing "authoritative metadata token usage overrides estimates and preserves cache splits" case, which reports cache fields explicitly, is unchanged and still asserts exact values.Checklist
Summary by CodeRabbit