Skip to content

feat: preserve clustering settings across rebuilds - #4421

Open
oleksii-tumanov wants to merge 3 commits into
Graphify-Labs:v8from
oleksii-tumanov:feat/persist-clustering-settings
Open

oleksii-tumanov wants to merge 3 commits into
Graphify-Labs:v8from
oleksii-tumanov:feat/persist-clustering-settings

Conversation

@oleksii-tumanov

Copy link
Copy Markdown
Contributor

What does this PR do?

After tuning a graph with cluster-only --exclude-hubs 90 --resolution 2.5, the next watch or hook rebuild currently uses the defaults again. This change saves explicitly chosen settings beside that graph and reuses them whenever update, watch, or a hook needs to recluster it.

cluster-only and clustered extract use explicit flags first, then saved values, then the existing defaults. With extract --out or a graph selected from another graphify-out directory, settings stay with that output. Fixes #1800.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

The two settings are stored in the existing .graphify_build.json. Explicit values are saved only after the core graph outputs succeed. Invalid flags fail before writes; if a config write reports an error, the actual file is checked before reporting whether settings were saved.

An update with unchanged topology still skips reclustering. Generated /graphify Step 4 can therefore leave a default partition while custom settings remain stored; run cluster-only on that output to reapply them immediately. Graph and config writes are not one transaction, and concurrent writers to the same output remain unsupported.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

How was this tested?

  • uv sync --all-extras --frozen
  • uv run --frozen pytest tests/ -q --tb=short: 7930 passed, 15 skipped.
  • uv run --frozen ruff check .: passed.
  • uv run --frozen python -m tools.skillgen --check: all 134 generated artifacts match.
  • uv run --frozen graphify update .: passed.
  • .venv/bin/pyright --pythonpath .venv/bin/python: 638 errors on both the base and this branch, with no added or removed diagnostics.

The tests cover saved settings, custom outputs, invalid flags, unchanged topology, and config-write failures. An earlier full run failed the watcher config-deletion test; it passed alone on both the base and this branch, and the unchanged full-suite rerun passed.

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (Not applicable: no source fragments changed; --check passed.)
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

Keep explicitly chosen clustering settings with the graph so later reclustering uses the same choices. Refs Graphify-Labs#1800.

AI-Assistance: OpenAI Codex
Handle overflow values during write-failure readback, preserve the previous config when serialization fails, and cover default-partition restoration.

AI-Assistance: OpenAI Codex
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @oleksii-tumanov. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Oct 13, 2026

@graphify-labs graphify-labs Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 4 advisory finding(s) below merit a look before merge.

Not checked: tests were not run; no formal proof of the changed code.


Graphify review — findings

Persists --resolution and --exclude-hubs in .graphify_build.json after a successful cluster-only or extract run, so later rebuilds reuse them. Settings now resolve from explicit flags first, then saved values, then defaults, and a --graph pointing into another graphify-out reads that directory's config. Flags are validated up front (finite, resolution > 0, percentile 0–100, value required; exit 2 otherwise); unreadable config exits 1, and --no-cluster warns and skips adoption.

Worth a look

  • --no-cluster still adopts clustering flags despite warning that they were not adopted — graphify/cli.py:5165 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • Rebuild now crashes on an undecodable or unreadable build config instead of falling back to defaults — graphify/watch.py:166 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • Non-atomic config write lets a concurrent rebuild silently use default clustering — graphify/watch.py:255 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • _read_build_config accepts overflow JSON numbers as non-finite floats — graphify/watch.py:156 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review

Review partial — this diff was larger than one review pass covers, so later files were not reviewed; some findings may be missing.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 1051 functions depend on the 724 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: _rebuild_code() — 179 callers, 60 callees
  • worse: dispatch_command() — 2 callers, 135 callees
  • worse: _make_graph() — 40 callers, 6 callees
  • new: _adopt_cluster_settings() — 5 callers, 4 callees

Verification — 1051 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 1006 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

58 of 412 test file(s) selected (14%) via static blast radius.

  • tests/test_affected_cli.py — impact
  • tests/test_agents_platform.py — impact
  • tests/test_cache_stale_import_target.py — impact
  • tests/test_cli_export.py — impact, changed-test
  • tests/test_cloud_cta.py — impact
  • tests/test_codebuddy.py — impact
  • tests/test_compact_graph_json.py — impact
  • tests/test_dedup_shrink_refuses_force_write.py — impact
  • tests/test_devin.py — impact
  • tests/test_elixir_import_resolution.py — impact
  • tests/test_elixir_qualified_calls.py — impact
  • tests/test_elixir_unqualified_call_scope.py — impact
  • tests/test_explain_cli.py — impact
  • tests/test_explain_same_file_tie.py — impact
  • tests/test_export_direction.py — impact
  • tests/test_external_stub_endpoints.py — impact
  • tests/test_extract_cli.py — impact
  • tests/test_extract_code_only_cli.py — impact, changed-test
  • tests/test_global_add_tag_inference.py — impact
  • tests/test_god_nodes_cli.py — impact
  • tests/test_hollow_chunks_arm_shrink_guard.py — impact
  • tests/test_hook_guard_token_match.py — impact
  • tests/test_hook_out_of_project_paths.py — impact
  • tests/test_hook_strict.py — impact
  • tests/test_incomplete_build_guard.py — impact
  • tests/test_incremental_unscanned_placeholders.py — impact
  • tests/test_install.py — impact
  • tests/test_install_references.py — impact
  • tests/test_java_member_calls.py — impact
  • tests/test_kotlin_grammar.py — impact
  • tests/test_labeling.py — impact
  • tests/test_language_override_lifecycle.py — impact
  • tests/test_lookup_exit_codes.py — impact
  • tests/test_lost_saved_semantic_nodes.py — impact
  • tests/test_markdown_code_spans.py — impact
  • tests/test_merge_chunks_validation.py — impact
  • tests/test_multigraph_diagnostics.py — impact
  • tests/test_no_cluster_undeclared_endpoints.py — impact
  • tests/test_no_dedup_flag.py — impact
  • tests/test_opencode_plugin_refresh.py — impact
  • tests/test_partial_cache.py — impact
  • tests/test_path_cli.py — impact
  • tests/test_pr10_watch_overrides.py — impact
  • tests/test_python_inherited_method_calls.py — impact
  • tests/test_python_property_reads.py — impact
  • tests/test_query_cli.py — impact
  • tests/test_query_induced_edges.py — impact
  • tests/test_query_seeds.py — impact
  • tests/test_rust_use_trees.py — impact
  • tests/test_skill_auto_refresh.py — impact
  • … and 8 more

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Docs that may be stale (advisory)

…and 10 more.

· 1 grounded finding(s) anchored inline below; 3 more finding(s) on lines outside this diff (see the check run).

Comment thread graphify/watch.py
return values["cluster_resolution"], values["cluster_exclude_hubs_percentile"]


def _adopt_cluster_settings(out_dir: Path, explicit: dict) -> str:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Health regression — _adopt_cluster_settings()

high coupling complexity (Ca·Ce = 20).

Grounded coupling-delta finding (deterministic), not an LLM guess.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: let the git-hook/watch rebuild honor a persisted clustering config (exclude-hubs)

1 participant