Revert "修复历史重读后旧消息追加到末尾的乱序"

This reverts commit 036395c6c9.
This commit is contained in:
2026-09-17 14:38:22 +08:00
parent d85622069d
commit dd339638cc
6 changed files with 3 additions and 46 deletions
+3 -4
View File
@@ -626,7 +626,7 @@ function claimInitialSupervisorMessageForPage(projectPath: string, scope = '') {
* **** messages latch user
* replace
*
* messages "非历史来源、运行时拥有、且回读结果里没有"
* messages "运行时拥有、且回读结果里没有"
*/
function mergeLoadedConversationWithPendingRuntimeMessages(
loaded: ChatMessage[],
@@ -644,7 +644,7 @@ function mergeLoadedConversationWithPendingRuntimeMessages(
loaded.map((message) => `${message.role}\u0000${message.text}`),
);
const pending = current.filter((message) => {
if (!message.runtimeOwned || message.fromHistory) {
if (!message.runtimeOwned) {
return false;
}
if (message.messageId) {
@@ -4202,7 +4202,7 @@ export function App({
const conversationMessages = mergeProjectSupervisorConversation(
resolvedProjectConversation.messages,
supervisorConversation?.messages ?? [],
).map((message) => ({ ...message, fromHistory: true }));
);
if (
conversationContainsProjectSupervisorResponseStream(
supervisorConversation?.messages ?? [],
@@ -12528,7 +12528,6 @@ export function App({
: ('assistant' as const),
text: message.content,
runtimeOwned: true,
fromHistory: true,
messageId: message.messageId,
updatedAt: message.updatedAt,
}));
@@ -999,8 +999,6 @@ export interface ChatMessage {
agentId?: string | null;
updatedAt?: number;
runtimeOwned?: boolean;
/** 来自历史回读,不作为尚未落盘的实时消息追加到新历史页末尾。 */
fromHistory?: boolean;
}
export type DesignAgentInput =
@@ -97,43 +97,6 @@ afterEach(() => {
});
describe('Direct 聊天历史分页集成', () => {
it('加载旧页后重读历史回到最新页,再翻页仍按原顺序且不重复', async () => {
const invoke = install((args) =>
args.beforeItemId
? page(messages.slice(0, 6), false)
: page(messages.slice(6), true),
);
mount();
await screen.findByText('历史正文 25');
fireEvent.click(earlier());
await screen.findByText('历史正文 0');
await setComposerText(screen.getByLabelText('陶泥儿对话内容'), '/history');
fireEvent.click(screen.getByRole('button', { name: '发送' }));
await act(async () => {
await Promise.resolve();
});
expect(screen.queryByText('历史正文 0')).toBeNull();
expect(screen.getByText('历史正文 25')).not.toBeNull();
fireEvent.click(earlier());
await screen.findByText('历史正文 0');
for (let index = 0; index < messages.length; index += 1) {
expect(screen.getAllByText(`历史正文 ${index}`)).toHaveLength(1);
if (index > 0) {
expect(
screen
.getByText(`历史正文 ${index - 1}`)
.compareDocumentPosition(screen.getByText(`历史正文 ${index}`)) &
Node.DOCUMENT_POSITION_FOLLOWING,
).not.toBe(0);
}
}
expect(
invoke.mock.calls.filter(
([command]) => command === 'read_direct_project_history_slice',
),
).toHaveLength(4);
});
it('首屏按消息加载20条,更早消息使用原生游标,原始工具记录不占页', async () => {
const invoke = install((args) =>
args.beforeItemId
@@ -10,7 +10,6 @@
2. 工作台首屏与更早消息读取显式请求消息模式,消费游标;加载代次隔离、单飞与 ID 去重。
3. 合成记录测试复现原始工具页卡住的形状,覆盖旧无 ID、坏行、时间、失败/重复/切项目;临时目录只读重放用户日志。
4. 前端/原生定向测试、类型、Lint、编码、文档和差异检查通过后,更新问题表及 PR 草稿并本地提交。
5. 在临时消息投影中标记历史来源,保留 Runtime 所有权语义;刷新合并时只保留非历史来源的待回读消息。补齐「先加载旧页,再 /history,再翻页」的顺序与去重回归,保持尚未落盘用户输入的保留逻辑。
## 边界与停止条件
@@ -17,4 +17,3 @@
2. 消息正文、原始 ID、时间和顺序保持不变,翻页能到达早期用户提问及最终回答,不重复。
3. 连点、请求失败重试、项目切换和同项目重新加载不会污染消息或游标。
4. 原始切片默认模式回归通过,用户日志只读重放可以取回全部现存消息;不把真实日志或对话正文提交到仓库。
5. 加载更早消息后重新读取历史,旧页不出现在最新回复之后;再次翻页保持顺序且不重复。未落盘的实时用户输入不因历史刷新被丢弃。
@@ -35,7 +35,6 @@
- 聊天历史使用 `read_direct_project_history_slice``messagesOnly: true` 模式,按有正文的 user/assistant 消息分页,默认 20 条;工具/推理原始记录不占聊天页名额、不进入聊天分页响应,也不从磁盘删除。接口省略该选项时维持原始 item 切片语义。响应给出明确的 `oldestItemId` 游标;消息投影不能重新发明分页位置。
- 消息模式读取逐行过滤原始记录,不在内存中积累整份工具输出;正文、原始 ID 和信封时间原样保留。旧的无 ID 消息不能凭空生成身份,必要时向前扩展到已有消息 ID 边界;没有更早消息时结束分页。
- 首屏和加载更早消息共用分页解析;重复点击只发一个请求,重叠消息按原始 ID 去重并保留当前显示版本。切项目、同项目重新加载及 A→B→A 的迟到响应不得覆盖当前消息、游标或加载状态;失败保留已有消息与分页位置并允许重试。
- 历史读取来源与 Runtime 所有权分开记录;从磁盘分页读出的消息不能当作未落盘实时消息保留到新页末尾。重新读取历史时回到最新页,旧页仍可从原生游标再次向前加载;真正尚未回读到的实时消息继续保留,不改原始日志、时间或内容。
- 交付合同:实时消息、历史回读、工具详情与最终回复先归一为按 `clientTurnId` 唯一的回合,再渲染一次。用户消息始终保留;同一回合的正文、工具和耗时不能从消息、实时尾部、未归属尾部等多个出口重复展示。
- 归属来自 `direct-codex:{clientTurnId}:{role}`、文本流中保留的原始 item ID,以及项目历史内明确用户记录之后的 assistant 记录。先在已加载的完整消息集合中关联,再做可见分页;持久历史继续通过 canonical item 切片懒加载,`hasMore` 为真时,未加载回合的工具流不得漂到当前页尾部。禁止将第 N 个有工具回合配给第 N 条用户消息,禁止按文本长度、标点或时间窗猜测归属。缺身份的旧记录保留,不猜造其与其它回合的关联。
- 有回合流时正文与工具位置仅来自 item 边界与 `seq`,工具详情按该回合的 `callId` 关联;没有流时同一个回合容器显示历史消息与工具。整轮累计文本仅在活动回合尚无流和持久 assistant 时作兜底,不另建实时消息出口。