Skip to content

fix(clients): keep the reply after an in-turn compaction checkpoint - #731

Merged
huichen merged 2 commits into
mainfrom
fix/compact-v3-projection
Sep 20, 2026
Merged

huichen merged 2 commits into
mainfrom
fix/compact-v3-projection

Conversation

@huichen

@huichen huichen commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator

问题

会话在一次回合内压缩(phase=mid_turn)之后,回复的后半段在客户端消失:重新打开会话只看到停在「上下文已压缩」分割线,之后的正文和工具结果全没了,看起来像"会话暂停了"。agent 侧并没有停——那次 run 正常跑完并 completed,journal 里数据都在。

根因

packages/thread-projection/src/projection.ts 判断"这个 checkpoint 属于当前回合、不该断开 exchange"时写的是字面版本:

const inTurn = entry.checkpoint?.schemaVersion === 2 && …

#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,新增用例立即失败。
  • 真实数据:用上面那个真实会话的 journal 重跑投影,修复后分割线之后的正文、尾部文案都回来了,分割线本身仍留在同一个回复气泡里。
  • 截图:新增 compact-resume 场景(桌面 + 手机,?compactHistory=1 注入一段含 v3 mid-turn checkpoint 的历史),场景里的 eval 断言会在分割线之后的正文缺失时直接让截图失败。修复前手机/桌面都失败(reply after the checkpoint was dropped),修复后 1/1 通过;截图 OCR 确认分割线之后有完整正文。
  • 回归:桌面 vitest run 139 文件 / 1185 用例全绿;手机 116 套件 / 1710 用例全绿;两端 tsc --noEmit + eslint 干净。全量截图跑了一遍,失败项与本次改动无关(m-rename 的菜单项在这一版 main 上同样点不到,基线一致)。

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.
@huichen
huichen enabled auto-merge (squash) September 20, 2026 01:16
@huichen
huichen merged commit 6218579 into main Sep 20, 2026
12 checks passed
@huichen
huichen deleted the fix/compact-v3-projection branch September 20, 2026 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant