Skip to content

Junction/symlink scan roots silently drop out-of-root targets, follow_symlinks does not help, and NTFS junctions bypass the flag entirely #2478

Open

Description

@alexrdunbar

Summary

A curated scan root built from NTFS junctions went from ~1613 indexed files to 29 on a routine 0.4.11 to 0.9.12 upgrade, with no warning, no error, and no CLI flag able to restore it. Two separate issues combine here.

Related but distinct: #2468 is another way the corpus silently zeroes out. Different root cause, same failure mode (success exit, empty graph, no warning).

Environment

  • graphify (graphifyy) 0.9.12, previously 0.4.11
  • Windows 11, Python 3.x, scan root is a directory of NTFS junctions

Setup

A deliberately curated scan root, so the graph covers exactly the knowledge surfaces we care about rather than the whole repo:

graphify-corpus/
  claude-agents    -> JUNCTION to ../.claude/agents
  claude-skills    -> JUNCTION to ../.claude/skills
  claude-rules     -> JUNCTION to ../.claude/rules
  claude-commands  -> JUNCTION to ../.claude/commands
  claude-scripts   -> JUNCTION to ../.claude/scripts
  memory           -> JUNCTION to ../memory
  tasks            -> JUNCTION to ../tasks
  docs/            (real directory)
  *.md             (real files)

Under 0.4.11 this indexed the full ~1613 files. Under 0.9.12 it indexes 29, the real (non-junction) entries only.

Issue 1: follow_symlinks cannot affect NTFS junctions

Junctions are reparse points, but not symlinks as far as Python is concerned:

>>> p = Path(r"...\graphify-corpus\memory")   # an NTFS junction
>>> os.path.islink(p)
False
>>> p.is_symlink()
False
>>> p.resolve()
WindowsPath('.../claude-code/memory')          # resolve() DOES traverse it

Both places follow_symlinks is consumed are therefore inert for junctions:

  • os.walk(scan_root, followlinks=follow_symlinks, ...) (detect.py:1132) already descends junctions regardless of the flag, because os.walk only treats islink() dirs specially.
  • the prune at detect.py:1164, if child.is_symlink() and not _resolves_under_root(...), never fires, because is_symlink() is False.

So on Windows the flag is a no-op for the most common way users build a curated scan root.

Issue 2: the actual exclusion is unconditional, and silent

The real gate is detect.py:1190:

if not _resolves_under_root(p, root):
    skipped_sensitive.append(str(p) + " [symlink target outside scan root]")
    continue

This is not gated on follow_symlinks. Because Path.resolve() traverses junctions, every junctioned file resolves outside the scan root and is dropped. Measured, same corpus:

follow_symlinks=False : total_files=29, 1571 skipped "[symlink target outside scan root]"
follow_symlinks=True  : total_files=29, 1571 skipped "[symlink target outside scan root]"

Identical. There is no CLI flag for this (cli.py exposes no follow-symlinks option) and no environment override (I scanned every GRAPHIFY_* name in the package).

I understand the containment rule is deliberate. detect.py:1046 states it plainly:

Kept for callers that import the private helper, but detection no longer enables symlink following automatically. Following symlinks is now an explicit opt-in, and out-of-root symlink targets are never indexed.

The problem is that "explicit opt-in" has no opt-in to make. follow_symlinks=True is documented as the opt-in, but out-of-root targets are refused regardless, so for any scan root whose links point outside itself (which is the entire point of a curated scan root) the opt-in does nothing.

Impact: this fails silently, and then compounds

The scan reported success. Nothing surfaced at normal verbosity. The 1571 dropped files went into skipped_sensitive, which reads as "sensitive files were protected", not "80% of your corpus is gone".

Worse, the next incremental run then reported 1613 of 1613 files as deleted, because the prior manifest still listed them. Anyone who runs an update on that result purges their graph. We caught it only because a weekly job kept flagging implausibly large change counts.

Requests

In rough priority order:

  1. Warn loudly when a scan root's own children are dropped by the containment rule. Any run where a top-level entry of the scan root contributes zero files because of out-of-root resolution should print a warning, not a skipped_sensitive line. This alone would have caught it on day one.
  2. Treat junctions as symlinks on Windows, or document explicitly that they are not covered by follow_symlinks. Right now the flag silently means something different on Windows than the name implies.
  3. Provide a real opt-in for out-of-root targets, e.g. --follow-symlinks plus --allow-outside-root, or --link-roots <path> to declare additional trusted roots. Containment-by-default is right; no escape hatch at all is what makes it a dead end.
  4. Guard the delete path. If a run detects a very large proportion of the manifest as deleted (here 100%), it should refuse and require a flag rather than proceed.

Workaround for others hitting this

Stop using a junction-based scan root. Point the scan at the real common ancestor and narrow it with .graphifyignore. Note that .graphifyinclude will not help: _is_included (detect.py:962) and _could_contain_included_path (detect.py:1011) are defined but never called in 0.9.12, and include_patterns (detect.py:1101) is assigned and never read. That looks like a separate regression and I am happy to split it into its own issue.

Activity

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