wavetermdev/waveterm · error

tool call with ID not found in chat

Error message

tool call with ID %s not found in chat %s

What it means

After locating the chat, UpdateToolUseData scans all native messages for a tool call whose ID matches toolCallId. If the whole chat is traversed without a match, it concludes the tool call does not exist in that chat and returns this error.

Solutions

  1. Confirm the toolCallId exists in this chat's messages (it may have been removed by RemoveToolUseCall)
  2. Use the exact tool_use id from the assistant message's tool_use block
  3. Check you are passing the correct chatId for that tool call

Example fix

// before
err := anthropic.UpdateToolUseData(chatId, staleToolCallID, data)
// after
if err := anthropic.UpdateToolUseData(chatId, toolCallID, data); err != nil {
    // skip or recreate the tool use instead of failing
    log.Printf("tool call %s gone, skipping update", toolCallID)
}
Defensive patterns

Strategy: try-catch

Try / catch

err := anthropic.UpdateToolUseData(chatId, toolCallId, data)
if err != nil && strings.Contains(err.Error(), "not found in chat") {
    // tool use already removed or wrong chat; log and continue
    log.Printf("tool call %s not in chat %s; skipping", toolCallId, chatId)
    return nil
}

Prevention

When it happens

Trigger: UpdateToolUseData called with a toolCallId that no *anthropicChatMessage in the chat contains — the call was already removed (e.g. by RemoveToolUseCall), the ID belongs to another chat, or the ID was fabricated.

Common situations: Double-applying an update after the tool use was removed; mixing up IDs between concurrent chats; using a truncated/renamed tool call ID from logs.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/3f274ad9cb8f2abb. Report an issue: GitHub.

Appendix: source

Thrown at pkg/aiusechat/anthropic/anthropic-convertmessage.go:901

			if block.Type != "tool_use" || block.ID != toolCallId {
				continue
			}
			updatedMsg := &anthropicChatMessage{
				MessageId: chatMsg.MessageId,
				Usage:     chatMsg.Usage,
				Role:      chatMsg.Role,
				Content:   slices.Clone(chatMsg.Content),
			}
			updatedMsg.Content[i].ToolUseData = &toolUseData
			aiOpts := &uctypes.AIOptsType{
				APIType:    chat.APIType,
				Model:      chat.Model,
				APIVersion: chat.APIVersion,
			}
			return chatstore.DefaultChatStore.PostMessage(chatId, aiOpts, updatedMsg)
		}
	}
	return fmt.Errorf("tool call with ID %s not found in chat %s", toolCallId, chatId)
}

func RemoveToolUseCall(chatId string, toolCallId string) error {
	chat := chatstore.DefaultChatStore.Get(chatId)
	if chat == nil {
		return fmt.Errorf("chat not found: %s", chatId)
	}
	for _, genMsg := range chat.NativeMessages {
		chatMsg, ok := genMsg.(*anthropicChatMessage)
		if !ok {
			continue
		}
		for i, block := range chatMsg.Content {
			if block.Type != "tool_use" || block.ID != toolCallId {
				continue
			}
			updatedMsg := &anthropicChatMessage{
				MessageId: chatMsg.MessageId,

View on GitHub (pinned to a4447c1563)