Repository navigation
Conversation
…ult threshold Drive real turns up to the default auto-compaction threshold with a provider that meters the full request, for 128k, 256k, 1M and 2M windows and for manual and auto triggers, and assert the compaction request extends the last turn request's prompt-cache prefix. A second round also asserts the previous compaction summary is still sent.
- keep the system prompt, tools and request params stable across context revisions for the same model - accept a tool table change only when the tool registry or the active tool names changed - flag a first compaction request that drops history although the full request plus the output reserve fits the context window, unless the provider already rejected the context - require every operation request kind to declare whether it shares the turn prefix Add self-tests for each rule and a resume scenario that starts the first request after a resume as a prefix extension of the last one.
…alization Assert that undo keeps everything before the undone turn as the next request's prefix, and that the openai, kimi and anthropic requesters serialize each request body as a prefix extension of the previous one.
|
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
Requirement or Bug
用测试拦住不合理的 prompt cache miss。起因是 compaction 在默认触发点裁掉历史开头、导致 cache 失效这一反馈。
Bug Reproduction Steps
本 PR 新增的
FullCompaction prompt-cache prefix用例可以在 main 上稳定复现。Root Cause
两层原因:
0.85 × (W − min(128Ki, W/8)) − 开销,约为 74% 窗口,低于默认自动触发点(85% 窗口或W − 50k)。所以在约 196k 以上的窗口里,常规的自动和手动 compaction 都会裁掉历史开头。本 PR 不修引擎,引擎修复在另一个 PR 里做。test/harness/prompt-cache-guard.ts对所有带裁剪的 compaction 请求、所有 context revision 变化、所有工具名集合变化都直接豁免,正好覆盖了这个 bug 所在的路径;同时没有任何用例让上下文达到默认触发点。本 PR 修的是这一层。Code Changes
收紧前,先在 guard 里临时插桩,跑了一遍 agent-core-v2 全量(7460 个用例),统计每一次豁免。下表是收紧的依据:
activeToolNames确实变了才放行droppedCount ≠ 0就整体跳过direct_testPREFIX_SHARING_OPERATIONS或INDEPENDENT_OPERATIONSR4 的判定也是引擎修复需要满足的约定:
文件变化:
packages/agent-core-v2/ ├── test/harness/ │ └── prompt-cache-guard.ts # R2–R5,导出 takePromptCacheViolations() 供自测使用 ├── test/agent/fullCompaction/ │ └── fullCompaction.test.ts # +10:默认触发点 × 128k/256k/1M/2M × manual/auto,以及连续两轮 ├── test/agent/llmRequester/ │ └── llmRequester.test.ts # +10 guard 自测(每条规则一正一反),+1 resume 场景 ├── test/agent/undo/ │ └── undo.test.ts # +1:undo 之前的历史仍是下一次请求的前缀 └── src/human/test/llm/ └── cache-key.test.ts # +3:openai / kimi / anthropic 序列化后的 body 逐个请求保持前缀延伸RuntimeCompactionStrategy,全程走真实 turn。reasoning_effort: 'medium',请求参数会因此变一次。kimi 和 anthropic 不受影响。是否要改留给后续讨论。合入顺序:在当前 main 上有 13 个预期内的失败,全部是上述 bug 的实例,必须和引擎修复一起合入,或在它之后合入:
FullCompaction prompt-cache prefix复现用例FullCompaction pre-shrink用例,它们把"放得下也裁"当成了预期,需要随修复更新FullCompaction > recovers from plain 413 when estimated request is over effective max:在任何 413 之前就主动裁剪了Behavior Changes and Affected Users
运行时行为:None。只改了
test/和src/human/test/下的测试与 harness,没有改任何运行时代码、默认值或契约文件(config/wire/state manifest、apiSurface 快照、node-sdk 入口、apps/kimi-code/src/cli/都没动)。受影响的只有在 agent-core-v2 里写测试的贡献者:
direct_test,已声明)测试覆盖:每一行都有
llmRequester.test.ts > prompt-cache guard里对应的自测。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.