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(chat): never schedule a silence timer onto an unmounted page
M3gA-Mindb90ba40fcf8a
diff --git a/app/src/features/conversations/Conversations.tsx b/app/src/features/conversations/Conversations.tsxindex 85a6ade8fd..b381e37092 100644--- a/app/src/features/conversations/Conversations.tsx+++ b/app/src/features/conversations/Conversations.tsx@@ -581,6 +581,9 @@ const Conversations = ({// timer keyed by thread id, so concurrent turns on different threads don't// share (and clobber) a single timeout.const sendingTimeoutsRef = useRef<Map<string, ReturnType<typeof setTimeout>>>(new Map());+ // Live for as long as this instance is: flipped in the unmount cleanup so an+ // async continuation cannot schedule a watchdog onto a torn-down page.+ const isMountedRef = useRef(true);// Ref so the mount-time dictation event handler can call the latest send fn.const handleSendMessageRef = useRef<((text?: string) => Promise<void>) | null>(null);// Refs the assistant-ui chat-surface registration binds through. Both target@@ -842,6 +845,17 @@ const Conversations = ({const armSilenceTimer = (threadId: string) => {clearSilenceTimer(threadId);+ // Never schedule onto a torn-down instance. `handleSendMessage` awaits+ // `addMessageLocal` before arming, so an unmount landing inside that await+ // runs the cleanup below — which finds nothing — and the continuation then+ // schedules a timer no cleanup will ever reach. Nothing can rearm it+ // either, so it survives to clear shared runtime state for a turn that may+ // still be live. The send itself is unaffected; only the watchdog is+ // skipped, which is correct: a page that is gone cannot supervise a turn.+ if (!isMountedRef.current) {+ debug(`armSilenceTimer: instance unmounted — not scheduling for ${threadId}`);+ return;+ }const timeout = setTimeout(() => {debug(`armSilenceTimer: no inference signal for 120s — clearing runtime (${threadId})`);setSendError(chatSendError('safety_timeout', t('chat.safetyTimeout')));@@ -872,6 +886,7 @@ const Conversations = ({useEffect(() => {const timers = sendingTimeoutsRef.current;return () => {+ isMountedRef.current = false;for (const timeout of timers.values()) clearTimeout(timeout);timers.clear();};diff --git a/app/src/pages/__tests__/Conversations.render.test.tsx b/app/src/pages/__tests__/Conversations.render.test.tsxindex 57598abaad..0507a201bf 100644--- a/app/src/pages/__tests__/Conversations.render.test.tsx+++ b/app/src/pages/__tests__/Conversations.render.test.tsx@@ -1589,6 +1589,36 @@ describe('Conversations — smoke render (#1123 welcome-lock removal)', () => {}});+ it('does not schedule a silence timer once the page has unmounted', async () => {+ // The send path awaits `addMessageLocal` before arming, so an unmount that+ // lands inside that await runs the cleanup — which finds nothing — and the+ // continuation would then schedule a timer no cleanup can ever reach.+ // Nothing can rearm it either, so it would survive to clear shared runtime+ // state for a turn that may still be live.+ vi.useFakeTimers({ shouldAdvanceTime: true });+ vi.mocked(threadApi.getTurnState).mockResolvedValue(inFlightSnapshot());+ try {+ const { store } = await renderSelectedConversation();+ await waitFor(() => {+ expect(store?.getState().chatRuntime.inferenceStatusByThread['send-thread']).toBeDefined();+ });++ // Tear down, then let hydration's own effects settle. Any arming that+ // happens after this point is arming onto a dead instance.+ await act(async () => {+ cleanup();+ });+ await act(async () => {+ await vi.advanceTimersByTimeAsync(120_000);+ });++ expect(store?.getState().chatRuntime.inferenceStatusByThread['send-thread']).toBeDefined();+ } finally {+ vi.mocked(threadApi.getTurnState).mockResolvedValue(null);+ vi.useRealTimers();+ }+ });+it('does not fire an armed silence timer after the page unmounts', async () => {// The timer's callback outlives this component: it dispatches// `clearRuntimeForThread` / `clearThreadInferenceActive` into the shared