fix: apply kernel truncation to surviving tool parts - #3
Closed
5258MF wants to merge 2 commits into
Closed
Conversation
Contributor
Author
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.
现象
acp-kernel 三层安全网的最后一层——emergency-truncate(上下文 ≥100% 时的文本级紧急截断)——在本插件中对工具输出截断后,截断文本无法到达模型,形同虚设。
根因
contentType !== "tool-result"跳过;触发条件tokenCount ≥ truncate.threshold × limit,默认 threshold=1)octoToCoreMessages把 tool part 投影为两个 core(call#c+ result#x);reassemble的 tool 分支(修复前)只校验callAlive && resultAlive就parts.push(p)原样放回原始 partstate.output,普通失败位于state.error,中断工具的部分输出位于state.metadata.output。kernel 改写在 result core 上的截断文本若不按状态写回,就会被丢弃patchRefTag中带正文改写检测(billion-context-pi/src/messages.ts:228-239,注释明确 "Honor kernel body mutations (emergency truncation of large tool-results)… otherwise truncation never reaches the model")——opencode 移植时漏掉了 tool 路径这一环修复
新增统一的工具结果正文映射,并由投影和回填共同使用:completed →
state.output;普通 error →"Error: "+state.error;metadata.interrupted === true的 error →state.metadata.output。applyToolBody(part, resultCore)与 result core 文本做trimEnd比较——相等则原样返回(正常路径零行为变化),不等则按原状态分别写回state.output、state.error或state.metadata.output。回填只替换工具结果正文,保留原来的
status、input、error、metadata、time等状态外壳;失败和中断状态不会被改成 completed。reassemble tool 分支使用parts.push(applyToolBody(p, outCoreById.get(ids[1]!)))。影响范围
仅紧急截断路径(需上下文推到 100%)。正常会话中 trimEnd 相等,行为与修复前完全一致。触发条件苛刻,实际运行未触发过(作者标注"还没测试"的部分),但逻辑缺陷经代码路径验证确实存在。
验证
metadata.output投影并回填,npm test30/30 通过npm run typecheck、npm test、npm run build全部通过