Harden asset symlink handling and fix image output pairing

- Re-resolve browser-artifact and thread-image claims on every request so
  post-issuance symlink swaps cannot redirect a signed token
- Verify canonical containment and media extension after realPath
- Render unscoped image outputs when no turn is unsettled
- Keep the image activity id paired with its path across collapsing

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
Julius MarmingeandClaude Fable 5 authored and Gabriel De Andrade committed 2026-07-29 16:58:58 -04:00
1 parent 6f9e892da8
commit e3edf9bc8e
7 files changed
+280 -20

No files matched your search

@@ -261,6 +261,61 @@ describe("resolveAssistantMessageCopyState", () => {
});
describe("deriveMessagesTimelineRows", () => {
it("renders unscoped image output when no turn is unsettled", () => {
const timelineEntries = [
{
id: "unscoped-image-entry",
kind: "work" as const,
createdAt: "2026-01-01T00:00:10Z",
entry: {
id: "unscoped-image-activity",
createdAt: "2026-01-01T00:00:10Z",
turnId: null,
label: "Image view",
tone: "tool" as const,
itemType: "image_view" as const,
imagePath: "/tmp/unscoped.png",
toolLifecycleStatus: "completed" as const,
},
},
{
id: "assistant-entry",
kind: "message" as const,
createdAt: "2026-01-01T00:00:20Z",
message: {
id: "assistant-message" as never,
role: "assistant" as const,
text: "Here is the image.",
turnId: null,
createdAt: "2026-01-01T00:00:20Z",
updatedAt: "2026-01-01T00:00:21Z",
streaming: false,
},
},
];
const rows = deriveMessagesTimelineRows({
timelineEntries,
isWorking: false,
activeTurnStartedAt: null,
turnDiffSummaryByAssistantMessageId: new Map(),
revertTurnCountByUserMessageId: new Map(),
expandedTurnIds: new Set(),
});
const imageOutputRow = rows.find((row) => row.kind === "image-output");
expect(imageOutputRow).toMatchObject({
kind: "image-output",
id: "image-output:unscoped",
images: [
{
entry: { id: "unscoped-image-activity" },
imagePath: "/tmp/unscoped.png",
},
],
});
});
it("deduplicates and groups image output after the terminal assistant message", () => {
const timelineEntries = [
{
@@ -277,7 +277,9 @@ function appendImageOutputRows(input: {
if (entry.itemType !== "image_view" || !entry.imagePath) {
continue;
}
if (entry.turnId === input.unsettledTurnId) {
// Only skip images that belong to the in-flight turn; an unscoped entry
// (null turnId) must still render when no turn is unsettled.
if (input.unsettledTurnId !== null && entry.turnId === input.unsettledTurnId) {
continue;
}
const turnId = entry.turnId ?? null;
@@ -1975,7 +1975,7 @@ function ImageOutputThumbnail({
const assetUrl = useAssetUrlState(activeThreadEnvironmentId, {
_tag: "thread-image",
threadId: threadRef.threadId,
activityId: EventId.make(image.entry.id),
activityId: EventId.make(image.entry.imageActivityId ?? image.entry.id),
});
const [failedUrl, setFailedUrl] = useState<string | null>(null);
const loadedUrl = assetUrl._tag === "Success" && assetUrl.url !== failedUrl ? assetUrl.url : null;
+43
View File
@@ -1057,6 +1057,49 @@ describe("deriveWorkLogEntries", () => {
});
});
it("keeps the image activity id paired with the path when collapsing entries", () => {
const imagePath = "/tmp/codex-preview.png";
const entries = deriveWorkLogEntries([
makeActivity({
id: "image-view-with-path",
kind: "tool.updated",
summary: "Image view",
payload: {
itemType: "image_view",
status: "in_progress",
title: "Image view",
data: {
toolCallId: "call-image-1",
item: { id: "call-image-1", path: imagePath, type: "imageView" },
},
},
}),
// The completion for the same tool call carries no path; collapsing
// adopts its id, so the path's owning activity id must be retained.
makeActivity({
id: "image-view-without-path",
kind: "tool.completed",
summary: "Image view",
payload: {
itemType: "image_view",
status: "completed",
title: "Image view",
data: {
toolCallId: "call-image-1",
item: { id: "call-image-1", type: "imageView" },
},
},
}),
]);
expect(entries).toHaveLength(1);
expect(entries[0]).toMatchObject({
id: "image-view-without-path",
imagePath,
imageActivityId: "image-view-with-path",
});
});
it("unwraps PowerShell command wrappers for displayed command text", () => {
const activities: OrchestrationThreadActivity[] = [
makeActivity({
+12 -1
View File
@@ -70,6 +70,12 @@ export interface WorkLogEntry {
rawCommand?: string;
changedFiles?: ReadonlyArray<string>;
imagePath?: string;
/**
* Activity that carried `imagePath`. Collapsing can merge a later activity's
* `id` onto an earlier activity's `imagePath`, and the asset lookup resolves
* the path from this activity's payload — so it must stay paired with it.
*/
imageActivityId?: string;
tone: "thinking" | "tool" | "info" | "error";
toolTitle?: string;
toolData?: unknown;
@@ -752,6 +758,7 @@ function toDerivedWorkLogEntry(activity: OrchestrationThreadActivity): DerivedWo
: null;
if (imagePath) {
entry.imagePath = imagePath;
entry.imageActivityId = entry.id;
}
}
if (itemType) {
@@ -825,7 +832,11 @@ function mergeDerivedWorkLogEntries(
const detail = next.detail ?? previous.detail;
const command = next.command ?? previous.command;
const rawCommand = next.rawCommand ?? previous.rawCommand;
// Keep the owning activity id paired with the path it came from.
const imagePath = next.imagePath ?? previous.imagePath;
const imageActivityId = next.imagePath
? (next.imageActivityId ?? next.id)
: (previous.imageActivityId ?? previous.id);
const toolTitle = next.toolTitle ?? previous.toolTitle;
const itemType = next.itemType ?? previous.itemType;
const requestKind = next.requestKind ?? previous.requestKind;
@@ -839,7 +850,7 @@ function mergeDerivedWorkLogEntries(
...(detail ? { detail } : {}),
...(command ? { command } : {}),
...(rawCommand ? { rawCommand } : {}),
...(imagePath ? { imagePath } : {}),
...(imagePath ? { imagePath, imageActivityId } : {}),
...(changedFiles.length > 0 ? { changedFiles } : {}),
...(toolTitle ? { toolTitle } : {}),
...(itemType ? { itemType } : {}),