Skip to content

Conversation

@cedefrespo
Copy link

Summary

  • Adds linear search fallback when Binary.search fails to find a session in the store
  • Fixes session rename not reflecting in the UI immediately
  • Fixes session delete potentially not syncing to UI

Problem

The session.updated and session.deleted event handlers use Binary.search to find sessions in the store array. However, the binary search can fail to find sessions when the store array order differs from the expected sort order (e.g., due to timing issues or string comparison edge cases).

This causes:

  • Session renames to appear to not work (the JSON file IS updated, but the UI doesn't reflect it)
  • Session deletes to potentially not sync

Solution

Add a linear search fallback (Array.findIndex) when Binary.search returns found: false. This ensures the session is found and updated in the UI regardless of array ordering.

The fix is minimal and defensive - it only runs the linear search if binary search fails, so there's no performance impact in the normal case.

Testing

  1. Open OpenCode TUI
  2. Create a session and send a message
  3. Open session list (Ctrl+X L)
  4. Rename session (Ctrl+R)
  5. Submit new name
  6. ✅ Session title should update immediately in the list

Fixes #5494
Fixes #3779

Binary.search may fail to find sessions when the store array order
differs from expected sort order. This adds a linear search fallback
to ensure session updates (rename) and deletes are properly synced
to the UI.

Fixes sst#5494
Fixes sst#3779
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session rename (via /rename or /session + ctrl-r) not working Renaming chat sessions not working

1 participant