C.W.K.
Stream
Lesson 05 of 05 · published

Cache Hit과 Hidden State 탐지

~24 min · cache, telemetry, probing

Level 0Window Watcher
0 XP0/50 lessons0/13 achievements
0/100 XP to next level100 XP to go0% complete

Cache state는 운영 state

Provider가 cache hit metric 노출하면 first-class telemetry로 다뤄. Cache-friendly라 생각한 워크플로가 silently 매 turn prefix 재구축할 수도 — cost graph가 알려주지만 log해야만. Cache hit ratio는 cost와 behavioral consistency 둘 다의 leading indicator.

의도적으로 cache probe

같은 prefix를 짧게 두 번 보내; 두 번째가 cache hit 보고하나 check. Prefix 1 byte 바꿔 보내; cache miss하나 check. 5분 test가 caching 전략이 의도대로 작동하는지 드러내.

Hidden state는 cache와 replay에 산다

'Mysterious'한 모형 behavior가 cache state 추적 — 이전 실험 prefix가 아직 warm해서 답 bias. Cold-restart session, force-bust cache(prefix 1 byte 변경), behavior 지속하나 봐. No면 버그가 hidden cache state, 모형 X.

Code

Telemetry 안 cache hit ratio·python
def cache_hit_ratio(usage):
    fresh = usage.input_tokens - getattr(usage, "cache_read_input_tokens", 0)
    cached = getattr(usage, "cache_read_input_tokens", 0)
    total = fresh + cached
    return cached / total if total else 0.0

if cache_hit_ratio(response.usage) < 0.3 and prefix_should_have_hit:
    log_cache_miss_anomaly(response)
Probe sequence·text
1. Send prefix P + question Q1. Record cached_tokens.
2. Send prefix P + question Q2 (same P). Expect cached_tokens > 0 on second call.
3. Send prefix P' (P with one byte changed) + question Q3. Expect cached_tokens = 0.
If step 2 shows no hit, your prefix is not actually byte-stable -> hunt the cache buster.

External links

Exercise

실제 워크플로 하나에서 연속 10 request에 turn당 cache hit ratio log. 50% 이하인데 high reuse 기대했으면, probe sequence 돌려 cache buster 찾아.
Hint
흔한 buster: timestamp, request id, unsorted JSON key, 재생성된 tool schema.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.