wavetermdev/waveterm · error

chat not found: %s

Error message

chat not found: %s

What it means

Lookup error: the referenced chat/session ID does not exist in the OpenAI chat registry (never created, closed, or evicted).

Source

Thrown at pkg/aiusechat/openaichat/openaichat-backend.go:38

	"github.com/wavetermdev/waveterm/pkg/aiusechat/chatstore"
	"github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes"
	"github.com/wavetermdev/waveterm/pkg/web/sse"
)

// RunChatStep executes a chat step using the chat completions API
func RunChatStep(
	ctx context.Context,
	sseHandler *sse.SSEHandlerCh,
	chatOpts uctypes.WaveChatOpts,
	cont *uctypes.WaveContinueResponse,
) (*uctypes.WaveStopReason, []*StoredChatMessage, *uctypes.RateLimitInfo, error) {
	if sseHandler == nil {
		return nil, nil, nil, errors.New("sse handler is nil")
	}

	chat := chatstore.DefaultChatStore.Get(chatOpts.ChatId)
	if chat == nil {
		return nil, nil, nil, fmt.Errorf("chat not found: %s", chatOpts.ChatId)
	}

	if chatOpts.Config.TimeoutMs > 0 {
		var cancel context.CancelFunc
		ctx, cancel = context.WithTimeout(ctx, time.Duration(chatOpts.Config.TimeoutMs)*time.Millisecond)
		defer cancel()
	}

	// Convert stored messages to chat completions format
	var messages []ChatRequestMessage

	// Convert native messages
	for _, genMsg := range chat.NativeMessages {
		chatMsg, ok := genMsg.(*StoredChatMessage)
		if !ok {
			return nil, nil, nil, fmt.Errorf("expected StoredChatMessage, got %T", genMsg)
		}
		messages = append(messages, *chatMsg.Message.clean())

View on GitHub (pinned to a4447c1563)

Solutions

  1. Verify the ChatId exists (chatstore.DefaultChatStore.Get(chatOpts.ChatId) != nil) before calling RunChatStep
  2. Create/register the chat first via the chatstore API before running a step
  3. Refresh the ChatId from the client after store restarts
  4. Check for code paths that delete chats unintentionally

Example fix

// before
_, _, _, err := RunChatStep(ctx, sseHandler, ChatOpts{ChatId: someID})
// after
if chatstore.DefaultChatStore.Get(someID) == nil {
    return fmt.Errorf("chat %s does not exist", someID)
}
_, _, _, err := RunChatStep(ctx, sseHandler, ChatOpts{ChatId: someID})
Defensive patterns

Strategy: validation

Validate before calling

if chatstore.DefaultChatStore.Get(chatOpts.ChatId) == nil {
    return fmt.Errorf("chat %s not in store", chatOpts.ChatId)
}

Try / catch

out, err := RunChatStep(ctx, sseHandler, opts)
if err != nil && strings.Contains(err.Error(), "chat not found") {
    // re-create the chat or notify the client the session expired
}

Prevention

When it happens

Trigger: Calling RunChatStep with a ChatId that was never registered in the store, or after the chat was deleted/expired from chatstore.DefaultChatStore.

Common situations: Using a stale ChatId after a server restart (in-memory store); typo'd or client-fabricated IDs; race where another request deleted the chat between calls.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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