Skip to content

Astro frontmatter variable nodes do not share their file node's ID stem, and can embed the absolute on-disk path in the node ID #2630

Open

Description

@rajarshidattapy

Labels: bug, extract, astro, node-identity
Version: 0.9.40

Summary

extract_astro() mints nodes for frontmatter variables using a different ID recipe than the
one used for the enclosing file node. As a result:

  1. The symbol node does not carry the file node's stem as a prefix, breaking the
    <file_stem>_<entity> convention the build layer relies on.
  2. When the path handed to extract() is absolute and no root is passed, the full
    absolute filesystem path
    is baked into the symbol node's ID — the leak class of Node IDs for file / directory / project nodes embed the absolute scan path (leaks local username, makes committed graph.json non-portable / non-idempotent) #1789 /
    Windows: absolute source_file from detect() breaks node identity on full rebuild and poisons the semantic cache #2197, still reachable in 0.9.38.

Steps to reproduce

src/pages/index.astro:

---
import { getPosts } from '../lib/content';
const posts = getPosts();
---
<h1>{posts.length}</h1>

1. Stem mismatch (relative input)

extract([Path('src/lib/content.ts'), Path('src/pages/index.astro')])
id=lib_content              # file node for content.ts
id=lib_content_getposts     # symbol      -- correctly prefixed
id=pages_index              # file node for index.astro
id=src_pages_index_posts    # symbol      -- NOT prefixed with "pages_index"

The file node is pages_index (2-component stem) but its own frontmatter variable is
src_pages_index_posts (3-component). They no longer share a prefix.

2. Absolute path leak (absolute input, no root)

extract([Path('src/pages/index.astro').resolve()])
id=index                                                              # file node -- fine
id=c_users_asus_appdata_local_temp_claude_c_users_asus_desktop_os_gra
   phify_accccdec_07ee_4c98_8664_8b2a39362228_scratchpad_astro_src_pa
   ges_index_posts                                                    # symbol -- LEAK

Note both nodes come from the same file: the file node was correctly anchored to index,
the variable node was not anchored at all.

Expected behavior

The variable node should be pages_index_posts (case 1) and index_posts (case 2) — always
<file node stem>_<entity>, never containing the absolute path.

Reachability

Case 1 is reachable from python -m graphify.extract src/pages/index.astro ...
(graphify/extract.py:6523 calls extract(paths) with no root) and from any library
caller. Case 2 needs absolute inputs whose inferred common root sits below the project root —
e.g. extract([Path('/abs/src/pages/index.astro')]), a single-file call.

Passing an explicit root produces correct IDs in both cases:

extract(paths, root=Path('.').resolve())
# -> src_lib_content, src_lib_content_getposts, src_pages_index, src_pages_index_posts

so the main graphify extract CLI is not affected. This is a library-API / module-entry-point
defect.

Impact

  • build._semantic_id_remap and graph_has_legacy_ids relate a symbol to its file with
    norm_nid.startswith(new_stem + "_") (build.py:630, build.py:1057). A symbol that does
    not carry its file's stem is invisible to that logic and never migrates.
  • The contains edge still connects them, but ID-based reconciliation (dedup, incremental
    re-key, cache replay) treats them as unrelated.
  • Case 2 makes graph.json non-portable and leaks the local username.

Suggested fix

extract_astro() (graphify/extract.py:1575) should mint frontmatter symbol IDs from the
same anchored stem the file node uses — i.e. reuse _make_id(_file_stem(rel), name) with the
already-computed relative path, rather than deriving from the raw input path. The safest
version is to have the extract() id-remap post-pass assert the invariant, so any extractor
that drifts is caught:

# post-pass sanity: every symbol node must sit under its file node's stem
assert sym_id.startswith(file_stem + "_"), (sym_id, file_stem)

Related

Activity

  1. ayushcodes10 commented on Sep 14, 2026

    @ayushcodes10
    Contributor

    This is already fixed — both reported symptoms are gone on current v8 (well past 0.9.61).

    The root cause was the warm-cache round-trip asymmetry in graphify/cache.py that #2632 (closed, not merged via the GitHub button but applied and shipped per the maintainer's comment there) fixed in v0.9.41. Re-ran both of this issue's own repros directly against current code:

    Case 1 (stem mismatch, relative input)

    extract([Path('src/lib/content.ts'), Path('src/pages/index.astro')])
    

    produces:

    src_lib_content_ts     content.ts
    src_lib_content_getposts   getPosts()
    src_pages_index_astro  index.astro
    src_pages_index_posts  posts   <- correctly prefixed now
    

    Case 2 (absolute path leak, single absolute file)

    extract([Path('src/pages/index.astro').resolve()])
    

    produces:

    index         index.astro
    index_posts   posts   <- correctly prefixed, no absolute path anywhere
    

    Both match the issue's own "Expected behavior" section exactly. Since the fix already shipped and the acceptance criteria are met, closing this out rather than opening a duplicate PR — let me know if you'd like it reopened for any remaining edge case.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions