Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix: retain background tool media across result updates
Chris589a9b9c12f7
diff --git a/apps/desktop/src/main/__tests__/messagePersistBroadcaster.test.ts b/apps/desktop/src/main/__tests__/messagePersistBroadcaster.test.tsindex 9535f8bb5a..053dd1536c 100644--- a/apps/desktop/src/main/__tests__/messagePersistBroadcaster.test.ts+++ b/apps/desktop/src/main/__tests__/messagePersistBroadcaster.test.ts@@ -4130,6 +4130,34 @@ it('keeps unrelated writes flowing and merges later summaries with process mediaexpect(JSON.parse(vi.mocked(updateMessageContent).mock.calls.at(-1)![2] as string)).toEqual({ text: 'Final image description', cindy_process_media: refs });});+// Unit regression for #6372: background results have a separate content map.+// Either completion order must keep the summary and media on the original row,+// even when the summary releases the background state while import is pending.+it.each(['summary-first', 'media-first'] as const)('retains background process media (%s)', async (order) => {+ const refs = [{ kind: 'image' as const, url: 'cindy-media://blobs/' + 'a'.repeat(64) + '.png' }];+ let finish!: (value: typeof refs) => void;+ vi.mocked(materializeToolProcessMedia).mockImplementationOnce(() => new Promise(resolve => { finish = resolve; }));+ onToolUseEvent(SESSION, { toolUseId: 'background-image', toolName: 'collab:spawnAgent', input: {} }, null, 'background');+ const result = onToolResultFullEvent(SESSION, { toolUseId: 'background-image', fullText: '' }, null, 'background')!;+ const pending = persistToolProcessMedia(SESSION, result.persistId, '', [{ kind: 'image', data: 'bytes' }], undefined, 'background');+ if (order === 'media-first') {+ finish(refs);+ await pending;+ await drainPersistQueue();+ }+ const summary = onToolResultEvent(SESSION, { toolUseIds: ['background-image'], summary: 'Image read' }, null, 'background')!;+ expect(summary.persistId).toBe(result.persistId);+ await drainPersistQueue();+ if (order === 'summary-first') {+ finish(refs);+ await pending;+ await drainPersistQueue();+ }+ const updates = vi.mocked(updateMessageContent).mock.calls;+ expect(updates.at(-1)?.slice(0, 2)).toEqual([SESSION, result.persistId]);+ expect(JSON.parse(updates.at(-1)![2] as string)).toEqual({ text: 'Image read', cindy_process_media: refs });+});+it('does not publish a pending media import after its owner is superseded', async () => {let finish!: (value: any[]) => void;vi.mocked(materializeToolProcessMedia).mockImplementationOnce(() => new Promise(resolve => { finish = resolve; }));diff --git a/apps/desktop/src/main/maker-ipc/sessionEventStream.ts b/apps/desktop/src/main/maker-ipc/sessionEventStream.tsindex 11c94f1faa..fc31158da0 100644--- a/apps/desktop/src/main/maker-ipc/sessionEventStream.ts+++ b/apps/desktop/src/main/maker-ipc/sessionEventStream.ts@@ -97,7 +97,7 @@ export function persistSessionStreamEvent(if (r && Array.isArray(processMedia) && processMedia.length) {persistToolProcessMedia(session.id, r.persistId, r.content, processMedia, {workdir: session.workDir, remoteHostId: session.remoteHostId,- });+ }, event.turnScope === 'background' ? 'background' : 'turn');}} else if (event.type === 'thinking') {// thinking final/redacted 落库收口 main;clientId=blockId(renderer 同源),无需diff --git a/apps/desktop/src/main/messagePersistBroadcaster.ts b/apps/desktop/src/main/messagePersistBroadcaster.tsindex f00967ae35..80f4ebbfd1 100644--- a/apps/desktop/src/main/messagePersistBroadcaster.ts+++ b/apps/desktop/src/main/messagePersistBroadcaster.ts@@ -1762,14 +1762,20 @@ export async function persistToolProcessMedia(text: string,items: NativeToolMedia[],origin?: import('./cindy-media/toolProcessMedia').ToolMediaOrigin,+ scope: 'turn' | 'background' = 'turn',): Promise<void> {if (!items.length) return;const ownerScope = captureOwnerScope();const assertStillValid = () => {if (!isOwnerScopeCurrent(ownerScope)) throw ownerScopeSupersededError();};- const contentMap = toolResultContentByClientId.get(sessionId)- ?? new Map([[persistId, text]]);+ // Capture the accepted result's map before fetching: a background summary+ // may release its state while media is still being materialized.+ const contentMap = scope === 'background'+ ? backgroundTurnPersistStatesBySession.get(sessionId)+ ?.find(state => state.toolResultContentByClientId.has(persistId))?.toolResultContentByClientId+ : toolResultContentByClientId.get(sessionId) ?? new Map([[persistId, text]]);+ if (!contentMap) return;try {assertStillValid();const db = getDbClient().drizzle;