Skip to content

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

Merged
morluto merged 2 commits into
mainfrom
fix/javascript-member-mutation-work-allowance
Nov 15, 2026
Merged

morluto merged 2 commits into
mainfrom
fix/javascript-member-mutation-work-allowance

Conversation

@morluto

@morluto morluto commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Member-mutation indexing in the JavaScript semantic engine had no bound on the work one source could take. A short alias history (#8294) made it keep scheduling alias states until the worker heap ran out, so the file was skipped after tens of seconds with heap advice that does not help. This PR adds a per-phase work meter. When a source passes a fixed allowance, the phase stops with a typed resource_constraint that names the allowance. This is step 5 of plan W10 (per-phase work meter with a fixed-ceiling refusal), applied first to the member-mutation phase, where the reports point.

Refs #8294 #6127 #6344 #7170 #7510 #8298. None of them is fully fixed: each still loses that source's facts. They now get a bounded typed refusal instead of heap exhaustion or a timeout.

Problem and expected behavior

Smallest trigger: eight conditional self-selections before one member write (351 bytes, from the #8294 thread):

function probe(input,env){var m;if(env.first)m=env.first.info;if(/case0/.test(input))m=m[0]; … if(/case7/.test(input))m=m[1];m[1]=input.length;return m}module.exports=probe;

markValue in collectSemanticMemberMutationsSteps keeps every scheduled alias state until its query finishes. After the existing alias-selections widening, scheduling continues and grows about 8× per added selection. Measured on main (in-process analyzeJavaScriptSemantics, Node 24.22.1, --max-old-space-size=1024):

selections scheduled alias states elapsed peak RSS
5 7,343 66 ms 147 MiB
6 52,003 303 ms 280 MiB
7 400,807 2.3 s 642 MiB
8 (heap exhausted) — 1 GiB heap

[email protected] umd/react-dom.production.min.js (sha256 35f4f974…6f0d) exhausts a 2 GiB heap the same way. At 1,000,000 processed states its worklist held 484,415 pending states and 1.16 GiB of heap.

Expected: the phase stays bounded and the refusal says which deterministic allowance was exceeded. Raising heap or timeout does not admit the same source.

Change and scope

  • New owner src/domain/javascript/javascriptSemanticWorkAllowance.ts: JavaScriptSemanticWorkMeter (one per phase run) and JAVASCRIPT_MEMBER_MUTATION_WORK_ALLOWANCE = 524_288 alias states per source. Charging past it throws AnalysisResourceConstraintError (resource cpu, reported limit javascript_member_mutation_alias_state_limit, fixed allowance kind work, not retryable). javaScriptSemanticWorkAllowance(limits) rebuilds the fixed-allowance recovery from reported limits, so each process boundary derives it from one place.
  • javascriptSemanticMemberMutations.ts: each markValue schedules through one schedule helper that charges the phase meter before retaining the state. Charging happens at scheduling, not processing, because scheduling outruns processing (react-dom above).
  • Application worker parent (JavaScriptAnalysisWorker#protocolFailure): a reported work limit becomes the fixed-allowance recovery, not the heap or result-budget remediation. The worker server already forwards AnalysisResourceConstraintError resource and limits.
  • Web bundle worker: before this change, the server wrapped any analyzer exception as "invalid result" (output), and the parent reported every resource frame as measured memory exhaustion. Now the server forwards the refusal as resource with its reported limits (new optional field on the failure frame). The parent maps it through the same owner to resource cpu with the fixed allowance. Other resource frames are unchanged.
  • Docs: javascript-artifact-reconstruction.md describes the allowance next to semantic_precision.

Why a refusal and not partial results: a member-mutation index that stops partway leaves later reads with stale literals. Making every affected binding, ambient path and required-module export unknown would have to reach each index those reads consult. That is the pushed-havoc redesign (audit C1 step 3), not this bound.

Why fixed and not a semantic_precision field: the plan asks for a fixed ceiling, and adding a field changes the advertised input schema. Making it caller-selectable is a follow-up decision. The value is sized from measurements, below.

Not included:

Contract and boundary impact

  • Semantic owner and earliest changed stage: javascriptSemanticWorkAllowance.ts owns the allowance, meter and recovery. Consumers: member-mutation indexing (producer), the application worker parent, and the web bundle worker server and parent. No superseded path remains. The web bundle parent's two duplicated resource-frame constructions now share one helper.
  • Contribution scope fit and linked maintainer decision: bounded-resource fix within existing analysis; not applicable.
  • CLI and MCP/tool-catalog contract: no schema change. A source that passes the allowance now fails with resource_constraint (resource cpu, fixed work allowance) instead of a worker heap exhaustion or timeout.
  • Provider, bridge, target-format, or platform compatibility: none. The internal web bundle worker failure frame gains an optional limits field. Parent and worker ship together.
  • Evidence, artifact, provenance, or reconstruction contract: per-source limitation text changes for refused sources only. Sources within the allowance are unchanged; see the corpus comparison.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable. Worker lifecycle is unchanged; a refusal is a normal failure frame.
  • Generated metadata, package, or installation impact: none.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated:

    • src/domain/javascript/javascriptSemanticWorkAllowance.test.ts: the 8-selection fixture is refused with the fixed allowance (about 2 s, about 700 MiB RSS for the test process, which is the cost of reaching the allowance). The 4-selection control completes.
    • src/domain/javascript/javascriptSemanticWorkAllowance.phase.test.ts: three write queries in one source charge one meter, and each source gets a fresh meter (fails if the meter moves into markValue).
    • tests/boundary/javascript/javascriptSourceAnalysisWorker.test.ts: a worker failure frame that reports the work limit becomes resource cpu, retryable: false, a fixed work allowance and no remediation sentence.
    • src/browser/WebBundleAnalysisWorkerServer.test.ts: the real worker server, with an analyzer that hits the meter, sends reason: "resource" with the reported limit and canonical reason.
    • src/browser/WebBundleAnalysisWorker.test.ts: the parent maps that frame to resource cpu with the fixed allowance.
  • Base reproduction: with JavaScriptAnalysisWorker.ts and WebBundleAnalysisWorker.ts restored from main, both parent tests fail (1 failed | 16 passed and 1 failed | 34 passed). On main the 8-selection fixture exhausts a 1 GiB heap (standalone run above). The server test would get an output frame from the old wrapper.

  • Measurements (executed; in-process analyzeJavaScriptSemantics, one cold tsx process per input, Node 24.22.1, macOS arm64, shared machine with load average 7–11, so times are noisy):

    input bytes alias states scheduled before after
    8 selections 350 > 524,288 heap exhausted (1 GiB) refused in 2.1 s, 637 MiB peak RSS, 3.1 s CPU
    react-dom 18.3.1 UMD 131,835 > 524,288 heap exhausted (2 GiB) refused in 20.7 s, 916 MiB peak RSS, 18.3 s CPU (1 GiB heap)
    7 selections 320 400,807 completes completes, no status change

    Corpus within the allowance: the same 14 published bundles from node_modules that fix(javascript): expose operands of unmodelled implicit execution #10631 used. Alias states scheduled per source (largest first): openpgp 122,568, rxjs 121,353, isomorphic-git 102,163, pako 66,229, docsearch 54,988, vue 33,075, zip.js 24,092, vueuse 18,880, algoliasearch 10,991, handlebars 10,397, js-yaml 6,744, preact 5,799, diff 4,798, underscore 4,237. The largest is 23% of the allowance; the largest single query (rxjs) scheduled 28,377 states, and every other query stayed at or below 307. Every value status was compared by JSON path between main and this branch: 0 changes across 81,312 values, and no refusals. The semantic IR is unchanged for these sources, so agent tokens are unchanged; they were not measured separately.

  • Sizing: retained states cost about 1.1–1.6 KiB each (react-dom: 1.16 GiB heap at 1,084,531 scheduled; 7 selections: 642 MiB RSS at 400,807). 524,288 keeps a refused source below the default 1 GiB worker heap on both fixtures. 262,144 would leave 2.1× headroom over the corpus maximum.

  • User-visible CLI/MCP output: not captured from a built CLI run. The refusal reason is JavaScript member-mutation analysis scheduled more than 524288 alias states for one source. Recovery names "The JavaScript member-mutation work allowance" as a fixed work allowance.

  • Remaining proof gaps: no end-to-end rea analyze-javascript-application or analyze-web-bundle run on react-dom. Elapsed-time numbers are single cold runs on a loaded machine. Large real bundles from analyze-javascript-application: semantic phase never completes on a 6.5 MB minified Electron main.js (3 timeouts, incl. reduced semantic limits) #7170 (6.5 MB) and [Bug] analyze-javascript-application never completes on a 20 MB Expo Router web bundle, even with semantic limits at 1 #7510 (20 MB) are unavailable locally. They may now be refused instead of running until the deadline, which loses no facts they currently return but is unmeasured.

  • Observed, derived, and inferred claims remain distinguishable.

  • Artifact identity, source provenance, and failed attempts remain preserved.

  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:local -- src/domain/javascript/javascriptSemanticWorkAllowance.test.ts src/browser/WebBundleAnalysisWorkerServer.test.ts — 8 passed.
  • npm run test:local -- src/domain/javascript/javascriptSemanticWorkAllowance.phase.test.ts — 2 passed (2 failed with the meter moved into markValue).
  • npm run test:local -- src/browser/WebBundleAnalysisWorker.test.ts — 35 passed (1 failed with the parent change reverted).
  • npm run test:focused -- tests/boundary/javascript/javascriptSourceAnalysisWorker.test.ts — 17 passed (1 failed with the parent change reverted).
  • npm run test:local -- src/domain/javascript/javascriptMemberMutationCoverage.test.ts src/domain/javascript/javascriptSemanticAnalysis.execution_points.test.ts src/domain/javascript/javascriptSemanticExecutionPoints.test.ts — 78 passed.
  • npm run check:fast — passed.
  • npm run docs:check — passed.
  • node scripts/verify/architecture-guards.mjs — passed.
  • npx oxfmt --check on changed files — passed.
  • Corpus and fixture measurements above (scratch scripts, not committed).

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Sources that previously exhausted the heap or timed out now get a typed refusal sooner.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; macOS arm64 only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: bounds worker memory and CPU for adversarial or pathological sources; no new authority.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

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
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-15T13:20:52.410421Z
We couldn’t complete this review. Comment @codex review to try again.
59e2663 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with the previous coverage gap addressed.

Summary

This PR caps member-mutation work and carries the fixed-allowance refusal through both worker paths.

  • JavaScript member-mutation analysis stops at a fixed per-source work limit.
  • Web-bundle analysis carries fixed work refusals across its worker boundary.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Schedule an alias state] --> B[Charge the source's meter]
  B --> C{Allowance exceeded?}
  C -->|No| D[Retain the state]
  C -->|Yes| E[Throw typed resource refusal]
  E --> F[Worker forwards reason and limits]
  F --> G[Parent restores fixed work allowance]
Loading

Reviews (2) · Last reviewed commit: "test(javascript): prove the member-mutat..." · Reviewed by Greptile

@morluto
morluto merged commit d07ab79 into main Nov 15, 2026
7 of 9 checks passed
@morluto
morluto deleted the fix/javascript-member-mutation-work-allowance branch November 15, 2026 13:34
morluto added a commit that referenced this pull request Nov 15, 2026
…etting

The member-mutation alias-state allowance from #11144 was a fixed constant, so a refused source could not be admitted without a code change.

Register javascript.member_mutation_alias_states (default 524288, 1 to 8388608 alias states) with the launch seed REA_JAVASCRIPT_MEMBER_MUTATION_ALIAS_STATES. The application, web bundle and reference-source boundaries resolve it from the accepted operation snapshot and launch environment, refuse a malformed seed before analysis, and send it to the workers with each source. A refusal names the setting, its effective value, source and range, and the recovery; worker parents rebuild it from the allowance they sent.

Refs #8294
morluto added a commit that referenced this pull request Nov 15, 2026
…etting (#11181)

* feat(javascript): make the member-mutation work allowance a runtime setting

The member-mutation alias-state allowance from #11144 was a fixed constant, so a refused source could not be admitted without a code change.

Register javascript.member_mutation_alias_states (default 524288, 1 to 8388608 alias states) with the launch seed REA_JAVASCRIPT_MEMBER_MUTATION_ALIAS_STATES. The application, web bundle and reference-source boundaries resolve it from the accepted operation snapshot and launch environment, refuse a malformed seed before analysis, and send it to the workers with each source. A refusal names the setting, its effective value, source and range, and the recovery; worker parents rebuild it from the allowance they sent.

Refs #8294

* fix(javascript): keep the setting and recovery of a refused web script

A web bundle script refused by the member-mutation allowance kept only its reason and reported limits, so the public unknown lost the setting, value, source and recovery. Carry the refusal's structured limit and remediation on the per-script result and its javascript_analysis unknown, grouping scripts only when that recovery agrees. Assert structured limit facts and the owning formatter's recovery instead of fixed wording.

* fix(browser): keep only registered setting limits on a refused web script

* feat(javascript): keep syntax facts for a source whose member-mutation phase is refused (#11187)

* feat(javascript): keep syntax facts for a source whose member-mutation phase is refused

A source refused by the member-mutation work allowance during static analysis lost every fact, so the application graph counted it as skipped. Reference-source import failed outright on such a file.

Checkpoint the parser, comment and text facts the static owner can still state, with parse status partial, examination not-examined and refused_phase member-mutations, before reporting the refusal; the semantic phase is not started because it indexes the same mutations. Reference-source import keeps the file's declaration-level imports and records that its CommonJS require calls were not examined.

Refs #8294

* test(javascript): compare the reference-source refusal with its owning formatter

* feat(javascript): keep a refused web script's parse and text facts

A captured script whose member-mutation phase was refused lost every fact in analyze_web_bundle, so it was neither counted as parsed nor kept its vendor markers.

The analyzer now returns the script as unavailable with partial facts: refused phase, parse status and the inferences read from script text alone. Findings gathered before the refusal are dropped, because they may have read an incomplete mutation index. The worker parent states the refusal and its setting recovery from the allowance it sent, through the same helper the isolated analyzer uses for every unavailable script. The bundle counts the script as parsed, keeps its text inferences, and its javascript_analysis unknown carries refused_phase.

Refs #8294

* chore(mcp): record the member-mutation setting in the advertised summary

* fix(javascript): rebuild a parked source worker when the member-mutation allowance changes

A worker parked on a resource scope was reused when heap, timeout and precision matched, but its requests carry the allowance it was built with. After update_analysis_settings accepted a new allowance, the next analysis on that scope kept the old one.

The reuse check now compares the allowance's value and source, so a changed setting gets a worker built with it. The web bundle worker already takes the allowance per script.
@morluto morluto added the bug Something isn't working label Nov 22, 2026
@morluto morluto added the area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior label Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant