Repository navigation
[PR] fix: anchor pool-outside caches on the session graph (#2920) - #2932
ranxianglei wants to merge 5 commits into
Conversation
The plugin remembered-history Map and the seam-forensics WeakMaps lived outside the session object graph: an evicted session's history lingered until the next remember call, and diagnostic str/full strings were views/aliases pinning the full backing store of large outbound bodies while staying invisible to #2803's resident byte metering. Both caches now anchor on explicit in-memory-only Session fields (pluginRemembered / seamLastSent / seamLastSettled): eviction frees them with the session and the object-graph metering counts them. Retained strings are independent UTF-16 code-unit-faithful copies (lone surrogates survive; no utf8 round-trip) bounded by SEAM_BODY_CAP; SHA-256 still hashes the full original body. No disk/wire exposure, no kernel change, no new config. Behavior changes: - remembered views die at session eviction (previously lingered until the next remember call for any session). - outbound bodies above SEAM_BODY_CAP (512 KiB) no longer retain a full copy (previously up to the retired 8 MiB BODY_FULL_CAP): exact first-divergence byte offset (bl) and mid/head classification (bs) become unavailable for those bodies; digest equality (be) is unchanged. Closes #2920
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3272-pr.2932.02f3c7eThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2932.tgz
npm install -g packageInstall instructions are refreshed on each push. |
The heap A/B test spawns a fixed-heap child (pid-unique script under TMPDIR, no ports, no shared state) — concurrency-safe at c=4.
[bot] 🏷 PR 审查结论(#2932,agent 完成的工作 — 未重做,核对代码 + CI + 顺手修了两处小问题) 我做了什么:checkout 分支逐行核对了 diff 与 master 现状;定位到 CI 红的原因并直接在 PR 分支补了两个 commit( 结构化八问
测试有效性:4 项新测试断言有牙——孤立 surrogate 保真按 code unit 硬断言;cap 上下分歧分类给出精确期望值(bl=50_000 vs undefined);持久化隔离读真实落盘 JSON;heap A/B 带 sanity 断言先证明泄漏前提(旧式 ≥~16 MB 钉住)再验收新式 <old/3。能抓住回归,不是恒真测试。 CI 状态与我的修补:原 head 上 判定:可合——等 CI 全绿后由人合并(本 PR 跨 3 模块动 session 对象面,不在 auto-merge 范围内)。CI 结果出来我再跟一条。 |
Absolute Windows paths (D:\a\...) embedded as ESM import specifiers in the generated child script parse as a URL scheme and fail with ERR_UNSUPPORTED_ESM_URL_SCHEME; pathToFileURL() yields valid file:// URLs on both platforms.
[bot] 🏷 审查跟进:审查期间同机制实现 #2923 已合入 master,本 PR 建议关闭为 superseded(等你确认,未擅自关) 情况变化(最重要):我审查期间,overFloweee 的 PR #2923(同一来源 issue #2920,分支 两个实现的差异(我核对过的全部差异)
分支卫生问题(当前 CI 红的原因,必须披露):我在本分支推了三个修复 commit(
建议(待你拍板)
结构化八问(相对 floor 4 结论的增量,未变项从略引用)
判定变更:由 floor 4 的「CI 绿即可合」→ 「建议关闭(superseded by #2923)」,等你确认;8 MiB 带去留如需反转,走第 2 条 follow-up。 |
[bot] 🏷 冲突唤醒处理:不 rebase,说明原因(按「分支已无需合并则不硬救」条款) 冲突成因(已实测):master 合入 #2923( 为什么不 rebase/解冲突:
当前状态与请求:等待你对上一条的建议做决定——①关闭 #2932(superseded by #2923,推荐)→ 冲突自然消解;或 ②要我开 8 MiB 带删除的 follow-up PR → 我开新 PR,本分支随后关闭。在你回复前冲突状态保持 dirty 是预期内的,不是遗漏。 八问(本轮增量):1. 问题:PR 分支与 master 冲突(系统唤醒)。2. 原因:master 合并了同机制的 #2923,两套实现在同一批行上互斥。3. 影响:仅本 PR 的 mergeable 状态变 dirty,master 无影响(#2923 已独立绿合并)。4. 处置:不 rebase——解冲突等价于替 owner 单方面选定实现取舍;改为等你二选一。5. 回归:不涉及(未动任何代码)。6. 缓存:不涉及。7. 设计方向:不变。8. 新配置:不涉及。 判定:挂起等 owner 决定(关 PR / 开 delta follow-up),不硬救。 |
Closes #2920
问题
两条 pool 外强引用绕过会话生命周期与 #2803 的对象图字节计量:
src/plugin.ts模块级Map<string, RememberedMessages>:已淘汰 session 的 processed/original 历史要等下一次任意 remember 调用才被清理,会话淘汰本身不解除引用;src/cache-ledger.ts两个以 Session 为键的 WeakMap seam slot:str = body.slice(0, 512 KiB)的 SlicedString 钉住整个 backing store(issue 实测锚点:8 × 4 MiB 只留 512 KiB 头,GC 后仍 ~32 MiB),且 ≤8 MiB(旧 BODY_FULL_CAP)时full直接别名原 body —— 两者都不进对象图计量。修法
两类派生缓存移到 Session 的显式 transient 字段(
pluginRemembered/seamLastSent/seamLastSettled,均标注 in-memory only、buildRecord 不投影):sessionWeightObject.keys 递归遍历自动计入新字段(无需注册)。rememberPluginMessages对非驻留 id 变为 no-op(status/tool API 读端本就要求驻留 session,非驻留写没有读者);模块 map 的 staleSessionIds 清理循环删除(GC 取代)。行为变更(旧 → 新,必须披露)
验证
tests/issue2920-cache-lifecycle.test.ts(4 项全绿):88b1e507e,零冲突,未提交):_resetSessionsForTest(8, 4 MiB)下仅靠两个新缓存(~3 MiB)就撑爆预算的 session 被 makeResidentRoom 逐出为新会话腾位;同形状无缓存对照组不被逐出 —— resident byte budget 确实看到这些缓存。合并树上双方套件 16/16 全绿、typecheck 干净。config surface:不涉及(无新增配置/env/CLI)。