fix(mcp): keep prompt completion within ready provider sessions

Avoid lazy provider startup for document and procedure completion. Propagate MCP cancellation through completers, cancel lookups during session transitions, and share provider result projection with ordinary operations. Cover cold, starting, warm, queued, cancelled, and closed sessions through MCP composition and provider boundaries.
This commit is contained in:
morluto
2026-10-12 16:27:51 +08:00
parent 0d5033ad12
commit 07b36c1489
16 changed files with 740 additions and 57 deletions
+54 -32
View File
@@ -5,6 +5,7 @@ import { accessSync, constants, statSync } from "node:fs";
import { createAnalysisExecution } from "../application/AnalysisProvider.js";
import type {
AnalysisClient,
AnalysisOperation,
AnalysisClientContext,
AnalysisProfileResolutionOptions,
AnalysisProviderCandidate,
@@ -16,6 +17,7 @@ import type {
import type { AnalysisProfileCommitment } from "../domain/analysisProfile.js";
import type { AppConfig } from "../config/types.js";
import type { BinaryTarget } from "../domain/binaryTargetTypes.js";
import type { JsonValue } from "../domain/jsonValue.js";
import type { Logger } from "pino";
import { AnalysisCapabilityUnavailableError } from "../domain/analysisErrorCore.js";
import { err, ok } from "../domain/result.js";
@@ -251,6 +253,40 @@ export class HopperProvider implements AnalysisProviderCandidate {
this.logger.info(diagnostic, "Hopper bridge reported a diagnostic"),
});
const regexSearch = new HopperRegexSearch(client);
const projectExecution = (
operation: AnalysisOperation,
normalized: JsonValue,
rawResult: JsonValue | null = null,
) =>
createAnalysisExecution(normalized, executionProvider, {
// Only the file-offset mapping differs from Hopper's reply.
rawResult,
...(profile === undefined ? {} : { analysisProfile: profile }),
...(operation === "procedure_callers" ||
operation === "procedure_callees"
? { relationshipCoverage: { status: "complete" as const } }
: {}),
limitations: [
...(preparedImage === undefined
? []
: [
"REA loaded a verified thin Mach-O slice from the original FAT64 source. Identity and file offsets refer to the original file. The owned temporary image and its Hopper document close together, including on MCP shutdown.",
]),
...(CAPABILITIES.find(
(descriptor) => descriptor.operation === operation,
)?.limitations ?? []),
...(operation === "read_bytes"
? [
"Hopper byte reads stop at the containing segment's exclusive end; a readable prefix is returned with complete=false when the requested range crosses it.",
]
: []),
...(operation === "procedure_references"
? [
"Native CallReference classifications and unresolved targets are preserved. Detailed reference flags and coverage beyond reported CallReference objects remain unknown.",
]
: []),
],
});
return {
execute: async (operation, parameters, options) => {
const result =
@@ -265,40 +301,26 @@ export class HopperProvider implements AnalysisProviderCandidate {
? await mapHopperFileOffset(target, result.value, options?.signal)
: result;
return mapped.ok
? {
ok: true,
value: createAnalysisExecution(mapped.value, executionProvider, {
// Only the file-offset mapping differs from Hopper's reply.
rawResult: mapped === result ? null : result.value,
...(profile === undefined ? {} : { analysisProfile: profile }),
...(operation === "procedure_callers" ||
operation === "procedure_callees"
? { relationshipCoverage: { status: "complete" as const } }
: {}),
limitations: [
...(preparedImage === undefined
? []
: [
"REA loaded a verified thin Mach-O slice from the original FAT64 source. Identity and file offsets refer to the original file. The owned temporary image and its Hopper document close together, including on MCP shutdown.",
]),
...(CAPABILITIES.find(
(descriptor) => descriptor.operation === operation,
)?.limitations ?? []),
...(operation === "read_bytes"
? [
"Hopper byte reads stop at the containing segment's exclusive end; a readable prefix is returned with complete=false when the requested range crosses it.",
]
: []),
...(operation === "procedure_references"
? [
"Native CallReference classifications and unresolved targets are preserved. Detailed reference flags and coverage beyond reported CallReference objects remain unknown.",
]
: []),
],
}),
}
? ok(
projectExecution(
operation,
mapped.value,
mapped === result ? null : result.value,
),
)
: mapped;
},
executeIfReady: async (operation, parameters, options) => {
if (operation !== "list_documents" && operation !== "list_procedures")
return undefined;
const result = await client.callToolIfReady(
operation,
parameters,
options?.signal === undefined ? {} : { signal: options.signal },
);
if (result === undefined || !result.ok) return result;
return ok(projectExecution(operation, result.value));
},
runtimeLineageSnapshots: () => {
const observation = client.runtimeLineage();
return observation === null