fix(runtime): retain complete reconciled graph content

This commit is contained in:
morluto committed 2026-09-29 11:38:03 +08:00
1 parent 24e1fa9a76
commit bedd55a4b4
3 files changed
+18 -39

No files matched your search

@@ -47,11 +47,8 @@ export const buildReconciledApplicationGraph = (
...input.runtime.edges,
...input.reconciliationEdges,
]);
const bounded = boundGraphContent(input, merged.nodes, allEdges);
const facts = graphCoverageFacts(
input,
merged.omittedObservations + bounded.omittedItems,
);
const bounded = boundGraphContent(input, merged, allEdges);
const facts = graphCoverageFacts(input, bounded.omittedItems);
const graph = createJavaScriptApplicationGraph({
schema: "JavaScriptApplicationGraph",
root_node_ids: bounded.rootNodeIds,
@@ -77,7 +74,7 @@ export const buildReconciledApplicationGraph = (
});
return {
graph,
omittedGraphItems: merged.omittedObservations + bounded.omittedItems,
omittedGraphItems: bounded.omittedItems,
};
};
@@ -92,32 +89,23 @@ const boundGraphContent = (
readonly omittedItems: number;
} => {
const allRoots = preferredRootIds(input);
const rootNodeIds = allRoots.slice(0, 1_000);
const roots = new Set(rootNodeIds);
const rootNodeIds = allRoots;
const sortedNodes = [...nodes].sort((left, right) =>
compareCodePoints(left.node_id, right.node_id),
);
const retainedNodes = [
...sortedNodes.filter(({ node_id: id }) => roots.has(id)),
...sortedNodes.filter(({ node_id: id }) => !roots.has(id)),
].slice(0, 100_000);
const retainedNodes = sortedNodes;
const retainedIds = new Set(retainedNodes.map(({ node_id: id }) => id));
const retainedEdges = [...edges]
.sort((left, right) => compareCodePoints(left.edge_id, right.edge_id))
.filter(
({ source_node_id: source, target_node_id: target }) =>
retainedIds.has(source) && retainedIds.has(target),
)
.slice(0, 200_000);
);
return {
rootNodeIds,
nodes: retainedNodes,
edges: retainedEdges,
omittedItems:
allRoots.length -
rootNodeIds.length +
(nodes.length - retainedNodes.length) +
(edges.length - retainedEdges.length),
omittedItems: 0,
};
};
@@ -219,16 +207,10 @@ const graphCoverage = (
limits: [],
};
const mergeNodes = (
nodes: readonly ApplicationNode[],
): {
readonly nodes: ApplicationNode[];
readonly omittedObservations: number;
} => {
const mergeNodes = (nodes: readonly ApplicationNode[]): ApplicationNode[] => {
const grouped = new Map<string, ApplicationNode[]>();
for (const node of nodes)
grouped.set(node.node_id, [...(grouped.get(node.node_id) ?? []), node]);
let omittedObservations = 0;
const merged = [...grouped.values()].map((group) => {
const first = group[0];
if (first === undefined) throw new TypeError("Empty JAG node group");
@@ -249,19 +231,16 @@ const mergeNodes = (
].sort((left, right) =>
compareCodePoints(left.observation_id, right.observation_id),
);
omittedObservations += Math.max(0, observations.length - 64);
return createJavaScriptApplicationNode({
kind: first.kind,
identity: first.identity,
observations: observations
.slice(0, 64)
.map(
({ observation_id: _id, identifier_strategy: _strategy, ...value }) =>
value,
),
observations: observations.map(
({ observation_id: _id, identifier_strategy: _strategy, ...value }) =>
value,
),
});
});
return { nodes: merged, omittedObservations };
return merged;
};
const uniqueEdges = (edges: readonly ApplicationEdge[]): ApplicationEdge[] => [
@@ -86,10 +86,10 @@ const captureSummaries = (
kind: capture.kind,
target_node_id: targetNode.node_id,
target_key: capture.inspection.target.target_id,
target_location: ("url" in capture.inspection.target
? capture.inspection.target.url
: capture.inspection.target.file_path
).slice(0, 4_096),
target_location:
"url" in capture.inspection.target
? capture.inspection.target.url
: capture.inspection.target.file_path,
frames: capture.inspection.frames.length,
scripts: capture.inspection.scripts.items.length,
workers: capture.inspection.workers.length,
@@ -173,7 +173,7 @@ const captureSummarySchema = z.strictObject({
kind: z.enum(["browser", "electron", "v8-inspector", "electron-active"]),
target_node_id: nodeIdSchema,
target_key: boundedTextSchema,
target_location: boundedTextSchema,
target_location: z.string().min(1).max(131_072),
frames: z.number().int().min(0),
scripts: z.number().int().min(0),
workers: z.number().int().min(0),