From 07540cbcde9cacda43c3758ec8e6ac9c868c983e Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Wed, 14 Oct 2026 14:46:34 +0800 Subject: [PATCH] fix(evm): preserve transferred cleanup ownership and bounded output Retain a worker owner transferred through the callback when a failure has no replacement owner. Give captured streams one canonical owner while preserving unrelated diagnostics and partial Evidence. Linux retained-cleanup coverage requires CI. --- src/evm/EvmoleFailures.ts | 10 ++----- src/evm/EvmoleInterfaceProvider.ts | 17 +++++++++-- .../evm/evmoleInterfaceProvider.test.ts | 29 +++++++++---------- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/evm/EvmoleFailures.ts b/src/evm/EvmoleFailures.ts index 63c6578aae..da1bae8d85 100644 --- a/src/evm/EvmoleFailures.ts +++ b/src/evm/EvmoleFailures.ts @@ -183,6 +183,9 @@ export const evmInterfaceFailure = ( { cause, ...cleanupOptions, + ...(cause instanceof OwnedCommandFailure && cause.snapshot !== null + ? { capturedOutput: capturedEvmOutput(cause.snapshot) } + : {}), diagnostics: { phase, path, @@ -198,13 +201,6 @@ export const evmInterfaceFailure = ( failure_kind: cause.reason, exit_code: cause.snapshot?.exitCode ?? null, signal: cause.snapshot?.signal ?? null, - stdout: cause.snapshot?.stdout.text ?? null, - stderr: cause.snapshot?.stderr.text ?? null, - ...(cause.snapshot === null - ? {} - : { - captured_output: { ...capturedEvmOutput(cause.snapshot) }, - }), } : {}), }, diff --git a/src/evm/EvmoleInterfaceProvider.ts b/src/evm/EvmoleInterfaceProvider.ts index 3628164118..1868945a98 100644 --- a/src/evm/EvmoleInterfaceProvider.ts +++ b/src/evm/EvmoleInterfaceProvider.ts @@ -85,6 +85,16 @@ const replySchema = z.discriminatedUnion("ok", [ type Launcher = NonNullable[2]>["launcher"]; type EvmOutcome = Result; +const compactErrorProjection = (error: AnalysisError) => { + const projection = projectAnalysisError(error); + if (error.capturedOutput === undefined) return projection; + // The cleanup result owns this exact captured stream. Other diagnostics and + // partial Evidence retain their original fields, including stdout/stderr. + const details = { ...projection.details }; + delete details.captured_output; + return { ...projection, details }; +}; + const evmExecutionEvidence = ( input: InspectEvmInterfaceInput, execution: EvmInterfaceExecution, @@ -118,7 +128,7 @@ const evmCleanupFailure = ( resources, { reason, - previous_error: result.ok ? null : projectAnalysisError(result.error), + previous_error: result.ok ? null : compactErrorProjection(result.error), ...(capturedOutput === undefined ? {} : { captured_output: { ...capturedOutput } }), @@ -444,7 +454,10 @@ export class EvmoleInterfaceProvider implements EvmInterfacePort { }), ); } catch (cause: unknown) { - if (cause instanceof OwnedCommandFailure) + if ( + cause instanceof OwnedCommandFailure && + cause.cleanupOwner !== undefined + ) processOwner = cause.cleanupOwner; let fileFailure: EvmFileSizeFailureEvidence | undefined; let markerCleanupFailure: ArtifactReaderFailure | undefined; diff --git a/tests/boundary/evm/evmoleInterfaceProvider.test.ts b/tests/boundary/evm/evmoleInterfaceProvider.test.ts index e83a6e4c01..51b5cb54ad 100644 --- a/tests/boundary/evm/evmoleInterfaceProvider.test.ts +++ b/tests/boundary/evm/evmoleInterfaceProvider.test.ts @@ -112,12 +112,12 @@ it.runIf(!unsupportedHost).each(["missing", "wrong"])( if (result.ok) throw new Error("Expected launcher failure"); expect(projectAnalysisError(result.error).code).toBe("execution_failure"); expect(result.error).toMatchObject({ + capturedOutput: { stdout: "launcher failure", truncated: false }, diagnostics: { file_size_failure_marker: { verified: false, failure: expect.any(String), }, - captured_output: { stdout: "launcher failure", truncated: false }, }, }); await expect(access(ownedPath)).rejects.toMatchObject({ code: "ENOENT" }); @@ -163,16 +163,12 @@ it.runIf(!unsupportedHost)( const cleanup = z .object({ reason: z.string(), - previous_error: z - .object({ - failure_kind: z.string(), - stdout: z.unknown().optional(), - stderr: z.unknown().optional(), - }) - .transform(({ failure_kind, stdout, stderr }) => ({ - failure_kind, - output_repeated: stdout !== undefined || stderr !== undefined, - })), + previous_error: z.object({ + code: z.string(), + category: z.string(), + message: z.string(), + details: z.record(z.string(), z.unknown()).optional(), + }), captured_output: z.object({ truncated: z.boolean(), stderr: z.literal(""), @@ -182,12 +178,13 @@ it.runIf(!unsupportedHost)( .parse(projectAnalysisError(result.error).details?.["diagnostics"]); expect(cleanup).toEqual({ reason: "injected post-cleanup reporting failure", - previous_error: { - failure_kind: "output-limit", - output_repeated: false, - }, + previous_error: expect.objectContaining({ code: "unreadable_output" }), captured_output: { truncated: true, stderr: "", stdout: 1048576 }, }); + expect(cleanup.previous_error.details?.["captured_output"]).toBeUndefined(); + expect(JSON.stringify(cleanup.previous_error)).not.toContain( + "x".repeat(256), + ); expect(result.error.cleanupResources).toContain(ownedPath); await access(ownedPath); const blocked = await provider.inspect({ path, encoding: "hex" }); @@ -266,7 +263,7 @@ it.runIf(!unsupportedHost).each(["completed", "malformed-reply"] as const)( reason: "injected retained cleanup failure", captured_output: { stderr: "worker completed", truncated: false }, ...(scenario === "malformed-reply" - ? { previous_error: { code: "output_failure" } } + ? { previous_error: { code: "unreadable_output" } } : { previous_error: null }), }); if (scenario === "completed")