Skip to content

--continue selects wrong session due to incorrect sort order in sync.tsx #5510

@Brandtweary

Description

@Brandtweary

Description

Sessions are sorted by ID string comparison (a.id.localeCompare(b.id)) but session IDs use descending timestamp encoding (newer sessions have lexicographically smaller IDs via Identifier.descending()). This causes --continue to select an old/stale session instead of the most recently updated one.

Root cause:
packages/opencode/src/cli/cmd/tui/context/sync.tsx:282
(x.data ?? []).toSorted((a, b) => a.id.localeCompare(b.id))

Fix:
Sort by timestamp instead:
(x.data ?? []).toSorted((a, b) => b.time.updated - a.time.updated)

OpenCode version

1.0.152 (built from source, dev branch)

Steps to reproduce

  1. Have multiple sessions (created over several hours/days)
  2. Run opencode --continue
  3. Observe that it opens an old session instead of the most recently updated one

Screenshot and/or share link

No response

Operating System

Pop!_OS 22.04 LTS

Terminal

Zed IDE integrated terminal

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingopentuiThis relates to changes in v1.0, now that opencode uses opentui

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions