-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(core): isolate fork cache readers by session #9471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wenshao
merged 4 commits into
QwenLM:main
from
tomsen02:fix/cache-safe-session-ownership
Aug 24, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7055fc3
fix(core): isolate fork cache readers by session
tomsen02 bd1babe
fix(core): skip foreign cache extraction
tomsen02 20bd886
perf(core): skip foreign cache before memory IO
tomsen02 955231f
test(core): provide session id in extraction fixture
tomsen02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] The fail-closed outcome of the session-scoped lookup is untested for both speculation readers. Every test in this file uses a mock that returns params unconditionally, and the new assertions only pin that the session id is passed — there is no case where
getCacheSafeParamsreturns null, so neither the throw instartSpeculationnor thereturn nullingeneratePipelinedSuggestionis exercised. The sibling readers pin the equivalent path (extractionAgentPlanner.test.ts"throws when getCacheSafeParams returns null",suggestionGenerator.test.tsforeign-slot fallback), but speculation does not.This matters in exactly the multi-session scenario this PR fixes: a future edit relaxing the null guard — for example falling back to an unscoped read to "fix" a speculation-not-starting report — would pass every test in this file green and silently reintroduce the cross-session fork. A mutation probe confirmed it: applying
getCacheSafeParams(config.getSessionId()) ?? getCacheSafeParams()here kept the suite 18/18 green while a contention probe showed the mutated code consuming the foreign snapshot past the guard; the same probe passes on the unmodified source.Add a test setting the mock to return null and asserting
startSpeculationrejects with 'CacheSafeParams not available for speculation' and neithercreateForkedChatnorrunForkedAgentis called, plus the analogous null case for the pipelined suggestion path:中文说明
两个推测(speculation)读取方的 fail-closed(会话校验失败返回 null)结果都没有测试覆盖。本文件中所有测试都使用无条件返回 params 的 mock,新增断言也只钉住了「传入了 session id」这一行为——没有任何用例让
getCacheSafeParams返回 null,因此startSpeculation的 throw 和generatePipelinedSuggestion的return null都不会被执行到。相邻的读取方钉住了等价路径(extractionAgentPlanner.test.ts的 "throws when getCacheSafeParams returns null"、suggestionGenerator.test.ts的外部 slot 回退),唯独 speculation 没有。这正是本 PR 修复的多 session 场景下的风险所在:未来若有人放宽 null 守卫——例如为了「修复」推测不启动的问题而回退到无 session 限定的读取——本文件的所有测试仍会全绿,跨 session fork 会被悄悄重新引入。变异探针证实了这一点:在此处应用
getCacheSafeParams(config.getSessionId()) ?? getCacheSafeParams()后,测试套件仍 18/18 全绿,而竞争探针显示变异后的代码越过守卫消费了外来快照;同一探针在未修改的源码上通过。建议新增一个测试:将 mock 设为返回 null,断言
startSpeculation以 'CacheSafeParams not available for speculation' 拒绝,且createForkedChat与runForkedAgent均未被调用;流水线推测路径也加类似的 null 用例。— qwen3.8-max via Qwen Code /review (v0.21.14)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in bd1babe. Added fail-closed coverage for both speculation readers: the initial null lookup now asserts rejection with zero forked-chat/agent calls, and a null second lookup completes speculation without producing a pipelined suggestion or calling the forked agent.