Skip to content

Silent data loss: env/*_env directories pruned as false-positive venvs, with zero trace in any report bucket #2058

Closed

Description

@oz-pressler-sndk

Summary

detect.py's directory-noise heuristic (_SKIP_DIRS / _is_noise_dir) treats any directory literally named env (or ending in _env) as a Python virtualenv and silently prunes it during the walk — with zero trace in any reportable bucket (ignored, unclassified, or any warning). This causes large, silent, undetectable data loss for any codebase that uses env/*_env as a real source directory name — a naming convention common in hardware/ASIC verification environments (UVM testbenches), and plausibly in other domains too.

Root cause

# graphify/detect.py
_SKIP_DIRS = {
    "venv", ".venv", "env", ".env",
    ...
}

def _is_noise_dir(part: str, parent: "Path | None" = None) -> bool:
    if part in _SKIP_DIRS:
        return True
    ...
    if part.endswith("_venv") or part.endswith("_env"):
        return True
    ...

This check is applied unconditionally to every subdirectory encountered during the os.walk traversal (detect(), around the kept_dirs/dirnames[:] pruning loop), before the _is_ignored() / .graphifyignore negation logic runs. Because of this ordering:

  1. A .graphifyignore negation (!env/) cannot rescue the directory — pruning happens earlier and unconditionally.
  2. Pruned directories are never added to ignored, unclassified, or any other bucket in the detect() return value — there is no way to detect the loss from the tool's own output. The only symptom is a lower file/node count than expected, with nothing pointing at why.
  3. The exact-name check (env) applies to every subdirectory the walker descends into, not just files reached directly — so even pointing detect()/extract directly at a parent directory (e.g. src_env/) does not protect a nested env/ subdirectory from being pruned.
  4. The suffix check (_env) additionally prunes any directory whose own name ends in _env (e.g. src_env/) the moment it's reached as a subdirectory from a parent scan — even though it's not literally named env.

Reproduction

Any repo with this structure:

repo/
  src_env/          # <- pruned entirely when scanned from repo root (matches *_env)
    env/            # <- pruned even if src_env/ itself is the scan root (exact match)
      my_class.py
    other_dir/
      also_real.py  # <- also lost, since the whole src_env/ subtree is pruned from the root scan
from graphify.detect import detect
from pathlib import Path
detect(Path("repo"))          # my_class.py and also_real.py: silently absent
detect(Path("repo/src_env"))  # my_class.py: still silently absent (env/ pruned as subdir)
                               # also_real.py: found (not under the env/ subdir)

Measured real-world impact

On a live Sandisk/WDC Gen-II UVM verification repo (ip-ctrl_mem_verif) that follows the extremely common convention of naming the top-level environment directory src_env/ and the user-owned environment-logic subdirectory env/ (e.g. verif_sv/src_env/env/ctrl_mem_env.sv):

  • 93 of 109 .sv source files (705 KB) were completely absent from the graph — including the core environment class, config, scoreboard, coverage collectors, and every sequence file.
  • The build reported success with no errors or warnings, and produced a plausible-looking (but badly incomplete) community/report structure — nothing in the tool's own output indicated anything was wrong.
  • Verification required manually diffing find . -iname "*.ext" | wc -l against detect()'s reported count per extension to even notice the gap.

This will reproduce on every repo following this convention — which is the default directory-naming convention for an entire class of hardware verification methodology (Sandisk/WDC "Gen-II" UVM environments), not a one-off.

Suggested fixes (any of these would help; happy to discuss/PR)

  1. Report pruned noise-dirs. Add pruned directories to a new bucket (e.g. pruned_as_noise_dir) in detect()'s return value, the same way ignored/unclassified already work — so at minimum the loss is visible and diffable.
  2. Let .graphifyignore negation override _is_noise_dir, not just _is_ignored, so !env/ in a .graphifyignore can rescue a real source directory the same way it already rescues gitignored-but-wanted paths.
  3. Narrow the heuristic with context, similar to the existing snapshots special-case (_JS_SNAPSHOT_TEST_ROOTS / checking for *.snap files before pruning a bare snapshots dir) — e.g. only treat env/venv as a Python virtualenv if it actually contains venv markers (pyvenv.cfg, bin/activate or Scripts/activate.bat, lib/pythonX.Y/site-packages), rather than pruning on bare name alone.

Happy to provide the exact repo structure / a minimal repro directory tree if useful.

Environment

  • graphify version: 0.9.20
  • Installed via: pip install graphifyy (python 3.11.1)
  • OS: Linux (RHEL-based, dspg CAD infra)

Activity

  1. safishamsi commented on Jul 20, 2026

    @safishamsi
    Member

    Fixed in v0.9.22: the venv heuristic for env/.env/*_env is now gated on real markers (pyvenv.cfg, activate, lib/python*, conda-meta/), so real source dirs with those names are indexed; pruned-as-noise dirs are also recorded in a new pruned_noise_dirs bucket. https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.22

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