{"record":{"id":"750d6868a2aeb094","repo":"wavetermdev/waveterm","slug":"expected-storedchatmessage-got-t","errorCode":null,"errorMessage":"expected StoredChatMessage, got %T","messagePattern":"expected StoredChatMessage, got %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/aiusechat/openaichat/openaichat-backend.go","lineNumber":54,"sourceCode":"\tchat := chatstore.DefaultChatStore.Get(chatOpts.ChatId)\n\tif chat == nil {\n\t\treturn nil, nil, nil, fmt.Errorf(\"chat not found: %s\", chatOpts.ChatId)\n\t}\n\n\tif chatOpts.Config.TimeoutMs > 0 {\n\t\tvar cancel context.CancelFunc\n\t\tctx, cancel = context.WithTimeout(ctx, time.Duration(chatOpts.Config.TimeoutMs)*time.Millisecond)\n\t\tdefer cancel()\n\t}\n\n\t// Convert stored messages to chat completions format\n\tvar messages []ChatRequestMessage\n\n\t// Convert native messages\n\tfor _, genMsg := range chat.NativeMessages {\n\t\tchatMsg, ok := genMsg.(*StoredChatMessage)\n\t\tif !ok {\n\t\t\treturn nil, nil, nil, fmt.Errorf(\"expected StoredChatMessage, got %T\", genMsg)\n\t\t}\n\t\tmessages = append(messages, *chatMsg.Message.clean())\n\t}\n\n\treq, err := buildChatHTTPRequest(ctx, messages, chatOpts)\n\tif err != nil {\n\t\treturn nil, nil, nil, err\n\t}\n\n\tclient, err := aiutil.MakeHTTPClient(chatOpts.Config.ProxyURL)\n\tif err != nil {\n\t\treturn nil, nil, nil, err\n\t}\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn nil, nil, nil, fmt.Errorf(\"request failed: %w\", err)\n\t}\n\tdefer resp.Body.Close()","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/aiusechat/openaichat/openaichat-backend.go#L36-L72","documentation":"RunChatStep converts the stored chat's NativeMessages, asserting each is a *StoredChatMessage; any other concrete type fails this assertion with the actual type reported. The openaichat backend only understands its own stored message wrapper.","triggerScenarios":"chat.NativeMessages contains native messages produced by another backend (e.g. *OpenAIChatMessage from the openai responses backend) instead of *StoredChatMessage.","commonSituations":"Persisting/loading chats across backends; mixing backends in one chat history; upgrading the library where message representations changed.","solutions":["Ensure only messages created by the openaichat backend are added to this chat's NativeMessages","Convert or re-create foreign messages as StoredChatMessage before running the step","Check the chat-loading code isn't deserializing into the wrong message type"],"exampleFix":"// before\nchat.NativeMessages = append(chat.NativeMessages, openaiMsg) // wrong type\n// after\nchat.NativeMessages = append(chat.NativeMessages, &StoredChatMessage{Message: toStored(openaiMsg)})","handlingStrategy":"type-guard","validationCode":"for i, m := range chat.NativeMessages {\n    if _, ok := m.(*StoredChatMessage); !ok {\n        return fmt.Errorf(\"native message %d is %T, not StoredChatMessage\", i, m)\n    }\n}","typeGuard":"func isStoredChatMessage(m any) bool { _, ok := m.(*StoredChatMessage); return ok }","tryCatchPattern":null,"preventionTips":["Convert foreign native messages to StoredChatMessage before storing","Validate message types when deserializing chat history","Keep openaichat chats isolated from other backends"],"tags":["type-assertion","chatstore","openai"],"backgroundTag":"unexpected-message-type","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}