Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
fix(web): keep message sharing usable when avatars time out (#896)
Gustavo Ye004001db66a2
diff --git a/src/web/src/lib/community/share-image-session.dom.test.ts b/src/web/src/lib/community/share-image-session.dom.test.tsindex 9d4cbcbfb..69aa70d26 100644--- a/src/web/src/lib/community/share-image-session.dom.test.ts+++ b/src/web/src/lib/community/share-image-session.dom.test.ts@@ -508,6 +508,39 @@ describe("prepareShareImageSession", () => {await vi.waitFor(() => expect(blockedCancel).toHaveBeenCalled())})+ it("uses an identity fallback when an avatar request never settles", async () => {+ vi.useFakeTimers()+ const source = sourceCard('<div data-share-identity-id="u1"><img data-avatar-photo-state="ready" src="/avatar.png"></div>')+ let requestSignal: AbortSignal | undefined+ const fetchAsset = vi.fn((_url: RequestInfo | URL, init?: RequestInit) => {+ requestSignal = init?.signal ?? undefined+ return new Promise<Response>(() => {})+ })+ const pending = prepareShareImageSession(source, {+ fetchAsset,+ getFontCSS: vi.fn().mockResolvedValue(FONT_CSS),+ waitForPaint: vi.fn().mockResolvedValue(undefined),+ timeoutMs: 25,+ })+ const assertion = expect(pending).resolves.toMatchObject({+ markup: expect.stringContaining('data-share-identity-fallback="beam"'),+ })+ await act(async () => vi.advanceTimersByTimeAsync(25))+ await assertion+ expect(requestSignal?.aborted).toBe(true)+ expect(source.querySelector("img")?.getAttribute("src")).toBe("/avatar.png")+ expect(document.querySelector("[data-share-detached-tree]")).toBeNull()+ })++ it("retains identity fallback and content failure for images without a source", async () => {+ const identity = sourceCard('<img data-remote-image-kind="identity">')+ await expect(prepare(identity)).resolves.toMatchObject({+ markup: expect.stringContaining('data-share-identity-fallback="beam"'),+ })+ const content = sourceCard("<img>")+ await expect(prepare(content)).rejects.toMatchObject({ stage: "assets", timedOut: false })+ })+it("times out a non-cooperative asset request", async () => {vi.useFakeTimers()const source = sourceCard('<img src="/pending.png">')@@ -555,6 +588,46 @@ describe("prepareShareImageSession", () => {expect(getFontCSS).toHaveBeenCalledTimes(1)})+ it.each(["body", "decode"])("falls back when avatar %s stalls", async (stage) => {+ vi.useFakeTimers()+ const cancel = vi.fn()+ const response = stage === "body"+ ? new Response(new ReadableStream({ cancel }), { headers: { "Content-Type": "image/png" } })+ : imageResponse()+ const source = sourceCard('<img data-remote-image-kind="identity" src="/avatar.png">')+ const pending = prepareShareImageSession(source, {+ fetchAsset: vi.fn().mockResolvedValue(response),+ staticizeAsset: stage === "decode" ? () => new Promise(() => {}) : async (blob) => blob,+ getFontCSS: vi.fn().mockResolvedValue(FONT_CSS),+ waitForPaint: vi.fn().mockResolvedValue(undefined),+ timeoutMs: 25,+ })+ await Promise.all([+ expect(pending).resolves.toMatchObject({ markup: expect.stringContaining('data-share-identity-fallback="beam"') }),+ act(async () => vi.advanceTimersByTimeAsync(25)),+ ])+ if (stage === "body") expect(cancel).toHaveBeenCalled()+ })++ it("does not turn external cancellation of a stalled avatar into fallback", async () => {+ const controller = new AbortController()+ const started = deferred<void>()+ const source = sourceCard('<img data-remote-image-kind="identity" src="/avatar.png">')+ const pending = prepareShareImageSession(source, {+ fetchAsset: vi.fn(() => {+ started.resolve()+ return new Promise<Response>(() => {})+ }),+ waitForPaint: vi.fn().mockResolvedValue(undefined),+ signal: controller.signal,+ })+ const assertion = expect(pending).rejects.toMatchObject({ name: "AbortError" })+ await started.promise+ controller.abort()+ await assertion+ expect(document.querySelector("[data-share-detached-tree]")).toBeNull()+ })+it("treats an empty font embed as a hard preparation failure", async () => {const source = sourceCard("<span>hello</span>")diff --git a/src/web/src/lib/community/share-image-session.ts b/src/web/src/lib/community/share-image-session.tsindex 67304f7e2..0977159c1 100644--- a/src/web/src/lib/community/share-image-session.ts+++ b/src/web/src/lib/community/share-image-session.ts@@ -719,29 +719,47 @@ export async function prepareShareImageSession(staticizeTail = result.then(() => undefined, () => undefined)return result}- const resolved = await withDeadline("assets", timeoutMs, options.signal, async (signal) => {+ await withDeadline("assets", timeoutMs, options.signal, async (signal) => {await waitForPaint()throwIfAborted(signal)- const assetTargets = new Map<string, ShareImageAssetTarget>()- for (const image of images) {+ })+ const assetTargets = new Map<string, ShareImageAssetTarget>()+ for (const image of images) {+ try {+ const request = assetRequest(image)+ mergeAssetTarget(assetTargets, request.cacheKey, assetTarget(image))+ } catch {+ continue+ }+ }+ const assetController = new AbortController()+ const abortAssets = () => assetController.abort()+ options.signal?.addEventListener("abort", abortAssets, { once: true })+ let resolved: Array<string | null>+ try {+ throwIfAborted(options.signal)+ resolved = await Promise.all(images.map(async (image) => {try {- const request = assetRequest(image)- mergeAssetTarget(assetTargets, request.cacheKey, assetTarget(image))- } catch {- // Preserve the existing per-image content failure / identity fallback semantics.+ return await withDeadline("assets", timeoutMs, assetController.signal, (signal) => resolveImage(+ image,+ options.fetchAsset ?? fetch,+ signal,+ assetCache,+ assetTargets,+ budget,+ options.staticizeAsset ?? staticizeImageBlob,+ enqueueStaticize,+ ))+ } catch (error) {+ if (imageKind(image) === "identity"+ && error instanceof ShareImageSessionError && error.timedOut) return null+ throw error}- }- return Promise.all(images.map((image) => resolveImage(- image,- options.fetchAsset ?? fetch,- signal,- assetCache,- assetTargets,- budget,- options.staticizeAsset ?? staticizeImageBlob,- enqueueStaticize,- )))- })+ }))+ } finally {+ options.signal?.removeEventListener("abort", abortAssets)+ abortAssets()+ }for (let index = 0; index < images.length; index += 1) {const image = images[index]!const dataUrl = resolved[index]diff --git a/src/web/src/test/e2e-ui/51-share-image-assets.spec.ts b/src/web/src/test/e2e-ui/51-share-image-assets.spec.tsindex 12199f073..94232b321 100644--- a/src/web/src/test/e2e-ui/51-share-image-assets.spec.ts+++ b/src/web/src/test/e2e-ui/51-share-image-assets.spec.ts@@ -611,6 +611,40 @@ test("closing cold preparation suppresses output and reopening starts a fresh seawait expect.poll(() => captureCounts(page)).toEqual({ clipboard: 1, download: 0 })})+test("stalled avatar falls back and a single text message exports", async ({ asUser }) => {+ test.setTimeout(120_000)+ const serverId = await seedServer("alice", `Share avatar timeout ${Date.now()}`)+ const channelId = await seedChannel("alice", serverId, "share-timeout")+ const { page } = await asUser("alice")+ await gotoAfterUserWsAuth(page, `/c/channels/${serverId}/${channelId}`)+ await uploadAvatar(page)+ const message = await seedMessage(page, channelId, "Text survives an unavailable avatar")+ await expect(page.getByTestId(tid.message(message.id)).locator('[data-slot="avatar-image"]')).toBeVisible()+ await installShareCapture(page)+ let release!: () => void+ const blocked = new Promise<void>((resolve) => { release = resolve })+ const pattern = "**/api/community/users/*/avatar*"+ await page.route(pattern, async (route) => {+ await blocked+ await route.abort("failed").catch(() => undefined)+ })+ try {+ const dialog = await openShareDialog(page, message.id)+ const card = await waitForReady(dialog)+ await expect(card.locator("[data-share-identity-fallback=beam]")).toBeVisible()+ await expect(card).toContainText("Text survives an unavailable avatar")+ await dialog.getByRole("button", { name: "Copy image" }).click()+ await expect(dialog.getByRole("button", { name: "Copied" })).toBeVisible()+ const downloaded = page.waitForEvent("download")+ await dialog.getByRole("button", { name: "Download" }).click()+ await downloaded+ await expect.poll(() => captureCounts(page)).toEqual({ clipboard: 1, download: 1 })+ } finally {+ release()+ await page.unroute(pattern)+ }+})+test("avatar failure is deterministic while content-image failure is atomic and retryable", async ({ asUser }) => {test.setTimeout(120_000)const serverId = await seedServer("alice", `Share failures ${Date.now()}`)