Skip to content

armgit / Ix

Public Imported from GitHub
0

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

fix(map): rerun only after an ingest that got through, under a deadline

KageBinarydaa570d3f449
diff --git a/ix-cli/src/cli/__tests__/map-result-cache.test.ts b/ix-cli/src/cli/__tests__/map-result-cache.test.ts
index 7c783852..6154bdcc 100644
--- a/ix-cli/src/cli/__tests__/map-result-cache.test.ts
+++ b/ix-cli/src/cli/__tests__/map-result-cache.test.ts
@@ -54,6 +54,8 @@ class FakeBackend {
systemId: string | null = null;
/** Run on the next commit request, then cleared. */
onCommit: (() => void) | undefined;
+ /** Answer every commit with a 500, as a backend that is down would. */
+ failCommits = false;
readonly hashes = new Map<string, { workspaceId: string | null; uri: string; hash: string }>();
private readonly patches = new Map<string, unknown[]>();
private server: Server | undefined;
@@ -95,6 +97,7 @@ class FakeBackend {
const hook = this.onCommit;
this.onCommit = undefined;
hook?.();
+ if (this.failCommits) return send(500, { error: "backend unavailable" });
type SentPatch = { patchId?: string; source?: { uri?: string; sourceHash?: string; workspaceId?: string }; intent?: string; ops?: unknown[] };
let patches: SentPatch[] = [];
try {
@@ -207,6 +210,21 @@ describe("ix map reuses an unchanged map", () => {
return { stdout: stdout.join("\n"), stderr: stderr.join("") };
}
+ /** `ix map <repo> --silent` in-process, without asserting on the exit code. */
+ async function runMap(): Promise<void> {
+ const write = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
+ const error = vi.spyOn(console, "error").mockImplementation(() => {});
+ try {
+ const program = new Command();
+ registerMapCommand(program);
+ await program.parseAsync(["node", "ix", "map", repo, "--silent"]);
+ } finally {
+ write.mockRestore();
+ error.mockRestore();
+ rmSync(lockPathForTest(repo), { force: true });
+ }
+ }
+
beforeEach(async () => {
backend = new FakeBackend();
home = realpathSync(mkdtempSync(join(tmpdir(), "ix-mapcache-home-")));
@@ -274,6 +292,25 @@ describe("ix map reuses an unchanged map", () => {
expect(takeMapRerun(repo), "the request was consumed").toBe(false);
});
+ it("a map whose ingest failed does not rerun against the same backend", async () => {
+ // The rerun ran from a finally block whatever had happened: after a
+ // failed ingest it retried a backend just seen to be down, with no
+ // deadline, keeping the lock (and the hook waiting on it) for as long
+ // as that took.
+ backend.failCommits = true;
+ const commits = () => backend.requests.filter(p => p === "/v1/patches/bulk" || p === "/v1/patch").length;
+ await runMap();
+ expect(process.exitCode, "the ingest failed").toBe(1);
+ const oneRun = commits();
+ process.exitCode = undefined;
+ backend.requests.length = 0;
+
+ backend.onCommit = () => requestMapRerun(repo);
+ await runMap();
+ expect(process.exitCode).toBe(1);
+ expect(commits(), "no second ingest after a failed one").toBe(oneRun);
+ });
+
it("a request left before a map starts is satisfied by that map, not rerun", async () => {
requestMapRerun(repo);
await map("--silent");
diff --git a/ix-cli/src/cli/commands/map.ts b/ix-cli/src/cli/commands/map.ts
index d596724e..7f777f48 100644
--- a/ix-cli/src/cli/commands/map.ts
+++ b/ix-cli/src/cli/commands/map.ts
@@ -913,7 +913,6 @@ async function runMapCommand(pathArg: string | undefined, opts: { format: string
// cloud ingestion doesn't require a local Ix backend.
const ingestStart = performance.now();
let localIngest: IngestFilesSummary | undefined;
- held.local = !cloudReady;
if (cloudReady) {
const runner = getRemoteRunner()!; // isCloudReady guarantees non-null
try {
@@ -954,6 +953,9 @@ async function runMapCommand(pathArg: string | undefined, opts: { format: string
process.exitCode = 1;
return;
}
+ // Only a local ingest that got through earns the rerun: after a failed
+ // one the backend was just seen to be down or out of time.
+ held.local = true;
}
const ingestMs = Math.round(performance.now() - ingestStart);
@@ -1141,6 +1143,9 @@ async function rerunIfRequested(root: string, local: boolean, opts: { silent?: b
printSummary: false,
suppressOutput: true,
mapMode: mapModeForIngest(),
+ // Bounded like the run it follows: its own budget, since the first
+ // run's may be all but spent.
+ deadlineSignal: mapDeadlineSignal(),
});
} catch (err: any) {
if (opts.silent !== true && opts.format !== "json" && opts.format !== "llm") {