Skip to content

fix(cluster-only): ensure output directory exists before writing report (#934) - #942

Closed
neo1777 wants to merge 1 commit into
Graphify-Labs:v8from
neo1777:fix/cluster-only-mkdir
Closed

neo1777 wants to merge 1 commit into
Graphify-Labs:v8from
neo1777:fix/cluster-only-mkdir

Conversation

@neo1777

@neo1777 neo1777 commented May 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #934.

What

Adds out.mkdir(parents=True, exist_ok=True) before the first write into out in the cluster-only codepath (graphify/__main__.py line 1827 on v8 HEAD).

Why

cluster-only crashes with FileNotFoundError when graphify-out/ doesn't exist at invocation — a natural state when archiving a previous run before re-clustering with new flags. The extract codepath creates out explicitly (line 2935); cluster-only assumed it existed, which is the asymmetry causing the bug.

The same pattern (mkdir(parents=True, exist_ok=True)) is already used at ~20 sites in the same file, so this fix aligns cluster-only with the rest of the codebase.

Manual verification

Reproduced the original crash and confirmed the fix on the same React/Firebase PWA codebase that surfaced #919 / #934 (full reproducer documented in #934).

Also ran the existing test suite locally with the fix applied:

  • 945 tests passed
  • The 8 failing SQL tests in test_multilang.py are pre-existing in my local environment (missing optional tree-sitter-sql dependency) and fail identically with the fix reverted, so unrelated to this change.

Tests

I held off adding a regression test specific to cluster-only because the codepath is currently invoked through the manual argparse-style parser in main() rather than a directly callable function, and I wasn't sure of the preferred pattern. Happy to add an end-to-end subprocess test, or to extract the codepath into a callable first if you prefer — let me know what would fit best.


First-time contributor — happy to iterate on anything.

@safishamsi

Copy link
Copy Markdown
Member

Great catch and a correct fix — thank you for the thorough write-up and for reproducing it.

We implemented this directly with two small improvements over the PR:

  1. Hoisted the mkdir earlier — moved it to right after out = watch_path / "graphify-out" (line 1810) so it runs before the labels_path.exists() read and any subsequent write, not just before the first write. This also ensures backup_if_protected always has a dir to operate on.

  2. Added the regression test you offered to write — an end-to-end subprocess test that archives graphify-out/, confirms the dir is gone, runs cluster-only --graph, and asserts GRAPH_REPORT.md lands correctly.

The fix will be in the next release. First-time contributor badge well earned — come back anytime.

@safishamsi safishamsi closed this May 20, 2026
@neo1777

neo1777 commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the quick turnaround, and for laying out the changes so clearly. Hoisting the mkdir right after the output path is computed is the better call — it covers backup_if_protected and the labels read, not just the first write.
Glad the reproducer and the write-up were useful. I'd like to look into the third option from #919 — the edge-weight-mode idea (inverse-degree edge weighting) — since exclude-hubs and edge-weighting tackle the super-hub problem from different angles. I'll dig into it properly and open it as a real PR with tests if it holds up. Thanks again.

@neo1777

neo1777 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Following up on the edge-weight idea above: I measured it on two codebases, and it gives no consistent gain over --resolution, so there's no PR for it. Numbers and method: #919 (comment).

@neo1777
neo1777 deleted the fix/cluster-only-mkdir branch October 1, 2026 09:02
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.

cluster-only crashes with FileNotFoundError if graphify-out/ doesn't exist before invocation

2 participants