Understand any codebase instantly. System intelligence for codebases, built for humans and AI.
TypeScript aiai-memoryclaude-codeclicode-analysiscode-mappingcode-memorycodebase-understandingcodexdeveloper-toolsllmopenclawpersistent-memoryprogram-analysissoftware-architecturesystem-intelligencesystem-mapping
fix(ingest): re-ingest every file once when the extractor changes
KageBinary064254005033
diff --git a/core-ingestion/src/patch-builder.ts b/core-ingestion/src/patch-builder.tsindex 9c7e74e6..55d61133 100644--- a/core-ingestion/src/patch-builder.ts+++ b/core-ingestion/src/patch-builder.ts@@ -134,9 +134,9 @@ function deduplicateUpsertEdges(ops: PatchOp[]): PatchOp[] {* old id and the new output never lands -- 1.26: JS/TS calls resolve by scope,* not name alone, and helper-loaded / dist/ imports link to their sources.*- * A bump does not trigger that re-ingest: `ix map` skips every file whose mtime- * or source hash is unchanged, so an unchanged file keeps the edges the old- * extractor built until the file changes or `ix ingest --force` runs.+ * `ix map` skips files whose mtime or source hash is unchanged, which would+ * keep the old extractor's edges on them, so the ingest baseline records this+ * name and a run that finds a different one re-ingests every file once.*/export function extractorName(): string {return `tree-sitter/1.26`;diff --git a/ix-cli/src/cli/__tests__/ingest-baseline-rev.test.ts b/ix-cli/src/cli/__tests__/ingest-baseline-rev.test.tsindex c2ecbcd3..b1ec0dd7 100644--- a/ix-cli/src/cli/__tests__/ingest-baseline-rev.test.ts+++ b/ix-cli/src/cli/__tests__/ingest-baseline-rev.test.ts@@ -6,7 +6,7 @@ import * as os from "node:os";import * as path from "node:path";import { ingestMtimeCachePath } from "../config.js";-import { loadIngestBaseline, saveIngestBaseline } from "../ingest-baseline.js";+import { extractorChanged, loadIngestBaseline, saveIngestBaseline } from "../ingest-baseline.js";import { advanceRev } from "../commands/ingest.js";let home: string;@@ -106,3 +106,28 @@ describe("advanceRev", () => {expect(advanceRev(3, undefined)).toBe(3);});});++describe("ingest baseline extractor", () => {+ const files = new Map<string, number>([["a.ts", 1_000]]);++ it("round-trips the extractor and reads a missing one as null", () => {+ const root = path.join(home, "p");+ saveIngestBaseline(root, files, 1, new Date(), new Map(), "tree-sitter/9.9");+ expect(loadIngestBaseline(root)?.extractor).toBe("tree-sitter/9.9");++ saveIngestBaseline(root, files, 1);+ expect(loadIngestBaseline(root)?.extractor).toBeNull();+ });++ it("counts an unrecorded or different extractor as a change, and no baseline as none", () => {+ const root = path.join(home, "p");+ expect(extractorChanged(null, "tree-sitter/9.9")).toBe(false);++ saveIngestBaseline(root, files, 1, new Date(), new Map(), "tree-sitter/9.9");+ expect(extractorChanged(loadIngestBaseline(root), "tree-sitter/9.9")).toBe(false);+ expect(extractorChanged(loadIngestBaseline(root), "tree-sitter/9.10")).toBe(true);++ saveIngestBaseline(root, files, 1);+ expect(extractorChanged(loadIngestBaseline(root), "tree-sitter/9.9")).toBe(true);+ });+});diff --git a/ix-cli/src/cli/__tests__/ingest-files.test.ts b/ix-cli/src/cli/__tests__/ingest-files.test.tsindex 4545da50..540c7fc9 100644--- a/ix-cli/src/cli/__tests__/ingest-files.test.ts+++ b/ix-cli/src/cli/__tests__/ingest-files.test.ts@@ -3,12 +3,13 @@import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import { createServer, type Server, type ServerResponse } from "node:http";import type { AddressInfo } from "node:net";-import { mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";+import { mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";import { join } from "node:path";import { execFileSync } from "node:child_process";import { ingestFiles } from "../commands/ingest.js";+import { ingestMtimeCachePath } from "../config.js";/*** Integration tests that drive `ingestFiles` end to end against a fake backend.@@ -809,6 +810,47 @@ describe("ingestFiles against a fake backend", () => {expect(message).toContain("30 of 30");});+ it("re-ingests everything once when the baseline names another extractor", async () => {+ // `ix map` skips files by mtime and source hash, and neither sees an+ // extractor bump, so the baseline records the extractor and a change+ // forces one full re-ingest. Asserted through the notice and the stored+ // name: this fake answers no source hashes, so its DB-reset guard makes+ // every incremental run look forced anyway.+ fixture(3);+ const incremental = () =>+ ingestFiles(repo, { format: "text", suppressOutput: true, printSummary: false });+ const stored = () =>+ JSON.parse(readFileSync(ingestMtimeCachePath(repo), "utf8")) as { extractor?: string };+ const notices = (): string[] =>+ stderr.mock.calls.map(([chunk]) => String(chunk)).filter(c => c.includes("[extractor changed]"));+ const stderr = vi.spyOn(process.stderr, "write").mockImplementation(() => true);+ try {+ await incremental();+ const current = stored().extractor;+ expect(current, "a clean run records its extractor").toMatch(/^tree-sitter\//);+ expect(notices(), "a first run has no baseline to compare").toEqual([]);++ writeFileSync(ingestMtimeCachePath(repo), JSON.stringify({ ...stored(), extractor: "tree-sitter/0.1" }));+ await incremental();+ expect(notices()).toEqual([expect.stringContaining(`tree-sitter/0.1 -> ${current}`)]);+ expect(stored().extractor).toBe(current);++ await incremental();+ expect(notices(), "the new name was recorded, so it happens once").toHaveLength(1);++ const { extractor: _dropped, ...unrecorded } = stored();+ writeFileSync(ingestMtimeCachePath(repo), JSON.stringify(unrecorded));+ await incremental();+ expect(notices()[1], "a baseline from before this was recorded").toContain(`unrecorded -> ${current}`);++ writeFileSync(ingestMtimeCachePath(repo), JSON.stringify({ ...stored(), extractor: "tree-sitter/0.1" }));+ await ingestFiles(repo, { format: "text", lang: "typescript", suppressOutput: true, printSummary: false });+ expect(stored().extractor, "a --lang run must not vouch for the other languages").toBe("tree-sitter/0.1");+ } finally {+ stderr.mockRestore();+ }+ });+it("commits a healthy repo in one bulk, with no per-file fan-out", async () => {fixture(12);diff --git a/ix-cli/src/cli/__tests__/stale-workspace.test.ts b/ix-cli/src/cli/__tests__/stale-workspace.test.tsindex 635d4783..a0573888 100644--- a/ix-cli/src/cli/__tests__/stale-workspace.test.ts+++ b/ix-cli/src/cli/__tests__/stale-workspace.test.ts@@ -292,7 +292,7 @@ describe("workspace-scoped staleness", () => {const completedAt = new Date("2026-08-09T18:01:00.000Z");const deletedFiles = new Map([[filePath, ["caller.js"]]]);expect(- persistIngestBaselineIfClean(root, new Map(), 15, 0, 0, completedAt, deletedFiles),+ persistIngestBaselineIfClean(root, new Map(), 15, 0, 0, completedAt, deletedFiles, "tree-sitter/9.9"),).toBe(true);expect(loadIngestBaseline(root)).toEqual({@@ -301,6 +301,7 @@ describe("workspace-scoped staleness", () => {currentRev: 15,lastIngestAt: completedAt.toISOString(),tracksMapBaseline: true,+ extractor: "tree-sitter/9.9",});});diff --git a/ix-cli/src/cli/commands/ingest.ts b/ix-cli/src/cli/commands/ingest.tsindex b4842dd5..9cdb5751 100644--- a/ix-cli/src/cli/commands/ingest.ts+++ b/ix-cli/src/cli/commands/ingest.ts@@ -13,7 +13,7 @@ import chalk from 'chalk';import { IxClient } from '../../client/api.js';import type { GraphPatchPayload } from '../../client/types.js';import { getEndpoint, resolveWorkspaceRoot, clearStitchScopeCache } from '../config.js';-import { isRev, loadIngestBaseline, saveIngestBaseline } from '../ingest-baseline.js';+import { extractorChanged, isRev, loadIngestBaseline, saveIngestBaseline } from '../ingest-baseline.js';import { resolveGitHubToken } from '../github/auth.js';import { parseGitHubRepo, fetchGitHubData } from '../github/fetch.js';import { loadIngestionModules } from './ingestion-loader.js';@@ -881,6 +881,7 @@ export function persistIngestBaselineIfClean(commitErrors: number,now?: Date,deletedFiles: Map<string, string[]> = new Map(),+ extractor?: string | null,): boolean {if (!ingestCompletedCleanly(parseErrors, commitErrors)) return false;// An empty mtime map is normally a discovery failure, not an empty repo —@@ -894,7 +895,7 @@ export function persistIngestBaselineIfClean(// empty is a real state and is persisted; without them, it is still treated// as discovery having gone wrong.if (mtimes.size === 0 && deletedFiles.size === 0) return false;- saveIngestBaseline(projectRoot, mtimes, currentRev, now, deletedFiles);+ saveIngestBaseline(projectRoot, mtimes, currentRev, now, deletedFiles, extractor);return true;}@@ -1433,6 +1434,7 @@ export async function ingestFiles(sourcePatchIdCandidates,fileNodeId,symbolNodeId,+ extractorName,},{ languageFromPath },] = await loadIngestionModules();@@ -1934,6 +1936,18 @@ export async function ingestFiles(// A just-migrated workspace (new path-based id) has no nodes under the new id, so// skip the mtime pre-filter and re-ingest everything, exactly like --force.const previousBaseline = loadIngestBaseline(projectRoot);+ const currentExtractor = extractorName();+ if (!opts.force && extractorChanged(previousBaseline, currentExtractor)) {+ process.stderr.write(+ `\n [extractor changed] ${previousBaseline?.extractor ?? 'unrecorded'} -> ${currentExtractor}. ` ++ `Re-ingesting every file once.\n`,+ );+ opts.force = true;+ }+ // A --lang run re-extracts only its own files, so it must not record the+ // new extractor for the rest; keep the old one and the next full run+ // still re-ingests them.+ const baselineExtractor = opts.lang ? previousBaseline?.extractor : currentExtractor;const previousMtimes = previousBaseline?.files ?? new Map<string, number>();const {previousDeletedFiles,@@ -3279,6 +3293,7 @@ export async function ingestFiles(previousBaseline.currentRev,new Date(previousBaseline.lastIngestAt),durableDeletedFiles,+ previousBaseline.extractor,);},});@@ -3310,6 +3325,7 @@ export async function ingestFiles(commitErrors,undefined,nextDeletedFiles,+ baselineExtractor,);// Migration cleanup (Ix#225 gap 2): the re-ingest under the new path-based id hasdiff --git a/ix-cli/src/cli/commands/ingestion-loader.ts b/ix-cli/src/cli/commands/ingestion-loader.tsindex 0f6760ff..8e12fae7 100644--- a/ix-cli/src/cli/commands/ingestion-loader.ts+++ b/ix-cli/src/cli/commands/ingestion-loader.ts@@ -17,6 +17,7 @@ type PatchBuilderModule = {sourcePatchIdCandidates: (filePath: string, sourceHash: string, workspaceId: string) => string[];fileNodeId: (workspaceId: string, filePath: string) => string;symbolNodeId: (workspaceId: string, filePath: string, qualifiedKey: string) => string;+ extractorName: () => string;};type LanguagesModule = {diff --git a/ix-cli/src/cli/ingest-baseline.ts b/ix-cli/src/cli/ingest-baseline.tsindex cb94fefb..6678571b 100644--- a/ix-cli/src/cli/ingest-baseline.ts+++ b/ix-cli/src/cli/ingest-baseline.ts@@ -11,6 +11,7 @@ interface SerializedIngestBaseline {currentRev?: number;lastIngestAt?: string;tracksMapBaseline?: boolean;+ extractor?: string;}export interface IngestBaseline {@@ -30,6 +31,12 @@ export interface IngestBaseline {* nothing has actually re-evaluated. See `hasCompletedMapFor`.*/tracksMapBaseline: boolean;+ /**+ * The extractor (`extractorName()`) whose output the recorded files carry.+ * Null on a baseline written before this was recorded, which could have been+ * any extractor, so it counts as a change. See `extractorChanged`.+ */+ extractor: string | null;}/**@@ -76,6 +83,7 @@ export function loadIngestBaseline(projectRoot: string): IngestBaseline | null {currentRev,lastIngestAt,tracksMapBaseline: data.tracksMapBaseline === true,+ extractor: typeof data.extractor === "string" ? data.extractor : null,};} catch {return null;@@ -88,6 +96,7 @@ export function saveIngestBaseline(currentRev: number,now: Date = new Date(),deletedFiles: Map<string, string[]> = new Map(),+ extractor?: string | null,): void {try {// Keep the last good rev rather than writing a shape the read side will@@ -110,6 +119,7 @@ export function saveIngestBaseline(// to before the map marker existed. The first ingest after an upgrade// sets it, which is what ends the grandfathering for this workspace.tracksMapBaseline: true,+ ...(extractor ? { extractor } : {}),};fs.mkdirSync(path.dirname(ingestMtimeCachePath(projectRoot)), { recursive: true });fs.writeFileSync(ingestMtimeCachePath(projectRoot), JSON.stringify(data));@@ -117,3 +127,15 @@ export function saveIngestBaseline(// The cache is an optimization and freshness hint. Ingestion itself succeeded.}}++/**+ * Whether the files in `baseline` were extracted by a different extractor.+ *+ * `ix map` skips a file whose mtime or source hash is unchanged, and neither+ * sees an extractor bump, so without this an unchanged file keeps the nodes and+ * edges the old extractor built until it is edited or `--force` runs. No+ * baseline means nothing was skipped anyway, so it is not a change.+ */+export function extractorChanged(baseline: IngestBaseline | null, current: string): boolean {+ return baseline !== null && baseline.extractor !== current;+}