fix: Codex 캐시 적중률 이중 카운팅 수정#102
Merged
soulduse merged 1 commit intosoulduse:mainfrom Apr 7, 2026
Merged
Conversation
OpenAI API의 input_tokens는 cached_input_tokens를 포함하는 반면, Anthropic API의 input_tokens는 캐시되지 않은 순수 입력만 포함합니다. 기존에는 이 차이를 고려하지 않고 동일한 공식으로 계산했기 때문에 Codex 쪽 캐�� 적중률이 이중 카운팅되어 실제(~90%)보다 훨씬 낮은 값(~48%)으로 표시되었습니다. 비용 계산(calculate_cost)에서는 이미 input - cached 처리를 하고 있었으나, 통계 집계(build_stats)에서는 누락되어 있었습니다. input_tokens 집계 시 cached_tokens를 차감하여 Claude/OpenCode와 동일한 의미(uncached-only)로 정규화합니다.
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.
목적
Codex 사용자가 캐시 적중률을 보고 "캐싱이 잘 안 되고 있나?" 하고 오해할 수 있는 문제를 해결합니다.
실제로는 90%로 잘 캐싱되고 있는데 48%로 표시되면, 불필요하게 프롬프트 구조를 바꾸거나 캐싱 최적화에 시간을 쓰게 됩니다.
또한 Claude + Codex를 함께 사용하는 경우 합산 적중률도 왜곡되어(96% -> 72%),
전체 사용 효율을 판단하는 데 혼란을 줍니다.
문제
제 문제의 경우에서 Codex(OpenAI) 소스의 캐시 적중률이 실제보다 낮게 표시됩니다.
원인
OpenAI API와 Anthropic API의
input_tokens의미가 다릅니다.input_tokens의미프론트엔드의 캐시 적중률 공식은
cache_read / (input_tokens + cache_read)인데,OpenAI 데이터에서는
input_tokens에 이미cached가 포함되어 있으므로분모에서 cached가 이중으로 카운팅됩니다.
비용 계산(
calculate_cost)에서는 이미input.saturating_sub(cached)로 처리하고 있었으나,통계 집계(
build_stats)에서는 이 정규화가 누락되어 있었습니다.수정 내용
build_stats()에서daily.input_tokens와mu.input_tokens집계 시entry.input_tokens.saturating_sub(entry.cached_tokens)를 사용하여Claude/OpenCode와 동일한 의미(uncached-only)로 정규화합니다.
영향 범위
CacheEfficiency컴포넌트의 캐시 적중률 도넛 차트statsHelpers.ts를 사용하는 Wrapped 카드useCombinedStats로 합산할 때의 aggregate 히트율model_usage기반 총 토큰 표시 (Header, WrappedCards 등)테스트
cargo test39개 전체 통과cargo check정상 (기존 warning만 존재)