[GH-ISSUE #12958] app: conversation sorting is incorrect #55105

Open
opened 2026-04-29 08:20:31 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @jmorganca on GitHub (Nov 4, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/12958

What is the issue?

Conversations in the sidebar are sorted by the last response, when they are usually sorted by last message sent by the user. I don't think this is a hard "bug" since conversations over Apple messages are sorted by response time, but this feels off since its different than other chat tools such as ChatGPT and Claude.

Relevant log output


OS

No response

GPU

No response

CPU

No response

Ollama version

No response

Originally created by @jmorganca on GitHub (Nov 4, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/12958 ### What is the issue? Conversations in the sidebar are sorted by the last response, when they are usually sorted by last message sent by the user. I don't think this is a hard "bug" since conversations over Apple messages are sorted by response time, but this feels off since its different than other chat tools such as ChatGPT and Claude. ### Relevant log output ```shell ``` ### OS _No response_ ### GPU _No response_ ### CPU _No response_ ### Ollama version _No response_
GiteaMirror added the appbug labels 2026-04-29 08:20:31 -05:00
Author
Owner

@matteocelani commented on GitHub (Apr 3, 2026):

I did a analysis of the sorting pipeline to verify the root cause. Here's the full technical breakdown:

The data flow:

  1. getAllChats() in app/store/database.go (line 580) runs a SQL query that computes MAX(m.updated_at) as last_updated
  2. The JOIN at line 596 (LEFT JOIN messages m ON c.id = m.chat_id) includes all message roles — both user and assistant
  3. This means last_updated reflects the timestamp of the last assistant response, not the last user message
  4. The result is packed into a dummy message (line 634-638) and returned to the API layer
  5. chatInfoFromChat() in app/ui/ui.go (line 1401) extracts updatedAt from this data
  6. The frontend (ChatSidebar.tsx, line 114) sorts by this updatedAt — so it inherits the incorrect ordering

There is a second code path affected:
chatInfoFromChat() is also called from renameChat() (line 1317), which loads full message history via getChatWithOptions()getMessages(). Without filtering by role in chatInfoFromChat(), renaming a chat would also return an incorrect updatedAt.

PR #13479 correctly addresses both paths:

  • database.go: adds AND m.role = 'user' to the JOIN, fixing the SQL-level sorting
  • ui.go: adds msg.Role == "user" guard in chatInfoFromChat(), fixing the rename path and any future callers that pass full message lists

The fix is minimal (2 lines), correct, and covers all affected code paths. It would be great to see it reviewed and merged.

<!-- gh-comment-id:4183007262 --> @matteocelani commented on GitHub (Apr 3, 2026): I did a analysis of the sorting pipeline to verify the root cause. Here's the full technical breakdown: **The data flow:** 1. `getAllChats()` in `app/store/database.go` (line 580) runs a SQL query that computes `MAX(m.updated_at)` as `last_updated` 2. The JOIN at line 596 (`LEFT JOIN messages m ON c.id = m.chat_id`) includes **all** message roles — both user and assistant 3. This means `last_updated` reflects the timestamp of the last assistant response, not the last user message 4. The result is packed into a dummy message (line 634-638) and returned to the API layer 5. `chatInfoFromChat()` in `app/ui/ui.go` (line 1401) extracts `updatedAt` from this data 6. The frontend (`ChatSidebar.tsx`, line 114) sorts by this `updatedAt` — so it inherits the incorrect ordering **There is a second code path affected:** `chatInfoFromChat()` is also called from `renameChat()` (line 1317), which loads full message history via `getChatWithOptions()` → `getMessages()`. Without filtering by role in `chatInfoFromChat()`, renaming a chat would also return an incorrect `updatedAt`. **PR #13479 correctly addresses both paths:** - `database.go`: adds `AND m.role = 'user'` to the JOIN, fixing the SQL-level sorting - `ui.go`: adds `msg.Role == "user"` guard in `chatInfoFromChat()`, fixing the rename path and any future callers that pass full message lists The fix is minimal (2 lines), correct, and covers all affected code paths. It would be great to see it reviewed and merged.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#55105