Skip to content

fix(acp): 保留自定义 agent 的会话分叉历史 - #1153

Open
ikelvingo wants to merge 3 commits into
spacering-net:mainfrom
ikelvingo:pr/custom-agent-fork-history
Open

ikelvingo wants to merge 3 commits into
spacering-net:mainfrom
ikelvingo:pr/custom-agent-fork-history

Conversation

@ikelvingo

Copy link
Copy Markdown

问题

使用自定义 ACP agent 分叉会话时,新会话的 Codeg transcript 可能只包含头部。分支打开后看不到历史,再次从该分支分叉时,也可能因为 Codeg 找不到所选轮次而失败。

修改

  • 使用 agent 提供的消息 ID 定位自定义 agent 的分叉点;无法定位所选轮次时返回错误,避免静默地从会话末尾分叉。
  • 自定义 agent 分叉成功后,加载子会话并暂存回放历史,再通过该会话的 transcript 写入队列发布。
  • 解析 ACP transcript 时保留 agent 消息 ID,并在分叉请求进行中阻止重复操作。
  • 保持内置 agent 原有的分叉行为。

验证

在包含此 patch、基于 v0.44.0 的合并源码上:

  • 服务器与 MCP release 构建通过。
  • ACP fork 单元测试:28 项通过。
  • ACP transcript 单元测试:32 项通过。
  • 前端生产构建通过。
  • 消息列表和 turn-stats 相关前端测试:93 项通过。

PR 候选包含与上述合并源码相同的 8 个代码文件,未包含本地交接文档和历史合并提交。尚未针对该候选运行完整测试套件,也没有自动化的「分叉 → 加载 → 继续对话 → 再次分叉」集成测试。

兼容性验证

已针对 DSH(@openma/deepseek-harness-acp)和 omp 检查分叉元数据及历史回放顺序。DSH 还通过 ACP 探针验证了子会话历史加载、工具调用回放、继续对话及再次分叉。

希望以 Draft PR 形式征求上游对自定义 adapter 兼容范围和回放完成边界的意见。

ikelvingo and others added 3 commits November 14, 2026 09:39
Review fixes on top of the custom-agent fork history change.

- Hold the fork reply for transcript-owned agents until
  hydrate_forked_transcript is done. The frontend refetches the branch
  the moment acpFork resolves; replying before the session/load replay
  landed showed the branch empty with nothing to refetch it later.
- Send the hydration session/load only to agents that advertise
  loadSession (ACP MUST NOT; the reconnect ladder already gates it), and
  bound it so an agent that never answers cannot hold the fork open.
- Keep "fork from here" at the thread tail for custom agents: an unnamed
  tail turn tail-forks (that IS the fork point), and the frontend asks for
  an explicit tail fork instead of sending a live-… id the backend can
  only refuse.
- Refuse a replay publish while records queued ahead of it are still
  deferred, so they cannot land after the replay.
- Repair null usage counts in the fork drain like the ladder does; scan
  the current session's transcript off the async workers; restore the
  read_transcript doc comment; drop the useless .into() clippy rejects.
hydrate_forked_transcript returned early on three paths after (or around)
sending session/load without draining the replay already routed to the
child session: a load the agent refused, a load that timed out, and a
sidecar that could not be opened after a successful load. The live loop
then read those frames as the agent talking now — rendered as a reply
nobody asked for, and, for frames that trailed a timed-out load into the
first prompt, recorded into the branch's transcript.

- Open the staging sidecar before sending the load, so failing to stage
  sends no load and leaves no replay in flight.
- A refused load is still an answer that bounds its replay: drain and
  discard it, publish nothing.
- An unanswered load bounds nothing, so end the connection instead of
  entering the live loop; the held fork reply drops and the fork reports
  a failure, leaving the conversation on the session it forked from.

Tests drive the three paths through the fork harness and assert the
replayed text never surfaces as live output; the refused-load test was
checked to fail with the old early return restored.
@xintaofei

Copy link
Copy Markdown
Collaborator

结论:方案成立。在本分支上叠加两个修复提交后,评估为可作为生产候选;合入前建议用真实自定义 adapter 做一次 UI 冒烟。

方案:用 agent 自己的 session/load 回放补齐分叉后由 codeg 持有的 transcript(与重连阶梯一致);自定义 agent 以流里的 messageId 作为分叉点。

已修复:

  1. 【高】分叉 reply 早于回放落盘:handle_fork_or_exit(src-tauri/src/acp/connection.rs)在 resume/load 之前就回复了;前端 acpFork 一返回就 refetchDetail,读到只有 header 的 transcript,当前标签显示空分支。现在对 transcript 由 codeg 持有的 agent,等 hydration 结束、SessionStarted 之前再回复。
  2. 【中】未检查 loadSession 就发 session/load(ACP 规定 MUST NOT)。现在透传 supports_load,并给 load 加 30s 上限。
  3. 【中】hydration 失败路径把回放漏给实时循环(独立评审发现):load 被拒、超时、sidecar 打开失败三条路径都没有排空已路由的回放帧,界面会冒出凭空的回复,超时时迟到的帧还会记进第一轮。现在 sidecar 在发 load 前创建,失败则不发;load 被拒仍排空并丢弃;load 无应答则结束连接,fork 报失败,会话行留在父会话。
  4. 【中】自定义 agent 丢了尾部分叉(线程末尾的 live-… id 被拒):前端 forkTurnIdFor 改发 null;resolve_fork_point(src-tauri/src/acp/fork.rs)对末尾无名轮次返回 Ok(None),非末尾仍拒绝。
  5. 【低】写入被 defer 时 Publish 仍会 rename;drain 缺 fix_usage_update_nulls;全文件扫描移入 spawn_blocking;修正注释与日志措辞。
  6. 原 PR 过不了 clippy --all-targets -D warnings(测试里的 .into()),已修。

验证: 新增 5 条端到端分叉测试(成功回放、未声明 loadSession、load 被拒、load 无应答、sidecar 无法创建),以及 transcript/分叉点单测;关键测试已确认在回退对应修复后失败。完整门禁:桌面/服务器 lib、集成、bin 与 doc 测试全部通过,唯一失败是与本改动无关的 codesign 环境用例;桌面/服务器/mcp 的 check 与 clippy 通过;前端 lint、build 通过;vitest 11674 项通过,另有 2 个无关文件在全量负载下超时,单独运行均通过。独立评审共两轮:第一轮提出第 3 条,修复后复审 APPROVED。

仍需维护者判断: Trae/CommandCode/MiniMaxCode 若声明了 fork+load 也会被 hydrate(与「内置 agent 行为不变」不完全一致,但修的是同一缺陷);fork 后先 resume 再 load,可能让部分 adapter 多重启一次 MCP server;尚无真实 adapter 的 UI 端到端验证。

The changes were pushed to this pull request (7 files, +732/-96).


🤖 Generated with Codeg

@ikelvingo
ikelvingo marked this pull request as ready for review November 15, 2026 15:20
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.

2 participants