## 症状 - 子代理线程页脚显示"用时 0秒"; - 任何 harness 线程关闭后重开(或从子线程切回主线程触发历史再水合),原本正确的 live 时长被替换为 0 / null,Desktop 渲染为"用时 0秒"、thinking 行 0 秒。 ## 环境 codexhost 0.5.0(main @ 1d021a6),Windows,Codex Desktop;影响**全部 7 个外部 harness**(历史再水合路径),子线程刷新变体影响 claude-code 与 omp(仅有的两个实现 `subagents.readSnapshot` 的适配器)。 ## 根因(三条独立机制,叠加) 1. **子线程刷新用同一个时间戳做 start 与 complete**:`app-server-host.ts:3543-3616`(`#refreshOpenSubagentThread`)在 `:3562` 取一次 `const emittedAtMs = Date.now()`,随后对每个变化 item 同时发 `item/started{startedAtMs: emittedAtMs}` 与 `item/completed{completedAtMs: emittedAtMs}`(`:3586-3606`)→ item 时长**按构造恒为 0**。该路径由 `subagent.transcript.changed`(`:3363-3371`)与 settle 后的 `SUBAGENT_TERMINAL_REFRESH_DELAYS_MS = [0,50,100,150]`(`:121, 3655-3663`)触发——150ms 内 4 次读取全部携带塌缩时间。 2. **历史投影硬编码 null**:`codex-ui-projector.ts:599-651`(`projectHistoricalTurn`)写死 `startedAt: null, completedAt: null, durationMs: null`(`:646-648`),reasoning 双子项 `durationMs` 亦为 null(`:637-641`);item 载荷 `durationMs: item.durationMs ?? null`(`:480/:496/:509`)对 Claude 历史恒为 null,因为 `mapClaudeSnapshot` / `mapClaudeSubagentSnapshot`(`claude-history.ts:164-341, 407-549`)**从不计算任何时长**——尽管 transcript 每条记录都带 ISO `timestamp`;`HostTurnSnapshot` 契约根本没有时间字段(`harness-adapter/src/text-session.ts:382-389`)。 3. **再水合抹掉 live 时长**:每次 `turn.completed` 后 `app-server-host.ts:3463` 置 `thread.historyHydrated = false`;下一次 head 页 `thread/turns/list` / `thread/items/list`(`:2943-2953`,例如用户从子线程导航回来)触发 `#refreshExternalThread → readSnapshot → alignSnapshot → projectHistoricalTurn`(`external-thread-repository.ts:406-466`),**把刚刚流式完成、带真实时长的 turn JSON 替换为 null 时长的历史投影**。附带不一致:历史 turn 边界只认人类用户消息(`claude-history.ts:167-176`,task-notification 被排除 `:48,60-62,88-93`),autonomous 续段 turn 会被折回原 turn 且 item id 改变。 ## 影响 - 所有 harness 的线程重开/导航后时长信息全部归零; - 与"autonomous 回放 0 秒"(另提 issue)叠加,使子代理场景下几乎没有可信时长。 ## 修复建议 1. 扩展历史契约:`HostTurnSnapshot` 与 snapshot item 增加可选 `startedAt` / `completedAt`(或 per-item `durationMs`);在 `mapClaudeSnapshot` / `mapClaudeSubagentSnapshot` 中用 transcript `timestamp` 填充(工具时长 = tool_result 时间 − tool_use 消息时间;turn = 首末记录时间)。 2. `projectHistoricalTurn` 改为输出这些真实时间而非 null,并给 reasoning 双子项设置 `durationMs`。 3. `#refreshOpenSubagentThread` 不再复用单一 `emittedAtMs`:从带时间的历史 turn JSON 取逐 item 时间,未知时才回退。 4. 再水合时若 live turn 已带真实时长,保留之(或用水合时间覆盖 null 而非反向覆盖)。
Activity
wosnxn123 commentedon Sep 6, 2026
【状态:已修复,待合并】PR: #182 (契约 commit +
fix(claude-code)+fix(host-runtime)+fix(protocol-core))修复内容(对应根因三机制):
HostTurnSnapshot增加可选startedAtMs/completedAtMs;HostReasoningItem/HostAgentMessageItem增加可选durationMs;timestamp计算 turn 首末时间与 item 时长(tool/command = tool_result−tool_use;reasoning/agentMessage = 下一记录−自身),不可计算时留空;projectHistoricalTurn改为输出真实 startedAt/completedAt/durationMs(不再硬编码 null),reasoning 双子项取 item durationMs;reasoning/agentMessage 的 wire payload 也透传 durationMs;#refreshOpenSubagentThread不再用单一 emittedAtMs:在历史 turn 的原生窗口内按逐 item durationMs 顺序铺排 startedAtMs/completedAtMs,未知时才回退到离散 now();alignSnapshot在历史投影时间为 null 时保留 live turn 的 startedAt/completedAt/durationMs 与逐 item durationMs,真实历史时间优先。验证:protocol-core 104 通过(含历史时序、reasoning twin、clamp);host-runtime 355 通过(含再水合保留用例);claude-code 225 通过(含 snapshot timings 用例)。所有 harness 受益(契约通用),无时序来源的 harness 维持现状但不再抹掉 live 时长。