From c7a59d52214239de8f7b0c8abf609713b171235e Mon Sep 17 00:00:00 2001 From: Byron Wall Date: Sat, 28 Nov 2026 01:15:13 -0500 Subject: [PATCH 1/2] Read UMAP points through one query fetchUmapPoints and fetchUmapPointsForRun both registered "umap-points", so Canvas and the run page read each other's cache entry with the wrong shape. Canvas crashed and the run page showed no points. Delete the second query and fail the tests on any repeated query name. Co-Authored-By: Claude Sonnet 5.5 --- app/src/features/umap/detail-types.ts | 1 - app/src/features/umap/useUmapCanvas.ts | 2 +- app/src/routes/umap/[id]/index.tsx | 20 ++++------- app/src/services/umap/umap.queries.ts | 30 ---------------- app/tests/unit/query-keys.test.ts | 48 ++++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 45 deletions(-) create mode 100644 app/tests/unit/query-keys.test.ts diff --git a/app/src/features/umap/detail-types.ts b/app/src/features/umap/detail-types.ts index 668eaf69..8bb3914e 100644 --- a/app/src/features/umap/detail-types.ts +++ b/app/src/features/umap/detail-types.ts @@ -5,6 +5,5 @@ import type { export type UmapDetailData = { meta: UmapRunDetail; - dims: number; points: UmapPoint[]; }; diff --git a/app/src/features/umap/useUmapCanvas.ts b/app/src/features/umap/useUmapCanvas.ts index d271d5f7..2a00fb67 100644 --- a/app/src/features/umap/useUmapCanvas.ts +++ b/app/src/features/umap/useUmapCanvas.ts @@ -35,7 +35,7 @@ export function useUmapCanvas(props: UseUmapCanvasProps) { createEffect(() => { const detail = props.detail(); const points = detail?.points ?? []; - const dims = detail?.dims ?? 2; + const dims = detail?.meta.dims ?? 2; const regions = detail?.meta.regions ?? null; const width = canvasWidth(); const height = canvasHeight(); diff --git a/app/src/routes/umap/[id]/index.tsx b/app/src/routes/umap/[id]/index.tsx index 401facc0..d5ea33ef 100644 --- a/app/src/routes/umap/[id]/index.tsx +++ b/app/src/routes/umap/[id]/index.tsx @@ -9,10 +9,8 @@ import { import { Link } from "~/components/ui/link"; import { Text } from "~/components/ui/text"; import { Box, Container, Grid, Stack } from "styled-system/jsx"; -import { - fetchUmapPointsForRun, - fetchUmapRun, -} from "~/services/umap/umap.queries"; +import { fetchUmapPoints } from "~/services/umap.service"; +import { fetchUmapRun } from "~/services/umap/umap.queries"; import { deleteUmapRun, regenerateUmapRegionsAction, @@ -39,20 +37,16 @@ const UmapDetail: VoidComponent = () => { const run = await fetchUmapRun(params.id); if (!run) return null; - const pointsData = await fetchUmapPointsForRun(params.id).catch(() => null); + const points = await fetchUmapPoints(params.id).catch(() => []); - return { - meta: run, - dims: pointsData?.dims ?? run.dims, - points: pointsData?.points ?? [], - }; + return { meta: run, points }; }); const { setCanvasContainerEl, setCanvasEl } = useUmapCanvas({ detail }); const refreshPoints = () => { if (!params.id) return; - void revalidate(fetchUmapPointsForRun.keyFor(params.id)); + void revalidate(fetchUmapPoints.keyFor(params.id)); }; const handleDelete = async () => { @@ -78,7 +72,7 @@ const UmapDetail: VoidComponent = () => { await runRegenerateRegions({ id: params.id }); await Promise.all([ revalidate(fetchUmapRun.keyFor(params.id)), - revalidate(fetchUmapPointsForRun.keyFor(params.id)), + revalidate(fetchUmapPoints.keyFor(params.id)), ]); } catch (error) { console.error(error); @@ -131,7 +125,7 @@ const UmapDetail: VoidComponent = () => { alignItems="start" > => { - "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"); - - const pts = await prisma.umapPoint.findMany({ - where: { runId, doc: { archivedAt: null } }, - select: { docId: true, x: true, y: true, z: true }, - }); - return { - runId, - dims: run.dims, - points: pts.map((p) => ({ - docId: p.docId, - x: p.x, - y: p.y, - z: p.z, - })), - }; - }, - "umap-points", -); - export const fetchUmapRegionDetail = query( async (input: { runId: string; diff --git a/app/tests/unit/query-keys.test.ts b/app/tests/unit/query-keys.test.ts new file mode 100644 index 00000000..a7ba27c3 --- /dev/null +++ b/app/tests/unit/query-keys.test.ts @@ -0,0 +1,48 @@ +import { readdirSync, readFileSync } from "node:fs"; +import { join, relative } from "node:path"; +import ts from "typescript"; +import { describe, expect, it } from "vitest"; + +const SRC = join(__dirname, "../../src"); + +/** Every `query(fn, name)` call in a file that imports from the router. */ +const queryNames = (file: string) => { + const text = readFileSync(file, "utf8"); + if (!text.includes("@solidjs/router")) return []; + const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest); + const found: { name: string; file: string }[] = []; + const walk = (node: ts.Node) => { + if ( + ts.isCallExpression(node) && + ts.isIdentifier(node.expression) && + node.expression.text === "query" && + node.arguments.length === 2 + ) { + const name = node.arguments[1]; + found.push({ + name: ts.isStringLiteralLike(name) ? name.text : "(not a literal)", + file: relative(SRC, file), + }); + } + ts.forEachChild(node, walk); + }; + walk(source); + return found; +}; + +describe("router query names", () => { + // The router caches by name plus arguments. Two queries with one name read + // each other's entries, whatever their return types say. + it("are literal and used once each", () => { + const all = readdirSync(SRC, { recursive: true, encoding: "utf8" }) + .filter((path) => /\.tsx?$/.test(path)) + .flatMap((path) => queryNames(join(SRC, path))); + const byName = Map.groupBy(all, (query) => query.name); + const clashes = [...byName] + .filter(([name, uses]) => uses.length > 1 || name === "(not a literal)") + .map(([name, uses]) => `${name}: ${uses.map((u) => u.file).join(", ")}`); + + expect(all.length).toBeGreaterThan(50); + expect(clashes).toEqual([]); + }); +}); From e222e324d451bd923ed8f21f63d26cc70d9058f1 Mon Sep 17 00:00:00 2001 From: Byron Wall Date: Sat, 28 Nov 2026 01:20:58 -0500 Subject: [PATCH 2/2] Close review gaps in the query name guard Fail the test on router imports and call shapes the scan cannot read. Keep the run page's dimensions badge live, and drop the removed query from the MCP parity matrix. Co-Authored-By: Claude Sonnet 5.5 --- app/docs/mcp-parity.md | 8 +++--- app/src/routes/umap/[id]/index.tsx | 2 +- app/tests/unit/query-keys.test.ts | 44 +++++++++++++++++++++++------- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/app/docs/mcp-parity.md b/app/docs/mcp-parity.md index f2fac9a9..64c9a43e 100644 --- a/app/docs/mcp-parity.md +++ b/app/docs/mcp-parity.md @@ -230,10 +230,10 @@ Keep this file current when adding an action or a tool. A new action is either c ## Embeddings and UMAP -| Action / query | MCP | Notes | -| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ---------------------------------------------------------------- | -| `createEmbeddingRun`, `processEmbeddingRun`, `updateEmbeddingRun`, `deleteEmbeddingRun`, `fetchEmbeddingRun`, `fetchEmbeddingRuns`, `fetchDocSections` | human-only | Admin; `search` uses the newest run, and agent writes refresh it | -| `createUmapRun`, `projectUmapRun`, `updateUmapRun`, `deleteUmapRun`, `regenerateUmapRegionsAction`, `fetchUmapRun`, `fetchUmapRuns`, `fetchUmapPointsForRun`, `fetchUmapRegionDetail`, `fetchLatestUmapRun`, `fetchUmapPoints`, `fetchNearbyUmapDocs` | human-only | The map view; `search` covers "notes like this" | +| Action / query | MCP | Notes | +| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ---------------------------------------------------------------- | +| `createEmbeddingRun`, `processEmbeddingRun`, `updateEmbeddingRun`, `deleteEmbeddingRun`, `fetchEmbeddingRun`, `fetchEmbeddingRuns`, `fetchDocSections` | human-only | Admin; `search` uses the newest run, and agent writes refresh it | +| `createUmapRun`, `projectUmapRun`, `updateUmapRun`, `deleteUmapRun`, `regenerateUmapRegionsAction`, `fetchUmapRun`, `fetchUmapRuns`, `fetchUmapRegionDetail`, `fetchLatestUmapRun`, `fetchUmapPoints`, `fetchNearbyUmapDocs` | human-only | The map view; `search` covers "notes like this" | ## Admin and auth diff --git a/app/src/routes/umap/[id]/index.tsx b/app/src/routes/umap/[id]/index.tsx index d5ea33ef..4a4a523c 100644 --- a/app/src/routes/umap/[id]/index.tsx +++ b/app/src/routes/umap/[id]/index.tsx @@ -125,7 +125,7 @@ const UmapDetail: VoidComponent = () => { alignItems="start" > + ts.isNamespaceImport(binding) || + binding.elements.some((element) => { + const imported = (element.propertyName ?? element.name).text; + if (imported === "cache") return true; + return imported === "query" && element.name.text !== "query"; + }); + +/** Every `query(fn, name)` call in a file that imports the router's `query`. */ const queryNames = (file: string) => { const text = readFileSync(file, "utf8"); if (!text.includes("@solidjs/router")) return []; const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest); const found: { name: string; file: string }[] = []; + const add = (name: string) => found.push({ name, file: relative(SRC, file) }); + const imports = source.statements.flatMap((node) => + ts.isImportDeclaration(node) && + ts.isStringLiteral(node.moduleSpecifier) && + node.moduleSpecifier.text === "@solidjs/router" && + node.importClause?.namedBindings + ? [node.importClause.namedBindings] + : [], + ); + if (imports.some(hidesQueries)) add(UNREADABLE); + // Elsewhere `query()` is usually a search-text signal. + const importsQuery = imports.some( + (binding) => + ts.isNamedImports(binding) && + binding.elements.some((element) => element.name.text === "query"), + ); const walk = (node: ts.Node) => { if ( + importsQuery && ts.isCallExpression(node) && ts.isIdentifier(node.expression) && - node.expression.text === "query" && - node.arguments.length === 2 + node.expression.text === "query" ) { - const name = node.arguments[1]; - found.push({ - name: ts.isStringLiteralLike(name) ? name.text : "(not a literal)", - file: relative(SRC, file), - }); + const [, name, ...rest] = node.arguments; + const literal = name && ts.isStringLiteralLike(name) && !rest.length; + add(literal ? name.text : UNREADABLE); } ts.forEachChild(node, walk); }; @@ -33,13 +57,13 @@ const queryNames = (file: string) => { describe("router query names", () => { // The router caches by name plus arguments. Two queries with one name read // each other's entries, whatever their return types say. - it("are literal and used once each", () => { + it("are readable and used once each", () => { const all = readdirSync(SRC, { recursive: true, encoding: "utf8" }) .filter((path) => /\.tsx?$/.test(path)) .flatMap((path) => queryNames(join(SRC, path))); const byName = Map.groupBy(all, (query) => query.name); const clashes = [...byName] - .filter(([name, uses]) => uses.length > 1 || name === "(not a literal)") + .filter(([name, uses]) => uses.length > 1 || name === UNREADABLE) .map(([name, uses]) => `${name}: ${uses.map((u) => u.file).join(", ")}`); expect(all.length).toBeGreaterThan(50);