Skip to content

fix(javascript): preserve captured destructuring dependencies - #7716

Closed
SII-YDD wants to merge 7 commits into
morluto:mainfrom
SII-YDD:fix/javascript-destructuring-read-presence
Closed

SII-YDD wants to merge 7 commits into
morluto:mainfrom
SII-YDD:fix/javascript-destructuring-read-presence

Conversation

@SII-YDD

@SII-YDD SII-YDD commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #7559. Keep an already-proven JavaScript destructuring dependency traversable after a later property write. Current head 33f8d4e305d7b285ada89c5f8caa619547c4c414 integrates main 79766ca96a22ee0b6e04c3681546d492702b4ae7; the obsolete Darwin-helper type change is now upstream and no longer in this PR's diff.

Problem and expected behavior

const config = { mode: "strict" };
let selected;
({ mode: selected } = config);
config.mode = "loose";

Node captures "strict". Previously the whole-program object value widened after the write, the earlier destructures edge became candidate, and default backward provenance omitted it. Later writes must not invalidate a proven earlier read.

Change and scope

The existing read-aware value owner supplies each selected path's sourcePresence to destructuring IR. Graph projection consumes that fact, with its existing fallback for older operations. computeDirectInitializerPosition accepts direct RHS reads of = object/array pattern assignments and reuses the shared ordering/activation proof. There is no second write inventory or source-line ordering heuristic.

Presence collection uses query-owned captures; existing callers retain their state-owned cache policy. The temporary cache is shared during evaluation, then released. This addresses the effective automated P1 finding, not a maintainer priority designation. Depth/cycle/dependency proofs remain intact. Each operation retains one presence enum; source objects are still evaluated per read, so this does not claim a CPU optimization or a new asymptotic time bound.

Deferred/repeated reads, effectful defaults, custom iterators and uncertain aliases remain conservative. Aggregate uninitialized-binding unknowns remain; this is not temporal SSA recovery or a promise that the entire trace becomes unambiguous.

Verified published-head diff: 13 files, 510 insertions /10 deletions against pinned main79766ca9 (the newer unpublished c3647ad integration has11 files):

  • Eight semantic/acceptance paths, including the capture-lifetime owner and memo regression.
  • Two test-only carrier fixtures adopt test(artifacts): make same-size carrier rewrites observable #8060 / 6079b0f by @SahinurDEV; original credited commits remain ancestors. One existing iNES fixture similarly makes its two same-size fault injections observably distinct using mtime. Production freshness policies and original integrity assertions are unchanged.
  • Two current-main CI prerequisites: format only the worker watch_dir array (independent TOML parsing proves identical configuration), and explicitly await three Node test registrations to satisfy the original typed-Promise gate. Original worker assertions remain; a private wrong-content-type control still executes all3 cases and exits1 (2pass/1fail), then production bytes are restored. These are baseline CI repairs, not JavaScript algorithm or deployment behavior changes.

Contract and boundary impact

Semantic owner: read-aware values → destructuring IR → semantic graph. This existing read-only static-analysis capability changes no public schema, persisted format, target execution or provider authority; advance scope decision is not applicable. Caller-selected paths, source bytes, Evidence identities, shared retained-Evidence owners and cleanup remain preserved. No real external decompiler or native macOS-helper verification is claimed.

Evidence and validation

AI assistance: Codex assisted implementation, investigation and validation. Node24.22.1 / npm11.16.0, isolated HOME/TMP/XDG, no GitHub/model credentials in project processes. Tested integration tree: 2df0ec8a173e4b2c4bb41fd13378b402a5a65107.

  • Published-head related union (pinned79766ca9): the exact test:focused command below — 387 passed /2 existing platform skips. This includes 38 destructuring cases, capture memo/depth/cycle consumers, actual compiled CLI/stdio MCP capture, iNES/carrier integrity fixtures, current Inspector and cleanup boundaries. Controlled engine fixtures are not real engine evidence.
  • Independent Node differential: 120 bounded synchronous object/array/nested programs, declaration/assignment forms and writes/deletes/rebinding before/after the read. Against pinned main79766ca9: 36 candidate dependencies become correctly resolved; no resolved-to-candidate changes or resolutions for runtime-absent properties were observed. Thirty pre-read-write cases remain conservative. This is a bounded presence oracle, not a real-world accuracy rate or proof for arbitrary JavaScript.
  • Public workflow: six independent Node captured-value controls; missing retained Evidence → ping → valid analysis/trace → ping on the same MCP connection. Named contracts, quoted/percent paths, source bytes, Evidence identity and owned cleanup are checked by the existing shared harness.
  • npm run check:fast, npm run check, npm run check:ci, npm run check:ci:deep, npm run docs:check — passed on this integration tree. npm run verify:test-discovery finds 2984 test files exactly once. Original commit hooks passed without changing that tree; the original pre-push hook runs in a credential-free wrapper.
  • Current-head full local coverage (2026-11-04): on exact head 33f8d4e305d7b285ada89c5f8caa619547c4c414 /tree 2df0ec8a173e4b2c4bb41fd13378b402a5a65107, all six original covered shards, the original global/domain/contracts threshold merge, complete inventory and timing gates passed: 40,041 passed /465 original conditional skips /0failed /2984 files exactly once. Source audit remains clean with7086 raw blob matches and the three declared Windows .cmd line-ending equivalents. Original thresholds and selectors were unchanged. This is Linux arm64 local evidence; the earlier80ee/2d11 diagnostics were not reused and this does not replace full hosted qualification.
  • node --test website/worker.test.mjs — all3 original cases pass on macOS and on the exact current Linux head. Latest-main format:check originally failed the one TOML file; check additionally identified the three floating test Promises. Both checks pass after the two-file prerequisite repair; no formatter exclusion, lint-rule change or test assertion was introduced.
  • Latest-head hosted CI 41563466821 completed: 20 successful jobs /20 conditional skips /0 failures or unfinished. Static, Source, all8 built shards, Portable JUnit/timing merge, CI required, Website checks, Apple controls and applicable package/recovery lanes succeeded. Portable: 40,241 passed /270 skipped /2,984 files; Source: 22,822 passed /16 skipped /1,228 files, included in the portable aggregation rather than an additional total. Website's three Node cases executed. Hosted Apple separately ran58 cases and a412-pass/5-skip boundary group; these groups are not summed or claimed as real external decompiler evidence. Actual checkout merge 20209e1daebda81daed3bb313e68c4f0845330c8 has main d496d803a4f50dc82248db0630042894c1136d00 and this head as parents, tree 84821f2095ea9d1e120351c4365df41547bef623. This is distinct from the locally tested tree. Classification remains fast / full portable selection / CI_FULL=false: remote deep/coverage/full qualification remains unexecuted, skips are not passes, and human readiness is PENDING. Draft and human-owned declarations stay unchanged.
Earlier red/green and retained-memory evidence

Before the production correction, the expanded 38-case graph matrix produced8 failures/30 passes on main and the compiled public workflow failed on its missing dependency. The fixed workflow passes; its conservative controls remain.

The prior capture strategy kept one complete object per read. A bounded darwin-arm64 Node24.22.1 retained-heap control (state/IR alive after explicit GC, 2,048 fields /64 reads) measured15,802,216→3,198,936 bytes for a809→80ee. It still transiently evaluates64 objects. This historical same-algorithm measurement is not a new-main measurement, peak/RSS reduction, production OOM reproduction or generic performance claim. Cold/prewarmed ownership regressions retain their16→0 state-cache full-object-access assertions.

The historical local macOS public-workflow attempt failed before analysis because the Swift SDK reports SwiftBridging module redefinition; an independent minimal Foundation compile reproduced it. The SDK was not changed. Actual Linux CLI/MCP execution above is separate evidence.

Related alternative #8142 remains open; no maintainer choice or approval is implied.

Exact related-test selection
npm run test:focused -- src/application/javascript/JavaScriptSemanticGraphDestructuring.test.ts src/application/javascript/JavaScriptSemanticGraphBuilder.test.ts src/application/javascript/JavaScriptSemanticGraphAssignments.test.ts src/domain/javascript/javascriptSemanticMutationInitializers.test.ts src/domain/javascript/javascriptSemanticMutationCycles.test.ts src/domain/javascript/javascriptSemanticRestAssignmentCaptures.test.ts src/domain/javascript/javascriptSemanticValues.memo.test.ts src/domain/javascript/javascriptSemanticCycles.test.ts src/application/javascript/JavaScriptEvidenceInputs.test.ts src/application/javascript/JavaScriptSemanticGraphSeedQueries.test.ts tests/acceptance/applications/javascriptDestructuringCapture.test.ts tests/acceptance/applications/javascriptFeatureTraceSeedSelectionCli.test.ts tests/boundary/process/darwinHelperCache.test.ts tests/process-global/darwinHelperCacheCleanup.test.ts tests/boundary/mcp/enhancedTools.traceFeatureCoverage.test.ts tests/boundary/mcp/idaReadinessFeatureTrace.test.ts tests/boundary/filesystem/inesArtifact.test.ts src/artifacts/NodeSeaArtifactReader.test.ts src/artifacts/pyinstaller/PyInstallerBoundaries.test.ts tests/process-global/cutterDescriptorLifetime.test.ts tests/boundary/mcp/javascriptRuntimeObservationMcp.test.ts tests/boundary/process/providerVerifierCleanup.test.ts

Additional main-drift check (2026-11-04): a separate unpublished/uncommitted combination of current main c3647ade1e557c4179a8b825a37e0c2193cd2526 and this head, tree 42da795be09144fe4bc5c91fe906c2e1f47d6bfc, passes45 Linux graph/seed/compiled CLI-MCP cases, including the empty endpoint regression. Its pinned-toolchain check:fast, check, check:ci, docs:check and discovery2991 pass on macOS; the97 source cases pass there, but three compiled public cases still stop at the known host SwiftBridging SDK conflict. This supersedes the earlier incomplete supplementary cold Linux typed-lint attempt without calling that attempt a pass. Native Node64 pattern-default/alias-order controls found no new unsafe resolution; they are not a global accuracy/performance claim. Main now supplies the equivalent website prerequisites under maintainer commit9ebbe67e; that11-file local integration is distinct from this published13-file/pinned-base comparison. No empty commit was added to refresh CI.

Author readiness

Human owner: @SII-YDD

  • 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.

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge, with no new actionable issue identified.

Summary

Preserves proven destructuring dependencies after later property writes.

  • Destructuring traces keep properties captured before later writes.
  • Artifact tests expose same-size rewrites, and website tests await each run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["Read-aware value owner"] --> B["Query-owned source capture"]
  B --> C["Path presence in destructuring IR"]
  C --> D["Graph projection"]
  D --> E["Resolved dependency remains traversable"]
Loading

Reviews (9) · Last reviewed commit: "fix(ci): repair website validation prere..." · Reviewed by Greptile

@SII-YDD

SII-YDD commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Current-head checkpoint, verified2026-11-04. Head 33f8d4e305d7b285ada89c5f8caa619547c4c414 remains unchanged.

New exact-head local evidence: all six original coverage shards, the original global/domain/contracts threshold merge and complete inventory/timing passed: 40,041passed /465original conditional skips /0failed /2984files exactly once on Linux arm64, tree2df0ec8a173e4b2c4bb41fd13378b402a5a65107. Changed graph38, capture workflow1, memo18, iNES37 and carrier integrity assertions executed. Source audit:7086raw matches plus3declared Windows text equivalents, no tracked edits. No older head's full result was transferred.

A separate current-mainc3647ade1+this head combination, tree42da795b, passes45 Linux graph/seed/actual CLI-MCP cases and all local static/deep/docs/discovery gates (2991files); macOS public workflows remain limited by the known SwiftBridging SDK conflict. The original incomplete cold Linux supplemental gate stays recorded as incomplete. Native64 pattern-order/alias controls found no new unsafe resolutions in that bounded set.

Latest hosted CI41563466821 remains20success/20conditional skips/0failed/0unfinished, actual merge20209e1d, based496d803, tree84821f20. It is fast/CI_FULL=false, with Portable40,241pass/270skip; Source22,822pass/16skip is included. Full hosted qualification remains unexecuted. Upstream permission is read-only for this account; the existing ci:full admission request remains open. Draft/readiness and human-owned declarations are unchanged; no repeated human attestation is supplied or implied. This is not a claim of quality-delivery completion, maintainer approval or merge.

@SII-YDD
SII-YDD force-pushed the fix/javascript-destructuring-read-presence branch from 4459a64 to ad9a67f Compare October 30, 2026 01:25
SII-YDD added a commit to SII-YDD/rea that referenced this pull request Oct 30, 2026
Apply only the three-file patch from PR morluto#8045 as a CI prerequisite for morluto#7716.
Implementation credit remains with its original author.

Original-commit: 96a8021
Co-authored-by: wunianze666-netizen <wunianze666@gmail.com>
@SII-YDD
SII-YDD force-pushed the fix/javascript-destructuring-read-presence branch from 7ab0d76 to 95dcf4f Compare October 31, 2026 05:52
SII-YDD and others added 3 commits November 1, 2026 09:19
Preserve the shared read-position proof through destructuring IR and graph projection. Rebuild the existing PR7716 fix on the current retained-Evidence and feature-trace owners.
Adopt the two-file test-only prerequisite from PR8060, preserving its original integrity and metadata assertions. Production freshness policy is unchanged.

Co-authored-by: SahinurDEV <68515168+SahinurDEV@users.noreply.github.com>
The current clean main fails Knip on this unused exported alias. Runtime helper creation, cache ownership and cleanup are unchanged.
@SII-YDD
SII-YDD force-pushed the fix/javascript-destructuring-read-presence branch from 95dcf4f to c8a0309 Compare November 1, 2026 01:33
@greptile-apps

greptile-apps Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff

These findings could not be posted inline.

  • P1 Valid event registrations disappear src/domain/javascript/javascriptSemanticAsyncEffects.ts:191 ▶

    This check treats the second argument of every .on or .off call as a Node listener without proving which method is called. Valid code such as element.on("click", ".save", handler) uses that argument for a selector, so the collector now drops the registration. Its event relationship and the function's event effect disappear from analysis.

    Apply this rejection only when the call uses Node's unchanged EventEmitter method. Keep other call forms as candidates.

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: All 7 changed test files pass at head 33f8d4e on three Node versions. With the changed source files put back to the merge base, 11 destructuring tests fail on each version. So the tests pin the fix.

Findings

Check Node 22.23.4 Node 24.22.1 Node 26.12.1
node --test website/worker.test.mjs on head pass: 3 pass, 0 fail pass: 3 pass, 0 fail pass: 3 pass, 0 fail
npm run test:focused on head, 6 files pass: 160 of 160 tests pass: 160 of 160 tests pass: 160 of 160 tests
Same focused run, 6 non-test files at 79766ca fail: 11 failed, 149 passed fail: 11 failed, 149 passed fail: 11 failed, 149 passed
  • In the focused run on head, 6 of 6 test files passed on each Node version.
  • In the red run, 3 of 6 test files failed on each Node version.
  • 8 of the 11 failures are in src/application/javascript/JavaScriptSemanticGraphDestructuring.test.ts. One is retains the captured property dependency before a later object write.
  • 2 are in src/domain/javascript/javascriptSemanticValues.memo.test.ts: keeps destructuring-only source copies out of state-owned capture caches, with prewarmed false and true.
  • 1 is in tests/acceptance/applications/javascriptDestructuringCapture.test.ts: retains captured destructuring dependencies through CLI and a reusable MCP connection.
  • website/worker.test.mjs passes 3 of 3 in the red run too. The website changes are formatting only: await test(...) and a reflowed watch_dir list.
  • The PR changes 13 files against the merge base: 7 test files and 6 others.

CI on head 33f8d4e, read live with gh:

  • GitHub reports mergeable true, state unstable, and the PR is a draft.
  • Workflow runs: CI is completed/success. CodeQL production is completed/skipped. 4 PR readiness runs and 4 PR title runs are completed/success.
  • 29 check runs are success. These include CI required, Source tests, Static checks, Build package and Test shard (1/8) through Test shard (8/8).
  • 21 check runs are skipped, such as Deep static checks and Python producer tests.
  • The commit status PR readiness is pending.

Not run

  • A run of javascriptSemanticValues.memo.test.ts with query changed to state at javascriptSemanticObjects.ts:160.
  • A probe of for-of, parameter and catch destructuring with no initializer. That path runs through javascriptSemanticObjects.ts:199-202 and JavaScriptSemanticGraphObjectProjection.ts:119.
  • A merge with current main, 25d3c72.
Test setup
  • Box: Fedora 44 VM (4 vCPUs, 8 GB) on my Nobara 44 PC, Linux 7.2.11
  • Node: 22.23.4, 24.22.1, 26.12.1
  • Head / base: 33f8d4e / 79766ca (merge base with main)
  • Red run: 33f8d4e with the changed source files from 79766ca
  • Install: npm ci --offline and npm run test:prepare on Node 24.22.1
Commands
npm ci --offline
npm run test:prepare
xvfb-run -a npm run test:focused -- src/application/javascript/JavaScriptSemanticGraphDestructuring.test.ts src/artifacts/NodeSeaArtifactReader.test.ts src/artifacts/pyinstaller/PyInstallerBoundaries.test.ts src/domain/javascript/javascriptSemanticValues.memo.test.ts tests/acceptance/applications/javascriptDestructuringCapture.test.ts tests/boundary/filesystem/inesArtifact.test.ts
node --test website/worker.test.mjs

🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊

@SII-YDD

SII-YDD commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the cross-version red/green run. I checked the two remaining probes from your note with Codex assistance, on Node 24.22.1 / npm 11.16.0.

  • On main c78c8aed4, applying the three PR regression files alone gives 11 failures and 46 passes, including the compiled CLI/stdio MCP test. Applying the eight JS paths from 33f8d4e3 onto that main (local tree 2ba9ccfc2566b292e655db68a59444dcd5e11672) gives 164 passes across the five focused files, including four temporary boundary probes.
  • Changing only the cache owner from "query" to "state" in collectDestructuring makes both destructuring-only cache cases fail (cold and prewarmed, 16 others pass). Restoring the original owner gives 18/18.
  • For-of and for-in patterns without an explicit initializer retain unknown source presence with no resolved destructures edge. The parameter and catch cases do not produce that object operation, and likewise add no resolved edge. Native Node executes all four fixtures and yields the expected values. The graph assertions pass on both current main and the JS overlay.

This was a local JS compatibility and regression check. The PR head is unchanged and full hosted qualification is still outstanding.

@N0zoM1z0

Copy link
Copy Markdown
Collaborator

Thanks for this. Its semantic part was prepared on top of current main (its 10 new tests fail on base), but it was taken out of #10538. Review found that each destructuring read evaluates the whole source object to get one path's presence, with a fresh query cache per read, so n reads of a w-field object cost about n·w. A presence-only query, or shared unchanged-source facts in the value evaluator, would avoid that. If you'd like to take it further, rebasing only the semantic files onto main with that change would be the way forward; the CI, website and fixture changes here are not needed.

morluto added a commit that referenced this pull request Nov 19, 2026
* fix(javascript): retain proven property presence at reads

The read-time IR and projection boundary builds on the destructuring work in #7716. This change adds an indexed own-slot proof and uses it for ordinary member reads as well.

Co-authored-by: SII-YDD <38822679+SII-YDD@users.noreply.github.com>

* fix(javascript): retain destructuring proof in read order

---------

Co-authored-by: SII-YDD <38822679+SII-YDD@users.noreply.github.com>
morluto added a commit that referenced this pull request Nov 19, 2026
Reuse the capture-lifetime approach from #7716 for ordinary array-read proof.

Co-authored-by: SII-YDD <38822679+SII-YDD@users.noreply.github.com>
@morluto

morluto commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Closing as superseded by the read-time destructuring changes on main, including #12551 and #12563. The original graph matrix, compiled CLI and stdio MCP acceptance, and cold/prewarmed cache controls passed against current main. The original issue #7559 is already closed. Thanks @SII-YDD for the reproducer and acceptance coverage. #12576 adds a later sibling case outside the original scope. The unrelated carrier fixtures are tracked in #10155.

@morluto morluto closed this Nov 19, 2026
@morluto morluto added area: runtime Process capture and runtime observation bug Something isn't working labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] A later scalar property assignment makes an earlier destructuring dependency ambiguous

4 participants