diff --git a/src/application/ntfs/NtfsJournalService.ts b/src/application/ntfs/NtfsJournalService.ts index 60801ac25c7..d9f24d61c1f 100644 --- a/src/application/ntfs/NtfsJournalService.ts +++ b/src/application/ntfs/NtfsJournalService.ts @@ -14,6 +14,7 @@ import { assertStableArtifactState, projectStableArtifactFailure, stableArtifactInputOptions, + selectedFileRequirement, readerIntegrityFailure, } from "../../resources/index.js"; import { @@ -68,6 +69,8 @@ const acquisitionConstraint = ( message: string, maxFileBytes: number, cause?: Error, + /** The acquisition's measured size, for a budget refusal. */ + requiredBytes?: number, ): AnalysisError => new AnalysisResourceConstraintError( operation, @@ -84,11 +87,12 @@ const acquisitionConstraint = ( } : { retryable: false, - limit: ntfsJournalFileBytesLimit(maxFileBytes), - remediationAction: - maxFileBytes < NTFS_JOURNAL_FILE_BYTES.maximum - ? `Raise max_file_bytes above ${String(maxFileBytes)} bytes on the next call for the same acquisitions; both are read into memory.` - : "max_file_bytes is at its maximum; select a smaller acquisition.", + limit: { + ...ntfsJournalFileBytesLimit(maxFileBytes), + ...(requiredBytes === undefined + ? {} + : { required_value: requiredBytes }), + }, }), }, ); @@ -120,6 +124,7 @@ const readFailure = ( cause.message, maxFileBytes, cause, + selectedFileRequirement(cause).required_value, ); } if ( @@ -169,6 +174,8 @@ const readAcquisition = async ( "budget", `The retained ${parameter} acquisition has ${String(cached.snapshot.bytes.length)} bytes, above max_file_bytes (${String(maxFileBytes)}).`, maxFileBytes, + undefined, + cached.snapshot.bytes.length, ), ); await assertStableArtifactState(path, cached.state, signal); diff --git a/src/artifacts/releaseExposure/releaseExposureFailures.ts b/src/artifacts/releaseExposure/releaseExposureFailures.ts index 6e5f03e3f4e..a60ee2e7bc9 100644 --- a/src/artifacts/releaseExposure/releaseExposureFailures.ts +++ b/src/artifacts/releaseExposure/releaseExposureFailures.ts @@ -4,6 +4,7 @@ import { artifactFileCancellationError, artifactFilePrimaryFacts, projectStableArtifactFailure, + selectedFileRequirement, readerIntegrityFailure, type ArtifactFilePrimaryFacts, } from "../../resources/index.js"; @@ -17,10 +18,7 @@ import { } from "../../domain/analysisErrorCore.js"; import { AnalysisError } from "../../domain/analysisErrorBase.js"; import { RELEASE_EXPOSURE_PROVIDER } from "../../domain/investigationProviders.js"; -import { - RELEASE_EXPOSURE_FILE_BYTES, - releaseExposureFileBytesLimit, -} from "../../domain/releaseExposure.js"; +import { releaseExposureFileBytesLimit } from "../../domain/releaseExposure.js"; import { ProviderAdapterError } from "../../domain/providerAdapterError.js"; import { isSelectedRegularFileError } from "../../filesystem/RegularFile.js"; import { errorMessage } from "../../kernel/errorMessage.js"; @@ -28,15 +26,6 @@ import { errorMessage } from "../../kernel/errorMessage.js"; export const RELEASE_EXPOSURE_AUDIT_OPERATION = "audit_release_exposure"; const PROVIDER_ID = RELEASE_EXPOSURE_PROVIDER.id; -const fileSizeRecovery = (maxFileBytes: number) => ({ - retryable: false as const, - limit: releaseExposureFileBytesLimit(maxFileBytes), - remediationAction: - maxFileBytes < RELEASE_EXPOSURE_FILE_BYTES.maximum - ? `Raise max_file_bytes above ${String(maxFileBytes)} bytes (up to ${String(RELEASE_EXPOSURE_FILE_BYTES.maximum)}) on the next call for the same artifact, or select a smaller artifact. Reads are held in memory.` - : `max_file_bytes is at its maximum of ${String(maxFileBytes)} bytes; select a smaller artifact.`, -}); - /** * The header admission is its own bound, not the selected-file ceiling, so * max_file_bytes cannot repair it. The recovery names the shared setting the @@ -85,7 +74,14 @@ export const releaseExposureLimitFailure = ( "file-size", cause.message, { max_file_bytes: maxFileBytes }, - { cause, ...fileSizeRecovery(maxFileBytes) }, + { + cause, + retryable: false, + limit: { + ...releaseExposureFileBytesLimit(maxFileBytes), + ...selectedFileRequirement(cause), + }, + }, ) : asarHeaderAdmissionFailure(cause, cause.admission); diff --git a/src/firmware/espNvs/EspNvsProvider.ts b/src/firmware/espNvs/EspNvsProvider.ts index d93ef2c975e..1636868c213 100644 --- a/src/firmware/espNvs/EspNvsProvider.ts +++ b/src/firmware/espNvs/EspNvsProvider.ts @@ -12,12 +12,12 @@ import { projectStableArtifactFailure, readStableArtifact, type StableArtifactSnapshot, + selectedFileRequirement, } from "../../resources/index.js"; import type { ExecutionOptions } from "../../ports/AnalysisProvider.js"; import type { EspNvsPort } from "../../ports/binaryDiagnostics/EspNvsPort.js"; import { ESP_NVS_PAGE_BYTES, - MAX_ESP_NVS_FILE_BYTES, espNvsBudgetLimit, type EspNvsProviderInput, } from "../../domain/firmware/espNvs.js"; @@ -115,11 +115,6 @@ export class EspNvsProvider implements EspNvsPort { } } -const fileSizeRemediation = (input: EspNvsProviderInput): string => - input.max_file_bytes >= MAX_ESP_NVS_FILE_BYTES - ? `The image exceeds the ${String(MAX_ESP_NVS_FILE_BYTES)}-byte input ceiling this operation accepts; carve the NVS partition first.` - : `Raise max_file_bytes above ${String(input.max_file_bytes)} bytes within its ${String(MAX_ESP_NVS_FILE_BYTES)}-byte ceiling, or carve the NVS partition first.`; - const espNvsFailure = ( cause: unknown, input: EspNvsProviderInput, @@ -160,8 +155,10 @@ const espNvsFailure = ( ), { retryable: false, - limit: espNvsBudgetLimit("max_file_bytes", input.max_file_bytes), - remediationAction: fileSizeRemediation(input), + limit: { + ...espNvsBudgetLimit("max_file_bytes", input.max_file_bytes), + ...selectedFileRequirement(failure), + }, }, ), }), diff --git a/src/il2cpp/Il2cppMetadataProvider.ts b/src/il2cpp/Il2cppMetadataProvider.ts index 894ae0977c8..df9c5dd9591 100644 --- a/src/il2cpp/Il2cppMetadataProvider.ts +++ b/src/il2cpp/Il2cppMetadataProvider.ts @@ -121,11 +121,14 @@ const failureForPrimary = ( isParseLimit(cause, IL2CPP_BINARY_FORMAT) && cause.failure.limit.name === ELF_VIRTUAL_POINTER_INDEX_LIMIT ) { - const selected = cause.failure.limit.maximum; + const { maximum: selected, required } = cause.failure.limit; + // The typed limit lets the shared refusal owner state the recovery. return parseLimitConstraint(OPERATION, "memory", cause, { retryable: false, - limit: il2cppNativeIndexLimit(selected), - remediationAction: `The ELF pointer index allowance is max_native_index_bytes = ${String(selected)} bytes. Pass a larger max_native_index_bytes (up to ${String(Number.MAX_SAFE_INTEGER)}) on the next ${OPERATION} call with the same binary_path; no restart is required. Host memory and the binary file allowance are independent. Repeating the unchanged request fails the same way.`, + limit: { + ...il2cppNativeIndexLimit(selected), + ...(typeof required === "number" ? { required_value: required } : {}), + }, }); } if ( diff --git a/src/java/MavenGradleMetadataProvider.ts b/src/java/MavenGradleMetadataProvider.ts index 41790e8d145..560ab7504b2 100644 --- a/src/java/MavenGradleMetadataProvider.ts +++ b/src/java/MavenGradleMetadataProvider.ts @@ -7,6 +7,7 @@ import { readStableArtifact, translateArtifactFailure, type StableArtifactSnapshot, + selectedFileRequirement, } from "../resources/index.js"; import { isParseLimit, @@ -17,7 +18,6 @@ import { xmlElementDepthConstraint } from "../domain/xmlDocument.js"; import { errorMessage } from "../kernel/errorMessage.js"; import { ArtifactOperationError } from "../domain/artifactOperationError.js"; import { - MAVEN_GRADLE_FILE_BYTES, mavenGradleFileBytesLimit, mavenGradleReportLimit, mavenGradleReportLimits, @@ -84,13 +84,6 @@ export class MavenGradleMetadataProvider { } } -const inputBudgetRemediation = ( - input: InspectMavenGradleMetadataInput, -): string => - input.max_file_bytes >= MAVEN_GRADLE_FILE_BYTES.maximum - ? `The file exceeds the ${String(MAVEN_GRADLE_FILE_BYTES.maximum)}-byte input ceiling this operation accepts; select a smaller artifact.` - : `Raise max_file_bytes above ${String(input.max_file_bytes)} bytes, up to ${String(MAVEN_GRADLE_FILE_BYTES.maximum)}, or select a smaller artifact; this is the caller-selected input read budget.`; - const REPORT_LIMIT_FIELDS = Object.keys( MAVEN_GRADLE_REPORT_LIMIT_BOUNDS, ) as MavenGradleReportLimitField[]; @@ -152,8 +145,10 @@ const mavenGradleMetadataFailure = ( ), { retryable: false, - limit: mavenGradleFileBytesLimit(input.max_file_bytes), - remediationAction: inputBudgetRemediation(input), + limit: { + ...mavenGradleFileBytesLimit(input.max_file_bytes), + ...selectedFileRequirement(failure), + }, }, ), unclassified: (failure, origin) => diff --git a/src/nuget/NugetNupkgProvider.ts b/src/nuget/NugetNupkgProvider.ts index 7834d1b5314..89161ac8dd0 100644 --- a/src/nuget/NugetNupkgProvider.ts +++ b/src/nuget/NugetNupkgProvider.ts @@ -7,6 +7,7 @@ import { projectStableArtifactFailure, translateArtifactFailure, withStableArtifactHandle, + selectedFileRequirement, } from "../resources/index.js"; import { isParseLimit, @@ -31,13 +32,24 @@ import { parseNugetNupkg } from "./NugetNupkgParser.js"; const OPERATION = "inspect_nuget_nupkg"; -/** The refusal options for an exhausted per-call budget. */ -const budgetRecovery = (parameter: NugetNupkgBudget, selected: number) => ({ - limit: nugetNupkgBudgetLimit(parameter, selected), - remediationAction: - selected >= NUGET_NUPKG_BUDGETS[parameter].maximum - ? `${parameter} is at this operation's maximum of ${String(NUGET_NUPKG_BUDGETS[parameter].maximum)}; select a complete artifact within that bound.` - : `Raise ${parameter} above ${String(selected)}, up to ${String(NUGET_NUPKG_BUDGETS[parameter].maximum)}, or select a smaller artifact. The budget applies on the next call; repeating the unchanged request does not raise it.`, +/** + * The typed limit of an exhausted per-call budget, so the shared refusal + * owner states the recovery. An early-stop read measures only a lower bound + * of the requirement, so it is reported as `required_value` only when even + * that bound exceeds the control's maximum: raising the budget cannot help. + */ +const budgetRecovery = ( + parameter: NugetNupkgBudget, + selected: number, + required?: number | bigint, +) => ({ + limit: { + ...nugetNupkgBudgetLimit(parameter, selected), + ...(typeof required === "number" && + required > NUGET_NUPKG_BUDGETS[parameter].maximum + ? { required_value: required } + : {}), + }, }); const nupkgFailure = ( @@ -71,7 +83,11 @@ const nupkgFailure = ( retryable: false, ...(parameter === undefined ? {} - : budgetRecovery(parameter, failure.failure.limit.maximum)), + : budgetRecovery( + parameter, + failure.failure.limit.maximum, + failure.failure.limit.required, + )), }, ); } @@ -113,7 +129,10 @@ const nupkgFailure = ( ), { retryable: false, - ...budgetRecovery("max_file_bytes", input.max_file_bytes), + limit: { + ...nugetNupkgBudgetLimit("max_file_bytes", input.max_file_bytes), + ...selectedFileRequirement(failure), + }, }, ), unclassified: (failure) => diff --git a/src/pcap/PcapProvider.ts b/src/pcap/PcapProvider.ts index 99cfe1b371e..e07b9a0eec0 100644 --- a/src/pcap/PcapProvider.ts +++ b/src/pcap/PcapProvider.ts @@ -19,6 +19,7 @@ import { PCAP_CAPTURE_HOST_REMEDIATION, type PcapRequest, type PcapOperation, + PCAP_PRODUCER_LIMITS, } from "../domain/pcap/pcapAnalysis.js"; import { AnalysisCancelledError, @@ -57,7 +58,6 @@ import { parseCapinfosOutput, prepareTsharkBaseOutput, } from "./PcapOutput.js"; -import { PCAP_PRODUCER_LIMITS } from "../domain/pcap/pcapAnalysis.js"; import type { AnalysisParameterLimit } from "../domain/analysisSettings.js"; import { resolveProducerLimits } from "../domain/producerResourceLimits.js"; import { @@ -288,6 +288,16 @@ class RetainedSnapshotFailure implements AnalysisCleanupReleaseClaim { } /** Inspect saved captures through bounded, owned tool processes and one stable input copy. */ +/** + * Whether raising the DNS pass's limit can run it: not when the limit is + * already at its maximum or the measured requirement is above it. + */ +const dnsLimitRecovery = (limit: AnalysisParameterLimit): string => + limit.effective_value >= limit.maximum || + (limit.required_value !== undefined && limit.required_value > limit.maximum) + ? `it cannot be raised far enough (maximum ${String(limit.maximum)}), so the DNS pass cannot run on this capture` + : "raise it on the next call to run the DNS pass"; + export class PcapProvider { readonly #resources: ArtifactAnalysisResources; private readonly environment: Readonly>; @@ -1299,7 +1309,7 @@ export class PcapProvider { cause.limit.control_kind === "parameter" ) dnsIdentityLimit = cause.limit; - dnsLimitation = `DNS wire identity extraction was unavailable: ${dnsFailureReason(cause)}; producer queries and addresses are retained without inferred ownership${dnsIdentityLimit === undefined ? "" : `. dns_identity_limit names ${dnsIdentityLimit.parameter}; raise it on the next call to run the DNS pass`}`; + dnsLimitation = `DNS wire identity extraction was unavailable: ${dnsFailureReason(cause)}; producer queries and addresses are retained without inferred ownership${dnsIdentityLimit === undefined ? "" : `. dns_identity_limit names ${dnsIdentityLimit.parameter}; ${dnsLimitRecovery(dnsIdentityLimit)}`}`; } } else { dnsLimitation = diff --git a/src/resources/ArtifactOperationFailure.test.ts b/src/resources/ArtifactOperationFailure.test.ts index 448d775396f..15b30fc06c7 100644 --- a/src/resources/ArtifactOperationFailure.test.ts +++ b/src/resources/ArtifactOperationFailure.test.ts @@ -18,7 +18,6 @@ import { translateArtifactFailure } from "./ArtifactOperationFailure.js"; import { projectAnalysisError } from "../domain/analysisErrorProjection.js"; import { constants as bufferConstants } from "node:buffer"; import { - imageFileSizeRemediation, projectOwnedArtifactInputFailure, projectStableArtifactFailure, readerIntegrityFailure, @@ -222,16 +221,6 @@ it("leaves opaque operation errors and decode limits with their owning projectio ).toBeUndefined(); }); -// The provider ceiling test uses a sparse file and is skipped on Windows. -it.skipIf(process.platform !== "win32")( - "names the fixed image ceiling when the selected budget is already maximal", - () => { - expect(imageFileSizeRemediation(1024, 1024)).toContain( - "no runtime override", - ); - }, -); - it.each([ { effective: 1, required: bufferConstants.MAX_STRING_LENGTH + 1 }, { effective: bufferConstants.MAX_STRING_LENGTH, required: undefined }, diff --git a/src/resources/StableArtifactFailure.ts b/src/resources/StableArtifactFailure.ts index 87f6d27cd74..7a769ec2553 100644 --- a/src/resources/StableArtifactFailure.ts +++ b/src/resources/StableArtifactFailure.ts @@ -174,14 +174,18 @@ export const projectSelectedArtifactFileFailure = ( return undefined; }; -/** Explain the selected image read budget and its fixed upper bound. */ -export const imageFileSizeRemediation = ( - selectedBytes: number, - maximumBytes: number, -): string => - selectedBytes >= maximumBytes - ? `The image exceeds the ${String(maximumBytes)}-byte input ceiling this operation accepts. This release has no runtime override. Select a smaller artifact.` - : `Raise max_file_bytes above ${String(selectedBytes)} bytes or select a smaller artifact; the limit is the caller-selected input read budget.`; +/** + * The selected file's measured size as a refused file-size budget's + * `required_value`, so the shared refusal owner can say whether raising the + * budget can admit the file. + */ +export const selectedFileRequirement = ( + cause: ArtifactReaderFailure, +): { readonly required_value?: number } => + cause.observedBytes !== undefined && + cause.observedBytes <= BigInt(Number.MAX_SAFE_INTEGER) + ? { required_value: Number(cause.observedBytes) } + : {}; /** Name an observed regular-file retry that admission will validate again. */ export const regularFileSymlinkRecovery = (resolvedPath: string): string => diff --git a/src/resources/index.ts b/src/resources/index.ts index c470996f380..3533df448d1 100644 --- a/src/resources/index.ts +++ b/src/resources/index.ts @@ -98,7 +98,7 @@ export type { RetainedResourceScope, } from "./ArtifactResourceScope.js"; export { - imageFileSizeRemediation, + selectedFileRequirement, closeArtifactResources, artifactFileCleanupError, projectArtifactCloseFailure, diff --git a/src/vsix/VsixPackageProvider.ts b/src/vsix/VsixPackageProvider.ts index fa9e186bf92..208cf2b9aeb 100644 --- a/src/vsix/VsixPackageProvider.ts +++ b/src/vsix/VsixPackageProvider.ts @@ -10,6 +10,7 @@ import { readStableArtifact, translateArtifactFailure, type StableArtifactSnapshot, + selectedFileRequirement, } from "../resources/index.js"; import { classifyProviderFailure, @@ -78,7 +79,10 @@ const vsixFileSizeFailure = ( { ...details, retryable: false, - ...budgetRecovery("max_file_bytes", input.max_file_bytes), + limit: { + ...vsixPackageBudgetLimit("max_file_bytes", input.max_file_bytes), + ...selectedFileRequirement(cause), + }, }, ); diff --git a/tests/boundary/mcp/nugetNupkgMcp.test.ts b/tests/boundary/mcp/nugetNupkgMcp.test.ts index 5ee6e213552..49526ccc476 100644 --- a/tests/boundary/mcp/nugetNupkgMcp.test.ts +++ b/tests/boundary/mcp/nugetNupkgMcp.test.ts @@ -148,6 +148,33 @@ mcpTest( }, ); +mcpTest( + "does not advise a larger budget than the maximum a measured .nuspec needs", + async ({ mcp }) => { + const { client, session } = await connect(mcp); + try { + const root = await createTestTempDirectory("rea-nupkg-mcp-nuspec-"); + const path = join(root, "Large.Nuspec.nupkg"); + // A .nuspec one byte past the 16 MiB max_nuspec_bytes maximum. + const maximum = 16 * 1024 * 1024; + const nuspec = ``; + await writeFile(path, await nugetNupkgFixture({ nuspec })); + const response = await client.callTool({ + name: "inspect_nuget_nupkg", + arguments: { path, max_nuspec_bytes: 1024 }, + }); + const { error } = parseMcpToolError(response); + expect(error.code).toBe("resource_constraint"); + expect(error.remediation.action).toContain( + `The request requires ${String(maximum + 1)} bytes, above the max_nuspec_bytes maximum`, + ); + expect(error.remediation.action).not.toMatch(/Raise max_nuspec_bytes/u); + } finally { + await session.close(); + } + }, +); + mcpTest( "summarizes a package over the agent result budget and keeps complete Evidence retained", async ({ mcp }) => {