Repository navigation
fix(clients): keep the reply after an in-turn compaction checkpoint - #731
Merged
Merged
Conversation
The projector treated only `schemaVersion === 2` checkpoints as durable in-turn markers. #715 moved the agent to schema 3, so every automatic mid-turn checkpoint was reclassified as an exchange boundary: the open exchange was flushed and the assistant/tool entries that followed it belonged to no user message, which `turnFromAcc` drops. Reopening a conversation showed it stopping at the "上下文已压缩" divider with the rest of the reply — and the tool results paired across the checkpoint — missing, even though the journal still had them and the run had completed normally. Gate on "v2 or newer" instead of a literal version, so a future schema bump cannot silently drop a turn again, and keep v1 destructive summaries as boundaries. Covered on both clients: the mobile timeline tests now run the in-turn case for schema 2 *and* 3, and a new desktop projection test pins the segments around a v3 mid-turn checkpoint. The screenshot harness gains a `compact-resume` scenario per platform (`?compactHistory=1`) whose `eval` assertions fail if the text after the divider is missing, so the regression cannot come back unnoticed.
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.
问题
会话在一次回合内压缩(
phase=mid_turn)之后,回复的后半段在客户端消失:重新打开会话只看到停在「上下文已压缩」分割线,之后的正文和工具结果全没了,看起来像"会话暂停了"。agent 侧并没有停——那次 run 正常跑完并completed,journal 里数据都在。根因
packages/thread-projection/src/projection.ts判断"这个 checkpoint 属于当前回合、不该断开 exchange"时写的是字面版本:#710 加这条规则时 checkpoint 还是 schema 2;#715 把 agent 的
SCHEMA_VERSION提到 3,这个闸门没跟着改。于是每个 v3 的回合内 checkpoint 都被当成回合边界:当前 exchange 被 flush,其后的 assistant/tool entry 落进一个没有 user message 的累加器,turnFromAcc因为!acc.userMessage直接丢弃——压缩点到下一个用户消息之间的整段内容都从投影里消失。两端共用这个包(手机
timelineFromEntries、桌面useThreadMessages),所以手机和桌面同时中招。测试全部写死schemaVersion: 2,CI 因而全绿。用真实数据核对过:把
20260919-231813-721d8c(1758 条 entry)喂给修复前的投影,最后一次压缩之后的 314 条 entry、5186 字正文在投影里一条不剩。修法
闸门改成「v2 或更新」(
(schemaVersion ?? 0) >= 2),v1 的破坏性摘要仍按边界处理。这样以后再 bump schema 也不会悄悄吞掉一个回合。验证
timeline.test.ts的回合内用例现在同时跑 schema 2 和 3(6 个组合);桌面entryProjection.test.ts新增 v3 mid-turn 用例。都做过反向对照——把闸门改回=== 2,新增用例立即失败。compact-resume场景(桌面 + 手机,?compactHistory=1注入一段含 v3 mid-turn checkpoint 的历史),场景里的eval断言会在分割线之后的正文缺失时直接让截图失败。修复前手机/桌面都失败(reply after the checkpoint was dropped),修复后 1/1 通过;截图 OCR 确认分割线之后有完整正文。vitest run139 文件 / 1185 用例全绿;手机 116 套件 / 1710 用例全绿;两端tsc --noEmit+eslint干净。全量截图跑了一遍,失败项与本次改动无关(m-rename的菜单项在这一版 main 上同样点不到,基线一致)。