mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
fix(errors): vsix and pyc limit refusals state recovery from the measured requirement (#15407)
* fix(errors): let the typed limit refusal state recovery, with the measured requirement A resource constraint with a typed adjustable limit now takes its recovery from the shared refusal owner, which compares the measured requirement with the control's maximum, instead of producer prose. The VSIX and pyc providers drop their hand-built "raise X up to MAX" text. pyc string and key limits report the size the parser measured; VSIX reports its early-stop lower bound only when it already exceeds the control's maximum. Refs #15325 * fix(python): report an integer key's limit without a byte requirement it did not measure * fix(errors): keep producer-authored recovery precedence; vsix and pyc state only typed facts The global precedence change hid multi-control advice (V8) and producer-measured requirements kept in prose (Maven/Gradle). The VSIX and pyc producers no longer author prose for a single-control limit, so the shared typed recovery applies to them without changing other producers.
This commit is contained in:
1 parent
2d1748117e
commit
b211f216d8
7 files changed
+73
-31
No files matched your search
@@ -17,11 +17,18 @@ const LIMIT_CONTROLS = {
|
||||
marshal_key_bytes: ["max_file_bytes"],
|
||||
} as const satisfies Record<string, readonly (keyof PythonPycLimits)[]>;
|
||||
|
||||
/** A parser allowance exhausted; `required` is the size the parser measured. */
|
||||
export const pythonPycLimit = (
|
||||
name: keyof typeof LIMIT_CONTROLS,
|
||||
maximum: number,
|
||||
detail: string,
|
||||
) => decodeLimit(PYTHON_PYC_FORMAT, detail, { name, maximum });
|
||||
required?: number,
|
||||
) =>
|
||||
decodeLimit(PYTHON_PYC_FORMAT, detail, {
|
||||
name,
|
||||
maximum,
|
||||
...(required === undefined ? {} : { required }),
|
||||
});
|
||||
|
||||
export const pythonPycLimitControls = (
|
||||
boundary: string,
|
||||
|
||||
@@ -1476,7 +1476,10 @@ it("preflights expanded shared code-name keys before building their hex table",
|
||||
expect.objectContaining({
|
||||
failure: expect.objectContaining({
|
||||
kind: "limit",
|
||||
limit: { name: "max_string_bytes", maximum: 4096 },
|
||||
limit: expect.objectContaining({
|
||||
name: "max_string_bytes",
|
||||
maximum: 4096,
|
||||
}),
|
||||
}),
|
||||
message: expect.stringContaining("max_string_bytes 4096"),
|
||||
}),
|
||||
|
||||
@@ -359,6 +359,7 @@ class PycMarshalReader extends MarshalReader<MarshalValue> {
|
||||
"max_string_bytes",
|
||||
max_string_bytes,
|
||||
`Marshal string of ${exceeded.amount} bytes exceeds max_string_bytes ${max_string_bytes}.`,
|
||||
exceeded.amount,
|
||||
);
|
||||
default:
|
||||
// Long digits; this reader sets no sequence or digit-count bound.
|
||||
@@ -366,6 +367,7 @@ class PycMarshalReader extends MarshalReader<MarshalValue> {
|
||||
"max_string_bytes",
|
||||
max_string_bytes,
|
||||
`Marshal long of ${exceeded.amount} digit bytes exceeds max_string_bytes ${max_string_bytes}.`,
|
||||
exceeded.amount,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1129,8 +1131,10 @@ class PycMarshalReader extends MarshalReader<MarshalValue> {
|
||||
if (mode === "hash") return value.value ? "i1" : "i0";
|
||||
return value.value ? "B1" : "B0";
|
||||
case "int":
|
||||
// A bit count bounds the decimal key only approximately, so it is
|
||||
// not reported as a byte requirement.
|
||||
if (value.bits > this.input.max_string_bytes * 3)
|
||||
this.#keyTooLarge(value.bits);
|
||||
this.#keyTooLarge(value.bits, false);
|
||||
return this.#boundedJoin("i", [value.value.toString()], "");
|
||||
case "float":
|
||||
if (Number.isNaN(value.value)) return this.#identity(value);
|
||||
@@ -1424,11 +1428,14 @@ class PycMarshalReader extends MarshalReader<MarshalValue> {
|
||||
this.work.keyBytes += size;
|
||||
}
|
||||
|
||||
#keyTooLarge(size: number): never {
|
||||
#keyTooLarge(size: number, measuredBytes = true): never {
|
||||
throw pythonPycLimit(
|
||||
"max_string_bytes",
|
||||
this.input.max_string_bytes,
|
||||
`Marshal key of ${size} bytes exceeds max_string_bytes ${this.input.max_string_bytes}.`,
|
||||
measuredBytes
|
||||
? `Marshal key of ${size} bytes exceeds max_string_bytes ${this.input.max_string_bytes}.`
|
||||
: `Marshal integer key of ${size} bits exceeds max_string_bytes ${this.input.max_string_bytes}.`,
|
||||
measuredBytes ? size : undefined,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,13 +33,25 @@ const OPERATION = "inspect_python_pyc";
|
||||
|
||||
/**
|
||||
* Recovery for the caller-selected budgets that determine one parser limit.
|
||||
* A limit owned by one control reports it as `limit`; a product of several
|
||||
* controls names each as a related parameter, since no single range applies.
|
||||
* A limit owned by one control is typed, with the requirement the parser
|
||||
* measured, so the shared refusal owner states whether raising it can help.
|
||||
* A product of several controls names each as a related parameter, since no
|
||||
* single range applies.
|
||||
*/
|
||||
const parserLimitRecovery = (
|
||||
input: InspectPythonPycInput,
|
||||
fields: readonly (keyof PythonPycLimits)[],
|
||||
required?: number | bigint,
|
||||
) => {
|
||||
const [only] = fields;
|
||||
if (fields.length === 1 && only !== undefined)
|
||||
return {
|
||||
retryable: false as const,
|
||||
limit: {
|
||||
...pythonPycBudgetLimit(only, input[only]),
|
||||
...(typeof required === "number" ? { required_value: required } : {}),
|
||||
},
|
||||
};
|
||||
const actions = fields.map((field) => {
|
||||
const selected = input[field];
|
||||
const { maximum } = PYTHON_PYC_READ_BUDGETS[field];
|
||||
@@ -47,14 +59,9 @@ const parserLimitRecovery = (
|
||||
? `Raise ${field} above ${String(selected)}, up to ${String(maximum)}, on the next call.`
|
||||
: `${field} is at this operation's maximum of ${String(maximum)}; select a complete artifact within that bound.`;
|
||||
});
|
||||
const [only] = fields;
|
||||
return {
|
||||
retryable: false as const,
|
||||
...(fields.length === 1 && only !== undefined
|
||||
? { limit: pythonPycBudgetLimit(only, input[only]) }
|
||||
: fields.length > 1
|
||||
? { related: { parameters: [...fields] } }
|
||||
: {}),
|
||||
...(fields.length > 1 ? { related: { parameters: [...fields] } } : {}),
|
||||
remediationAction: `${actions.join(" ")} Repeating the unchanged request fails the same way; waiting or adding host memory does not raise these parser limits.`,
|
||||
};
|
||||
};
|
||||
@@ -81,7 +88,11 @@ const failureFor = (
|
||||
OPERATION,
|
||||
name === "max_depth" ? "capacity" : "memory",
|
||||
failure,
|
||||
parserLimitRecovery(input, pythonPycLimitControls(name)),
|
||||
parserLimitRecovery(
|
||||
input,
|
||||
pythonPycLimitControls(name),
|
||||
failure.failure.limit.required,
|
||||
),
|
||||
);
|
||||
},
|
||||
fileSize: (failure) =>
|
||||
|
||||
Reference in new issue
Block a user