Repository navigation
fix(javascript): keep strict module checks unproven when alias walks exhaust their budget - #9387
Conversation
…exhaust their budget Fixes morluto#8201.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] The PR appears safe to merge, with the earlier non-blocking test weakness still present. Findings
Fix with agent prompt### Issue 1
src/domain/javascript/javascriptStaticAnalysisAssignedRequire.test.ts:217-218
`exhaustedWalkWrite` includes a loop-aliased `Object.defineProperty(r,k,...)` write that already makes the loader unknown, as the test at line 198 shows. The later tests therefore pass even if the added receiver assignment, `Object.defineProperty`, or `Object.assign` is never recorded.
Remove the helper's independent write and add a control without the tested write. That will let these tests catch a broken cutoff fix.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryThe PR separates a possible module source, a completed negative search, and an incomplete search.
No new findings were accepted. Supersession could not be checked because GitHub access was unavailable. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Check a write receiver] --> B[Walk selected sources]
B --> C{Search result}
C -->|Possible module source| D[Record the write]
C -->|Incomplete search| D
C -->|Completed without a match| E[Do not record the write]
D --> F[Apply existing write timing]
F --> G[Keep affected loader unknown]
Reviews (8) · Last reviewed commit: "fix(javascript): retain uncertainty at a..." · Reviewed by Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 13608c7530
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…hausts its budget A strict check that exhausts the alias budget stopped the whole walk, so a module branch queued beside the growing alias was never examined. Stop expanding instead, and drain the queued sources.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 63a951c0d8
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| depths: readonly number[], | ||
| ...sources: ModuleObjectSource[] | ||
| ) => { | ||
| if (exhausted) return; |
There was a problem hiding this comment.
Resolve finite queued sources after alias-budget exhaustion
The new direct-module cases miss a finite queued wrapper: in the same growing-r loop, (flag ? (0, module) : r).require = replacement leaves the sequence pending while r exhausts the budget. When that sequence is popped, this new guard prevents it from enqueueing its final module expression, so the strict walk returns false, whereas reversing the branches returns true. This drops a possible native write from writesModuleRequire, letting commonJsLoaderAt label a subsequent require('electron') as commonjs-loader and expose concrete Electron facts despite a potentially replaced delegate. Preserve a bounded route for resolving finite pending alternatives rather than treating their native identities as absent.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed on 63a951c: (flag ? (0, module) : r) kept require("electron") as a loader, and the reversed order revoked it. 5ad934f keeps expanding finite expressions (sequences, conditionals, members, awaits, containers) after exhaustion and stops only at bindings and calls, so both orders revoke. The binding form, const m = module; (flag ? m : r), is still order-dependent; I raised it as a policy question in the PR conversation.
…nite expressions After exhaustion the limiter widens every key, so draining by normalized paths could match process.foo as mainModule. Keep each queued source's selected keys, expand finite expressions such as sequences and conditionals, and stop only at bindings and calls.
|
One design question I could not settle from the code; the PR is reviewable as is. When a strict The remaining gap is a module reached through a binding, when the exhausted alias is explored first: const m = module;
(flag ? m : r).require = replacement; // r is the loop-aliased walk
Options as I see them:
Which would you prefer? I'm happy to rework this toward 2, 3 or 4, or to close it if the current trade-off is intended. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5ad934f181
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
… strict walks An exhausted strict walk skipped every binding and call, so (flag ? m : r).require with const m = module lost the module branch when r was explored first. Drain the queue breadth first after exhaustion and follow bindings and calls under a second alias selection budget, so a growing alias cannot starve a sibling.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6103e26360
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…tion After the alias budget is exhausted, paths are no longer normalized, so a cycle through containers or getters can keep growing its selected path without crossing a binding or call. Count each new state against the drain budget instead of only binding and call follow-ups.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 078a19a49c
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // expansion beyond the shared selector budget. | ||
| if ( | ||
| if (exhausted) { | ||
| if (++drained > SEMANTIC_ALIAS_SELECTION_LIMIT) break; |
There was a problem hiding this comment.
Preserve unresolved module sources at the final drain cutoff
With the growing r from exhaustedWalkWrite, use (flag ? [0, …, 0, module][key] : r) with 520 explicit zero elements. The new breadth-first drain queues module behind those finite elements, exhausts this second budget, and falls through to false while that native identity is still pending; reversing the branches returns true. Consequently, writesModuleRequire misses the possible native .require replacement and commonJsLoaderAt classifies the following require('electron') as a known loader, enabling unsupported Electron facts. Preserve an unresolved outcome, or inspect queued terminal identities, when this final cap is hit instead of treating the unfinished search as no module source.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
|
@mvanhorn Thanks for laying out the tradeoff. We chose the conservative behavior closest to option 2, but only after the bounded follow-up walk is exhausted: an unfinished receiver search is recorded as incomplete, so a potentially affected loader becomes unknown. It does not assert that the receiver is definitely In 04b6b97, the search distinguishes a possible source, a completed negative result, and an incomplete search. It still examines queued sources and skips primitive leaves that cannot contribute a module source. The write index preserves the incomplete result and applies the existing effect-timing check. Both branch orders for Validation: |
| const exhaustedWalkWrite = (receiver: string): string => | ||
| `const m=module,g=()=>module;function f(n,e,flag){let r=n,i=0;for(;i<e.length;){let k=e[i];Object.prototype.hasOwnProperty.call(r,k)||Object.defineProperty(r,k,{value:{_errors:[]}});let s=r[k];r=s,i++}${receiver}.require=replacement;return r}let h=require("electron");new h.BrowserWindow({});`; |
There was a problem hiding this comment.
Helper masks broken write checks
exhaustedWalkWrite includes a loop-aliased Object.defineProperty(r,k,...) write that already makes the loader unknown, as the test at line 198 shows. The later tests therefore pass even if the added receiver assignment, Object.defineProperty, or Object.assign is never recorded.
Remove the helper's independent write and add a control without the tested write. That will let these tests catch a broken cutoff fix.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptStaticAnalysisAssignedRequire.test.ts
Line: 217-218
Comment:
**Helper masks broken write checks**
`exhaustedWalkWrite` includes a loop-aliased `Object.defineProperty(r,k,...)` write that already makes the loader unknown, as the test at line 198 shows. The later tests therefore pass even if the added receiver assignment, `Object.defineProperty`, or `Object.assign` is never recorded.
Remove the helper's independent write and add a control without the tested write. That will let these tests catch a broken cutoff fix.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Summary
Fixes #8201.
analyze_javascript_applicationreports 0 BrowserWindows and 0 IPC operations on Electron main bundles that also contain a loop-aliasedObject.definePropertywalk, which zod's error formatter has.A strict "is this the CommonJS module object?" check treats a budget-exhausted alias walk as a proven
moduleidentity.writesModuleRequirethen records an unrelated local object'sdefinePropertyas a possiblemodule.requirewrite, revokes the hostrequire, and theelectronbinding stops resolving.After this change, a strict check that runs out of budget answers "not proven", so the Electron facts are recovered, and the
alias-selectionsresource limit is still reported.Problem and expected behavior
Smallest trigger, from the reproduction in the issue thread:
Violated invariant:
hasCommonJsModuleSource(..., includeUnknown = false, ...)should returntrueonly for a retained module identity. Both budget exits (selections.limitedand theadditionalStates > SEMANTIC_ALIAS_SELECTION_LIMITbranch) returnedtruewhateverincludeUnknownwas. Running out of budget was treated as proof.Expected: the window and the
x:ymain handler are reported, and the budget exhaustion stays visible as a resource limit.Change and scope
Permissive callers (
includeUnknown = true, the default forisCommonJsModuleObjectandsemanticModuleRequireCallAt) still returntrueat either budget exit and are unchanged.A strict check that reaches a budget exit no longer returns. It stops following bindings and calls, keeps expanding finite expressions (sequences, conditionals, members, awaits, containers), and examines each queued source by its own selected keys rather than the limiter's widened ones. It returns
falseonly if none of them is a retained module identity.Review found the two earlier versions of this rule order-dependent: ending the walk outright missed
(flag ? module : r), and a drain without finite expansion missed(flag ? (0, module) : r). Strict callers affected:writesModuleRequire. This is the reported failure: an exhausted walk over an unrelated local object no longer revokes the host delegate.semanticModuleRequireCallAt(node, bindings, false)injavascriptStaticAnalysisCalls.ts, and the interopisCommonJsRequireDelegate(..., false, ...)branch. Under exhaustion these no longer treat an unproven callee as a module-require delegate. That matches the contract theincludeUnknown = falseparameter already states. I did not add separate tests for these two sites.Not included: the per-site budgets are unchanged. Also unchanged: #7253's
canonicalWebpackInteropBindingssite (same family, different site) is untouched. Contribution scope: an ordinary fix within existing boundaries; no maintainer scope decision is required.Open policy question: a strict walk that exhausts the budget cannot be both precise and sound. This version still misses a module reached through a binding beside the exhausted alias, for example
const m = module; (flag ? m : r).require = replacement, whenris explored first. Base behavior (revoke on exhaustion) is sound but suppresses Electron facts whenever an unrelated walk such as zod's exhausts the budget. See the PR conversation for the options.Contract and boundary impact
hasCommonJsModuleSourceinsrc/domain/javascript/javascriptSemanticRequireOrigin.ts(semantic require-origin analysis). Consumers:writesModuleRequire, the strict require-call recognizer injavascriptStaticAnalysisCalls.ts, and the interop delegate branch ofsemanticModuleRequireCallAt.semantic_resource_limitsstill listsalias-selections.Expected effects:
Evidence and regression coverage
Tests added or updated, in
src/domain/javascript/javascriptStaticAnalysisAssignedRequire.test.ts:revokes the host delegate through %s after alias selections are exhausted:module,(0,module)andprocess.mainModulebeside the exhausted alias revoke the loader in both branch orders.keeps the host delegate through %s after alias selections are exhausted:process.foobeside the exhausted alias does not revoke, in both orders.keeps electron facts when a loop-aliased defineProperty exhausts alias selections: the reduction above. It asserts 1 BrowserWindow, thex:ymain handler, theelectronrequire reference, andalias-selectionsinanalysis_coverage.examination.semantic_resource_limits. It fails on08637b0without the source change (Tests 1 failed | 48 passed).keeps electron facts for the same path walk without defineProperty: a control; passes before and after.revokes the host delegate after a dynamic defineProperty on module: a control showing a real, proven module receiver with a dynamic key still revokes (specifier: null).Base reproduction (executed). I built an Electron main entry that imports real
[email protected]and callsz.formatError, bundled it with[email protected](--format cjs --platform node --external electron --minify; 69,567 bytes), and ranrea analyze-javascript-application <app> --source-path dist/main.jsfrom a source build:08637b0browser_windowsexplicit_web_preferencesipc.operations/main_handlers/literal_channelselectron_semanticsrecoveredsemantic_resource_limitsalias-selectionsalias-selectionsUser-visible CLI/MCP output: the graph
summarycounts above.Remaining proof gaps: the binding case in the open policy question above is not covered. I did not run the Signal Desktop 8.33.0 or Wonder 0.2.220 bundles from the issue, and I did not check whether Signal reaches this exact site. The two other strict callers have no dedicated regression tests.
For evidence-bearing changes:
Validation performed
Alias cutoff: the module-source search now distinguishes a possible source, a completed negative result, and an incomplete search. Possible or incomplete receiver writes remain indexed with their source and use existing effect timing; they make a potentially affected CommonJS loader unknown. Primitive leaves the walker would discard are pruned before consuming the remaining search allowance. Direct assignment,
Object.definePropertyandObject.assignregressions fail on the previous head and pass here, including both branch orders and identifier alternatives.npm run check:fastpassed. The focused require/Electron source suites passed (457 tests, plus two addedObjectcases subsequently passed in the 67-test assigned-require suite).npm run test:focused -- tests/acceptance/applications/javascriptModuleResolutionSemantics.test.ts tests/boundary/filesystem/javascript-applications/electronApplicationAnalysis.test.ts tests/boundary/filesystem/javascriptArtifactSemanticUnknowns.test.tspassed (16 tests; CLI and stdio MCP included).Precision limitation: when the bounded walk cannot rule out a write, including the Zod-like computed-property loop, the loader remains unknown and previously reported Electron facts are no longer inferred. Further precision requires proving that an unresolved receiver cannot alias the module; that refinement is not implemented.
npx vitest run src/domain/javascript/javascriptStaticAnalysisAssignedRequire.test.tson base without the source change: 1 failed, 48 passed (the new regression).npx vitest run src/domain/javascript/javascriptStaticAnalysisAssignedRequire.test.ts src/domain/javascript/electronBundledRequireIdentity.test.ts src/domain/javascript/javascriptSemanticRequireCaptures.test.ts: 3 files, 181 tests passed before the review follow-up; the assigned-require file now has 57 passing tests (includes "keeps a limited loader-alias walk unknown").npx vitest run src/domain/javascript: 174 files, 5051 tests passed.npm run check:fast(typecheck, lint): passed.npm run verify:test-discovery: "Discovered all 3192 test files exactly once."npm run check: typecheck and lint passed (0 errors).metadata:checkfailed under local Node 26.5.0 withERR_INVALID_ARG_VALUE ... options.mode ... 'transform'; it fails the same way on unmodified base, below the repo'senginesfloor. Under Node 24.22.1,npm ciandnpm run build:cached(which includesmetadata:check) passed.rea analyze-javascript-applicationbefore/after on the zod bundle: the table above, re-run on the final commit with the same result.npx oxfmt --checkon both changed files: correct format.Compatibility, safety, and release
Author readiness
Human owner: @mvanhorn
Before merge
type(scope): outcome.AI was used for assistance.