From 3f327a56c4ed01aa12d5f571ef2da2858362e749 Mon Sep 17 00:00:00 2001 From: Byron Wall Date: Sat, 28 Nov 2026 08:26:18 -0500 Subject: [PATCH 1/3] Make Refresh points reread a UMAP run's points The run page read its points after awaiting the run record, so the router did not track the read and revalidating it reran nothing. Start both reads before the first await. Co-Authored-By: Claude Sonnet 5.5 --- app/src/routes/umap/[id]/index.tsx | 11 ++++--- app/tests/e2e/helpers/fixtures.ts | 40 +++++++++++++++++++++++- app/tests/e2e/umap-run-refresh.spec.ts | 43 ++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 app/tests/e2e/umap-run-refresh.spec.ts diff --git a/app/src/routes/umap/[id]/index.tsx b/app/src/routes/umap/[id]/index.tsx index 4a4a523c..b59d4e92 100644 --- a/app/src/routes/umap/[id]/index.tsx +++ b/app/src/routes/umap/[id]/index.tsx @@ -34,12 +34,15 @@ const UmapDetail: VoidComponent = () => { const detail = createAsync(async (): Promise => { if (!params.id) return null; - const run = await fetchUmapRun(params.id); - if (!run) return null; + // Start both reads before the first await. A query called after it isn't + // tracked, so revalidating it would not rerun this. + const runRead = fetchUmapRun(params.id); + const pointsRead = fetchUmapPoints(params.id).catch(() => []); - const points = await fetchUmapPoints(params.id).catch(() => []); + const run = await runRead; + if (!run) return null; - return { meta: run, points }; + return { meta: run, points: await pointsRead }; }); const { setCanvasContainerEl, setCanvasEl } = useUmapCanvas({ detail }); diff --git a/app/tests/e2e/helpers/fixtures.ts b/app/tests/e2e/helpers/fixtures.ts index 45d51034..6a65bb2d 100644 --- a/app/tests/e2e/helpers/fixtures.ts +++ b/app/tests/e2e/helpers/fixtures.ts @@ -295,11 +295,13 @@ export const seedRevisionFixture = async ( * one embedding run, one UMAP run with a single region, and a point per note. * No app endpoint creates these without OpenAI and the Python UMAP step, so * this writes directly, and only to the run manifest's synthetic database. - * The canvas reads the newest UMAP run, so callers must not run in parallel. + * The canvas reads the newest UMAP run, so callers must not run in parallel, + * unless they date their run into the past with `createdAt`. */ export const seedCanvasRegionFixture = async ( regionTitle: string, notes: Array<{ id: string; title: string }>, + { createdAt }: { createdAt?: Date } = {}, ) => { const datasourceUrl = seedDatasourceUrl(); @@ -380,6 +382,7 @@ export const seedCanvasRegionFixture = async ( params: {}, regionsJson, regionsUpdatedAt: new Date(), + createdAt, points: { create: points }, }, }); @@ -388,3 +391,38 @@ export const seedCanvasRegionFixture = async ( await prisma.$disconnect(); } }; + +/** + * Drops one note's point from a seeded projection, so a reread of the run's + * points returns one fewer. It writes only to the run manifest's synthetic + * database. + */ +export const removeUmapPointFixture = async ( + embeddingRunId: string, + docId: string, +) => { + const { PrismaClient } = await import("@prisma/client"); + const prisma = new PrismaClient({ datasourceUrl: seedDatasourceUrl() }); + try { + await prisma.umapPoint.deleteMany({ + where: { docId, run: { embeddingRunId } }, + }); + } finally { + await prisma.$disconnect(); + } +}; + +/** The id of the UMAP run a seeded embedding run holds. */ +export const umapRunIdFixture = async (embeddingRunId: string) => { + const { PrismaClient } = await import("@prisma/client"); + const prisma = new PrismaClient({ datasourceUrl: seedDatasourceUrl() }); + try { + const run = await prisma.umapRun.findFirstOrThrow({ + where: { embeddingRunId }, + select: { id: true }, + }); + return run.id; + } finally { + await prisma.$disconnect(); + } +}; diff --git a/app/tests/e2e/umap-run-refresh.spec.ts b/app/tests/e2e/umap-run-refresh.spec.ts new file mode 100644 index 00000000..c629a04d --- /dev/null +++ b/app/tests/e2e/umap-run-refresh.spec.ts @@ -0,0 +1,43 @@ +import { expect, test } from "@playwright/test"; +import { + canSeedAuditDatabase, + createNoteFixture, + removeUmapPointFixture, + seedCanvasRegionFixture, + umapRunIdFixture, + uniqueSuffix, +} from "./helpers/fixtures"; +import { waitForAppReady } from "./helpers/readiness"; + +// "Refresh points" sent no request: the run page read its points after an +// await, so revalidating them reran nothing. +test.describe("UMAP run page", () => { + test.skip( + !canSeedAuditDatabase(), + "needs AUDIT_RUN_MANIFEST and AUDIT_ENV_FILE to seed a UMAP run", + ); + + test("Refresh points shows the run's current points", async ({ page }) => { + const suffix = uniqueSuffix(); + const notes: Array<{ id: string; title: string }> = []; + for (const name of ["first", "second"]) { + const title = `UMAP refresh ${name} ${suffix}`; + const id = await createNoteFixture(page, { title, markdown: title }); + notes.push({ id, title }); + } + // Dated into the past so the canvas specs' run stays the newest. + const embeddingRunId = await seedCanvasRegionFixture( + `UMAP refresh ${suffix}`, + notes, + { createdAt: new Date(0) }, + ); + await page.goto(`/umap/${await umapRunIdFixture(embeddingRunId)}`); + await waitForAppReady(page); + await expect(page.getByText("2 points", { exact: true })).toBeVisible(); + + await removeUmapPointFixture(embeddingRunId, notes[0].id); + await page.getByRole("button", { name: "Refresh points" }).click(); + + await expect(page.getByText("1 points", { exact: true })).toBeVisible(); + }); +}); From c0f480817af718113c2307c2332356ca2b542183 Mon Sep 17 00:00:00 2001 From: Byron Wall Date: Sat, 28 Nov 2026 08:33:03 -0500 Subject: [PATCH 2/3] Return no points for an unknown UMAP run The run page now asks for points before it knows the run exists, and the "Run not found" throw reached the browser console. Co-Authored-By: Claude Sonnet 5.5 --- app/src/services/umap.service.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/src/services/umap.service.ts b/app/src/services/umap.service.ts index 5425169b..cc4b7ce8 100644 --- a/app/src/services/umap.service.ts +++ b/app/src/services/umap.service.ts @@ -48,11 +48,7 @@ export const fetchUmapPoints = query( async (runId: string): Promise => { "use server"; if (!runId) throw new Error("Missing runId"); - const run = await prisma.umapRun.findUnique({ - where: { id: runId }, - select: { id: true, dims: true }, - }); - if (!run) throw new Error("Run not found"); + // An unknown run has no points. The run page reads both at once. const pts = await prisma.umapPoint.findMany({ where: { runId, doc: { archivedAt: null } }, select: { docId: true, x: true, y: true, z: true }, From e05bacf7288fe8f4c71581537c7d5bf957dfa84d Mon Sep 17 00:00:00 2001 From: Byron Wall Date: Sat, 28 Nov 2026 08:37:08 -0500 Subject: [PATCH 3/3] Keep a UMAP run's points when a refresh fails Co-Authored-By: Claude Sonnet 5.5 --- app/src/routes/umap/[id]/index.tsx | 13 +++++++++---- app/tests/e2e/umap-run-refresh.spec.ts | 12 +++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/src/routes/umap/[id]/index.tsx b/app/src/routes/umap/[id]/index.tsx index b59d4e92..1eb0c6f7 100644 --- a/app/src/routes/umap/[id]/index.tsx +++ b/app/src/routes/umap/[id]/index.tsx @@ -31,13 +31,18 @@ const UmapDetail: VoidComponent = () => { const [busy, setBusy] = createSignal(false); const [regeneratingRegions, setRegeneratingRegions] = createSignal(false); - const detail = createAsync(async (): Promise => { - if (!params.id) return null; + const detail = createAsync(async (prev) => { + const id = params.id; + if (!id) return null; // Start both reads before the first await. A query called after it isn't // tracked, so revalidating it would not rerun this. - const runRead = fetchUmapRun(params.id); - const pointsRead = fetchUmapPoints(params.id).catch(() => []); + const runRead = fetchUmapRun(id); + const pointsRead = fetchUmapPoints(id).catch((error) => { + console.warn("[UmapDetail] points read failed", error); + // A failed reread keeps this run's last points. + return prev?.meta.id === id ? prev.points : []; + }); const run = await runRead; if (!run) return null; diff --git a/app/tests/e2e/umap-run-refresh.spec.ts b/app/tests/e2e/umap-run-refresh.spec.ts index c629a04d..3fd7ce66 100644 --- a/app/tests/e2e/umap-run-refresh.spec.ts +++ b/app/tests/e2e/umap-run-refresh.spec.ts @@ -35,9 +35,19 @@ test.describe("UMAP run page", () => { await waitForAppReady(page); await expect(page.getByText("2 points", { exact: true })).toBeVisible(); + const refresh = page.getByRole("button", { name: "Refresh points" }); await removeUmapPointFixture(embeddingRunId, notes[0].id); - await page.getByRole("button", { name: "Refresh points" }).click(); + await page.route("**/_server*", (route) => route.abort()); + const failed = page.waitForEvent("console", (message) => + message.text().includes("[UmapDetail] points read failed"), + ); + await refresh.click(); + await failed; + await expect(page.getByText("2 points", { exact: true })).toBeVisible(); + + await page.unroute("**/_server*"); + await refresh.click(); await expect(page.getByText("1 points", { exact: true })).toBeVisible(); }); });