Skip to content

fix: 修复被打断 run 的悬空 tool_calls 与会话自愈(issue #304) - #335

Merged
Xingkai98 merged 11 commits into
masterfrom
fix-issue-304-dangling-tool-calls/2026-11-02
Nov 2, 2026
Merged

Xingkai98 merged 11 commits into
masterfrom
fix-issue-304-dangling-tool-calls/2026-11-02

Conversation

@Xingkai98

Copy link
Copy Markdown
Owner

背景

issue #304:run 在 assistant tool_calls 已写入、tool_result 未写回之间被打断(重启 / 取消 / 群聊成员 240s 超时),消息链留下悬空 tool_use;下一次请求被 Anthropic/DeepSeek 400 拒绝,会话永久不可用。

改动

  • run 边界自愈:AgentLoop._run 起点(resume 重建后)调用纯函数 repair_tool_call_pairing;run() 的 finally 第一条语句做 best-effort 补配对(不覆盖 SIGKILL/断电)。
  • 合成结果:确定性、固定前缀 [asterwynd:synthetic-tool-result] Error:、携带原 tool_call_id;幂等、正常链零改动;Anthropic 序列化 is_error: true,OpenAI 用 Error: 文本前缀。
  • Case B:orphan-before / misplaced-after 只 warning、不重复合成,不承诺修复畸形链。
  • 可观测:run 起点发 tool_pairing_repaired 事件 + trace;finally 修复同步记录 source="finally" trace。
  • resume 早期取消:消息重建与 todos/skills/user_system_prompt 同步恢复移到 set_mode await 之前。
  • 诊断性:HTTP >=400 先读取完整 body 并附加到异常;trace/Web 展示有界 detail;群聊共享日志只写 HTTP <status> + 已知错误类型枚举,不写 error.message/原始 body。
  • 规格/文档:agent-runtime / observability / web-ui spec delta 已施加;ADR-0009;architecture / testing-guide 同步。

验证

  • 新增/改造测试 43 条(纯函数、真实链路、resume、同进程重试、finally trace、web/群聊、诊断、前端 JS)。
  • 定向/回归测试:266 passed(实现提交时);审阅者复跑受影响集 42 passed。
  • 全量 pytest:4485 passed / 9 skipped / 4 failed;4 条均为既有基线/环境项(TestFindScopeRoot ×2、test_task_output_truncated 在干净 origin/master 复现;test_history_redraw_drops_pending_tool_rows 为本机 Playwright 计时 flake,单跑通过)。
  • OpenSpec strict validate 29/29;瘦 checker exit 0;benchmark smoke EXIT=0(72 tasks,fake agent 4 passed/68 failed 属接线验证预期)。
  • 独立 grill + 设计对抗环 + 实现后独立审阅均 PASS;witnessloop check 通过(三份 manifest 已绑定)。

关联

Closes #304(合入后补完成说明 comment 并关闭)。

🤖 Generated with Claude Code

CI and others added 11 commits November 1, 2026 13:04
用真实 AgentLoop + SessionStore + AnthropicLLM 序列化路径,在工具执行中途
cancel run,再从快照恢复发起下一次请求;协议校验 fake provider 返回 400。
当前为失败测试,供后续加载/续跑自愈修复验证。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- proposal / design / tasks / spec delta(agent-runtime、observability、web-ui)
- RIR full 档:Anthropic 配对协议、LangGraph/pydantic-ai/ADK/OpenAI Agents/Bernstein 对照
- 独立 grill + 设计对抗环:8 项 + 3 项 deferred 全部 verified,出口 PASS
- backlog 登记第二十二批(issue #304)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- AgentLoop:run 起点持久化自愈 + finally best-effort 补配对;resume 同步状态在 set_mode await 前恢复
- 合成确定性 tool_result(固定前缀、幂等、Anthropic is_error、OpenAI Error 前缀)
- tool_pairing_repaired 事件 + trace;正常链零改动
- HTTP >=400 body 附加到异常;trace/Web 展示有界 detail;群聊共享日志固定状态+错误类型枚举
- 测试:真实链路失败测试转绿,新增纯函数/恢复/中断/诊断/前端用例

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- agent-runtime / observability / web-ui delta 施加进 current specs
- ADR-0009 记录 run 边界修复、合成 vs 丢弃、finally best-effort 边界
- architecture / testing-guide 补中断自愈事实
- 补 web resume、群聊超时、run-source 事件、哨兵与前缀碰撞测试

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- 空 body HTTP 错误仍携带 status_code(群聊摘要显示 HTTP <status>)
- 后续无状态码 error 不清空已有 HTTP 摘要
- 补事件 id 边界、OpenAI 逐 id 配对、repair→compact、空 body 测试
- tasks 1.2.1 文件名同步

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

【feature】被打断的 run 留下悬空 tool_calls → 会话每次请求 400 永久卡死(需加载/续跑自愈)

1 participant