| ... | @@ -14,12 +14,14 @@ import { Button } from "../components/ui/button"; | ... | @@ -14,12 +14,14 @@ import { Button } from "../components/ui/button"; |
| 14 | import { AnchoredToastProvider, ToastProvider, toastManager } from "../components/ui/toast"; | 14 | import { AnchoredToastProvider, ToastProvider, toastManager } from "../components/ui/toast"; |
| 15 | import { serverConfigQueryOptions, serverQueryKeys } from "../lib/serverReactQuery"; | 15 | import { serverConfigQueryOptions, serverQueryKeys } from "../lib/serverReactQuery"; |
| 16 | import { readNativeApi } from "../nativeApi"; | 16 | import { readNativeApi } from "../nativeApi"; |
| | 17 | import { useComposerDraftStore } from "../composerDraftStore"; |
| 17 | import { useStore } from "../store"; | 18 | import { useStore } from "../store"; |
| 18 | import { useTerminalStateStore } from "../terminalStateStore"; | 19 | import { useTerminalStateStore } from "../terminalStateStore"; |
| 19 | import { preferredTerminalEditor } from "../terminal-links"; | 20 | import { preferredTerminalEditor } from "../terminal-links"; |
| 20 | import { terminalRunningSubprocessFromEvent } from "../terminalActivity"; | 21 | import { terminalRunningSubprocessFromEvent } from "../terminalActivity"; |
| 21 | import { onServerConfigUpdated, onServerWelcome } from "../wsNativeApi"; | 22 | import { onServerConfigUpdated, onServerWelcome } from "../wsNativeApi"; |
| 22 | import { providerQueryKeys } from "../lib/providerReactQuery"; | 23 | import { providerQueryKeys } from "../lib/providerReactQuery"; |
| | 24 | import { collectActiveTerminalThreadIds } from "../lib/terminalStateCleanup"; |
| 23 | | 25 | |
| 24 | export const Route = createRootRouteWithContext<{ | 26 | export const Route = createRootRouteWithContext<{ |
| 25 | queryClient: QueryClient; | 27 | queryClient: QueryClient; |
| ... | @@ -154,9 +156,13 @@ function EventRouter() { | ... | @@ -154,9 +156,13 @@ function EventRouter() { |
| 154 | if (disposed) return; | 156 | if (disposed) return; |
| 155 | latestSequence = Math.max(latestSequence, snapshot.snapshotSequence); | 157 | latestSequence = Math.max(latestSequence, snapshot.snapshotSequence); |
| 156 | syncServerReadModel(snapshot); | 158 | syncServerReadModel(snapshot); |
| 157 | const activeThreadIds = new Set( | 159 | const draftThreadIds = Object.keys( |
| 158 | snapshot.threads.filter((t) => t.deletedAt === null).map((t) => t.id), | 160 | useComposerDraftStore.getState().draftThreadsByThreadId, |
| 159 | ); | 161 | ) as ThreadId[]; |
| | 162 | const activeThreadIds = collectActiveTerminalThreadIds({ |
| | 163 | snapshotThreads: snapshot.threads, |
| | 164 | draftThreadIds, |
| | 165 | }); |
| 160 | removeOrphanedTerminalStates(activeThreadIds); | 166 | removeOrphanedTerminalStates(activeThreadIds); |
| 161 | if (pending) { | 167 | if (pending) { |
| 162 | pending = false; | 168 | pending = false; |