issue #189 grill定案——用asyncio.shield保护delegate task的in-flight工具调用 #196

Open
KumaAgent wants to merge 1 commit from feat/189-delegate-task-cancellation-shield into main
Member

Summary

grill issue #189(评估:task.cancel()可能中断已生效副作用工具调用)定案:asyncio.shield() 保护delegate task中正在执行的工具调用,不被取消打断

核实确认 task.cancel() 是真正的 asyncio.Task.cancel(),可在 subagent.py::run_delegated_task 循环体任意 await 点(含 call_host_tool 工具调用执行中途)抛出 CancelledError。零host接入意味着当前没有真实副作用工具,但 issue #188(已合并)新增的"真人活跃"自动抢占触发源大概率复用同一条取消路径,且不经模型识别、drive_tick周期性运行暴露窗口更大——"取消撞上工具调用执行中"这个场景的触发概率会实质性上升,现在就把保护机制设计好。

asyncio.shield() 包住 call_host_tool 那次 await:取消时外层循环仍会立刻识别取消并停止继续,但被shield保护的工具调用本身会在后台跑完、不被从中打断,确保副作用完整生效而非半途而废。不需要host配合(不用给工具标记"是否有副作用"),也不需要重新设计取消入口。

issue #189 已从评估票转为实现票。

Changes

ADR-0020 追加一条更新节记录这次定案,append-only。

Test plan

  • 纯文档变更,无代码改动(代码改动留给 issue #189 实现票)
  • issue #189 标题/正文/标签已核对:已从"待评估"改为"智能体就绪",正文含具体代码改动位置+精确AC

🤖 Generated with Claude Code

## Summary grill issue #189(评估:task.cancel()可能中断已生效副作用工具调用)定案:**用 `asyncio.shield()` 保护delegate task中正在执行的工具调用,不被取消打断**。 核实确认 `task.cancel()` 是真正的 `asyncio.Task.cancel()`,可在 `subagent.py::run_delegated_task` 循环体任意 await 点(含 `call_host_tool` 工具调用执行中途)抛出 `CancelledError`。零host接入意味着当前没有真实副作用工具,但 issue #188(已合并)新增的"真人活跃"自动抢占触发源大概率复用同一条取消路径,且不经模型识别、drive_tick周期性运行暴露窗口更大——"取消撞上工具调用执行中"这个场景的触发概率会实质性上升,现在就把保护机制设计好。 用 `asyncio.shield()` 包住 `call_host_tool` 那次 await:取消时外层循环仍会立刻识别取消并停止继续,但被shield保护的工具调用本身会在后台跑完、不被从中打断,确保副作用完整生效而非半途而废。不需要host配合(不用给工具标记"是否有副作用"),也不需要重新设计取消入口。 issue #189 已从评估票转为实现票。 ## Changes ADR-0020 追加一条更新节记录这次定案,append-only。 ## Test plan - [x] 纯文档变更,无代码改动(代码改动留给 issue #189 实现票) - [x] issue #189 标题/正文/标签已核对:已从"待评估"改为"智能体就绪",正文含具体代码改动位置+精确AC 🤖 Generated with [Claude Code](https://claude.com/claude-code)
grill issue #189时核实:task.cancel()是真正的asyncio.Task.cancel(),可在subagent.py
run_delegated_task循环体任意await点(含call_host_tool执行中途)抛出CancelledError。
零host接入意味着当前没有真实副作用工具,但issue #188新增的自动抢占触发源会让"取消撞上
工具调用执行中"这个场景的触发概率实质性上升,现在就把保护机制设计好。

决策:用asyncio.shield()包住call_host_tool那次await——取消时外层循环立刻识别取消并
停止,但被shield保护的工具调用本身在后台跑完不被打断,确保副作用完整生效。不需要host
配合、不需要重新设计取消入口。issue #189已从评估票转为实现票。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/189-delegate-task-cancellation-shield:feat/189-delegate-task-cancellation-shield
git switch feat/189-delegate-task-cancellation-shield

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff feat/189-delegate-task-cancellation-shield
git switch feat/189-delegate-task-cancellation-shield
git rebase main
git switch main
git merge --ff-only feat/189-delegate-task-cancellation-shield
git switch feat/189-delegate-task-cancellation-shield
git rebase main
git switch main
git merge --no-ff feat/189-delegate-task-cancellation-shield
git switch main
git merge --squash feat/189-delegate-task-cancellation-shield
git switch main
git merge --ff-only feat/189-delegate-task-cancellation-shield
git switch main
git merge feat/189-delegate-task-cancellation-shield
git push origin main
Sign in to join this conversation.
No description provided.