From 70b53665d54afa1268202c139d479bb2d373b478 Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Tue, 24 Nov 2026 21:33:15 +0100 Subject: [PATCH] fix(web/claw): fetch an image again for a card the mirror rebuilt A page read, a mirror reset, or a turn folding into the record builds new card objects, and the pass that fetches image bytes remembered attachment ids, so a rebuilt card whose bytes had not landed was never asked for again. The guard now rides the card object: a new card gets its fetch, and the useClaw cache answers a repeat with the blob it already holds, so nothing is requested twice. The object URL also lands on every card naming the id, not only the first. A page's open tail is dropped and re-read with the turn's beginning above it, which can leave two cards for one attachment, and the second stayed blank. --- web/claw/README.md | 9 +++++--- web/claw/app/app.vue | 25 +++++++++++++---------- web/claw/app/composables/useTranscript.ts | 5 +++-- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/web/claw/README.md b/web/claw/README.md index f71d6f4..21fef23 100644 --- a/web/claw/README.md +++ b/web/claw/README.md @@ -60,9 +60,12 @@ Two consequences worth knowing before changing this code: fire-and-forget (202); the reply streams back on `GET /v1/sessions/{key}/events`. The transcript here is a mirror of the stream, and the stream opens on the newest turn before the live - feed — a reload paints the latest conversation at once instead of - replaying a session that may have run for weeks, and the turns above - it come from `GET /v1/sessions/{key}/history`, one whole turn per + feed. That turn comes back whole even when it is longer than the + replay window, so a reload never lands mid-reply with the file the + turn handed over above the cut. A reload paints the latest + conversation at once instead of replaying a session that may have run + for weeks, and the turns above it come from + `GET /v1/sessions/{key}/history`, one whole turn per page, as the reader scrolls up (or right away, while the transcript is shorter than the screen). So the transcript survives the browser, not just the claw. diff --git a/web/claw/app/app.vue b/web/claw/app/app.vue index 7048230..abb9257 100644 --- a/web/claw/app/app.vue +++ b/web/claw/app/app.vue @@ -121,9 +121,12 @@ const { // for weeks costs nothing up front and still reaches its first message. const olderAvailable = ref(true) -// Attachment ids this page already tried to fetch; a failed fetch is -// not retried until the stream resets and clears the set. -const attemptedAttachments = new Set() +// The cards this page already tried to fetch. Keyed by the card object +// rather than the attachment id: a page read, a mirror reset, or a live +// turn folding into a record builds new cards, and a new card deserves +// its fetch — the useClaw cache answers a repeat with the blob it +// already holds, so a retry costs no request. +let attemptedAttachments = new WeakSet() // Image cards need their bytes before they can render: fetched as the // card appears, not on any timer. code/file fetch on download instead. @@ -139,8 +142,8 @@ const attemptedAttachments = new Set() function requestAttachmentImages(): void { const fetchAttachment = (attachment: AttachmentCard) => { const { id, media, url } = attachment - if (media !== 'image' || url !== null || attemptedAttachments.has(id)) return - attemptedAttachments.add(id) + if (media !== 'image' || url !== null || attemptedAttachments.has(attachment)) return + attemptedAttachments.add(attachment) claw .attachmentUrl(id) .then((fetched) => transcript.setAttachmentUrl(id, fetched)) @@ -156,8 +159,8 @@ function requestAttachmentImages(): void { } else if (item.kind === 'sent') { for (const image of item.images) { const { id, url } = image - if (id === null || url !== null || attemptedAttachments.has(id)) continue - attemptedAttachments.add(id) + if (id === null || url !== null || attemptedAttachments.has(image)) continue + attemptedAttachments.add(image) claw .attachmentUrl(id) .then((fetched) => transcript.setSentImageUrl(id, fetched)) @@ -709,7 +712,7 @@ function resubscribe(): void { stream = null transcript.reset() olderAvailable.value = true - attemptedAttachments.clear() + attemptedAttachments = new WeakSet() notices.value = [] streamStatus.value = 'connecting' threadRevision = null @@ -732,7 +735,7 @@ function resubscribe(): void { onReset: () => { transcript.reset() olderAvailable.value = true - attemptedAttachments.clear() + attemptedAttachments = new WeakSet() requestAttachmentImages() }, onStatus: (status) => { @@ -742,7 +745,7 @@ function resubscribe(): void { // is. Only the attachment set is cleared — a fetch that failed // during the outage should retry against the recovered stream. if (status === 'reconnecting') { - attemptedAttachments.clear() + attemptedAttachments = new WeakSet() requestAttachmentImages() } if (status === 'open') void refreshSessions() @@ -764,7 +767,7 @@ async function loadThread(): Promise { // the new one under it would duplicate every turn. transcript.reset() olderAvailable.value = true - attemptedAttachments.clear() + attemptedAttachments = new WeakSet() try { const page = await claw.history(key) if (key !== activeKey.value) return diff --git a/web/claw/app/composables/useTranscript.ts b/web/claw/app/composables/useTranscript.ts index e92d736..8bd980e 100644 --- a/web/claw/app/composables/useTranscript.ts +++ b/web/claw/app/composables/useTranscript.ts @@ -437,13 +437,14 @@ export function useTranscript() { } } - /** An attachment's object URL landed; stored on its card. The useClaw + /** An attachment's object URL landed; stored on every card that names + * the id. Two cards can hold one id when a page's open tail is dropped + * and re-read, so the loop does not stop at the first. The useClaw * cache keeps a reconnect's replay from refetching the bytes. */ function setAttachmentUrl(id: string, url: string): void { for (const card of cards()) { if (card.kind === 'attachment' && card.attachment.id === id) { card.attachment.url = url - return } } }