Skip to content

tui: model picker search ranks scattered-letter matches above exact ones #50531

Description

@fede-kamel

Description

Searching in the TUI model picker returns matches in release-date order instead of relevance order, so an exact match can sit at the bottom of the list below models that only share a few scattered letters with the query.

Searching luna against an OpenRouter catalogue:

inclusionai/ling-3.0-flash        ← top result, selected
inclusionai/ling-3.0-flash-fin
inclusionai/ling-3.0-flash-fin:free
...
openai/gpt-5.6-luna
openai/gpt-5.6-luna-pro
...
poolside/laguna-s-2.1
~openai/gpt-luna-latest            ← exact match, last

inclusionai/ling-3.0-flash matches because fuzzysort finds l-u-n-a in order inside "incLUsioNAi". That fuzzy match is fine on its own — the problem is that it outranks names that literally contain luna, and pressing Enter picks it.

Cause

A regression from #33558 ("sort model picker by release date"). In packages/tui/src/component/dialog-model.tsx the search branch became:

...sortModelOptions(
  fuzzysort.go(needle, providerOptions, { keys: ["title", "category"] }).map((x) => x.obj),
  false,
),

fuzzysort.go returns results best-first; sortModelOptions(…, false) then re-sorts them free-first, newest-first, discarding the relevance order. Before #33558 the search results were passed through unsorted. The release-date ordering makes sense for the unfiltered picker, but not for search results.

model-options.test.ts covers sortModelOptions itself, not the search path, which is why nothing caught it.

Steps to reproduce

  1. Configure a provider with a large catalogue (OpenRouter shows it well).
  2. Open /models and type luna.
  3. The first, pre-selected result is inclusionai/ling-3.0-flash, not a luna model.

Operating System

Linux x86_64 (WSL2)

Terminal

Windows Terminal

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions