GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GET /session: Add ORDER BY time_updated DESC to Session.list() for deterministic ordering and correct limit behavior · Issue #13569 · anomalyco/opencode

GET /session: Add ORDER BY time_updated DESC to Session.list() for deterministic ordering and correct limit behavior #13569

New issue
Copy link
New issue
Copy link
Closed
Closed
GET /session: Add ORDER BY time_updated DESC to Session.list() for deterministic ordering and correct limit behavior#13569
Copy link
Assignees
thdxr
Labels
bugSomething isn't working

Description

@BetaYao
BetaYao
opened on Feb 14, 2026
Issue body actions

Description

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:

export function* list() {
    const rows = Database.use((db) =>
      db
        .select()
        .from(SessionTable)
        .where(eq(SessionTable.project_id, project.id))
        .all(),  // No ORDER BY
    )
    // ...
}

This causes two issues:

  1. Undefined ordering — The GET /session endpoint returns sessions in SQLite's internal storage order, which is not guaranteed to be stable or meaningful.

  2. 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():

import { desc } from "../storage/db"

export function* list() {
    const project = Instance.project
    const rows = Database.use((db) =>
      db
        .select()
        .from(SessionTable)
        .where(eq(SessionTable.project_id, project.id))
        .orderBy(desc(SessionTable.time_updated))  // ← Add this
        .all(),
    )
    for (const row of rows) {
      yield fromRow(row)
    }
}

Bonus: offset support

For clients that need pagination (e.g., GUI apps showing session lists), adding an offset query parameter to GET /session would be very helpful:

// In route handler, after sorting at DB level:
if (query.offset !== undefined) {
    sessions = sessions.slice(query.offset)
}

Context

I'm building a GUI client for OpenCode. Currently I have to fetch all sessions and sort client-side because:

  1. The API order is undefined
  2. limit without ordering gives arbitrary results
  3. There's no offset for pagination

Server-side ORDER BY + offset would significantly reduce client complexity and data transfer.

Plugins

No response

OpenCode version

1.1.55

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

macos 26

Terminal

Ghostty

Activity

  1. BetaYao
    added
    bugSomething isn't working
    on Feb 14, 2026
  2. github-actions commented on Feb 14, 2026

    @github-actions
    github-actionsBot
    on Feb 14, 2026 – with GitHub Actions
    Contributor
    More actions

    This issue might be related to existing issues. Please check:

    • feature request: pagination for messages & sessions #4918: feature request: pagination for messages & sessions (broader pagination request that includes sessions)

    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.

  3. github-actions
    assigned
    thdxr
    on Feb 14, 2026
  4. zerone0x
    added a commit that references this issue on Feb 14, 2026

    fix(session): add ORDER BY time_updated DESC to Session.list() and ch…

    This issue will close once commit 68b5bc7 is merged into the 'dev' branch.
    68b5bc7
  5. thdxr commented on Feb 14, 2026

    @thdxr
    thdxr
    on Feb 14, 2026
    Member
    More actions

    good call - fixed in latest

  6. thdxr
    closed this as completedon Feb 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @thdxr
    thdxr

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.