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): arm the 120s silence timer for a turn inherited through hydration
M3gA-Mind19ee171adba4
diff --git a/app/src/features/conversations/Conversations.tsx b/app/src/features/conversations/Conversations.tsxindex a1f1b865a1..b717ac87db 100644--- a/app/src/features/conversations/Conversations.tsx+++ b/app/src/features/conversations/Conversations.tsx@@ -858,6 +858,46 @@ const Conversations = ({sendingTimeoutsRef.current.set(threadId, timeout);};+ // A turn this client did not start still needs the 120s watchdog.+ //+ // `armSilenceTimer` is only called on the local send path, so a client that+ // reloads or reconnects mid-turn — hydrating through+ // `fetchAndHydrateTurnState` on thread selection — renders a live-looking+ // "Thinking..." pill with no timer behind it. If the terminal event is then+ // missed, nothing ever clears it: in the observed incident two sockets+ // connected mid-turn, the turn ended 95s later, and the UI still read+ // "Thinking... (15)" 25 minutes on. A core restart heals it today+ // (`mark_all_interrupted` sweeps non-terminal snapshots at startup), which is+ // why it only bites long-lived sessions.+ //+ // Arm only for a turn that is genuinely in flight. A terminal snapshot+ // deletes `inferenceStatusByThread` in the reducer's interrupted/completed+ // branch, so the status check alone already excludes one; the `interrupted`+ // guard is belt-and-braces, so this cannot start firing `safety_timeout` on a+ // settled thread if that branch ever changes. (`completed` is not a member of+ // `InferenceTurnLifecycle` — the reducer deletes the key instead of storing a+ // terminal value — so there is no such case to guard.)+ //+ // Arming is the whole fix: the rearm effect below iterates+ // `sendingTimeoutsRef` keys, so a thread holding no timer is invisible to it.+ // Once a timer exists, heartbeats (#4270), streaming text and sub-agent tool+ // activity rearm it exactly as for a locally-sent turn, and the+ // done-transition clears it — an inherited turn gets the same treatment as an+ // owned one rather than a second, parallel mechanism.+ useEffect(() => {+ if (!selectedThreadId) return;+ // A local send already armed one. Never replace it: re-arming here would+ // hand the turn a fresh 120s every time this effect re-ran.+ if (sendingTimeoutsRef.current.has(selectedThreadId)) return;+ if (!inferenceStatusByThread[selectedThreadId]) return;+ if (inferenceTurnLifecycleByThread[selectedThreadId] === 'interrupted') return;+ debug(`inherited in-flight turn on ${selectedThreadId} — arming silence timer`);+ armSilenceTimer(selectedThreadId);+ // `armSilenceTimer` reads only refs and `dispatch`, so it is stable enough+ // to omit; including it would re-run this on every render.+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [selectedThreadId, inferenceStatusByThread, inferenceTurnLifecycleByThread]);+// Rearm the silence timer on every inference signal for the sending// thread. Top-level tool / iteration events bump `inferenceStatusByThread`;// pure-text streams (no tools) only bump `streamingAssistantByThread`;diff --git a/app/src/pages/__tests__/Conversations.render.test.tsx b/app/src/pages/__tests__/Conversations.render.test.tsxindex 7c76674c8e..36d7235640 100644--- a/app/src/pages/__tests__/Conversations.render.test.tsx+++ b/app/src/pages/__tests__/Conversations.render.test.tsx@@ -1438,6 +1438,119 @@ describe('Conversations — smoke render (#1123 welcome-lock removal)', () => {}});+ // A snapshot describing a turn that is still running, as the core would have+ // persisted it at its last flush boundary.+ function inFlightSnapshot(lifecycle: 'started' | 'streaming' = 'streaming') {+ return {+ threadId: 'send-thread',+ requestId: 'req-inherited-1',+ lifecycle,+ iteration: 15,+ maxIterations: 50,+ phase: 'thinking' as const,+ streamingText: '',+ thinking: '',+ toolTimeline: [],+ startedAt: new Date().toISOString(),+ updatedAt: new Date().toISOString(),+ };+ }++ it('arms the silence timer for a turn inherited through hydration', async () => {+ // Regression: `armSilenceTimer` was only called on the local send path, so+ // a client that reloaded or reconnected mid-turn hydrated a live-looking+ // "Thinking…" pill with no watchdog behind it. If the terminal event was+ // then missed the pill never cleared — observed sitting on "Thinking… (15)"+ // 25 minutes after the turn had ended.+ vi.useFakeTimers({ shouldAdvanceTime: true });+ vi.mocked(threadApi.getTurnState).mockResolvedValue(inFlightSnapshot());+ try {+ const { store } = await renderSelectedConversation();++ // Hydration produced a live turn — without this the test could pass by+ // asserting a timeout on a thread that was never rendered as running.+ await waitFor(() => {+ expect(store?.getState().chatRuntime.inferenceStatusByThread['send-thread']).toBeDefined();+ });+ expect(screen.queryByTestId('chat-send-error')).toBeNull();++ await act(async () => {+ await vi.advanceTimersByTimeAsync(120_000);+ });++ const banner = await screen.findByTestId('chat-send-error');+ expect(banner).toHaveAttribute('data-chat-send-error-code', 'safety_timeout');+ expect(store?.getState().chatRuntime.inferenceStatusByThread['send-thread']).toBeUndefined();+ } finally {+ vi.mocked(threadApi.getTurnState).mockResolvedValue(null);+ vi.useRealTimers();+ }+ });++ it.each(['interrupted', 'completed'] as const)(+ 'does not arm the silence timer for a %s snapshot',+ async lifecycle => {+ // A terminal snapshot has no live driver. Arming here would fire a+ // spurious `safety_timeout` on a thread that has already settled.+ vi.useFakeTimers({ shouldAdvanceTime: true });+ vi.mocked(threadApi.getTurnState).mockResolvedValue({ ...inFlightSnapshot(), lifecycle });+ try {+ const { store } = await renderSelectedConversation();++ await act(async () => {+ await vi.advanceTimersByTimeAsync(120_000);+ });++ expect(screen.queryByTestId('chat-send-error')).toBeNull();+ expect(+ store?.getState().chatRuntime.inferenceStatusByThread['send-thread']+ ).toBeUndefined();+ } finally {+ vi.mocked(threadApi.getTurnState).mockResolvedValue(null);+ vi.useRealTimers();+ }+ }+ );++ it('rearms an inherited silence timer on a heartbeat', async () => {+ // #4270: a silent reasoning phase emits only heartbeats. A hydrated timer+ // must take part in the rearm effect exactly as a locally-armed one does,+ // or a genuinely live inherited turn trips the watchdog mid-run.+ 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();+ });++ await act(async () => {+ await vi.advanceTimersByTimeAsync(80_000);+ });+ await act(async () => {+ store?.dispatch(bumpInferenceHeartbeatForThread({ threadId: 'send-thread' }));+ });+ await act(async () => {+ await vi.advanceTimersByTimeAsync(80_000);+ });++ // 160s since hydration, but only 80s since the beat — still armed.+ expect(screen.queryByTestId('chat-send-error')).toBeNull();++ // Control: the timer was rearmed, NOT cancelled. Without this, the+ // assertion above would pass just as well if the heartbeat had cleared+ // the timer outright.+ await act(async () => {+ await vi.advanceTimersByTimeAsync(60_000);+ });+ const banner = await screen.findByTestId('chat-send-error');+ expect(banner).toHaveAttribute('data-chat-send-error-code', 'safety_timeout');+ } finally {+ vi.mocked(threadApi.getTurnState).mockResolvedValue(null);+ vi.useRealTimers();+ }+ });+it('rearms the silence timer on sub-agent tool-timeline updates', async () => {// Regression: when a delegated sub-agent (`Research`, `Tools Agent`,// …) is running, the parent thread's `inferenceStatusByThread` and