From 77ff1ee30492d437ef3aa904dd2b1e63a1584e0f Mon Sep 17 00:00:00 2001 From: Ben Davis <45952064+bmdavis419@users.noreply.github.com> Date: Mon, 27 Jul 2026 21:06:36 -0700 Subject: [PATCH] fix(client-runtime): live media deliveries kept their file only after reload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The thread reducer's notification-delivered case predates media and built the message with turnId hard-coded null and no attachments — so a turn-scoped media delivery streamed into an open thread as "(empty response)" while a reload, which reads the projection row, showed the file. The reducer now mirrors the projector: attachments ride along and turnId comes from the payload (null for proactive deliveries, unchanged). latestTurn and checkpoint rebinding stay untouched either way. Live repro: second image-send attempt in a Hermes thread after the plugin scope fix — the frame arrived, persisted correctly with its attachment, and rendered empty until refresh. Co-Authored-By: Claude Fable 5 --- .../src/state/threadReducer.test.ts | 40 +++++++++++++++++++ .../client-runtime/src/state/threadReducer.ts | 16 +++++--- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/packages/client-runtime/src/state/threadReducer.test.ts b/packages/client-runtime/src/state/threadReducer.test.ts index c181af4220..acc2940068 100644 --- a/packages/client-runtime/src/state/threadReducer.test.ts +++ b/packages/client-runtime/src/state/threadReducer.test.ts @@ -490,6 +490,46 @@ describe("applyThreadDetailEvent", () => { } }); + it("carries turn-scoped media's attachments and turn id into the live message", () => { + // The live repro: turn-scoped media streamed in without its file (this + // reducer dropped attachments/turnId), while a reload — which reads the + // projection row — showed it. The two views must agree. + const mediaEvent = { + ...deliveryEvent, + payload: { + ...deliveryEvent.payload, + messageId: MessageId.make("msg-media"), + text: "", + turnId: TurnId.make("turn-media"), + attachments: [ + { + type: "image" as const, + id: "thread-1-attachment-1", + name: "chart.png", + mimeType: "image/png", + sizeBytes: 1024, + }, + ], + notification: { + kind: "message" as const, + label: "Hermes", + deliveryId: "delivery-media-1", + }, + }, + } as const; + + const result = applyThreadDetailEvent(baseThread, mediaEvent); + + expect(result.kind).toBe("updated"); + if (result.kind === "updated") { + expect(result.thread.messages[0]).toMatchObject({ + id: "msg-media", + turnId: "turn-media", + attachments: [{ id: "thread-1-attachment-1", name: "chart.png" }], + }); + } + }); + it("leaves an unrelated live turn untouched", () => { // A delivery can land mid-turn; attributing it to that turn would fold // it away behind the turn's summary and mis-settle the turn state. diff --git a/packages/client-runtime/src/state/threadReducer.ts b/packages/client-runtime/src/state/threadReducer.ts index 160c5cf2fb..b5d5ce531e 100644 --- a/packages/client-runtime/src/state/threadReducer.ts +++ b/packages/client-runtime/src/state/threadReducer.ts @@ -327,15 +327,21 @@ export function applyThreadDetailEvent( case "thread.notification-delivered": { // A proactive delivery is an ordinary transcript message carrying - // provenance. It binds to no turn, so latestTurn and the checkpoint - // rebinding that `thread.message-sent` performs are deliberately - // untouched — attributing it to the live turn would fold it away - // behind that turn's summary. + // provenance. latestTurn and the checkpoint rebinding that + // `thread.message-sent` performs are deliberately untouched — + // attributing a delivery to the live turn would fold it away behind + // that turn's summary. Turn-scoped media is the one exception: its + // payload names the turn it rode in on (sequencing only), and dropping + // it here made the live-streamed delivery render without its file + // while a reload — which reads the projection row — showed it. const message: OrchestrationMessage = { id: event.payload.messageId, role: "assistant", text: event.payload.text, - turnId: null, + ...(event.payload.attachments !== undefined + ? { attachments: event.payload.attachments } + : {}), + turnId: event.payload.turnId ?? null, streaming: false, notification: event.payload.notification, createdAt: event.payload.createdAt,