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;
|
||||
|
||||
Reference in New Issue
Block a user