Repository navigation
Conversation
|
Spotless violation on my pushed file (the server-side-constructed content skipped the local format pass — the standard step I keep re-learning). Fixed in 3d4c5a3 (formatting only, verified the fix content is intact). Rerun should be green. |
|
Two correctness issues remain in
Please add regressions for mixed valid/stale blocks, all-stale results accompanied by user text, a later legitimate result for a still-running call, and pending interaction/reply-id handling. Reviewed head: |
转录重放型客户端(AG-UI / CopilotKit 式)会连同新消息重发早先轮次已 消费的 tool result。validateAndAddToolResults 对 pending 集合之外的 任何 id 都抛 IllegalStateException,而异常发生在消息入上下文之前—— pending 轮原样留存,陈旧结果也留在客户端转录里,此后该会话每条消息 都以同样方式失败。 修复:在进入任何"调用方提供了结果"的判定之前,把不属于 pending 调用 的结果块从输入中剔除(按块剔除,保留当前结果、用户文本与其他内容)。 评审意见(agentscope-ai#3766)对应: - P1 陈旧块被过滤却仍持久化:剔除作用于输入本身,持久化的 msgsToPersist 与发布的事件都不再包含陈旧结果。 - P2 全陈旧重放被当成取消:不再有"全陈旧即合成错误结果"的分支。 - 输入只含陈旧结果(纯重放):调用方对 pending 调用没有任何新指示, 因此不恢复执行、不修补、不写入,直接返回 TOOL_SUSPENDED——pending 调用保持原样。(不能走既有的"无输入则 resume"路径:那会重新分发 pending 调用。) - 陈旧结果附带用户文本:剔除后等同"未提供结果"——pending 调用保持 pending;只有显式开启 enablePendingToolRecovery 时才由既有恢复 逻辑取消它们,且用户文本照常进入上下文。 其余校验不变:重复 id、部分结果附带文本仍然报错。 请求记账:挂起的外部调用是一个 pending 请求,以 RequireExternalExecution 的 replyId 标识。剔除陈旧结果不影响它——请求仍由真实结果、在同一 replyId 下恰好结算一次;纯重放不发布 ExternalExecutionResultEvent, pending 请求及其 replyId 原样保留。 测试:ReActAgentStaleToolResultTest 共 15 例——混合有效/陈旧(跨消息 与同消息)、陈旧结果不进入模型输入、纯重放不报错且不重新分发 pending 调用、陈旧结果附带用户文本(未开/已开 recovery)、仍在运行的调用事后 收到真实结果、结果事件与 replyId 记账(混合提交/纯重放/被拒绝的提交/ recovery 取消)、重复 id 与部分结果附带文本仍被拒绝。
175995f to
1a88c47
Compare
|
@juruoO-o Both issues are addressed in P1 — stale blocks were filtered but still persistedStale results are now removed from the input itself, before any "the caller provided results" decision is taken. What gets persisted and what gets published on P2 — an all-stale replay cancelled pending work and dropped the inputThe "all stale → synthesize error results for every pending call" branch is gone. Ignoring a replay and cancelling calls are now separate things:
One detail worth flagging on the pure-replay row: I first routed it through the existing "no input → resume" path, on the reasoning that it is equivalent to the caller having sent nothing. It is not — that path dispatches the pending calls again, so every replay would re-run the tool. A regression with a dispatch counter caught it ( Regressions you asked for
With the removal of stale results disabled, 11 of the 15 fail; the other four guard behaviour that did not change.
One policy point is yours to decide: I kept "stale results + user text" as an error unless |
Fixes #3043
Problem
Transcript-replaying clients (AG-UI, CopilotKit-style) resend results that were already consumed in an earlier round, together with the new message.
validateAndAddToolResultsthrew on any result id outside the pending set, and it threw before anything reached the context: the pending round survived unchanged, the stale result stayed in the client's transcript, and every later message in the thread failed the same way.Fix
Stale results are removed from the input itself, before any "the caller provided results" decision is taken. Everything downstream then behaves exactly as if they had never been sent: nothing stale is persisted or published, and the remaining checks (duplicate ids, partial results with text) are unchanged.
A stale result says nothing about the calls that are still pending, so ignoring it is kept apart from cancelling them:
TOOL_SUSPENDED, the pending calls stay as they areenablePendingToolRecovery(opt-in), with the user's text kept; without it the submission is rejected with an error naming the pending callsA pure replay deliberately does not take the existing "no input → resume" path: that path dispatches the pending calls again.
Tests
ReActAgentStaleToolResultTest, 15 cases: mixed valid/stale blocks in separate and in the same message; all-stale results with user text, recovery off and on; a later legitimate result for a still-running call; no re-dispatch on replay; request/result bookkeeping under theRequireExternalExecutionEventreply id (mixed submission, pure replay, rejected submission, recovery cancellation); the unchanged duplicate-id and partial-results-with-text checks.With the removal of stale results disabled, 11 of the 15 fail; the other four guard behaviour that did not change.