fix(core): preserve managed memory during microcompaction - #6714
Conversation
|
Thanks for the PR! Template looks good ✓ — all required sections present, bilingual description included. Problem: Observed bug with clear reproduction in #6713. Managed-memory topic files loaded via Direction: Aligned. Memory content that the model has already loaded should survive microcompaction — it's durable guidance, not ephemeral tool output. Full compaction remaining lossy is the right boundary. No direct CHANGELOG reference, but this falls squarely within the Size: Core paths touched — 139 production logic lines (client.ts: 9, geminiChat.ts: 9, paths.ts: 27, memoryPressureMonitor.ts: 25, microcompact.ts: 69). Well under the 500-line threshold. 301 test lines + 99 docs lines. Approach: The callback-predicate design ( Moving on to code review. 🔍 中文说明感谢贡献! 模板完整 ✓ — 所有必要章节齐全,包含双语描述。 问题: #6713 中有明确复现的已观测 bug。通过 方向: 对齐。模型已加载的记忆内容应该在微压缩中存活——这是持久指导,不是临时工具输出。完整压缩仍然有损是正确的边界。CHANGELOG 无直接参考,但属于 规模: 触及核心路径 — 139 行生产逻辑(client.ts: 9, geminiChat.ts: 9, paths.ts: 27, memoryPressureMonitor.ts: 25, microcompact.ts: 69)。远低于 500 行阈值。301 行测试 + 99 行文档。 方案: 回调谓词设计( 进入代码审查 🔍 — Qwen Code · qwen3.7-max |
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
No review findings. Downgraded from Approve to Comment: CI checks still pending.
— qwen3.7-max via Qwen Code /review
2a. Code ReviewIndependent proposal (before reading the diff): Comparison with PR:
Reuse check: No critical issues found. The code is focused, follows project conventions (ESM, no 2b. Real-Scenario TestingRan all 3 related test suites in tmux: TypeScript typecheck ( New tests cover: idle/forced/size-based preservation, mixed protected+compactable results, ambiguous call IDs, error responses, symlink escapes, size overage with only protected memory, and protected memory not counting against the recent-result budget. 中文说明2a. 代码审查独立方案(读 diff 前): 在 与 PR 对比: PR 方案完全匹配。实现干净且遵循现有模式:
无关键问题。 代码聚焦,遵循项目约定,边界情况处理到位。 2b. 实际场景测试在 tmux 中运行了全部 3 个相关测试套件:145 个测试全部通过。TypeScript 类型检查通过,无错误。 — Qwen Code · qwen3.7-max |
|
This PR solves a real, well-documented bug (#6713) with a focused, minimal change. The callback-predicate approach is the right level of abstraction — it extends the existing microcompaction pipeline without restructuring it, and all three production callers are wired consistently. The test suite is thorough: 7 new test cases covering the preservation semantics across all trigger paths (idle, forced, size-based), edge cases (ambiguous call IDs, error responses, symlink escapes), and the interaction with the recent-result budget. All 145 tests across the 3 affected files pass, and typecheck is clean. The tradeoff — managed-memory reads consuming tokens until full compaction — is acknowledged in the PR description and is the right call: durable guidance matters more than reclaiming those tokens when full compaction remains available as the hard cap. No concerns. Approving. 中文说明这个 PR 用聚焦且最小的改动解决了一个真实的、有详细记录的 bug(#6713)。回调谓词方案是正确的抽象层次——扩展了现有微压缩管道而没有重构,三个生产调用者一致接入。 测试套件全面:7 个新测试用例覆盖所有触发路径(idle、forced、size-based)下的保留语义、边界情况(模糊 call ID、错误响应、符号链接逃逸)以及与最近结果预算的交互。3 个受影响文件的 145 个测试全部通过,类型检查干净。 取舍——managed-memory 读取在完整压缩前占用 token——在 PR 描述中有说明且是正确选择:持久指导比回收这些 token 更重要,而完整压缩仍可作为硬上限。 无顾虑。通过。 — Qwen Code · qwen3.7-max |
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
LGTM, looks ready to ship. ✅
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
Reviewed — no blockers. Suggestions are inline.
|
本轮只处理 PR 目标内的 bug/CI/回归问题。这 3 条 review 建议分别涉及缓存 managed memory root realpath、抽取 preserve predicate factory、复用 microcompaction callId map,都是性能/抽象方向的改进建议;当前 CI 已通过且没有证据表明它们是本 PR 引入的 correctness 问题。按自动化的最小修复边界,本轮不扩大 PR 实现,作为后续优化方向处理。 |
wenshao
left a comment
There was a problem hiding this comment.
Reviewed — no blockers. Suggestions are inline.
Local Tmux verificationI ran a real interactive verification on Scenario
Observed resultQwen's debug log recorded: The request sent after microcompaction contained:
The final TUI output was: Coverage
Full compaction and ordinary historical tool-result retention remain unchanged by design and are outside this PR's scope. |
✅ Maintainer local verification — recommended for mergeI built this PR locally from a clean worktree and verified it end-to-end. The change does exactly what it claims: a Environment: local build · macOS 24.6 · Node v22.23.1 · 1. Behavioral proof (the important part)Instead of the unit tests' synthetic
I also ran a before/after differential on the PR's own suite: reverting only the production 2. Test & quality evidence
3. Notes for reviewers
Verdict: functionally correct, well-tested, no regressions observed locally. 👍 🇨🇳 中文说明(点击展开)✅ 维护者本地验证 —— 建议合并我在干净的 worktree 中从头构建了本 PR 并做了端到端验证。改动完全符合描述:managed-memory 文件的 环境: 本地构建 · macOS 24.6 · Node v22.23.1 · 1. 行为验证(重点)我没有用单测里合成的
我还对 PR 自带的测试做了前后差分:只把生产代码 2. 测试与质量证据
3. 给 reviewer 的说明
结论: 功能正确、测试充分、本地未见回归。👍 Verification screenshots are real terminal output from the local run, hosted on branch |
|
本轮按 review comments 做了最小 closeout:
验证: |
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
Reviewed — no blockers. Suggestions are inline.
|
@qwen-code /triage |
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
LGTM, looks ready to ship. ✅
|
Reviewed the remaining suggestion-only threads. I am not changing code for these in this PR because they are cleanup/future-proofing suggestions rather than bugs, CI failures, or behavior gaps in the managed-memory preservation fix:
|




What this PR does
This PR keeps successful managed-memory
read_fileresults available across idle, size-based,/compress-fast, and memory-pressure microcompaction. It recognizes project, user, and team memory through realpath-aware containment checks, while ordinary tool results continue to be compacted normally.Why it's needed
Managed-memory topic files are loaded lazily through
read_file. Before this change, their content was replaced with[Old tool result content cleared]after leaving the recent-result window. The model could then silently lose durable guidance it had already loaded.Reviewer Test Plan
How to verify
Read a managed-memory topic file, trigger microcompaction with enough later tool calls, and then ask the model to use a unique value from that memory without reading the file again. Ordinary old tool results should be cleared, while the managed-memory content should remain available.
Evidence (Before & After)
Before: the memory marker disappeared from the final API request, and the model reported that it needed to read the file again.
After: ordinary old tool results are still cleared, but the complete managed-memory Markdown and marker remain in the request. The model outputs
ORIOLE-6487-VERIFY-SURVIVESwithout re-reading the file.Tested on
Environment (optional)
Local
node dist/cli.jsbundle using API Config, withtoolResultsTotalCharsThreshold: 1andtoolResultsNumToKeep: 1to force the size-based microcompaction path.Risk & Scope
/rememberis handled separately by fix(memory): refresh instructions after remember #6497.Linked Issues
Fixes #6713
Refs #6487
中文说明
这个 PR 做了什么
这个 PR 会在 idle、size-based、
/compress-fast和 memory-pressure microcompaction 中保留成功读取的 managed-memory 内容。路径识别覆盖 project、user 和 team memory,并使用 realpath containment check;普通工具结果仍会正常压缩。为什么需要
managed-memory topic 通过
read_file按需加载。修改前,内容移出 recent-result 窗口后会被替换为[Old tool result content cleared],导致模型静默丢失已经加载的持久指导。Reviewer Test Plan
读取 managed-memory topic,执行足够多的后续工具调用触发 microcompaction,然后要求模型在不重新读取文件的情况下使用其中的唯一值。预期普通旧工具结果被清除,但 managed-memory 内容保持可用。
Before:memory marker 从最终 API 请求中消失,模型表示需要重新读取文件。
After:普通旧工具结果仍被清除,但 managed-memory 的完整 Markdown 和 marker 保留,模型无需重新读取即可输出
ORIOLE-6487-VERIFY-SURVIVES。风险和范围
/remember后索引过期由 fix(memory): refresh instructions after remember #6497 处理。