fix(javascript): refuse member-mutation work beyond a fixed allowance (#11144)

* fix(javascript): refuse member-mutation work beyond a fixed allowance

Member-mutation indexing retained every scheduled alias state until its query finished, with no bound on the phase. Conditional self-selections before one member write (#8294) multiplied those states until the worker heap was exhausted.

Charge each scheduled alias state to a per-phase work meter. Past 524,288 states the phase is refused with a resource_constraint that names the fixed work allowance. The application and web bundle workers carry the reported limit to the parent, which rebuilds the refusal with that allowance instead of heap advice.

Refs #8294 #6127 #6344 #7170 #7510 #8298

* test(javascript): prove the member-mutation meter spans the phase
This commit is contained in:
morluto authored and GitHub committed 2026-11-15 21:34:13 +08:00
1 parent 4eafd9dee5
commit d07ab79f9b
12 files changed
+371 -34

No files matched your search

@@ -6,6 +6,7 @@ import {
retainSemanticAmbientEffect,
} from "./javascriptSemanticAmbientWrites.js";
import { isIntrinsicMapLookup } from "./javascriptSemanticMapOperations.js";
import { JavaScriptSemanticWorkMeter } from "./javascriptSemanticWorkAllowance.js";
import {
isIntrinsicTypedArrayConstruction,
isTypedArrayNumericIndex,
@@ -515,6 +516,9 @@ export function* collectSemanticMemberMutationsSteps(
const deferredMapReceivers = new Set<
t.CallExpression | t.OptionalCallExpression
>();
// Alias states are retained until their query finishes; bound the phase
// before a pathological alias history exhausts the worker heap.
const work = new JavaScriptSemanticWorkMeter();
// The binding pass already retained callable nodes. Ordinary data-only code
// must not pay an alias walk for every member read or assignment.
const accessorKeys = {
@@ -923,6 +927,10 @@ export function* collectSemanticMemberMutationsSteps(
};
};
const pending: PendingValue[] = [];
const schedule = (value: PendingValue): void => {
work.charge();
pending.push(value);
};
// The effect, mutation and assigned sources belong to this invocation.
// Alias histories do not select a value: the binding/capture/projection do.
// Keep small alternatives exact. Bound additional states across this whole
@@ -949,7 +957,7 @@ export function* collectSemanticMemberMutationsSteps(
? resolveBinding(expression, expression.name)
: undefined;
if (binding === undefined) {
pending.push(value);
schedule(value);
return;
}
const observablePath = observablePaths.normalize(
@@ -1014,12 +1022,12 @@ export function* collectSemanticMemberMutationsSteps(
: { path, definiteReceiver, scheduled: false };
joinedProjections.set(key, joined);
if (!projectionsWidened) {
pending.push({ ...value, exactKey: key });
schedule({ ...value, exactKey: key });
return;
}
if (joined.scheduled) return;
joined.scheduled = true;
pending.push({
schedule({
...value,
path,
definiteReceiver,