Repository navigation
fix(agent): hand a tool call with an unknown result back to the model - #7043
Conversation
M4n5ter
left a comment
There was a problem hiding this comment.
Review: reusing RiskAdjudicated causes 4 live-reproduced state/UI/recovery bugs; recommend a dedicated AcceptedResult variant
English
The goal of handing confirmed-ended unknown tool calls back to the model is solid, and answer to Review Question #1 is a clear yes—use a dedicated AcceptedResult / AcceptedToolResult variant rather than reusing Fact::Blocked + Fact::RiskAdjudicated(RecordExternalObservation) + magic JSON key "unknownOutcome". Overloading RiskAdjudicated and LocalToolReturned(Unknown) causes four concrete, live-reproduced bugs:
1. [Major] session_catalog live projection vs rebuild diverges and permanently marks completed Runs as unknown_effects = true (live-reproduced)
- Locations:
index.rs#L117-L127,fold.rs#L162-L181,patches.rs#L352. - Path & Repro: After
Action::SettleUnknown,tool_pendingbecomesfalse(agent_tools.pending = 0), so the next live fact loads onlypending = 1tools and flipsagent_catalog_runs.unknown_effectsback to0. Onstore.rebuild(run)orcatalog.rebuild(session), full replay reloads the settled tool, andsession_catalog/index.rs:117-127matchesOperationOutcome::Unknownwithout excludingt.unknown_outcome_accepted(). Repro on realRootStore/Store/SessionCatalogprintedafter_settle=true, after_complete=false, after_run_rebuild=true, after_cat_rebuild=true—permanently blockingowner/patches.rs:352and polluting session list status.
2. [Major] Reusing RiskAdjudicated leaks raw internal JSON and unresolved sha256: refs to UI/SessionRead/maka://.../tool-results/... and leaves Recall empty (live-reproduced)
- Locations:
driver.rs#L2214-L2241,tool_result_source.rs#L761-L768,index.rs#L391. - Path & Repro:
ToolResultAcceptedoutranksLocalToolReturned/OperationObservedin history pairing (service/history/source.rs:886-910), andtool_result_source.rs:761passes"risk_adjudicated"straight through without dereferencingdecision.evidence. Repro viaToolResultReader::livereturned raw internal JSON containing"digest":"sha256:..."with no diagnostic text;recall/index.rs:391also skipsRiskAdjudicated.
3. [Major] Failed CellWait during driver retirement (retiring == true) is misclassified as an ended local tool call and triggers bogus Action::SettleUnknown (live-reproduced)
- Locations:
driver_effects.rs#L568-L590,driver.rs#L1841,reconcile.rs#L385-L399. - Path & Repro:
view.original_cell(&wait_tool)is alwaysNone(Cells belong toexec, notwait). WhenCellWaithitsOutcomeUnknownwhileretiring == true,driver.rs:1841skips writingBlocked(OriginalAdmissionUnknown), andsettle_alldeliberately publishesLocalToolReturned(Unknown)to preserve logical Cell uncertainty (driver_cells.rs:1441). On recovery,reconcile::unknown_outcomesees noOriginalAdmissionUnknownand nooriginal_cell, returningAction::SettleUnknown(reproduced by running the PR's owndriver/tests.rsscenario withretiring = true).
4. [Major] User Stop during a local tool returning OutcomeUnknown permanently locks the session (blocks_followup() == true) (live-reproduced)
- Locations:
reconcile.rs#L364,fold.rs#L531-L590. - Path & Repro: Real local tools (e.g. CUA click/scroll and stdio MCP after process teardown) return
ToolError::OutcomeUnknownon cancellation. Becausereconcile.rs:364rejectsSettleUnknownwhenview.stopped == true, the tool falls intoLookup->OriginalAdmissionUnknown->Terminal::Failed.fold.rs:531-590only exempts HostUnknown + Confirmed, soblocks_followup()staystrueand permanently rejects follow-up messages withOriginalOperationUnsettled.
Design & Test Quality
- Design: Add a dedicated
AcceptedResult+AcceptedToolResultvariant carrying text diagnostics (mirroringProviderOutcomeUnknownandRejected { diagnostic }) and unwrap it intool_result_source.rsandrecall/index.rs. SplitDispatchSourceintoOrdinary | CellExec | CellWaitsodriver_effects.rsdoesn't re-querystate.frontieror overloadLocalToolReturned(Unknown). - Tests (673 / 927 = 72.6%): Heavy scaffolding and white-box implementation mirroring—
driver/tests.rs(+330) copies internaldriver.rslines and opens 5pub(in crate::driver)holes inwitness.rs, while the newdriver_model.rsbranch has 0 test coverage (contradicting the PR Verification note). Recommend deletingdriver/tests.rs, slimmingreconcile/tests.rs, and writing focused behavioral tests covering the state transitions + an end-to-endRigtest throughDriverModel,ToolResultReader::live, andstore.rebuild/catalog.rebuild.
简体中文
把已确认结束但结果未知的工具调用交回给模型这个方向是对的,针对 PR Review Question #1,答案很明确:应该新增独立的 AcceptedResult / AcceptedToolResult 变体,不要为了避开 facts schema 改动而硬借 Fact::Blocked + Fact::RiskAdjudicated(RecordExternalObservation) + 魔法 JSON key "unknownOutcome"。借壳复用与一词两用直接带出了 4 个实跑复现的可达 bug:
1. [Major] session_catalog live 投影与 rebuild 分歧,重建后把已完成 Run 永久污染成 unknown_effects = true(实跑复现)
- 位置:
index.rs#L117-L127、fold.rs#L162-L181、patches.rs#L352。 - 路径与复现:
Action::SettleUnknown后agent_tools.pending = 0,后续 live fact 只加载pending = 1工具把unknown_effects翻回0;但一旦触发store.rebuild或catalog.rebuild,全量重放重新载入该 tool,而session_catalog/index.rs:117-127匹配OperationOutcome::Unknown时没排除t.unknown_outcome_accepted()。在真实RootStore/Store/SessionCatalog实跑输出after_settle=true, after_complete=false, after_run_rebuild=true, after_cat_rebuild=true,直接卡死owner/patches.rs:352并污染会话列表状态。
2. [Major] 复用 RiskAdjudicated 导致 UI/SessionRead/maka://.../tool-results/... 吐出裸内部 JSON 与 sha256: 指针,且 Recall 索引留空(实跑复现)
- 位置:
driver.rs#L2214-L2241、tool_result_source.rs#L761-L768、index.rs#L391。 - 路径与复现:历史配对中
ToolResultAccepted优先级压过LocalToolReturned/OperationObserved,而tool_result_source.rs:761对"risk_adjudicated"不解引用decision.evidence。实跑ToolResultReader::live直接返回含"digest":"sha256:..."的原始内部 JSON(不含诊断文案);recall/index.rs:391也直接跳过RiskAdjudicated。
3. [Major] Driver 退场(retiring == true)期间失败的 CellWait 会被误判为普通已结束本地调用并误触发 Action::SettleUnknown(实跑复现)
- 位置:
driver_effects.rs#L568-L590、driver.rs#L1841、reconcile.rs#L385-L399。 - 路径与复现:
Cell归属于exec而非wait,view.original_cell(&wait_tool)恒为None。retiring == true时driver.rs:1841跳过写OriginalAdmissionUnknown,随后settle_all有意落盘LocalToolReturned(Unknown)保留 Cell 逻辑不确定性;下次恢复时reconcile::unknown_outcome两个启发式条件全被绕过,直接返回Action::SettleUnknown(用本 PR 的driver/tests.rs场景改为retiring = true已实跑复现)。
4. [Major] 用户点 Stop 时本地工具取消返回 OutcomeUnknown 会永久锁死会话(blocks_followup() == true)(实跑复现)
- 位置:
reconcile.rs#L364、fold.rs#L531-L590。 - 路径与复现:CUA 原生点击/滚动与 stdio MCP 在取消后都会返回
ToolError::OutcomeUnknown。reconcile.rs:364在view.stopped时拒绝SettleUnknown退回Lookup->OriginalAdmissionUnknown->Failed,而fold.rs:531-590只放行 HostUnknown + Confirmed,导致blocks_followup() == true永久拒收后续消息。
设计与测试建议
- 设计:仿照现成的
AcceptedResult::ProviderOutcomeUnknown和AcceptedToolResult::Rejected { diagnostic }加专用变体并在tool_result_source.rs/recall/index.rs解包诊断文本;将DispatchSource拆为Ordinary | CellExec | CellWait,省掉driver_effects.rs的异步frontier反查并彻底消掉LocalToolReturned(Unknown)的语义重载。 - 测试(673 / 927 = 72.6%):
driver/tests.rs(+330 行)大量复刻私有实现并给witness.rs开了 5 处可见性后门,而driver_model.rs新增代码实际为 0 覆盖(与 PR Verification 描述不符)。建议删掉driver/tests.rs、精简reconcile/tests.rs,重构为状态转移表 + 一条真正跑通DriverModel、ToolResultReader::live与store/catalog.rebuild的端到端行为测试。
48bfa05 to
9bf8623
Compare
|
Thanks — rebased onto current
|
A call that ended without a known result is accepted as OutcomeUnknown and goes back to the model as error text with its diagnostic; it is never run again. A Host operation has ended once its cleanup is confirmed. A local call counts as ended only when this activation's dispatch recorded the unknown return, because a failed Cell wait records the same fact; after a restart such a call keeps its existing recovery. Accepting the result resolves the open OperationUnknown blocker, settles the call for admission, the catalog and Recall, and also applies after a Stop, so follow-up messages are not blocked. Generated-by: Claude Code (Claude Opus 5.5)
9bf8623 to
4b0266c
Compare
Summary
When a tool call ended but its effect was unknown (a Host operation that reported
Unknownwith confirmed cleanup, or a local call that returnedOutcomeUnknown), the Run stopped on a blocker and failed. The model never saw what happened, and the user saw a failed turn.Now such a call is handed back to the model as its result: "The call ended, but its result is unknown: . It may or may not have taken effect. Check the current state before deciding what to do next; do not simply repeat the call." The call is never run again.
AcceptedResult::OutcomeUnknown. The model-facing result isAcceptedToolResult::OutcomeUnknown { diagnostic }, and the model gets the diagnostic as error text. The fold accepts it only with evidence: anUnknownreceipt with confirmed cleanup, or a localUnknownreturn for a call without an original Cell. Acceptance resolves an openOperationUnknownblocker for the call.unknown_effects. History and Recall show the diagnostic text.OutcomeUnknownis first recorded durably as a returned call with settlementUnknown, then its resources are released.OutcomeUnknownis settled, so it does not block follow-up messages.execkeeps its own recovery.blocks_followupandblocks_continuationare unchanged.Trade-offs
Unknown(LocalToolReturnedwith settlementUnknown). The stored fact alone cannot tell them apart. So the engine settles a local call only when the dispatch in the current activation recorded that return. If the Host restarts between the return and the settlement, the call falls back to the existing recovery and the Run fails as it does today. A durable signal would close this gap, but it needs a new settlement value or a check on the reserved tool namewait.DispatchSourceis nowOrdinary | CellExec | CellWait, so the Host can tell anexecfrom an ordinary tool without reading the frontier.Not covered
A remote MCP call whose result is unknown still invalidates the connection, so every later Run that uses it fails (separate issue).
AI use
Tool(s) and scope: Claude Code (Claude Opus 5.5) found the failure path, wrote the change and the tests, and made the review changes.
Checklist
Does this PR entail a change in behavior?