Skip to content

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

fix(ui): artifacts loaded on thread open take no owner from the live turn

Sanil3a4cdbe51562
diff --git a/app/src/features/conversations/hooks/useThreadArtifactsHydration.ts b/app/src/features/conversations/hooks/useThreadArtifactsHydration.ts
index 484aad9f93..98d3007849 100644
--- a/app/src/features/conversations/hooks/useThreadArtifactsHydration.ts
+++ b/app/src/features/conversations/hooks/useThreadArtifactsHydration.ts
@@ -43,6 +43,7 @@ export function useThreadArtifactsHydration(threadId: string | null | undefined)
title: artifact.title,
path: artifact.path,
sizeBytes: artifact.sizeBytes,
+ loaded: true,
})
);
}
diff --git a/app/src/store/__tests__/chatRuntimeSlice.artifactOwner.test.ts b/app/src/store/__tests__/chatRuntimeSlice.artifactOwner.test.ts
index e08e80d56b..4a6a1111b9 100644
--- a/app/src/store/__tests__/chatRuntimeSlice.artifactOwner.test.ts
+++ b/app/src/store/__tests__/chatRuntimeSlice.artifactOwner.test.ts
@@ -28,6 +28,43 @@ function apply(state: State, ...actions: Parameters<typeof chatRuntimeReducer>[1
}
describe('artifact owner turn', () => {
+ it('gives an artifact loaded when the thread opens no owner from the live turn', () => {
+ const state = apply(
+ chatRuntimeReducer(undefined, { type: 'init' }),
+ liveTurnStarted({ threadId: THREAD, requestId: 'req-latest' }),
+ upsertArtifactReadyForThread({
+ threadId: THREAD,
+ artifactId: 'old-1',
+ kind: 'document',
+ title: 'old-1',
+ path: '/tmp/old-1.md',
+ sizeBytes: 12,
+ loaded: true,
+ })
+ );
+ // Its reply comes from the thread's artifact rows; an owner here would pull
+ // every older card into the latest reply.
+ expect(owner(state, 'old-1')).toBeUndefined();
+ });
+
+ it('keeps the owner a live event gave when the same artifact is loaded later', () => {
+ const state = apply(
+ chatRuntimeReducer(undefined, { type: 'init' }),
+ liveTurnStarted({ threadId: THREAD, requestId: 'req-1' }),
+ ready('a-1'),
+ upsertArtifactReadyForThread({
+ threadId: THREAD,
+ artifactId: 'a-1',
+ kind: 'document',
+ title: 'a-1',
+ path: '/tmp/a-1.md',
+ sizeBytes: 12,
+ loaded: true,
+ })
+ );
+ expect(owner(state, 'a-1')).toBe('req-1');
+ });
+
it('tags an artifact with the turn that was live when it appeared', () => {
const state = apply(
chatRuntimeReducer(undefined, { type: 'init' }),
diff --git a/app/src/store/chatRuntimeSlice.ts b/app/src/store/chatRuntimeSlice.ts
index ecc7667f52..dcf5646c58 100644
--- a/app/src/store/chatRuntimeSlice.ts
+++ b/app/src/store/chatRuntimeSlice.ts
@@ -2701,9 +2701,15 @@ const chatRuntimeSlice = createSlice({
sizeBytes: number;
toolCallId?: string;
requestId?: string;
+ /**
+ * Loaded from the core (`ai_list_artifacts`), not announced by a turn:
+ * it takes no owner from the thread's live turn. Its placement comes
+ * from the thread's artifact rows.
+ */
+ loaded?: boolean;
}>
) => {
- const { threadId, artifactId, kind, title, path, sizeBytes, toolCallId, requestId } =
+ const { threadId, artifactId, kind, title, path, sizeBytes, toolCallId, requestId, loaded } =
action.payload;
const existing = (state.artifactsByThread[threadId] ?? []).find(
entry => entry.artifactId === artifactId
@@ -2717,7 +2723,9 @@ const chatRuntimeSlice = createSlice({
sizeBytes,
updatedAt: Date.now(),
toolCallId: toolCallId ?? existing?.toolCallId,
- ownerRequestId: ownerFor(state, threadId, existing, requestId),
+ ownerRequestId: loaded
+ ? existing?.ownerRequestId
+ : ownerFor(state, threadId, existing, requestId),
};
state.artifactsByThread[threadId] = upsertArtifact(
state.artifactsByThread[threadId],