opencode
opencode copied to clipboard
fix(tui): add linear search fallback for session update/delete sync
Summary
- Adds linear search fallback when
Binary.searchfails 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
- Open OpenCode TUI
- Create a session and send a message
- Open session list (
Ctrl+X L) - Rename session (
Ctrl+R) - Submit new name
- ✅ Session title should update immediately in the list
Fixes #5494 Fixes #3779