fix(io): retain cleanup ownership and honor cancellation
Keep failed JSON read handles in the existing server resource scope and fail admission until cleanup succeeds. Thread cancellation through every process CLI input read and replace timer-driven cancellation checks with a shared first-read gate. Classify authenticated standalone Evidence as wrong-kind input while preserving tampered-record integrity failures and actionable messages across ledger, CLI, and MCP consumers. Record unrelated CS_RESTRICT process neighbors as unverified without weakening related-process ownership checks. Update stale ADB fixtures for the actual shell protocol. Validated focused CLI, MCP, filesystem, ownership, and error projection tests; static, docs, and duplication gates pass. The host-level CS_RESTRICT load reproduction was not run. Refs #2050, #2035, #2064.
This commit is contained in:
@@ -12,12 +12,14 @@ import { BUNDLE_COMPARISON_PROVIDER } from "../application/InvestigationProvider
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { withAdmittedAnalysis } from "./analysisAdmission.js";
|
||||
import { runAdmittedToolOperation } from "./admittedToolOperation.js";
|
||||
import type { ArtifactResourceScope } from "../artifacts/ArtifactResourceScope.js";
|
||||
|
||||
/** Register canonical Evidence bundle comparison. */
|
||||
export const registerBundleComparisonTool = (
|
||||
server: EvidenceMcpServer,
|
||||
session: BinarySessionPort,
|
||||
contract: ReturnType<typeof toolContract<"compare_bundles">>,
|
||||
resources: ArtifactResourceScope,
|
||||
): void => {
|
||||
const admission = withAdmittedAnalysis({ kind: "session", session });
|
||||
server.registerTool(
|
||||
@@ -31,8 +33,16 @@ export const registerBundleComparisonTool = (
|
||||
context.mcpReq.signal,
|
||||
async () => {
|
||||
const [left, right] = await Promise.all([
|
||||
readEvidenceBundle(input.left_bundle_path, context.mcpReq.signal),
|
||||
readEvidenceBundle(input.right_bundle_path, context.mcpReq.signal),
|
||||
readEvidenceBundle(
|
||||
input.left_bundle_path,
|
||||
context.mcpReq.signal,
|
||||
resources,
|
||||
),
|
||||
readEvidenceBundle(
|
||||
input.right_bundle_path,
|
||||
context.mcpReq.signal,
|
||||
resources,
|
||||
),
|
||||
]);
|
||||
if (!left.ok) return server.delivery.toCallToolResult(left, contract);
|
||||
if (!right.ok)
|
||||
|
||||
@@ -89,6 +89,7 @@ const registerSnapshotEvidenceTool = ({
|
||||
const registerImportEvidenceTool = ({
|
||||
server,
|
||||
session,
|
||||
resources,
|
||||
importContract,
|
||||
}: EvidenceToolRegistration): void => {
|
||||
server.registerTool(
|
||||
@@ -97,7 +98,7 @@ const registerImportEvidenceTool = ({
|
||||
async (input, context) => {
|
||||
const path = input.path;
|
||||
const signal = context.mcpReq.signal;
|
||||
const loaded = await readImmutableEvidenceBundle(path, signal);
|
||||
const loaded = await readImmutableEvidenceBundle(path, signal, resources);
|
||||
if (!loaded.ok)
|
||||
return server.delivery.toCallToolResult(loaded, importContract);
|
||||
const retainedUnknownRevisions = new Set(
|
||||
|
||||
@@ -160,6 +160,7 @@ export interface LifecycleToolRegistration {
|
||||
|
||||
const registerLifecycleTools = (
|
||||
registration: LifecycleToolRegistration,
|
||||
artifactResources: ArtifactResourceScope,
|
||||
): void => {
|
||||
const {
|
||||
server,
|
||||
@@ -169,7 +170,7 @@ const registerLifecycleTools = (
|
||||
availabilityPolicy,
|
||||
androidAnalysisAvailability,
|
||||
} = registration;
|
||||
registerOpenLifecycleTool(registration);
|
||||
registerOpenLifecycleTool(registration, artifactResources);
|
||||
registerCloseLifecycleTool(registration);
|
||||
registerSessionStatusTool({
|
||||
server,
|
||||
@@ -181,12 +182,10 @@ const registerLifecycleTools = (
|
||||
});
|
||||
};
|
||||
|
||||
const registerOpenLifecycleTool = ({
|
||||
server,
|
||||
session,
|
||||
logger,
|
||||
openContract,
|
||||
}: LifecycleToolRegistration): void => {
|
||||
const registerOpenLifecycleTool = (
|
||||
{ server, session, logger, openContract }: LifecycleToolRegistration,
|
||||
artifactResources: ArtifactResourceScope,
|
||||
): void => {
|
||||
server.registerTool(
|
||||
openContract.name,
|
||||
toolRegistrationOptions(openContract),
|
||||
@@ -196,6 +195,7 @@ const registerOpenLifecycleTool = ({
|
||||
const loaded = await readAnalysisSnapshot(
|
||||
input.snapshot_path,
|
||||
context.mcpReq.signal,
|
||||
artifactResources,
|
||||
);
|
||||
if (!loaded.ok)
|
||||
return server.delivery.toCallToolResult(loaded, openContract);
|
||||
@@ -302,42 +302,45 @@ export const registerSessionTools = (
|
||||
const compareBundlesContract = toolContract("compare_bundles");
|
||||
const snapshotContract = toolContract("get_evidence_bundle");
|
||||
const processResources = new ProcessCaptureResourceScope();
|
||||
registerLifecycleTools({
|
||||
server,
|
||||
session,
|
||||
logger,
|
||||
openContract,
|
||||
closeContract,
|
||||
statusContract,
|
||||
startedAt: options.startedAt ?? new Date().toISOString(),
|
||||
availabilityPolicy: sessionAvailabilityPolicy(
|
||||
options.availabilityPolicy,
|
||||
{},
|
||||
),
|
||||
androidAnalysisAvailability:
|
||||
options.androidAnalysisAvailability ?? missingAndroidAvailability,
|
||||
closeProcessResources: async () => {
|
||||
try {
|
||||
await processResources.retryCleanup();
|
||||
return ok(null);
|
||||
} catch (cause: unknown) {
|
||||
return err(
|
||||
new ProcessCaptureError(
|
||||
"process capture cleanup remains incomplete",
|
||||
{
|
||||
cause,
|
||||
reason: "cleanup_incomplete",
|
||||
cleanupResources: ["process_capture_resources"],
|
||||
executionFailure:
|
||||
cause instanceof Error
|
||||
? cause.message || cause.name
|
||||
: String(cause),
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
registerLifecycleTools(
|
||||
{
|
||||
server,
|
||||
session,
|
||||
logger,
|
||||
openContract,
|
||||
closeContract,
|
||||
statusContract,
|
||||
startedAt: options.startedAt ?? new Date().toISOString(),
|
||||
availabilityPolicy: sessionAvailabilityPolicy(
|
||||
options.availabilityPolicy,
|
||||
{},
|
||||
),
|
||||
androidAnalysisAvailability:
|
||||
options.androidAnalysisAvailability ?? missingAndroidAvailability,
|
||||
closeProcessResources: async () => {
|
||||
try {
|
||||
await processResources.retryCleanup();
|
||||
return ok(null);
|
||||
} catch (cause: unknown) {
|
||||
return err(
|
||||
new ProcessCaptureError(
|
||||
"process capture cleanup remains incomplete",
|
||||
{
|
||||
cause,
|
||||
reason: "cleanup_incomplete",
|
||||
cleanupResources: ["process_capture_resources"],
|
||||
executionFailure:
|
||||
cause instanceof Error
|
||||
? cause.message || cause.name
|
||||
: String(cause),
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
options.artifactResources,
|
||||
);
|
||||
registerEvidenceTools({
|
||||
server,
|
||||
session,
|
||||
@@ -381,7 +384,12 @@ export const registerSessionTools = (
|
||||
registerProcessComparisonTool(server, session, compareContract);
|
||||
registerArtifactComparisonTool(server, session, compareArtifactsContract);
|
||||
registerFunctionComparisonTool(server, session, compareFunctionsContract);
|
||||
registerBundleComparisonTool(server, session, compareBundlesContract);
|
||||
registerBundleComparisonTool(
|
||||
server,
|
||||
session,
|
||||
compareBundlesContract,
|
||||
options.artifactResources,
|
||||
);
|
||||
registerInvestigationTools(server, session);
|
||||
registerUnknownTools({ server, session });
|
||||
registerContextTools(server, session);
|
||||
|
||||
Reference in New Issue
Block a user