{"record":{"id":"2289cdfdab9b514a","repo":"wavetermdev/waveterm","slug":"chat-not-found-s-2289cd","errorCode":null,"errorMessage":"chat not found: %s","messagePattern":"chat not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/aiusechat/anthropic/anthropic-convertmessage.go","lineNumber":875,"sourceCode":"\t\t\targsBytes, err := json.Marshal(argsInput)\n\t\t\tif err != nil {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\treturn &uctypes.AIFunctionCallInput{\n\t\t\t\tCallId:      block.ID,\n\t\t\t\tName:        block.Name,\n\t\t\t\tArguments:   string(argsBytes),\n\t\t\t\tToolUseData: block.ToolUseData,\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc UpdateToolUseData(chatId string, toolCallId string, toolUseData 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\tfor _, genMsg := range chat.NativeMessages {\n\t\tchatMsg, ok := genMsg.(*anthropicChatMessage)\n\t\tif !ok {\n\t\t\tcontinue\n\t\t}\n\t\tfor i, block := range chatMsg.Content {\n\t\t\tif block.Type != \"tool_use\" || block.ID != toolCallId {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tupdatedMsg := &anthropicChatMessage{\n\t\t\t\tMessageId: chatMsg.MessageId,\n\t\t\t\tUsage:     chatMsg.Usage,\n\t\t\t\tRole:      chatMsg.Role,\n\t\t\t\tContent:   slices.Clone(chatMsg.Content),\n\t\t\t}\n\t\t\tupdatedMsg.Content[i].ToolUseData = &toolUseData\n\t\t\taiOpts := &uctypes.AIOptsType{","sourceCodeStart":857,"sourceCodeEnd":893,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/aiusechat/anthropic/anthropic-convertmessage.go#L857-L893","documentation":"Returned when the referenced Anthropic chat id is not present in the chat store during message lookup.","triggerScenarios":"Calling UpdateToolUseData(chatId, toolCallId, data) where DefaultChatStore.Get(chatId) returns nil — the chat was never registered, was already removed, or the ID string is wrong.","commonSituations":"Using a chat ID from a different process/session, calling after RemoveChat/chat store reset, typos in the ID, or a race where the chat is deleted before the update.","solutions":["Verify the chatId matches one registered in chatstore.DefaultChatStore (create/register the chat first)","Check the call ordering so the chat is not removed before UpdateToolUseData runs","Log/store the chat ID at creation time and reuse the exact value"],"exampleFix":"// before\nerr := anthropic.UpdateToolUseData(chatId, toolCallId, data) // chat never created\n// after\nif chatstore.DefaultChatStore.Get(chatId) != nil {\n    err = anthropic.UpdateToolUseData(chatId, toolCallId, data)\n}","handlingStrategy":"try-catch","validationCode":"if chatstore.DefaultChatStore.Get(chatId) == nil {\n    return fmt.Errorf(\"chat %s is not registered\", chatId)\n}","typeGuard":null,"tryCatchPattern":"if err := anthropic.UpdateToolUseData(chatId, toolCallId, data); err != nil && strings.HasPrefix(err.Error(), \"chat not found\") {\n    // recreate chat or skip update\n    return nil\n}","preventionTips":["Create/register the chat before any tool-use mutations","Keep chatId in one place (session context) instead of passing ad-hoc strings","Treat store lookups as fallible; check existence before mutating"],"tags":["go","anthropic","chat-store","not-found"],"backgroundTag":"resource-not-found","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}