From efede3661a316241ab65dee88c035fbffa71edda Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 27 Jul 2026 23:34:02 +0200 Subject: [PATCH] Keep image view paths when pruning activity payloads Payload pruning (#4622) stripped every item field outside the command allowlist, so image view activities reached clients without the path and the chat gallery rendered nothing. Preserve the item type and path while still dropping the base64 image bytes. Co-Authored-By: Claude Fable 5 --- .../ActivityPayloadProjection.test.ts | 63 +++++++++++++++++++ .../ActivityPayloadProjection.ts | 27 +++++++- 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 apps/server/src/orchestration/ActivityPayloadProjection.test.ts diff --git a/apps/server/src/orchestration/ActivityPayloadProjection.test.ts b/apps/server/src/orchestration/ActivityPayloadProjection.test.ts new file mode 100644 index 0000000000..d0a4a0d7df --- /dev/null +++ b/apps/server/src/orchestration/ActivityPayloadProjection.test.ts @@ -0,0 +1,63 @@ +import { EventId, TurnId, type OrchestrationThreadActivity } from "@t3tools/contracts"; +import { describe, expect, it } from "@effect/vitest"; + +import { projectActivityPayload } from "./ActivityPayloadProjection.ts"; + +const makeImageActivity = (item: Record): OrchestrationThreadActivity => ({ + id: EventId.make("activity-image-1"), + tone: "tool", + kind: "tool.completed", + summary: "Image view", + payload: { + itemType: "image_view", + detail: "/tmp/generated.png", + data: { completedAtMs: 1, item }, + }, + turnId: TurnId.make("turn-1"), + createdAt: "2026-07-27T21:17:50.000Z", +}); + +const projectedItem = (activity: OrchestrationThreadActivity): Record => { + const payload = activity.payload as { data?: { item?: Record } }; + return payload.data?.item ?? {}; +}; + +describe("projectActivityPayload", () => { + it("keeps the saved path for generated images while pruning the base64 result", () => { + const projected = projectActivityPayload( + makeImageActivity({ + id: "call-1", + type: "imageGeneration", + savedPath: "/Users/test/.codex/generated_images/thread/call.png", + revisedPrompt: "a prompt", + result: "iVBORw0KGgoAAAANSUhEUg", + status: "completed", + }), + ); + + const item = projectedItem(projected); + expect(item.savedPath).toBe("/Users/test/.codex/generated_images/thread/call.png"); + expect(item.type).toBe("imageGeneration"); + // The generated image bytes are megabytes per activity and unread by clients. + expect(item.result).toBeUndefined(); + expect(item.revisedPrompt).toBeUndefined(); + }); + + it("keeps the viewed path for image view items", () => { + const projected = projectActivityPayload( + makeImageActivity({ id: "call-2", type: "imageView", path: "/tmp/screenshot.png" }), + ); + + const item = projectedItem(projected); + expect(item.path).toBe("/tmp/screenshot.png"); + expect(item.type).toBe("imageView"); + }); + + it("still prunes unrelated tool item payloads", () => { + const projected = projectActivityPayload( + makeImageActivity({ id: "call-3", type: "somethingElse", secret: "value" }), + ); + + expect(projectedItem(projected)).toEqual({}); + }); +}); diff --git a/apps/server/src/orchestration/ActivityPayloadProjection.ts b/apps/server/src/orchestration/ActivityPayloadProjection.ts index 67896961b3..905dacc3f7 100644 --- a/apps/server/src/orchestration/ActivityPayloadProjection.ts +++ b/apps/server/src/orchestration/ActivityPayloadProjection.ts @@ -104,6 +104,31 @@ function projectCommandData(data: Record): Record 0 ? projectedItem : undefined; } +/** + * Image view items carry the on-disk path both clients need to render the + * output gallery. The generated image itself also rides along in `result` as + * base64 — that stays pruned, since it is megabytes per activity and no client + * reads it. + */ +function projectImageViewData(data: Record): Record | undefined { + const item = asRecord(data.item); + if (!item) { + return undefined; + } + if (item.type !== "imageView" && item.type !== "imageGeneration") { + return undefined; + } + + const projectedItem: Record = { type: item.type }; + if (asTrimmedString(item.path)) { + projectedItem.path = item.path; + } + if (asTrimmedString(item.savedPath)) { + projectedItem.savedPath = item.savedPath; + } + return Object.keys(projectedItem).length > 1 ? projectedItem : undefined; +} + function summarizeToolTextOutput(value: string): string | null { const lines: string[] = []; for (const rawLine of value.split(/\r?\n/u)) { @@ -165,7 +190,7 @@ export function projectActivityPayload( } const projectedData: Record = {}; - const item = projectCommandData(data); + const item = projectCommandData(data) ?? projectImageViewData(data); if (item) { projectedData.item = item; }