Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

fix: keep running-turn chunks visible after refresh (#977)

harshil-209668ea7aed8536
diff --git a/.changeset/resume-running-tip-ingest.md b/.changeset/resume-running-tip-ingest.md
new file mode 100644
index 000000000..b7a1e51e5
--- /dev/null
+++ b/.changeset/resume-running-tip-ingest.md
@@ -0,0 +1,5 @@
+---
+"@truefoundry/trueforge-assistant-ui-runtime": patch
+---
+
+On refresh mid-turn, keep already-ingested running-tip model messages in live resume instead of hiding them behind the group baseline.
diff --git a/packages/assistant-ui-runtime/src/convertTurnMessages.ts b/packages/assistant-ui-runtime/src/convertTurnMessages.ts
index 21738996c..a8878a5bd 100644
--- a/packages/assistant-ui-runtime/src/convertTurnMessages.ts
+++ b/packages/assistant-ui-runtime/src/convertTurnMessages.ts
@@ -469,13 +469,14 @@ function attachRunningTurn(snapshot: SessionSnapshot, runningTurn: Turn | undefi
return snapshot;
}
const pendingUserText = extractTurnUserText(runningTurn.input);
- // Tip is not in `turns` yet. A new user tip must baseline every prior root
- // model.message (same as live send) — otherwise computeGroupRootBaseline
- // treats the last completed user turn as the active group and that turn's
- // content leaks into resume after refresh.
+ // Tip is not in `turns`. Baseline committed groups only — fold already
+ // includes the open tip's messages, which must stay in live resume.
+ //2 scenario for Page Refresh:
+ // 1. only baseline the committed groups(there is only user msg no assistant msg)
+ // 2. the open tip's messages must stay in live resume (there is some assistant msg response in the fold)
const groupRootBaseline =
pendingUserText !== undefined
- ? [...(snapshot.fold.threads.get(ROOT_THREAD_ID)?.modelMessageIds ?? [])]
+ ? snapshot.turns.flatMap(turn => turn.rootModelMessageIds ?? [])
: computeGroupRootBaseline(snapshot.turns);
return replaceSessionSnapshot(snapshot, {
runningTurn,
diff --git a/packages/assistant-ui-runtime/test/convertTurnMessages.test.ts b/packages/assistant-ui-runtime/test/convertTurnMessages.test.ts
index b7925be9e..328dce5b2 100644
--- a/packages/assistant-ui-runtime/test/convertTurnMessages.test.ts
+++ b/packages/assistant-ui-runtime/test/convertTurnMessages.test.ts
@@ -28,6 +28,7 @@ import {
projectSessionMessages,
repositoryItemsFromMessages,
resolveGatewayBranchPreviousTurnIdForTurn,
+ rootModelMessageIdsSinceBaseline,
streamTurnEvents,
turnStreamUpdateToAssistantMessage,
} from '../src/convertTurnMessages.js';
@@ -2654,6 +2655,84 @@ describe('buildSnapshotFromSessionEvents', () => {
});
});
+ it("keeps the running tip's already-ingested model messages in live resume scope", async () => {
+ const runningTurn = {
+ id: 't2',
+ state: { status: 'running' },
+ input: [{ type: 'user.message', content: 'can 10 random sandbox tool calll' }],
+ createdAt,
+ } as unknown as Turn;
+
+ const items: SessionEventItem[] = [
+ {
+ turnId: 't1',
+ event: {
+ type: 'turn.created',
+ id: 'evt-c1',
+ turnId: 't1',
+ input: [{ type: 'user.message', content: 'first' }],
+ state: { status: 'running' },
+ createdAt,
+ },
+ },
+ {
+ turnId: 't1',
+ event: modelMessage({ id: 'm1', threadId: ROOT_THREAD_ID, content: 'reply 1' }),
+ },
+ {
+ turnId: 't1',
+ event: {
+ type: 'turn.done',
+ id: 'evt-d1',
+ state: { status: 'done', requiredActions: [], completedAt: createdAt },
+ createdAt,
+ } as TurnDoneEvent,
+ },
+ {
+ turnId: 't2',
+ event: {
+ type: 'turn.created',
+ id: 'evt-c2',
+ turnId: 't2',
+ input: [{ type: 'user.message', content: 'can 10 random sandbox tool calll' }],
+ state: { status: 'running' },
+ createdAt,
+ },
+ },
+ {
+ turnId: 't2',
+ event: modelMessage({
+ id: 'm2',
+ threadId: ROOT_THREAD_ID,
+ content: 'Running 10 random sandbox commands at once:',
+ }),
+ },
+ ];
+
+ const snapshot = await buildSnapshotFromSessionEvents(mockServerWithEvents([runningTurn], items), SESSION_ID);
+
+ expect(snapshot.turns).toHaveLength(1);
+ expect(snapshot.groupRootBaseline).toEqual(['m1']);
+ expect(rootModelMessageIdsSinceBaseline(snapshot.fold, snapshot.groupRootBaseline ?? [])).toEqual(['m2']);
+
+ const updates = await collectStream(
+ streamTurnEvents(
+ streamFrom([
+ modelMessage({
+ id: 'm3',
+ threadId: ROOT_THREAD_ID,
+ content: 'I ran 10 sandbox commands',
+ }),
+ ]),
+ snapshot.fold,
+ snapshot.groupRootBaseline,
+ ),
+ );
+
+ const texts = (updates.at(-1)?.content ?? []).filter(part => part.type === 'text').map(part => part.text);
+ expect(texts).toEqual(['Running 10 random sandbox commands at once:', 'I ran 10 sandbox commands']);
+ });
+
it('calls onProgress after each completed turn', async () => {
const items: SessionEventItem[] = [
{