Skip to content

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

test(providers): cover repeated next-turn history stability

Steven Enamakel3232d8f471c4
diff --git a/app/src/providers/__tests__/assistantUiMessages.test.ts b/app/src/providers/__tests__/assistantUiMessages.test.ts
index c6953c4e6b..ef071e5687 100644
--- a/app/src/providers/__tests__/assistantUiMessages.test.ts
+++ b/app/src/providers/__tests__/assistantUiMessages.test.ts
@@ -969,3 +969,23 @@ describe('next-turn history stability', () => {
expect(after[1]).toBe(before[1]);
});
});
+
+
+it('simulates repeated next turns without changing settled part order or identities', () => {
+ const history: ThreadMessage[] = [];
+ let previous: ReturnType<typeof buildRuntimeMessages> = [];
+ for (let turn = 0; turn < 12; turn++) {
+ history.push(msg({id: `user-${turn}`, content: turn ? 'try now' : 'first turn'}));
+ for (const text of ['Thinking', 'Working', 'Finished']) {
+ const running = buildRuntimeMessages(history, {requestId: `r${turn}`, content: text, thinking: ''}, {isRunning: true, liveRequestId: `r${turn}`});
+ previous.forEach((message, index) => expect(running[index]).toBe(message));
+ expect(running.at(-2)?.id).toBe(`user-${turn}`);
+ expect(running.at(-1)?.id).toBe(STREAMING_TAIL_ID);
+ }
+ history.push(msg({id: `agent-${turn}`, sender: 'agent', content: `Completed turn ${turn}`, extraMetadata: {requestId: `r${turn}`}}));
+ const settled = buildRuntimeMessages(history, null, {isRunning: false});
+ previous.forEach((message, index) => expect(settled[index]).toBe(message));
+ expect(settled.map(message => message.role)).toEqual(Array.from({length: turn + 1}, () => ['user', 'assistant']).flat());
+ previous = settled;
+ }
+});
diff --git a/app/src/providers/useOpenHumanExternalStore.ts b/app/src/providers/useOpenHumanExternalStore.ts
index 5308e7b91a..71e2d7ec57 100644
--- a/app/src/providers/useOpenHumanExternalStore.ts
+++ b/app/src/providers/useOpenHumanExternalStore.ts
@@ -159,9 +159,10 @@ export function useCoreTranscriptProjection(
}
let cancelled = false;
const skipRequestIds = liveRequestId ? new Set([liveRequestId]) : undefined;
- const project = (items: DerivedDisplayItem[]) => {
+ const project = (items: DerivedDisplayItem[], partial = false) => {
const mapped = mapDisplayItems(items, { skipRequestIds });
setProjection(previous => {
+ if (partial && previous.threadId === threadId && Object.keys(previous.timelines).length > 0) return previous;
if (previous.threadId !== threadId) {
return { threadId, timelines: mapped.timelines, transcripts: mapped.transcripts };
}
@@ -189,7 +190,7 @@ export function useCoreTranscriptProjection(
// page that begins mid-turn hides that turn's leading tool calls until
// its boundary is in view — both only resolve with the full list.
let items = first.items;
- project(items);
+ project(items, first.hasMore);
let cursor = first.hasMore ? first.nextCursor : undefined;
let pages = 1;
while (cursor && pages < DERIVED_TRANSCRIPT_MAX_PAGES) {
@@ -208,9 +209,8 @@ export function useCoreTranscriptProjection(
} catch {
// A missing/older core has no settled process trail; message text and
// the live socket projection remain usable. Navigation must not fail.
- if (!cancelled) {
- setProjection({ threadId, timelines: EMPTY_TURN_MAP, transcripts: EMPTY_TURN_MAP });
- }
+ // A transient refresh failure must not erase the last complete trail.
+ // The return below already masks projections belonging to another thread.
}
})();
return () => {