From d4a7c17b38775e090f91a1d7d84d1b3bbcd56e0c Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Mon, 16 Nov 2026 08:39:18 +0800 Subject: [PATCH] feat(errors): project fixed native and producer input allowances as typed refusals (#11623) * feat(errors): project fixed native and producer input allowances as typed refusals fixedNativeAllowance wrote its allowance and value only into the remediation sentence, and fixedProducerInputAllowance put the byte count into the allowance name. Both now build fixedAllowanceOptions with limit and unit, so the native command output capture, PE resource metadata, Ghidra installation-properties and artifact analysis input refusals project details.refusal {kind: fixed_ceiling, allowance_kind, limit, unit}. The fixed-ceiling remediation renders the value from those facts for every ceiling that carries them. Refs #10508 * test(errors): check the rendered allowance value, not its sentence --- src/application/ntfs/NtfsJournalService.test.ts | 2 +- src/domain/analysisRefusal.test.ts | 2 ++ src/domain/analysisRefusal.ts | 8 ++++++-- src/domain/fixedAllowanceRemediation.ts | 5 +---- src/domain/native/nativeDeadlines.ts | 14 +++++++------- src/native/NativeCommandAnalysisError.ts | 3 ++- src/native/pe/PeResourcesProvider.test.ts | 12 ++++++++---- src/native/pe/PeResourcesProvider.ts | 3 ++- .../ghidraInstallationProperties.test.ts | 14 +++++++------- 9 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/application/ntfs/NtfsJournalService.test.ts b/src/application/ntfs/NtfsJournalService.test.ts index 4288f8b905..78eeeff9c6 100644 --- a/src/application/ntfs/NtfsJournalService.test.ts +++ b/src/application/ntfs/NtfsJournalService.test.ts @@ -101,7 +101,7 @@ it("refuses an oversized acquisition as a fixed ceiling, not host memory", async }, }); // Recovery comes from the fixed-allowance owner, not host-memory advice. - expect(projected.remediation.action).toBe( + expect(projected.remediation.action).toContain( fixedAllowanceRemediation("The NTFS journal file allowance", "input"), ); } finally { diff --git a/src/domain/analysisRefusal.test.ts b/src/domain/analysisRefusal.test.ts index 0f2853090f..5cb89c7122 100644 --- a/src/domain/analysisRefusal.test.ts +++ b/src/domain/analysisRefusal.test.ts @@ -50,6 +50,8 @@ describe("typed refusals", () => { expect(projected.remediation.action).toMatch( /^The GraphQL nesting allowance is a fixed allowance\..*Select a shallower document\.$/u, ); + // The value comes from the ceiling's facts, so a producer need not write it into the name. + expect(projected.remediation.action).toMatch(/\b128 levels\b/u); expect(projected.remediation.action).not.toMatch(/worker memory|doctor/u); expect(projected.details?.refusal).toEqual({ kind: "fixed_ceiling", diff --git a/src/domain/analysisRefusal.ts b/src/domain/analysisRefusal.ts index c9413254ea..f0a62a805a 100644 --- a/src/domain/analysisRefusal.ts +++ b/src/domain/analysisRefusal.ts @@ -102,9 +102,13 @@ export const analysisRefusalRemediation = ( case "fixed_ceiling": { const { ceiling } = refusal; const base = fixedAllowanceRemediation(ceiling.name, ceiling.kind); + const value = + ceiling.limit === undefined || ceiling.unit === undefined + ? "" + : ` The allowance is ${String(ceiling.limit)} ${ceiling.unit}; this release has no runtime override.`; return ceiling.narrowing === undefined - ? base - : `${base} ${ceiling.narrowing}`; + ? `${base}${value}` + : `${base}${value} ${ceiling.narrowing}`; } case "adjustable_budget": return adjustableBudgetRemediation( diff --git a/src/domain/fixedAllowanceRemediation.ts b/src/domain/fixedAllowanceRemediation.ts index f9f75fefd5..aafd0fdefe 100644 --- a/src/domain/fixedAllowanceRemediation.ts +++ b/src/domain/fixedAllowanceRemediation.ts @@ -78,7 +78,4 @@ export const fixedProducerInputAllowance = ( bytes: number, allowance: string, ): { readonly retryable: false; readonly fixedAllowance: FixedAllowance } => - fixedAllowanceOptions( - `${allowance} of ${String(bytes)} bytes (this release has no runtime override)`, - "input", - ); + fixedAllowanceOptions(allowance, "input", { limit: bytes, unit: "bytes" }); diff --git a/src/domain/native/nativeDeadlines.ts b/src/domain/native/nativeDeadlines.ts index d3f6420ef4..57625ccee8 100644 --- a/src/domain/native/nativeDeadlines.ts +++ b/src/domain/native/nativeDeadlines.ts @@ -6,7 +6,8 @@ import { import type { AnalysisControlLimit } from "../analysisSettings.js"; import { - fixedAllowanceRemediation, + fixedAllowanceOptions, + type FixedAllowance, type FixedAllowanceKind, } from "../fixedAllowanceRemediation.js"; @@ -100,12 +101,11 @@ export const nativeDeadlineRecovery = (input: { }; }; -/** Fixed native allowance the agent can see, with the value and no override. */ +/** Fixed native allowance projected as `details.refusal`, with its value and unit. */ export const fixedNativeAllowance = ( allowance: string, kind: FixedAllowanceKind, - valueWithUnits: string, -): { readonly retryable: false; readonly remediationAction: string } => ({ - retryable: false, - remediationAction: `${fixedAllowanceRemediation(allowance, kind)} This release has no runtime override. The allowance is ${valueWithUnits}.`, -}); + limit: number, + unit: string, +): { readonly retryable: false; readonly fixedAllowance: FixedAllowance } => + fixedAllowanceOptions(allowance, kind, { limit, unit }); diff --git a/src/native/NativeCommandAnalysisError.ts b/src/native/NativeCommandAnalysisError.ts index b8a9728143..e8257a5cd1 100644 --- a/src/native/NativeCommandAnalysisError.ts +++ b/src/native/NativeCommandAnalysisError.ts @@ -218,7 +218,8 @@ export const translateNativeCommandFailure = ( ...fixedNativeAllowance( "The native command output capture allowance", "capture", - `${String(NATIVE_COMMAND_OUTPUT_BUDGET_BYTES)} bytes`, + NATIVE_COMMAND_OUTPUT_BUDGET_BYTES, + "bytes", ), }, ), diff --git a/src/native/pe/PeResourcesProvider.test.ts b/src/native/pe/PeResourcesProvider.test.ts index 2d655f40f3..6164ac8bfc 100644 --- a/src/native/pe/PeResourcesProvider.test.ts +++ b/src/native/pe/PeResourcesProvider.test.ts @@ -180,8 +180,12 @@ it("names the fixed PE metadata allowance instead of host memory", async () => { }); const projected = projectAnalysisError(error); expect(projected.retryable).toBe(false); - expect(projected.remediation.action).toContain( - "PE resource metadata allowance", - ); - expect(projected.remediation.action).not.toMatch(/available host memory/u); + expect(projected.details).toMatchObject({ + refusal: { + kind: "fixed_ceiling", + allowance_kind: "parser", + limit: 8 * 1024 * 1024, + unit: "bytes", + }, + }); }); diff --git a/src/native/pe/PeResourcesProvider.ts b/src/native/pe/PeResourcesProvider.ts index 57df29491e..f71a8cffa3 100644 --- a/src/native/pe/PeResourcesProvider.ts +++ b/src/native/pe/PeResourcesProvider.ts @@ -153,7 +153,8 @@ const peResourcesFailurePrimary = ( ? fixedNativeAllowance( "The PE resource metadata allowance", "parser", - `${String(PE_RESOURCE_METADATA_BYTES)} bytes (8 MiB)`, + PE_RESOURCE_METADATA_BYTES, + "bytes", ) : { retryable: false as const, diff --git a/tests/boundary/filesystem/ghidraInstallationProperties.test.ts b/tests/boundary/filesystem/ghidraInstallationProperties.test.ts index 136b0317e2..91194263c3 100644 --- a/tests/boundary/filesystem/ghidraInstallationProperties.test.ts +++ b/tests/boundary/filesystem/ghidraInstallationProperties.test.ts @@ -173,15 +173,15 @@ it("refuses an oversized descriptor before reading file bytes", async () => { expect(projectAnalysisError(failure)).toMatchObject({ code: "resource_constraint", retryable: false, - remediation: { - action: expect.stringContaining( - "Ghidra installation-properties read allowance of 1048576 bytes (this release has no runtime override)", - ), + details: { + refusal: { + kind: "fixed_ceiling", + allowance_kind: "input", + limit: MAX_GHIDRA_INSTALLATION_PROPERTIES_BYTES, + unit: "bytes", + }, }, }); - expect(projectAnalysisError(failure).remediation.action).toContain( - "Increasing an evidence-reply file-size allowance does not admit this input", - ); expect(reads).toBe(0); } finally { await resources.close();