fix(call-path): preserve relationship coverage from analysis (#2001)
Forward observed relationship coverage into function Evidence and use its typed completeness when searching call paths. Preserve contextual limitations, legacy fallback, provenance, and unknown outcomes. Avoid argument-spread exhaustion on large valid limitation lists. Cover the public MCP producer/consumer chain, metadata tampering, terminal and unreachable coverage, and large-list capacity. Related to #1964; separate get_call_graph and trace_call_path work is not included. AI-assisted with Hermes (Nous Research).
This commit is contained in:
@@ -46,6 +46,9 @@ export const executeFunctionAnalysisEvidence = async (
|
||||
rawResult: observation.rawResult,
|
||||
limitations: observation.limitations,
|
||||
locations: observation.locations,
|
||||
...(observation.relationshipCoverage === undefined
|
||||
? {}
|
||||
: { relationshipCoverage: observation.relationshipCoverage }),
|
||||
...(observation.analysisProfile === undefined
|
||||
? {}
|
||||
: { analysisProfile: observation.analysisProfile }),
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
import { createEvidence, type Evidence } from "./evidence.js";
|
||||
import { functionDossierSchema } from "./hopperValues.js";
|
||||
import { jsonValueSchema } from "./jsonValue.js";
|
||||
import type { RelationshipCoverage } from "./relationshipCoverage.js";
|
||||
|
||||
const observe = (
|
||||
address: string,
|
||||
@@ -17,6 +18,7 @@ const observe = (
|
||||
options: {
|
||||
readonly evidenceLimitations?: readonly string[];
|
||||
readonly dossierLimitations?: readonly string[];
|
||||
readonly relationshipCoverage?: RelationshipCoverage;
|
||||
} = {},
|
||||
): Evidence => {
|
||||
const value = functionDossierSchema.parse({
|
||||
@@ -69,6 +71,9 @@ const observe = (
|
||||
...(options.evidenceLimitations === undefined
|
||||
? {}
|
||||
: { limitations: options.evidenceLimitations }),
|
||||
...(options.relationshipCoverage === undefined
|
||||
? {}
|
||||
: { relationshipCoverage: options.relationshipCoverage }),
|
||||
},
|
||||
);
|
||||
};
|
||||
@@ -171,6 +176,21 @@ describe("call path reconstruction", () => {
|
||||
});
|
||||
|
||||
describe("call path topology and capacity", () => {
|
||||
it("retains every distinct generic limitation beyond the push argument limit", () => {
|
||||
const limitations = Array.from(
|
||||
{ length: 1_000_000 },
|
||||
(_, index) => `context-${index.toString().padStart(7, "0")}`,
|
||||
);
|
||||
const result = run([
|
||||
observe("0x1000", [], "rea-workflow", {
|
||||
evidenceLimitations: [...limitations].reverse(),
|
||||
}),
|
||||
]);
|
||||
expect(result.status).toBe("unknown");
|
||||
expect(result.search_scope.exhaustive).toBe(false);
|
||||
expect(result.limitations).toEqual(limitations);
|
||||
}, 30_000);
|
||||
|
||||
it("retains every shortest path through merging branches and cycles", () => {
|
||||
const result = run([
|
||||
observe("0x1000", ["0x3000", "0x2000", "0x1000"]),
|
||||
@@ -314,6 +334,96 @@ describe("call path topology and capacity", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("explicit call relationship coverage", () => {
|
||||
it.each([150_000, 1_000_000])(
|
||||
"accumulates %i partial reasons without argument-stack exhaustion",
|
||||
(length) => {
|
||||
const result = run([
|
||||
observe("0x1000", [], "rea-workflow", {
|
||||
relationshipCoverage: {
|
||||
status: "partial",
|
||||
limitations: Array<string>(length).fill("omitted"),
|
||||
},
|
||||
evidenceLimitations: [],
|
||||
dossierLimitations: [],
|
||||
}),
|
||||
]);
|
||||
expect(result).toMatchObject({
|
||||
status: "unknown",
|
||||
search_scope: { exhaustive: false },
|
||||
limitations: ["omitted"],
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("retains contextual limits on a found path without reducing complete coverage", () => {
|
||||
const limitation = "Provider results reflect the current database state.";
|
||||
const result = run([
|
||||
observe("0x1000", ["0x4000"], "rea-workflow", {
|
||||
relationshipCoverage: { status: "complete" },
|
||||
evidenceLimitations: [limitation],
|
||||
}),
|
||||
]);
|
||||
expect(result).toMatchObject({
|
||||
status: "found",
|
||||
shortest_hops: 1,
|
||||
search_scope: { exhaustive: true },
|
||||
});
|
||||
expect(result.limitations).toContain(limitation);
|
||||
});
|
||||
|
||||
it("retains a found path while its expanded relationship coverage remains partial", () => {
|
||||
const limitation = "Other callees were omitted by the provider cap.";
|
||||
const result = run([
|
||||
observe("0x1000", ["0x4000"], "rea-workflow", {
|
||||
relationshipCoverage: { status: "partial", limitations: [limitation] },
|
||||
}),
|
||||
]);
|
||||
expect(result).toMatchObject({
|
||||
status: "found",
|
||||
shortest_hops: 1,
|
||||
search_scope: { exhaustive: false },
|
||||
});
|
||||
expect(result.limitations).toContain(limitation);
|
||||
});
|
||||
|
||||
it("retains an unknown goal coverage reason without expanding the terminal goal", () => {
|
||||
const reason = "The goal's outgoing relationship coverage is unknown.";
|
||||
const result = run([
|
||||
observe("0x1000", ["0x4000"], "rea-workflow", {
|
||||
relationshipCoverage: { status: "complete" },
|
||||
}),
|
||||
observe("0x4000", ["0x5000"], "rea-workflow", {
|
||||
relationshipCoverage: { status: "unknown", reason },
|
||||
}),
|
||||
]);
|
||||
expect(result).toMatchObject({
|
||||
status: "found",
|
||||
search_scope: { exhaustive: true },
|
||||
explored: { nodes: 2 },
|
||||
});
|
||||
expect(result.limitations).toEqual([reason]);
|
||||
});
|
||||
|
||||
it("ignores incomplete relationship coverage outside the reachable search closure", () => {
|
||||
const reason = "An unrelated function's callees were not observed.";
|
||||
const result = run([
|
||||
observe("0x1000", [], "rea-workflow", {
|
||||
relationshipCoverage: { status: "complete" },
|
||||
}),
|
||||
observe("0x2000", ["0x5000"], "rea-workflow", {
|
||||
relationshipCoverage: { status: "unknown", reason },
|
||||
}),
|
||||
]);
|
||||
expect(result).toMatchObject({
|
||||
status: "not_found",
|
||||
search_scope: { exhaustive: true },
|
||||
explored: { nodes: 1 },
|
||||
});
|
||||
expect(result.limitations).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("call path evidence admission", () => {
|
||||
it("normalizes hex addresses and rejects duplicates and mixed providers", () => {
|
||||
expect(
|
||||
|
||||
+17
-2
@@ -236,12 +236,27 @@ const inspectSearch = ({
|
||||
const depth = reached.get(node) ?? 0;
|
||||
const snapshot = snapshots.get(node);
|
||||
if (snapshot !== undefined) {
|
||||
limitations.push(...snapshot.limitations);
|
||||
const coverage = snapshot.evidence.relationship_coverage;
|
||||
for (const limitation of snapshot.limitations)
|
||||
limitations.push(limitation);
|
||||
if (coverage?.status === "partial")
|
||||
for (const limitation of coverage.limitations)
|
||||
limitations.push(limitation);
|
||||
else if (coverage?.status === "unknown")
|
||||
limitations.push(coverage.reason);
|
||||
// The requested goal is a terminal for this search. Its outgoing edges
|
||||
// cannot add a path to the goal, so its dossier limits are contextual
|
||||
// but do not make the searched start-to-goal closure incomplete.
|
||||
if (node === goal) continue;
|
||||
if (snapshot.limitations.length > 0) incompleteExpandedCoverage = true;
|
||||
// Explicit, Evidence-bound relationship coverage owns completeness;
|
||||
// generic provider/dossier limitations remain contextual. Legacy Evidence
|
||||
// without that metadata retains its conservative limitation-based rule.
|
||||
if (
|
||||
coverage === null
|
||||
? snapshot.limitations.length > 0
|
||||
: coverage.status !== "complete"
|
||||
)
|
||||
incompleteExpandedCoverage = true;
|
||||
} else if (node === goal) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user