You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
折叠时按消息类型机械保真:opencode 子代理派发对的 seg id 由代码强制写入压缩块(#1563 根因修复) #1702
plugin 模式(opencode2)下折叠时刻 bili 同样持有折叠前原文:handlePluginTool(src/plugin.ts:899)读取 remembered 快照(remembered.get(session.id),由 rememberPluginMessages src/plugin.ts:276 在 forward 后写入,调用点 src/server.ts:2744),并作为 ctx.messages 传入 executeProxyTool(src/loop/core.ts:226)。快照是折叠前的——宿主只在 tool success 返回后才从后续请求里移除被覆盖消息。⇒ src/stream.ts:381-383 的注释("Proxy mode only: plugin-mode agents own their folds, so bili never sees those originals")与该路径不符,建议随本修复一并修正;该注释还会误导对 CCR storeCoveredOriginals(src/stream.ts:387,无 mode gate)是否已覆盖 plugin 模式的判断。
分支另加了一个第三提交(注释修正,零行为变更):src/stream.ts 的 CCR 注释原写 "Proxy mode only: plugin-mode agents own their folds, so bili never sees those originals"——经核实不准确:opencode native 插件的 compress 是转发到代理端执行的,落块时 bili 持有 pre-fold 快照(src/plugin.ts:991-998 remembered snapshot → executeProxyTool messages),该 lane 的折叠原文可见,CCR 存储与本次机械保真钩子都覆盖它;只有 pi 这类宿主自带内核的 lane 才是 no-op。注释已改为按 lane 精确区分。
Fix delivered in #1722 (replaces #1704 per the review direction there): the sub-agent session id is captured mechanically from the dispatch pair's structured field (sessionId/sessionID/session_id under a strict ses_… shape predicate — prose is never regex-scanned) at fold commit into a session.metadata["subagentSessions"] sidecar, and re-attached model-side on the compress receipt plus the active block's rendered summary message. Stored summaries stay byte-clean; tier distillation never re-copies ids. opencode only, gated on pluginAgent === "opencode".
① 方向:遵循 #1704 review thread 的定向(结构化字段捕获、无正则、sidecar、渲染期 attach、opencode-only)。对 issue 字面验收("id 存在块内")的偏离已在 PR body 明示并经你确认——保的是精神(每次折叠后 id 机械保证模型可见),存摘要保持字节干净。✓
Activity
ranxianglei commentedon Sep 29, 2026
不属于本项目
ranxianglei commentedon Sep 29, 2026
搞错了 属于本项目
ranxianglei commentedon Sep 29, 2026
[bot] 🏷 已接到 #1702。计划:
ALWAYS_PROTECTED_TOOLS仅内核元数据工具、新鲜区默认 5 条/5K、宿主未注册派发工具保护),确认「seg id 唯一存活通道是模型手写摘要」这一机制成立;ses_[A-Za-z0-9]+机械提取 + 去重 + 机器附录行写入压缩块;提示词层不动;有进展会持续回帖。
ranxianglei commentedon Sep 29, 2026
补充两个已对照 origin/master@8d3d1bfc 验证的实现事实(对应计划第 2 步「定位落块点」):
handlePluginTool(src/plugin.ts:899)读取 remembered 快照(remembered.get(session.id),由rememberPluginMessagessrc/plugin.ts:276 在 forward 后写入,调用点 src/server.ts:2744),并作为 ctx.messages 传入executeProxyTool(src/loop/core.ts:226)。快照是折叠前的——宿主只在 tool success 返回后才从后续请求里移除被覆盖消息。⇒ src/stream.ts:381-383 的注释("Proxy mode only: plugin-mode agents own their folds, so bili never sees those originals")与该路径不符,建议随本修复一并修正;该注释还会误导对 CCRstoreCoveredOriginals(src/stream.ts:387,无 mode gate)是否已覆盖 plugin 模式的判断。applyRanges(src/stream.ts:281)中,ctx.core.applyCompression返回含新 block 的 res.state、且ctx.session.state = res.state赋值之前,被折叠原文(ctx.messages / ctx.compressMessages)与新 blocks 同时在手——与cacheBlockContent(src/stream.ts:371)消费原文的位置相同,两种模式都走这里。可在此做 block → covered refs → 原文映射,机械提取 id,向 block.summary 追加机器附录行。注意:这是对内核返回 state 的后处理,落地时需确认不与既有不变量冲突(如 token 计数、渲染路径)。ranxianglei commentedon Sep 29, 2026
[bot] 🏷 根因修复已落地 → PR #1704: #1704 (Closes #1702)
审核三步结论(动手前验证)
ALWAYS_PROTECTED_TOOLS = ["compress","acp_rule"](dist/index.js:1253)、软保护preserveRecentMessages: 5/preserveRecentTokens: 5e3(dist/index.js:431-432)、宿主侧无任何派发工具的内容级保护。子代理派发对(参数里的ses_id + 结果)在内核眼里就是普通工具交换,父代理多轮工作后必然滑出新鲜区被折叠——与 opecode2 压缩的时候会截断sub agent的 session_id #1563 事故时序一致,"resume 发生在新鲜区"的假设确实已被事故证伪。ses_token(而非匹配派发工具名)——工具名随 opencode 版本/wire 形态漂移,内容门控同时覆盖参数与结果文本,且天然满足验收标准"块内 id 逐字存在"。实现(单提交,4 files, +386):
src/mechanical-preserve.ts:提取(ses_[A-Za-z0-9]+,去重保序,每块上限 100 个并记录截断)+ 幂等 strip-then-re-pin(模型若把自己的旧附录行抄进新摘要也会被规范化)。src/stream.tsapplyRanges—— 全部折叠通道的唯一采纳点(model-driven compress / preflight overflow / in-place refold 都汇聚于此),在模型输出之后、任何消费者(指纹摘录/token 估算/持久化)读取之前执行。T2 蒸馏自动覆盖:子块摘要(含附录行)本身就是父折叠的覆盖文本,每层重新 pin。opencode native V1/V2 插件的 compress 是转发到代理端执行的(forwardTool),所以插件模式同样覆盖;pi 这类宿主自带内核的 lane 看不到折叠原文,结构上 no-op。ID_PATTERNS数组(commit hash / PR 号后续按同一机制扩展,本 PR 刻意不做)。行为变更披露(旧→新):覆盖到含
ses_id 内容的折叠,其压缩块摘要 = 模型原文 +\n\n[acp-mechanical-preserve] <ids>(旧:纯模型文本;新增约几十字节机器行,稳定 marker 前缀)。不含此类 id 的折叠字节级不变(有测试钉住)。原因即修复本身:id 存活不得依赖模型抄写质量。证据
tests/mechanical-preserve.test.ts(14 项全过):机械断言(无论模型摘要写什么,块内 includes 全串匹配)、opecode2 压缩的时候会截断sub agent的 session_id #1563 截短失败模式(模型只写出 12 字符前缀 → 块内仍为完整 id 且仅一条附录行)、T2 传播、refold 规范化、零成本字节一致、extract/strip/pin 单元覆盖。一句话中文摘要:修复了折叠丢失 opencode 子代理 session id 的根本原因(内核保护按工具名键控、内容零感知),改为落块时代码从覆盖原文机械提取 ses_ id 强制写入压缩块附录行,保真不再依赖模型抄写,可以合并。
ranxianglei commentedon Sep 29, 2026
[bot] 🏷 跟进:rebase 到当前 master + 顺手修掉一个 master 上既有的测试 bug(PR #1704 已更新)
背景:PR #1704 的 CI 里 4 个
testjob(ubuntu/windows × node 22/24)全红。排查后确认与本 PR diff 无关,是 master 上的既有问题:#1101 T9: BILI_CHAIN_CONTENT env parse(tests/issue1086-chain-self-exemption.test.ts:728),错误为ReferenceError: rmSync is not defined。该文件第 6 行node:fsimport 只有mkdirSync, mkdtempSync, writeFileSync,漏了rmSync;T9 的 finally 清理(728 行)直接调用了它。<bili-chain …/>is injected as a visible trailing user-role message — models read it as phantom user input and burn tokens commenting on it #1683(fix: make chain-integrity recognition header-only by default)在我分支切出点之后合入 master 的;当前 master tip(8293a54)自己的 CI 同样 4 个 test job 全红、同一失败项——即 master 本身是红的,不是本 PR 引入。处理(按「可安全顺手修的小问题 → 独立标注提交」规则):一行修复——import 列表补上
rmSync,独立提交2799fb1a(纯 test 文件,零行为变更)。修后本地:typecheck clean,全套 3285 pass / 0 fail / 12 skipped,build OK。分支现状(PR #1704 head 已更新,CI 自动重跑中):
175b00eafix: mechanically pin subagent session ids into fold blocks (折叠时按消息类型机械保真:opencode 子代理派发对的 seg id 由代码强制写入压缩块(#1563 根因修复) #1702)— 主修复,rebase 后无冲突;2799fb1atest: import rmSync in issue1086 chain test — 顺手小修(上述既有 bug)。上一轮 head 上所有 e2e workflow(real codex / fake codex / hermetic registry / native pi·opencode·dsh lanes / codex overlay)均已绿;本次重跑会在新 head 上再验一遍。等 CI 转绿即可合并。
一句话中文摘要:PR 的 4 个红 test job 是 master 既有的
rmSync漏 import(#1683 引入,与 #1704 无关),已 rebase 到最新 master 并用独立提交补上这一行 import,全套测试转绿,可以合并。docs: correct CCR comment — proxy-forwarded plugin lanes do see folde…
ranxianglei commentedon Sep 29, 2026
[bot] 🏷 CI 全绿确认(head
bacc573e,13/13 通过)testjob(ubuntu/windows × node22/24)已随 rmSync import 修复转绿——修复在真实 CI 环境验证生效;e2e(真实 codex CLI 全生命周期)、hermetic registry、各 fake-upstream lane、build-artifact 全部通过。分支另加了一个第三提交(注释修正,零行为变更):
src/stream.ts的 CCR 注释原写 "Proxy mode only: plugin-mode agents own their folds, so bili never sees those originals"——经核实不准确:opencode native 插件的 compress 是转发到代理端执行的,落块时 bili 持有 pre-fold 快照(src/plugin.ts:991-998remembered snapshot →executeProxyToolmessages),该 lane 的折叠原文可见,CCR 存储与本次机械保真钩子都覆盖它;只有 pi 这类宿主自带内核的 lane 才是 no-op。注释已改为按 lane 精确区分。PR #1704 现状:3 commits(主修复 / test rmSync 顺手修 / 注释修正),基于当前 master tip,CI 13/13 绿,可以合并。
一句话中文摘要:CI 已全绿(含此前因 master 预存 bug 而红的 4 个测试 job),并顺手修正了一处会误导读者的 CCR 注释(opencode 插件 lane 实际能看到折叠原文),PR 可合并。
ranxianglei commentedon Sep 29, 2026
[bot] 🏷 收到(这条是开头「不属于本项目 → 搞错了 属于本项目」的补发确认)。与最终落地一致:修复完全在本项目内完成——挂点
src/stream.ts applyRanges(bili 侧落块后处理),acp-kernel 一行未改、无跨仓依赖;PR #1704 基于当前 master tip,CI 13/13 绿,等人工合并即可。ranxianglei commentedon Sep 30, 2026
Fix delivered in #1722 (replaces #1704 per the review direction there): the sub-agent session id is captured mechanically from the dispatch pair's structured field (
sessionId/sessionID/session_idunder a strictses_…shape predicate — prose is never regex-scanned) at fold commit into asession.metadata["subagentSessions"]sidecar, and re-attached model-side on the compress receipt plus the active block's rendered summary message. Stored summaries stay byte-clean; tier distillation never re-copies ids. opencode only, gated onpluginAgent === "opencode".ranxianglei commentedon Sep 30, 2026
[bot] 🏷 #1722 review 完成:可合并(CI 13/13 全绿,head
410ca72e,基于当前 master tip)。按审查规范逐项核过:① 方向:遵循 #1704 review thread 的定向(结构化字段捕获、无正则、sidecar、渲染期 attach、opencode-only)。对 issue 字面验收("id 存在块内")的偏离已在 PR body 明示并经你确认——保的是精神(每次折叠后 id 机械保证模型可见),存摘要保持字节干净。✓
② 回归清点(触碰路径的既有行为):
applyRanges指纹循环重构:谓词不变(prev === undefined || prev !== b.summary),既有 lane 的 receipt 输出逐字节不变——note 行仅在 opencode 门控命中且条目非空时出现;src/persist.ts:681写 /:757读),加键即存活重启,无格式版本变更;preflight.ts:993预览直调core.applyCompression(不过applyRanges),钩子只在真实提交(:1131)触发——dummy summary 不会污染 sidecar;pluginAgent === "opencode"门控排除。③ 代码主关:三个此前无法从 diff 内部自证的假设全部外部验证通过——内核
CompressionBlock.active: boolean确实存在(acp-kerneltypes.d.ts:46,attach 的 active 过滤不会静默失效)、metadata 持久化闭环、dry-run 隔离。严格形态谓词 + 工具名门控 → 只可能漏捕(优雅降级回现状),不可能误捕。④ 测试有效性:断言有牙——存储摘要与模型载荷逐字节相等(strict equal)、no-regex 证明(prose 提及与嵌套 JSON 回声均不产生条目)、attach 不可变 + 引用同一性、opencode/非 opencode 双向集成。小缺口(不拦):refold 继承与 metadata 往返各缺一个端到端用例,后续可补。
[acp-subagent-sessions bN: …]行;活跃块渲染出的摘要消息尾部追加同内容 id 行(仅渲染层,存储摘要零变化——与 #1704 改存储摘要的方案相反)。其他客户端 lane:零行为变化。一个残留风险(低风险,留档):
sessionId/sessionID/session_id字段名依据 #1563 事故数据,仓库内没有真实 task 载荷 fixture 可对拍;若生产载荷把 id 嵌在其他顶层键下,捕获会静默漏(降级为现状,不会损坏数据)。建议拿一条事故会话的真实 dispatch payload 对拍一次,或日后补进 e2e-native-opencode lane。一句话中文摘要:#1722(sidecar 方案替代 #1704)代码、回归、测试三关均过且 CI 全绿,唯一残留风险是字段名需对真实载荷确认一次,可以合并。
fix: capture opencode 2.x subagent envelopes + e2e the sidecar across…
fix: preserve opencode sub-agent session ids across folds via structu…
fix: capture opencode 2.x subagent envelopes + e2e the sidecar across…
Merge pull request #1722 from ranxianglei/2026-09-30_subagent-session…