Repository navigation
fix(javascript): resolve module-relative Worker URL references - #2104
Conversation
Codex Review SummaryThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4943b6aaa4
ℹ️ 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".
| !specifier.startsWith("?") && | ||
| !specifier.startsWith("#") |
There was a problem hiding this comment.
Validate only the URL pathname
When the URL literal puts encoded path syntax only in its query or fragment—for example new URL("./worker.js?redirect=%2Ffoo", import.meta.url)—this returns the full value, and resolveArtifactPathByContext runs rejectDeclaration on it before contextualCandidate removes ?/#. The URL's pathname is still ./worker.js, but %2F (likewise %2E, %5C, a backslash, or NUL) causes the reference to be rejected, so an inventoried worker gets no maps_to edge. Strip or parse the URL suffix before path admission while preserving the declared specifier.
AGENTS.md reference: AGENTS.md:L25-L25
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5b97315a04
ℹ️ 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".
| return pathname.length > 0 && | ||
| stripQueryAndFragment(htmlUrlText(specifier)) === pathname | ||
| ? specifier |
There was a problem hiding this comment.
Preserve directory-form URL semantics
When the literal path ends in a dot segment, for example new URL("./worker.js/.", import.meta.url) in dist/app.mjs, this condition promotes it to a static specifier. URL resolution preserves the directory form as /dist/worker.js/, but relativeCandidate later uses posix.join, which collapses /. to dist/worker.js; if that file is inventoried, the graph emits a maps_to edge even though the Worker requests a distinct directory-form URL. Parse and carry the URL pathname's trailing-directory state, or leave these references unresolved, rather than treating the normalized filesystem path as an exact URL match.
AGENTS.md reference: AGENTS.md:L25-L25
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6301950464
ℹ️ 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".
| const node = argumentNode(argument); | ||
| if ( | ||
| !t.isNewExpression(node) || |
There was a problem hiding this comment.
Unwrap transparent expressions before matching Worker URLs
When TypeScript wraps the URL value in a runtime-transparent assertion, for example new Worker(new URL("./worker.js", import.meta.url) as URL), argumentNode returns a TSAsExpression, so t.isNewExpression(node) fails and the valid static URL remains an opaque expression with no maps_to edge. readExactJavaScriptLiteral already handles these wrappers through unwrapJavaScriptExpression; unwrap the Worker argument before applying this shape check as well.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c534adaeaf
ℹ️ 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".
| addReference(context, { | ||
| node, | ||
| kind: "worker", | ||
| specifier: first ?? workerUrlSpecifier(node.arguments[0], bindings), |
There was a problem hiding this comment.
Check the outer Worker binding before resolving its URL
When an ESM file declares a different lexical Worker (for example, class Worker {}; new Worker(new URL("./worker.js", import.meta.url))), the name test still enters this block and only the inner URL is checked against bindings. This change therefore upgrades the previously opaque call to a static specifier and emits a maps_to edge to any matching file even though no worker is loaded; consult the outer callee's binding (while allowing proven worker implementations such as worker_threads.Worker) before promoting the nested URL.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0c2803e1c7
ℹ️ 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".
| ]); | ||
| return exactUrlPathCandidate( | ||
| decoded, | ||
| relativeCandidate(input.sourcePath, decoded), |
There was a problem hiding this comment.
Leave drive-letter URL forms unresolved
When the analyzed module runs from a file URL (the Node/Electron case), WHATWG resolves new URL("c|/worker.js", import.meta.url) to file:///c:/worker.js, but this POSIX join produces dist/c|/worker.js for dist/app.mjs. If an artifact contains that legal POSIX path, the new Worker promotion emits a false maps_to edge to a file the runtime never requests; because the base scheme is not modeled and HTTP treats this spelling differently, leave this drive-letter form unresolved rather than joining it.
AGENTS.md reference: AGENTS.md:L25-L25
Useful? React with 👍 / 👎.
Use WHATWG file URL parsing before pathname decoding to detect drive-letter forms whose resource identity depends on the unmodeled source URL scheme. Preserve encoded and ordinary relative pipe paths, and cover false matches through the compiled CLI and resolver boundary tests.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6862b0c0d5
ℹ️ 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".
| return pathname.length > 0 && | ||
| stripQueryAndFragment(htmlUrlText(specifier)) === pathname | ||
| ? specifier |
There was a problem hiding this comment.
Keep absolute file-based Worker URLs unresolved
The final code now rejects drive-letter file URLs, but for a node:worker_threads call such as new Worker(new URL("/worker.js", import.meta.url)), this return still promotes the leading-slash specifier and relativeCandidate later maps it to inventory path worker.js. In Node the base is a file URL, so the runtime target is filesystem-root /worker.js (or the current drive root on Windows), not the selected application's worker.js; a same-named file therefore gains a false maps_to edge. Carry the file-URL base semantics or leave this absolute form unresolved.
AGENTS.md reference: AGENTS.md:L25-L25
Useful? React with 👍 / 👎.
| !isUnshadowedGlobal( | ||
| unwrapJavaScriptExpression(node.callee).node, | ||
| bindings, | ||
| "URL", | ||
| ) || |
There was a problem hiding this comment.
Treat locally overwritten global URL as unknown
When source code replaces the global constructor before the call, for example const RealURL = URL; globalThis.URL = class { constructor() { return new RealURL("./other.js", import.meta.url); } };, this lexical-only check still treats the subsequent bare URL as the built-in. A proven worker_threads.Worker call is then linked to the literal worker.js even though runtime loads other.js; source-local writes to the global constructor should make the identity unknown.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
| addReference(context, { | ||
| node, | ||
| kind: "worker", | ||
| specifier: first ?? workerUrlSpecifier(node, bindings), |
There was a problem hiding this comment.
Consult bindings before filtering Worker callee spellings
When the immutable Node constructor is imported under an alias, such as import { Worker as ThreadWorker } from "node:worker_threads"; new ThreadWorker(new URL("./worker.js", import.meta.url)), calleeName is ThreadWorker, so the surrounding spelling gate never invokes this binding-aware fallback. The same happens for a TypeScript-wrapped outer callee even though isWorkerConstructor can unwrap it, leaving no worker finding or maps_to edge; run constructor identity before restricting the callee spelling.
AGENTS.md reference: AGENTS.md:L17-L17
Useful? React with 👍 / 👎.
Recognize known Worker bindings before filtering callee spellings so ESM aliases and transparent constructor wrappers reach URL analysis. Keep root-relative module URLs unknown without a modeled runtime base root. Index direct source-local global writes with the shared mutation collector before promoting URL and browser Worker constructors. Preserve lexical shadowing and unrelated property identities, and exercise all three review regressions through the compiled CLI.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bb76ee4dd3
ℹ️ 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".
| if ( | ||
| !t.isIdentifier(callee, { name: "URL" }) || | ||
| !isUnmodifiedGlobalReference(callee, bindings, "URL") || | ||
| !isImportMetaUrl(argumentNode(node.arguments[1])) |
There was a problem hiding this comment.
Treat writes to import.meta.url as unknown
When a Node ESM source rewrites the writable import.meta.url before this call—for example, import.meta.url = "file:///tmp/base.mjs"; new Worker(new URL("./worker.js", import.meta.url)) with an imported worker_threads.Worker—this syntax-only check still succeeds. Runtime resolves the URL to /tmp/worker.js, but the graph resolves it relative to the analyzed artifact and can emit a false maps_to edge to an inventoried sibling worker.js; track assignments/redefinitions/deletions of this meta property or retain the Worker argument as an expression when its base identity is mutable.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
Track source-local import.meta writes alongside ambient global writes so Worker URL expressions keep an unknown base after a possible URL mutation. Tag the identity roots independently and cover direct mutation and unrelated property cases through the compiled CLI.
|
finally |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8d30ba4c0a
ℹ️ 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".
| if (kind === "member" && globalObjectName(root, state) !== undefined) | ||
| return ["global"]; |
There was a problem hiding this comment.
Canonicalize nested global aliases before trusting URL
When a Node module mutates URL through the self-alias globalThis.global, for example globalThis.global.URL = class {}; before an imported worker_threads.Worker call, this branch retains ['global', 'global', 'URL']. isUnmodifiedGlobalReference checks only ['global', 'URL'], so the nested new URL(...) is promoted and an inventoried sibling receives maps_to, while runtime passes a plain object to Worker and throws instead of loading it. The fresh evidence after the earlier direct-global fix is this new index's noncanonical path; collapse known global-object aliases or keep the identity unknown.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
| return pathname.length > 0 && | ||
| !pathname.startsWith("/") && | ||
| stripQueryAndFragment(htmlUrlText(specifier)) === pathname | ||
| ? specifier |
There was a problem hiding this comment.
Keep malformed-percent Node Worker URLs unresolved
When the proven constructor is imported from node:worker_threads and the literal path contains a stray percent, such as new Worker(new URL("./worker%.js", import.meta.url)), this promotes the argument; percentDecodeUrlPath leaves that malformed escape literal, so an inventoried worker%.js receives maps_to. Node converts this file URL to a path and throws URIError: URI malformed, so that file cannot be loaded; reject malformed path escapes or carry the known Node/file semantics before promotion.
AGENTS.md reference: AGENTS.md:L25-L25
Useful? React with 👍 / 👎.
Resolve ambient object identities before appending written properties, and retain possible source-local aliases across rebinding. Reuse intrinsic invocation handling for aliased and bound mutators, array spreads, and transparent TypeScript wrappers while preserving Electron write semantics. Keep malformed-percent nested Worker URL pathnames unknown because the base scheme is unavailable and Node rejects these file URLs. Preserve tolerant HTML URL handling, valid escapes, and query/fragment evidence. Cover the new cases and unrelated writes through the compiled CLI with existing-file decoys. All 591 targeted tests and npm run check pass.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5d84b26d7e
ℹ️ 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".
| if (possibleWrites && t.isConditionalExpression(root)) { | ||
| continueWith(root.consequent); | ||
| continueWith(root.alternate); |
There was a problem hiding this comment.
Bound repeated ambient alias expansion
When analyzed input contains a chain such as const aN = flag ? aPrev : aPrev followed by aN.URL = replacement, both branches are enqueued with independent visited sets and each re-expands the same preceding binding, so N aliases produce 2^N pending states before identical terminal paths are coalesced. This loop has no yield or resource budget and runs before static traversal, so a few dozen harmless-looking declarations can hang CLI/MCP analysis; deduplicate resolver states or cap expansion while preserving an unknown result.
AGENTS.md reference: AGENTS.md:L46-L46
Useful? React with 👍 / 👎.
| node, | ||
| kind: "worker", | ||
| specifier: | ||
| first ?? |
There was a problem hiding this comment.
Keep Node worker strings in filesystem context
For a newly recognized alias such as import { Worker as W } from "node:worker_threads"; new W("/worker.js"), first wins here and resolveReference subsequently treats the string as an artifact-root URL, potentially emitting maps_to for the selected application's worker.js; Node instead interprets this as filesystem-root /worker.js (and resolves relative strings against the process cwd). The fresh evidence beyond the earlier nested-URL case is that binding-aware alias recognition now reaches this literal fast path and bypasses workerUrlSpecifier entirely, so distinguish Node constructors and leave string paths unresolved without filesystem/cwd context.
AGENTS.md reference: AGENTS.md:L25-L25
Useful? React with 👍 / 👎.
| if (!t.isNewExpression(node)) return undefined; | ||
| const callee = unwrapJavaScriptExpression(node.callee).node; | ||
| if ( | ||
| !t.isIdentifier(callee, { name: "URL" }) || |
There was a problem hiding this comment.
Admit qualified global URL constructors
When a proven Worker uses new globalThis.URL("./worker.js", import.meta.url) (likewise window.URL or self.URL), unwrapping yields a member expression and this guard rejects it before isUnmodifiedGlobalReference can apply the ambient-write proof it already supports for direct global properties. These forms invoke the same canonical constructor, but the reference remains opaque with no maps_to; let the identity helper validate qualified global URL constructors instead of requiring a bare identifier.
AGENTS.md reference: AGENTS.md:L17-L17
Useful? React with 👍 / 👎.
Join ambient identity projections instead of enumerating alias histories. Memoize repeated value and provenance queries while preserving capture, depth, and cycle-dependent uncertainty. Keep Node Worker string arguments unresolved without filesystem or cwd context, and admit qualified global URL constructors through identity checks. Validate three 40-level alias branch shapes through the compiled CLI, 925 source tests, 25 CLI/boundary tests, and the full npm run check gate.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Preserve the author history and both binding-aware producer consumers: current-main bundler registration/esbuild inspection and Worker URL call inspection. Resolve only their shared call-site conflict.\n\nValidation: 398 related source tests, one additional scratch producer witness, six compiled CLI journeys with process-table access, check:fast and check. The sandboxed CLI attempt was blocked by spawn EPERM during process ownership inspection.
Retain CTS import-equals loader evidence and binding-aware Worker scans. Share active-stack and expression-depth dependence across value and provenance evaluation; retain live values only in the effects-aware state and provenance only for one query. Propagate memo dependencies through cache hits and invalidate all state-owned values when mutation facts change. Source validation: 712 focused tests passed. check:fast and compiled Worker CLI journeys are blocked by unchanged upstream contractToolHandler.ts:69 (missing fourth argument). No hosted publication performed.
Pass the exact named contract returnsTargetContent flag through the shared partial-Evidence error delivery path introduced by the shortlist integration. Exercise successful and failed recording through in-memory MCP for marked and unmarked contracts, preserving source payload and original failures. Observe both shared-handler emission and wire delivery so the SDK error-marker fallback cannot hide omissions. Suppressing the flag fails exactly the two marked cases. Validation: check:fast, check, 736 semantic tests, 29 MCP transport/error tests and six compiled static Worker CLI journeys pass. No live target/provider execution or hosted publication.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
baron
left a comment
There was a problem hiding this comment.
Source verdict: APPROVE for 814b4bf3e8d50cea3167703694886197f3a629d8.
The integrated change preserves binding-aware Worker/import.meta.url, CTS import-equals, and bundler scans at their shared producer boundary. Caller-dependent/cyclic/depth-limited values cannot leak from analysis-state memoization. Query-local provenance propagates exact dependency proofs and rejects active-ancestor reuse. The unpublished integration's flattened transitive Sets were replaced before publishing a candidate head with immutable shared proofs; the original contributor is not being blamed for that integration defect. Obsolete duplicate value memo/cycle-epoch representation is removed.
A discriminating 32/64 reconvergent witness fails with the old owner and passes with the shared-proof representation. Independent exact-source verification confirms the prior blocker is resolved, including immutable union/membership and handler provenance. Proof construction/retention scaling is measured, not whole-analysis speed, token cost or process-family peak memory; those remain unmeasured.
Pinned validation: 738 semantic tests plus 39 static CLI/in-memory MCP tests (777 distinct passes), build prerequisites, check:fast, check and 998-file discovery. The four named-contract/retained-or-failed recording cases inspect handler emission AND wire framing; false-flag mutation fails the two marked cases. The production retained-partial provenance correction had already landed on main and is inherited, not duplicated. Static analysis never executed analyzed targets; simulated/in-memory producers do not establish real-provider behavior. Earlier sandbox-limited runtime residue remains preserved with ownership/cleanup settlement UNKNOWN; the later bounded journeys passed without bypassing ownership.
Fresh published-head hosted CI is green: Static checks, Test (coverage + timing), and CI required succeeded in run https://github.com/morluto/rea/actions/runs/38314617241. Optional skips are not represented as provider execution. Current-main integration is rechecked immediately before gated merge; no admin bypass or history rewrite.
Summary
Recover the common
new Worker(new URL("./worker.js", import.meta.url), { type: "module" })pattern as a Worker-to-file relationship. Previously the Worker was retained as an unknown expression with nomaps_toedge.Found during a source audit; no existing issue was identified for this pattern.
Problem and expected behavior
A literal URL relative to the current module gives enough static evidence to locate an inventoried Worker script. It must use exact URL resource lookup, including one percent-decoding pass and query/fragment removal before pathname admission, without selecting a similarly named bundled module or applying CommonJS extension/index/package fallbacks.
Representative artifact-graph result, verified through the production source pipeline:
declared_specifiernull"./worker.js"resolved_pathnull"worker.js"maps_toChange and scope
new URLargument with a literal string or substitution-free template, an unshadowed globalURL, and animport.meta.urlbase. Reuse the canonical transparent-expression unwrapping for TypeScript assertions, non-null expressions, andsatisfies, including wrapped URL callees and module bases. Keep lexical shadow checks and the original Worker evidence node.worker_threads/node:worker_threads. The lexical owner distinguishes runtime ESM imports from type-only and import-equals syntax. Keep local classes, parameters, unrelated imports, reassigned bindings, default imports, and CommonJS objects unresolved; mutable module objects do not establish a Worker identity./,/.,/..) before filesystem normalization, and leave repeated URL separators unresolved instead of collapsing distinct URL identities. Reuse the existing HTML directory predicate and confinement handling.URLare not guessed.Contract and boundary impact
Evidence and regression coverage
Added three public compiled CLI journeys covering 25 resolved and 34 unresolved cases: relative/parent/template URLs, encoding and query/fragment handling, double-decoding decoy, ordinary string Worker, bundled-module collision, dynamic/shadowed/custom URL cases, missing exact files with extension/index/package decoys, external URLs, and unsupported URL forms.
The ordinary Worker URL bug was reproduced before the change through the production analyzer and graph builder.
Added resolver regressions for both query and fragment data (
%2F,%2E,%5C,%00,%FF, raw backslash, and NUL), while retaining pathname rejection. Both suffix tests failed on4943b6aand pass after the fix. Six directory/empty-segment regression cases failed on5b97315and now pass; interior dot segments, dotfiles, root confinement, and existing HTML behavior remain covered.Added eight TypeScript wrapper scenarios and three wrapped shadow/dynamic negative scenarios. The
as URLcase reproduced a missing relationship on6301950; all pass through the production source pipeline after the fix.Added 21 constructor-identity cases (7 resolved, 14 unknown), including browser namespaces, both Node built-in module spellings, local classes/parameters, custom imports, type-only imports, reassignment, mutable namespaces, and calls without
new. The local-class case fails againstc534adaby creating a false file edge and passes after the fix.Independently executed all 59 new fixture expectations through real file inventory, production source analysis, and graph construction. All passed, including the competing bundled-module assertion.
Remaining proof gap: compiled CLI and native-worker boundary tests are blocked locally before worker startup by the installed macOS Command Line Tools
SwiftBridgingduplicate module definition. No process ownership checks were bypassed.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
Pinned Node 24.18.0 / npm 11.16.0:
npm run check— passed: typecheck, lint (warnings, no errors), formatting, knip, metadata, module boundaries, and architecture guards.npm run verify:test-discovery— all 916 test files discovered exactly once.git diff --cached --check— passed before commit.npm run test:focused -- tests/acceptance/applications/javascriptWorkerUrlCli.test.ts— local execution blocked by the Swift toolchain startup failure. Both existing Worker CLI journeys, including TypeScript wrapper, suffix, and directory-form/empty-segment cases, passed in Linux CI onc534ada. The new constructor-identity journey awaits CI on the latest head.The previous PR CI run failed in MCP prompt completion and Darwin package prompt smoke tests. The same failures occur in main's CI at
c22111e, following the independent prompt-completion lifecycle change in07b36c1. Worker acceptance passed; no unrelated MCP change is included here.Compatibility, safety, and release
Review checklist