Skip to content

Fix rebuilds from deleted hook cwd#1703

Open
FranciscoJSBarragan wants to merge 1 commit into
Graphify-Labs:v8from
FranciscoJSBarragan:fix/rebuild-deleted-cwd
Open

Fix rebuilds from deleted hook cwd#1703
FranciscoJSBarragan wants to merge 1 commit into
Graphify-Labs:v8from
FranciscoJSBarragan:fix/rebuild-deleted-cwd

Conversation

@FranciscoJSBarragan

Copy link
Copy Markdown

Summary

Fix detached rebuilds that inherit a deleted transient working directory before graphify can create graphify-out/.pending_changes or acquire the rebuild lock.

Problem

Post-commit/post-checkout hook rebuilds can run in a background process after the launcher CWD has disappeared. In that state, relative path setup such as graphify-out queue/lock creation can raise:

FileNotFoundError: [Errno 2] No such file or directory

This happens before the main rebuild body reaches the existing path/root handling.

Changes

  • Add _stabilize_rebuild_cwd() and call it at the start of _rebuild_code() before _queue_pending() / _rebuild_lock().
  • Recover by chdir'ing to GRAPHIFY_REPO_ROOT when hooks provide it.
  • Return False with a clear message if the CWD is gone and no repo-root fallback is available.
  • Add regression tests for both the clean-failure and repo-root recovery cases.

Validation

  • .venv/bin/pytest tests/test_watch.py -q54 passed, 2 skipped
  • .venv/bin/ruff check graphify/watch.py tests/test_watch.py → passed
  • .venv/bin/python -m py_compile graphify/watch.py tests/test_watch.py → passed
  • env -u PYTHONPATH -u PYTHONHOME PYTHONHASHSEED=0 .venv/bin/pytest -q2904 passed, 30 skipped

Note: running the full suite without PYTHONHASHSEED=0 exposed an unrelated ordering-sensitive labeling assertion ([100, 50, 100] vs [100, 100, 50]). With the deterministic hash seed already used by graphify hooks, the full suite passes.

What changed
- Stabilize relative rebuild execution before graphify-out queue/lock setup.
- Recover from deleted transient hook CWDs when GRAPHIFY_REPO_ROOT points at the repository root.
- Fail cleanly when the current working directory is gone and no repo root fallback is available.
- Add regression coverage for both fallback and clean-failure paths.

Why
- Detached post-commit/post-checkout rebuilds can inherit a transient CWD that is deleted before the background process starts.
- _rebuild_code previously used relative graphify-out paths before Path.cwd()/watch_path resolution could be handled, causing FileNotFoundError: [Errno 2] No such file or directory.

Validation
- .venv/bin/pytest tests/test_watch.py -q: 54 passed, 2 skipped.
- .venv/bin/ruff check graphify/watch.py tests/test_watch.py: passed.
- .venv/bin/python -m py_compile graphify/watch.py tests/test_watch.py: passed.
- env -u PYTHONPATH -u PYTHONHOME PYTHONHASHSEED=0 .venv/bin/pytest -q: 2904 passed, 30 skipped.

Notes
- Full suite without PYTHONHASHSEED=0 exposed an unrelated ordering-sensitive labeling test; with the deterministic hash seed used by graphify hooks, the suite passes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant