fix(client-runtime): live media deliveries kept their file only after reload

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 <[email protected]>
This commit is contained in:
Ben DavisandClaude Fable 5 committed 2026-07-27 21:06:36 -07:00
1 parent ae8c0ca7fd
commit 77ff1ee304
2 files changed
+51 -5

No files matched your search

@@ -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.
@@ -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,