Skip to content

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

fix(chat): correct provider to restore missing chat history

Steven Enamakel5de523ecf3c8
diff --git a/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx b/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
index 551fb1246d..00bd9b02f2 100644
--- a/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
+++ b/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
@@ -2337,19 +2337,24 @@ describe('ChatRuntimeProvider — chat_cancelled (wire-contract.md)', () => {
it('does not double-persist a partial the local Stop path already saved for the same request', async () => {
const listeners = renderProvider();
const threadId = 't-chat-cancelled-dedupe';
+ const alreadyPersisted = {
+ id: 'a-already-stopped',
+ sender: 'agent' as const,
+ type: 'text' as const,
+ content: 'already saved locally',
+ extraMetadata: { stopped: true, cancelReason: 'user_stop', requestId: 'r-dup' },
+ createdAt: '2026-01-01T00:00:00.000Z',
+ };
+ vi.mocked(threadApi.appendMessage).mockResolvedValueOnce(alreadyPersisted);
- act(() => {
- store.dispatch(
- loadThreads.fulfilled(
- { threads: [], count: 0 },
- '',
- undefined as never
- )
- );
- });
// Seed the local cache exactly as `Conversations.tsx`'s
- // `handleStopGeneration` does, keyed by the same `requestId`.
- store.getState(); // no-op read to keep lint happy about unused import removal
+ // `handleStopGeneration` already does for a user-initiated Stop, keyed by
+ // the same `requestId` this turn's `chat_cancelled` will carry.
+ await act(async () => {
+ await store.dispatch(addMessageLocal({ threadId, message: alreadyPersisted })).unwrap();
+ });
+ expect(threadApi.appendMessage).toHaveBeenCalledTimes(1);
+
act(() => {
store.dispatch(
setStreamingAssistantForThread({
@@ -2368,7 +2373,9 @@ describe('ChatRuntimeProvider — chat_cancelled (wire-contract.md)', () => {
});
await new Promise(resolve => setTimeout(resolve, 50));
- expect(threadApi.appendMessage).toHaveBeenCalledTimes(0);
+ // Still just the one call from the seed above — `onCancelled` must not
+ // have persisted a second copy of the same partial.
+ expect(threadApi.appendMessage).toHaveBeenCalledTimes(1);
});
it('produces no message when nothing streamed (no partial to save)', async () => {