mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
fix(evidence): classify derived failures at their owning boundary
Parse caller selections and authenticated Evidence at their owners, reuse the parsed function and comparison facts, and preserve unexpected implementation failures. Remove downstream error guessing and redundant validation wrappers. Verify with 526 affected tests, source checks, docs conformance, test discovery and duplication checks. Seven public SDK regressions fail on the main baseline. No real-provider execution was performed.
This commit is contained in:
1 parent
7091be291c
commit
93a384db77
46 files changed
+1706
-566
No files matched your search
@@ -205,12 +205,7 @@ const artifactInventoryValues = (
|
||||
? [inventory.manifest.manifest_id]
|
||||
: inventory.occurrences.map(({ occurrence_id: id }) => id);
|
||||
} catch (cause: unknown) {
|
||||
if (
|
||||
cause instanceof TypeError ||
|
||||
cause instanceof z.ZodError ||
|
||||
cause instanceof EvidenceIntegrityError
|
||||
)
|
||||
return [];
|
||||
if (cause instanceof EvidenceIntegrityError) return [];
|
||||
throw cause;
|
||||
}
|
||||
};
|
||||
@@ -224,11 +219,7 @@ const isProcessCaptureEvidence = (evidence: LedgerEvidence): boolean => {
|
||||
return false;
|
||||
case "invalid-evidence":
|
||||
case "invalid-capture":
|
||||
if (
|
||||
parsed.error.cause instanceof TypeError ||
|
||||
parsed.error.cause instanceof z.ZodError
|
||||
)
|
||||
return false;
|
||||
if (parsed.error.cause instanceof z.ZodError) return false;
|
||||
throw parsed.error.cause;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,7 +4,8 @@ import type { BinarySessionPort } from "../application/binary/BinarySessionPort.
|
||||
import { toolContract } from "../contracts/toolContracts.js";
|
||||
import { compareArtifacts } from "../domain/artifactComparison.js";
|
||||
import { ARTIFACT_COMPARISON_PROVIDER } from "../domain/comparisonEvidenceIdentity.js";
|
||||
import { createEvidence, parseEvidence } from "../domain/evidence.js";
|
||||
import { createEvidence } from "../domain/evidence.js";
|
||||
import { readEvidence } from "../domain/evidenceValidation.js";
|
||||
import { jsonValueSchema } from "../domain/jsonValue.js";
|
||||
import { resolveArtifactComparisonEvidence } from "../application/artifacts/ArtifactComparisonEvidence.js";
|
||||
import type { RecordUnknownInput } from "../domain/residualUnknown.js";
|
||||
@@ -39,15 +40,17 @@ export const registerArtifactComparisonTool = (
|
||||
context,
|
||||
contract.name,
|
||||
() => {
|
||||
const suppliedLeft = parseEvidence(input.left);
|
||||
const suppliedRight = parseEvidence(input.right);
|
||||
const suppliedLeft = readEvidence(input.left);
|
||||
if (!suppliedLeft.ok) throw suppliedLeft.error;
|
||||
const suppliedRight = readEvidence(input.right);
|
||||
if (!suppliedRight.ok) throw suppliedRight.error;
|
||||
const resolvedLeft = resolveArtifactComparisonEvidence(
|
||||
suppliedLeft,
|
||||
suppliedLeft.value,
|
||||
evidenceById,
|
||||
);
|
||||
if (!resolvedLeft.ok) throw resolvedLeft.error;
|
||||
const resolvedRight = resolveArtifactComparisonEvidence(
|
||||
suppliedRight,
|
||||
suppliedRight.value,
|
||||
evidenceById,
|
||||
);
|
||||
if (!resolvedRight.ok) throw resolvedRight.error;
|
||||
|
||||
@@ -3,14 +3,9 @@ import type { EvidenceMcpServer } from "./EvidenceMcpServer.js";
|
||||
|
||||
import type { BinarySessionPort } from "../application/binary/BinarySessionPort.js";
|
||||
import { toolContract } from "../contracts/toolContracts.js";
|
||||
import {
|
||||
createEvidence,
|
||||
parseEvidence,
|
||||
type Evidence,
|
||||
} from "../domain/evidence.js";
|
||||
import { createEvidence } from "../domain/evidence.js";
|
||||
import { parseFunctionEvidence } from "../domain/functionDossierEvidence.js";
|
||||
import { FUNCTION_COMPARISON_PROVIDER } from "../domain/comparisonEvidenceIdentity.js";
|
||||
import { EvidenceIntegrityError } from "../domain/evidenceErrors.js";
|
||||
import { err } from "../domain/result.js";
|
||||
import { jsonValueSchema } from "../domain/jsonValue.js";
|
||||
import type { RecordUnknownInput } from "../domain/residualUnknown.js";
|
||||
import { recordDerivedEvidence } from "./recordDerivedEvidence.js";
|
||||
@@ -46,45 +41,34 @@ export const registerFunctionComparisonTool = (
|
||||
);
|
||||
if (!resolved.ok)
|
||||
return server.delivery.toCallToolResult(resolved, contract);
|
||||
let leftEvidence: Evidence;
|
||||
let rightEvidence: Evidence;
|
||||
try {
|
||||
leftEvidence = parseEvidence(resolved.value.left);
|
||||
rightEvidence = parseEvidence(resolved.value.right);
|
||||
} catch (cause: unknown) {
|
||||
return server.delivery.toCallToolResult(
|
||||
err(
|
||||
new EvidenceIntegrityError(
|
||||
cause instanceof Error ? cause.message : "Invalid Evidence",
|
||||
),
|
||||
),
|
||||
contract,
|
||||
);
|
||||
}
|
||||
if (
|
||||
leftEvidence.operation !== "analyze_function" ||
|
||||
rightEvidence.operation !== "analyze_function" ||
|
||||
leftEvidence.predicate_type !== "rea.analysis" ||
|
||||
rightEvidence.predicate_type !== "rea.analysis"
|
||||
)
|
||||
return server.delivery.toCallToolResult(
|
||||
err(
|
||||
new EvidenceIntegrityError(
|
||||
"Expected analyze_function Evidence",
|
||||
),
|
||||
),
|
||||
contract,
|
||||
);
|
||||
const leftIds = [leftEvidence.evidence_id];
|
||||
const rightIds = [rightEvidence.evidence_id];
|
||||
const computed = await runDerivedOperation(
|
||||
context,
|
||||
contract.name,
|
||||
() => compareFunctions(leftEvidence, rightEvidence),
|
||||
() => {
|
||||
const left = parseFunctionEvidence(resolved.value.left, {
|
||||
operation: contract.name,
|
||||
path: ["left"],
|
||||
});
|
||||
if (!left.ok) throw left.error;
|
||||
const right = parseFunctionEvidence(resolved.value.right, {
|
||||
operation: contract.name,
|
||||
path: ["right"],
|
||||
});
|
||||
if (!right.ok) throw right.error;
|
||||
return {
|
||||
left: left.value,
|
||||
right: right.value,
|
||||
comparison: compareFunctions(left.value, right.value),
|
||||
};
|
||||
},
|
||||
);
|
||||
if (!computed.ok)
|
||||
return server.delivery.toCallToolResult(computed, contract);
|
||||
const comparison = computed.value;
|
||||
const { left, right, comparison } = computed.value;
|
||||
const leftEvidence = left.evidence;
|
||||
const rightEvidence = right.evidence;
|
||||
const leftIds = [leftEvidence.evidence_id];
|
||||
const rightIds = [rightEvidence.evidence_id];
|
||||
const recordedSources = recordSessionEvidenceSources(
|
||||
(evidence) => session.recordEvidence(evidence),
|
||||
[leftEvidence, rightEvidence],
|
||||
|
||||
@@ -10,7 +10,6 @@ import { correlateStaticAndRuntime } from "../domain/staticRuntimeCorrelation.js
|
||||
import {
|
||||
comparisonClosure,
|
||||
evidenceClosure,
|
||||
functionEvidenceIds,
|
||||
isIncomplete,
|
||||
recordWorkflowEvidence,
|
||||
} from "./registerInvestigationTools/helpers.js";
|
||||
@@ -139,7 +138,7 @@ const registerCallPath = (
|
||||
async () => {
|
||||
const closure = evidenceClosure(
|
||||
session,
|
||||
functionEvidenceIds(input.functions),
|
||||
input.functions.map(({ evidence_id }) => evidence_id),
|
||||
);
|
||||
if (!closure.ok)
|
||||
return server.delivery.toCallToolResult(closure, contract);
|
||||
|
||||
@@ -19,9 +19,6 @@ export const comparisonClosure = (comparisons: readonly Evidence[]): string[] =>
|
||||
]),
|
||||
);
|
||||
|
||||
export const functionEvidenceIds = (records: readonly Evidence[]): string[] =>
|
||||
uniqueIds(records.map(({ evidence_id }) => evidence_id));
|
||||
|
||||
const uniqueIds = (ids: readonly string[]): string[] =>
|
||||
[...new Set(ids)].sort((left, right) =>
|
||||
compareUnicodeCodePoints(left, right),
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { BinarySessionPort } from "../application/binary/BinarySessionPort.
|
||||
import { toolContract } from "../contracts/toolContracts.js";
|
||||
import { AnalysisInputError } from "../domain/analysisErrorCore.js";
|
||||
import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import { describeValidationFailure } from "../domain/evidenceBundle.js";
|
||||
import { describeValidationFailure } from "../domain/validationFailure.js";
|
||||
import { EvidenceIntegrityError } from "../domain/evidenceErrors.js";
|
||||
import {
|
||||
createEvidence,
|
||||
|
||||
@@ -147,30 +147,23 @@ describe("derived MCP operation boundary", () => {
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("projects synchronous computation failures into a typed result", async () => {
|
||||
const result = await runDerivedOperation(
|
||||
context(new AbortController()),
|
||||
"compare_artifacts",
|
||||
() => {
|
||||
throw new TypeError("malformed comparison evidence");
|
||||
},
|
||||
);
|
||||
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
_tag: "AnalysisInputError",
|
||||
operation: "compare_artifacts",
|
||||
issues: [
|
||||
{
|
||||
path: [],
|
||||
reason: "invalid_value",
|
||||
message: "malformed comparison evidence",
|
||||
it.each([
|
||||
new TypeError("internal type failure"),
|
||||
new Error("internal computation failure"),
|
||||
])(
|
||||
"preserves an untagged computation failure without calling it invalid input: $name",
|
||||
async (cause) => {
|
||||
await expect(
|
||||
runDerivedOperation(
|
||||
context(new AbortController()),
|
||||
"compare_artifacts",
|
||||
() => {
|
||||
throw cause;
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
),
|
||||
).rejects.toBe(cause);
|
||||
},
|
||||
);
|
||||
|
||||
it("preserves a tagged integrity failure instead of replacing it with invalid input", async () => {
|
||||
const failure = new EvidenceIntegrityError(
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import type { ServerContext } from "@modelcontextprotocol/server";
|
||||
import { setImmediate } from "node:timers/promises";
|
||||
import { z } from "zod";
|
||||
|
||||
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
AnalysisInputError,
|
||||
} from "../domain/analysisErrorCore.js";
|
||||
import { describeValidationFailure } from "../domain/evidenceBundle.js";
|
||||
import { AnalysisCancelledError } from "../domain/analysisErrorCore.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import { mcpProgressReporter, type McpProgressContext } from "./mcpProgress.js";
|
||||
|
||||
@@ -42,21 +37,7 @@ export const runDerivedOperation = async <Value>(
|
||||
} catch (cause: unknown) {
|
||||
// Typed causes already name the failed constraint; keep their issues.
|
||||
if (cause instanceof AnalysisError) return err(cause);
|
||||
return err(
|
||||
new AnalysisInputError(
|
||||
operation,
|
||||
{ cause },
|
||||
cause instanceof TypeError || cause instanceof z.ZodError
|
||||
? [
|
||||
{
|
||||
path: [],
|
||||
reason: "invalid_value",
|
||||
message: describeValidationFailure(cause),
|
||||
},
|
||||
]
|
||||
: [],
|
||||
),
|
||||
);
|
||||
throw cause;
|
||||
}
|
||||
await progress.report({
|
||||
phase: "compute",
|
||||
|
||||
Reference in new issue
Block a user