[PR #5518] fix(tui): add linear search fallback for session update/delete sync #11450

Closed
opened 2026-02-16 18:16:17 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/5518

State: closed
Merged: No


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

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/5518 **State:** closed **Merged:** No --- ## 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
yindo added the pull-request label 2026-02-16 18:16:17 -05:00
yindo closed this issue 2026-02-16 18:16:17 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11450