graphify icon indicating copy to clipboard operation
graphify copied to clipboard

imports to a file absent from the scan (e.g. gitignored codegen) emit abs-path slug endpoints (residual of #2262)

Open vanjos opened this issue 3 months ago • 5 comments

Follow-on to #2262. That report's .tsx-handler calls case was fixed in 0.9.30, but the import-edge residual I flagged in a follow-up comment (before the issue was closed) is still present on 0.9.32. Filing it separately with a minimal repro since it is a distinct code path.

Bug

When a TS/JS file imports from a module that is not present in the scanned tree (e.g. a gitignored codegen output), the imports and imports_from edges get absolute-path-derived slug endpoints instead of a stable identifier. The slug is machine-specific and differs per checkout path, so committed graphs churn on every rebuild from a different location, the same reproducibility problem as #2262 and #2273.

Repro (minimal, deterministic on 0.9.32)

proj/tsconfig.json
proj/src/consumer.ts   -> import { getFoo } from "./generated/api";
                          export function run(): number { return getFoo(); }

proj/src/generated/api.ts is intentionally absent (mimics gitignored codegen output). graphify update proj --no-cluster yields:

src_consumer --imports_from--> <abs-scan-slug>_proj_src_generated_api
src_consumer --imports-->      <abs-scan-slug>_proj_src_generated_api_getfoo

Both endpoints are the absolute scan path slugified, for a module and symbol that are not on disk.

Scale

On a real TS monorepo (~75k nodes), this produced ~6,700 such endpoints (4,138 imports, 2,510 imports_from, plus a few references/re_exports), almost all imports to a gitignored generated GraphQL client. It is the dominant reason that graph fails a fail-closed host-path check.

Suggested fix

For an import target that resolves to no node (an absent file), emit a repo-relative stable identifier or drop the edge, rather than an absolute-path-derived slug. The general backstop that canonicalizes node-less absolute-derived endpoints elsewhere does not cover the imports/imports_from path.

vanjos avatar Aug 04 '26 17:08 vanjos

Confirmed this still reproduces on 0.9.36. This one is the dominant blocker for us: on a real TS monorepo it accounts for ~6,700 abs-path slug endpoints, which fails a fail-closed host-path check and keeps that graph out of commit. Happy to test a patch or share more of the real graph if it helps.

vanjos avatar Aug 10 '26 14:08 vanjos

Still reproduces on graphify 0.9.38. The minimal repro (a TS file importing from a module absent from the scan, e.g. gitignored codegen output) still emits absolute-path slug endpoints for both import edges:

src_consumer  imports_from  <abs-scan-slug>_proj_src_generated_api
src_consumer  imports       <abs-scan-slug>_proj_src_generated_api_getfoo

At scale on a real TS monorepo (~82k nodes, ~52k ts/tsx), 6,609 such endpoints remain (imports 4,053, imports_from 2,476, references 64, re_exports 16), almost all imports to a gitignored generated GraphQL client. Consistent with the ~6,731 seen on 0.9.32, so no change.

vanjos avatar Aug 11 '26 15:08 vanjos

I reproduced this on current v8: an unresolved relative TypeScript import still emits absolute-path-derived imports and imports_from targets. I’m adding a regression test for the missing generated-module case, then will keep unresolved local imports on a stable external reference path so checkout paths cannot leak into the graph.

rohit-jsfreaky avatar Aug 11 '26 16:08 rohit-jsfreaky

Fixed in v0.9.41 (graphifyy==0.9.41 on PyPI). An unresolved local JS/TS import (to a file absent from the scan) now emits a stable, portable ref_* target id instead of leaking a per-checkout absolute-path slug. Thanks @rohit-jsfreaky (PR #2645).

safishamsi avatar Aug 12 '26 13:08 safishamsi

This is not fully fixed in 0.9.41 - could you reopen? It fixes plain import ... from an absent/gitignored module (verified: those edges now resolve to ref_* ids). But three other code paths that hit the same unresolved-absent-file resolution still emit the per-checkout absolute-path slug instead of a ref_* id. On a real TS monorepo (~82k nodes) this leaves 314 abs-path-slug endpoints, down from ~6,609 on 0.9.38.

1. re_exports edges (verified minimal repro on 0.9.41)

export { X } from "./absent" still leaks. Minimal:

proj/src/reexport.ts        ->  export { getFoo } from "./generated/api";
(proj/src/generated/api.ts is absent)

yields:

src_reexport  imports_from  ref_generated_api                          (fixed)
src_reexport  re_exports    <abs-scan-slug>_proj_src_generated_api     (still an abs-path slug)

The imports_from half now resolves to ref_, but the paired re_exports edge does not. Same file category as the fixed import case. 6 such leaks in the real repo (e.g. Packages/file-management/src/index.ts, Packages/insights/test/mocks/MockData.ts re-exporting the gitignored generated GraphQL client).

2. CommonJS require()

Unresolved require("./oop") / require("../lib/event") still leaks the abs-path slug (both imports and imports_from). 244 leaks in the real repo, all in two vendored bundles (LegacyPageScripts/src/Vendor/ace/ace.js, .../Vendor/ace-12/ace.js) that require sibling files absent from the checkout.

3. Markdown references

Doc-to-doc cross-references to absent paths use a separate extraction path and still emit abs-path slugs. 64 leaks (e.g. Apps/storybook/.ai/instructions.md). Likely outside the strict JS/TS import scope; flagging for completeness.

Extending the same ref_* resolution to re_exports and require() (and optionally the markdown reference path) would close the remaining 314.

vanjos avatar Aug 12 '26 15:08 vanjos