Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(chat): clear stale sender attribution on message hydration (#6577)
Chris Zhang6d827f7806ae
diff --git a/apps/desktop/src/renderer/__tests__/botCollaborationMessages.test.ts b/apps/desktop/src/renderer/__tests__/botCollaborationMessages.test.tsindex 6d373618d0..70ebc167a6 100644--- a/apps/desktop/src/renderer/__tests__/botCollaborationMessages.test.ts+++ b/apps/desktop/src/renderer/__tests__/botCollaborationMessages.test.ts@@ -86,6 +86,39 @@ describe('readBotDelegationCompletionBody(已移除) —— 完成回执不再});describe('mapServerMessages — Bot collaboration', () => {+ // Unit regression: a host refresh must remove stale cached attribution, not+ // merge it into an ordinary user message. Existing cases only add origins.+ it('replaces cached sender identity with the authoritative user message source', () => {+ const [cached] = makerChatStore.__mapServerMessagesForTest([row({+ clientId: 'user-source-refresh',+ role: 'user',+ content: 'Continue with this change',+ agentMeta: {+ origin: {+ kind: 'session', senderSessionId: 'partner-session',+ senderBotId: 'bot-cindy', senderBotName: 'Cindy',+ },+ sourcePlugin: { pluginId: 'plugin-1', name: 'Plugin' },+ sourceDevice: { deviceId: 'phone-1', platform: 'mobile' },+ },+ })]);+ const [authoritative] = makerChatStore.__mapServerMessagesForTest([row({+ clientId: cached.clientId,+ role: 'user',+ content: 'Continue with this change',+ agentMeta: null,+ })]);+ const [refreshed] = makerChatStore.__mergeMessagesForTest([authoritative], [cached]);+ expect(refreshed.automationOrigin).toBeUndefined();+ expect(refreshed.sourcePlugin).toBeUndefined();+ expect(refreshed.sourceDevice).toBeUndefined();+ expect(refreshed.content).toBe(authoritative.content);++ // A genuine partner message still gains its host-stamped label on refresh.+ const [partner] = makerChatStore.__mergeMessagesForTest([cached], [refreshed]);+ expect(partner.automationOrigin).toEqual(cached.automationOrigin);+ });+it('derives a private-conversation entrance without putting its preview in the timeline', () => {const [mapped] = makerChatStore.__mapServerMessagesForTest([row({diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.tsindex 982b999555..c350f47f79 100644--- a/apps/desktop/src/renderer/lib/makerChatStore.ts+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts@@ -5196,6 +5196,16 @@ function hydratePersistedMessage(...(existing.retryFiles ? { retryFiles: existing.retryFiles } : {}),...(existing.retryMentions ? { retryMentions: existing.retryMentions } : {}),};+ // Sender metadata is an authoritative snapshot, not an additive patch.+ // Absence means ordinary user input (or no source on an assistant row).+ // Keeping a cached field here can falsely label a user message as a teammate,+ // even after the host has delivered a source-free row.+ for (const field of [+ 'automationOrigin', 'sourceDevice', 'sourcePlugin', 'sourceGroup',+ 'hookSource', 'sharedAuthorName', 'sharedAuthorMemberId',+ ] as const) {+ if (persisted[field] === undefined) delete hydrated[field];+ }if (options.preserveExistingCodexPlanContent === true &&existing.role === 'tool_use' &&