Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix: preserve failed-turn recovery across transcript and UI

Steven Enamakeld1a6f45c994e
diff --git a/app/src/providers/ChatRuntimeProvider.tsx b/app/src/providers/ChatRuntimeProvider.tsx
index 7898c5e13b..5a66ce6fd9 100644
--- a/app/src/providers/ChatRuntimeProvider.tsx
+++ b/app/src/providers/ChatRuntimeProvider.tsx
@@ -1845,20 +1845,28 @@ const ChatRuntimeProvider = ({ children }: { children: React.ReactNode }) => {
segmentDeliveriesRef.current,
segmentDeliveryKey(event.thread_id, event.request_id)
);
- dispatch(clearInferenceStatusForThread({ threadId: event.thread_id }));
- dispatch(clearStreamingAssistantForThread({ threadId: event.thread_id }));
- dispatch(clearPendingApprovalForThread({ threadId: event.thread_id }));
- dispatch(clearPendingPlanReviewForThread({ threadId: event.thread_id }));
-
- const existing = store.getState().chatRuntime.toolTimelineByThread[event.thread_id] ?? [];
- if (existing.length > 0) {
- const entries = existing.map(entry =>
- entry.status === 'running' ? { ...entry, status: 'error' as const } : entry
- );
- dispatch(setToolTimelineForThread({ threadId: event.thread_id, entries }));
+ const currentState = store.getState();
+ const liveRequestId =
+ currentState.chatRuntime.liveRequestIdByThread[event.thread_id] ??
+ currentState.chatRuntime.streamingAssistantByThread[event.thread_id]?.requestId;
+ const olderTurn = Boolean(
+ event.request_id && liveRequestId && event.request_id !== liveRequestId
+ );
+ if (!olderTurn) {
+ dispatch(clearInferenceStatusForThread({ threadId: event.thread_id }));
+ dispatch(clearStreamingAssistantForThread({ threadId: event.thread_id }));
+ dispatch(clearPendingApprovalForThread({ threadId: event.thread_id }));
+ dispatch(clearPendingPlanReviewForThread({ threadId: event.thread_id }));
+
+ const existing = currentState.chatRuntime.toolTimelineByThread[event.thread_id] ?? [];
+ if (existing.length > 0) {
+ const entries = existing.map(entry =>
+ entry.status === 'running' ? { ...entry, status: 'error' as const } : entry
+ );
+ dispatch(setToolTimelineForThread({ threadId: event.thread_id, entries }));
+ }
}
- const currentState = store.getState();
const threadMessages = currentState.thread.messagesByThreadId[event.thread_id] ?? [];
const lastMsg = threadMessages[threadMessages.length - 1];
// Every error_type — including the generic 'inference' fallback — carries a
@@ -1898,6 +1906,11 @@ const ChatRuntimeProvider = ({ children }: { children: React.ReactNode }) => {
});
requestUsageRefresh();
+ // The core can start a queued follow-up before delivering the prior
+ // turn's error. Its error card still belongs in the thread, but the
+ // live lifecycle and composer now belong to the follow-up request.
+ if (olderTurn) return;
+
// The backend drains + dispatches queued follow-ups even when the turn
// errored, so flush them to the transcript here too (otherwise their
// prompts are lost). Mirrors the done path (sequential internally).
diff --git a/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx b/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
index b2d61054b8..590b870f7d 100644
--- a/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
+++ b/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
@@ -8,6 +8,7 @@ import { threadApi } from '../../services/api/threadApi';
import { socketService } from '../../services/socketService';
import { store } from '../../store';
import {
+ beginInferenceTurn,
clearAllChatRuntime,
findPendingDelegationContext,
registerParallelRequest,
@@ -1792,6 +1793,41 @@ describe('ChatRuntimeProvider — dedupe, proactive resolution, mid-turn invaria
expect(store.getState().chatRuntime.inferenceStatusByThread['t-err']).toBeUndefined();
});
+ it('keeps a queued follow-up live when the previous turn error arrives late', async () => {
+ const listeners = renderProvider();
+ const threadId = 't-late-error';
+ act(() => {
+ store.dispatch(beginInferenceTurn({ threadId }));
+ store.dispatch(setActiveThread(threadId));
+ listeners.onInferenceStart?.({ thread_id: threadId, request_id: 'new' });
+ store.dispatch(
+ setStreamingAssistantForThread({
+ threadId,
+ streaming: { content: 'new answer', thinking: '', requestId: 'new' },
+ })
+ );
+ listeners.onError?.({
+ thread_id: threadId,
+ request_id: 'old',
+ message: 'Earlier turn failed',
+ error_type: 'inference',
+ round: 0,
+ });
+ });
+
+ const state = store.getState();
+ expect(state.chatRuntime.liveRequestIdByThread[threadId]).toBe('new');
+ expect(state.chatRuntime.inferenceTurnLifecycleByThread[threadId]).toBe('streaming');
+ expect(state.chatRuntime.streamingAssistantByThread[threadId]?.content).toBe('new answer');
+ expect(state.thread.activeThreadIds[threadId]).toBe(true);
+ await waitFor(() =>
+ expect(threadApi.appendMessage).toHaveBeenCalledWith(
+ threadId,
+ expect.objectContaining({ content: 'Earlier turn failed' })
+ )
+ );
+ });
+
it('forwards the server-provided inference error message verbatim', async () => {
const listeners = renderProvider();
// Transport-level failures yield no provider `error.message` body, so
diff --git a/crates/openhuman-core/src/web_chat/ops/start_chat.rs b/crates/openhuman-core/src/web_chat/ops/start_chat.rs
index 2bac41f312..ac5c813a0c 100644
--- a/crates/openhuman-core/src/web_chat/ops/start_chat.rs
+++ b/crates/openhuman-core/src/web_chat/ops/start_chat.rs
@@ -646,6 +646,13 @@ pub async fn start_chat(
};
followups
};
+ // Announce the failed turn before starting its queued successor.
+ // Socket subscribers then observe the old terminal event before
+ // any inference_start from the follow-up, even if it starts at
+ // once on another task.
+ if let Some(event) = deferred_error {
+ publish_web_channel_event(event);
+ }
if !followups.is_empty() {
log::info!(
"[web-channel] dispatching {} followup(s) thread_id={}",
@@ -667,9 +674,6 @@ pub async fn start_chat(
);
dispatch_followups(followups);
}
- if let Some(event) = deferred_error {
- publish_web_channel_event(event);
- }
},
));
diff --git a/vendor/tinyagents b/vendor/tinyagents
index c0ea84492e..f4dfc027e0 160000
--- a/vendor/tinyagents
+++ b/vendor/tinyagents
@@ -1 +1 @@
-Subproject commit c0ea84492e2a6dd0eb3866f35bd90e96f9381241
+Subproject commit f4dfc027e0730e5f9b8c7741670c5d632e3d65e2