Repository navigation
fix(agent-runtime): size compaction summary prompts with the CJK-aware estimate - #2366
Conversation
|
Note: the earlier #2365 for this issue fails the JS unit-test step (subagent-context.test.ts:394, expected "compacted" got "overflow") because its shared-estimator change makes the delegate CJK brief, truncated at the chars/3.5 cap, still exceed the budget it is then measured against. This PR sizes the delegate brief truncation with the same CJK-aware estimate so the truncation result and the guard agree; see truncateDelegateUserMessage. |
|
独立复查 head 5ebb31a,并合入最新 main 2270533 生成 integration 819f4bb4b 后执行三组生产测试(compaction-summary-input / subagent-context / output-cap):84 通过、5 失败;相同 main 基线 84/84 通过。CJK 摘要低估问题已在 #2365 审查中复现,但本 PR 目前带入明确回归,暂不合入。
建议先移除这些既有逻辑的回退,以最小范围补齐 summary prompt/chunk/previous-summary 的 CJK 估算;保留所有现有回归断言,在最新 main 集成候选上重跑后再审。 |
5ebb31a to
509bad6
Compare
…elegate summaries (vastsa#2364) - output-cap: align with main and export countCjkChars; keep all shared truncation helpers - compaction-summary-input: single CJK-aware estimate shared by the session guard, the chunk planner, and chunk truncation (issue vastsa#2364) - subagent-context: when even the reduced delegate summary input cannot fit one prompt, split it with the shared planSummaryChunks and chain the summaries instead of skipping the summary (issue vastsa#827 machinery) - specs: document the delegate compaction chunking behavior
|
复查更新:此前三类回归均已消除。已在独立 worktree 合入最新 main e17e5e7,集成候选 64352a7 上运行 runtime 全量测试:135 文件、2039 项通过;三组重点测试 89/89 通过。重新 bundle 后,生产 sidecar + 本地 Responses fixture 的 e2e-context-usage-compaction 三组场景通过(cached-input、partial-buckets、normal-usage),diff check 通过。原始 CJK 低估缺陷此前已独立复现。本轮没有调用真实付费 provider。 已保留作者提交,非强制推送最新 main 的合入提交,修复 Head contains latest base 门禁。等待此精确 head 的全部 CI 通过后再作最终合入检查。 |
vastsa
left a comment
There was a problem hiding this comment.
复查更新:此前三类回归均已消除。已在独立 worktree 合入最新 main e17e5e7,集成候选 64352a7 上运行 runtime 全量测试:135 文件、2039 项通过;三组重点测试 89/89 通过。重新 bundle 后,生产 sidecar + 本地 Responses fixture 的 e2e-context-usage-compaction 三组场景通过(cached-input、partial-buckets、normal-usage),diff check 通过。原始 CJK 低估缺陷此前已独立复现。本轮没有调用真实付费 provider。
已保留作者提交,非强制推送最新 main 的合入提交,修复 Head contains latest base 门禁。等待此精确 head 的全部 CI 通过后再作最终合入检查。
追加验收:生产 Host 的 e2e-compaction-tail 通过(restart=true),验证压缩尾部的持久化及重启恢复。
根因
Compaction 的摘要请求(
compaction-request.ts→completeSimple)不走 agent 的streamFn,因此没有 output-cap 闸门;唯一的预算检查estimateSummaryPromptTokens用 chars/3.5 的英文比例估算序列化后的 prompt。Han/kana/Hangul 实际按约 1 token/字编码,一个「看起来能放下」的 CJK prompt 被整段发出,被 provider 以 context overflow 拒绝,随后该 turn 回退到 retained-tail,摘要被丢弃。#2340 已用 output-cap 的 CJK 估算器约束 retained tail、checkpoint user message 与 delegate brief,唯独摘要请求本身仍留在英文比例上。
修复
estimateSummaryPromptTokens(及共享的estimatePromptTextTokens):在 chars/3.5 基线上加回 0.75 token/CJK 字符的缺口,与output-cap.ts的countCjkChars同一口径;ASCII 估算不变。planSummaryChunks:每条消息的 chunk 成本 = pi 估算 + CJK 缺口;单条超预算的 CJK 消息改为按 CJK 口径二分截断(纯 ASCII 保持原 chars/3.5 截断上限,行为不变)。compactionSummaryReserveTokens对携带的 previous summary 使用同一 CJK 口径。subagent-context.ts的 delegate brief 截断同样改为 CJK-aware(否则截断后的 CJK brief 仍会越过新估算下的预算而被误判 overflow)。验证
packages/agent-runtime:vitest run compaction-summary-input / subagent-context / output-cap / runtime / session-context / context-usage-compaction / pi-coding-agent-compaction / hosted-search-compaction全绿(538 tests)。tsc --noEmit(4GB heap)0 错误。Fixes #2364