Repository navigation
test(agent-core-v2): check that a resumed session sends every tool result as it did live - #5658
Conversation
…sult as it did live expectResumeMatches compares the engine state before and after a resume, and it drops reminders first. Two prompt cache bugs slipped past it, because the history a resumed session sends can differ from the live one while the state matches. The harness gains expectResumeSendsTheSameHistory, which also projects the next request's messages on both sides with the projection every request goes through and compares them. A new resume test registers tools that return results of many shapes (notes, errors, empty and multi-part output, truncation, an image, a crash, a wall-time tool and a denied tool, then a parallel batch) and checks the resume with it. Without the fixes from #5585 or #5640 the test fails. expectResumeMatches keeps its behavior for now: the new comparison still finds three divergences in existing cases (a parallel batch with a denied call is reordered, a tool call that failed before it started disappears, and an interruption reminder comes back after undoing every turn). Once they are fixed, expectResumeMatches will compare the next request too. The cache catalog lists the new test under A8 and A9.
|
Codex Review Summary: ✅ CompletedThis 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
恢复会话(重启、
/reload、重新载入)之后,第一个请求发给模型的历史必须和实时发出的一模一样,否则 prompt 缓存从第一处不同开始全部失效,用户看不到任何信号。最近修的两个缓存问题都属于这一类:#5585(被拒的工具恢复后多出Wall time)和 #5640(Write、Edit 的说明恢复后被拼成一段)。两次都是很晚才被偶然发现:已有的检查只比较恢复前后的引擎状态,不比较真正发出去的请求;而且只有测试作者想到的那几种工具结果才经过重启。这个 PR 在引擎测试里加一条通用检查:恢复后投影出的下一个请求,必须和实时投影出的一样。另外加一个工具结果矩阵,按结果类型的字段组合出各种形状(细节和没覆盖的字段见下文),而不是挑几个工具。它跑在每个 PR 都必过的 test 作业里。
Bug Reproduction Steps
N/A:只改测试。
Root Cause
N/A。
Code Changes
测试工具
packages/agent-core-v2/test/harness/agent.ts:project(),处理各自 loop 里的原始消息(previewRequestContent().messages,也就是请求实际用的那份)。packages/agent-core-v2/test/wire/resume.test.ts的「carries every kind of tool result exactly as the live session sent it」,用 testkit 的假模型。ExecutableToolResult的字段出发,所以以后新加的结果字段能直接加进表里,不依赖记得去测某个具体工具。这次没覆盖spill、spillExempt、stopTurn、stopTurnReason四个字段:stopTurn会结束回合,要单独一个用例;spill要真的写出落盘文件。tests/e2e/scenarios/cache/catalog.yaml的 A8、A9 各加一条引擎覆盖,指向这个用例。为什么新比较还不对所有调用方打开:
expectResumeMatches()已经被 31 个测试文件调用。把新比较加进去,有两条现有用例会失败,而且都是真问题。另外还有一个问题,这次的矩阵为了绕开它,改变了编排方式:tool.call)loop.test.ts「lets a loop error handler recover a non-context loop error by retrying」)loop.test.ts「keeps an interruption reminder when undo only removes a later turn」)这三处会另外修。修好之后,
expectResumeMatches()改成也做这项比较,所有调用方就都会检查;那两条现有用例,以及「并行批次里有被拒的调用」,就是它们的回归测试。这个 PR 里的矩阵因此把被拒的调用单独放成一步,并行批次里不放。阅读顺序:先看
agent.ts里的checkResume和nextRequestMessages,再看resume.test.ts里的矩阵(最后一个describe,后面是原有的辅助函数)。Behavior Changes and Affected Users
None:只改了测试工具、一个测试文件和缓存清单,产品代码没动。
expectResumeMatches()的行为不变,31 个调用它的测试文件结果不变。验证
基于 main
87058b908(#5585、#5640 都已合入)。packages/agent-core-v2/src/agent/contextMemory/toolResultRender.ts的修复临时打回去,矩阵在新的消息比较上失败,差异是"Wrote 8 bytes to out.txt"和说明被拼成一段;packages/agent-core-v2/src/agent/loop/turnProjection.ts的修复打回去,同一处比较失败,差异是被拒的工具多出Wall time: 0.000 seconds;pnpm exec vitest run --reporter=agent跑全部 31 个调用expectResumeMatches()的测试文件,加上新用例,共 1264 条通过。pnpm lint通过(包括test-doubles:新用例用 testkit 的假模型),pnpm exec tsc -p packages/agent-core-v2/tsconfig.json --noEmit通过,node --test 'scripts/checks/*.test.mjs'124 条通过,pnpm run check:duplication 87058b908没有新增重复。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.