-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Describe the bug
Tool results are not being persisted to chat history when streamText() returns with tool calls, causing Anthropic API errors on subsequent handler loops. The chat history becomes malformed (assistant messages with tool_use blocks not followed by user messages with tool_result blocks).
Initial trigger: The corruption appears to have originated from Lambda timeouts/crashes interrupting tool result recording. When the Lambda crashed mid-tool-execution:
- Tool may have executed (e.g., Slack message posted)
- Tool result was never recorded to chat history
- Chat left in inconsistent state
- Subsequent requests to that chat failed with malformed history
Observed errors during crashes:
Runtime.UnhandledPromiseRejection: timeout
Runtime.ExitError
LAMBDA_RUNTIME Failed to post handler success response. Http response code: 403
Subsequent Anthropic errors:
messages.1: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01NkJjQdLn3bRzcxHfDGQz8h
Ongoing issue: After the initial crash-induced corruption, even NEW chats (fresh threads with different chat keys) exhibited similar behavior - tool results not being recorded properly.
Evidence from logs in a fresh chat:
🔍 [Sanitize] Only 1 messages, keeping all ← User's initial message
📤 [Slack Tool] sendMessage called...
📤 [Slack Tool] sendMessage succeeded ← Tool executes correctly
Finish reason: tool-calls
[Handler loops]
🔍 [Sanitize] Only 2 messages, keeping all ← Should be 3 messages (missing tool result)
Expected behavior:
- Tool results should be recorded as user messages after tool execution
- If Lambda crashes mid-execution, chat history should either be rolled back or gracefully handle the incomplete state on next request
Environment
- OS: macOS 25.0.0 (darwin)
- Node.js version: v22.x (Lambda runtime)
- Blink version: Latest as of Dec 16, 2025
- Installation method: bun
Additional Context
Code pattern:
agent.on("chat", async ({ messages, chat }) => {
const slackTools = slack.createTools({ client: app.client });
return streamText({
model: anthropic("claude-sonnet-4-5"),
messages: convertToModelMessages(messages, { ignoreIncompleteToolCalls: true }),
tools: {
...slackTools,
// other tools...
},
});
});Packages used:
blink@blink-sdk/slackai(Vercel AI SDK v5)@ai-sdk/anthropic
Questions:
- Is
agent.chatsupposed to automatically record tool results whenstreamTextreturns with tool calls? - Should Blink handle Lambda crashes/timeouts more gracefully to prevent chat corruption?
- Is there a way to repair/reset a corrupted chat history?
- Why do new chats (different chat keys) also exhibit tool result recording issues?