Skip to content

Wire --no-viz flag in cluster-only + GRAPHIFY_VIZ_NODE_LIMIT env var (closes #541) - #565

Merged
safishamsi merged 2 commits into
Graphify-Labs:v5from
market4drill:fix/no-viz-cluster-only-and-env-var
May 2, 2026
Merged

safishamsi merged 2 commits into
Graphify-Labs:v5from
market4drill:fix/no-viz-cluster-only-and-env-var

Conversation

@market4drill

Copy link
Copy Markdown

Summary

Closes #541 by exposing both APIs the reporter proposed:

Also fixes a related crash: cluster-only previously called to_html() unconditionally, so on graphs >5000 nodes the ValueError fired after graph.json was written but before the final "Done — …" line, leaving a stale graph.html on disk and no clear signal in CLI output. This mirrors the existing watch.py rebuild pattern (try/except + delete stale html).

Repro of the cluster-only crash

# On any repo whose graph.json contains >5000 nodes:
graphify cluster-only .

Before:

Loading existing graph...
Graph: 8881 nodes, 10829 edges
Re-clustering...
Traceback (most recent call last):
  ...
ValueError: Graph has 8881 nodes - too large for HTML viz. Use --no-viz or reduce input size.
# graph.json fresh, GRAPH_REPORT.md fresh, graph.html stale, no "Done" line

After (default):

Loading existing graph...
Graph: 8881 nodes, 10829 edges
Re-clustering...
Skipped graph.html: Graph has 8881 nodes - too large for HTML viz (limit: 5000). Use --no-viz, raise GRAPHIFY_VIZ_NODE_LIMIT, or reduce input size.
Done — 741 communities. GRAPH_REPORT.md and graph.json updated.

With --no-viz:

Done — 741 communities. GRAPH_REPORT.md and graph.json updated (--no-viz; graph.html removed).

With GRAPHIFY_VIZ_NODE_LIMIT=10000:

Done — 741 communities. GRAPH_REPORT.md, graph.json and graph.html updated.

Out of scope (intentionally)

  • graphify hook install --no-viz (the original Expose --no-viz flag and/or GRAPHIFY_VIZ_NODE_LIMIT env var #541 reporter's option 1): the hook script invokes _rebuild_code() from watch.py, which already has the try/except guard. So hook users on v5 are implicitly safe from the crash, and the env var lets them tune the limit globally. A dedicated hook install --no-viz flag could be added in a follow-up if you'd like a more explicit knob — happy to do it.
  • argparse refactor of __main__.py: would be cleaner than the ad-hoc sys.argv slicing, but is a larger change that deserves its own PR.

Tests

tests/test_export.py gains 7 tests (all green together with the existing 13):

  • test_viz_node_limit_default — unset env var falls back to MAX_NODES_FOR_VIZ
  • test_viz_node_limit_env_override_higher — =20000 raises the cap
  • test_viz_node_limit_env_override_zero_disables — =0 disables viz
  • test_viz_node_limit_invalid_falls_back_to_default — non-integer is ignored
  • test_viz_node_limit_empty_falls_back_to_default — whitespace/empty is ignored
  • test_to_html_raises_with_lowered_limit — end-to-end ValueError with =1
  • test_to_html_writes_with_raised_limit — end-to-end success with =100000

Run with: pytest tests/test_export.py -v

Compatibility

  • Backward compatible. Default behavior unchanged (MAX_NODES_FOR_VIZ = 5_000, to_html still raises ValueError).
  • No new dependencies.
  • One private symbol added to graphify.export: _viz_node_limit (underscore-prefixed; tests import it for direct unit coverage).

Verified against

  • graphify cluster-only . on a real 8881-node graph (a polyglot Flutter + Postgres + n8n repo): all three exit paths (default, --no-viz, env var override) produce the expected output and artifact mtimes.

QponCoin and others added 2 commits April 27, 2026 11:00
…OR_VIZ

Adds opt-in env var so users with large graphs (>5000 nodes) can either
raise the HTML viz limit or disable viz entirely (set to 0) without
patching the package.

- New _viz_node_limit() helper reads GRAPHIFY_VIZ_NODE_LIMIT, falls back
  to MAX_NODES_FOR_VIZ on unset/empty/non-integer values.
- to_html() now uses the helper; ValueError message references both
  --no-viz and GRAPHIFY_VIZ_NODE_LIMIT for discoverability.
- 7 new tests in test_export.py covering default, raise/lower, zero,
  invalid, empty, and end-to-end to_html behavior.

Addresses option 2 in Graphify-Labs#541 (env var as default behavior, zero-config
for most users, tunable for large repos.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
EOF
)
Before this change, `graphify cluster-only <path>` called to_html()
unconditionally, so on graphs >5000 nodes the ValueError fired AFTER
graph.json was written but BEFORE the "Done — ..." print, leaving a
stale graph.html on disk and no clear signal in the CLI output.

This mirrors the watch.py rebuild pattern (already merged): try/except
around to_html, delete the stale graph.html when skipping, and emit a
"Done" line that accurately reflects which artifacts landed.

- Parse "--no-viz" from sys.argv (documented as such in skill.md but
  previously never wired into the Python CLI).
- Wrap to_html() in try/except so core outputs (graph.json +
  GRAPH_REPORT.md) always land.
- Remove stale graph.html when viz is skipped or fails — avoids the
  silent desync where graph.html lags behind graph.json by days.
- Update help text under `cluster-only` to advertise --no-viz.

Addresses option 1 in Graphify-Labs#541 (--no-viz flag, simplest opt-in).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@Qodo-Free-For-OSS

Copy link
Copy Markdown

Hi, In graphify.__main__.main() for cluster-only, watch_path is always taken from sys.argv[2], so graphify cluster-only --no-viz . interprets --no-viz as the path and fails to find graphify-out/graph.json. This makes the new flag order-sensitive and can cause immediate command failure with a confusing error message.

Severity: action required | Category: correctness

How to fix: Parse cluster-only args properly

Agent prompt to fix - you can give this to your LLM of choice:

Issue description

graphify cluster-only uses sys.argv[2] as the path unconditionally, so putting --no-viz before the path breaks the command.

Issue Context

--no-viz is now supported for cluster-only, but the current parsing is not robust to flag ordering.

Fix Focus Areas

  • graphify/main.py[1372-1376]

Recommended fix

Use argparse (preferred) for the cluster-only subcommand:

  • positional path with default .
  • optional --no-viz boolean flag
    This will correctly handle both graphify cluster-only . --no-viz and graphify cluster-only --no-viz ..

If you want to avoid argparse here, manually parse sys.argv[2:] to:

  • detect and remove --no-viz
  • treat the first remaining non-flag token as the path (or default to .).

We noticed a couple of other issues in this PR as well - happy to share if helpful.


Found by Qodo code review. FYI, Qodo is free for open-source.

@safishamsi
safishamsi merged commit 6c9b5ef into Graphify-Labs:v5 May 2, 2026
@safishamsi

Copy link
Copy Markdown
Member

Fixed in v0.6.6. Available on PyPI: pip install graphifyy==0.6.6

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.

Expose --no-viz flag and/or GRAPHIFY_VIZ_NODE_LIMIT env var

4 participants