Skip to content

Interview question · Context Engineering & Caching

Prompt cache hit rate dropped from 80% to 10% after a release. Find it.

Something in the release changed bytes near the front of the prompt. You find it by hashing the blocks of two consecutive requests and reading the first one that differs, not by reading the diff of the release.

hardEssentialNewUpdated Nov 2026

TL;DR: A collapse that large means almost every request now differs from the previous one early in the prompt. Confirm the metric first (cached input tokens over total input, per agent type and model, before and after the deploy). Then capture two consecutive requests from one run exactly as sent, hash each block (system prompt, each tool, each message) and find the first block that differs. That block names the cause, which is nearly always one of a short list: a timestamp or per-user field up front, tool order or filtering, serialization, a model or setting change, or edits to earlier messages.

How to approach it

Say what a cache hit needs (an identical prefix) and what the numbers imply: 10% cached means only a small fixed part, or nothing, still matches. Then work from evidence to cause rather than from the release notes to a guess, and finish with the guard that stops it recurring.

A strong answer

1. Check the metric is real. Was the change in caching or in measurement? Confirm the usage fields the dashboard reads still exist under the same names, and split the ratio by agent type, model and tenant. If one agent type collapsed and the others did not, the cause is in that agent's context assembly. If everything collapsed at once, suspect something shared: the SDK, the serializer, the model route.

2. Capture two consecutive requests. From one run, the exact bytes sent on turn n and turn n+1. With an append-only history, turn n+1 should begin with all of turn n. Comparing block by block is faster to read than a character diff:

import hashlib, json

def blocks(req):
    yield "system", req["system"]
    for t in req["tools"]:
        yield f"tool:{t['name']}", json.dumps(t, sort_keys=True)
    for i, m in enumerate(req["messages"]):
        yield f"msg:{i}", json.dumps(m, sort_keys=True)

def first_changed(prev, nxt):
    a, b = list(blocks(prev)), list(blocks(nxt))
    for (name_a, body_a), (name_b, body_b) in zip(a, b):
        if name_a != name_b:
            return f"order changed: {name_a} became {name_b}"
        if hashlib.sha256(body_a.encode()).digest() != \
           hashlib.sha256(body_b.encode()).digest():
            return f"content changed: {name_a}"
    return "no change in shared prefix"

tools = [{"name": "orders_get"}, {"name": "orders_cancel"}]
t1 = {"system": "Support agent. Today: 2026-11-23 10:05:13", "tools": tools,
      "messages": [{"role": "user", "content": "Cancel ord_004471"}]}
t2 = {"system": "Support agent. Today: 2026-11-23 10:05:41", "tools": tools,
      "messages": t1["messages"] + [{"role": "assistant", "content": "Checking."}]}
print(first_changed(t1, t2))  # => content changed: system

Here the first block differs, and the reason is in plain sight: the release added a timestamp with seconds to the system prompt. Every request now starts with different bytes, so nothing after it can be served from cache.

3. Match the block to a cause.

First changed blockLikely causeFix
systemTimestamp, user name, tenant or feature flag rendered into itMove dynamic values to the end; round dates to the day
tool order changedTools now built from a set or a dict with unstable order, or filtered per requestFixed order; stable core first, extras appended
tool contentSerializer upgrade, descriptions templated per userSorted keys, fixed separators; no per-user text in tools
an early messageRedaction, clearing or compaction now runs every turnBatch reductions at thresholds
nothing differsRequests went to a different model, region or settingCheck routing and settings; caches are per model

If two requests share every block but still miss, the cause is outside the bytes: a new model route, a changed cache setting, or a request rate so low that entries expire between turns.

4. Fix, verify, guard. Ship the fix, watch the ratio recover on the next deploy, and add a test that builds turn n and n+1 for a fixed scripted run and asserts the shared prefix is byte-identical. Keep the ratio on a dashboard with an alert; a cache regression shows up there days before it shows up in the bill.

What interviewers probe next

"How much did the incident cost?" Work it out from usage rather than guessing: the extra input tokens billed at full rate instead of the cached rate, over the hours it ran. A cached-to-uncached price ratio of about 10× is typical (check your provider's current price list), so a prefix-heavy agent can see input cost rise severalfold.

"Latency also went up. Related?" Yes. Cached prefixes are processed faster, so time to first token rises when hits disappear. It is a second signal for the same alert.

"The fix moves the timestamp to the end, but the product needs the agent to know the time." It still does; position does not change what the model can read. Put the time in the final user-turn context block, where it changes the least cached content.

How it's scored

Weak: Reads the release diff hoping to spot the cause, or blames the provider.

Hire: Knows a hit needs an identical prefix, compares two consecutive requests and finds a common breaker such as a timestamp.

Strong Hire: Validates and segments the metric first, compares requests block by block to locate the first divergence, maps it to cause and fix, covers the no-divergence case (model route, settings, expiry), and adds a byte-identical-prefix test and an alert.

Common mistakes

  • Diffing two requests from different runs, which differ for legitimate reasons.
  • Comparing pretty-printed requests rather than the exact bytes sent.
  • Fixing the symptom with a cache-warming job instead of the prefix.
  • No regression test, so the next release reintroduces it.
You just read a free answer. Every topic opens its first 5 answers to anyone. Sign in and the count per topic goes to 6, and the site remembers where you stopped in each one.Google sign-in · free · no payment details
HOW DID IT GO?
0
READING SIGNED OUT

Signing in raises your free answers from 5 to 6 per topic, adds an applied lesson in every topic and easy practice tests, and the site starts remembering you: mastery per topic, bookmarks, and a next-focus recommendation. Free, no card.

Sign in free
UP NEXT ON YOUR JOURNEY
DISCUSSION · 0

Nobody has commented. Post a correction or another way to answer.