Skip to content

archiving rewrites time_updated, so archived sessions take over the default session list #63951

Open

Description

@ValDagon

Summary

Archiving a session rewrites time_updated, and the session list is ordered by
time_updated with no archived filter by default. Any archive sweep therefore moves
every archived session to the top: on my DB the default page is 47 archived sessions
out of 50.

Measured on v2.3.0 (macOS, read-only copy of the live DB)

  • 499 sessions across 41 projects; 176 archived.
  • All 176 have time_updated == time_archived.
  • The 176 came from one bulk loop, PATCH /api/session/{id} {"archived":true}, at
    2026-11-14T11:01:29–11:01:33Z.
  • The endpoint's default page is "the newest 50 sessions" (from the served OpenAPI).
    In that ordering 47 of the 50 are archived: the three live sessions sit at
    positions 1–3, and positions 4–50 are all archive.
-- copy of the DB, opened mode=ro&immutable=1
select count(*) from session_v2 where time_archived is not null and time_archived > 0;
-- 176
select count(*) from session_v2 where time_archived = time_updated and time_archived > 0;
-- 176
select count(*) from (
  select time_archived from session_v2 order by time_updated desc limit 50
) where time_archived is not null and time_archived > 0;
-- 47

In the app the archived sessions sit at the top of the list, ahead of everything
actually recent.

All fixes are small

GET /api/session already accepts archived (true | false) and project, so
any of these works:

  1. server — treat an absent archived param as false, so archived sessions
    are opt-in;
  2. client — pass archived=false (and project=<id> when the list is scoped)
    on the default list request;
  3. ordering — order the default list by the last message instead of by a session
    column that bookkeeping rewrites (same direction as session: idle sessions gain time_updated after a service restart and jump to the top of the list #63920), at the cost of a join.

One thing I could not measure: the desktop's list request parameters are not in the
retained server log, so I am not claiming which side drops them. #58364 was exactly
this shape on the TUI — the API filter existed and the picker did not pass it — and
was closed as completed on 2026-11-02. This is the same problem on the desktop side
and in the default API response.

Related

I'm happy to prepare a patch if you say which side the default should live on.

Activity

  1. opencodejr commented on Nov 14, 2026

    @opencodejr
    Contributor

    Thanks for the careful measurements and the offer of a patch, @ValDagon.

    You're asking for GET /api/session to stop putting archived sessions on the default page. That could mean leaving them out unless archived is passed, or ordering the default list by something that archiving doesn't rewrite.

    From the code I read, this is how it currently works:

    • Archiving sets time_updated along with time_archived on purpose (packages/core/src/session/projector.ts), and unarchiving does the same.
    • The list endpoint applies the archived filter only when archived is passed (packages/core/src/session/store.ts). So the default newest-50 page includes archived sessions, as you found.

    Since this is the current design, I've filed it as a feature request. Maintainers will decide whether the default belongs on the server, in the clients, or in the ordering, so please hold off on the patch until they've weighed in. I can't promise an outcome.

    On the app side, I couldn't find where archived sessions would show. The views I read all leave them out:

    • Home fetches a page of 500 and drops archived sessions on the client (packages/app/src/home/sessions/index.ts).
    • The recent-sessions list, the command palette and session search all request archived: false.

    If a specific view in the desktop app on 2.3.0 does list archived sessions at the top, a comment naming that view (Home, the sidebar, the palette…) and a screenshot would help. That part would then be handled as a bug.

    Related issues:

  2. added
    area/sdk-api
    type/feature
    version/v2
    on Nov 14, 2026
  3. ValDagon commented on Nov 14, 2026

    @ValDagon
    Author

    Correction on the desktop part of this report

    The API numbers stand: the default page of GET /api/session (newest 50, no
    parameters) is 47/50 archived, because archiving stamps time_updated.

    The line "In the app the archived sessions sit at the top of the list" is not
    something I checked on a screen. It came from that API result, and I should have
    said so instead of presenting it as an observation.

    Reading dev, no ordinary list shows them:

    • Home drops time.archived !== undefined, both on load and on merge
      (packages/app/src/home/sessions/index.ts).
    • The palette passes archived: false
      (packages/app/src/shell/commands/palette.ts).
    • The sidebar keeps archived sessions out of the list and says they live in the
      Archived dialog, which loads them through a separate query
      (packages/app/src/shell/titlebar/inbox.tsx, inbox-model.ts).

    So "the client simply does not pass it" was wrong too.

    What I am still asking for is narrower than what I wrote: the default response of
    GET /api/session returns archived rows and orders by a column that archiving
    rewrites, and the 47/50 page is what any consumer of that default gets. Treat the
    desktop-UI half as withdrawn — if a maintainer wants it reopened, I will reproduce
    on 2.3.0 and bring a screenshot.

  4. oliver-mee commented on Nov 25, 2026

    @oliver-mee

    Reproduced on v2.4.1 (Linux, fresh data directory).

    • Created five sessions a second apart, then archived the oldest. The PATCH returned 204 and set time.updated == time.archived, 29s after that session was created.
    • The unmodified GET /api/session returned the archived session first straight away.
    • Unarchiving also rewrites time.updated. time.archived is cleared and time.updated moves forward again, so restoring a session sends it to the top too.
    • opencode session list --max-count 10 shows the archived session at row 1 with the archive timestamp. Nothing marks it as archived and there is no flag to exclude it.
    • Repeating the same PATCH is a no-op and leaves time.updated alone, so the reorder happens once per state change, not on every sweep.

    The query filter works correctly for both ?archived=true and ?archived=false, so the client and server options in the report both have what they need.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/sdk-apiplatform/macostype/featureversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions