The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(conversations): handle edge cases in stop generation and worker thread selection
Steven Enamakelf69e7a59cd78
diff --git a/app/src/features/conversations/Conversations.tsx b/app/src/features/conversations/Conversations.tsxindex a1f1b865a1..f8acaf08bb 100644--- a/app/src/features/conversations/Conversations.tsx+++ b/app/src/features/conversations/Conversations.tsx@@ -1452,12 +1452,38 @@ const Conversations = ({partial.trim().length,shouldPersist);- void chatCancel(threadId).then(cancelled => {- debug('[chat] stop generation: chatCancel thread=%s ok=%s', threadId, cancelled);- if (!cancelled) {- // Cancel not accepted: don't leave a misleading partial, and release the- // claim so a later Stop/ESC can persist once cancellation goes through.+ void chatCancel(threadId).then(outcome => {+ const accepted = outcome?.accepted === true;+ const turnCancelled = outcome?.turnCancelled === true;+ debug(+ '[chat] stop generation: chatCancel thread=%s accepted=%s turnCancelled=%s',+ threadId,+ accepted,+ turnCancelled+ );+ if (!accepted || !turnCancelled) {+ // Cancel not accepted, or the core had no turn to tear down: don't leave+ // a misleading partial, and release the claim so a later Stop/ESC can+ // persist once cancellation goes through.if (shouldPersist && requestId) stoppedRequestIdsRef.current.delete(requestId);+ }+ if (!accepted) return;+ if (!turnCancelled) {+ // The core has nothing running on this thread, so no `cancelled`+ // chat_error will ever arrive to clear the composer. Without this the+ // thread stays "generating" with a Stop button that can never work —+ // e.g. a turn whose terminal event was lost across a reconnect. A send+ // still waiting on its RPC is skipped: its turn may not be registered+ // yet, and its own completion path owns the state.+ if (pendingSendsRef.current.has(threadId)) {+ debug('[chat] stop generation: nothing in flight but send pending thread=%s', threadId);+ return;+ }+ debug('[chat] stop generation: nothing in flight — settling local state thread=%s', threadId);+ clearSilenceTimer(threadId);+ turnSignatureByThreadRef.current.delete(threadId);+ dispatch(clearRuntimeForThread({ threadId }));+ dispatch(clearThreadInferenceActive(threadId));return;}if (shouldPersist) {@@ -1470,7 +1496,7 @@ const Conversations = ({).then(() => debug('[chat] stop generation: persisted stopped reply thread=%s', threadId));}});- }, [selectedThreadId, streamingAssistantByThread, dispatch]);+ }, [selectedThreadId, streamingAssistantByThread, dispatch, clearSilenceTimer]);handleStopGenerationRef.current = handleStopGeneration;diff --git a/app/src/features/conversations/components/WorkerThreadRefCard.tsx b/app/src/features/conversations/components/WorkerThreadRefCard.tsxindex 2b1f5a5bb9..50a78f1873 100644--- a/app/src/features/conversations/components/WorkerThreadRefCard.tsx+++ b/app/src/features/conversations/components/WorkerThreadRefCard.tsx@@ -1,7 +1,7 @@-import { useDispatch } from 'react-redux';+import { useAppDispatch } from '../../../store/hooks';import { useT } from '../../../lib/i18n/I18nContext';-import { setActiveThread } from '../../../store/threadSlice';+import { loadThreadMessages, setSelectedThread } from '../../../store/threadSlice';import type { WorkerThreadRef } from '../utils/workerThreadRef';/**@@ -77,7 +77,7 @@ export function WorkerThreadRefCard({status?: WorkerThreadStatus;}) {const { t } = useT();- const dispatch = useDispatch();+ const dispatch = useAppDispatch();const meta: string[] = [];if (ref.agentId) meta.push(ref.agentId);if (typeof ref.iterations === 'number') {@@ -90,7 +90,14 @@ export function WorkerThreadRefCard({return (<buttontype="button"- onClick={() => dispatch(setActiveThread(ref.threadId))}+ onClick={() => {+ // Open (select) the worker thread. This used to dispatch+ // `setActiveThread`, which marks a thread as having an in-flight turn —+ // so opening a worker left a phantom "generating" state whose Stop+ // button had no turn to cancel.+ dispatch(setSelectedThread(ref.threadId));+ void dispatch(loadThreadMessages(ref.threadId));+ }}className="mt-1 flex w-full items-center justify-between gap-3 rounded-xl border border-primary-200 dark:border-primary-500/30 bg-primary-50 dark:bg-primary-500/15 px-3 py-2 text-left transition-colors hover:bg-primary-100 dark:hover:bg-primary-500/25"><div className="min-w-0"><div className="flex items-center gap-2">