Skip to content

Commit 4861d11

Browse files
authored
Merge pull request stakpak#478 from stakpak/fix/orphaned-tool-use-on-user-message
fix: add tool_result for abandoned tool calls when user sends a new message
2 parents 8485602 + dba5f55 commit 4861d11

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

cli/src/commands/agent/run/mode_interactive.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,16 @@ pub async fn run_interactive(
363363
};
364364

365365
send_input_event(&input_tx, InputEvent::HasUserMessage).await?;
366-
tools_queue.clear();
366+
// Add tool_result for any remaining queued tool calls before clearing.
367+
// Without this, assistant messages containing tool_use blocks for these
368+
// calls would be orphaned (no matching tool_result), causing Anthropic
369+
// API 400 errors on the next request.
370+
for abandoned_tool in tools_queue.drain(..) {
371+
messages.push(tool_result(
372+
abandoned_tool.id,
373+
"TOOL_CALL_CANCELLED".to_string(),
374+
));
375+
}
367376
messages.push(user_msg);
368377

369378
// Capture telemetry when not using Stakpak API (local mode)

0 commit comments

Comments
 (0)