Repository navigation
fix(chat): update the context ring as soon as a compaction lands - #2018
Conversation
The composer ring reads the newest assistant message's provider usage, and a compaction produces no such message. After /compact the ring kept the pre-compaction figure until another turn ran, which made a successful compaction look like it had failed. The runtime already estimates the compacted request before installing a checkpoint. It now stamps that estimate into the checkpoint's opaque details, so the mark on compaction_end and the marks rebuilt on session open both carry it. The ring shows it while no request after the checkpoint has reported usage; older checkpoints without the field keep the previous behavior. fixes vastsa#2015
vastsa
left a comment
There was a problem hiding this comment.
已验证原问题真实存在,并完成候选验证,可以合入。
独立使用 main 和候选的生产 inspector 同一夹具比较:82% 的压缩前用量,在带 12000-token 检查点后,main 仍为 82%,候选为 12%。新增四个 renderer 用例及 shared 14 个用例通过;runtime.test.ts + context-usage-compaction.test.ts 共 398/398 通过,runtime build/typecheck 通过。
生产 sidecar + localhost Responses 网关三种离线场景通过(缓存输入、不完整计数、普通用量),额外断言持久化 checkpoint.details.contextTokens 为正且与 compaction_end.mark.contextTokens 一致。原 E2E fake-host 未适配新合入的 tools.fileBatchCapabilities,诊断中补了 supported:false 后通过;未改贡献者提交。没有真实供应商调用或本地 Electron UI E2E;远端六项检查全部通过,包含 Electron 和 Windows。
可选 metadata 保留旧检查点兼容性,live/reload 共用 mark,下一次真实用量恢复供应商值;改动范围与问题一致。最新 main 为 head 祖先,PR integration tree 与测试 head 相同 e46b12202da5eb85306488ce70c51dc874dd508c。本机旧依赖不兼容,已仅在隔离工作区安装锁定依赖;原工作区未修改。
fixes #2015
问题
输入框右侧的上下文圆环读取的是最新一条助手消息里的供应商用量。压缩本身不会产生助手消息,所以
/compact成功后,圆环还停在压缩前的数字,要等下一轮请求报告用量才会变。看起来像压缩没生效。修改
persistCheckpoint在安装检查点前本来就会估算压缩后的下一次请求大小(compactedBudget.tokens,用来判断是否超出安全预算)。现在把这个值写进检查点的details.contextTokens。details由 host 原样持久化,和generation一样,重开会话后也在。ContextCompactionStatus增加可选的contextTokens,contextCompactionMark()从details读出。实时的compaction_end.mark和打开会话时重建的 mark 都会带上它。latestTurnContextInspector()从末尾往前找时,如果先遇到最新检查点的throughMessageId,再遇到带用量的消息,说明这份用量是压缩前的。这时返回compactedContextTokens,圆环和百分比用它计算。面板里的输入、输出、缓存这些供应商用量仍显示最后一次真实请求的数据。下一次请求报告用量后,自动换回真实数据。兼容性
contextTokens,圆环和现在的表现一样。验证
apps/desktop/test/compaction-context-usage.test.mjs:runtime.test.ts的阈值压缩用例:要求持久化的details和compaction_end.mark都带contextTokens。改代码前这个用例失败,改后通过。checkpointContextTokens和 mark 都有覆盖。pnpm build:js、desktop 和 agent-runtime 的 typecheck、pnpm lint、check-architecture、git diff --check。docs/project/unreleased.md。