Skip to content

Commit fc36599

Browse files
committed
fix(tui): add linear search fallback for session update/delete sync
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 anomalyco#5494 Fixes anomalyco#3779
1 parent f8bca50 commit fc36599

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

  • packages/opencode/src/cli/cmd/tui/context

‎packages/opencode/src/cli/cmd/tui/context/sync.tsx‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
148148
draft.splice(result.index, 1)
149149
}),
150150
)
151+
break
152+
}
153+
// Linear search fallback for sort order edge cases
154+
const linearIndex = store.session.findIndex((s) => s.id === event.properties.info.id)
155+
if (linearIndex !== -1) {
156+
setStore(
157+
"session",
158+
produce((draft) => {
159+
draft.splice(linearIndex, 1)
160+
}),
161+
)
151162
}
152163
break
153164
}
@@ -157,6 +168,13 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
157168
setStore("session", result.index, reconcile(event.properties.info))
158169
break
159170
}
171+
// Linear search fallback for sort order edge cases
172+
const linearIndex = store.session.findIndex((s) => s.id === event.properties.info.id)
173+
if (linearIndex !== -1) {
174+
setStore("session", linearIndex, reconcile(event.properties.info))
175+
break
176+
}
177+
// Not found, insert at binary search position
160178
setStore(
161179
"session",
162180
produce((draft) => {

0 commit comments

Comments
 (0)