{"record":{"id":"c4f274a11054de65","repo":"wavetermdev/waveterm","slug":"chat-not-found-s-c4f274","errorCode":null,"errorMessage":"chat not found: %s","messagePattern":"chat not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/aiusechat/openai/openai-backend.go","lineNumber":414,"sourceCode":"\tpartialJSON     []byte // For function calls: accumulated JSON arguments\n\taccumulatedText string // For text blocks: accumulated text content\n}\n\ntype openaiStreamingState struct {\n\tblockMap       map[string]*openaiBlockState // Use item_id as key for UI streaming\n\tmsgID          string\n\tmodel          string\n\tstepStarted    bool\n\tchatOpts       uctypes.WaveChatOpts\n\twebSearchCount int\n}\n\n// ---------- Public entrypoint ----------\n\nfunc UpdateToolUseData(chatId string, callId string, newToolUseData uctypes.UIMessageDataToolUse) error {\n\tchat := chatstore.DefaultChatStore.Get(chatId)\n\tif chat == nil {\n\t\treturn fmt.Errorf(\"chat not found: %s\", chatId)\n\t}\n\n\tfor _, genMsg := range chat.NativeMessages {\n\t\tchatMsg, ok := genMsg.(*OpenAIChatMessage)\n\t\tif !ok {\n\t\t\tcontinue\n\t\t}\n\n\t\tif chatMsg.FunctionCall != nil && chatMsg.FunctionCall.CallId == callId {\n\t\t\tupdatedMsg := *chatMsg\n\t\t\tupdatedFunctionCall := *chatMsg.FunctionCall\n\t\t\tupdatedFunctionCall.ToolUseData = &newToolUseData\n\t\t\tupdatedMsg.FunctionCall = &updatedFunctionCall\n\n\t\t\taiOpts := &uctypes.AIOptsType{\n\t\t\t\tAPIType:    chat.APIType,\n\t\t\t\tModel:      chat.Model,\n\t\t\t\tAPIVersion: chat.APIVersion,","sourceCodeStart":396,"sourceCodeEnd":432,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/aiusechat/openai/openai-backend.go#L396-L432","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Verify the chatId passed to UpdateToolUseData exists: call chatstore.DefaultChatStore.Get(chatId) first and handle nil","Re-create the chat (re-run the chat step) if the store was restarted/evicted, instead of updating tool data","Confirm you are not swapping chatId and callId arguments","Check that the same process/store instance is used (DefaultChatStore is in-memory, not persisted)"],"exampleFix":"// before\nerr := UpdateToolUseData(chatId, callId, data)\n// after\nif chatstore.DefaultChatStore.Get(chatId) == nil {\n    return fmt.Errorf(\"cannot update tool use: chat %q no longer exists\", chatId)\n}\nerr := UpdateToolUseData(chatId, callId, data)","handlingStrategy":"validation","validationCode":"if chatstore.DefaultChatStore.Get(chatId) == nil {\n    return fmt.Errorf(\"chat %q does not exist; cannot update tool use\", chatId)\n}","typeGuard":"func chatExists(chatId string) bool {\n    return chatstore.DefaultChatStore.Get(chatId) != nil\n}","tryCatchPattern":"if err := UpdateToolUseData(chatId, callId, data); err != nil {\n    if strings.HasPrefix(err.Error(), \"chat not found\") {\n        return nil // chat gone; skip update\n    }\n    return err\n}","preventionTips":["Always obtain chatId from chat creation, never construct it","Check chat existence before any per-chat mutation","Recreate chats after process restarts rather than reusing old ids","Keep argument order (chatId, callId) straight in call sites"],"tags":["go","chatstore","state","openai"],"backgroundTag":"chat-not-found","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}