fix(native): skip missing endpoints in investigation traces (#12220)

* fix(native): skip missing endpoints in investigation traces

* fix(native): count only eligible investigation trace edges

---------

Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
ShuaixinHuangandmorluto authored and GitHub committed 2026-11-19 11:59:24 +00:00
1 parent 94cbae6d0c
commit fa84be9f3a
2 files changed
+78 -7

No files matched your search

@@ -142,6 +142,41 @@ describe("native investigation graph traces", () => {
expect(trace).toMatchObject({ reached_depth: 1, truncated: false });
});
it.each(["forward", "backward"] as const)(
"keeps tracing after an edge to a missing node in the %s direction",
(direction) => {
const forward = direction === "forward";
const partial = nativeInvestigationGraphSchema.parse({
...graph,
truncated: true,
edges: [
{
...graph.edges[0],
id: "missing-endpoint",
from: forward ? "b" : "missing",
to: forward ? "missing" : "b",
},
...graph.edges,
],
});
const trace = traceNativeInvestigationGraph(partial, {
start: "b",
direction,
limits: { max_edges: forward ? 2 : 1 },
});
expect(trace.edges.map(({ id }) => id)).toEqual([forward ? "2" : "1"]);
expect(trace.nodes.map(({ id }) => id)).toEqual([
"b",
forward ? "c" : "a",
]);
expect(trace).toMatchObject({
truncated: true,
reason: "edge_target_missing_from_graph",
reached_depth: 1,
});
},
);
it("retains observed and inferred route edges plus unresolved dispatch", () => {
const trace = traceNativeInvestigationGraph(graph, { start: "a" });
expect(trace.nodes.map(({ id }) => id)).toEqual(["a", "b", "c"]);
@@ -211,6 +246,37 @@ describe("native investigation graph traces", () => {
);
});
it.each(["forward", "backward"] as const)(
"reports a missing endpoint after the last eligible %s edge fills the budget",
(direction) => {
const forward = direction === "forward";
const partial = nativeInvestigationGraphSchema.parse({
...graph,
truncated: true,
edges: [
graph.edges[0],
{
...graph.edges[0],
id: "missing-endpoint",
from: forward ? "b" : "missing",
to: forward ? "missing" : "a",
},
],
});
const trace = traceNativeInvestigationGraph(partial, {
start: forward ? "a" : "b",
direction,
limits: { max_edges: 1 },
});
expect(trace.edges.map(({ id }) => id)).toEqual(["1"]);
expect(trace).toMatchObject({
truncated: true,
reason: "edge_target_missing_from_graph",
reached_depth: 1,
});
},
);
describe("Interface Builder dispatch joins", () => {
it.each([
{
+12 -7
View File
@@ -242,16 +242,26 @@ export const traceNativeInvestigationGraph = (
const adjacent = adjacency.get(current.id) ?? [];
for (const edge of adjacent) {
const nextId =
edge.resolution === "unresolved"
? null
: direction === "forward"
? edge.to
: edge.from;
if (nextId !== null && !nodeById.has(nextId)) {
truncated = true;
reason ??= "edge_target_missing_from_graph";
continue;
}
if (selectedEdges.size + unresolved.size >= limits.max_edges) {
truncated = true;
reason = "max_edges_reached";
break;
}
if (edge.resolution === "unresolved") {
if (nextId === null) {
unresolved.set(edge.id, edge);
continue;
}
const nextId = direction === "forward" ? edge.to : edge.from;
const alreadyVisited = visited.has(nextId);
if (!alreadyVisited && current.depth >= limits.max_depth) {
truncated = true;
@@ -267,11 +277,6 @@ export const traceNativeInvestigationGraph = (
}
selectedEdges.set(edge.id, edge);
if (alreadyVisited) continue;
if (!nodeById.has(nextId)) {
truncated = true;
reason ??= "edge_target_missing_from_graph";
continue;
}
visited.add(nextId);
// A retained node has already been reached even if a later sibling
// exhausts a budget before this node is dequeued for expansion.