wavetermdev/waveterm · error

chat not found: %s

Error message

chat not found: %s

What it means

UpdateToolUseData returns "chat not found: %s" when chatstore.DefaultChatStore.Get(chatId) returns nil — i.e. no chat with that id exists in the in-memory chat store. This happens at openai-backend.go:414 before scanning NativeMessages for the matching function call.

Source

Thrown at pkg/aiusechat/openai/openai-backend.go:414

	partialJSON     []byte // For function calls: accumulated JSON arguments
	accumulatedText string // For text blocks: accumulated text content
}

type openaiStreamingState struct {
	blockMap       map[string]*openaiBlockState // Use item_id as key for UI streaming
	msgID          string
	model          string
	stepStarted    bool
	chatOpts       uctypes.WaveChatOpts
	webSearchCount int
}

// ---------- Public entrypoint ----------

func UpdateToolUseData(chatId string, callId string, newToolUseData uctypes.UIMessageDataToolUse) 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.(*OpenAIChatMessage)
		if !ok {
			continue
		}

		if chatMsg.FunctionCall != nil && chatMsg.FunctionCall.CallId == callId {
			updatedMsg := *chatMsg
			updatedFunctionCall := *chatMsg.FunctionCall
			updatedFunctionCall.ToolUseData = &newToolUseData
			updatedMsg.FunctionCall = &updatedFunctionCall

			aiOpts := &uctypes.AIOptsType{
				APIType:    chat.APIType,
				Model:      chat.Model,
				APIVersion: chat.APIVersion,

View on GitHub (pinned to a4447c1563)

Solutions

  1. Verify the chatId passed to UpdateToolUseData exists: call chatstore.DefaultChatStore.Get(chatId) first and handle nil
  2. Re-create the chat (re-run the chat step) if the store was restarted/evicted, instead of updating tool data
  3. Confirm you are not swapping chatId and callId arguments
  4. Check that the same process/store instance is used (DefaultChatStore is in-memory, not persisted)

Example fix

// before
err := UpdateToolUseData(chatId, callId, data)
// after
if chatstore.DefaultChatStore.Get(chatId) == nil {
    return fmt.Errorf("cannot update tool use: chat %q no longer exists", chatId)
}
err := UpdateToolUseData(chatId, callId, data)
Defensive patterns

Strategy: validation

Validate before calling

if chatstore.DefaultChatStore.Get(chatId) == nil {
    return fmt.Errorf("chat %q does not exist; cannot update tool use", chatId)
}

Type guard

func chatExists(chatId string) bool {
    return chatstore.DefaultChatStore.Get(chatId) != nil
}

Try / catch

if err := UpdateToolUseData(chatId, callId, data); err != nil {
    if strings.HasPrefix(err.Error(), "chat not found") {
        return nil // chat gone; skip update
    }
    return err
}

Prevention

When it happens

Trigger: Calling UpdateToolUseData(chatId, callId, data) with a chatId that was never created, was already deleted, or belongs to a different backend/store lifetime (e.g. after server restart or store eviction).

Common situations: Stale chatId cached in the UI after app restart; calling tool-use update after the chat was removed; passing the callId where the chatId belongs or vice versa; chats created under a different API backend (openai vs azure) with separate ids.

Related errors


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