fix: 修复 lastCacheSafeParams 跨会话残留导致 post-turn fork 上下文污染#1304
Merged
claude-code-best merged 1 commit intoJul 20, 2026
Merged
Conversation
全局槽 lastCacheSafeParams 从不清空,/clear(regenerateSessionId)与进程内 /resume(switchSession)后残留旧会话完整历史,会被 /recap、SDK side_question/promptSuggestion 拼进发给 API 的请求前缀,导致回复引用另一段 对话。 - 槽迁到 src/utils/cacheSafeParamsSlot.ts:保存时记 sessionId,读取时不匹配 则自愈清空并释放旧消息数组 - clearConversation 显式 saveCacheSafeParams(null) 立即释放内存 - 迁移四处调用点 import(stopHooks/print/btw/generateRecap) - biome.json 排除 dist-stable 构建产物快照,避免 precheck 扫描改写 - 新增 8 个单测,用真实 regenerateSessionId/switchSession 复现两条路径 Co-Authored-By: claude-fable-5 <noreply@anthropic.com>
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (9)
📝 WalkthroughWalkthroughChangesCache-safe parameter lifecycle
Biome path exclusion
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
整体修复的起因是我在实际使用上遇到了输出信息与输入信息不一致的问题,排查的思路分两个方向:
我目前在采用mitmproxy抓包API信息排查第一种情况,(从token消耗量上来看,第一种可能性较大,尽管这有些不合常理,毕竟Anthropic这么大的公司)同时也在看harness层的一些问题。
以下为发现的一些问题,对应改动以及可复现单测(这里确实是存在一些问题,不过个人评估与上面的问题并不完全rootcase):
全局槽 lastCacheSafeParams 从不清空,/clear(regenerateSessionId)与进程内 /resume(switchSession)后残留旧会话完整历史,会被 /recap、SDK
side_question/promptSuggestion 拼进发给 API 的请求前缀,导致回复引用另一段 对话。
Summary by CodeRabbit
Bug Fixes
Tests
Chores