diff --git a/src/ida/IdaConfiguration.ts b/src/ida/IdaConfiguration.ts index 78653d15c1..12ff633aab 100644 --- a/src/ida/IdaConfiguration.ts +++ b/src/ida/IdaConfiguration.ts @@ -355,6 +355,18 @@ export const idaRegistrationTimeoutGuidance = ( remediationAction: `Set timeoutMs in the JSON file named by REA_IDA_MCP_CONFIG to an integer from 1 to ${String(MAX_NODE_TIMER_DELAY_MS)} (omitted means ${String(DEFAULT_IDA_REQUEST_TIMEOUT_MS)}). REA applies the edited file on the next IDA connection after it re-reads the registration; an already open session keeps the timeout it connected with. Allow execution, cleanup and delivery headroom in the outer MCP client deadline. Confirm outstanding work and cleanup before retrying.`, }); +/** + * Name the upstream supervisor setting that ended an open. It belongs to the + * process that runs ida-pro-mcp, not to REA's registration timeoutMs. + */ +export const idaSupervisorOpenTimeoutGuidance = ( + seconds: number, +): { readonly userMessage: string; readonly remediationAction: string } => ({ + userMessage: `The IDA database supervisor stopped opening and analyzing the input after its IDA_MCP_OPEN_TIMEOUT deadline of ${String(seconds)} s. That deadline is an ida-pro-mcp setting, separate from REA's registration timeoutMs.`, + remediationAction: + "Raise IDA_MCP_OPEN_TIMEOUT (0 waits indefinitely) in the environment that starts the ida-pro-mcp supervisor, then restart it. Keep the registration timeoutMs in the JSON file named by REA_IDA_MCP_CONFIG above the expected analysis time as well. Confirm retained cleanup before retrying.", +}); + /** A REA_IDA_MCP_CONFIG rejection that names the setting it concerns. */ export const idaConfigurationError = ( constraint: string, diff --git a/src/ida/IdaProtocolValues.ts b/src/ida/IdaProtocolValues.ts index 7e3a538891..624bb45c0f 100644 --- a/src/ida/IdaProtocolValues.ts +++ b/src/ida/IdaProtocolValues.ts @@ -211,6 +211,26 @@ export const openDatabaseSchema = z .passthrough(), }) .passthrough(); +/** + * ida-pro-mcp's database supervisor (snapshot c133c385) rejects an open whose + * worker outlived IDA_MCP_OPEN_TIMEOUT with this sentence and the whole-second + * deadline. Only that exact prefix is read; any other rejection keeps its text. + */ +const SUPERVISOR_OPEN_TIMEOUT = + /^idalib worker timed out after (\d+)s while opening and analyzing /u; + +/** The supervisor's open deadline in seconds when a rejection reports it. */ +export const supervisorOpenTimeoutSeconds = ( + reason: string, +): number | undefined => { + const digits = SUPERVISOR_OPEN_TIMEOUT.exec(reason)?.[1]; + if (digits === undefined) return undefined; + const seconds = Number(digits); + return seconds > 0 && Number.isSafeInteger(seconds * 1000) + ? seconds + : undefined; +}; + /** Only an explicit completed rejection preserves legacy no-worker cleanup. */ export const rejectedOpenDatabaseSchema = z .object({ diff --git a/src/ida/IdaSessionClient.test.ts b/src/ida/IdaSessionClient.test.ts index 2cab179f18..ec112bded2 100644 --- a/src/ida/IdaSessionClient.test.ts +++ b/src/ida/IdaSessionClient.test.ts @@ -2243,6 +2243,35 @@ describe("headless IDA literal string predicate pushdown", () => { }); describe("headless IDA open rejection", () => { + it("reports the supervisor's open deadline as a provider timeout", async () => { + const { producer, client } = await fixture("headless"); + // ida-pro-mcp c133c385 idalib_supervisor.py reports a reaped open this way. + producer.overrideCall = (name) => + name === "idb_open" + ? { + error: + "idalib worker timed out after 1800s while opening and analyzing /work/target.exe. The binary may drive auto-analysis into an unbounded loop. Retry with run_auto_analysis=false (open without analysis and decompile on demand), or raise IDA_MCP_OPEN_TIMEOUT.", + } + : undefined; + + const result = await client.execute("health", {}); + expect(result.ok).toBe(false); + if (result.ok) return; + const projected = projectAnalysisError(result.error); + expect(projected.code).toBe("provider_timeout"); + expect(projected.message).toContain( + "IDA_MCP_OPEN_TIMEOUT deadline of 1800 s", + ); + expect(projected.remediation.action).toContain( + "Raise IDA_MCP_OPEN_TIMEOUT", + ); + expect(result.error.diagnostics).toMatchObject({ + upstream_setting: "IDA_MCP_OPEN_TIMEOUT", + upstream_timeout_seconds: 1800, + }); + expect((await client.close()).ok).toBe(true); + }); + it("reports an idb_open rejection with its upstream reason", async () => { const { producer, client } = await fixture("headless"); producer.overrideCall = (name) => diff --git a/src/ida/IdaSessionClient.ts b/src/ida/IdaSessionClient.ts index a596541a01..3d16596a92 100644 --- a/src/ida/IdaSessionClient.ts +++ b/src/ida/IdaSessionClient.ts @@ -37,7 +37,10 @@ import { type HexRaysCloseReceipt, type HexRaysStatus, } from "./IdaHexRaysProtocol.js"; -import { idaCompatibilityProfile } from "./IdaConfiguration.js"; +import { + idaCompatibilityProfile, + idaSupervisorOpenTimeoutGuidance, +} from "./IdaConfiguration.js"; import { createIdaDiagnosticRedactor } from "./IdaDiagnosticRedactor.js"; import { nativeTools } from "./IdaNativeProtocol.js"; import { readSettledHealth } from "./IdaBusyHealth.js"; @@ -64,6 +67,7 @@ import { modernHealthSchema, openDatabaseSchema, rejectedOpenDatabaseSchema, + supervisorOpenTimeoutSeconds, } from "./IdaProtocolValues.js"; import { idaFileDigest, @@ -808,10 +812,21 @@ export class IdaSessionClient implements AnalysisClient { if (rejected.success) { const diagnostic = createIdaDiagnosticRedactor(this.config); const reason = diagnostic.blocks([rejected.data.error]); - throw new IdaToolRejection( + const rejection = new IdaToolRejection( diagnostic.message("IDA MCP tool failed: ", reason), { diagnostics: { reason } }, ); + const seconds = supervisorOpenTimeoutSeconds(rejected.data.error); + if (seconds === undefined) throw rejection; + throw new AnalysisTimeoutError("idb_open", seconds * 1000, { + cause: rejection, + ...idaSupervisorOpenTimeoutGuidance(seconds), + diagnostics: { + reason, + upstream_setting: "IDA_MCP_OPEN_TIMEOUT", + upstream_timeout_seconds: seconds, + }, + }); } const opened = openDatabaseSchema.parse(raw); if (!sameIdaHostPath(opened.session.input_path, workspace.inputPath))