fix: let direct models continue after tool execution failures

Return ordinary tool exceptions as paired error results so the model can decide how to recover. Preserve cancellation, existing recovery guidance, and failed tool activities without adding automatic retries or retry limits.

Validate all three text protocols with real process execution and cover bounded errors and cancellation. Focused tests: 161 passed, 1 skipped; typecheck and lint passed. Full suite: 6230 passed, 87 skipped, 1 Obsidian temporary-directory assertion failed.

Release note: Direct-model conversations can continue after a tool fails, allowing the model to use the reported error to choose its next step.
This commit is contained in:
mesalogo
2026-10-05 15:20:17 +08:00
parent 0eaaa85d4c
commit 56b8b10d46
5 changed files with 259 additions and 16 deletions
+18 -1
View File
@@ -10,7 +10,24 @@
| 日期 | 2026-09-09 |
| 关联入口 | [直连模型 Agent 能力](./README.md) |
## 当前结论
## 2026-10-05 工具执行异常回传
- 普通工具执行异常也返回模型,保留失败活动与错误详情,由模型决定后续行动;规则见
[失败恢复](./technical-design.md#读取与搜索失败恢复)。请求取消与 `AbortError` 仍停止循环。
- 新增三协议回归使用真实 Provider、进程服务和文件系统:无效 cwd 产生 `ENOENT`,
下一次模拟模型请求收到对应失败结果,再调用同一工具执行真实命令成功。另覆盖错误详情
有界处理和取消;未使用真实外部模型,不作为桌面 UI 或真实模型自主决策验收。
- 修复验证中发现 `DOMException` 不一定满足 `instanceof Error`,改为按错误名称识别取消;
取消测试在意外后续模型请求时立即失败,避免模拟响应无限重复耗尽内存。
- `model-runtime.test.ts`、`model-tool-provider.test.ts`、`direct-model-process-service.test.ts`:
161 项通过、1 项跳过。`npm run typecheck`、`npm run lint` 通过。
- 全量 `npm test`:6,230 项通过、87 项跳过、1 项失败;失败为
`obsidian-electron.test.ts:29` 要求临时目录在仓库外,与本次按仓库规范设置
`TEMP`/`TMP` 到仓库 `temp/` 冲突。未修改该测试,全量不能记为通过。
- 托管 SSH 使用远端 OpenCode/Continue 的工具循环,不运行本次修改的 `ModelAgentRuntime`;
不涉及 gbagent 生产路径。临时目录创建、保留和清理逻辑未修改。
## 既有本机验收结论
本机生产路径已经完成源码接线:直连模型 Execute 可运行平台 Shell,Ask/Execute 均可按
父模式委派单层编程 Subagent;长输出可通过 `output_read` 续读。OpenCode、Continue、
@@ -98,8 +98,11 @@ type BuiltinModelToolSummary = {
`EISDIR`、`EACCES`、`EPERM`、`ELOOP`、`ENAMETOOLONG` 等已列明的文件系统错误。
Runtime 向模型返回 `{ ok: false, recoverable: true, error, nextAction }` 的 JSON 文本工具结果,
工具活动记为 `recoverable`,继续工具循环,由模型修正路径、分页参数、glob 或搜索表达式;
提示不得原样重复失败参数。取消、远端断线、失效工作区、缺失 rg 可执行文件及未分类的内部
错误继续向外传播,不转为可恢复结果。
提示不得原样重复失败参数。其他工具执行异常(包括进程启动或输出文件的 `ENOENT`、
远端断线、失效工作区、缺失 rg 可执行文件)由 Runtime 返回 `{ ok: false, error }`,
工具活动记为 `failed`,错误详情使用已有有界处理并保留 cause 信息。失败结果继续进入
下一次模型请求,由模型决定重试、调整方法或说明失败;不自动重放工具,也不增加重试次数限制。
Anthropic 的失败结果同时设置 `is_error: true`。请求取消及 `AbortError` 仍向外传播并停止循环。
`workspace_read_text` 仍只接受工作区内相对路径。搜索原样接受 rg 参数及账号可访问的路径,
不增加逐工具授权;保留 `--no-config` 默认参数、原生退出码、取消和分页,不提升系统权限。