fix(ghidra): report progress while startup is pending (#1877)

Forward Ghidra startup waiting observations through the existing progress reporter. Count emitted MCP status notifications and omit the unknown total to keep progress strictly increasing.

Verified with focused tests, type/lint/docs checks, packaging and actual installed Windows timeout/recovery workflows. Native first-query speed and large-target memory remain open under #1065.

Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
This commit is contained in:
Ysopwnable
2026-10-11 23:55:39 +08:00
committed by GitHub
co-authored by Kaoru0822
parent fa9a7e5ec0
commit 29d2624b34
8 changed files with 204 additions and 34 deletions
+47 -3
View File
@@ -1,5 +1,6 @@
import { randomBytes, randomUUID } from "node:crypto";
import type { Socket } from "node:net";
import type { ProgressReporter } from "../application/ProgressReporter.js";
import { AnalysisError } from "../domain/analysisErrorBase.js";
import type { JsonValue } from "../domain/jsonValue.js";
@@ -162,7 +163,12 @@ export class GhidraClient {
}
/** Launch Ghidra once and require its exact post-analysis handshake. */
start(signal?: AbortSignal): Promise<GhidraStartResult> {
start(
signal?: AbortSignal,
progress?: ProgressReporter,
): Promise<GhidraStartResult> {
if (progress !== undefined)
return this.#reportStartupWait(this.start(signal), signal, progress);
if (this.#closePromise !== undefined)
return this.#closePromise.then(
() => this.start(signal),
@@ -216,6 +222,41 @@ export class GhidraClient {
return started;
}
async #reportStartupWait(
started: Promise<GhidraStartResult>,
signal: AbortSignal | undefined,
progress: ProgressReporter,
): Promise<GhidraStartResult> {
const startedAt = performance.now();
let active = true;
let reporting = false;
const timer = setInterval(() => {
if (!active || reporting || signal?.aborted) return;
reporting = true;
void Promise.resolve()
.then(() => {
if (!active || signal?.aborted) return;
return progress.report({
phase: "ghidra_startup",
completed: 0,
total: null,
message: `Waiting for Ghidra startup (${String(Math.floor((performance.now() - startedAt) / 1000))}s elapsed); import, auto-analysis and bridge readiness may still be pending`,
});
})
// Notification failure does not release the owned startup process.
.catch(() => {})
.finally(() => {
reporting = false;
});
}, 10_000);
try {
return await started;
} finally {
active = false;
clearInterval(timer);
}
}
/** Revalidate live bridge, provider, run, and profile metadata. */
async ping(
options: GhidraRequestOptions = {},
@@ -231,9 +272,12 @@ export class GhidraClient {
async callTool(
operation: GhidraOperation,
parameters: Readonly<Record<string, JsonValue>>,
options: { readonly signal?: AbortSignal } = {},
options: {
readonly signal?: AbortSignal;
readonly progress?: ProgressReporter;
} = {},
): Promise<Result<JsonValue, GhidraSessionError>> {
const started = await this.start(options.signal);
const started = await this.start(options.signal, options.progress);
if (!started.ok) return started;
return this.#requestQueue.run(
operation,
+12 -8
View File
@@ -573,7 +573,7 @@ export const createGhidraProviderClient = (input: {
),
);
if (operation === "health") {
const started = await client.start(options?.signal);
const started = await client.start(options?.signal, options?.progress);
if (!started.ok)
return err(
projectSessionError(
@@ -596,7 +596,7 @@ export const createGhidraProviderClient = (input: {
: parseGhidraInventoryInput(operation, parameters);
if (!input.ok) return input;
if (extensions.length > 0 || seeds !== undefined) {
const started = await client.start(options?.signal);
const started = await client.start(options?.signal, options?.progress);
if (!started.ok)
return err(
projectSessionError(
@@ -608,11 +608,12 @@ export const createGhidraProviderClient = (input: {
const failed = await checkExtensions(operation, started.value);
if (failed !== undefined) return err(failed);
}
const called = await client.callTool(
operation,
input.value,
options?.signal === undefined ? {} : { signal: options.signal },
);
const called = await client.callTool(operation, input.value, {
...(options?.signal === undefined ? {} : { signal: options.signal }),
...(options?.progress === undefined
? {}
: { progress: options.progress }),
});
if (!called.ok)
return err(
projectSessionError(
@@ -637,7 +638,10 @@ export const createGhidraProviderClient = (input: {
const address = input.value.address;
if (typeof address === "string") {
if (target.format === "pe" && nativeAotOwner !== undefined) {
const started = await client.start(options?.signal);
const started = await client.start(
options?.signal,
options?.progress,
);
if (!started.ok)
return err(
projectSessionError(
+4 -2
View File
@@ -22,8 +22,10 @@ export const mcpProgressReporter = (
method: "notifications/progress",
params: {
progressToken: token,
progress: update.completed,
...(update.total === null ? {} : { total: update.total }),
// Status phases can repeat their work count while waiting. The
// protocol requires every notification to advance; count emitted
// observations without inventing a total amount of analysis work.
progress: update.sequence,
message: `${update.phase}: ${update.message}`,
},
});
+4 -2
View File
@@ -67,8 +67,10 @@ describe("derived MCP operation boundary", () => {
);
expect(result).toEqual({ ok: true, value: "complete" });
expect(notifications.map(({ params }) => params?.progress)).toEqual([0, 2]);
expect(notifications.every(({ params }) => params?.total === 2)).toBe(true);
expect(notifications.map(({ params }) => params?.progress)).toEqual([1, 2]);
expect(
notifications.every(({ params }) => params?.total === undefined),
).toBe(true);
});
it("projects synchronous computation failures into a typed result", async () => {