fix(hopper): preserve launcher evidence on readiness timeout
This commit is contained in:
@@ -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.`;
|
||||
|
||||
@@ -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 }),
|
||||
|
||||
@@ -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`,
|
||||
|
||||
+42
-22
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user