Last week I wrote about the trust-and-cost side of DeepSeeker-Code — the ledger, the budget caps, the night shift (part one). A reader then asked a sharp question: the batch runner gives every task its own git worktree, and tool results embed absolute paths — doesn't that break prompt caching across tasks, since cache hits need byte-identical prefixes?

I knew the answer, because I had run the experiments in September and never published them. And the answer is more interesting than the question: the prompt cache is not a byte-prefix you can bisect. It's block-granular — and one wrong byte inside the block costs you the whole block.

That one measured fact explains half the "caching ghosts" I had been chasing. Here are the four experiments, with real numbers.

The agent keeps full traces of every run. Each request logs fingerprints — sysHash (sha1 of the system message), toolsHash (sha1 of the tool specs), sumHash (summary slot) — and each response records the raw usage the API returned: prompt tokens and cache-hit tokens, as reported, not derived. A test script drives the real agent loop with the full 44-tool table against the real API. No mocks. Fresh process, fresh session, every run.

R1 — baseline. Re-run the same prompt minutes apart in a brand-new process: first-round hit 99.8% (11,264 of 11,285 prompt tokens). One number, two conclusions: the vendor's cache persists across sessions and processes, and it is byte-exact — when the prefix really is byte-identical.

Byte-level intuition says: a change at the tail of the prefix should only invalidate the tail. Change ~100 bytes at byte ~11,000 and you'd expect most of the cached prefix to survive.

R4 flips exactly that: one fence inside the system prompt — the language rule ("reply in Chinese" vs "reply in English") — roughly 100 bytes at the tail of message[0]. Same question, same everything else.

Measured first-round hit: 0%. Not 75%. Not "the part after the divergence". The entire block died and was re-prefilled at full price.

R2 locates the boundary. Same project, different question: hit = 11,264 exactly — the whole block — and the miss is ~19 tokens: just the user message. So the first cacheable unit ends right after the summary slot, and the task text lives beyond it. (Side finding: tools are serialized into the request before the messages — the block includes them.)

R3 changes the project directory entirely: fingerprints byte-identical, 99.8% again. The directory is not, by itself, a divergence source — in this harness, project state enters the prefix only through injected indexes (memory, skills), which is the next section's story.

For scale: the fixed prefix is ≈12.7K real tokens per fresh session, ~9.4K of which is tool schemas (44 tools). The first cacheable block is ≈11.3K tokens: tools + system prompt + summary slot, as one unit.

Once you accept "a byte inside the block is worth as much as the whole block", several ghosts get names:

Real-world fresh sessions hit ~15%, not 99.8%. Six weeks of traces settled it: toolsHash was constant, sysHash differed every session — the injected indexes (memory index, skills list) drift across sessions, and any drift inside the block kills it. The shared head shrank to ~2K tokens. Cost came out to ≈¥0.02 per session, which I judged structural and left alone — but at least it had a name.

The silent-killer list. Language/output-style switches (user-initiated, rare — acceptable). Skills/agents directory updates — readdir order used to flip bytes; sort-deterministic injection fixed it. MCP servers connecting or disconnecting (tool table change = new block). Env-gated tools flipping. Memory-index drift. And compaction rewriting history — the biggest single collapse I've measured: one compaction event, −163K tokens re-prefilled, next-round hit 12.8%. Making compaction cache-aware (timing it by hit rate) beat every compaction-efficiency trick I tried.

The parallel-worker trap. N concurrent agents with byte-identical fingerprints still miss each other: cache writes take seconds to become visible. Parallel same-hash workers measured 0–14% mutual hits; the identical chain run serially hits 95–98%. If you fan out N workers, budget N full-price first rounds.

Historical reasoning. Assistant reasoning_content was 25–29% of resent input across turns. Stripping it entirely on the wire keeps the prefix byte-stable; keeping "just the latest turn" would flip bytes every turn and kill the block. (Verify against your provider before copying this one.)

Back to the reader's question. No — because of where the divergence sits.

Each batch task is a fresh conversation whose first user message — the task description — differs from every other task's. That is the first divergence, and it sits below the fixed block. The block itself is byte-stable by construction (templated system prompt, machine-constant paths, session-frozen injections), and serial runs hit 95–98% on it. Everything the worktree path strings would pollute — tool results — lies below the first divergence: the region that never hits across tasks anyway, because the task texts differ first. Within a task, the path is constant.

So a fixed-path mount would buy ≈0 in this design. It only starts paying if tasks share large identical prompts, which batch tickets never do. Sometimes the loss is bounded not because you fixed something, but because of where the divergence point sits.

Record the raw hit/miss fields per request. Don't derive them from totals: caching is block-quantized, so a short tail after the last block boundary never caches, and a derived metric happily reads it as normal input. Raw fields plus fingerprints are what let me bisect every anomaly to a specific cause.

Audit cost with real billing weights. Cache-hit tokens cost roughly 10× less than misses; an aggregate console number cannot tell you which turn burned the money. That's the ledger half — part one.

The whole thing is one open-source repo — DeepSeeker-Code — VS Code extension, terminal CLI, and local API sharing one engine. If you build agents on DeepSeek, the two posts together are the complete playbook: know what it costs, know why the cache dies, and instrument the raw numbers before you optimize anything.

原文来源:dev.to