Skip to content

fix(javascript): answer an over-budget member-mutation query by escaping whole objects - #14153

Merged
morluto merged 4 commits into
mainfrom
fix/javascript-member-mutation-query-budget
Nov 23, 2026
Merged

morluto merged 4 commits into
mainfrom
fix/javascript-member-mutation-query-budget

Conversation

@morluto

@morluto morluto commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

Refs #14150.

Member-mutation analysis walks alias states with exact member paths, once per query. On a dense alias cluster, a single query can schedule tens of thousands of states. A handful of such queries then spend the whole per-source allowance (javascript.member_mutation_alias_states), and the source is refused with no semantic result.

This PR gives each query its own state budget. A query that outgrows it is answered again by escaping whole objects, and that answer is shared by later queries.

Behavior

  • Budget: semantic_precision.alias_selections × 8 states per top-level query, which is 4,096 at the default. It is derived from the existing control so the reported limit and its recovery stay truthful: raising alias_selections raises the budget.
  • Collapsed answer: the query is re-run as an escape of the whole value, and every alias reached through a projection escapes whole. For a write, every value it stored (including guarded alternatives) also escapes, because those values become reachable through an object whose members are no longer tracked.
  • No site on the collapsed escape: it is recorded without a site, so it may precede any read. Readers already treat a site-less effect as unknown timing. Its alias states then do not depend on the query that reached them, so a later collapsed query stops at whatever an earlier one covered, instead of walking the same cluster again.
  • Why this is sound: the module's existing rule is that an escape at a prefix covers every longer effect, so the collapsed answer is a superset of the exact one. Dropping the site widens it further. Effects the abandoned exact attempt already recorded are true and are kept. Collapsed states are keyed separately, so coverage retained by the abandoned attempt cannot suppress the collapsed answer.
  • Dense bindings: bindings an abandoned query walked are remembered. A later query that reaches one collapses immediately, without first spending its budget.
  • Disclosure: the alias-selections resource limit is recorded, so coverage is partial with the existing limitation text.
  • The per-source allowance is unchanged and still enforced.

Effect

Local, macOS arm64, Node 24.22.1, in-process.

Ordinary sources are unaffected. Over 121 completing files in a 122-file sample of real JavaScript (349,885 queries), the largest query on main schedules 407 states, so the budget never triggers. A 359-file sample (10.4 MB) compared by SHA-256 of static facts and semantic IR against main has 0 differences. The harness is a local script, not part of this PR.

The #8294 pathology completes. selections(8), which the allowance test used to expect a refusal for, completes in 19 ms with partial coverage; selections(32) completes in 22 ms; selections(4) is still complete.

A real bundle completes at the default allowance. playwright-core/lib/vite/dashboard/assets/index-hRvO4yU2.js (328 KB, Vite + React):

main this PR
default allowance (524,288) refused at 20% of the file after 3.9 s completes: 353,816 states (279,628 exact, 74,188 collapsed), static 24.5 s, semantic 7.1 s, heap 320 MiB
allowance 16,000,000 Node aborted out of memory at about 6 GB not measured

28,396 queries ran and 1,866 collapsed, at 40 states each on average. Before the site was dropped, a collapsed query cost about 212 states and the bundle needed an allowance of about one million.

The result has partial coverage, 6,122 bindings, 1,558 callables, 5,564 call sites and 3 request operations. Binding values: 190 literal, 5,006 unknown, 902 ambiguous. Those counts are the same with and without the site on the collapsed escape.

Tests

  • New javascriptMemberMutationQueryBudget.test.ts:
    • an over-budget query completes with a disclosed bound;
    • a collapsed write escapes the value it stored (control: with that rule disabled, the test fails);
    • a hundred queries into one cyclic cluster fit an allowance of 3,000 (control: with site-specific collapsed escapes the same source needs 4,118 and the test fails; with sharing it needs 1,973);
    • a query within its budget stays exact and undisclosed.
  • javascriptSemanticWorkAllowance.test.ts: the default-allowance refusal test asserted a refusal for selections(8). That source now completes, so the test asserts the conservative answer for 8 and 32 selections, and the refusal's contract fields are asserted on javaScriptMemberMutationRefusal directly.
  • src/domain/javascript/*.test.ts and src/javascript/analysis/*.test.ts: 209 files, 6,235 tests passed. Allowance tests in src/config, src/browser, src/application/javascript and tests/boundary/javascript passed, as did the javascriptReturnedReferences and javascriptAnalysisLimits acceptance tests.
  • oxfmt --check; check:fast.

Not done

…ing whole objects

Member-mutation analysis enumerates alias states with exact member paths
for each query. On a dense alias cluster one query can schedule tens of
thousands of states, so a handful of queries spent the whole per-source
allowance and the source was refused: a 328 KB Vite and React bundle was
refused at any allowance.

Each query now has a state budget derived from
semantic_precision.alias_selections. A query that outgrows it is answered
again as an escape of the whole value and of every value a write stored
into it. An escape covers every effect below it, so the answer is a
superset of the exact one; the alias-selections limit is recorded.
Bindings an abandoned query walked are remembered so later queries that
reach them collapse without spending their budget first.

Refs #14150
@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-23T21:15:50.995380Z
We couldn’t complete this review. Comment @codex review to try again.
9fe158d 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 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new blocking issues were found.

Summary

The PR gives each member-mutation query a budget. Queries that exceed it restart by escaping whole objects, disclose reduced precision, and share work across later queries.

  • Dense member-mutation queries now finish with conservative answers.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Start query] --> B[Walk exact member paths]
  B --> C{Query exceeds budget?}
  C -->|No| D[Keep exact answer]
  C -->|Yes| E[Disclose reduced precision]
  E --> F[Escape whole receiver and stored values]
  F --> G[Share covered escapes]
  B --> H[Charge source allowance]
  F --> H
Loading

Reviews (3) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

…site

A collapsed query escaped whole objects at its own call site, so every
collapsed query walked the same dense alias cluster again. An escape that
names no site may precede any read, which readers already treat as
unknown timing. Its alias states then do not depend on the query that
reached them, and a later collapsed query stops at whatever an earlier
one covered.

Refs #14150
@morluto

morluto commented Nov 23, 2026

Copy link
Copy Markdown
Owner Author

Integration note with #14148. The two merge cleanly in git but do not compile together: #14148 moves the limit sets under state.observations, and this PR records a limit with state.valueResourceLimits.add("alias-selections") in the markValue wrapper. Whichever lands second needs that one line changed to state.observations.valueResourceLimits (or the reverse rename if this lands first, which the mechanical rename in #14148 would then cover on rebase).

I verified the full stack on a temporary merge of #14148, #14149, #14153, #14171 and #14191 with that one-line adjustment: 462 unit test files (10,903 tests) and all 28 tests/boundary/javascript files pass.

End to end through the CLI (analyze-javascript-application <dir> --artifact-format directory --json, same 328 KB bundle, macOS arm64, one run each):

main combined
exit / wall / peak RSS 0 / 7.0 s / 676 MiB 0 / 13.6 s / 729 MiB
visited_ast_nodes 0 109,149
findings 0 11
semantic graph 1 node, 0 relations 20,000 nodes, 19,151 relations, 1,512 fingerprints
limitation member-mutation refusal at 524,288 alias states alias-selection bound, partial coverage
output 31.5 KB 42.7 MB

main exits 0 with an empty analysis and the refusal in limitations. The 42.7 MB complete output and the node count of exactly 20,000 are worth a separate look.

…er alias

A collapsed query started a nested walk for every alias reached through
a projection, so a long chain of projected aliases nested one call per
link and overflowed the call stack, where the exact walk follows the
same links through its queue. An escape walk now queues the whole-object
escape as another state.
@morluto
morluto enabled auto-merge (squash) November 23, 2026 23:02
@morluto
morluto merged commit c4916a6 into main Nov 23, 2026
40 checks passed
@morluto
morluto deleted the fix/javascript-member-mutation-query-budget branch November 23, 2026 23:08
morluto added a commit that referenced this pull request Nov 24, 2026
…tions (#14220)

#14153 added a collapsed member-mutation query that recorded its
resource limit on state.valueResourceLimits. #14148, merged after it,
moved that set under state.observations, so the line failed typecheck
and threw at runtime when a query exceeded its state budget.
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working labels 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