Skip to content

Handle aborted tool calls to prevent tool_use without tool_result error #43

@blinkagent

Description

@blinkagent

https://codercom.slack.com/archives/C093W1J73V0/p1761009411681159

Problem

When the agent is stopped while making an MCP call, a tool_use block is written but no corresponding tool_result block exists (because the call was canceled). This causes the conversation to be broken forever with the error:

`tool_use` ids were found without `tool_result` blocks immediately after <the id> 

Context

This appears to be a state management issue where messages are stored even when tool execution is incomplete or canceled. The conversation becomes permanently broken after this happens.

Potential Solutions

  1. Don't store messages unless we have the result - Only persist the message once the tool_result is available
  2. Add a "cancelled" result block - When cancellation occurs, inject a tool_result block with a cancellation error
  3. Research API best practices - Investigate if there's an expected way to handle this according to the API specification

Impact

This breaks the conversation flow permanently and requires the user to start a new conversation or manually delete the tool_use block from the context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions