Skip to content

searchOtherThreads drops valid cross-thread text search results when target message order is lower #256

@robinebers

Description

@robinebers

Using @convex-dev/agent@0.6.1

I have an agent configured with:

contextOptions: {
  searchOtherThreads: true,
  searchOptions: {
    limit: 10,
    textSearch: true,
  },
}

and my contextHandler includes args.search.

Expected: a new thread should be able to retrieve matching messages from older threads with the same stored userId.

Actual: direct text search finds the old matching messages, but they get filtered out when the new thread’s current message has a lower order.

Example:

  • New thread prompt: what do you remember about high-ticket coaches
  • Old thread message: tom and jerry are both amazing high-ticket coaches and educators...

Both threads have the same userId.
Raw text_search returns the old message.

But the agent context search returns no cross-thread match.

It looks like the “only include messages before targetMessageId” filter compares order across different threads. That makes sense within one thread, but not across threads where the search results could be used in order 0 or 1 even though in other threads they may have been order 100.

Files affected

  • src/component/messages.ts
    textSearch filters results using targetMessage.order.

  • src/client/search.ts
    passes targetMessageId into searchMessages while also using searchOtherThreads.

Potential fix

When searchAllMessagesForUserId is set, only apply the targetMessageId order filter to messages from the same threadId.

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