Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
b0d8773
fix(node-sea): bound duplicate blob verification work
ShuaixinHuang Nov 13, 2026
8b5c792
Merge commit 'bd9f2cca45cb99c7460ab678f4fe6a3b12d6ba3a' into work/aud…
ShuaixinHuang Nov 15, 2026
85e84ff
Merge commit 'f916b3ecf5455ffc80e300d8cf7eea144d02d61c' into work/fin…
ShuaixinHuang Nov 15, 2026
010fa34
test(mcp): observe cleanup failures at their current delivery boundary
g1at Nov 16, 2026
50fb5ef
fix(mcp): preserve workflow completion progress through delivery
g1at Nov 16, 2026
f810ad1
test(setup): keep the Windows Kimi profile fixture on a supported pro…
IvenKooLab Nov 16, 2026
0199c9f
test(ci): restore verifier and MCP contract regressions
ShuaixinHuang Nov 16, 2026
439e091
Merge remote-tracking branch 'origin/main' into fix/ci-current-verifi…
ShuaixinHuang Nov 16, 2026
d540c4f
Merge remote-tracking branch 'prereq/11702' into fix/ci-current-verif…
ShuaixinHuang Nov 16, 2026
c4c4409
Merge remote-tracking branch 'prereq/11703' into fix/ci-current-verif…
ShuaixinHuang Nov 16, 2026
a1a3b89
Merge remote-tracking branch 'prereq/11725' into fix/ci-current-verif…
ShuaixinHuang Nov 16, 2026
5c44f5a
test(captures): assert adapter-owned input issue field names
ShuaixinHuang Nov 16, 2026
f93ba97
Merge commit '5c44f5af16aae3e61fa298257451639e690e9977' into repair/v…
ShuaixinHuang Nov 16, 2026
a8f98b7
fix(ghidra): avoid Java probes for missing installations
ShuaixinHuang Nov 16, 2026
4942d2d
Merge commit 'a8f98b7a951ba0c28cb91f7429d7461cad205ced' into repair/v…
ShuaixinHuang Nov 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(mcp): preserve workflow completion progress through delivery
  • Loading branch information
g1at committed Nov 16, 2026
commit 50fb5ef02d842318a56a489be5503859267c80b0
12 changes: 8 additions & 4 deletions src/server/contractToolBindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type { ArtifactResourceScope } from "../resources/index.js";
import {
type AnalysisWorkflow,
type AnalysisWorkflowOutcome,
type AnalysisWorkflowOptions,
type ApplicationWorkflowRequest,
createAnalysisToolHandler,
createApplicationToolHandler,
Expand Down Expand Up @@ -340,6 +341,7 @@ type ApplicationBinding<Input = unknown> =
*/
type AnalysisBinding<Input> = {
readonly admission: "sdk";
readonly completionProgress?: AnalysisWorkflowOptions["completionProgress"];
readonly run?: never;
readonly summary?: never;
readonly value?: never;
Expand Down Expand Up @@ -521,10 +523,9 @@ export const registerContractTools = (
| ValueBinding
| ApplicationBinding
| DerivedBinding
| {
| ({
readonly admission: "sdk";
readonly analyze: AnalysisWorkflow;
readonly detail?: "delivery";
readonly value?: never;
readonly workflow?: never;
readonly derive?: never;
Expand All @@ -533,7 +534,7 @@ export const registerContractTools = (
readonly mutation?: never;
readonly query?: never;
readonly provider?: never;
}
} & AnalysisWorkflowOptions)
| ExternalMutationBinding<unknown>
| QueryBinding<unknown>
| ProviderBinding<ProviderOperation>
Expand Down Expand Up @@ -591,7 +592,10 @@ export const registerContractTools = (
logger,
retention,
requiredAdmission(withAdmittedAnalysis, contract.name),
binding.detail === "delivery",
{
detail: binding.detail,
completionProgress: binding.completionProgress,
},
)(contract)
: binding.query !== undefined
? createValueToolHandler(
Expand Down
35 changes: 19 additions & 16 deletions src/server/contractToolHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ import type { InvestigationWorkflowExecution } from "../application/investigatio
import { withAdmittedAnalysis as sessionAdmission } from "./analysisAdmission.js";
import { deliverInvestigationWorkflow } from "./deliverInvestigationWorkflow.js";
import { runDerivedOperation } from "./runDerivedOperation.js";
import {
reportOperationEnd,
reportOperationStart,
} from "./operationProgress.js";
import { createOperationProgress } from "./operationProgress.js";
import {
deliverApplicationExecution,
type ApplicationExecutionRecords,
Expand Down Expand Up @@ -533,6 +530,12 @@ export type AnalysisWorkflow = (
request: ApplicationWorkflowRequest,
) => Promise<Result<AnalysisWorkflowOutcome, AnalysisError>>;

/** Delivery controls and the owner of this complete workflow's terminal progress. */
export interface AnalysisWorkflowOptions {
readonly detail?: "delivery" | undefined;
readonly completionProgress?: "workflow" | undefined;
}

/**
* Run a provider-backed workflow on the analysis that admission grants for
* the call, reporting its start and terminal disposition, and deliver its
Expand All @@ -548,16 +551,17 @@ export const createAnalysisToolHandler =
logger: Logger,
retention: AnalysisViewRetention,
withAdmittedAnalysis: WithAdmittedAnalysis,
selectsDetail: boolean,
options: AnalysisWorkflowOptions,
) =>
(contract: ToolContract) =>
async (
rawInput: unknown,
context: ServerContext,
): Promise<CallToolResult> => {
const { detail, input } = selectsDetail
? deliveryDetail(rawInput)
: { detail: undefined, input: rawInput };
const { detail, input } =
options.detail === "delivery"
? deliveryDetail(rawInput)
: { detail: undefined, input: rawInput };
if (detail === "summary") {
const ready = requireAnalysisViewRetention(contract.name, retention);
if (!ready.ok) return server.delivery.toCallToolResult(ready, contract);
Expand All @@ -567,8 +571,12 @@ export const createAnalysisToolHandler =
contract.name,
signal,
async (analysis) => {
const progress = mcpProgressReporter(context);
await reportOperationStart(progress, contract.name);
const progress = createOperationProgress(
mcpProgressReporter(context),
contract.name,
options.completionProgress,
);
await progress.start();
const analyzed = await logToolExecution(logger, contract.name, () =>
analyze(input, analysis, { signal, progress }),
);
Expand Down Expand Up @@ -597,12 +605,7 @@ export const createAnalysisToolHandler =
contract,
analyzed.value.recorded,
);
await reportOperationEnd(
progress,
contract.name,
response.isError !== true,
);
return response;
return progress.complete(response);
},
);
return admitted.ok
Expand Down
78 changes: 78 additions & 0 deletions src/server/operationProgress.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { expect, it, vi } from "vitest";

import { createOperationProgress } from "./operationProgress.js";

const cleanup = {
phase: "cleanup",
completed: 3,
total: null,
message: "disposition=timeout owned_process_group=cleaned",
terminal: true,
} as const;

it("preserves the complete workflow's terminal observation on successful delivery", async () => {
const report = vi.fn().mockResolvedValue(undefined);
const progress = createOperationProgress({ report }, "capture", "workflow");
await progress.start();
await progress.report(cleanup);
const response = { content: [] };
expect(await progress.complete(response)).toBe(response);
expect(report.mock.calls.at(-1)?.[0]).toEqual(cleanup);
expect(report).toHaveBeenCalledTimes(2);
});

it("retains cleanup facts when delivery fails after the workflow's terminal observation", async () => {
const report = vi.fn().mockResolvedValue(undefined);
const progress = createOperationProgress({ report }, "capture", "workflow");
await progress.report(cleanup);
await progress.complete({ content: [], isError: true });
expect(report.mock.calls.at(-1)?.[0]).toEqual({
...cleanup,
phase: "capture",
message: "failed; cleanup: disposition=timeout owned_process_group=cleaned",
});
});

it("does not treat a child terminal observation as the complete operation's terminal", async () => {
const report = vi.fn().mockResolvedValue(undefined);
const progress = createOperationProgress({ report }, "parent");
await progress.report(cleanup);
await progress.complete({ content: [] });
expect(report.mock.calls.at(-1)?.[0]).toMatchObject({
phase: "parent",
message: "completed",
terminal: true,
});
});

it("allows a workflow to continue after a child's terminal observation", async () => {
const report = vi.fn().mockResolvedValue(undefined);
const progress = createOperationProgress({ report }, "parent", "workflow");
await progress.report(cleanup);
await progress.report({
phase: "reconcile",
completed: 0,
total: null,
message: "examining",
});
await progress.complete({ content: [] });
expect(report.mock.calls.at(-1)?.[0]).toMatchObject({
phase: "parent",
message: "completed",
terminal: true,
});
});

it.each([false, true])(
"finishes a workflow with no producer terminal (isError=%s)",
async (isError) => {
const report = vi.fn().mockResolvedValue(undefined);
const progress = createOperationProgress({ report }, "plan", "workflow");
await progress.complete({ content: [], isError });
expect(report.mock.calls.at(-1)?.[0]).toMatchObject({
phase: "plan",
message: isError ? "failed" : "completed",
terminal: true,
});
},
);
34 changes: 33 additions & 1 deletion src/server/operationProgress.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { ProgressReporter } from "../ports/ProgressReporter.js";
import type { CallToolResult } from "@modelcontextprotocol/server";
import type {
ProgressReporter,
ProgressUpdate,
} from "../ports/ProgressReporter.js";

/** Report one operation start through the shared monotonic boundary. */
export const reportOperationStart = (
Expand All @@ -20,3 +24,31 @@ export const reportOperationEnd = (
message: succeeded ? "completed" : "failed",
terminal: true,
});

/** Finish only after delivery, preserving a declared workflow's own final facts. */
export const createOperationProgress = (
progress: ProgressReporter,
phase: string,
completionProgress?: "workflow",
) => {
let terminal: ProgressUpdate | undefined;
return {
report(update: ProgressUpdate): Promise<void> {
terminal = update.terminal === true ? update : undefined;
return progress.report(update);
},
start: () => reportOperationStart(progress, phase),
async complete(response: CallToolResult): Promise<CallToolResult> {
const final = completionProgress === "workflow" ? terminal : undefined;
if (final === undefined)
await reportOperationEnd(progress, phase, response.isError !== true);
else if (response.isError === true)
await progress.report({
...final,
phase,
message: `failed; ${final.phase}: ${final.message}`,
});
return response;
},
};
};
39 changes: 24 additions & 15 deletions src/server/providerOperationToolHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ import { mcpProgressReporter } from "./mcpProgress.js";
import { logToolExecution } from "./toolLogging.js";
import type { WithAdmittedAnalysis } from "./analysisAdmission.js";
import { recordEvidenceSources } from "../application/investigation/recordEvidenceSources.js";
import {
reportOperationStart,
reportOperationEnd,
} from "./operationProgress.js";
import { createOperationProgress } from "./operationProgress.js";

/** A provider operation a tool contract names. */
export type ProviderOperation = Exclude<AnalysisOperation, "health">;
Expand Down Expand Up @@ -95,8 +92,11 @@ export const createProviderOperationToolHandler =
const analysis =
options.analysisForAdmission?.(admittedAnalysis) ??
admittedAnalysis;
const progress = mcpProgressReporter(context);
await reportOperationStart(progress, contract.name);
const progress = createOperationProgress(
mcpProgressReporter(context),
contract.name,
);
await progress.start();
const providerParameters =
contract.retainedSummary === undefined
? parameters
Expand All @@ -115,16 +115,19 @@ export const createProviderOperationToolHandler =
server.advertisesTool(advertised),
}),
);
await reportOperationEnd(progress, contract.name, execution.ok);
if (!execution.ok)
return server.delivery.toCallToolResult(execution, contract);
return progress.complete(
server.delivery.toCallToolResult(execution, contract),
);
const sourceEvidence = execution.value.sourceEvidence ?? [];
const sourceRecorded = recordEvidenceSources(
dependencies.recordEvidence,
sourceEvidence,
);
if (!sourceRecorded.ok)
return server.delivery.toCallToolResult(sourceRecorded, contract);
return progress.complete(
server.delivery.toCallToolResult(sourceRecorded, contract),
);
const evidenceParameters =
contract.retainedSummary?.evidenceParameters === "omit-detail"
? providerParameters
Expand All @@ -140,17 +143,23 @@ export const createProviderOperationToolHandler =
},
);
if (!evidence.ok)
return server.delivery.toCallToolResult(evidence, contract);
return progress.complete(
server.delivery.toCallToolResult(evidence, contract),
);
const projected =
delivery?.projectEvidence(parameters, evidence.value) ??
ok(evidence.value);
if (!projected.ok)
return server.delivery.toCallToolResult(projected, contract);
return progress.complete(
server.delivery.toCallToolResult(projected, contract),
);
const recorded = dependencies.recordEvidence?.(projected.value);
return server.delivery.toEvidenceToolResult(
projected.value,
contract,
recorded,
return progress.complete(
server.delivery.toEvidenceToolResult(
projected.value,
contract,
recorded,
),
);
},
);
Expand Down
1 change: 1 addition & 0 deletions src/server/serviceToolBindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,7 @@ const SERVICE_TOOL_BINDINGS = {
processCapture: ((options) => ({
capture_process_scenario: {
admission: "sdk",
completionProgress: "workflow",
analyze: (input, _analysis, request) =>
captureSessionProcessScenario(options, input, request),
},
Expand Down
48 changes: 48 additions & 0 deletions tests/boundary/mcp/progressMcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { FUNCTION_COMPARISON_EXAMPLE } from "../../../src/contracts/functionComp
import { AnalysisCancelledError } from "../../../src/domain/analysisErrorCore.js";
import { err, ok } from "../../../src/domain/result.js";
import { createServer } from "../../../src/server/createServer.js";
import { ToolResultDelivery } from "../../../src/server/ToolResultDelivery.js";
import { observed } from "../../fixtures/analysisExecution.js";
import { phaseGate } from "../../support/lifecycleHarness.js";
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
Expand All @@ -22,6 +23,53 @@ const testClient = (name: string) =>
{ jsonSchemaValidator: createMcpSchemaValidation() },
);

it.each(["current_address", "analyze_function"] as const)(
"reports failed when %s completes analysis but its response cannot be delivered",
async (name) => {
const analysis: AnalysisOperationPort = {
execute: async (operation, _parameters, options) => {
await options?.progress?.report({
phase: "native",
completed: 1,
total: 1,
message: "observation complete",
terminal: true,
});
return observed(
operation === "analyze_function"
? FUNCTION_COMPARISON_EXAMPLE.left.normalized_result
: "0x1000",
);
},
};
const server = createServer(
{ kind: "fixed", analysis },
{ delivery: new ToolResultDelivery(1024) },
);
const client = testClient("delivery-progress-test");
const [clientTransport, serverTransport] =
InMemoryTransport.createLinkedPair();
const messages: Array<string | undefined> = [];
await withVerifierCleanup(async () => {
await server.connect(serverTransport);
await client.connect(clientTransport);
const response = await client.callTool(
{
name,
arguments:
name === "analyze_function"
? { procedure: "main", detail: "complete" }
: {},
},
{ onprogress: ({ message }) => messages.push(message) },
);
expect(response.isError).toBe(true);
expect(messages).toContain("native: observation complete");
expect(messages.at(-1)).toBe(`${name}: failed`);
}, [() => client.close(), () => server.close()]);
},
);

describe("ordinary MCP progress and cancellation", () => {
it("advances MCP progress when provider waiting does not advance completed work", async () => {
const analysis: AnalysisOperationPort = {
Expand Down
Loading