opencode icon indicating copy to clipboard operation
opencode copied to clipboard

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

Open Brandtweary opened this issue 2 weeks ago • 2 comments

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

Brandtweary avatar Dec 14 '25 04:12 Brandtweary

This issue might be a duplicate of existing issues. Please check:

  • #4378: --continue doesn't always continue the project's previous session

Feel free to ignore if none of these address your specific case.

github-actions[bot] avatar Dec 14 '25 04:12 github-actions[bot]

Not the same as #4378, that's for concurrent situations. This occurs even if you have only one instance open at a time.

Brandtweary avatar Dec 14 '25 05:12 Brandtweary