diff --git a/apps/desktop/src/plugins/hermes-bots/profile-ops.test.ts b/apps/desktop/src/plugins/hermes-bots/profile-ops.test.ts index 067e273423..76d6b33fdf 100644 --- a/apps/desktop/src/plugins/hermes-bots/profile-ops.test.ts +++ b/apps/desktop/src/plugins/hermes-bots/profile-ops.test.ts @@ -15,8 +15,9 @@ import { $botMeta } from './data' import { duplicateBot } from './profile-ops' import type { RosterRow } from './types' -const { ensureBotMetadataMock, hostMock, storageMock } = vi.hoisted(() => ({ +const { ensureBotMetadataMock, faceOnlyMock, hostMock, storageMock } = vi.hoisted(() => ({ ensureBotMetadataMock: vi.fn(), + faceOnlyMock: vi.fn((_data: string) => false), hostMock: { request: vi.fn(), requestProfile: vi.fn(), @@ -39,13 +40,14 @@ vi.mock('@hermes/plugin-sdk', async () => { }) vi.mock('./shared', () => ({ getPluginCtx: () => ({ storage: storageMock }), ID: 'hermes-bots' })) -vi.mock('./avatar-image', () => ({ isBackfilledFacePng: () => false })) +vi.mock('./avatar-image', () => ({ isBackfilledFacePng: (data: string) => faceOnlyMock(data) })) vi.mock('./canonical-chat', () => ({ ensureBotMetadata: ensureBotMetadataMock })) const calls: Array<{ method: string; params: Record }> = [] beforeEach(() => { vi.clearAllMocks() + faceOnlyMock.mockReturnValue(false) calls.length = 0 $botMeta.set({}) storageMock.set.mockResolvedValue(undefined) @@ -209,4 +211,30 @@ describe('roster avatar sync (#102978)', () => { expect(hostMock.requestProfile).not.toHaveBeenCalled() expect(hostMock.request).toHaveBeenCalledWith('profiles.get_asset', { asset: 'avatar', name: 'default' }) }) + + it('does not re-fetch a face-only raster on the next roster tick (#99336)', async () => { + const { pullServerAvatars } = await import('./profile-ops') + faceOnlyMock.mockReturnValue(true) + hostMock.request.mockResolvedValue({ data: 'data:image/png;base64,AAAA', found: true }) + + const row = { + connectionId: 'local', + has_avatar: true, + name: 'secretary', + route: { connectionId: 'local', mode: 'local', profile: 'secretary', targetProfile: 'secretary' }, + sourceScoped: true + } as RosterRow + + pullServerAvatars([row]) + await vi.waitFor(() => expect(hostMock.request).toHaveBeenCalledTimes(1)) + // Let the first fetch settle (its in-flight guard clears in a finally) so + // the second tick is decided by the memo, not by that guard. + await new Promise(resolve => setTimeout(resolve, 0)) + pullServerAvatars([row]) + await new Promise(resolve => setTimeout(resolve, 0)) + + expect(hostMock.request).toHaveBeenCalledTimes(1) + // The raster is a notice-only copy of the live face, never parked on the roster. + expect($botMeta.get()['local::secretary']?.image).toBeUndefined() + }) }) diff --git a/apps/desktop/src/plugins/hermes-bots/profile-ops.ts b/apps/desktop/src/plugins/hermes-bots/profile-ops.ts index 518977c8ca..74918cbe3d 100644 --- a/apps/desktop/src/plugins/hermes-bots/profile-ops.ts +++ b/apps/desktop/src/plugins/hermes-bots/profile-ops.ts @@ -39,8 +39,11 @@ import type { RosterRow } from './types' const avatarFetchInflight = new Set() const avatarPushInflight = new Set() +// Rows whose server avatar is only the plugin's own face raster: nothing to +// paint, so the roster must not re-fetch it on every tick. +const avatarFaceOnly = new Set() -/** Asset RPC for a row of the ACTIVE source's roster (#102978). These rows +/** Asset RPC for a row of the ACTIVE source's roster (#102978, #99336, #102913). These rows * came back from the active gateway's own `profiles.list`, which reads every * local profile's directory — `profiles.get_asset` / `set_asset` are the * same directory reads, so the active gateway answers them with the row's @@ -167,7 +170,7 @@ export function pullServerAvatars(roster: RosterRow[]) { for (const bot of roster) { const key = botMetaKey(bot) - if (!bot.has_avatar || avatarFetchInflight.has(key)) { + if (!bot.has_avatar || avatarFetchInflight.has(key) || avatarFaceOnly.has(key)) { continue } @@ -189,8 +192,12 @@ export function pullServerAvatars(roster: RosterRow[]) { const mine = current[key] || {} // A 160px raster of the vector face is only for inter-agent - // notices. Do not park it on the roster or the live face dies. + // notices. Do not park it on the roster or the live face dies — + // and remember the answer, or the empty image slot re-fetches the + // same raster on every roster tick. if (isBackfilledFacePng(res.data) && mine.imageKind !== 'photo' && !mine.pet) { + avatarFaceOnly.add(key) + return } @@ -429,6 +436,7 @@ export async function deleteBot(bot: RosterRow) { forgetSessionUnread([bot.canonical_session?.id, bot.canonical_session?.resolved_id], bot.name) rosterWatermarks.delete(botSelectionKey(bot)) avatarFetchInflight.delete(botMetaKey(bot)) + avatarFaceOnly.delete(botMetaKey(bot)) avatarPushInflight.delete(botMetaKey(bot)) if ($selectedBot.get() === botSelectionKey(bot)) {