Skip to content

[Bug]: graphify uninstall --purge deletes the whole project when GRAPHIFY_OUT is set but empty (or .) #4328

Closed

Description

@Hassannzidan

Pre-flight checks

  • I have checked the Troubleshooting section in the README

What happened?

graphify uninstall --purge is documented to delete graphify-out/ (README: "add --purge to also delete graphify-out/"). When GRAPHIFY_OUT is set to an empty string, or to ., it instead runs shutil.rmtree on the project folder itself: source, .git, everything. It asks for no confirmation and prints only / -> deleted (--purge).

GRAPHIFY_OUT Expected Actual
unset / graphify-out delete ./graphify-out/ deletes ./graphify-out/ ✅
"" (set but empty) treat as unset, delete ./graphify-out/ deletes the whole project
. refuse, since it is the project deletes the whole project

Without --purge the bad value still misroutes output: out_path() resolves into the project root, so graph.json, cache/ and reports are written there instead of graphify-out/.

Root cause (v8 @ b4e6307):

  • graphify/paths.py:28: GRAPHIFY_OUT = os.environ.get("GRAPHIFY_OUT", "graphify-out"). The default only applies when the variable is missing; a set-but-empty value comes through as "". Then GRAPHIFY_OUT_NAME (paths.py:397) becomes '.' and out_path() (paths.py:400) points at the project root.
  • graphify/install.py:2143-2148, the purge block in uninstall_all(): out = pd / _GRAPHIFY_OUT gives Path(".") / "", which is Path("."). Then rmtree(out) runs, with no check that out is inside the project and not the project itself.
  • The same pattern appears in the git-hook rebuild bodies, graphify/hooks.py:224 and :299. They read os.environ.get('GRAPHIFY_OUT', 'graphify-out') directly and miss graphify-out/.graphify_root when the value is empty. This doesn't delete anything, but it's the same bug.

How an empty value happens in practice: a .env entry left blank (GRAPHIFY_OUT=), docker-compose GRAPHIFY_OUT=${GRAPHIFY_OUT} when the host variable is unset, a CI variable defined with an empty value, or export GRAPHIFY_OUT= in a shell profile.

Steps to reproduce

# Safe: neither step deletes anything. Run in bash from a graphify checkout or any env with graphify installed.

# 1. The path arithmetic the purge relies on:
python -c "from pathlib import Path; print(repr(Path('.') / ''), repr(Path('.') / '.'))"

# 2. What graphify resolves the output dir to:
GRAPHIFY_OUT= python -c "import graphify.paths as p; print(repr(p.GRAPHIFY_OUT), repr(p.GRAPHIFY_OUT_NAME), p.out_path('graph.json'))"
GRAPHIFY_OUT=. python -c "import graphify.paths as p; print(repr(p.GRAPHIFY_OUT), repr(p.GRAPHIFY_OUT_NAME), p.out_path('graph.json'))"
python -c "import graphify.paths as p; print(repr(p.GRAPHIFY_OUT), repr(p.GRAPHIFY_OUT_NAME), p.out_path('graph.json'))"

# 3. With either bad value, `graphify uninstall --purge` then calls rmtree(Path(".")).
#    WARNING: please don't confirm this in a real folder. Besides deleting the project,
#    `graphify uninstall` removes graphify from every agent platform on the machine.
#    Confirmed only in a throwaway temp project, with the platform uninstallers stubbed out.

Error output or graph output

# step 1
WindowsPath('.') WindowsPath('.')

# step 2: empty, dot, unset
'' '.' graph.json
'.' '.' graph.json
'graphify-out' 'graphify-out' graphify-out\graph.json

# step 3: uninstall --purge with GRAPHIFY_OUT="" (temp project)
  /  ->  deleted (--purge)
# the project directory, including src/, no longer exists

Graphify version

0.9.85 (v8 @ b4e6307)

Operating System

Windows

Python Version

3.13

Installation Method

uv tool install (recommended)

Additional Environment Details

Python 3.14.5 (the dropdown has no 3.14 option). No provider/LLM environment variables are involved. A clean checkout of v8 @ b4e6307 reproduces it. The code path is platform-independent, so it likely affects Linux and macOS the same way.

Additional context

Likely also affected (not verified): GRAPHIFY_OUT=.. (purge target would be the project's parent) and an absolute GRAPHIFY_OUT pointing at the project or one of its parents, since the purge has no containment check.

I have a fix with regression tests ready: it treats a blank value as unset, rejects ./.. in paths.py, and adds a guard in uninstall_all() that refuses to purge the project, its parents, home or a filesystem root before anything is uninstalled. I'll open a PR that references this issue.

Activity

  1. added
    bug
    on Oct 11, 2026
  2. github-actions commented on Oct 11, 2026

    @github-actions

    Thanks for opening this issue, @Hassannzidan. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

  3. added a commit that references this issue on Oct 11, 2026
    97a938f
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions