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(mcp): clear queued resolution notices before each in-process command
KageBinaryd5a747741ed5
diff --git a/ix-cli/src/cli/__tests__/mcp-runner.test.ts b/ix-cli/src/cli/__tests__/mcp-runner.test.tsindex 7c9a07ec..7bf7172b 100644--- a/ix-cli/src/cli/__tests__/mcp-runner.test.ts+++ b/ix-cli/src/cli/__tests__/mcp-runner.test.ts@@ -7,6 +7,7 @@ import { join } from "node:path";import { Command } from "commander";import { afterEach, describe, expect, it, vi } from "vitest";+import { noteResolutionNotices, printJson } from "../format.js";import { acquireMapLock, lockPathForTest } from "../single-flight.js";import { createInProcessRunner, resolveDefaultRunner, runCurrentIx } from "../../mcp/runner.js";@@ -96,6 +97,15 @@ function createTestProgram(): Command {program.command("ingest").action(() => console.log("ingested"));+ // A json command whose target resolved with a notice, then failed before it+ // printed (a backend error after resolution).+ program.command("resolve-then-fail").action(() => {+ noteResolutionNotices([{ code: "fuzzy_match", target: "Old" }]);+ throw new Error("backend went away");+ });++ program.command("emit-json").action(() => printJson({ ok: true }));+// Never settles: a hung backend call, or a rejection that used to end the// process and is now only logged by the server's error handlers.program.command("hang").action(async () => {@@ -188,6 +198,15 @@ describe("in-process ix runner", () => {expect(process.exitCode).toBeUndefined();});+ it("does not hand one command's resolution notices to the next json call", async () => {+ const run = testRunner();++ expect((await run(["resolve-then-fail"])).ok).toBe(false);+ const next = await run(["emit-json"]);++ expect(JSON.parse(next.stdout)).toEqual({ ok: true });+ });+it("does not leak option values from one run into the next", async () => {const run = testRunner();diff --git a/ix-cli/src/cli/format.ts b/ix-cli/src/cli/format.tsindex 57c78324..6a7c018a 100644--- a/ix-cli/src/cli/format.ts+++ b/ix-cli/src/cli/format.ts@@ -42,9 +42,10 @@ function jsonIndent(): number | undefined {/*** Notices about a guessed target (`ambiguous_target`, `fuzzy_match`) waiting for- * the command's own json object. Per process: `ix mcp` runs every command as a- * subprocess, so nothing outlives one command. Tests that call a command- * in-process should call `resetResolutionNotices` between cases.+ * the command's own json object. Module state: `ix mcp` runs commands in this+ * process by default (see mcp/runner.ts), so its runner calls+ * `resetResolutionNotices` before each command, and so should tests that call a+ * command in-process.*/let pendingResolutionNotices: unknown[] = [];diff --git a/ix-cli/src/mcp/runner.ts b/ix-cli/src/mcp/runner.tsindex 37e08458..31fefec7 100644--- a/ix-cli/src/mcp/runner.ts+++ b/ix-cli/src/mcp/runner.ts@@ -12,6 +12,7 @@ import { Command, CommanderError } from "commander";import { registerOssCommands, registerProStubs } from "../cli/register/oss.js";import { tryLoadProCommands } from "../cli/register/pro-loader.js";+import { resetResolutionNotices } from "../cli/format.js";import { resetReadScope } from "../cli/resolve.js";import { releaseLocksOwnedBy, setLockOwnerResolver } from "../cli/single-flight.js";import { IX_CALLER_ENV } from "../cli/next-step.js";@@ -407,6 +408,11 @@ async function executeInProcess(abortSettleMs: number = ABORT_SETTLE_MS,): Promise<IxRunResult> {const program = throwOnUsageError(await createProgram(version));+ // Resolution notices wait in module state for the command's printJson. A+ // command that queued some and then failed before printing (a backend error+ // or a timeout after its target resolved) would otherwise hand them to the+ // next json call, attached to a different command's answer.+ resetResolutionNotices();const run: ActiveRun = {stdout: [],stderr: [],