Skip to content

fix(javascript): resolve destructuring relation using read-position object slot state - #8142

Closed
highmachs wants to merge 4 commits into
morluto:mainfrom
highmachs:fix/js-destructuring-property-mutation-edge
Closed

highmachs wants to merge 4 commits into
morluto:mainfrom
highmachs:fix/js-destructuring-property-mutation-edge

Conversation

@highmachs

Copy link
Copy Markdown
Contributor

Summary

Fixes #7559.

When building semantic graphs for JavaScript applications, destructuring dependencies (destructures edges) are projected by evaluating the property slot of the target object. When a scalar property assignment occurred after destructuring (e.g., config.mode = "loose" after const { mode } = config;), the object's merged slot state acquired presence: "unknown-coverage", which caused the earlier read's destructuring edge to downgrade from resolved to candidate.

This change evaluates target slots against the binding's initializer value when no preceding write has affected the property path within the same callable context, keeping the earlier destructures dependency resolved and traversable in default queries.

Problem and expected behavior

In code such as:

const config = { mode: "strict" };
const { mode } = config;
config.mode = "loose";

trace-javascript-semantics with a backward-provenance seed for mode returned status: "ambiguous" with 3 nodes and 2 defines relations, omitting the destructures relation because default query traversal filters candidate edges.

The expected contract (docs/javascript-application-workflows.md:257-259) specifies:

"Proven preceding unconditional assignments, including writes dominating a read in the same conditional block, can resolve a target; later writes do not replace an earlier read or captured alias."

Because projectSemanticObjects evaluated target slots using the merged whole-program value from binding.value rather than the slot state at the operation's read position, the subsequent assignment config.mode = "loose" downgraded the earlier read's destructuring edge to candidate and emitted a spurious ambiguous-target unknown.

Change and scope

  • In src/application/javascript/JavaScriptSemanticGraphObjectProjection.ts:
    • Track preceding member writes per object binding during semantic object projection.
    • Determine whether a preceding write within the same callable context has affected the property path using prefix path matching.
    • Evaluate the target slot against binding.initializerValue when no preceding write has affected the property path, preserving the resolved slot presence from the initializer.
    • Update objectTarget to accept an optional readPositionValue override.
  • In src/application/javascript/JavaScriptSemanticGraphDestructuring.test.ts:
    • Added unit test verifying that destructures relation remains resolved, no destructures unknowns are emitted, and backward-provenance query successfully traverses through destructures to the property slot when a property is mutated after destructuring.
    • Added regression test verifying that destructures relation remains candidate when the mutation precedes destructuring.

Contract and boundary impact

  • Semantic owner and earliest changed stage: projectSemanticObjects in JavaScriptSemanticGraphObjectProjection.ts; affects semantic graph relationship resolution and semantic query traversal.
  • Contribution scope fit and linked maintainer decision: Fixes bug [Bug] A later scalar property assignment makes an earlier destructuring dependency ambiguous #7559; aligns with straight-line capture order and read-position value invariants.
  • CLI and MCP/tool-catalog contract: Preserves existing CLI and MCP schemas; enables default backward-provenance and dependency queries to reach resolved destructuring sources.
  • Provider, bridge, target-format, or platform compatibility: JavaScript analysis engine (platform-independent).
  • Evidence, artifact, provenance, or reconstruction contract: Eliminates false candidate resolution and spurious ambiguous-target unknowns on earlier destructuring operations.
  • Target selection, authority, upstream behavior, and cleanup details: No target interaction or cleanup changes.
  • Generated metadata, package, or installation impact: None.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated:
    • src/application/javascript/JavaScriptSemanticGraphDestructuring.test.ts: Added retains resolved destructuring relation when a property is mutated after destructuring and keeps destructuring relation candidate when a property is mutated before destructuring.
  • Base reproduction or other evidence: On base revision, relations[0].resolution was "candidate", an unknown was emitted in graph.unknowns, and queryJavaScriptSemanticGraph omitted destructures from default backward provenance traversal.
  • User-visible CLI/MCP output: trace-javascript-semantics default query traverses destructures edge directly to property slot without requiring include_ambiguous_dynamic_edges: true.
  • Remaining proof gaps: None.

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

  • npx vitest run src/application/javascript/JavaScriptSemanticGraphDestructuring.test.ts - 14 passed.
  • npx vitest run src/application/javascript/ - 25 test files passed (622 tests passed).
  • npx vitest run src/domain/javascript/ - 162 test files passed (4429 tests passed).
  • npm run check:fast - turbo typecheck & lint passed (2 successful).
  • npm run verify:module-boundaries - checked 3432 source files successfully.
  • npm run verify:test-discovery - discovered all 2871 test files exactly once.

Compatibility, safety, and release

  • Breaking changes or migration steps: None.
  • Real Hopper/Ghidra, browser, or OS coverage: Validated on Node.js 22 & 24 on Windows 11.
  • Package or release metadata impact: None.
  • Security, privacy, process, or containment review: Fully contained in local AST projection.

Author readiness

Human owner: @highmachs

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

Copilot AI balanced review requested due to automatic review settings October 30, 2026 10:06
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-30T10:06:52.197137Z
We couldn’t complete this review. Comment @codex review to try again.
6557893 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the nested-read finding is fixed and no new blocking issue was found.

Summary

Fixes nested destructuring reads by checking the property path relative to the evaluated source.

  • Earlier destructuring reads keep their property links after later writes.

Reviews (4) · Last reviewed commit: "fix(javascript): resolve pattern-relativ..." · Reviewed by Greptile

…bject slot state

When projecting semantic graph object operations, lookups for target slots previously used the merged binding value across the entire program. When a scalar property assignment occurred after destructuring (e.g. config.mode = 'loose' after const { mode } = config), the merged slot state acquired unknown-coverage presence, downgrading the earlier read's destructuring edge to candidate and emitting a spurious ambiguous-target unknown.

Track preceding member writes within the same callable context and evaluate reads against the binding's initializer value when no preceding write has affected the property path, preserving resolved destructuring provenance.
@highmachs
highmachs force-pushed the fix/js-destructuring-property-mutation-edge branch from 6557893 to f3786f9 Compare October 31, 2026 14:35
…rget binding state

Resolve function callable node IDs using context.callableNodes and evaluate destructuring read-position slot state using the producer's target binding facts. This preserves resolved dependencies inside functions while keeping destructuring relations uncertain when affected by alias writes or loop-carried mutations.
@highmachs
highmachs force-pushed the fix/js-destructuring-property-mutation-edge branch from f3786f9 to 0887da2 Compare October 31, 2026 14:38
@greptile-apps

greptile-apps Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

@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
@morluto

morluto commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Closing as superseded on main by #12477 (1dc22f18cd), #12673 (a5f19cbaf6), and #13433 (365bbd9008), which record read-position sourcePresence in src/domain/javascript/javascriptSemanticObjects.ts. Linked issue #7559 is already closed.

@morluto morluto closed this 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.

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

3 participants