You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GET /session: Add ORDER BY time_updated DESC to Session.list() for deterministic ordering and correct limit behavior #13569
GET /session: Add ORDER BY time_updated DESC to Session.list() for deterministic ordering and correct limit behavior
Problem
The Session.list() function in packages/opencode/src/session/index.ts does not include an ORDER BY clause:
exportfunction*list(){constrows=Database.use((db)=>db.select().from(SessionTable).where(eq(SessionTable.project_id,project.id)).all(),// No ORDER BY)// ...}
This causes two issues:
Undefined ordering — The GET /session endpoint returns sessions in SQLite's internal storage order, which is not guaranteed to be stable or meaningful.
limit truncates arbitrarily — When limit is used, clients receive an arbitrary subset of sessions rather than the most recently active ones. This makes the limit parameter unreliable for any practical use case (pagination, initial load, etc.).
Expected Behavior
Sessions should be returned in time_updated DESC order (most recently active first). This is consistent with:
How the TUI already handles this (client-side .toSorted((a, b) => b.time.updated - a.time.updated))
Standard UX expectations (chat apps, IDEs, etc.)
Making limit useful — "give me the N most recent sessions"
Suggested Fix
Add ORDER BY at the database level in Session.list():
The current issue is specifically focused on database-level ordering and limit behavior, which is a more targeted improvement that would complement broader pagination support.
Activity
github-actions commentedon Feb 14, 2026
This issue might be related to existing issues. Please check:
The current issue is specifically focused on database-level ordering and
limitbehavior, which is a more targeted improvement that would complement broader pagination support.fix(session): add ORDER BY time_updated DESC to Session.list() and ch…
thdxr commentedon Feb 14, 2026
good call - fixed in latest