[PR #3849] [CLOSED] fix(javascript): stop classifying replaced globals as built-in effects #5945

Closed
opened 2026-10-31 01:10:38 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/3849
Author: @kaoru0822-kitauji
Created: 10/15/2026
Status: ❌ Closed

Base: main ← Head: fix/3367-replaced-global-effects


📝 Commits (1)

  • 3be4511 fix(javascript): stop classifying replaced globals as built-in effects

📊 Changes

4 files changed (+221 additions, -63 deletions)

View changed files

📝 src/domain/javascript/javascriptSemanticAmbientWrites.ts (+89 -18)
➕ src/domain/javascript/javascriptSemanticAnalysis.replaced_globals.test.ts (+57 -0)
📝 src/domain/javascript/javascriptSemanticAsyncEffects.ts (+38 -18)
📝 src/domain/javascript/javascriptSemanticDataEffects.ts (+37 -27)

📄 Description

Summary

Fixes #3367. Semantic timer, request, coercion and JSON.parse effects recognized unbound globals without consulting visible source-local writes. As a result, setTimeout = f, self.fetch = f or JSON.parse = f still produced complete Node timer, fetch and JSON parse operations.

Problem and expected behavior

Smallest trigger: setTimeout = f; setTimeout(work, 1) reports a complete setTimeout schedule. The violated invariant is that a built-in effect requires the callee to still denote the built-in. A visible exact overwrite breaks that identity. A write under an unknown key, such as globalThis[k] = v, may or may not break it, so the result must stay uncertain rather than becoming absent or complete.

Change and scope

  • Owner of the classification: javascriptSemanticAmbientWrites.ts, which owns ambient write facts, now classifies a global reference as one of:
    • not global;
    • unmodified;
    • possibly replaced: the coverage index matches, but only through an unknown-key or widened write;
    • replaced: an exact, all-literal written path equals the reference or member path.
  • Index: exact written paths are indexed once per ambient write list. The index is keyed on the list identity and its length.
  • Consumers: the timer, fetch/WebSocket, coercion and JSON.parse consumers use semanticBuiltinGlobalResolution:
    • replaced → no built-in effect;
    • possibly replaced → the effect is kept with partial resolution;
    • unmodified → unchanged.
  • Removed: isUnmodifiedGlobalMember is superseded and removed. isUnmodifiedGlobalReference keeps its exact prior meaning (unmodified only) for its URL, Worker and undefined callers.
  • Not included: flow-sensitive ordering. A call before the overwrite is classified the same way as one after it, matching how the existing ambient-write coverage already behaves. Write paths the resolver widens, such as Object.defineProperties(globalThis, {...}), remain "possibly replaced". Making them precise is resolver work outside this fix.

Contract and boundary impact

  • Semantic owner and earliest changed stage: JavaScript semantic analysis, ambient global identity (javascriptSemanticAmbientWrites.ts).
  • Contribution scope fit and linked maintainer decision: an ordinary fix within existing boundaries, so not applicable.
  • CLI and MCP/tool-catalog contract: no schema change. resolution values stay within the existing complete | partial | unresolved enums.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: IR operations behind a definite overwrite are no longer emitted. Operations behind an uncertain write become partial. Function fingerprints whose effect components include removed requests change accordingly.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • Generated metadata, package, or installation impact: none.

Expected effects:

  • Read existing files or captured data.

Evidence and regression coverage

  • Tests added: src/domain/javascript/javascriptSemanticAnalysis.replaced_globals.test.ts covers the replaced, possibly replaced (globalThis[Symbol.for(...)] = …) and unmodified cases. The replaced and possibly replaced cases fail on the base revision, which reports all three effects as complete.
  • Base reproduction (executed; base = main build at f09f454f4 vs. this branch, with setTimeout(work, 1); fetch(...); JSON.parse("1") after each prefix):
Prefix main this branch
none setTimeout:complete, fetch:complete, JSON.parse:complete unchanged
setTimeout = f; fetch = f; JSON.parse = f all three complete parse:partial only (generic parse)
globalThis.setTimeout = f all three complete fetch:complete, JSON.parse:complete
delete globalThis.setTimeout all three complete fetch:complete, JSON.parse:complete
globalThis[k] = v all three complete all three partial
  • Real-app semantic IR comparison (executed): full analyzeParsedJavaScriptSemantics output for every JS file, main build vs. this change.
Corpus Files Identical Differing Semantic ms (main → branch)
Discord 1 1 0 35 → 33
Notion 96 96 0 8,347 → 8,206
Signal 572 569 3 22,251 → 21,881
Claude 421 418 3 38,379 → 37,574
Tabby 2,183 2,183 0 11,154 → 10,854
VS Code out/ 27 25 2 19,194 → 19,155

In the 8 differing files, every difference was classified per operation:

  • 1,152 changed from complete to partial: 859 coercion/JSON.parse boundary operations and 293 timer operations. Each sits behind an unknown-key global write: globalThis[e] = …, a Symbol-keyed registry write re[k] ??= new Map(), or Object.defineProperties(globalThis, …).
  • 11 fetch requests and their 13 json/text response consumers were removed, all in VS Code. They sit behind genuine overwrites: globalThis.fetch = async function… in extensionHostProcess.js and self.fetch = function… in extensionHostWorkerMain.js.
  • 10 function fingerprints changed in the same VS Code file. Their effect components follow the removed requests.
  • No other IR field changed.
  • Output size: removed operations shrink the IR slightly. Resolution changes are equal-length string swaps, apart from complete → partial being 1 byte shorter.
  • Remaining proof gaps: no CLI/MCP workflow output was captured separately. The IR comparison exercises the producer that both adapters consume. Timing figures are single warm runs on one machine.

For evidence-bearing changes:

  • 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/javascriptSemanticAnalysis.replaced_globals.test.ts: 3 passed.
  • 161 JavaScript/domain test files via npm run test:local: 2,985 passed (after rebasing onto 788964d52).
  • npm run check:fast: typecheck and lint pass.
  • The semantic IR comparison above on Discord, Notion, Signal, Claude, Tabby and VS Code bundles.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Consumers already handle partial resolutions.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable (static JavaScript analysis).
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no target interaction. Private app bundles are referenced only by name and path.

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.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/3849 **Author:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Created:** 10/15/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/3367-replaced-global-effects` --- ### 📝 Commits (1) - [`3be4511`](https://github.com/morluto/rea/commit/3be45116ab262dd2edde504975ef4fb48107f2ef) fix(javascript): stop classifying replaced globals as built-in effects ### 📊 Changes **4 files changed** (+221 additions, -63 deletions) <details> <summary>View changed files</summary> 📝 `src/domain/javascript/javascriptSemanticAmbientWrites.ts` (+89 -18) ➕ `src/domain/javascript/javascriptSemanticAnalysis.replaced_globals.test.ts` (+57 -0) 📝 `src/domain/javascript/javascriptSemanticAsyncEffects.ts` (+38 -18) 📝 `src/domain/javascript/javascriptSemanticDataEffects.ts` (+37 -27) </details> ### 📄 Description ## Summary Fixes #3367. Semantic timer, request, coercion and `JSON.parse` effects recognized unbound globals without consulting visible source-local writes. As a result, `setTimeout = f`, `self.fetch = f` or `JSON.parse = f` still produced complete Node timer, fetch and JSON parse operations. ## Problem and expected behavior Smallest trigger: `setTimeout = f; setTimeout(work, 1)` reports a complete `setTimeout` schedule. The violated invariant is that a built-in effect requires the callee to still denote the built-in. A visible exact overwrite breaks that identity. A write under an unknown key, such as `globalThis[k] = v`, may or may not break it, so the result must stay uncertain rather than becoming absent or complete. ## Change and scope - **Owner of the classification:** `javascriptSemanticAmbientWrites.ts`, which owns ambient write facts, now classifies a global reference as one of: - not global; - unmodified; - possibly replaced: the coverage index matches, but only through an unknown-key or widened write; - replaced: an exact, all-literal written path equals the reference or member path. - **Index:** exact written paths are indexed once per ambient write list. The index is keyed on the list identity and its length. - **Consumers:** the timer, fetch/WebSocket, coercion and `JSON.parse` consumers use `semanticBuiltinGlobalResolution`: - replaced → no built-in effect; - possibly replaced → the effect is kept with `partial` resolution; - unmodified → unchanged. - **Removed:** `isUnmodifiedGlobalMember` is superseded and removed. `isUnmodifiedGlobalReference` keeps its exact prior meaning (`unmodified` only) for its URL, Worker and `undefined` callers. - **Not included:** flow-sensitive ordering. A call before the overwrite is classified the same way as one after it, matching how the existing ambient-write coverage already behaves. Write paths the resolver widens, such as `Object.defineProperties(globalThis, {...})`, remain "possibly replaced". Making them precise is resolver work outside this fix. ## Contract and boundary impact - Semantic owner and earliest changed stage: JavaScript semantic analysis, ambient global identity (`javascriptSemanticAmbientWrites.ts`). - Contribution scope fit and linked maintainer decision: an ordinary fix within existing boundaries, so not applicable. - CLI and MCP/tool-catalog contract: no schema change. `resolution` values stay within the existing `complete | partial | unresolved` enums. - Provider, bridge, target-format, or platform compatibility: none. - Evidence, artifact, provenance, or reconstruction contract: IR operations behind a definite overwrite are no longer emitted. Operations behind an uncertain write become `partial`. Function fingerprints whose effect components include removed requests change accordingly. - Target selection, authority, upstream behavior, and cleanup details: not applicable. - Generated metadata, package, or installation impact: none. Expected effects: - [x] Read existing files or captured data. ## Evidence and regression coverage - Tests added: `src/domain/javascript/javascriptSemanticAnalysis.replaced_globals.test.ts` covers the replaced, possibly replaced (`globalThis[Symbol.for(...)] = …`) and unmodified cases. The replaced and possibly replaced cases fail on the base revision, which reports all three effects as complete. - Base reproduction (executed; base = main build at f09f454f4 vs. this branch, with `setTimeout(work, 1); fetch(...); JSON.parse("1")` after each prefix): | Prefix | main | this branch | |---|---|---| | none | setTimeout:complete, fetch:complete, JSON.parse:complete | unchanged | | `setTimeout = f; fetch = f; JSON.parse = f` | all three complete | `parse:partial` only (generic parse) | | `globalThis.setTimeout = f` | all three complete | fetch:complete, JSON.parse:complete | | `delete globalThis.setTimeout` | all three complete | fetch:complete, JSON.parse:complete | | `globalThis[k] = v` | all three complete | all three partial | - Real-app semantic IR comparison (executed): full `analyzeParsedJavaScriptSemantics` output for every JS file, main build vs. this change. | Corpus | Files | Identical | Differing | Semantic ms (main → branch) | |---|---:|---:|---:|---:| | Discord | 1 | 1 | 0 | 35 → 33 | | Notion | 96 | 96 | 0 | 8,347 → 8,206 | | Signal | 572 | 569 | 3 | 22,251 → 21,881 | | Claude | 421 | 418 | 3 | 38,379 → 37,574 | | Tabby | 2,183 | 2,183 | 0 | 11,154 → 10,854 | | VS Code `out/` | 27 | 25 | 2 | 19,194 → 19,155 | In the 8 differing files, every difference was classified per operation: - 1,152 changed from `complete` to `partial`: 859 coercion/`JSON.parse` boundary operations and 293 timer operations. Each sits behind an unknown-key global write: `globalThis[e] = …`, a Symbol-keyed registry write `re[k] ??= new Map()`, or `Object.defineProperties(globalThis, …)`. - 11 `fetch` requests and their 13 `json`/`text` response consumers were removed, all in VS Code. They sit behind genuine overwrites: `globalThis.fetch = async function…` in `extensionHostProcess.js` and `self.fetch = function…` in `extensionHostWorkerMain.js`. - 10 function fingerprints changed in the same VS Code file. Their effect components follow the removed requests. - No other IR field changed. - Output size: removed operations shrink the IR slightly. Resolution changes are equal-length string swaps, apart from `complete` → `partial` being 1 byte shorter. - Remaining proof gaps: no CLI/MCP workflow output was captured separately. The IR comparison exercises the producer that both adapters consume. Timing figures are single warm runs on one machine. For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npm run test:local -- src/domain/javascript/javascriptSemanticAnalysis.replaced_globals.test.ts`: 3 passed. - 161 JavaScript/domain test files via `npm run test:local`: 2,985 passed (after rebasing onto 788964d52). - `npm run check:fast`: typecheck and lint pass. - The semantic IR comparison above on Discord, Notion, Signal, Claude, Tabby and VS Code bundles. ## Compatibility, safety, and release - Breaking changes or migration steps: none. Consumers already handle `partial` resolutions. - Real Hopper/Ghidra, browser, or OS coverage: not applicable (static JavaScript analysis). - Package or release metadata impact: none. - Security, privacy, process, or containment review: no target interaction. Private app bundles are referenced only by name and path. ## Author readiness Human owner: <!-- @GitHub-handle --> - [ ] 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. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:10:38 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#5945
No description provided.