From c52c3aa106fec896de13f08ef4d3fbc507ba956e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Fri, 4 Sep 2026 17:56:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=20DirectProject=20=E5=8E=9F?= =?UTF-8?q?=E5=A7=8B=E5=8E=86=E5=8F=B2=E5=AE=9E=E7=8E=B0=E7=BA=A6=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 记录线程注入与用户消息写入顺序 明确空 rawResponseItem 错误及浏览器只读边界 补充历史模块职责位置 --- ...方案】DirectProject Codex原始历史与异常恢复-2026-09-04.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/technical/【技术方案】DirectProject Codex原始历史与异常恢复-2026-09-04.md b/docs/technical/【技术方案】DirectProject Codex原始历史与异常恢复-2026-09-04.md index 58f0537b8..ec03bae19 100644 --- a/docs/technical/【技术方案】DirectProject Codex原始历史与异常恢复-2026-09-04.md +++ b/docs/technical/【技术方案】DirectProject Codex原始历史与异常恢复-2026-09-04.md @@ -22,8 +22,8 @@ DirectProject 不迁移旧 `{role,content}` 行;实现按新格式工作。 ## 正常回合 -1. 将本轮用户文本构造成 Responses `message` item 并追加、flush。 -2. 启动 `ephemeral: true` 线程,并启用 `experimentalRawEvents: true`。 +1. 启动 `ephemeral: true` 线程,并启用 `experimentalRawEvents: true`。 +2. 新线程先把历史 item 数组一次注入;注入成功后,将本轮用户文本构造成 Responses `message` item 并追加、flush。 3. 收到 `rawResponseItem/completed` 后立即追加其 `params.item` 并 flush。 4. 正常 `turn/completed: completed` 不生成额外记录。 @@ -39,12 +39,16 @@ AGC 判定本轮不会再产生新事件时收尾:用户中断、turn failed 合成 item 在返回错误、销毁连接或启动恢复线程前追加并 flush。没有文本 delta 的半截工具/MCP 调用不合成,等待完整 `rawResponseItem/completed`。 +`rawResponseItem/completed` 缺少 `item`(包括 `null`)时视为反序列化错误;该回合按异常终态收尾,历史中不会写入非法空 item。 + ## 恢复 创建新的 ephemeral thread 后,读取 `project.jsonl` 中所有 `response_item.payload`,按文件行顺序一次调用 `thread/inject_items`,再执行新的 `turn/start`。Codex 负责上下文窗口管理;注入失败直接失败,AGC 不截断、摘要或改写历史。 聊天界面只从 message item 提取 user/assistant 内容;工具 item 不再拼成 `tool: ...` 假文本。 +DirectProject 的浏览器层只负责显示和乐观状态,不再调用通用对话写入器;Rust 是该历史文件的唯一写入方。历史读写与回合累计分别位于 `agent/direct_project_history.rs` 和 `agent/direct_project_turn_history.rs`。 + ## 写入与损坏边界 写入使用 `write_all + flush`。读取时允许丢弃文件末尾一条不完整 JSON 行;中间坏行直接失败。不会对旧格式做迁移或兼容。