fix(server): deliver the retained copy that carries the session selection

Recording stamps the active session's provider selection onto the ledger copy
of a semantic ID. The tools that build or project their own Evidence value
then delivered that unattributed copy, so the MCP response and the snapshot
export disagreed for the same evidence_id: Ghidra reference and evidence
flows, composed workflow overviews, analysis functions and the process
capture tools all failed deep-equality against the retained record.

Hand the delivered copy the session's selection when the ID is retained.
Other retained display metadata, such as a caller path carried by an
imported record, stays as the caller built it.
This commit is contained in:
2SinceJuly committed 2026-11-13 21:42:19 +08:00
1 parent b6e40dc914
commit 76d14ff9f9
2 files changed
+45 -4

No files matched your search

+30 -3
View File
@@ -1,4 +1,5 @@
import type { Evidence } from "../domain/evidence.js";
import { withEvidenceProviderSelection } from "../domain/evidence.js";
import type { ToolResultDelivery } from "./ToolResultDelivery.js";
import type { EvidenceMcpServer } from "./EvidenceMcpServer.js";
import type {
@@ -369,9 +370,16 @@ const executeEnhancedTool = async (
return finish(
registration.delivery.toCallToolResult(delivered, contract),
);
// Recording stamps the active session's provider selection onto the
// retained value. Carry that stamp on the copy we deliver so the
// response agrees with the ledger and its exports; other retained
// display metadata stays as this call built it.
return finish(
registration.delivery.toEvidenceToolResult(
delivered.value,
stampSessionSelection(
registration.evidenceById?.(delivered.value.evidence_id),
delivered.value,
),
contract,
request.detail === "summary"
? registration.recordEvidence?.(delivered.value)
@@ -475,18 +483,37 @@ const deliverFunctionAnalysis = async (
if (!summary.ok)
return registration.delivery.toCallToolResult(summary, contract);
return registration.delivery.toEvidenceToolResult(
summary.value,
stampSessionSelection(
registration.evidenceById?.(summary.value.evidence_id),
summary.value,
),
contract,
registration.recordEvidence?.(summary.value),
);
}
return registration.delivery.toEvidenceToolResult(
result.value,
stampSessionSelection(
registration.evidenceById?.(result.value.evidence_id),
result.value,
),
contract,
registration.recordEvidence?.(result.value),
);
};
/**
* Recording stamps the active session's provider selection onto the retained
* value under the same semantic ID. Deliver that copy so a response agrees
* with the ledger and its exports, falling back when the call was not retained.
*/
const stampSessionSelection = (
retained: Evidence | undefined,
evidence: Evidence,
): Evidence =>
retained?.provider_selection === undefined
? evidence
: withEvidenceProviderSelection(evidence, retained.provider_selection);
/**
* Deliver an analysis failure with any partial Evidence it carries, whether a
* stopped workflow or its failing read produced that partial.
+15 -1
View File
@@ -17,6 +17,7 @@ import { admitCompletedAnalysis } from "../application/investigation/admitComple
import type { RecoveryAdmission } from "../application/investigation/InvestigationRetention.js";
import type { BinaryTarget } from "../domain/binaryTargetTypes.js";
import { createAnalysisExecutionEvidence } from "../domain/analysisObservation.js";
import { withEvidenceProviderSelection } from "../domain/evidence.js";
import { jsonObjectSchema, type JsonValue } from "../domain/jsonValue.js";
import type { Logger } from "pino";
import { mcpProgressReporter } from "./mcpProgress.js";
@@ -143,8 +144,21 @@ export const registerEvidenceTools = (
if (!projected.ok)
return server.delivery.toCallToolResult(projected, contract);
const recorded = options.recordEvidence?.(projected.value);
// Recording stamps the active session's provider selection onto the
// retained record. Deliver the caller's own copy carrying that
// stamp so the response agrees with the ledger and its exports;
// other retained display metadata stays as the caller built it.
const retained =
options.evidenceById?.(evidence.evidence_id) ?? projected.value;
const delivered =
retained.provider_selection === undefined
? projected.value
: withEvidenceProviderSelection(
projected.value,
retained.provider_selection,
);
return server.delivery.toEvidenceToolResult(
projected.value,
delivered,
contract,
recorded,
);