fix(web/claw): fetch an image again for a card the mirror rebuilt
android / debug (push) Successful in 2m31s
ci / docker (push) Successful in 2m3s
ci / web (push) Successful in 15s
ci / publish-edge-images (deploy/docker/claw.Dockerfile, rhema-claw) (push) Successful in 2m3s
android / release (push) Successful in 2m13s
ci / checks (push) Successful in 1m7s
ci / test (push) Successful in 39s
ci / chart (push) Successful in 5s
ci / publish-edge-images (deploy/docker/ui.Dockerfile, rhema-claw-ui) (push) Successful in 13s
ci / publish-edge-chart (push) Successful in 3s

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.
This commit is contained in:
vhaudiquet committed 2026-11-24 21:33:15 +01:00
1 parent ea6edfe67a
commit 70b53665d5
3 files changed
+23 -16

No files matched your search

+6 -3
View File
@@ -60,9 +60,12 @@ Two consequences worth knowing before changing this code:
fire-and-forget (202); the reply streams back on fire-and-forget (202); the reply streams back on
`GET /v1/sessions/{key}/events`. The transcript here is a mirror of `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 the stream, and the stream opens on the newest turn before the live
feed — a reload paints the latest conversation at once instead of feed. That turn comes back whole even when it is longer than the
replaying a session that may have run for weeks, and the turns above replay window, so a reload never lands mid-reply with the file the
it come from `GET /v1/sessions/{key}/history`, one whole turn per 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 page, as the reader scrolls up (or right away, while the transcript
is shorter than the screen). So the transcript survives the browser, is shorter than the screen). So the transcript survives the browser,
not just the claw. not just the claw.
+14 -11
View File
@@ -121,9 +121,12 @@ const {
// for weeks costs nothing up front and still reaches its first message. // for weeks costs nothing up front and still reaches its first message.
const olderAvailable = ref(true) const olderAvailable = ref(true)
// Attachment ids this page already tried to fetch; a failed fetch is // The cards this page already tried to fetch. Keyed by the card object
// not retried until the stream resets and clears the set. // rather than the attachment id: a page read, a mirror reset, or a live
const attemptedAttachments = new Set<string>() // 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<object>()
// Image cards need their bytes before they can render: fetched as the // Image cards need their bytes before they can render: fetched as the
// card appears, not on any timer. code/file fetch on download instead. // card appears, not on any timer. code/file fetch on download instead.
@@ -139,8 +142,8 @@ const attemptedAttachments = new Set<string>()
function requestAttachmentImages(): void { function requestAttachmentImages(): void {
const fetchAttachment = (attachment: AttachmentCard) => { const fetchAttachment = (attachment: AttachmentCard) => {
const { id, media, url } = attachment const { id, media, url } = attachment
if (media !== 'image' || url !== null || attemptedAttachments.has(id)) return if (media !== 'image' || url !== null || attemptedAttachments.has(attachment)) return
attemptedAttachments.add(id) attemptedAttachments.add(attachment)
claw claw
.attachmentUrl(id) .attachmentUrl(id)
.then((fetched) => transcript.setAttachmentUrl(id, fetched)) .then((fetched) => transcript.setAttachmentUrl(id, fetched))
@@ -156,8 +159,8 @@ function requestAttachmentImages(): void {
} else if (item.kind === 'sent') { } else if (item.kind === 'sent') {
for (const image of item.images) { for (const image of item.images) {
const { id, url } = image const { id, url } = image
if (id === null || url !== null || attemptedAttachments.has(id)) continue if (id === null || url !== null || attemptedAttachments.has(image)) continue
attemptedAttachments.add(id) attemptedAttachments.add(image)
claw claw
.attachmentUrl(id) .attachmentUrl(id)
.then((fetched) => transcript.setSentImageUrl(id, fetched)) .then((fetched) => transcript.setSentImageUrl(id, fetched))
@@ -709,7 +712,7 @@ function resubscribe(): void {
stream = null stream = null
transcript.reset() transcript.reset()
olderAvailable.value = true olderAvailable.value = true
attemptedAttachments.clear() attemptedAttachments = new WeakSet<object>()
notices.value = [] notices.value = []
streamStatus.value = 'connecting' streamStatus.value = 'connecting'
threadRevision = null threadRevision = null
@@ -732,7 +735,7 @@ function resubscribe(): void {
onReset: () => { onReset: () => {
transcript.reset() transcript.reset()
olderAvailable.value = true olderAvailable.value = true
attemptedAttachments.clear() attemptedAttachments = new WeakSet<object>()
requestAttachmentImages() requestAttachmentImages()
}, },
onStatus: (status) => { onStatus: (status) => {
@@ -742,7 +745,7 @@ function resubscribe(): void {
// is. Only the attachment set is cleared — a fetch that failed // is. Only the attachment set is cleared — a fetch that failed
// during the outage should retry against the recovered stream. // during the outage should retry against the recovered stream.
if (status === 'reconnecting') { if (status === 'reconnecting') {
attemptedAttachments.clear() attemptedAttachments = new WeakSet<object>()
requestAttachmentImages() requestAttachmentImages()
} }
if (status === 'open') void refreshSessions() if (status === 'open') void refreshSessions()
@@ -764,7 +767,7 @@ async function loadThread(): Promise<void> {
// the new one under it would duplicate every turn. // the new one under it would duplicate every turn.
transcript.reset() transcript.reset()
olderAvailable.value = true olderAvailable.value = true
attemptedAttachments.clear() attemptedAttachments = new WeakSet<object>()
try { try {
const page = await claw.history(key) const page = await claw.history(key)
if (key !== activeKey.value) return if (key !== activeKey.value) return
+3 -2
View File
@@ -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. */ * cache keeps a reconnect's replay from refetching the bytes. */
function setAttachmentUrl(id: string, url: string): void { function setAttachmentUrl(id: string, url: string): void {
for (const card of cards()) { for (const card of cards()) {
if (card.kind === 'attachment' && card.attachment.id === id) { if (card.kind === 'attachment' && card.attachment.id === id) {
card.attachment.url = url card.attachment.url = url
return
} }
} }
} }