Files
mnote/bugs/07-ai/done/7-61-page-ai-pi-history-replay-source-mixing-v1.md
T

32 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 7-61 Page AI Pi 历史回放真源混用
## 问题
Pi Lab 实时对话正常,但重新打开历史 session 后,同一条 assistant 结果可能重复显示多次;工具过程没有同步重复。
## 根因
历史打开链路同时读取并合并两个来源:
- `/api/page-ai/pi/sessions/{id}/tree`Pi Rust JSONL session tree,会话消息真源。
- `/api/page-ai/pi/sessions/{id}/events`control-plane runtime events,用于 SSE backlog、导出和诊断。
`events` 中同一次回复可能以 `message_update/text_delta``message_end``agent_end` 等形式记录运行过程;它不是历史消息 UI 的 canonical source。前端把 `tree``events` 合并回放后,就会把同一 assistant 结果渲染成多条消息。
## 修复
- `sidebar-page-ai-pi-lab-runtime.js`
- `openHistorySession()` 只从 `/tree` 读取并回放消息。
- 移除历史回放消息层面的 `eventsToReplayMessages()` / `mergeReplayMessages()` / `replayMessageKey()`,避免用去重掩盖多真源。
- `/events` 继续保留给实时 SSE backlog、导出和诊断,不参与历史消息回放。
- `scripts/task-pi-lab-history-tail-smoke.js`
- 构造 JSONL 只有 1 条 assistant 回复,但 runtime events 中包含多段同文结果事件。
- 打开历史后断言 UI 只显示 JSONL 中的 1 条 assistant 回复。
## 验证
- `node --check rust/crates/mnote-web/browser/sidebar-page-ai-pi-lab-runtime.js`
- `node --check scripts/task-pi-lab-history-tail-smoke.js`
- `node scripts/task-pi-lab-static-smoke.js`
- `node scripts/task-pi-lab-history-tail-smoke.js`