Skip to content

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

fix(chat): dedupe a core failure by its run id, not its text\n\nThe `chat_error` handler skipped its append whenever the last cached row\nwas an agent message carrying the same content. Core-owned turns now\npersist under a deterministic `agent:<run_id>`, and two runs can fail\nwith byte-identical text — the same sanitized upstream provider message,\nor the generic fallback — so that check read the previous run's row as\nthis one and dropped the new failure from the frontend cache. Unlike the\ndone path, `chat_error` does not re-hydrate from the core snapshot, so\nthe row stayed missing until the next reload.\n\nDedupe on `agent:<run_id>` when the event carries one, and keep the text\ncheck for interactive turns, which have no pre-persisted id to match on.\n

Shanuec09ad0a905c
diff --git a/app/src/providers/ChatRuntimeProvider.tsx b/app/src/providers/ChatRuntimeProvider.tsx
index 2e188b2eee..598de6168d 100644
--- a/app/src/providers/ChatRuntimeProvider.tsx
+++ b/app/src/providers/ChatRuntimeProvider.tsx
@@ -1355,12 +1355,22 @@ const ChatRuntimeProvider = ({ children }: { children: React.ReactNode }) => {
// surfacing it tells the user *why* the turn failed instead of a blanket apology.
// The hardcoded constant is only a last-resort fallback for an empty/missing message.
const errorContent = event.message || USER_FACING_AGENT_ERROR_MESSAGE;
- if (!(lastMsg?.sender === 'agent' && lastMsg?.content === errorContent)) {
+ // A core-owned failure carries a deterministic id, so dedupe on that
+ // rather than on the text. Two runs can fail with byte-identical
+ // content — the same upstream provider message, or the generic
+ // fallback above — and a text check would then read the previous
+ // run's row as this one and drop the current failure from the cache.
+ // Interactive turns have no pre-persisted id and keep the text check.
+ const errorMessageId = corePersistedMessageId(event);
+ const alreadyPresent = errorMessageId
+ ? threadMessages.some(message => message.id === errorMessageId)
+ : lastMsg?.sender === 'agent' && lastMsg?.content === errorContent;
+ if (!alreadyPresent) {
void dispatch(
addInferenceResponse({
content: errorContent,
threadId: event.thread_id,
- messageId: corePersistedMessageId(event),
+ messageId: errorMessageId,
})
);
}
diff --git a/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx b/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
index a033128100..91f9498273 100644
--- a/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
+++ b/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
@@ -533,6 +533,78 @@ describe('ChatRuntimeProvider — dedupe, proactive resolution, mid-turn invaria
);
});
+ it('persists a second core failure with identical text under its own id (#5933)', async () => {
+ const listeners = renderProvider();
+
+ act(() => {
+ listeners.onError?.({
+ thread_id: 't-sys-err-dup',
+ request_id: 'bgdeliver-a',
+ client_id: 'system',
+ message: 'Run failed: boom',
+ error_type: 'inference',
+ round: null,
+ });
+ });
+
+ await waitFor(() =>
+ expect(threadApi.appendMessage).toHaveBeenCalledWith(
+ 't-sys-err-dup',
+ expect.objectContaining({ id: 'agent:bgdeliver-a' })
+ )
+ );
+
+ // Same thread, same failure text, a different run. The core persisted
+ // this one as `agent:bgdeliver-b`; deduping on the last row's content
+ // would read the previous run's row as this one and drop the new
+ // failure from the cache entirely.
+ act(() => {
+ listeners.onError?.({
+ thread_id: 't-sys-err-dup',
+ request_id: 'bgdeliver-b',
+ client_id: 'system',
+ message: 'Run failed: boom',
+ error_type: 'inference',
+ round: null,
+ });
+ });
+
+ await waitFor(() =>
+ expect(threadApi.appendMessage).toHaveBeenCalledWith(
+ 't-sys-err-dup',
+ expect.objectContaining({ id: 'agent:bgdeliver-b', sender: 'agent' })
+ )
+ );
+ expect(threadApi.appendMessage).toHaveBeenCalledTimes(2);
+ });
+
+ it('still suppresses a repeat of the same core failure event', async () => {
+ const listeners = renderProvider();
+ const fire = () =>
+ act(() => {
+ listeners.onError?.({
+ thread_id: 't-sys-err-same',
+ request_id: 'bgdeliver-c',
+ client_id: 'system',
+ message: 'Run failed: boom',
+ error_type: 'inference',
+ round: null,
+ });
+ });
+
+ fire();
+ await waitFor(() => expect(threadApi.appendMessage).toHaveBeenCalledTimes(1));
+
+ // The row is in the cache under `agent:bgdeliver-c` now, so the id check
+ // recognises the redelivery. Trading the content check for an id check
+ // must not turn a duplicate event into a duplicate append.
+ fire();
+ await act(async () => {
+ await Promise.resolve();
+ });
+ expect(threadApi.appendMessage).toHaveBeenCalledTimes(1);
+ });
+
it('keeps a generated id for an interactive chat_done (nothing else persisted it)', async () => {
const listeners = renderProvider();