Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/domain/analysisErrorCleanup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"], {});
Expand Down
10 changes: 10 additions & 0 deletions src/domain/analysisErrorPresentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment thread
prabhuramkarki marked this conversation as resolved.
Resolved
)
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);
};

Expand Down
57 changes: 57 additions & 0 deletions src/domain/analysisErrorProjection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
AnalysisCancelledError,
AnalysisTimeoutError,
AnalysisResourceConstraintError,
AnalysisProtocolError,
} from "./analysisErrorCore.js";
import { ArtifactOperationError } from "./artifactOperationError.js";
import { BinaryTargetError } from "./configurationErrors.js";
Expand All @@ -17,6 +18,8 @@ import {
HopperRemoteError,
HopperStartError,
HopperTimeoutError,
HopperCancelledError,
HopperProtocolError,
} from "./hopperErrors.js";
import { ProviderAdapterError } from "./providerAdapterError.js";
import { UnknownRegistryError } from "./unknownRegistryError.js";
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
},
},
},
Expand Down
11 changes: 8 additions & 3 deletions tests/boundary/providers/kuna/kunaProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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();
});

Expand Down
Loading