Skip to content

Commit 342dacc

Browse files
committed
Fix threadPlanCatalogCache leak and restore snapshot sync before implementation thread navigation
- Prune stale entries from threadPlanCatalogCache when threads are removed from the store, preventing unbounded growth of the module-level Map. - Re-add snapshot sync (getSnapshot + syncServerReadModel) before navigating to a newly created implementation thread, ensuring the thread exists in the store before ChatView renders. Also restore the snapshot sync in the error cleanup path.
1 parent a7dc0c9 commit 342dacc

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

apps/web/src/components/ChatView.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,14 @@ export default function ChatView({ threadId }: ChatViewProps) {
494494
const threadPlanCatalog = useStore(
495495
useShallow((store) => store.threads.map(toThreadPlanCatalogEntry)),
496496
);
497+
useEffect(() => {
498+
const activeIds = new Set(threadPlanCatalog.map((t) => t.id));
499+
for (const id of threadPlanCatalogCache.keys()) {
500+
if (!activeIds.has(id)) {
501+
threadPlanCatalogCache.delete(id);
502+
}
503+
}
504+
}, [threadPlanCatalog]);
497505
const localDraftError = serverThread ? null : (localDraftErrorsByThreadId[threadId] ?? null);
498506
const localDraftThread = useMemo(
499507
() =>
@@ -3158,7 +3166,9 @@ export default function ChatView({ threadId }: ChatViewProps) {
31583166
createdAt,
31593167
});
31603168
})
3161-
.then(() => {
3169+
.then(() => api.orchestration.getSnapshot())
3170+
.then((snapshot) => {
3171+
useStore.getState().syncServerReadModel(snapshot);
31623172
// Signal that the plan sidebar should open on the new thread.
31633173
planSidebarOpenOnNextThreadRef.current = true;
31643174
return navigate({
@@ -3174,6 +3184,12 @@ export default function ChatView({ threadId }: ChatViewProps) {
31743184
threadId: nextThreadId,
31753185
})
31763186
.catch(() => undefined);
3187+
await api.orchestration
3188+
.getSnapshot()
3189+
.then((snapshot) => {
3190+
useStore.getState().syncServerReadModel(snapshot);
3191+
})
3192+
.catch(() => undefined);
31773193
toastManager.add({
31783194
type: "error",
31793195
title: "Could not start implementation thread",

0 commit comments

Comments
 (0)