Files
reverse-engineering-anything/src/domain/analysisErrorProjectionSchema.ts
T
morluto 6ac87697e7 fix(errors)!: make retry_class the only retry field of a target failure (#15450)
* fix(errors)!: make retry_class the only retry field of a target failure

A target failure reported two retry fields: its own `retry` hint
(`none | backoff | after_change`) and the `retry_class` every error
carries. They mapped one to one, so readers had to reconcile both.
`retry_class` is now the single owner: the target-failure table declares
it directly, the projection no longer emits `retry`, the error schema no
longer accepts it, and the CLI recovery rewrite reads `retry_class`.

BREAKING CHANGE: target failures no longer include `retry`, and the
error schema rejects it. Read `retry_class` instead: `backoff` is
`same_call`, `after_change` is `change_first` and `none` is `never`.

* test(errors): readers reject the removed target-failure retry field
2026-12-01 10:36:15 -05:00

120 lines
3.9 KiB
TypeScript

import { z } from "zod";
import { analysisErrorRecoverySchema } from "./analysisErrorRecovery.js";
import { signedAfterPackingExplanationSchema } from "./artifactIntegrity.js";
import { jsonValueSchema } from "./jsonValue.js";
import type { AnalysisErrorProjection } from "./analysisErrorProjection.js";
const categorySchema = z.enum([
"invalid_input",
"unsupported_provider",
"unsupported_target",
"integrity_mismatch",
"partial",
"cancelled",
"timeout",
"resource_constraint",
"unavailable",
"execution_failure",
]);
const remediationSchema = z
.object({
action: z.string().min(1),
})
.strict();
const common = {
category: categorySchema,
message: z.string().min(1),
retryable: z.boolean(),
// Always produced; optional when reading errors retained by earlier releases.
retry_class: z
.enum(["same_call", "change_first", "never", "unknown_outcome"])
.optional(),
remediation: remediationSchema,
recovery: analysisErrorRecoverySchema.optional(),
};
const genericDetails = z.record(z.string(), jsonValueSchema).optional();
const generic = <Code extends string>(code: Code) =>
z
.object({ code: z.literal(code), ...common, details: genericDetails })
.strict();
/** The canonical invalid-input projection, also used for facet-local refusals. */
export const analysisInputErrorProjectionSchema = generic("invalid_request");
/** The canonical resource refusal, including its reported limits and recovery. */
export const analysisResourceErrorProjectionSchema = generic(
"resource_constraint",
);
/** Authentication or integrity refusal for a supplied Evidence record. */
export const evidenceIntegrityErrorProjectionSchema = generic(
"evidence_integrity_mismatch",
);
/** Stable discriminated schema shared by every CLI and MCP error surface. */
export const analysisErrorProjectionSchema = z.discriminatedUnion("code", [
analysisInputErrorProjectionSchema,
generic("access_denied"),
generic("artifact_changed"),
generic("unreadable_output"),
generic("capability_unavailable"),
generic("unsupported_target"),
generic("provider_unavailable"),
generic("provider_timeout"),
analysisResourceErrorProjectionSchema,
generic("cancelled"),
z
.object({
code: z.literal("artifact_integrity_mismatch"),
...common,
details: z.union([
z
.object({
logical_path: z.string(),
declared_sha256: z.string().nullable(),
calculated_sha256: z.string().nullable(),
unpacked: z.boolean(),
signing_explanation:
signedAfterPackingExplanationSchema.exactOptional(),
})
.catchall(jsonValueSchema),
z
.object({
logical_path: z.string(),
algorithm: z.literal("md5"),
declared_md5: z.string().regex(/^[a-f0-9]{32}$/u),
calculated_md5: z
.string()
.regex(/^[a-f0-9]{32}$/u)
.nullable(),
unpacked: z.boolean(),
})
.catchall(jsonValueSchema),
z
.object({
logical_path: z.string(),
algorithm: z.enum(["dfu-crc32", "crc32"]),
declared_crc32: z.string().regex(/^[a-f0-9]{8}$/u),
calculated_crc32: z
.string()
.regex(/^[a-f0-9]{8}$/u)
.nullable(),
unpacked: z.boolean(),
})
.catchall(jsonValueSchema),
]),
})
.strict(),
generic("artifact_operation_failed"),
evidenceIntegrityErrorProjectionSchema,
generic("partial"),
generic("target_integrity_mismatch"),
generic("input_conflict"),
generic("host_io_failed"),
generic("process_capture_failed"),
generic("cleanup_incomplete"),
generic("revision_conflict"),
generic("configuration_invalid"),
generic("target_unavailable"),
generic("execution_failure"),
]) as unknown as z.ZodType<AnalysisErrorProjection>;