Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(hopper): preserve launcher evidence on readiness timeout

morluto458771cb583e
diff --git a/src/domain/analysisErrorPresentation.ts b/src/domain/analysisErrorPresentation.ts
index 56b0ad273..66cdb5caf 100644
--- a/src/domain/analysisErrorPresentation.ts
+++ b/src/domain/analysisErrorPresentation.ts
@@ -52,9 +52,11 @@ export const analysisErrorRemediationAction = (
: "Review the reported worker memory limits and available host memory. Retry with sufficient memory or a smaller artifact; REA retains tighter inherited limits.")
);
if (error instanceof HopperTimeoutError)
- return error.providerState === "busy"
- ? "Check binary_session.analysis_activity, wait for the active Hopper request to finish, then retry."
- : "Check binary_session for Hopper health, then retry the operation.";
+ return error.operation === undefined
+ ? "Inspect Hopper for a loader or license dialog and review details.launcher. Correct the loader configuration or complete Hopper setup, then open the target again."
+ : error.providerState === "busy"
+ ? "Check binary_session.analysis_activity, wait for the active Hopper request to finish, then retry."
+ : "Check binary_session for Hopper health, then retry the operation.";
if (error instanceof HopperProcessError)
return hopperProcessRemediation(error);
if (error instanceof HopperStartError)
@@ -201,7 +203,9 @@ export const analysisErrorUserMessage = (error: AnalysisError): string => {
const hopperErrorUserMessage = (error: AnalysisError): string | undefined => {
if (error instanceof HopperTimeoutError) {
- const request = error.operation ?? "startup";
+ if (error.operation === undefined)
+ return "REA timed out waiting for Hopper bridge readiness. Hopper may be waiting for a loader or license dialog; inspect its window and the captured launcher outcome before retrying.";
+ const request = error.operation;
return error.providerState === "busy"
? `Hopper timed out during ${request} while the provider remained busy. Check binary_session.analysis_activity, wait for the active request to finish, then retry.`
: `Hopper timed out during ${request} before it started. Check binary_session for provider health, then retry.`;
diff --git a/src/domain/analysisErrorProjection.ts b/src/domain/analysisErrorProjection.ts
index 1e14bde97..39509368a 100644
--- a/src/domain/analysisErrorProjection.ts
+++ b/src/domain/analysisErrorProjection.ts
@@ -445,6 +445,9 @@ const lifecycleErrorDetails = (
return {
stage: error.operation === undefined ? "startup" : error.stage,
timeout_ms: error.timeoutMs,
+ ...(error.launcherOutcome === undefined
+ ? {}
+ : { launcher: error.launcherOutcome }),
provider_state: error.providerState,
retry_action: error.providerState === "busy" ? "wait" : "retry",
...(error.operation === undefined ? {} : { operation: error.operation }),
diff --git a/src/domain/hopperErrors.ts b/src/domain/hopperErrors.ts
index 2246bdec5..68c5b9ee4 100644
--- a/src/domain/hopperErrors.ts
+++ b/src/domain/hopperErrors.ts
@@ -35,6 +35,7 @@ export class HopperTimeoutError extends HopperError {
readonly stage: ProviderFailureStage = operation === undefined
? "launch"
: "analysis",
+ readonly launcherOutcome?: HopperLauncherOutcome,
) {
super(
`Hopper ${operation === undefined ? "startup" : operation} timed out after ${String(timeoutMs)}ms`,
diff --git a/src/hopper/HopperClient.ts b/src/hopper/HopperClient.ts
index c8c49958c..20430c16e 100644
--- a/src/hopper/HopperClient.ts
+++ b/src/hopper/HopperClient.ts
@@ -502,7 +502,8 @@ export class HopperClient {
deadline: ProviderStartupDeadline,
): Promise<Result<undefined, HopperError>> {
while (deadline.remainingMs() > 0) {
- if (deadline.signal.aborted) return err(startupInterruption(deadline));
+ if (deadline.signal.aborted)
+ return err(await this.#startupInterruption(deadline));
if (this.#closing) return err(new HopperProcessError(null));
if (
this.#launcherExitCode !== undefined &&
@@ -516,7 +517,7 @@ export class HopperClient {
deadline,
);
return deadline.interruption === "cancelled"
- ? err(startupInterruption(deadline))
+ ? err(await this.#startupInterruption(deadline))
: err(failure);
}
try {
@@ -525,7 +526,7 @@ export class HopperClient {
// best-effort cleanup: socket polling; absence means keep waiting.
void cause;
if ((await deadline.wait(50)) === "aborted")
- return err(startupInterruption(deadline));
+ return err(await this.#startupInterruption(deadline));
continue;
}
const attempt = await connectHopperSocketOnce(
@@ -538,9 +539,44 @@ export class HopperClient {
return ok(undefined);
}
if ((await deadline.wait(50)) === "aborted")
- return err(startupInterruption(deadline));
+ return err(await this.#startupInterruption(deadline));
}
- return err(new HopperTimeoutError(this.#options.startupTimeoutMs));
+ return err(await this.#startupInterruption(deadline));
+ }
+
+ async #startupInterruption(
+ deadline: ProviderStartupDeadline,
+ ): Promise<HopperCancelledError | HopperTimeoutError> {
+ if (deadline.interruption === "cancelled")
+ return new HopperCancelledError();
+ return new HopperTimeoutError(
+ deadline.timeoutMs,
+ undefined,
+ undefined,
+ "not_started",
+ "launch",
+ this.#launcherOutcome(
+ (await this.#process?.waitForOutputClose(0)) ?? false,
+ ),
+ );
+ }
+
+ #launcherOutcome(outputClosed: boolean): HopperLauncherOutcome | undefined {
+ const snapshot = this.#process?.snapshot();
+ const token = this.#token;
+ if (snapshot === undefined) return undefined;
+ const redact = (text: string): string =>
+ token === undefined
+ ? text
+ : text.replaceAll(token, "[redacted transport credential]");
+ return {
+ exit_code: snapshot.exitCode ?? null,
+ signal: snapshot.signal ?? null,
+ stdout: { ...snapshot.stdout, text: redact(snapshot.stdout.text) },
+ stderr: { ...snapshot.stderr, text: redact(snapshot.stderr.text) },
+ output_closed: outputClosed,
+ diagnostic_truncated: snapshot.diagnosticTruncated === true,
+ };
}
async #launcherStartupFailure(
@@ -549,29 +585,13 @@ export class HopperClient {
deadline: ProviderStartupDeadline,
): Promise<HopperError> {
const process = this.#process;
- const token = this.#token;
// Descendants may inherit the helper's pipes. Bound drainage independently
// from readiness, and report whether producer output actually closed.
const outputClosed =
(await process?.waitForOutputClose(
Math.min(1_000, deadline.remainingMs()),
)) ?? false;
- const snapshot = process?.snapshot();
- const redact = (text: string): string =>
- token === undefined
- ? text
- : text.replaceAll(token, "[redacted transport credential]");
- const launcherFailure: HopperLauncherOutcome | undefined =
- snapshot === undefined
- ? undefined
- : {
- exit_code: exitCode,
- signal: snapshot.signal ?? null,
- stdout: { ...snapshot.stdout, text: redact(snapshot.stdout.text) },
- stderr: { ...snapshot.stderr, text: redact(snapshot.stderr.text) },
- output_closed: outputClosed,
- diagnostic_truncated: snapshot.diagnosticTruncated === true,
- };
+ const launcherFailure = this.#launcherOutcome(outputClosed);
if (ownsProviderLifetime)
return new HopperProcessError(
exitCode,
diff --git a/tests/boundary/providers/hopper/hopperClient.helperFailure.test.ts b/tests/boundary/providers/hopper/hopperClient.helperFailure.test.ts
index a99542fc4..b7be9ea19 100644
--- a/tests/boundary/providers/hopper/hopperClient.helperFailure.test.ts
+++ b/tests/boundary/providers/hopper/hopperClient.helperFailure.test.ts
@@ -134,3 +134,48 @@ it.each([0, 1])(
});
},
);
+
+it("preserves a successful helper's diagnostics when bridge readiness is never observed", async () => {
+ let token = "";
+ const launcher: BridgeLauncher = {
+ launch(session) {
+ token = session.token;
+ return Promise.resolve(
+ ok({
+ process: spawn(
+ process.execPath,
+ [
+ "-e",
+ `process.stdout.write(${JSON.stringify("source=local-evidence ")} + ${JSON.stringify(session.token)}); process.stderr.write("loader callback pending");`,
+ ],
+ { stdio: ["ignore", "pipe", "pipe"] },
+ ),
+ ownsProcessLifetime: false as const,
+ providerLifetime: "external-application" as const,
+ shutdownMode: "bridge-request" as const,
+ }),
+ );
+ },
+ };
+ const client = new HopperClient({ launcher, startupTimeoutMs: 1500 });
+ onTestFinished(() => client.close());
+ const result = await client.start();
+ if (result.ok)
+ throw new Error("Expected missing bridge readiness to time out");
+ const projected = projectAnalysisError(result.error);
+ expect(projected).toMatchObject({
+ code: "provider_timeout",
+ details: {
+ stage: "startup",
+ launcher: {
+ exit_code: 0,
+ output_closed: true,
+ stdout: { text: expect.stringContaining("source=local-evidence") },
+ stderr: { text: "loader callback pending" },
+ },
+ },
+ });
+ expect(projected.message).toContain("bridge readiness");
+ expect(projected.message).not.toContain("before it started");
+ expect(JSON.stringify(projected)).not.toContain(token);
+});