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:
@@ -1,3 +1,5 @@
|
||||
import { resolve } from "node:path";
|
||||
|
||||
import {
|
||||
createImmutableEvidenceBundle,
|
||||
describeEvidenceBundleFailure,
|
||||
@@ -37,13 +39,15 @@ type EvidenceWriteFailure =
|
||||
export const readEvidenceBundle = (
|
||||
path: string,
|
||||
signal?: AbortSignal,
|
||||
resources?: ArtifactResourceScope,
|
||||
): Promise<Result<EvidenceBundle, EvidenceReadFailure>> =>
|
||||
readBundle(path, parseEvidenceBundle, signal);
|
||||
readBundle(path, parseEvidenceBundle, signal, resources);
|
||||
|
||||
/** Read an authenticated immutable snapshot for a subsequent session import. */
|
||||
export const readImmutableEvidenceBundle = (
|
||||
path: string,
|
||||
signal?: AbortSignal,
|
||||
resources?: ArtifactResourceScope,
|
||||
): Promise<Result<EvidenceBundle, EvidenceReadFailure>> =>
|
||||
readBundle(
|
||||
path,
|
||||
@@ -52,26 +56,30 @@ export const readImmutableEvidenceBundle = (
|
||||
return createImmutableEvidenceBundle(bundle.records, bundle.unknowns);
|
||||
},
|
||||
signal,
|
||||
resources,
|
||||
);
|
||||
|
||||
const readBundle = async (
|
||||
path: string,
|
||||
parseBundle: (input: unknown) => EvidenceBundle,
|
||||
signal?: AbortSignal,
|
||||
resources?: ArtifactResourceScope,
|
||||
): Promise<Result<EvidenceBundle, EvidenceReadFailure>> => {
|
||||
if (signal?.aborted)
|
||||
return err(new AnalysisCancelledError("import_evidence_bundle"));
|
||||
const loaded = await readJsonFile(path, signal).catch((cause: unknown) => {
|
||||
// A failed close transfers a live handle owner; preserve that failure.
|
||||
if (
|
||||
signal?.aborted === true &&
|
||||
!(cause instanceof RegularFileCleanupFailure)
|
||||
)
|
||||
return err(
|
||||
new AnalysisCancelledError("import_evidence_bundle", { cause }),
|
||||
);
|
||||
throw cause;
|
||||
});
|
||||
const loaded = await readJsonFile(path, signal, resources).catch(
|
||||
(cause: unknown) => {
|
||||
// A failed close transfers a live handle owner; preserve that failure.
|
||||
if (
|
||||
signal?.aborted === true &&
|
||||
!(cause instanceof RegularFileCleanupFailure)
|
||||
)
|
||||
return err(
|
||||
new AnalysisCancelledError("import_evidence_bundle", { cause }),
|
||||
);
|
||||
throw cause;
|
||||
},
|
||||
);
|
||||
if (!loaded.ok) return loaded;
|
||||
if (signal?.aborted)
|
||||
return err(new AnalysisCancelledError("import_evidence_bundle"));
|
||||
@@ -79,10 +87,19 @@ const readBundle = async (
|
||||
try {
|
||||
bundle = parseBundle(loaded.value);
|
||||
} catch (cause: unknown) {
|
||||
const failure = describeEvidenceBundleFailure(loaded.value, cause);
|
||||
if (failure.kind === "single-record")
|
||||
return err(
|
||||
new EvidenceFileError("read", "wrong-kind", {
|
||||
path: resolve(path),
|
||||
cause,
|
||||
userMessage: failure.message,
|
||||
}),
|
||||
);
|
||||
return err(
|
||||
new EvidenceIntegrityError("Evidence bundle validation failed", {
|
||||
cause,
|
||||
userMessage: describeEvidenceBundleFailure(loaded.value, cause),
|
||||
userMessage: failure.message,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user