[PR #13580] fix(session): add ORDER BY time_updated DESC to Session.list() and children() #14721

Closed
opened 2026-02-16 18:19:29 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/13580

State: closed
Merged: No


Summary

Fixes #13569

Adds ORDER BY time_updated DESC to Session.list() and Session.children() for deterministic ordering.

Problem

The current implementation returns sessions in SQLite's internal storage order, which is not guaranteed to be stable. This makes the limit parameter unreliable (returns arbitrary subset instead of most recent).

Changes

  • Add desc import from storage/db
  • Add .orderBy(desc(SessionTable.time_updated)) to list()
  • Add .orderBy(desc(SessionTable.time_updated)) to children()

Testing

This is a minimal change that adds database-level ordering. The TUI already sorts client-side with .toSorted((a, b) => b.time.updated - a.time.updated), so this change aligns the API behavior with existing client expectations.


🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/13580 **State:** closed **Merged:** No --- ## Summary Fixes #13569 Adds `ORDER BY time_updated DESC` to `Session.list()` and `Session.children()` for deterministic ordering. ## Problem The current implementation returns sessions in SQLite's internal storage order, which is not guaranteed to be stable. This makes the `limit` parameter unreliable (returns arbitrary subset instead of most recent). ## Changes - Add `desc` import from `storage/db` - Add `.orderBy(desc(SessionTable.time_updated))` to `list()` - Add `.orderBy(desc(SessionTable.time_updated))` to `children()` ## Testing This is a minimal change that adds database-level ordering. The TUI already sorts client-side with `.toSorted((a, b) => b.time.updated - a.time.updated)`, so this change aligns the API behavior with existing client expectations. --- 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
yindo added the pull-request label 2026-02-16 18:19:29 -05:00
yindo closed this issue 2026-02-16 18:19:29 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14721