🍑 桃儿
🎮 训练
🚴 运动
📊 周报
📝 笔记
✏️ Openclaw Cache Hit Issue
💾 保存
🗑 删除
👁 预览
← 返回
# OpenClaw DeepSeek Cache Hit Rate Issue **Date:** 2026-06-25 **OpenClaw version:** 2026.6.5 (5181e4f) **Model:** deepseek-v4-pro (1000k ctx) ## Symptom In long conversational sessions (>50 turns), DeepSeek KV cache hit rate alternates between ~20% and ~99% on consecutive API calls within the same user message turn. - Full-turn calls (user message processing): **~20%** cache hit — only ~27k tokens (system prompt) cached, 100k+ conversation history misses - Tool-continuation calls: **~99%** cache hit — full history cached Overall session cache hit: ~51%, wasting ~15M input tokens (~$27). ## Root Cause (Code Trace) `/opt/homebrew/lib/node_modules/openclaw/dist/run-attempt-DXkrH0fF.js` Line 201-207: Turn-scoped workspace developer context files: ```javascript const CODEX_TURN_SCOPED_WORKSPACE_DEVELOPER_CONTEXT_BASENAMES = new Set([ "identity.md", "soul.md", "user.md" ]); ``` Line 318: These files are selectively loaded per turn: ```javascript const turnScopedDeveloperInstructionFiles = shouldInjectCodexOpenClawPromptContext(params.params) ? selectCodexWorkspaceTurnScopedDeveloperInstructionFiles(contextFiles) : []; ``` Line 8250-8256: Turn collaboration developer instructions are built differently for full turns vs tool-continuation turns: ```javascript const buildCodexTurnCollaborationDeveloperInstructions = () => buildTurnCollaborationMode(params, { turnScopedDeveloperInstructions: workspaceBootstrapContext.turnScopedDeveloperInstructions, ... }).settings.developer_instructions ?? void 0; const buildRenderedCodexDeveloperInstructions = () => joinPresentSections(promptBuild.developerInstructions, buildCodexTurnCollaborationDeveloperInstructions()); ``` **Mechanism:** The developer instructions (containing SOUL.md, IDENTITY.md, USER.md) are injected at the FRONT of the messages array differently between full-turn calls and tool-continuation calls. This creates two different message prefixes, so DeepSeek's KV cache can never serve the full conversation history on full-turn calls. A full-turn call writes cache entry for prefix [dev_instr_v1, system, history...]. The subsequent tool-continuation call matches this prefix (99% hit). But the NEXT full-turn call has a different dev_instr_v2 → prefix mismatch → 20% hit. ## Impact - ~15M wasted input tokens per long session - ~$27 unnecessary cost at DeepSeek rates - Extended latency for every user message (full context re-computation) ## Session Data Session ID: bb84ac8e-55f3-4024-acac-d5bd7f60d242 Key: agent:main:telegram:direct:1128617346 Turns: 340, Total input: 28M, Cached: 43M, Hit rate: 50.98% Detailed turn-by-turn analysis available in session file: ~/.openclaw/agents/main/sessions/bb84ac8e-55f3-4024-acac-d5bd7f60d242.jsonl