diff --git a/src/domain/analysisErrorCleanup.test.ts b/src/domain/analysisErrorCleanup.test.ts index 41ce5abcfa9..287ad09c575 100644 --- a/src/domain/analysisErrorCleanup.test.ts +++ b/src/domain/analysisErrorCleanup.test.ts @@ -16,6 +16,16 @@ import { import { ProviderCleanupError } from "./providerCleanupError.js"; import { createEvidence } from "./evidence.js"; +it("preserves cleanup recovery guidance while resources remain owned", () => { + const cleanup = new ProviderCleanupError("fixture", ["owned-input"], {}); + expect(projectAnalysisError(cleanup)).toMatchObject({ + code: "cleanup_incomplete", + retryable: false, + remediation: { action: cleanup.userMessage }, + }); + expect(cleanup.cleanupResources).toEqual(["owned-input"]); +}); + it("keeps dependency-owned resources empty after the final owner releases", () => { const file = new ProviderCleanupError("fixture", ["file-owner"], {}); const trace = new ProviderCleanupError("fixture", ["trace-owner"], {}); diff --git a/src/domain/analysisErrorPresentation.ts b/src/domain/analysisErrorPresentation.ts index ec5efa50dd7..43e41f1926f 100644 --- a/src/domain/analysisErrorPresentation.ts +++ b/src/domain/analysisErrorPresentation.ts @@ -138,6 +138,16 @@ export const analysisErrorRemediationAction = ( return error.remediationAction; if (error instanceof UnknownRegistryError && error.reason === "not-found") return "Check that the unknown_id belongs to this session, then retry."; + if (error.userMessage !== undefined) return error.userMessage; + if ( + UNREADABLE_OUTPUT_TAGS.has(error._tag) || + ADAPTER_FAILURE_TAGS.has(error._tag) + ) + return "Run `rea doctor` and review the reported details to correct the request or provider setup before running the analysis again."; + if (CANCELLED_TAGS.has(error._tag)) + return "Start the analysis again when ready."; + if (TIMEOUT_TAGS.has(error._tag)) + return "Narrow the request, then run `rea doctor` if it still exceeds its deadline."; return analysisErrorUserMessage(error); }; diff --git a/src/domain/analysisErrorProjection.test.ts b/src/domain/analysisErrorProjection.test.ts index cc8fac59b98..2f09a1dd046 100644 --- a/src/domain/analysisErrorProjection.test.ts +++ b/src/domain/analysisErrorProjection.test.ts @@ -7,6 +7,7 @@ import { AnalysisCancelledError, AnalysisTimeoutError, AnalysisResourceConstraintError, + AnalysisProtocolError, } from "./analysisErrorCore.js"; import { ArtifactOperationError } from "./artifactOperationError.js"; import { BinaryTargetError } from "./configurationErrors.js"; @@ -17,6 +18,8 @@ import { HopperRemoteError, HopperStartError, HopperTimeoutError, + HopperCancelledError, + HopperProtocolError, } from "./hopperErrors.js"; import { ProviderAdapterError } from "./providerAdapterError.js"; import { UnknownRegistryError } from "./unknownRegistryError.js"; @@ -573,6 +576,60 @@ describe("analysis error projection: Hopper startup failures", () => { }); describe("analysis error projection: retry guidance", () => { + it.each([ + new AnalysisProtocolError("invalid reply"), + new AnalysisOutputError("inspect", "report missing"), + new HopperProtocolError("invalid reply"), + new ProviderAdapterError("fixture", "inspect"), + new AnalysisCancelledError("inspect"), + new HopperCancelledError(), + new AnalysisTimeoutError("inspect", 30), + ])("separates recovery actions from the $_tag failure message", (error) => { + const projected = projectAnalysisError(error); + expect(projected.remediation.action).not.toBe(projected.message); + expect(projected.remediation.action).toMatch(/^(Run|Start|Narrow)\b/u); + expect(analysisErrorProjectionSchema.safeParse(projected).success).toBe( + true, + ); + }); + + it.each([ + new ProviderAdapterError("fixture", "inspect", { + userMessage: "Reopen the target to refresh the selected provider.", + }), + new AnalysisOutputError("inspect", "report missing", { + userMessage: "Select a complete report.", + }), + new AnalysisTimeoutError("inspect", 30, { + userMessage: "Increase the selected operation deadline.", + }), + ])("preserves custom producer guidance for $_tag", (error) => { + expect(projectAnalysisError(error)).toMatchObject({ + message: error.userMessage, + remediation: { action: error.userMessage }, + }); + }); + + it.each([ + new ProviderAdapterError("fixture", "inspect", { + userMessage: "Selected provider failed.", + remediationAction: "Correct the selected provider setting.", + }), + new AnalysisOutputError("inspect", "report missing", { + userMessage: "Selected report is incomplete.", + remediationAction: "Select a complete report.", + }), + new AnalysisTimeoutError("inspect", 30, { + userMessage: "Selected deadline elapsed.", + remediationAction: "Increase the selected operation deadline.", + }), + ])("preserves producer recovery guidance for $_tag", (error) => { + expect(projectAnalysisError(error)).toMatchObject({ + message: error.userMessage, + remediation: { action: error.remediationAction }, + }); + }); + it.each([ [ "unreadable output", diff --git a/tests/boundary/mcp/enhancedTools.callPathsAndBatches.test.ts b/tests/boundary/mcp/enhancedTools.callPathsAndBatches.test.ts index 24c28580198..128fc71a0eb 100644 --- a/tests/boundary/mcp/enhancedTools.callPathsAndBatches.test.ts +++ b/tests/boundary/mcp/enhancedTools.callPathsAndBatches.test.ts @@ -513,7 +513,7 @@ describe("enhanced MCP batches", () => { retryable: false, remediation: { action: - "Analysis returned an unreadable result. Run `rea doctor` and review the reported details; repeating the unchanged request is not expected to succeed.", + "Run `rea doctor` and review the reported details to correct the request or provider setup before running the analysis again.", }, }, }, diff --git a/tests/boundary/providers/kuna/kunaProvider.test.ts b/tests/boundary/providers/kuna/kunaProvider.test.ts index e6035e9b4b1..456d3337bf9 100644 --- a/tests/boundary/providers/kuna/kunaProvider.test.ts +++ b/tests/boundary/providers/kuna/kunaProvider.test.ts @@ -778,9 +778,10 @@ it("refuses to launch an executable replaced after the target was opened", async await run(client, "procedure_pseudo_code", { procedure: "main" }); await appendFile(kuna, "\n// replaced mid-session\n"); - expect( - await client.execute("procedure_pseudo_code", { procedure: "parse" }), - ).toMatchObject({ + const replaced = await client.execute("procedure_pseudo_code", { + procedure: "parse", + }); + expect(replaced).toMatchObject({ ok: false, error: { _tag: "ProviderAdapterError", @@ -789,6 +790,10 @@ it("refuses to launch an executable replaced after the target was opened", async ), }, }); + if (!replaced.ok) + expect(projectAnalysisError(replaced.error).remediation.action).toContain( + "reopen the target", + ); await client.close(); });