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): keep the failure reason when the cap fired before the throw
KageBinary1f49d9fe3eb7
diff --git a/ix-cli/src/cli/__tests__/mcp-runner.test.ts b/ix-cli/src/cli/__tests__/mcp-runner.test.tsindex 05eb78fe..381b0f82 100644--- a/ix-cli/src/cli/__tests__/mcp-runner.test.ts+++ b/ix-cli/src/cli/__tests__/mcp-runner.test.ts@@ -436,6 +436,29 @@ describe("in-process ix runner", () => {expect(result.stderr).not.toContain("E".repeat(500));});+ it("keeps the failure reason when the cap already fired before the throw", async () => {+ // Routing thrown text through appendChunk means it is dropped outright once+ // the cap has fired, so a crash reaches the client as nothing but "output+ // exceeded N bytes" — exactly when an operator most needs the reason.+ const run = createInProcessRunner({+ maxOutputBytes: 500,+ createProgram: () => {+ const program = new Command();+ program.command("flood-then-throw").action(() => {+ for (let i = 0; i < 20; i += 1) console.log("x".repeat(100));+ throw new Error("backend refused the connection");+ });+ return program;+ },+ });++ const result = await run(["flood-then-throw"]);++ expect(result.ok).toBe(false);+ expect(result.stderr).toContain("exceeded 500 bytes and was truncated");+ expect(result.stderr).toContain("backend refused the connection");+ });+it("reports an unknown command as a failure with commander's message", async () => {const run = testRunner();diff --git a/ix-cli/src/mcp/runner.ts b/ix-cli/src/mcp/runner.tsindex 7f850539..3023ed84 100644--- a/ix-cli/src/mcp/runner.ts+++ b/ix-cli/src/mcp/runner.ts@@ -26,6 +26,9 @@ export const DEFAULT_TIMEOUT_MS = 30_000;*/const MAX_OUTPUT_BYTES = 16 * 1024 * 1024;+/** How much of a thrown error's text to keep once the output cap has fired. */+const FAILURE_DETAIL_CHARS = 2 * 1024;+export interface IxRunResult {ok: boolean;stdout: string;@@ -422,7 +425,16 @@ async function executeInProcess(} finally {commandExitCode = commandExitCode ?? (exitCodeIsOurs ? process.exitCode : undefined);process.exitCode = callerExitCode;- if (failure !== null) appendChunk(run, "stderr", failure);+ if (failure !== null) {+ if (run.truncated) {+ // appendChunk is a no-op once the cap has fired, but *why* the command+ // threw is the one thing an operator still needs — otherwise a crash is+ // reported as nothing but "output exceeded N bytes". Keep a bounded copy.+ run.stderr.push(`\n[ix mcp] command failed: ${failure.slice(0, FAILURE_DETAIL_CHARS)}\n`);+ } else {+ appendChunk(run, "stderr", failure);+ }+ }run.closed = true;activeRun = null;