From ee4a58b56c808df142fc523c99422faa224e7c49 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Thu, 19 Nov 2026 07:54:18 +0100 Subject: [PATCH 1/4] test(client-runtime): file tooltips keep the size after workspace search Co-authored-by: Claude Opus 5.5 --- .../src/state/fileMetadata.test.ts | 5 ++- ...ile-tooltip-keeps-size-after-search.e2e.ts | 33 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 scripts/scenarios/cited-file-tooltip-keeps-size-after-search.e2e.ts diff --git a/packages/client-runtime/src/state/fileMetadata.test.ts b/packages/client-runtime/src/state/fileMetadata.test.ts index daf50845e2c05..9ebca489c63ff 100644 --- a/packages/client-runtime/src/state/fileMetadata.test.ts +++ b/packages/client-runtime/src/state/fileMetadata.test.ts @@ -346,12 +346,15 @@ describe("file metadata", () => { }), ); - it.effect("uses search and tree kinds without another request", () => + it.effect("uses search and tree kinds for directories but still stats found files", () => Effect.gen(function* () { const h = yield* makeHarness(); yield* h.seed("folder.ts", "directory"); expect(yield* h.read("/workspace/folder.ts")).toEqual({ kind: "directory" }); expect(h.batches).toHaveLength(0); + h.values.set("/workspace/notes.md", { kind: "file", byteLength: 2048 }); + yield* h.seed("notes.md", "file"); + expect(yield* h.read("/workspace/notes.md")).toEqual({ kind: "file", byteLength: 2048 }); }), ); diff --git a/scripts/scenarios/cited-file-tooltip-keeps-size-after-search.e2e.ts b/scripts/scenarios/cited-file-tooltip-keeps-size-after-search.e2e.ts new file mode 100644 index 0000000000000..bff8319ab1d84 --- /dev/null +++ b/scripts/scenarios/cited-file-tooltip-keeps-size-after-search.e2e.ts @@ -0,0 +1,33 @@ +import { expect } from "e2e"; + +import { test, WEB } from "./t3.ts"; + +const FILE = "quarterly-figures.md"; + +test( + "The file citation tooltip shows the size even after workspace search finds the file", + WEB, + async ({ t3, app, browser, screen }) => { + const project = await t3.project("demo", { [FILE]: "x".repeat(2048) }); + const thread = await t3.thread({ + project, + title: "Review figures", + messages: [`See :codex-file-citation{path="${FILE}" line_range_start="1"}`], + }); + await t3.open(thread); + + await screen.getByRole("textbox").pressSequentially(`@${FILE}`); + await screen.getByRole("option", FILE, { exact: false }).hover(); + await browser.keyboard.press("Escape"); + await screen.getByRole("button", /^Agent See/).tap(); + await screen.getByRole("link", /^quarterly-figures\.md/).hover(); + + try { + await expect( + browser.locator('[data-slot="tooltip-viewport"]:has-text("quarterly-figures.md")'), + ).toContainText("2 KB"); + } finally { + await app.screenshot("cited-file-tooltip"); + } + }, +); From 3feec568ac131a52756647c281177f1ec7619962 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Thu, 19 Nov 2026 07:56:10 +0100 Subject: [PATCH 2/4] fix(client-runtime): file tooltips keep the size after workspace search Workspace search and tree listings seeded file paths into the metadata cache with only their kind, so a file chip mounted afterwards read that entry and never learned the file's size. Listings now seed directories only, whose kind is their whole metadata, and files still get a stat. Co-authored-by: Claude Opus 5.5 --- packages/client-runtime/src/state/fileMetadata.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/client-runtime/src/state/fileMetadata.ts b/packages/client-runtime/src/state/fileMetadata.ts index 5d20d3188909a..bcd382a834ed1 100644 --- a/packages/client-runtime/src/state/fileMetadata.ts +++ b/packages/client-runtime/src/state/fileMetadata.ts @@ -263,6 +263,8 @@ export function createFileMetadataAtoms( const now = yield* Clock.currentTimeMillis; if (isCurrent && !isCurrent(session.value)) return; for (const entry of entries) { + // A listing knows a file's kind but not its size or MIME type, so files still get a stat. + if (entry.kind !== "directory") continue; const path = resolveWorkspaceFilePath(entry.path, cwd); const previous = knownEntry(session.value, path, now); if (previous?.value?.kind === entry.kind) continue; From fdcfd2cc0829ced7110b20fd74b38cdcf0b4f0b4 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Thu, 19 Nov 2026 08:17:29 +0100 Subject: [PATCH 3/4] fix(client-runtime): invalidate stale metadata for listed files Co-authored-by: GPT 6.2 Sol --- .../src/state/fileMetadata.test.ts | 34 +++++++++++++++++++ .../client-runtime/src/state/fileMetadata.ts | 21 +++++++++--- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/packages/client-runtime/src/state/fileMetadata.test.ts b/packages/client-runtime/src/state/fileMetadata.test.ts index 9ebca489c63ff..ecea10516a05e 100644 --- a/packages/client-runtime/src/state/fileMetadata.test.ts +++ b/packages/client-runtime/src/state/fileMetadata.test.ts @@ -358,6 +358,40 @@ describe("file metadata", () => { }), ); + it.effect("stats listed files that replace directories or misses and reuses known file sizes", () => + Effect.gen(function* () { + const h = yield* makeHarness(); + const threadId = ThreadId.make("listed-file-thread"); + h.registry.mount(h.atoms.retainThread({ environmentId: ENVIRONMENT_ID, threadId })); + const directory = "/workspace/was-directory"; + const missing = "/workspace/was-missing"; + const file = "/workspace/known-file"; + yield* h.seed("was-directory", "directory"); + expect(yield* h.read(missing, ENVIRONMENT_ID, threadId)).toBeNull(); + h.values.set(file, { kind: "file", byteLength: 100 }); + yield* h.read(file, ENVIRONMENT_ID, threadId); + + h.values.set(directory, { kind: "file", byteLength: 2048 }); + h.values.set(missing, { kind: "file", byteLength: 4096 }); + yield* h.seed("was-directory", "file"); + yield* h.seed("was-missing", "file"); + yield* h.seed("known-file", "file"); + + expect(yield* h.read(directory)).toEqual({ kind: "file", byteLength: 2048 }); + h.registry.refresh(h.atom(missing, ENVIRONMENT_ID, threadId)); + expect(yield* h.read(missing, ENVIRONMENT_ID, threadId)).toEqual({ + kind: "file", + byteLength: 4096, + }); + h.registry.refresh(h.atom(file, ENVIRONMENT_ID, threadId)); + expect(yield* h.read(file, ENVIRONMENT_ID, threadId)).toEqual({ + kind: "file", + byteLength: 100, + }); + expect(h.batches.flat()).toEqual([missing, file, directory, missing]); + }), + ); + it.effect("splits large mounts into bounded batches and caches misses", () => Effect.gen(function* () { const h = yield* makeHarness(); diff --git a/packages/client-runtime/src/state/fileMetadata.ts b/packages/client-runtime/src/state/fileMetadata.ts index bcd382a834ed1..88bc3f6fc0a2d 100644 --- a/packages/client-runtime/src/state/fileMetadata.ts +++ b/packages/client-runtime/src/state/fileMetadata.ts @@ -263,12 +263,23 @@ export function createFileMetadataAtoms( const now = yield* Clock.currentTimeMillis; if (isCurrent && !isCurrent(session.value)) return; for (const entry of entries) { - // A listing knows a file's kind but not its size or MIME type, so files still get a stat. - if (entry.kind !== "directory") continue; const path = resolveWorkspaceFilePath(entry.path, cwd); - const previous = knownEntry(session.value, path, now); - if (previous?.value?.kind === entry.kind) continue; - remember(session.value, path, { kind: entry.kind }, now, true); + if (entry.kind === "directory") { + if (knownEntry(session.value, path, now)?.value?.kind !== "directory") + remember(session.value, path, { kind: "directory" }, now, true); + continue; + } + + // A file listing can invalidate the cached kind but only a stat supplies full metadata. + const key = normalizeProjectPathForComparison(path); + const cached = cache.get(session.value); + if (cached?.get(key)?.value?.kind === "file") continue; + cached?.delete(key); + for (const thread of retainedThreads.values()) { + const retained = thread.sessions.get(session.value); + const previous = retained?.get(key); + if (previous && previous.value?.kind !== "file") retained?.delete(key); + } } }); From 71beebcb41ed48c60bf5c0b354fec24320a073af Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Thu, 19 Nov 2026 08:17:58 +0100 Subject: [PATCH 4/4] style(client-runtime): format file metadata regression test Co-authored-by: GPT 6.2 Sol --- .../src/state/fileMetadata.test.ts | 62 ++++++++++--------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/packages/client-runtime/src/state/fileMetadata.test.ts b/packages/client-runtime/src/state/fileMetadata.test.ts index ecea10516a05e..c662fa26ee429 100644 --- a/packages/client-runtime/src/state/fileMetadata.test.ts +++ b/packages/client-runtime/src/state/fileMetadata.test.ts @@ -358,38 +358,40 @@ describe("file metadata", () => { }), ); - it.effect("stats listed files that replace directories or misses and reuses known file sizes", () => - Effect.gen(function* () { - const h = yield* makeHarness(); - const threadId = ThreadId.make("listed-file-thread"); - h.registry.mount(h.atoms.retainThread({ environmentId: ENVIRONMENT_ID, threadId })); - const directory = "/workspace/was-directory"; - const missing = "/workspace/was-missing"; - const file = "/workspace/known-file"; - yield* h.seed("was-directory", "directory"); - expect(yield* h.read(missing, ENVIRONMENT_ID, threadId)).toBeNull(); - h.values.set(file, { kind: "file", byteLength: 100 }); - yield* h.read(file, ENVIRONMENT_ID, threadId); + it.effect( + "stats listed files that replace directories or misses and reuses known file sizes", + () => + Effect.gen(function* () { + const h = yield* makeHarness(); + const threadId = ThreadId.make("listed-file-thread"); + h.registry.mount(h.atoms.retainThread({ environmentId: ENVIRONMENT_ID, threadId })); + const directory = "/workspace/was-directory"; + const missing = "/workspace/was-missing"; + const file = "/workspace/known-file"; + yield* h.seed("was-directory", "directory"); + expect(yield* h.read(missing, ENVIRONMENT_ID, threadId)).toBeNull(); + h.values.set(file, { kind: "file", byteLength: 100 }); + yield* h.read(file, ENVIRONMENT_ID, threadId); - h.values.set(directory, { kind: "file", byteLength: 2048 }); - h.values.set(missing, { kind: "file", byteLength: 4096 }); - yield* h.seed("was-directory", "file"); - yield* h.seed("was-missing", "file"); - yield* h.seed("known-file", "file"); + h.values.set(directory, { kind: "file", byteLength: 2048 }); + h.values.set(missing, { kind: "file", byteLength: 4096 }); + yield* h.seed("was-directory", "file"); + yield* h.seed("was-missing", "file"); + yield* h.seed("known-file", "file"); - expect(yield* h.read(directory)).toEqual({ kind: "file", byteLength: 2048 }); - h.registry.refresh(h.atom(missing, ENVIRONMENT_ID, threadId)); - expect(yield* h.read(missing, ENVIRONMENT_ID, threadId)).toEqual({ - kind: "file", - byteLength: 4096, - }); - h.registry.refresh(h.atom(file, ENVIRONMENT_ID, threadId)); - expect(yield* h.read(file, ENVIRONMENT_ID, threadId)).toEqual({ - kind: "file", - byteLength: 100, - }); - expect(h.batches.flat()).toEqual([missing, file, directory, missing]); - }), + expect(yield* h.read(directory)).toEqual({ kind: "file", byteLength: 2048 }); + h.registry.refresh(h.atom(missing, ENVIRONMENT_ID, threadId)); + expect(yield* h.read(missing, ENVIRONMENT_ID, threadId)).toEqual({ + kind: "file", + byteLength: 4096, + }); + h.registry.refresh(h.atom(file, ENVIRONMENT_ID, threadId)); + expect(yield* h.read(file, ENVIRONMENT_ID, threadId)).toEqual({ + kind: "file", + byteLength: 100, + }); + expect(h.batches.flat()).toEqual([missing, file, directory, missing]); + }), ); it.effect("splits large mounts into bounded batches and caches misses", () =>