feat(errors): type refusals at the producer with a total recovery (#10577)

* feat(errors): type refusals at the producer with a total recovery

A resource refusal without authored text fell back to resource-kind advice:
a fixed parser ceiling reported as memory told the caller to add host
memory, an upstream IDA reply ceiling pointed at REA's MCP transport, and a
fixed Kuna text ceiling reported as capacity was marked retryable. An
ambiguous selector was reported as invalid input that pointed at the schema.

Add AnalysisRefusal with three variants built from facts producers already
own: fixed_ceiling (FixedAllowance, now with limit, unit and narrowing),
adjustable_budget (AnalysisSettingLimit) and ambiguous_selector (new
AnalysisInputError option). Each variant is attributed to the error's
operation and projected under details.refusal. Presentation is a total
switch over the variants, and authored text still takes precedence.

Migrate the first producers. GraphQL nesting, Playwright trace input, the
Kuna function text and the IDA upstream reply become fixed ceilings. jadx
overloads and Kuna ambiguous names become ambiguous selectors, replacing the
two Kuna-specific ambiguity texts. Seven occupied admissions declare
measuredExhaustion. The rea/typed-resource-refusal lint rule rejects new
untyped resource constraints, and the remaining 24 are counted in a baseline
that can only shrink.

* fix(errors): honor refusal recovery ownership
This commit is contained in:
morluto authored and GitHub committed 2026-11-14 14:36:14 -05:00
1 parent a0d9025202
commit e83e3fa8a0
31 files changed
+896 -57

No files matched your search

+40 -20
View File
@@ -37,7 +37,11 @@ import { ProviderSelectionError } from "./providerSelectionError.js";
import { ProviderAdapterError } from "./providerAdapterError.js";
import { UnknownRegistryError } from "./unknownRegistryError.js";
import { providerRetryAction } from "./providerOperationHealth.js";
import { fixedAllowanceRemediation } from "./fixedAllowanceRemediation.js";
import { analysisErrorRefusal } from "./analysisErrorRefusal.js";
import {
analysisRefusalMessage,
analysisRefusalRemediation,
} from "./analysisRefusal.js";
import {
primaryAnalysisError,
resolvedAnalysisError,
@@ -127,24 +131,13 @@ export const analysisErrorRemediationAction = (
error.remediationAction ??
"Select a target supported by this operation or choose an operation supporting the reported target format."
);
if (error instanceof AnalysisResourceConstraintError)
return (
error.remediationAction ??
(error.fixedAllowance !== undefined
? fixedAllowanceRemediation(
error.fixedAllowance.name,
error.fixedAllowance.kind,
)
: error.resource === "capacity"
? "Wait for an active analysis to complete, then retry within the reported admission limits."
: error.resource === "transport"
? MCP_TRANSPORT_EVIDENCE_DISCOVERY
: error.resource === "cpu"
? "Review the reported worker CPU limits and observed signal. Retry with sufficient CPU time or a smaller artifact; REA retains tighter inherited limits."
: error.resource === "file-size"
? "Review the reported worker file-size limits and write failure. Retry with a sufficient file-size allowance for the evidence reply; REA retains tighter inherited limits."
: "Review the reported worker memory limits and available host memory. Retry with sufficient memory or a smaller artifact; REA retains tighter inherited limits.")
);
if (error instanceof AnalysisResourceConstraintError) {
if (error.remediationAction !== undefined) return error.remediationAction;
const refusal = analysisErrorRefusal(error);
return refusal === undefined
? measuredResourceRemediation(error.resource)
: analysisRefusalRemediation(refusal, callerLifetime);
}
if (
error instanceof AnalysisTimeoutError &&
error.remediationAction !== undefined
@@ -253,6 +246,9 @@ export const analysisErrorRemediationAction = (
: analysisErrorUserMessage(error))
);
if (error instanceof AnalysisInputError) {
const refusal = analysisErrorRefusal(error);
if (error.remediationAction === undefined && refusal !== undefined)
return analysisRefusalRemediation(refusal, callerLifetime);
const mistakeRemediation = knownArgumentMistakeRemediation(
error.operation,
error.issues,
@@ -311,6 +307,27 @@ export const analysisErrorRemediationAction = (
return analysisErrorUserMessage(error);
};
/**
* Recovery for a measured exhaustion or occupied admission. A typed refusal
* never reaches this: its own variant names the recovery.
*/
const measuredResourceRemediation = (
resource: AnalysisResourceConstraintError["resource"],
): string => {
switch (resource) {
case "capacity":
return "Wait for an active analysis to complete, then retry within the reported admission limits.";
case "transport":
return MCP_TRANSPORT_EVIDENCE_DISCOVERY;
case "cpu":
return "Review the reported worker CPU limits and observed signal. Retry with sufficient CPU time or a smaller artifact; REA retains tighter inherited limits.";
case "file-size":
return "Review the reported worker file-size limits and write failure. Retry with a sufficient file-size allowance for the evidence reply; REA retains tighter inherited limits.";
case "memory":
return "Review the reported worker memory limits and available host memory. Retry with sufficient memory or a smaller artifact; REA retains tighter inherited limits.";
}
};
export const analysisErrorCategory = (
error: AnalysisError,
): AnalysisErrorProjection["category"] => {
@@ -520,11 +537,14 @@ const outcomeUserMessage = (error: AnalysisError): string => {
return "Host filesystem permissions denied read access to the selected path.";
if (error instanceof AnalysisArtifactChangedError)
return "The selected artifact changed during acquisition; no stable snapshot was decoded.";
if (error instanceof AnalysisInputError)
if (error instanceof AnalysisInputError) {
const refusal = analysisErrorRefusal(error);
return (
error.userMessage ??
(refusal === undefined ? undefined : analysisRefusalMessage(refusal)) ??
"Analysis input is invalid. Check the arguments and try again."
);
}
if (error instanceof AnalysisTimeoutError)
return error.userMessage ?? timeoutUserMessage(error);
const hopperMessage = hopperErrorUserMessage(error);