Skip to content

latestConversationId() can return the wrong conversation because parent updated_at is never refreshed #381

@ruttydm

Description

@ruttydm

I found what looks like a conversation-store bug in laravel/ai v0.1.5.

DatabaseConversationStore::latestConversationId() selects the latest conversation by ordering agent_conversations.updated_at DESC.

However, agent_conversations.updated_at appears to only be written when the conversation row is created. When later user/assistant messages are stored, the parent conversation row is not updated.

Why this matters

If a user has multiple remembered conversations, continueLastConversation() can resume the wrong one:

  1. create conversation A
  2. create conversation B
  3. add more messages to conversation A
  4. call continueLastConversation()

At that point, conversation A is the most recently active conversation, but conversation B may still win because its parent row has the newer updated_at.

Expected

The “last conversation” lookup should reflect the most recently active conversation.

Actual

It reflects the most recently created conversation row, unless something else updates the parent row externally.

Relevant code

  • src/Storage/DatabaseConversationStore.php
  • latestConversationId()
  • storeConversation()
  • storeUserMessage()
  • storeAssistantMessage()

Possible fixes could be either:

  • updating agent_conversations.updated_at whenever a message is stored, or
  • deriving “latest” from message timestamps instead of the parent row timestamp.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions