Skip to content

fix(runtime): scope SendAgentMessage idempotency keys to the assistant round - #4693

Open
jolestar wants to merge 1 commit into
mainfrom
fix/issue-4691-sendagentmessage-round-idempotency
Open

jolestar wants to merge 1 commit into
mainfrom
fix/issue-4691-sendagentmessage-round-idempotency

Conversation

@jolestar

Copy link
Copy Markdown
Collaborator

Runtime concept changed

Delivery idempotency key ownership moves fully to the runtime. SendAgentMessage previously used the provider-issued tool call id as the client_idempotency_key. Gemini transports synthesize tool-use ids as {tool}__holon_gemini_call_{index}, so the first tool call of every round reuses one id. The second same-position send to the same target then hit the persisted (caller:target scope, key digest) row with a different request_digest and failed permanently with IdempotencyConflict (#4691).

Per the issue spec (#4691 (comment)), the key is now composed from the assistant round that issued the tool call:

  • ToolExecutionContext gains assistant_round_id: Option<String>, populated in the turn tool-execution loop from the same assistant_round_id source that ExternalCommandAttempt already uses.
  • The SendAgentMessage host branch passes the context through, and the delivery key becomes {assistant_round_id}#{tool_call_id} when the round is known; None falls back to the legacy bare tool call id (known collision boundary, documented in tests).

Semantics:

  • Same assistant round + same tool call (crash-recovery replay) → same key → existing Complete{replay:true} admission path; no duplicate enqueue.
  • Cross-round sends with an identical synthesized id → distinct keys → independent deliveries, no conflict.
  • Idempotency scope (caller:target) and runtime_db conflict semantics are unchanged.

Non-goals (per spec): no Gemini synthetic id changes, no responseId modeling, no scope changes, no runtime_db logic changes, no other tool idempotency changes.

Verification

  • cargo fmt --all -- --check
  • RUSTFLAGS="-D warnings" cargo check --all-targets (root, holon-tools, holon-runtime)
  • cargo test send_agent_message — 7 passed (3 new unit tests on key composition; 3 new integration tests covering same-round replay, cross-round split with Gemini-shaped ids, and the None fallback incl. the known legacy conflict boundary; existing test unchanged)
  • cargo test agent_message_delivery — 50 passed (includes idempotency_conflict_is_typed_and_does_not_admit_twice)
  • cargo test idempotency — 7 passed
  • cargo test agent_message_wait — 18 passed (one first-run parallel-load flake in agent_message_wait_retries_outbox_read_and_terminal_commit_without_synthetic_failure passed 2/2 in isolation and 18/18 on group rerun; unrelated to this change)

Fixes #4691

…t round

Gemini synthesizes tool-use ids as `{tool}__holon_gemini_call_{index}`, so
the first tool call of every round shares one id. SendAgentMessage keyed
delivery idempotency on the bare tool call id, so a second send to the same
target from the same in-round position hit the persisted (scope, key) row
with a different request digest and failed permanently with
IdempotencyConflict.

The runtime owns delivery idempotency, so the key is now composed as
`{assistant_round_id}#{tool_call_id}` when the executing round is known:
same-round crash-recovery replays keep resolving to the same delivery,
while cross-round sends with an identical tool call id admit as
independent deliveries. Without an assistant round the legacy bare
tool-call-id key is preserved (known collision boundary).

Fixes #4691

@jolestar jolestar left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

深审结论:逻辑 LGTM,CI 有一处确定性失败需修复

6 文件 +285/-4 逐文件审查完成(idempotency key 组合、无 round 回退路径、wiring、fixture 更新、单元 + 集成双套测试),修复方案与 #4691 的 Gemini 碰撞场景完全对应,未发现正确性问题。

CI 失败定性(blocking,PR 自身引入)

Rust Test (lib-a) 03:21:14Z 失败(exit 2,非测试断言失败,是分片校验拦截):

ValueError: lib compile group a contains tests owned by another group
(missing or incorrect source cfg):
tool::tools::send_agent_message::tests::delivery_idempotency_key_changes_across_rounds_for_the_same_tool_call_id,
tool::tools::send_agent_message::tests::delivery_idempotency_key_falls_back_to_the_bare_tool_call_id,
tool::tools::send_agent_message::tests::delivery_idempotency_key_scopes_to_the_assistant_round

根因:crates/holon-runtime/src/tool/host/send_agent_message.rs 新增的 mod tests 只有裸 #[cfg(test)],缺少该目录统一惯例的 shard 门控。tool 是 LIB_C_OWNERS(组 c owner),无门控的测试会编入每个 shard 的测试二进制,非 c 组的 validate_lib_group 必然失败(lib-b / misc / control 也会撞同一错误,lib-a 只是先到)。

修复(一行)

在 #[cfg(test)] mod tests 上方补门控,与同目录 timer.rs、memory_get.rs、view_image.rs 等完全一致:

#[cfg(holon_lib_test_shard = "c")]
#[cfg(test)]
mod tests {

其余核实(无同类问题)

  • runtime/tests/agent_and_tools.rs(+200):tests/mod.rs 对 agent_and_tools 已有组级 #[cfg(holon_lib_test_shard = "a")](runtime owner → 组 a),无需逐测试门控。
  • runtime/tests/work_items.rs(+2):仅为 ToolExecutionContext 新字段补 assistant_round_id: None fixture 值。
  • runtime/turn/execution.rs / tool/host/mod.rs / holon-tools/src/tool/spec.rs:wiring 与字段定义正确,无新增测试。

补上这一行后 CI 应恢复全绿,逻辑层面无需其他改动。

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant