fix(server): stop provider sessions after thread archive #14240
Closedkvnloo(GitHub profile, opens in a new tab)wants to merge 6 commits into
main fromrefs/pull/14240/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/server/src/orchestration/Layers/ProviderCommandReactor.ts line 1730OutdatedResolvedby kvnloo(GitHub profile, opens in a new tab)@@ -1720,5 +1720,11 @@17201720 const processSessionStopRequested = Effect.fn("processSessionStopRequested")(function* (17211721 event: Extract<ProviderIntentEvent, { type: "thread.session-stop-requested" }>,17221722 ) {1723- const thread = yield* resolveThreadShell(event.payload.threadId);1724- if (!thread) {1723+ const threadId = event.payload.threadId;1724+ const thread = yield* resolveThreadShell(threadId);1725+ // Archived threads disappear from the active shell projection before their1726+ // queued stop event necessarily reaches this reactor. ProviderService is1727+ // the runtime authority: if it still owns a session for the thread, stop it1728+ // even when the UI-facing shell is already gone.1729+ const activeSession = yield* providerService1730+ .listSessions()
- apps/server/src/orchestration/Layers/ProviderCommandReactor.ts lines 1723 to 1754Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1728,11 +1738,15 @@1738+ projectedSession?.providerInstanceId ?? activeSession?.providerInstanceId;17281739 const now = event.payload.createdAt;1729- const wasCompacting = compactingThreadIds.has(thread.id);1730- stoppingThreadIds.add(thread.id);1731- const clearStopping = Effect.sync(() => void stoppingThreadIds.delete(thread.id));1740+ const wasCompacting = compactingThreadIds.has(threadId);1741+ stoppingThreadIds.add(threadId);1742+ const clearStopping = Effect.sync(() => void stoppingThreadIds.delete(threadId));17321743 yield* cancelTurnsAfterCompaction(1733- thread.id,1744+ threadId,17341745 "The session was stopped during context compaction. Send this message again to continue.",17351746 ).pipe(17361747 Effect.andThen(1737- thread.session && thread.session.status !== "stopped"1738- ? providerService.stopSession({ threadId: thread.id })1748+ activeSession !== undefined ||1749+ (projectedSession !== null &&1750+ projectedSession !== undefined &&1751+ projectedSession.status !== "stopped")1752+ ? providerService.stopSession({ threadId })apps/server/src/orchestration/Layers/ProviderCommandReactor.ts line 1793OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1765,14 +1779,13 @@17651779 },17661780 onSuccess: () =>17671781 setThreadSession({1768- threadId: thread.id,1782+ threadId,17691783 session: {1770- threadId: thread.id,1784+ threadId,17711785 status: "stopped",1772- providerName: thread.session?.providerName ?? null,1773- ...(thread.session?.providerInstanceId !== undefined1774- ? { providerInstanceId: thread.session.providerInstanceId }1775- : {}),1776- runtimeMode: thread.session?.runtimeMode ?? DEFAULT_RUNTIME_MODE,1786+ providerName: projectedSession?.providerName ?? activeSession?.provider ?? null,1787+ ...(providerInstanceId !== undefined ? { providerInstanceId } : {}),1788+ runtimeMode:1789+ projectedSession?.runtimeMode ?? activeSession?.runtimeMode ?? DEFAULT_RUNTIME_MODE,17771790 activeTurnId: null,1778- lastError: thread.session?.lastError ?? null,1791+ lastError: projectedSession?.lastError ?? null,
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed