perf(ci): optimize semantic graph construction, directory containment checks, gate checkouts, and boundary stragglers (#11851)

* perf(javascript): avoid redundant semantic graph validation and node hashing

* perf(resources): deduplicate directory containment checks and root lstat calls

* perf(ci): trace script fixture modules, sparse-checkout gate jobs, and parallelize built doc checks

* perf(tests): memoize live MCP doctor expectations and reuse CLI and verifier compilation

* fix(ci): enforce containment after skipped entries, validate interned contexts, and supervise doc and verifier teardowns

* fix(docs): decode buffered check output once to preserve multi-byte UTF-8
This commit is contained in:
morluto authored and GitHub committed 2026-11-17 14:57:30 -05:00
1 parent 015f726a9e
commit 84ee604c6d
25 files changed
+1650 -259

No files matched your search

@@ -84,6 +84,7 @@ import {
addSemanticGraphRelation as addRelation,
createSemanticGraphProjectionState as emptyState,
bindSemanticGraphApplicationNodes,
semanticNodeIdentityLookupKey,
type SemanticGraphProjectionState as BuilderState,
} from "./JavaScriptSemanticGraphConstruction.js";
import type {
@@ -332,7 +333,7 @@ export const createJavaScriptSemanticGraphProjection = (
root_artifact_sha256: rootArtifactSha256,
application_graph_id: applicationGraph.graph_id,
root_node_ids: [...state.roots],
evidence_contexts: state.evidenceContexts.contexts,
evidence_contexts: state.evidenceContexts.ownedContexts,
nodes: [...state.nodes.values()],
relations,
// The input is transferred to the factory; `fingerprints` is cleared below.
@@ -389,6 +390,7 @@ export const createJavaScriptSemanticGraphProjection = (
],
});
state.nodes.clear();
state.nodesByLookupKey.clear();
state.relations.clear();
state.unknowns.clear();
state.unknownOmissions.clear();
@@ -437,7 +439,10 @@ export const createJavaScriptSemanticGraphProjection = (
recordSemanticUnknownOmission(state, omission);
for (const context of projection.evidenceContexts)
state.evidenceContexts.adopt(context);
for (const node of newNodes) state.nodes.set(node.node_id, node);
for (const node of newNodes) {
state.nodes.set(node.node_id, node);
state.nodesByLookupKey.set(semanticNodeIdentityLookupKey(node), node);
}
for (const relation of projection.relations)
state.relations.set(relation.relation_id, relation);
for (const unknown of newUnknowns)
@@ -582,7 +587,7 @@ export function* projectJavaScriptSemanticFileSteps(
const fingerprints = yield* projectFileSteps(file, ir, state, paths);
return {
roots: [...state.roots],
evidenceContexts: state.evidenceContexts.contexts,
evidenceContexts: state.evidenceContexts.ownedContexts,
nodes: [...state.nodes.values()],
relations: [...state.relations.values()],
unknowns: [...state.unknowns.values()],
@@ -4,11 +4,11 @@ import type { JavaScriptApplicationGraph } from "../../domain/javascript/javascr
import type { JsonValue } from "../../domain/jsonValue.js";
import { javascriptDisplayText } from "../../domain/javascript/javascriptAstValues.js";
import {
createJavaScriptSemanticGraphNode,
createJavaScriptSemanticGraphUnknown,
createJavaScriptSemanticGraphRelation,
createOwnedJavaScriptSemanticGraphNode,
createOwnedJavaScriptSemanticGraphUnknown,
createOwnedJavaScriptSemanticGraphRelation,
JavaScriptSemanticEvidenceContextRegistry,
javaScriptSemanticNodeId,
withJavaScriptSemanticNodeApplicationIds,
} from "../../domain/javascript/javascriptSemanticGraph.js";
import type {
JavaScriptSemanticGraphNode,
@@ -29,6 +29,7 @@ import {
/** Mutable local projection state hidden from graph callers. */
export interface SemanticGraphProjectionState {
readonly nodes: Map<string, JavaScriptSemanticGraphNode>;
readonly nodesByLookupKey: Map<string, JavaScriptSemanticGraphNode>;
readonly relations: Map<string, JavaScriptSemanticGraphRelation>;
readonly unknowns: Map<string, JavaScriptSemanticGraphUnknown>;
/** Absolute retained unknown count allowed during this file; null outside admission. */
@@ -82,6 +83,7 @@ export interface SemanticRelationConstructionInput {
export const createSemanticGraphProjectionState =
(): SemanticGraphProjectionState => ({
nodes: new Map(),
nodesByLookupKey: new Map(),
relations: new Map(),
unknowns: new Map(),
unknownCapacity: null,
@@ -99,18 +101,26 @@ export const bindSemanticGraphApplicationNodes = (
applicationGraph.nodes,
);
for (const [identifier, node] of state.nodes) {
state.nodes.set(identifier, {
...node,
application_node_ids: [
...(applicationNodeIdsByLocation.get(
applicationLocationKey(
node.identity.artifact_sha256,
node.identity.module_path,
node.identity.source_range,
),
) ?? []),
],
});
const matched = applicationNodeIdsByLocation.get(
applicationLocationKey(
node.identity.artifact_sha256,
node.identity.module_path,
node.identity.source_range,
),
);
if (matched === undefined && node.application_node_ids.length === 0)
continue;
const updated = withJavaScriptSemanticNodeApplicationIds(
node,
matched ?? [],
);
if (updated !== node) {
state.nodes.set(identifier, updated);
state.nodesByLookupKey.set(
semanticNodeIdentityLookupKey(updated),
updated,
);
}
}
};
@@ -120,7 +130,7 @@ export const constructSemanticGraphNode = (
input: SemanticNodeConstructionInput,
state: SemanticGraphProjectionState,
): JavaScriptSemanticGraphNode =>
createJavaScriptSemanticGraphNode(
createOwnedJavaScriptSemanticGraphNode(
{
kind: input.kind,
identity: {
@@ -139,22 +149,40 @@ export const constructSemanticGraphNode = (
state.evidenceContexts,
);
const semanticNodeLookupKey = (
kind: JavaScriptSemanticGraphNode["kind"],
artifactSha256: string,
modulePath: string,
sourceRange: JavaScriptSourceRange | null,
roleKey: string,
): string =>
`${kind}:${artifactSha256}:${String(modulePath.length)}:${modulePath}:${sourceRange === null ? "-" : javascriptSourceRangeKey(sourceRange)}:${roleKey}`;
export const semanticNodeIdentityLookupKey = (
node: Pick<JavaScriptSemanticGraphNode, "kind" | "identity">,
): string =>
semanticNodeLookupKey(
node.kind,
node.identity.artifact_sha256,
node.identity.module_path,
node.identity.source_range,
node.identity.role_key,
);
/** Reuse retained identities and reject exhausted budgets before allocation. */
export const retainSemanticGraphNode = (
state: SemanticGraphProjectionState,
file: JavaScriptArtifactFile,
input: SemanticNodeConstructionInput,
): JavaScriptSemanticGraphNode | null => {
const identifier = javaScriptSemanticNodeId({
kind: input.kind,
identity: {
artifact_sha256: file.sha256,
module_path: file.path,
source_range: input.location,
role_key: input.roleKey,
},
});
const existing = state.nodes.get(identifier);
const lookupKey = semanticNodeLookupKey(
input.kind,
file.sha256,
file.path,
input.location,
input.roleKey,
);
const existing = state.nodesByLookupKey.get(lookupKey);
if (existing !== undefined) return existing;
if (typeof state.fileNodeBudget === "number" && state.fileNodeBudget <= 0) {
state.fileNodesDropped = true;
@@ -163,6 +191,7 @@ export const retainSemanticGraphNode = (
return addSemanticGraphNode(
state,
constructSemanticGraphNode(file, input, state),
lookupKey,
);
};
@@ -170,6 +199,7 @@ export const retainSemanticGraphNode = (
export const addSemanticGraphNode = (
state: SemanticGraphProjectionState,
node: JavaScriptSemanticGraphNode,
knownLookupKey?: string,
): JavaScriptSemanticGraphNode | null => {
const existing = state.nodes.get(node.node_id);
if (existing !== undefined) return existing;
@@ -182,6 +212,10 @@ export const addSemanticGraphNode = (
state.fileNodeBudget = budget - 1;
}
state.nodes.set(node.node_id, node);
state.nodesByLookupKey.set(
knownLookupKey ?? semanticNodeIdentityLookupKey(node),
node,
);
return node;
};
@@ -198,7 +232,7 @@ export const addSemanticGraphRelation = (
input.source.node_id === input.target.node_id
)
return;
const value = createJavaScriptSemanticGraphRelation(
const value = createOwnedJavaScriptSemanticGraphRelation(
{
source_node_id: input.source.node_id,
target_node_id: input.target.node_id,
@@ -252,7 +286,7 @@ export const addSemanticGraphUnknown = (
});
return;
}
const unknown = createJavaScriptSemanticGraphUnknown(
const unknown = createOwnedJavaScriptSemanticGraphUnknown(
input,
state.evidenceContexts,
);
@@ -267,7 +301,7 @@ export const addSemanticFallbackRoot = (
): void => {
const node = addSemanticGraphNode(
state,
createJavaScriptSemanticGraphNode(
createOwnedJavaScriptSemanticGraphNode(
{
kind: "module",
identity: {
@@ -5,6 +5,66 @@ import type { JsonValue } from "../../domain/jsonValue.js";
const INFERENCE_LIMITATION =
"This relationship is a conservative static candidate; it does not prove runtime execution or causal flow.";
const CANDIDATE_BUILTIN_LIMITATION =
"The built-in identity or its mutation state is unproven; this operation is conditional.";
const UNKNOWN_SYNTAX_LIMITATION =
"Dynamic syntax prevents an exact static relationship.";
const SEMANTIC_EXTRACTOR: ApplicationGraphEvidence["extractor"] = Object.freeze(
{
name: "rea-javascript-semantic-analysis",
version: "1",
operation: "analyze_javascript_application",
executable_sha256: null,
},
);
const EMPTY_LIMITS = Object.freeze(
[],
) as unknown as ApplicationGraphEvidence["coverage"]["limits"];
const COMPLETE_COVERAGE: ApplicationGraphEvidence["coverage"] = Object.freeze({
status: "complete",
truncated: false,
omitted_count: 0,
limits: EMPTY_LIMITS,
});
const EMPTY_STRINGS: readonly string[] = Object.freeze([]);
const INFERENCE_LIMITATIONS: readonly string[] = Object.freeze([
INFERENCE_LIMITATION,
]);
const CANDIDATE_BUILTIN_LIMITATIONS: readonly string[] = Object.freeze([
INFERENCE_LIMITATION,
CANDIDATE_BUILTIN_LIMITATION,
]);
const UNKNOWN_LIMITATIONS: readonly string[] = Object.freeze([
UNKNOWN_SYNTAX_LIMITATION,
]);
type AvailableArtifactReference = Extract<
ApplicationGraphEvidence["artifact"],
{ readonly available: true }
>;
const cachedFileArtifacts = new WeakMap<
JavaScriptArtifactFile,
AvailableArtifactReference
>();
const observedFileArtifact = (
file: JavaScriptArtifactFile,
): AvailableArtifactReference => {
const cached = cachedFileArtifacts.get(file);
if (cached !== undefined && cached.sha256 === file.sha256) return cached;
const created: AvailableArtifactReference = Object.freeze({
available: true,
artifact_id: `art_${file.sha256}`,
sha256: file.sha256,
});
cachedFileArtifacts.set(file, created);
return created;
};
/** Exact artifact-backed syntax evidence for one semantic graph node. */
export const observedSemanticEvidence = (
@@ -14,11 +74,7 @@ export const observedSemanticEvidence = (
authority: "ast-static-analysis",
state: "observed",
confidence: "exact",
artifact: {
available: true,
artifact_id: `art_${file.sha256}`,
sha256: file.sha256,
},
artifact: observedFileArtifact(file),
location:
location === null
? { available: true, value: { kind: "artifact-path", path: file.path } }
@@ -26,20 +82,10 @@ export const observedSemanticEvidence = (
available: true,
value: { kind: "source-range", source: file.path, ...location },
},
extractor: {
name: "rea-javascript-semantic-analysis",
version: "1",
operation: "analyze_javascript_application",
executable_sha256: null,
},
coverage: {
status: "complete",
truncated: false,
omitted_count: 0,
limits: [],
},
limitations: [],
evidence_ids: [],
extractor: SEMANTIC_EXTRACTOR,
coverage: COMPLETE_COVERAGE,
limitations: EMPTY_STRINGS as string[],
evidence_ids: EMPTY_STRINGS as string[],
});
/** Conservative static relationship evidence derived from one syntax node. */
@@ -50,7 +96,7 @@ export const inferredSemanticEvidence = (
authority: "static-relationship-inference",
state: "inferred",
confidence: "high",
limitations: [INFERENCE_LIMITATION],
limitations: INFERENCE_LIMITATIONS as string[],
});
/** Static relationship evidence anchored at the syntax that proves the link. */
@@ -62,24 +108,20 @@ export const inferredSemanticEvidenceAt = (
authority: "static-relationship-inference",
state: "inferred",
confidence: "high",
limitations: [INFERENCE_LIMITATION],
limitations: INFERENCE_LIMITATIONS as string[],
});
/** A built-in operation whose identity is conditional on loader or mutation facts. */
export const candidateBuiltinSemanticEvidence = (
file: JavaScriptArtifactFile,
location: JavaScriptSourceRange,
): ApplicationGraphEvidence => {
const evidence = inferredSemanticEvidenceAt(file, location);
return {
...evidence,
confidence: "low",
limitations: [
...evidence.limitations,
"The built-in identity or its mutation state is unproven; this operation is conditional.",
],
};
};
): ApplicationGraphEvidence => ({
...observedSemanticEvidence(file, location),
authority: "static-relationship-inference",
state: "inferred",
confidence: "low",
limitations: CANDIDATE_BUILTIN_LIMITATIONS as string[],
});
type SemanticBuiltinOperation = {
readonly builtinAuthority?: "candidate" | undefined;
@@ -160,5 +202,5 @@ export const unknownSemanticEvidence = (
authority: "unknown",
state: "unknown",
confidence: "unknown",
limitations: ["Dynamic syntax prevents an exact static relationship."],
limitations: UNKNOWN_LIMITATIONS as string[],
});
@@ -1,5 +1,5 @@
import {
createJavaScriptSemanticFingerprint,
createOwnedJavaScriptSemanticFingerprint,
type JavaScriptSemanticEvidenceContextRegistry,
} from "../../domain/javascript/javascriptSemanticGraph.js";
import type {
@@ -21,7 +21,7 @@ export const projectSemanticFunctionFingerprints = (
const callable = callableNodes.get(fingerprint.callableId);
if (callable === undefined) return [];
return [
createJavaScriptSemanticFingerprint(
createOwnedJavaScriptSemanticFingerprint(
{
function_node_id: callable.node_id,
algorithm: "rea.javascript-semantic-function",