{"record":{"id":"cf1068e47a013400","repo":"wavetermdev/waveterm","slug":"cannot-continue-with-a-different-model-model-q-cf1068","errorCode":null,"errorMessage":"cannot continue with a different model, model:%q, cont-model:%q","messagePattern":"cannot continue with a different model, model:%q, cont-model:%q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/aiusechat/openai/openai-backend.go","lineNumber":500,"sourceCode":"\t}\n\tif !uctypes.AreModelsCompatible(chat.APIType, chat.Model, chatOpts.Config.Model) {\n\t\treturn nil, nil, nil, fmt.Errorf(\"model mismatch: chat has %s, chatOpts has %s\", chat.Model, chatOpts.Config.Model)\n\t}\n\tif chat.APIVersion != chatOpts.Config.APIVersion {\n\t\treturn nil, nil, nil, fmt.Errorf(\"API version mismatch: chat has %s, chatOpts has %s\", chat.APIVersion, chatOpts.Config.APIVersion)\n\t}\n\n\t// Context with timeout if provided.\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// Validate continuation if provided\n\tif cont != nil {\n\t\tif !uctypes.AreModelsCompatible(chat.APIType, chatOpts.Config.Model, cont.Model) {\n\t\t\treturn nil, nil, nil, fmt.Errorf(\"cannot continue with a different model, model:%q, cont-model:%q\", chatOpts.Config.Model, cont.Model)\n\t\t}\n\t}\n\n\t// Convert GenAIMessages to input objects (OpenAIMessage or OpenAIFunctionCallInput)\n\tvar inputs []any\n\tfor _, genMsg := range chat.NativeMessages {\n\t\t// Cast to OpenAIChatMessage\n\t\tchatMsg, ok := genMsg.(*OpenAIChatMessage)\n\t\tif !ok {\n\t\t\treturn nil, nil, nil, fmt.Errorf(\"expected OpenAIChatMessage, got %T\", genMsg)\n\t\t}\n\n\t\t// Convert to appropriate input type based on what's populated\n\t\tif chatMsg.Message != nil {\n\t\t\t// Clean message to remove preview URLs\n\t\t\tcleanedMsg := chatMsg.Message.cleanAndCopy()\n\t\t\tinputs = append(inputs, *cleanedMsg)\n\t\t} else if chatMsg.FunctionCall != nil {","sourceCodeStart":482,"sourceCodeEnd":518,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/aiusechat/openai/openai-backend.go#L482-L518","documentation":"RunOpenAIChatStep validates a provided continuation (cont *uctypes.WaveContinueResponse) at openai-backend.go:500: if uctypes.AreModelsCompatible(chat.APIType, chatOpts.Config.Model, cont.Model) is false, it returns \"cannot continue with a different model\". A continuation response must have been produced by the same (compatible) model as the request being made.","triggerScenarios":"Passing a cont (e.g. a follow-up/next-page response handle) whose cont.Model was produced under a different model than chatOpts.Config.Model — typically after the user switched models between a stopped turn and its continuation.","commonSituations":"Model changed in settings between the original response and clicking 'continue'; replaying an old saved continuation record against a chat now configured with a newer model; concurrent chats sharing a continuation object by mistake.","solutions":["Drop the cont argument (pass nil) and start a fresh step with the new model","Align chatOpts.Config.Model with cont.Model (if that's the model you intend to continue with)","Re-generate the continuation under the current model instead of reusing the old one","Check AreModelsCompatible: if the models should be compatible, fix the model strings (aliases/version suffixes) rather than the logic"],"exampleFix":"// before\ncont := loadSavedContinuation() // cont.Model = \"gpt-4o\"\nchatOpts.Config.Model = \"gpt-4.1\"\nRunOpenAIChatStep(ctx, sse, chatOpts, cont) // mismatch\n// after\nif cont != nil && cont.Model != chatOpts.Config.Model {\n    cont = nil // discard stale continuation\n}\nRunOpenAIChatStep(ctx, sse, chatOpts, cont)","handlingStrategy":"validation","validationCode":"if cont != nil {\n    chat := chatstore.DefaultChatStore.Get(chatOpts.ChatId)\n    if chat == nil || !uctypes.AreModelsCompatible(chat.APIType, chatOpts.Config.Model, cont.Model) {\n        cont = nil // discard incompatible continuation\n    }\n}","typeGuard":"func continuationValid(chatOpts uctypes.WaveChatOpts, cont *uctypes.WaveContinueResponse) bool {\n    if cont == nil {\n        return true\n    }\n    chat := chatstore.DefaultChatStore.Get(chatOpts.ChatId)\n    return chat != nil && uctypes.AreModelsCompatible(chat.APIType, chatOpts.Config.Model, cont.Model)\n}","tryCatchPattern":"if _, _, _, err := RunOpenAIChatStep(ctx, sse, chatOpts, cont); err != nil {\n    if strings.Contains(err.Error(), \"cannot continue with a different model\") {\n        // retry once with cont = nil\n        _, _, _, err = RunOpenAIChatStep(ctx, sse, chatOpts, nil)\n        return err\n    }\n    return err\n}","preventionTips":["Store the model alongside any saved continuation and validate before reuse","Discard continuations when the model setting changes","Never share continuation objects between chats/models","Prefer fresh steps over replaying stale continuation handles"],"tags":["go","continuation","model","openai"],"backgroundTag":"model-mismatch","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}