From 8f8242f48fd2f826fa39889ebe9ba8d4335da787 Mon Sep 17 00:00:00 2001 From: Prabhuram Karki Date: Sat, 17 Oct 2026 21:48:49 +0545 Subject: [PATCH 1/2] fix(errors): separate recovery actions from failure messages --- src/domain/analysisErrorPresentation.ts | 9 +++++ src/domain/analysisErrorProjection.test.ts | 40 +++++++++++++++++++ .../enhancedTools.callPathsAndBatches.test.ts | 2 +- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/domain/analysisErrorPresentation.ts b/src/domain/analysisErrorPresentation.ts index 75a2d0c285c..9b97b2cefe4 100644 --- a/src/domain/analysisErrorPresentation.ts +++ b/src/domain/analysisErrorPresentation.ts @@ -137,6 +137,15 @@ 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 ( + 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 de8c326afa0..a5ff6defd73 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,43 @@ 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: "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.", }, }, }, From 373c3b72aae64440b469bb9056595737b618baf9 Mon Sep 17 00:00:00 2001 From: Prabhuram Karki Date: Mon, 19 Oct 2026 14:29:02 +0545 Subject: [PATCH 2/2] test(errors): preserve retained cleanup recovery guidance --- src/domain/analysisErrorCleanup.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) 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"], {});