Skip to content

Sort chat recents by last activity - #6844

Merged
Imagineer99 merged 4 commits into
unslothai:mainfrom
NilayYadav:chat-recents-sort
Jul 7, 2026
Merged

Imagineer99 merged 4 commits into
unslothai:mainfrom
NilayYadav:chat-recents-sort

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

Adds an updatedAt field to chat threads that gets bumped whenever a message is written. The Recents sidebar now sorts by last activity instead of creation time, so continuing an old chat bubbles it to the top.

  • Backend: new updated_at column with migration backfill from existing messages
  • Frontend: sorts sidebar items by updatedAt ?? createdAt; compare pairs take the newest activity across both panes
  • Empty state in the sidebar only renders after the first fetch resolves, preventing a flash on load

@NilayYadav
NilayYadav requested a review from danielhanchen as a code owner July 3, 2026 15:09
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an updatedAt field to chat threads to track and sort by the last activity time (e.g., when messages are added or synced). It includes backend database schema updates, a migration to backfill existing threads, API model adjustments, and frontend updates to sort threads by updatedAt and display a "No chats yet" message when the sidebar is empty. There are no review comments, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 7, 2026
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7194536cc6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread studio/backend/storage/studio_db.py Resolved
Comment thread studio/backend/storage/studio_db.py Resolved
@Imagineer99

Copy link
Copy Markdown
Member

Ran a focused check on this PR: https://github.com/Imagineer99/unsloth/actions/runs/28875558129

Looks good. Backend updated_at ordering tests passed, frontend sidebar sorting checks passed, and the screenshot artifact shows recents moving from createdAt order to last-activity order.

@Imagineer99

Copy link
Copy Markdown
Member
image

Full CI pass on staging fork.

@Imagineer99

Copy link
Copy Markdown
Member
image

Tested manually and working as expected, nice work @NilayYadav.

@Imagineer99

Copy link
Copy Markdown
Member

pre-commit.ci is failing only on formatting. I reproduced it locally and the fix is just running the repo formatter on:

  • studio/backend/storage/studio_db.py
  • studio/backend/tests/test_chat_history_storage.py

Can you apply that and push? Maintainer edits are disabled, so I can’t push the fix directly to your branch.

@Imagineer99
Imagineer99 merged commit 07ecdb3 into unslothai:main Jul 7, 2026
44 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8f0dfb511e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

conn.execute("ALTER TABLE chat_threads ADD COLUMN updated_at INTEGER")
# Floor at created_at: forked threads copy older ancestor messages,
# so the fork's creation time must win over the branch message times.
conn.execute(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Commit the updated_at backfill during migration

When the first request after upgrade is read-only (for example GET /api/chat/threads), this UPDATE starts a sqlite transaction inside _ensure_schema, but _ensure_schema never commits it; the caller then closes the connection after reading, rolling the backfill back while _schema_ready is already true. The column remains added but existing rows keep updated_at = NULL, so old chats continue sorting by created_at until they are written again. Commit the schema/backfill work before marking the schema ready or otherwise ensure this DML is committed even on read paths.

Useful? React with 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants