Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

fix(ingest): report a changed file the backend answers Idempotent

KageBinaryed3b66aa30e0
diff --git a/ix-cli/src/cli/__tests__/ingest-files.test.ts b/ix-cli/src/cli/__tests__/ingest-files.test.ts
index 4ca92700..28b6bd1a 100644
--- a/ix-cli/src/cli/__tests__/ingest-files.test.ts
+++ b/ix-cli/src/cli/__tests__/ingest-files.test.ts
@@ -1,7 +1,7 @@
// Copyright 2026 Ix Infrastructure Inc.
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
-import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync, symlinkSync, utimesSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { execFileSync } from "node:child_process";
@@ -10,6 +10,9 @@ import { ingestFiles } from "../commands/ingest.js";
import { ingestMtimeCachePath, ingestRebuildPath, loadConfig } from "../config.js";
import { workspaceIdForPath } from "../system.js";
import { FakeBackend } from "./helpers/fake-backend.js";
+import { loadIngestBaseline } from "../ingest-baseline.js";
+import { detectStaleFiles } from "../stale.js";
+import { renderStatusLlm } from "../commands/status.js";
/**
* Integration tests that drive `ingestFiles` end to end against a fake backend.
@@ -676,6 +679,109 @@ describe("ingestFiles against a fake backend", () => {
expect(baselineFiles()).toEqual(expect.arrayContaining([join(repo, "src", "m000.ts"), join(repo, "src", "m002.ts")]));
});
+ describe("a changed file the backend answers Idempotent is reported, not marked clean (F-01)", () => {
+ // A revert sends the patch id the backend committed for the original
+ // bytes. The shipped backend replays any id it has seen, so it answers
+ // `Idempotent`, writes nothing, and the graph keeps the edit -- while the
+ // CLI used to count the patch as applied, record the file as clean, and
+ // let `ix status` say the graph was up to date.
+ const incremental = () =>
+ ingestFiles(repo, { format: "text", suppressOutput: true, printSummary: false });
+ const target = () => join(repo, "src", "m003.ts");
+ let tick = Date.now();
+ /** Write and give the file an mtime no earlier write can share. */
+ const write = (text: string) => {
+ writeFileSync(target(), text, "utf8");
+ tick += 10_000;
+ utimesSync(target(), new Date(tick), new Date(tick));
+ execFileSync("git", ["add", "-A"], { cwd: repo, stdio: "ignore" });
+ };
+ const stored = () => loadIngestBaseline(repo)!;
+ let stderr: ReturnType<typeof vi.spyOn>;
+ const warnings = (): string[] =>
+ stderr.mock.calls.map((call: unknown[]) => String(call[0])).filter((c: string) => c.includes("Graph is unverified"));
+
+ beforeEach(() => {
+ fixture(16);
+ stderr = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
+ // Earlier tests in this file end runs that set it.
+ process.exitCode = undefined;
+ });
+ afterEach(() => {
+ stderr.mockRestore();
+ process.exitCode = undefined;
+ });
+
+ const revert = async () => {
+ const original = readFileSync(target(), "utf8");
+ await incremental();
+ write("export function f3(): number { return 33; }\n");
+ await incremental();
+ write(original);
+ backend.resetRequests();
+ return incremental();
+ };
+
+ it("a revert on a backend without BEW-03 is named and stays dirty", async () => {
+ backend.semantics = "legacy";
+
+ const summary = await revert();
+
+ expect(backend.commitCount, "the revert was sent").toBeGreaterThan(0);
+ expect(summary.replayedChanges).toEqual(["src/m003.ts"]);
+ expect(warnings().join("")).toContain("src/m003.ts");
+ expect(process.exitCode, "a warning, not a failure").not.toBe(1);
+ expect(stored().replayedFiles).toEqual(["src/m003.ts"]);
+ expect(stored().files.get(target()), "kept dirty for the next run").not.toBe(statSync(target()).mtimeMs);
+
+ const status = detectStaleFiles(repo);
+ expect(status.replayedFiles).toEqual(["src/m003.ts"]);
+ expect(renderStatusLlm("ok", "x", status)[0]).toContain("stale=true");
+
+ // The next run tries again rather than calling the file unchanged.
+ backend.resetRequests();
+ const next = await incremental();
+ expect(next.filesSkippedAsUnchanged).toBe(15);
+ expect(next.replayedChanges).toEqual(["src/m003.ts"]);
+ });
+
+ it("a revert on a backend with BEW-03 is applied and nothing is reported", async () => {
+ backend.semantics = "head";
+
+ const summary = await revert();
+
+ expect(summary.replayedChanges).toEqual([]);
+ expect(warnings()).toEqual([]);
+ expect(stored().replayedFiles).toEqual([]);
+ expect(stored().files.get(target())).toBe(statSync(target()).mtimeMs);
+ });
+
+ it("a restored file on a backend without BEW-03 is named", async () => {
+ backend.semantics = "legacy";
+ const original = readFileSync(target(), "utf8");
+ await incremental();
+ rmSync(target());
+ execFileSync("git", ["add", "-A"], { cwd: repo, stdio: "ignore" });
+ await incremental();
+ write(original);
+
+ const summary = await incremental();
+
+ expect(summary.replayedChanges).toEqual(["src/m003.ts"]);
+ });
+
+ it("an unchanged file answered Idempotent is not reported", async () => {
+ // --force re-sends every file; replays of unchanged content are fine.
+ backend.semantics = "legacy";
+ await incremental();
+
+ const summary = await ingestFiles(repo, { format: "text", force: true, suppressOutput: true, printSummary: false });
+
+ expect(summary.idempotentPatches).toBeGreaterThan(0);
+ expect(summary.replayedChanges).toEqual([]);
+ });
+ });
+
it("ingests only the languages --lang names, and keeps the rest of the baseline", async () => {
fixture(3);
writeFileSync(join(repo, "src", "tool.py"), "def tool():\n return 1\n", "utf8");
diff --git a/ix-cli/src/cli/__tests__/stale-workspace.test.ts b/ix-cli/src/cli/__tests__/stale-workspace.test.ts
index 97f853a3..0d931555 100644
--- a/ix-cli/src/cli/__tests__/stale-workspace.test.ts
+++ b/ix-cli/src/cli/__tests__/stale-workspace.test.ts
@@ -76,6 +76,7 @@ describe("workspace-scoped staleness", () => {
currentRev: 11,
staleFiles: 1,
sampleChangedFiles: ["a.js"],
+ replayedFiles: [],
});
expect(
@@ -139,6 +140,7 @@ describe("workspace-scoped staleness", () => {
currentRev: 0,
staleFiles: 0,
sampleChangedFiles: [],
+ replayedFiles: [],
});
// The workspace is unverified, but no individual file is known to have
// changed — the distinction this pair of assertions exists to pin down.
@@ -200,6 +202,7 @@ describe("workspace-scoped staleness", () => {
currentRev: 26,
staleFiles: 0,
sampleChangedFiles: [],
+ replayedFiles: [],
});
});
@@ -272,6 +275,7 @@ describe("workspace-scoped staleness", () => {
currentRev: 14,
staleFiles: 1,
sampleChangedFiles: ["deleted.js"],
+ replayedFiles: [],
});
// From inside the workspace, as a read runs. The probe resolves the active
// root from cwd, and a repository cwd now outranks `default: true` (see
@@ -312,6 +316,7 @@ describe("workspace-scoped staleness", () => {
lastIngestAt: completedAt.toISOString(),
tracksMapBaseline: true,
extractor: "tree-sitter/9.9",
+ replayedFiles: [],
});
});
diff --git a/ix-cli/src/cli/commands/ingest.ts b/ix-cli/src/cli/commands/ingest.ts
index 47f9ff07..9551fb0f 100644
--- a/ix-cli/src/cli/commands/ingest.ts
+++ b/ix-cli/src/cli/commands/ingest.ts
@@ -51,6 +51,7 @@ import {
transformCommit,
} from '../github/transform.js';
import { printJson } from '../format.js';
+import { describeReplayedChanges } from '../graph-health.js';
// ---------------------------------------------------------------------------
// File discovery
// ---------------------------------------------------------------------------
@@ -936,6 +937,28 @@ export function carryForwardMtimes(
return out;
}
+/**
+ * The mtimes to record, with each of `retried` back at its previous mtime --
+ * or left out when it had none -- so the next run sees it as changed and sends
+ * it again. For files whose patch this run could not get applied (F-01): a
+ * deleted file comes back too, which is what makes the next run find it
+ * deleted again.
+ */
+export function retryOnNextRun(
+ mtimes: Map<string, number>,
+ previousMtimes: Map<string, number>,
+ retried: readonly string[],
+): Map<string, number> {
+ if (retried.length === 0) return mtimes;
+ const out = new Map(mtimes);
+ for (const filePath of retried) {
+ const previous = previousMtimes.get(filePath);
+ if (previous === undefined) out.delete(filePath);
+ else out.set(filePath, previous);
+ }
+ return out;
+}
+
export function persistIngestBaselineIfClean(
projectRoot: string,
mtimes: Map<string, number>,
@@ -945,6 +968,7 @@ export function persistIngestBaselineIfClean(
now?: Date,
deletedFiles: Map<string, string[]> = new Map(),
extractor?: string | null,
+ replayedFiles: readonly string[] = [],
): boolean {
if (!ingestCompletedCleanly(parseErrors, commitErrors)) return false;
// An empty mtime map is normally a discovery failure, not an empty repo —
@@ -958,7 +982,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, extractor);
+ saveIngestBaseline(projectRoot, mtimes, currentRev, now, deletedFiles, extractor, replayedFiles);
return true;
}
@@ -1065,6 +1089,17 @@ export interface IngestFilesSummary {
* sign that nothing needed to be (#527).
*/
idempotentPatches: number;
+ /**
+ * Changed files whose patch the backend answered `Idempotent` (F-01), by
+ * workspace-relative path. Unlike the rest of `idempotentPatches`, these
+ * are not harmless: the file differs from what the backend last recorded
+ * for it, yet its patch id was committed before -- a file reverted to
+ * earlier bytes, or deleted and restored -- so the backend wrote nothing and
+ * the graph still shows the content in between. Not counted as errors and
+ * not in the exit code; the run warns, and the baseline keeps these files
+ * dirty so the next run sends them again.
+ */
+ replayedChanges: string[];
/**
* Files this run skipped because they were already unchanged — mtime-clean
* against the local baseline, or hash-clean against the backend.
@@ -1833,6 +1868,8 @@ export async function ingestFiles(
let filesChanged = 0;
let patchesApplied = 0;
let idempotentPatches = 0;
+ /** Workspace-relative paths of changed files the backend answered `Idempotent` (F-01). */
+ const replayedChanges = new Set<string>();
// What `graphUnchanged` is computed from, beside the counters above. Each is
// a way this run can have written to the graph, or have found it not where
// the last run left it, without a patch being counted.
@@ -2284,13 +2321,49 @@ export async function ingestFiles(
patch: GraphPatchPayload;
fileNumber: number;
filePath: string;
+ /**
+ * The graph should change when this lands: the backend held a different
+ * hash for the file, it is a deletion, or it was forced (a restored file
+ * and its dependents). Such a patch answered `Idempotent` wrote nothing
+ * the graph needed -- see `settleCommitted`.
+ */
+ changed: boolean;
};
const makePreparedPatch = (
patch: GraphPatchPayload,
fileNumber: number,
filePath: string,
- ): PreparedPatch => ({ patch, fileNumber, filePath });
+ changed: boolean,
+ ): PreparedPatch => ({ patch, fileNumber, filePath, changed });
+
+ let forcedRelativePaths: Set<string> | undefined;
+ /** Whether a workspace-relative path was forced this run. Built on first use, once the set is final. */
+ const isForced = (relFilePath: string): boolean =>
+ (forcedRelativePaths ??= new Set([...forceReingestPaths].map(toWorkspaceRelative))).has(relFilePath);
+
+ /**
+ * Record a patch the backend took, or one it only claims to hold.
+ *
+ * A changed file answered `Idempotent` is a replay of a patch id the backend
+ * committed before: a file reverted to earlier bytes, or deleted and
+ * restored. The backend wrote nothing, so the graph still shows the content
+ * in between (F-01). Such a patch is counted in `replayedChanges`, named in
+ * the summary, and kept away from `onCommitted`, and its file keeps its old
+ * mtime in the baseline so the next run tries again.
+ */
+ const settleCommitted = (
+ item: PreparedPatch,
+ rev: number,
+ replay: boolean,
+ onCommitted?: (item: PreparedPatch, rev: number) => void,
+ ): void => {
+ if (replay && item.changed) {
+ replayedChanges.add(item.filePath);
+ return;
+ }
+ onCommitted?.(item, rev);
+ };
// Commit HTTP batches in parallel (COMMIT_CONCURRENCY workers). Each worker pulls
// the next unsent chunk from a shared queue. JS is single-threaded so the queue
@@ -2488,7 +2561,7 @@ export async function ingestFiles(
patchesTheBackendTook++;
commitBreaker.recordSuccess();
if (result.status === COMMIT_STATUS_IDEMPOTENT) idempotentPatches++;
- opts?.onCommitted?.(item, result.rev);
+ settleCommitted(item, result.rev, result.status === COMMIT_STATUS_IDEMPOTENT, opts?.onCommitted);
} catch (commitErr) {
// Counted apart from parseErrors: a patch that parsed fine and
// failed to commit means the graph is now behind the working
@@ -2667,7 +2740,9 @@ export async function ingestFiles(
// `idempotentPatches: 0` and fall back to the language hypothesis
// this change exists to retire.
if (result.status === COMMIT_STATUS_IDEMPOTENT) idempotentPatches += chunk.length;
- for (const item of chunk) opts?.onCommitted?.(item, result.rev);
+ for (const item of chunk) {
+ settleCommitted(item, result.rev, result.status === COMMIT_STATUS_IDEMPOTENT, opts?.onCommitted);
+ }
if (debug) process.stderr.write(` [cutoff] bulk placed ${chunk.length} of ${items.length} held
`);
probeQueue = rest;
@@ -2697,7 +2772,8 @@ export async function ingestFiles(
// `latestRev` rather than a rev of its own: the server holds
// these already, so their rev is at or below it, and
// `saveIngestBaseline` floors what it stores anyway.
- for (const item of landed) opts?.onCommitted?.(item, latestRev);
+ // A replay by definition: the server already held these ids.
+ for (const item of landed) settleCommitted(item, latestRev, true, opts?.onCommitted);
// NOT `patchesTheBackendTook`. That counter's whole reason for
// existing is to keep 409-sourced counts from reopening a gate
// closed against a dead backend -- "counted only where a
@@ -2851,7 +2927,9 @@ export async function ingestFiles(
// One status covers the whole bulk: the backend commits the chunk
// as a unit, so `Idempotent` means every patch in it was a replay.
if (result.status === COMMIT_STATUS_IDEMPOTENT) idempotentPatches += items.length;
- for (const item of items) opts?.onCommitted?.(item, result.rev);
+ for (const item of items) {
+ settleCommitted(item, result.rev, result.status === COMMIT_STATUS_IDEMPOTENT, opts?.onCommitted);
+ }
},
commitIndividually,
shouldStop: () => commitBreaker.tripped(),
@@ -3032,7 +3110,7 @@ export async function ingestFiles(
if (mapMode) patch = stripMapModeOps(patch);
// source.uri (workspace-relative) and source.workspaceId are set
// inside buildPatch; the backend stores both as opaque attributes.
- preparedPatches.push(makePreparedPatch(patch, j + 1, p.filePath));
+ preparedPatches.push(makePreparedPatch(patch, j + 1, p.filePath, previousHash !== undefined || isForced(p.filePath)));
} catch (err) {
parseErrors++;
process.stderr.write(`\n [patch build error] ${p.filePath}: ${err}\n`);
@@ -3110,7 +3188,7 @@ export async function ingestFiles(
}
if (mapMode) patch = stripMapModeOps(patch);
// source.uri and source.workspaceId are set inside buildPatch (see flushBatch).
- preparedPatches.push(makePreparedPatch(patch, j + 1, p.filePath));
+ preparedPatches.push(makePreparedPatch(patch, j + 1, p.filePath, previousHash !== undefined || isForced(p.filePath)));
} catch (err) {
parseErrors++;
process.stderr.write(`\n [patch build error] ${p.filePath}: ${err}\n`);
@@ -3468,7 +3546,7 @@ export async function ingestFiles(
mapMode,
);
if (mapMode) patch = stripMapModeOps(patch);
- deletedPatches.push(makePreparedPatch(patch, i + 1, relFilePath));
+ deletedPatches.push(makePreparedPatch(patch, i + 1, relFilePath, true));
const dependents = [...dependentSourceUris].sort();
nextDeletedFiles.set(absFilePath, dependents);
pendingDeletionRecovery.set(relFilePath, {
@@ -3497,6 +3575,7 @@ export async function ingestFiles(
new Date(previousBaseline.lastIngestAt),
durableDeletedFiles,
previousBaseline.extractor,
+ previousBaseline.replayedFiles,
);
},
});
@@ -3522,9 +3601,28 @@ export async function ingestFiles(
// writes none -- one written from a part of the workspace would mark the
// whole graph complete.
const outOfScope = scopedRun ? [...previousMtimes.keys()].filter(fp => !inScope(fp)) : [];
+ // Replayed changes keep their previous mtime, so the next run sends them
+ // again. Patches name files workspace-relative; the baseline is keyed by
+ // absolute path, deleted files included.
+ const absoluteFor = new Map(
+ [...previousMtimes.keys(), ...currentMtimes.keys()].map(abs => [toWorkspaceRelative(abs), abs]),
+ );
+ const replayedAbsolute = [...replayedChanges].flatMap(rel => absoluteFor.get(rel) ?? []);
+ // A run that did not look at a file has not resolved its replay.
+ const replayedFiles = [
+ ...replayedChanges,
+ ...(previousBaseline?.replayedFiles ?? []).filter(rel => {
+ const abs = absoluteFor.get(rel);
+ return abs !== undefined && (!inScope(abs) || langExcluded.includes(abs));
+ }),
+ ];
const baselinePersisted = (scopedRun && !previousBaseline) ? false : persistIngestBaselineIfClean(
projectRoot,
- carryForwardMtimes(currentMtimes, previousMtimes, [...deferredDeletions, ...langExcluded, ...outOfScope]),
+ retryOnNextRun(
+ carryForwardMtimes(currentMtimes, previousMtimes, [...deferredDeletions, ...langExcluded, ...outOfScope]),
+ previousMtimes,
+ replayedAbsolute,
+ ),
latestRev,
// Lost parses count as parse errors HERE, whatever they are called
// elsewhere. A run whose worker pool died resolves every later file as
@@ -3539,6 +3637,7 @@ export async function ingestFiles(
scopedRun && previousBaseline ? new Date(previousBaseline.lastIngestAt) : undefined,
nextDeletedFiles,
baselineExtractor,
+ replayedFiles,
);
if (rebuildProgress !== null) {
// Finished: the baseline now records the new extractor. Otherwise keep
@@ -3787,6 +3886,7 @@ export async function ingestFiles(
filesDiscovered,
patchesApplied,
idempotentPatches,
+ replayedChanges: [...replayedChanges].sort(),
filesSkippedAsUnchanged,
// `+ crashedParses()`, as the baseline and delete guards already do. Files
// lost to a dead parse pool raise `filesSkippedUnparsed`, never
@@ -3849,6 +3949,10 @@ export async function ingestFiles(
// reads as an unexplained regression without the reason.
process.stderr.write(` ${describeStitchSkipped(stitchSkipped, stitchSkippedRule, debug)}\n`);
}
+ if (replayedChanges.size > 0) {
+ // stderr and exit 0: nothing failed on this side, and the next run retries.
+ process.stderr.write(` ${describeReplayedChanges(summary.replayedChanges)}\n`);
+ }
if (commitReport.kind === "warn") {
process.stderr.write(` ${commitReport.message}\n`);
// Non-zero even though we do not throw. A partial failure still means the
@@ -3873,6 +3977,7 @@ export async function ingestFiles(
patchesApplied,
filesSkipped,
idempotentPatches,
+ replayedChanges: summary.replayedChanges,
entitiesParsed,
latestRev,
// `unchanged` is the files we ASSUMED unchanged, not every skip. It used
@@ -3934,6 +4039,7 @@ export async function ingestFiles(
const parseErrorsShown = parseErrors + crashedParses();
if (parseErrorsShown > 0) console.log(` ${chalk.red('parse errors:')} ${parseErrorsShown}`);
if (commitErrors > 0) console.log(` ${chalk.red('commit errors:')} ${commitErrors}`);
+ if (replayedChanges.size > 0) console.log(` ${chalk.yellow('not applied:')} ${replayedChanges.size} ${chalk.dim('(see the warning above)')}`);
if (tooLarge > 0) console.log(` ${chalk.dim('skipped too large:')} ${tooLarge}`);
if (minifiedLikely > 0) console.log(` ${chalk.dim('skipped minified:')} ${minifiedLikely}`);
// Not dimmed like the others: these were dropped because the repo pointed
diff --git a/ix-cli/src/cli/commands/map.ts b/ix-cli/src/cli/commands/map.ts
index 78ca3aea..8f07df56 100644
--- a/ix-cli/src/cli/commands/map.ts
+++ b/ix-cli/src/cli/commands/map.ts
@@ -207,7 +207,10 @@ export function describeEmptyCompletedMap(
// backend cannot build a hierarchy for skips its 99 clean files, and one
// reverted file whose content was ingested before commits as `Idempotent` —
// giving patches === 1, idempotentPatches === 1, file_count === 0 with a
- // graph that is perfectly intact and a 24-hour wait that changes nothing.
+ // graph that is not empty, and a 24-hour wait that changes nothing here. That
+ // graph is not intact either: the revert was never applied, so it still
+ // shows the file's content in between. The ingest reports that one itself,
+ // as `replayedChanges` (F-01).
// A real #527 run skips nothing: the DB-reset guard clears the mtime cache
// and the hash lookup comes back empty, so every file is re-submitted.
if (patches > 0 && ingest.idempotentPatches >= patches && ingest.filesSkippedAsUnchanged === 0) {
diff --git a/ix-cli/src/cli/commands/status.ts b/ix-cli/src/cli/commands/status.ts
index 70a6b5cf..752042c8 100644
--- a/ix-cli/src/cli/commands/status.ts
+++ b/ix-cli/src/cli/commands/status.ts
@@ -9,6 +9,7 @@ import { detectStaleFiles } from "../stale.js";
import { llmError, llmLine, printLlmLines } from "../llm.js";
import { backendUnreachableError, isBackendUnreachable } from "../errors.js";
import { printJson } from "../format.js";
+import { describeReplayedChanges } from "../graph-health.js";
interface StatusStaleInfo {
graphCompleted: boolean;
@@ -17,6 +18,8 @@ interface StatusStaleInfo {
lastIngestAt: string | null;
staleFiles: number;
sampleChangedFiles: string[];
+ /** Changed files the last run could not get applied (F-01); see `IngestBaseline.replayedFiles`. */
+ replayedFiles?: string[];
}
/**
@@ -43,11 +46,17 @@ export function renderStatusLlm(
["rev", staleInfo ? String(staleInfo.currentRev) : null],
["last_ingest_at", staleInfo?.lastIngestAt ?? null],
["stale_files", staleInfo ? String(staleInfo.staleFiles) : null],
- ["stale", staleInfo ? (!staleInfo.graphCompleted || staleInfo.staleFiles > 0 ? "true" : "false") : null],
+ ["not_applied", staleInfo ? String(staleInfo.replayedFiles?.length ?? 0) : null],
+ ["stale", staleInfo
+ ? (!staleInfo.graphCompleted || staleInfo.staleFiles > 0 || (staleInfo.replayedFiles?.length ?? 0) > 0 ? "true" : "false")
+ : null],
])];
for (const f of staleInfo?.sampleChangedFiles ?? []) {
lines.push(llmLine("changed", [["path", f]]));
}
+ for (const f of staleInfo?.replayedFiles ?? []) {
+ lines.push(llmLine("not_applied", [["path", f]]));
+ }
return lines;
}
@@ -82,6 +91,7 @@ export function registerStatusCommand(program: Command): void {
lastIngestAt: staleInfo?.lastIngestAt ?? null,
staleFiles: staleInfo?.staleFiles ?? 0,
sampleChangedFiles: staleInfo?.sampleChangedFiles ?? [],
+ replayedFiles: staleInfo?.replayedFiles ?? [],
};
printJson(result);
} else {
@@ -97,6 +107,10 @@ export function registerStatusCommand(program: Command): void {
if (!staleInfo.graphCompleted) {
renderWarning("No completed source graph ingest is recorded for this workspace.");
renderNote("Run ix map to build a trustworthy graph.");
+ } else if ((staleInfo.replayedFiles?.length ?? 0) > 0) {
+ // Ahead of the stale-file check: a restored file can look current
+ // by mtime while the graph still holds the content in between.
+ renderWarning(describeReplayedChanges(staleInfo.replayedFiles!));
} else if (staleInfo.staleFiles > 0) {
renderWarning(`${staleInfo.staleFiles} file(s) changed since last ingest:`);
for (const f of staleInfo.sampleChangedFiles) {
diff --git a/ix-cli/src/cli/graph-health.ts b/ix-cli/src/cli/graph-health.ts
index 61a73e70..9318dbdb 100644
--- a/ix-cli/src/cli/graph-health.ts
+++ b/ix-cli/src/cli/graph-health.ts
@@ -73,6 +73,22 @@ export const GRAPH_REBUILD_FIX = "ix reset --workspace --yes --ingest";
/** For a registered workspace the backend holds nothing for. */
export const GRAPH_MAP_FIX = "ix map";
+/**
+ * The warning for changed files the backend answered `Idempotent` (F-01): it
+ * had committed their patch id before -- a file reverted to earlier bytes, or
+ * deleted and restored -- so it wrote nothing, and the graph still shows the
+ * content in between. Shared by `ix map` and `ix status`.
+ */
+export function describeReplayedChanges(files: readonly string[], sample = 5): string {
+ const shown = files.slice(0, sample).join(", ");
+ const more = files.length > sample ? ` and ${files.length - sample} more` : "";
+ return (
+ `Graph is unverified: ${files.length} changed file(s) were not applied: ${shown}${more}. ` +
+ "The backend already held their patch (a revert, or a restored file) and wrote nothing. " +
+ `The next ix map sends them again; if this persists, rebuild with: ${GRAPH_REBUILD_FIX}`
+ );
+}
+
const STRUCTURAL_PREDICATES = new Set(["CONTAINS", "DEFINES", "CONTAINS_CHUNK"]);
/** Below this many symbols the coverage ratio is too noisy to judge by. */
diff --git a/ix-cli/src/cli/ingest-baseline.ts b/ix-cli/src/cli/ingest-baseline.ts
index 1ebd529d..d44e4d8a 100644
--- a/ix-cli/src/cli/ingest-baseline.ts
+++ b/ix-cli/src/cli/ingest-baseline.ts
@@ -12,6 +12,7 @@ interface SerializedIngestBaseline {
lastIngestAt?: string;
tracksMapBaseline?: boolean;
extractor?: string;
+ replayedFiles?: string[];
}
export interface IngestBaseline {
@@ -37,6 +38,14 @@ export interface IngestBaseline {
* any extractor, so it counts as a change. See `extractorChanged`.
*/
extractor: string | null;
+ /**
+ * Workspace-relative paths of changed files the last run sent and the
+ * backend answered `Idempotent`: it already held that patch id and wrote
+ * nothing, so the graph does not show these files as they are (F-01, a
+ * revert or a restore). Empty when every change was applied. Their mtimes
+ * are kept at the previous value, so the next run sends them again.
+ */
+ replayedFiles: string[];
}
/**
@@ -84,6 +93,9 @@ export function loadIngestBaseline(projectRoot: string): IngestBaseline | null {
lastIngestAt,
tracksMapBaseline: data.tracksMapBaseline === true,
extractor: typeof data.extractor === "string" ? data.extractor : null,
+ replayedFiles: Array.isArray(data.replayedFiles)
+ ? data.replayedFiles.filter((p): p is string => typeof p === "string")
+ : [],
};
} catch {
return null;
@@ -97,6 +109,7 @@ export function saveIngestBaseline(
now: Date = new Date(),
deletedFiles: Map<string, string[]> = new Map(),
extractor?: string | null,
+ replayedFiles: readonly string[] = [],
): void {
try {
// Keep the last good rev rather than writing a shape the read side will
@@ -120,6 +133,7 @@ export function saveIngestBaseline(
// sets it, which is what ends the grandfathering for this workspace.
tracksMapBaseline: true,
...(extractor ? { extractor } : {}),
+ ...(replayedFiles.length > 0 ? { replayedFiles: [...replayedFiles].sort() } : {}),
};
fs.mkdirSync(path.dirname(ingestMtimeCachePath(projectRoot)), { recursive: true });
fs.writeFileSync(ingestMtimeCachePath(projectRoot), JSON.stringify(data));
diff --git a/ix-cli/src/cli/stale.ts b/ix-cli/src/cli/stale.ts
index 33bdd7fa..c787efaf 100644
--- a/ix-cli/src/cli/stale.ts
+++ b/ix-cli/src/cli/stale.ts
@@ -14,6 +14,8 @@ export interface StaleInfo {
currentRev: number;
staleFiles: number;
sampleChangedFiles: string[];
+ /** Changed files the last run could not get applied (F-01); see `IngestBaseline.replayedFiles`. */
+ replayedFiles: string[];
}
const SUPPORTED_NAMES = new Set([
@@ -101,6 +103,7 @@ export function detectStaleFiles(
currentRev: 0,
staleFiles: 0,
sampleChangedFiles: [],
+ replayedFiles: [],
};
}
@@ -139,6 +142,7 @@ export function detectStaleFiles(
currentRev: baseline.currentRev,
staleFiles: changedFiles.length,
sampleChangedFiles: changedFiles.slice(0, maxSamples),
+ replayedFiles: baseline.replayedFiles,
};
}