diff --git a/src/ida/IdaSessionClient.test.ts b/src/ida/IdaSessionClient.test.ts index 083cb14574..2cab179f18 100644 --- a/src/ida/IdaSessionClient.test.ts +++ b/src/ida/IdaSessionClient.test.ts @@ -2241,3 +2241,22 @@ describe("headless IDA literal string predicate pushdown", () => { } }); }); + +describe("headless IDA open rejection", () => { + it("reports an idb_open rejection with its upstream reason", async () => { + const { producer, client } = await fixture("headless"); + producer.overrideCall = (name) => + name === "idb_open" + ? { error: "Input was rejected before creating a session" } + : undefined; + + const result = await client.execute("health", {}); + expect(result.ok).toBe(false); + if (result.ok) return; + expect(result.error.message).toContain( + "Input was rejected before creating a session", + ); + expect(result.error.message).not.toContain("malformed or unsupported"); + expect((await client.close()).ok).toBe(true); + }); +}); diff --git a/src/ida/IdaSessionClient.ts b/src/ida/IdaSessionClient.ts index 3f654bb952..a596541a01 100644 --- a/src/ida/IdaSessionClient.ts +++ b/src/ida/IdaSessionClient.ts @@ -800,10 +800,19 @@ export class IdaSessionClient implements AnalysisClient { init_hexrays: true, preferred_session_id: workspace.sessionId, }); - this.#openOutcome = rejectedOpenDatabaseSchema.safeParse(raw).success - ? "no_worker" - : "reply_received"; + const rejected = rejectedOpenDatabaseSchema.safeParse(raw); + this.#openOutcome = rejected.success ? "no_worker" : "reply_received"; this.#lifecycle.push(raw); + // The supervisor reports any open failure as `{ error }` rather than an + // MCP tool error; keep its reason instead of reading it as malformed data. + if (rejected.success) { + const diagnostic = createIdaDiagnosticRedactor(this.config); + const reason = diagnostic.blocks([rejected.data.error]); + throw new IdaToolRejection( + diagnostic.message("IDA MCP tool failed: ", reason), + { diagnostics: { reason } }, + ); + } const opened = openDatabaseSchema.parse(raw); if (!sameIdaHostPath(opened.session.input_path, workspace.inputPath)) throw new IdaIdentityRefusal(