fix(agent): backfill tool name on Responses API event ordering race

output_item.added may arrive after function_call_arguments.delta when
the Responses API reorders events. The delta handler creates the HashMap
entry with an empty name, and the previous or_insert_with no-oped on
existing entries. Use and_modify to backfill the name regardless of
insertion order.

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
This commit is contained in:
npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
2026-06-10 12:33:04 -04:00
parent d22ba793a6
commit 52e1013b17

View File

@@ -732,6 +732,11 @@ impl Llm {
if !call_id.is_empty() {
tool_calls_map
.entry(call_id)
.and_modify(|e| {
if e.0.is_empty() {
e.0 = name.clone();
}
})
.or_insert_with(|| (name, String::new()));
}
}