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
+58 -13
View File
@@ -108,6 +108,7 @@ export type GhidraProviderClientFactory = (
Partial<
Pick<
GhidraClient,
| "callToolIfReady"
| "operationHealthSnapshot"
| "runtimeLineage"
| "readTargetSnapshot"
@@ -667,6 +668,40 @@ export const createGhidraProviderClient = (input: {
startupTimeoutMs: config.ghidraStartupTimeoutMs,
})
: undefined;
const projectExecution = (
operation: AnalysisOperation,
normalized: JsonValue,
rawResult: JsonValue,
observationLimitations: readonly string[] = [],
) => {
const relationshipCoverage = relationshipCoverageFor(operation);
return createAnalysisExecution(normalized, committedProfile.provider, {
rawResult,
analysisProfile: committedProfile,
...(relationshipCoverage === undefined ? {} : { relationshipCoverage }),
limitations: [
...limitationsFor(operation),
...observationLimitations,
...sessionLimitations(),
],
});
};
const inventoryExecution = (
operation: "list_documents" | "list_procedures",
called: Result<JsonValue, GhidraSessionError>,
) => {
if (!called.ok)
return err(
projectSessionError(
operation,
called.error,
config.ghidraStartupTimeoutMs,
),
);
const parsed = parseGhidraInventoryResult(operation, called.value);
if (!parsed.ok) return parsed;
return ok(projectExecution(operation, parsed.value, called.value));
};
return {
execute: async (operation, parameters, options) => {
if (extensionFailure !== undefined) return err(extensionFailure);
@@ -724,6 +759,8 @@ export const createGhidraProviderClient = (input: {
? {}
: { progress: options.progress }),
});
if (operation === "list_documents" || operation === "list_procedures")
return inventoryExecution(operation, called);
if (!called.ok)
return err(
projectSessionError(
@@ -827,22 +864,30 @@ export const createGhidraProviderClient = (input: {
if (!attested.ok) return attested;
normalized = attested.value;
}
const relationshipCoverage = relationshipCoverageFor(operation);
return ok(
createAnalysisExecution(normalized, committedProfile.provider, {
rawResult: called.value,
analysisProfile: committedProfile,
...(relationshipCoverage === undefined
? {}
: { relationshipCoverage }),
limitations: [
...limitationsFor(operation),
...observationLimitations,
...sessionLimitations(),
],
}),
projectExecution(
operation,
normalized,
called.value,
observationLimitations,
),
);
},
executeIfReady: async (operation, parameters, options) => {
if (operation !== "list_documents" && operation !== "list_procedures")
return undefined;
if (extensionFailure !== undefined) return err(extensionFailure);
const input = parseGhidraInventoryInput(operation, parameters);
if (!input.ok) return input;
if (client.callToolIfReady === undefined) return undefined;
const called = await client.callToolIfReady(
operation,
input.value,
options?.signal === undefined ? {} : { signal: options.signal },
);
if (called === undefined) return undefined;
return inventoryExecution(operation, called);
},
operationHealthSnapshot: () => client.operationHealthSnapshot?.(),
runtimeLineageSnapshots: () => {
const observation = client.runtimeLineage?.() ?? null;