Repository navigation
fix(cache): 修复热缓存误判冷、断点落在 reminder,删除 cache_edits/scope - #429
Merged
Merged
Conversation
- 冷热判定:provider 出口记录请求发出时刻(api/cache-warmth.ts),距上次 ≥1h 才算冷, 不知道按热。旧 LoopState.lastResponseAt 每条用户消息重建,首轮必判冷(回放 60 次/41 会话) - 冷清理落成 ContextManager 会话状态,之后每轮逐字节重放;在 getCleanedMessages 之前执行, BeforeModel/raw.jsonl/prefix_break 看到的就是真实发送前缀 - reminder 块带 transient 标记,messages 区断点打在第一个 transient 之前(回放 13% 请求断点白写) - 删除 cached-microcompact 状态机与 cache_edits(非公开字段,无法验证效果) - 删除 cache_control.scope=global(公开 API 无此字段,且未配 beta 头) - 新增 PromptCacheLayout / ColdCacheClear 事件与 digest 聚合 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
njfuzrs
enabled auto-merge
October 24, 2026 06:10
…HE_EDITS 本 PR 删除了 cache_edits 与 global scope,这两个变量在源码里已无读取点, help 里仍保留导致 tests/scripts/help-env-consumers.test.ts 红。同步删除并重新生成 website/ref/env.md。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改了什么
修复 Context 文档 §6 列出的 5 个 prompt cache 问题,并补上对应的可观测性。
api/cache-warmth.ts,在 Anthropic provider 出口记录请求发出时刻,进程级保存。距上次 ≥1h(最长可能 TTL)才判冷,不知道就按热。ContextManager.applyColdCacheClear(),决策写进会话状态,之后每轮逐字节重放。它在getCleanedMessages之前执行,所以 BeforeModel、raw.jsonl、prefix_break 看到的就是真实发出的前缀。transient标记(不上线),messages 区断点打在第一个 transient 块之前。cached-microcompact.ts状态机及全部接线、notifyCacheDeletion。cache_control.scope=global。PromptCacheLayout和ColdCacheClear事件,trace/digest.ts做聚合。为什么
本机轨迹回放(411 个会话,10-04 到 10-23):
LoopState.lastResponseAt每条用户消息都会重建。cache_edits不是公开 Messages API 字段,网关静默接受,效果无法验证。scope不在公开 API 里,本仓也从未发过对应的 beta 头。取舍:阈值从 5min 改成 1h,会少清一些本地 token,换来不在热缓存上制造 miss。详见 Agent Note。
怎么验证的
bun run affected-tests:run:581 文件,7566 pass / 0 failmake build:自检通过,没有will always be undefined告警上线后的验收(需要真实流量):
ColdCacheClear.gap_ms < 1h的计数为 0;PromptCacheLayout.message_breakpoint_on_transient占比从 13% 降到 0。Agent Note:
.agents/notes/implemented/bug-fix/2026-10-24-prompt-cache冷热误判与断点落点修复.md🤖 Generated with Claude Code