diff --git a/src/application/reverse/ReverseEngineeringService.ts b/src/application/reverse/ReverseEngineeringService.ts index 57126d6764..cbc312f3a4 100644 --- a/src/application/reverse/ReverseEngineeringService.ts +++ b/src/application/reverse/ReverseEngineeringService.ts @@ -40,6 +40,7 @@ import type { import { execFileOutput, execFileOutputFailure, + HOST_SPAWN_CAPACITY_CODES, } from "../../process/ExecFileOutput.js"; import { OwnedCommandFailure, @@ -579,6 +580,35 @@ export class ReverseEngineeringService { }, { cause, ...ownedCleanupOptions(cause) }, ); + if ( + earlyFailure === undefined && + typeof code === "string" && + HOST_SPAWN_CAPACITY_CODES.has(code) + ) { + const provider = + operation === "inspect_with_objdump" ? "objdump" : "rizin"; + const setting = + operation === "inspect_with_objdump" + ? "REA_OBJDUMP_COMMAND" + : "REA_RIZIN_COMMAND"; + earlyFailure = new AnalysisResourceConstraintError( + operation, + "capacity", + `The host ran out of process, memory or file-descriptor capacity (${code}) to start ${provider}.`, + { spawn_error: code, command }, + { + cause, + retryable: true, + remediationAction: `The host ran out of process, memory or file-descriptor capacity (${code}). Close unused processes or files, or raise the process or open-file limit of the REA process, then retry; ${setting} does not need to change.`, + diagnostics: { + boundary: "host-capacity", + command, + system_code: code, + }, + ...ownedCleanupOptions(cause), + }, + ); + } if ( earlyFailure === undefined && (capture === undefined || diff --git a/src/process/ExecFileOutput.ts b/src/process/ExecFileOutput.ts index a96837152e..09563bd531 100644 --- a/src/process/ExecFileOutput.ts +++ b/src/process/ExecFileOutput.ts @@ -132,7 +132,7 @@ export const execFileOutputFailure = ( }; /** Spawn errnos reporting exhausted host capacity rather than an unusable command. */ -const HOST_SPAWN_CAPACITY_CODES: ReadonlySet = new Set([ +export const HOST_SPAWN_CAPACITY_CODES: ReadonlySet = new Set([ "EAGAIN", "EMFILE", "ENFILE", diff --git a/tests/composition/reverseProviderLaunchErrors.test.ts b/tests/composition/reverseProviderLaunchErrors.test.ts index 9dc77bcc74..cbcf5e2f8d 100644 --- a/tests/composition/reverseProviderLaunchErrors.test.ts +++ b/tests/composition/reverseProviderLaunchErrors.test.ts @@ -63,6 +63,122 @@ it.each(["ENOENT", "EACCES", "EPERM", "ENOTDIR"] as const)( }, ); +it.each(["EAGAIN", "EMFILE", "ENFILE", "ENOMEM"] as const)( + "treats objdump host capacity spawn failure %s as retryable resource constraint without recording launch failure", + async (code) => { + const { directory, path } = await createArtifact(); + const command = resolve(directory, "configured-objdump"); + const hostFailure = Object.assign( + new Error("controlled host capacity rejection"), + { code }, + ); + const service = new TestReverseEngineeringService({ + environment: { REA_OBJDUMP_COMMAND: command }, + runOwned: async () => { + throw new OwnedCommandFailure("process", "launch failed", null, null, { + cause: hostFailure, + }); + }, + }); + try { + for (const input of [ + { operation: "architectures" }, + { path, operation: "file_headers" }, + ]) { + const result = await service.inspectWithObjdump(input); + if (result.ok) + throw new Error("Expected host capacity resource constraint failure"); + const projected = projectAnalysisError(result.error); + expect(projected).toMatchObject({ + code: "resource_constraint", + retryable: true, + details: { + resource: "capacity", + reported_limits: { + spawn_error: code, + command, + }, + diagnostics: { + boundary: "host-capacity", + command, + system_code: code, + }, + }, + remediation: { + action: expect.stringContaining( + "REA_OBJDUMP_COMMAND does not need to change", + ), + }, + }); + expect(projected.message).toContain(code); + expect(projected.remediation.action).toContain(code); + } + expect(service.observedLaunchFailures()).toEqual({}); + } finally { + await service.close(); + await rm(directory, { recursive: true, force: true }); + } + }, +); + +it.each(["EAGAIN", "EMFILE", "ENFILE", "ENOMEM"] as const)( + "treats rizin host capacity spawn failure %s as retryable resource constraint without recording launch failure", + async (code) => { + const { directory, path } = await createArtifact(); + const command = resolve(directory, "configured-rizin"); + const hostFailure = Object.assign( + new Error("controlled host capacity rejection"), + { code }, + ); + const service = new TestReverseEngineeringService({ + environment: { REA_RIZIN_COMMAND: command }, + runOwned: async () => { + throw new OwnedCommandFailure("process", "launch failed", null, null, { + cause: hostFailure, + }); + }, + }); + try { + const result = await service.executeRizinCommand({ + path, + command: "iI", + }); + if (result.ok) + throw new Error( + "Expected rizin host capacity resource constraint failure", + ); + const projected = projectAnalysisError(result.error); + expect(projected).toMatchObject({ + code: "resource_constraint", + retryable: true, + details: { + resource: "capacity", + reported_limits: { + spawn_error: code, + command, + }, + diagnostics: { + boundary: "host-capacity", + command, + system_code: code, + }, + }, + remediation: { + action: expect.stringContaining( + "REA_RIZIN_COMMAND does not need to change", + ), + }, + }); + expect(projected.message).toContain(code); + expect(projected.remediation.action).toContain(code); + expect(service.observedLaunchFailures()).toEqual({}); + } finally { + await service.close(); + await rm(directory, { recursive: true, force: true }); + } + }, +); + it("preserves target-read permission diagnostics before provider launch", async () => { let launches = 0; const path = resolve("read-denied-artifact");