Skip to content
38 changes: 32 additions & 6 deletions docs/javascript-artifact-reconstruction.md
Original file line number Diff line number Diff line change
Expand Up @@ -597,17 +597,20 @@ The default semantic capacities are 100000 nodes across the application and
`--max-semantic-nodes-per-file`), each from 1 to 1000000. The per-file offer is
also bounded by the remaining application capacity. Raising these controls does
not bypass worker heap, execution deadline or parent result admission. Truncated
coverage reports both effective node ceilings; omitted relationships remain
unknown.
coverage lists both effective ceilings, `max_semantic_nodes` and
`max_semantic_nodes_per_file`. The limitation names only the ceiling that
stopped retention. Omitted relationships remain unknown.

Unknown records have independent defaults of 100000 across the application and
20000 per source. Select `max_semantic_unknowns` and
`max_semantic_unknowns_per_file` (CLI: `--max-semantic-unknowns` and
`--max-semantic-unknowns-per-file`), each from 1 to 1000000. The parent offers the
remaining capacity to the worker, and rejects excess records before adoption.
Unknown admission happens before canonical identity and provenance construction.
When capacity is exhausted, coverage is partial and truncated and names both
effective unknown ceilings. `coverage.omitted_unknown_occurrences` counts examined
When capacity is exhausted, coverage is partial and truncated. Coverage lists
both effective unknown ceilings, `max_semantic_unknowns` and
`max_semantic_unknowns_per_file`. The limitation names only the ceiling that
stopped retention. `coverage.omitted_unknown_occurrences` counts examined
emission occurrences by family and reason, including repeated emissions. It does
not claim distinct discarded identities or count frontiers in unexamined source.
Omitted unknown provenance and IDs are not retained. Existing source, node,
Expand All @@ -620,12 +623,35 @@ checkpoint at its 8 MiB bound with the same 6x retention expansion used at
admission. Earlier checkpoints are already charged to retained bytes; the
remaining inventory does not multiply the reserve. Streamed file transfers keep the default 512 MiB
allowance, and can grow with the parent's offered retention budget (8x byte
expansion), up to 2 GiB. Individual records remain bounded to 8 MiB. The parent
expansion), up to 2 GiB. Individual records remain bounded to 8 MiB. The 8 MiB
record ceiling and the 2 GiB file maximum have no runtime override, and raising
`max_heap_mb` does not raise them. The effective file ceiling follows the
parent's offered result budget. On Node, a larger CLI/MCP process heap
(`NODE_OPTIONS`, for example `--max-old-space-size=<MiB>`, after restarting that
process) can raise it up to 2 GiB. Selecting fewer `source_paths` can also
raise that effective allowance, because the reserve for remaining sources and
earlier retained results reduce the offered budget. Neither change raises the
record ceiling or the 2 GiB maximum. The parent
still independently checks actual bytes, record overhead, digests and source
identities before adopting results.

A source that exhausts the analyzer heap does not terminate the CLI/MCP
process. Completed static facts are retained, other files can still be analyzed,
process. On Node, the failure names `max_heap_mb` (CLI `--max-heap-mb`), the
effective mebibytes, the inclusive range 128 to 16384, and the 1024 MiB
default. A changed value applies on the next analysis, which starts a new
worker. It does not change a worker that is already running and does not
require restarting the REA server. On Bun, the same heap-exhaustion diagnostic
is not attributed to that V8 old-space limit, because Bun ignores the flag.
Raising `max_heap_mb` does not raise the parent result budget,
the transfer record ceiling, the 2 GiB transfer file maximum, the CLI/MCP
process heap, or fixed parser limits. The parent result budget follows that
process heap. On Node, set `NODE_OPTIONS` (for example `--max-old-space-size=<MiB>`)
in the environment that starts the CLI or MCP server, then restart that
process, to raise the parent heap and the result budget. A completed static
checkpoint that does not fit the parent's remaining heap names that parent
process heap. Increasing `max_heap_mb` does not raise it. On Node, the same
`NODE_OPTIONS` restart can raise the parent heap and admit the checkpoint.
Completed static facts are retained, other files can still be analyzed,
and unexamined semantic relationships remain explicit unknowns. The parent
also checks transfer expansion and accumulated results against its remaining
heap before accepting semantic facts. A resource-limited result has partial
Expand Down
13 changes: 9 additions & 4 deletions docs/javascript-recovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,15 @@ equivalence remain unknown. No network fetching occurs.

## Resource policy and verification

Each operation uses one worker, a 1 GiB address-space ceiling and a 120-second
deadline; it accepts up to 64 MiB of total input across all selected files and
128 MiB/10000 entries of staged
output, with 8 MiB per diagnostic/report stream. Exceeding a limit is an explicit
Each operation uses one worker, a 1 GiB address-space ceiling and a 120000 ms
deadline. That deadline has no runtime override: raising `analysis_timeout_ms`
or `max_heap_mb` does not raise it. An unchanged retry may hit the deadline
again. The operation accepts up to 64 MiB of total
input across all selected files and 128 MiB/10000 entries of staged output,
with 8 MiB per diagnostic/report stream. A `provenance.json` over that report
allowance names the fixed limit: this release has no runtime override, and
raising `max_heap_mb` or `analysis_timeout_ms` does not raise it. Malformed
reports stay distinct from that size refusal. Exceeding a limit is an explicit
failure with rollback. Selected inputs beyond the total input allowance return a
non-retryable `resource_constraint` with `resource: "file-size"` and
`reported_limits.maximum_input_bytes`/`remaining_input_bytes`; input that is not
Expand Down
136 changes: 136 additions & 0 deletions src/application/javascript/JavaScriptSemanticGraphBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,142 @@ it("bounds semantic node projection and reports the ceiling in coverage", () =>
({ name }) => name === "semantic_graph_node_ceiling",
),
).toBe(true);
expect(graph.coverage.limits).toEqual(
expect.arrayContaining([
expect.objectContaining({ name: "max_semantic_nodes" }),
expect.objectContaining({ name: "max_semantic_nodes_per_file" }),
]),
);
expect(graph.limitations.join("\n")).toContain(
"max_semantic_nodes_per_file is 20000",
);
expect(graph.limitations.join("\n")).not.toContain(
"max_semantic_nodes is 100000",
);
expect(graph.limitations.join("\n")).toContain("1 to 1000000");
expect(graph.coverage.limits).toEqual(
expect.arrayContaining([
{ name: "semantic_graph_node_ceiling", value: 100_000, unit: "items" },
{
name: "semantic_graph_file_node_ceiling",
value: 20_000,
unit: "items",
},
{ name: "max_semantic_nodes", value: 100_000, unit: "items" },
{ name: "max_semantic_nodes_per_file", value: 20_000, unit: "items" },
]),
);
});

const semanticApplication = {
graph_id: `jag_${"b".repeat(64)}`,
nodes: [],
};

const semanticFile = (path: string, value: string): JavaScriptArtifactFile => ({
path,
container_sha256: SHA256,
sha256: SHA256,
bytes: Buffer.byteLength(value),
inventory_artifact_id: `art_${SHA256}`,
kind: "javascript",
unpacked: false,
text: { included: true, value },
});

const finishSources = (
limits: {
readonly totalNodes: number;
readonly fileNodes: number;
},
sources: readonly { readonly path: string; readonly text: string }[],
) => {
const projection = createJavaScriptSemanticGraphProjection(limits);
for (const source of sources)
projection.projectFile(
semanticFile(source.path, source.text),
analyzeJavaScriptSemantics(source.text),
);
return projection.finish(SHA256, semanticApplication);
};

it("names only the node ceiling that stopped retention", () => {
const references = (count: number) => "external;\n".repeat(count);
const perFile = finishSources({ totalNodes: 10, fileNodes: 3 }, [
{ path: "only.js", text: references(5) },
]);
expect(perFile.nodes).toHaveLength(3);
expect(perFile.limitations.join("\n")).toContain(
"max_semantic_nodes_per_file is 3",
);
expect(perFile.limitations.join("\n")).not.toContain(
"max_semantic_nodes is 10",
);
expect(perFile.coverage.limits).toEqual(
expect.arrayContaining([
{ name: "semantic_graph_node_ceiling", value: 10, unit: "items" },
{ name: "semantic_graph_file_node_ceiling", value: 3, unit: "items" },
{ name: "max_semantic_nodes", value: 10, unit: "items" },
{ name: "max_semantic_nodes_per_file", value: 3, unit: "items" },
]),
);

const skipped = finishSources({ totalNodes: 4, fileNodes: 10 }, [
{ path: "first.js", text: references(3) },
{ path: "second.js", text: references(3) },
]);
expect(skipped.nodes).toHaveLength(4);
expect(
skipped.nodes.filter((node) => node.identity.module_path === "second.js"),
).toHaveLength(0);
expect(skipped.limitations.join("\n")).toContain("max_semantic_nodes is 4");
expect(skipped.limitations.join("\n")).not.toContain(
"max_semantic_nodes_per_file is 10",
);

const remaining = finishSources({ totalNodes: 5, fileNodes: 4 }, [
{ path: "first.js", text: references(2) },
{ path: "second.js", text: references(3) },
]);
expect(remaining.nodes).toHaveLength(5);
expect(remaining.limitations.join("\n")).toContain("max_semantic_nodes is 5");
expect(remaining.limitations.join("\n")).not.toContain(
"max_semantic_nodes_per_file is 4",
);

const both = finishSources({ totalNodes: 5, fileNodes: 3 }, [
{ path: "first.js", text: references(5) },
{ path: "second.js", text: references(3) },
]);
expect(both.nodes).toHaveLength(5);
expect(both.limitations.join("\n")).toContain("max_semantic_nodes is 5");
expect(both.limitations.join("\n")).toContain(
"max_semantic_nodes_per_file is 3",
);
expect(both.limitations.join("\n")).toContain(
"Set max_semantic_nodes and max_semantic_nodes_per_file",
);
});

it("attributes an adopted file to the ceiling that bounded its offer", () => {
const text = "external;\n".repeat(5);
const projection = createJavaScriptSemanticGraphProjection({
totalNodes: 10,
fileNodes: 3,
});
const steps = projectJavaScriptSemanticFileSteps(
semanticFile("adopted.js", text),
analyzeJavaScriptSemantics(text),
projection.remainingFileCapacity(),
);
let step = steps.next();
while (!step.done) step = steps.next();
projection.adoptFileProjection(step.value);
const limitation = projection
.finish(SHA256, semanticApplication)
.limitations.join("\n");
expect(limitation).toContain("max_semantic_nodes_per_file is 3");
expect(limitation).not.toContain("max_semantic_nodes is 10");
});

it("leaves a small application complete and untruncated", () => {
Expand Down
Loading
Loading