Skip to content

fix(resolution): repoint cross-extension re-exports without leaking an absolute path (#1814) - #1976

Closed
alphanury wants to merge 1 commit into
Graphify-Labs:v8from
alphanury:fix/1814-cross-ext-self-cycle
Closed

alphanury wants to merge 1 commit into
Graphify-Labs:v8from
alphanury:fix/1814-cross-ext-self-cycle

Conversation

@alphanury

Copy link
Copy Markdown
Contributor

Fixes #1814.

Summary

A same-basename cross-extension re-export — a typed .ts wrapper re-exporting a hand-written .mjs runtime, export { N } from "./foo.mjs" — produced a phantom self-cycle: foo.ts → foo.ts, reported as a 1-file import cycle in GRAPH_REPORT.md.

Root cause

foo.ts and foo.mjs collapse onto one base file id (the id stem drops the extension). _disambiguate_colliding_node_ids correctly salts the two file nodes apart (foo_ts_foo / foo_mjs_foo), but the re-export edge keyed its target salt by the importer's own source_file. So the ./foo.mjs target was salted back onto foo.ts — a source == target self-loop. The residual was purely at the edge layer; node ids were already correct.

Fix

When an import/re-export edge is emitted, the emitter now stamps the resolved target file on the edge as a transient target_file hint. During disambiguation, an imports / imports_from / re_exports edge keys its target salt by that file instead of the importer's, so the salt lands on the real sibling node and the phantom cycle disappears. This generalizes the C/ObjC .h-sibling carve-out from #1475 to every language and to re_exports.

The hint has no downstream reader and holds an absolute path, so it must never persist into graph.json:

  • it is poped the moment disambiguation consumes it (both the colliding and the no-collision early-exit paths);
  • the graph serializer drops any target_file as a backstop, so an incremental build_merge that re-serializes base edges without re-running disambiguation can't leak one either.

graph.json stays deterministic and byte-identical across checkout locations. Node ids are unchanged, so no forced rebuild. (The extension-aware-id alternative was rejected: it would rewrite every file and symbol id and force a full-rebuild migration in lockstep with the skill/validation id spec, #1033.)

One caveat, called out in the CHANGELOG: a graph written by a pre-fix build still records the stale self-loop, and because graphify update only re-extracts changed files, an unchanged wrapper keeps that edge until it is next edited or a --force full rebuild runs.

Testing

New tests/test_cross_extension_reexport_self_cycle.py (10 cases): the reported .ts/.mjs repro, static + dynamic + require import forms, star and namespace re-exports, the no-collision path (target salt untouched), and a serializer check that no target_file survives into the persisted graph.

  • New file: 10 passed.
  • Full suite: 3363 passed, 33 skipped. The only failures (4, in tests/test_ollama_retry_cap.py) are pre-existing and unrelated — they fail identically on a clean v8 checkout (an ollama SDK module missing from the test env).

@safishamsi

Copy link
Copy Markdown
Member

Landed on v8 (ships in 0.9.19) in d56b70a, cherry-picked to preserve your authorship. Thanks @alphanury for the fix and @Greg-Moskalenko for the report — a same-basename cross-extension re-export (foo.ts re-exporting ./foo.mjs) no longer manufactures a phantom self-cycle; the re-export edge target is salted by the resolved sibling file, no absolute path leaks, node ids unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Phantom self-cycles: same-basename cross-extension re-exports (X.ts → ./X.mjs) collapse to one node

2 participants