CodeWhale icon indicating copy to clipboard operation
CodeWhale copied to clipboard

Improve prefix cache inspection and warmup

Open wplll opened this issue 6 months ago • 1 comments

Summary

Improve DeepSeek prefix-cache stability diagnostics and warmup correctness by making cache inspection and warmup keys account for real prompt layers, tool schemas, project context packs, and skills.

Motivation

Previous cache diagnostics could report incomplete or misleading cache state because /cache inspect did not include the real tool catalog, warmup keys depended on prior inspection state, and project context pack cache invalidation could miss prompt-relevant changes.

Changes

  • Include the real request tool catalog in /cache inspect.
  • Add tool_catalog_hash and stable_prefix_hash to prompt inspection output.
  • Add a complete CacheWarmupKey covering provider, model, base URL, stable prefix, tool catalog, project pack, and skills.
  • Compute warmup keys from current app/request state instead of last_cache_inspection.
  • Make Project Context Pack generation deterministic with sorted entries and sort-before-truncate behavior.
  • Improve Project Context Pack cache invalidation with a manifest hash covering included file paths and README excerpt content.
  • Skip wire-payload dedup for short tool results and keep dedup strictly wire-only.
  • Update memory documentation to describe memory/session goal content as dynamic.

Cache hit improvement rationale

The changes increase probability of prefix cache reuse by stabilizing prompt-layer ordering, tool catalog ordering, and Project Context Pack rendering. They also make cache misses more diagnosable by exposing stable prefix, full reusable prefix, tool catalog, project pack, and skills hashes.

Performance considerations

Project Context Pack generation now walks prompt-relevant entries to compute a reliable manifest hash, while reusing rendered packs when the manifest is unchanged. Short tool results bypass dedup hashing and map lookup entirely. Warmup does not introduce extra catalog/network requests beyond the explicit warmup model call.

Risks and rollback

Risk is limited to cache diagnostics, warmup behavior, project context pack rendering, and wire payload compaction. Rollback can revert the cache inspection/warmup and project pack changes independently if provider behavior differs in production.

Follow-up work

  • Optionally allow first-run /cache inspect to build the current tool catalog before any model turn.
  • Consider adding config file excerpts to Project Context Pack only if they are intentionally part of the prompt, with matching manifest hash coverage.

wplll avatar May 11 '26 20:05 wplll

Thanks for the contribution. I’m keeping the v0.8.33 branch focused on final release polish and not pulling this PR into that branch right now. Leaving it open for review in the next cycle.

Hmbown avatar May 13 '26 02:05 Hmbown

感谢你的分享。我现在把v0.8.33分支放在最终版本的润色上,暂时不把这个PR拉到那个分支。留给下一轮审查。

Excuse me, which version is expected to conduct the review of this PR

wplll avatar May 20 '26 08:05 wplll

This PR was opened before the v0.8.41 rebrand and is now stale. Feel free to rebase onto current main and reopen. 鲸鱼兄弟们等你 🐋

Hmbown avatar May 23 '26 21:05 Hmbown