Skip to content

Filter orphan tool calls when rehydrating database conversations#679

Draft
Anoop-Kadachi wants to merge 1 commit into
laravel:0.xfrom
Anoop-Kadachi:fix/conversation-store-orphan-tool-calls
Draft

Filter orphan tool calls when rehydrating database conversations#679
Anoop-Kadachi wants to merge 1 commit into
laravel:0.xfrom
Anoop-Kadachi:fix/conversation-store-orphan-tool-calls

Conversation

@Anoop-Kadachi

@Anoop-Kadachi Anoop-Kadachi commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #639.

DatabaseConversationStore::getLatestConversationMessages() currently rehydrates every stored tool call on an assistant row, even if that tool call has no matching tool result.

That can happen when a multi-step agent turn hits its maxSteps limit after the model has requested tools, but before those tool calls are executed. The assistant message can then be stored with pending tool_calls and no corresponding tool_results.

On the next prompt, the stored conversation history is replayed with orphan tool-use IDs. Providers such as Anthropic reject that history with:

tool_use ids were found without tool_result blocks immediately after


Changes
------------------
Filters stored assistant tool_calls during database conversation rehydration so only calls with a matching tool_results.id are replayed.
Preserves assistant text content when all stored tool calls are orphaned.
Skips fully empty assistant rows that only contain orphaned tool calls.
Adds regression coverage for mixed matched/orphan calls, orphan calls with assistant content, and orphan calls without content.

Why
--------------

This prevents one interrupted or max-step-limited agent turn from permanently corrupting future conversation replays.

@pushpak1300 pushpak1300 marked this pull request as draft June 11, 2026 18:54
@pushpak1300

Copy link
Copy Markdown
Member

can you fix conflicts ?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tool_use ids were found without tool_result blocks immediately after

2 participants