fix(evidence): preserve trace uncertainty and partial provider observations
Distinguish an unresolved goal from an exhausted call graph and preserve provider failures through cancellation. Retain completed IDA replies and post-operation identity observations as partial Evidence without claiming a verified final binding. Remove source-wide bundler cache-name heuristics and stale expectations.
This commit is contained in:
@@ -4,10 +4,11 @@ import type {
|
||||
ExecutionOptions,
|
||||
} from "./AnalysisProvider.js";
|
||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||
import { AnalysisCancelledError } from "../domain/analysisErrorCore.js";
|
||||
import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import { parseRelatedAddresses } from "../domain/hopperValues.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import { ok, type Result } from "../domain/result.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import type { EnhancedResult } from "./EnhancedToolTypes.js";
|
||||
import { resolveProcedureAddress } from "./ProcedureAddressResolution.js";
|
||||
import type { RelationshipCoverage } from "../domain/relationshipCoverage.js";
|
||||
@@ -91,24 +92,31 @@ export const traceCallPath = async (
|
||||
...(goal === undefined ? {} : { goal }),
|
||||
direction: input.direction,
|
||||
};
|
||||
if (isAborted(signal))
|
||||
return err(new AnalysisCancelledError("trace_call_path"));
|
||||
const state = createTraceState(resolvedInput);
|
||||
while (
|
||||
state.queueIndex < state.queue.length &&
|
||||
state.traversalPath.length === 0
|
||||
) {
|
||||
if (isAborted(signal))
|
||||
return err(new AnalysisCancelledError("trace_call_path"));
|
||||
const address = state.queue[state.queueIndex++];
|
||||
if (address === undefined) break;
|
||||
const current = state.visited.get(address);
|
||||
if (current === undefined) continue;
|
||||
const found = await expandAddress(callRelationship, {
|
||||
const expanded = await expandAddress(callRelationship, {
|
||||
input: resolvedInput,
|
||||
state,
|
||||
address,
|
||||
current,
|
||||
...(signal === undefined ? {} : { signal }),
|
||||
});
|
||||
if (found) break;
|
||||
if (!expanded.ok) return expanded;
|
||||
if (expanded.value) break;
|
||||
}
|
||||
if (isAborted(signal))
|
||||
return err(new AnalysisCancelledError("trace_call_path"));
|
||||
return ok(projectTrace(resolvedInput, state));
|
||||
};
|
||||
|
||||
@@ -127,19 +135,28 @@ const createTraceState = (input: CallPathTraceInput): TraceState => ({
|
||||
const expandAddress = async (
|
||||
call: RelationshipCall,
|
||||
expansion: AddressExpansion,
|
||||
): Promise<boolean> => {
|
||||
): Promise<Result<boolean, AnalysisError>> => {
|
||||
const { input, state, address, current, signal } = expansion;
|
||||
const relation = input.direction === "forward" ? "callees" : "callers";
|
||||
const tool =
|
||||
input.direction === "forward" ? "procedure_callees" : "procedure_callers";
|
||||
const result = await call(tool, { procedure: address }, signal, "provider");
|
||||
if (!result.ok) {
|
||||
if (
|
||||
result.error._tag === "AnalysisCancelledError" ||
|
||||
signal?.aborted === true
|
||||
)
|
||||
return result;
|
||||
}
|
||||
if (isAborted(signal))
|
||||
return err(new AnalysisCancelledError("trace_call_path"));
|
||||
if (!result.ok) {
|
||||
state.failures.push({
|
||||
address,
|
||||
error: projectAnalysisError(result.error),
|
||||
});
|
||||
state.residual.add(`Call relationships were unavailable for ${address}.`);
|
||||
return false;
|
||||
return ok(false);
|
||||
}
|
||||
const related = parseRelatedAddresses(result.value.result, relation);
|
||||
if (!related.ok) {
|
||||
@@ -148,7 +165,7 @@ const expandAddress = async (
|
||||
error: projectAnalysisError(related.error),
|
||||
});
|
||||
state.residual.add(`Call relationships were unreadable for ${address}.`);
|
||||
return false;
|
||||
return ok(false);
|
||||
}
|
||||
for (const limitation of result.value.limitations)
|
||||
state.limitations.add(limitation);
|
||||
@@ -184,7 +201,7 @@ const expandAddress = async (
|
||||
if (state.visited.has(relatedAddress)) {
|
||||
if (relatedAddress === input.goal) {
|
||||
state.traversalPath = path;
|
||||
return true;
|
||||
return ok(true);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -194,11 +211,11 @@ const expandAddress = async (
|
||||
});
|
||||
if (relatedAddress === input.goal) {
|
||||
state.traversalPath = path;
|
||||
return true;
|
||||
return ok(true);
|
||||
}
|
||||
state.queue.push(relatedAddress);
|
||||
}
|
||||
return false;
|
||||
return ok(false);
|
||||
};
|
||||
|
||||
const recordEdge = (
|
||||
@@ -228,7 +245,9 @@ const projectTrace = (input: CallPathTraceInput, state: TraceState) => ({
|
||||
? "not_requested"
|
||||
: state.traversalPath.length > 0
|
||||
? "reached"
|
||||
: "not_reached",
|
||||
: state.residual.size > 0
|
||||
? "unknown"
|
||||
: "not_reached",
|
||||
nodes: [...state.visited.entries()]
|
||||
.map(([address, { depth }]) => ({ address, depth }))
|
||||
.sort(
|
||||
@@ -264,3 +283,6 @@ const compareAddress = (left: string, right: string): number =>
|
||||
|
||||
const sortedUniqueAddresses = (addresses: readonly string[]): string[] =>
|
||||
[...new Set(addresses)].sort(compareAddress);
|
||||
|
||||
const isAborted = (signal: AbortSignal | undefined): boolean =>
|
||||
signal?.aborted === true;
|
||||
|
||||
@@ -4,7 +4,11 @@ import {
|
||||
type AnalysisOperation,
|
||||
type AnalysisOperationPort,
|
||||
} from "./AnalysisProvider.js";
|
||||
import { AnalysisInputError } from "../domain/analysisErrorCore.js";
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
AnalysisInputError,
|
||||
AnalysisProtocolError,
|
||||
} from "../domain/analysisErrorCore.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import { err, ok } from "../domain/result.js";
|
||||
import { EnhancedTools } from "./EnhancedTools.js";
|
||||
@@ -140,3 +144,118 @@ describe("selector origin of composed workflows", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("trace path completion and cancellation", () => {
|
||||
it("keeps an unreachable goal unknown when provider coverage is unresolved", async () => {
|
||||
const tools = new EnhancedTools({
|
||||
execute: async (operation, parameters) => {
|
||||
if (operation === "procedure_address")
|
||||
return ok(createAnalysisExecution(parameters.procedure, provider));
|
||||
if (operation === "procedure_callees")
|
||||
return ok(
|
||||
createAnalysisExecution([], provider, {
|
||||
relationshipCoverage: {
|
||||
status: "unknown",
|
||||
reason: "the provider cannot confirm graph coverage",
|
||||
},
|
||||
}),
|
||||
);
|
||||
throw new Error(`Unexpected operation: ${operation}`);
|
||||
},
|
||||
});
|
||||
|
||||
const result = await tools.execute("trace_call_path", {
|
||||
start: "0x1000",
|
||||
goal: "0x2000",
|
||||
});
|
||||
|
||||
expect(result).toMatchObject({
|
||||
ok: true,
|
||||
value: { goal_status: "unknown", truncated: true },
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ abortSignal: false, errorKind: "cancelled" },
|
||||
{ abortSignal: true, errorKind: "cancelled" },
|
||||
{ abortSignal: true, errorKind: "protocol" },
|
||||
])(
|
||||
"preserves provider $errorKind failure and cleanup with request abort: $abortSignal",
|
||||
async ({ abortSignal, errorKind }) => {
|
||||
const cleanup = {
|
||||
reason: "provider cleanup is still pending",
|
||||
resources: ["provider session"],
|
||||
};
|
||||
const providerFailure =
|
||||
errorKind === "cancelled"
|
||||
? new AnalysisCancelledError("procedure_callees", { cleanup })
|
||||
: new AnalysisProtocolError("provider relationship read failed", {
|
||||
cleanup,
|
||||
});
|
||||
const controller = new AbortController();
|
||||
const tools = new EnhancedTools({
|
||||
execute: async (operation, parameters) => {
|
||||
if (operation === "procedure_address")
|
||||
return ok(createAnalysisExecution(parameters.procedure, provider));
|
||||
if (operation === "procedure_callees") {
|
||||
if (abortSignal) controller.abort();
|
||||
return err(providerFailure);
|
||||
}
|
||||
throw new Error(`Unexpected operation: ${operation}`);
|
||||
},
|
||||
});
|
||||
|
||||
const result = await tools.execute(
|
||||
"trace_call_path",
|
||||
{ start: "0x1000", goal: "0x2000" },
|
||||
abortSignal ? controller.signal : undefined,
|
||||
);
|
||||
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
_tag:
|
||||
errorKind === "cancelled"
|
||||
? "AnalysisCancelledError"
|
||||
: "AnalysisProtocolError",
|
||||
cleanup,
|
||||
},
|
||||
});
|
||||
if (result.ok) throw new Error("expected provider failure");
|
||||
expect(result.error).toBe(providerFailure);
|
||||
},
|
||||
);
|
||||
|
||||
it("stops after cancellation races with a successful relationship response", async () => {
|
||||
const controller = new AbortController();
|
||||
const calls: string[] = [];
|
||||
const tools = new EnhancedTools({
|
||||
execute: async (operation, parameters) => {
|
||||
calls.push(operation);
|
||||
if (operation === "procedure_address")
|
||||
return ok(createAnalysisExecution(parameters.procedure, provider));
|
||||
if (operation === "procedure_callees") {
|
||||
controller.abort();
|
||||
return ok(createAnalysisExecution(["0x2000"], provider));
|
||||
}
|
||||
throw new Error(`Unexpected operation: ${operation}`);
|
||||
},
|
||||
});
|
||||
|
||||
const result = await tools.execute(
|
||||
"trace_call_path",
|
||||
{ start: "0x1000", goal: "0x3000" },
|
||||
controller.signal,
|
||||
);
|
||||
|
||||
expect(calls).toEqual([
|
||||
"procedure_address",
|
||||
"procedure_address",
|
||||
"procedure_callees",
|
||||
]);
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisCancelledError" },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -591,6 +591,7 @@ export class EnhancedTools {
|
||||
...(signal === undefined ? {} : { signal }),
|
||||
...(selectorOrigin === undefined ? {} : { selectorOrigin }),
|
||||
});
|
||||
if (!execution.ok) return execution;
|
||||
if (isAborted(signal)) return err(new AnalysisCancelledError(name));
|
||||
return execution;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user