From 8ff45fd380338406e186fb79083f05da4c4bcf11 Mon Sep 17 00:00:00 2001 From: Predat1000 <213030819+Predat1000@users.noreply.github.com> Date: Sat, 7 Nov 2026 00:52:29 +0100 Subject: [PATCH] Summarize the selected provider's Java probe timeout --- packages/provider-rea/src/reaMcp.ts | 36 ++++++++++++++++++++++- packages/provider-rea/test/reaMcp.test.ts | 16 ++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/packages/provider-rea/src/reaMcp.ts b/packages/provider-rea/src/reaMcp.ts index 53124c2..83ef1f8 100644 --- a/packages/provider-rea/src/reaMcp.ts +++ b/packages/provider-rea/src/reaMcp.ts @@ -29,9 +29,32 @@ function cleanEnvironment(environment: NodeJS.ProcessEnv): Record | undefined { + if (value && typeof value === "object" && !Array.isArray(value)) return value as Record; + return undefined; +} + +function diagnosticMessage(value: unknown): string | undefined { + const error = asRecord(asRecord(value)?.error); + if (!error) return undefined; + const details = asRecord(error.details); + const rejections = details?.rejections; + if (Array.isArray(rejections) && typeof details?.requested_provider_id === "string") { + const selected = rejections.map(asRecord).find((entry) => entry?.provider_id === details.requested_provider_id); + const probe = asRecord(asRecord(selected?.diagnostics)?.java_probe_failure); + if (probe?.process_error_code === "ETIMEDOUT") { + return "The Java runtime check timed out. Retry when the machine is less busy."; + } + if (typeof selected?.reason === "string" && selected.reason.trim()) return selected.reason.trim(); + } + return typeof error.message === "string" ? error.message.trim() : undefined; +} + function providerErrorDetail(reply: unknown): string | null { if (!reply || typeof reply !== "object" || Array.isArray(reply)) return null; const response = reply as Record; + const diagnostic = diagnosticMessage(response.structuredContent); + if (diagnostic) return diagnostic; const textParts = Array.isArray(response.content) ? response.content.flatMap((item) => { if (!item || typeof item !== "object" || Array.isArray(item)) return []; @@ -39,7 +62,18 @@ function providerErrorDetail(reply: unknown): string | null { return typeof record.text === "string" && record.text.trim() ? [record.text.trim()] : []; }) : []; - if (textParts.length > 0) return textParts.join(" "); + if (textParts.length > 0) { + const text = textParts.join(" "); + if (text.startsWith("{")) { + try { + const summary = diagnosticMessage(JSON.parse(text)); + if (summary) return summary; + } catch { + // Some provider errors are plain text that begins with a brace. + } + } + return text; + } if (response.structuredContent && typeof response.structuredContent === "object" && !Array.isArray(response.structuredContent)) { const record = response.structuredContent as Record; diff --git a/packages/provider-rea/test/reaMcp.test.ts b/packages/provider-rea/test/reaMcp.test.ts index c471baf..16ccc0b 100644 --- a/packages/provider-rea/test/reaMcp.test.ts +++ b/packages/provider-rea/test/reaMcp.test.ts @@ -231,3 +231,19 @@ test("uses structured provider detail without inventing a setup diagnosis", () = assert.match(error.message, /Unsupported target language/); assert.doesNotMatch(error.message, /Verify Ghidra|Verify a compatible JDK/); }); + +test("summarizes a timed-out Java probe for the requested provider", () => { + const report = { error: { message: "Provider unavailable", details: { + requested_provider_id: "ghidra", rejections: [ + { provider_id: "other", reason: "Other launcher missing" }, + { provider_id: "ghidra", reason: "Update JAVA_HOME", diagnostics: { + java_probe_failure: { process_error_code: "ETIMEDOUT", output: "private system settings" }, + } }, + ], + } } }; + for (const reply of [{ structuredContent: report }, { content: [{ text: JSON.stringify(report) }] }]) { + const error = __mcpTest.providerFailure("open_binary", reply); + assert.match(error.message, /Java runtime check timed out/); + assert.doesNotMatch(error.message, /private system settings|JAVA_HOME|Other launcher|Verify Ghidra/); + } +}); \ No newline at end of file