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

Closed
opened 2026-02-16 17:40:33 -05:00 by yindo · 2 comments
Owner

Originally created by @Brandtweary on GitHub (Dec 13, 2025).

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

Originally created by @Brandtweary on GitHub (Dec 13, 2025). ### 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
yindo added the opentuibug labels 2026-02-16 17:40:33 -05:00
yindo closed this issue 2026-02-16 17:40:33 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Dec 13, 2025):

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] commented on GitHub (Dec 13, 2025): 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.
Author
Owner

@Brandtweary commented on GitHub (Dec 14, 2025):

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

@Brandtweary commented on GitHub (Dec 14, 2025): Not the same as #4378, that's for concurrent situations. This occurs even if you have only one instance open at a time.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3533