coder / coder/blink

Handle aborted tool calls to prevent `tool_use` without `tool_result` error

Open
#43 0 comments 0 reactions 0 assignees View on GitHub
TUI
Dominant language
TypeScript
Stars
164
Forks
18
Avg merge
1m
Merged PRs (30d)
4

Description

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
```

## 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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.