Skip to content

fix(watch,cli): publish label sidecars atomically, labels before signatures - #3853

Closed
shashank-100 wants to merge 3 commits into
Graphify-Labs:v8from
shashank-100:fix/atomic-labels-sig-writes
Closed

shashank-100 wants to merge 3 commits into
Graphify-Labs:v8from
shashank-100:fix/atomic-labels-sig-writes

Conversation

@shashank-100

@shashank-100 shashank-100 commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem

_rebuild_code publishes graph.json atomically, then writes three sidecars with plain write_text:

graph_tmp.replace(existing_graph)          # atomic
report_path.write_text(report)             # not atomic
labels_file.write_text(labels_json)        # not atomic
sig_file.write_text(...)                   # not atomic

Each is truncated in place, so a crash, ENOSPC, or SIGKILL mid-write can publish a half-written sidecar. The staleness guard reads those signatures, so a torn .sig degrades label reuse to the count-based heuristic.

Fix

  • Publish both sidecars (and GRAPH_REPORT.md) with the existing paths.write_text_atomic helper — temp file in the same directory plus os.replace, with the symlink resolution and mode preservation the hand-rolled writes lacked.
  • Apply the same fix to the parallel writer in the graphify label path (cli.py:2332), which wrote its .sig with a bare Path.write_text while writing labels atomically. That is the path that actually produces LLM labels, and it feeds the same guard.

On write order

An earlier revision of this PR reordered the writes to put signatures first, arguing that it was the crash-safe direction. That was wrong, and it is worth stating plainly because it inverted the bug rather than fixing it. The guard is:

stale = {cid for cid in labels if saved_sigs.get(cid) != cur_sigs.get(cid)}

saved_sigs comes from the sidecar, cur_sigs is recomputed from the current clustering — the comparison never involves the labels. So a crash after the signatures and before the labels leaves a sidecar that already describes the new clustering sitting beside the old labels: the next rebuild recomputes the same signatures, finds them equal, reports nothing stale, and silently keeps names for a clustering that no longer exists.

Reproduced against that revision — the signature advanced, the label did not, and the recovery rebuild kept LLM-Name-0 with no community set changed since labeling warning.

Labels are written first, so an interruption leaves the sidecar trailing, which the guard sees as a mismatch and re-labels by hub. Both writers now use that order.

Test

test_rebuild_code_sidecar_writes_are_atomic_and_labels_first tracks os.replace, Path.write_text and a writing open() scoped to the live output directory, so it asserts observable behaviour rather than the helper's name. Against the pre-fix code it reports both sidecars as :non-atomic; against the signatures-first ordering it fails with saw ['sig', 'labels'].

(The open() hook is scoped to out/ deliberately: backup_if_protected copies the old sidecars into a dated backup folder via shutil.copy2 before the rebuild advances them, which is a copy of the previous file rather than a publish of the new one.)

Verification

tests/test_watch.py: 5 failed / 137 passed before, 5 failed / 138 passed after. -k "label or cluster": 21 failed / 220 passed before, 21 failed / 221 passed after. The failures are identical with and without the change — missing tree-sitter language grammars in this environment — and are present on a clean v8. CI is the real check for those.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RqZJxkPvMu7sNMeJLXtziE

@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 1 advisory finding(s) below merit a look before merge.


Graphify review — findings

Makes _rebuild_code publish the clustering sidecars atomically via write_text_atomic (temp file + rename) and writes the .sig fingerprints before labels.json. This inverts the failure mode of an interrupted rebuild: signatures ahead of labels reads as stale and gets refreshed, whereas the old order left labels advanced against matching-but-outdated signatures, silently keeping stale cluster names.

Worth a look

  • Publishes signature marker before the labels it validates — graphify/watch.py:2059 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 570 functions depend on the 394 functions this change touches.

Health — this change adds coupling hotspots:

  • new: _rebuild_code() — 114 callers, 51 callees
  • new: dispatch_command() — 2 callers, 123 callees
  • new: watch() — 5 callers, 7 callees
  • new: _reconcile_graph_html() — 6 callers, 5 callees
  • new: _reconcile_existing_graph() — 1 callers, 8 callees
  • new: _reconcile_markdown_links() — 1 callers, 6 callees
  • new: test_poisoned_manifest_is_healed() — 0 callers, 6 callees

Verification — 570 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: 406 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

3 of 244 test file(s) selected (1%) via static blast radius.

  • tests/test_labeling.py — impact
  • tests/test_watch.py — impact, changed-test
  • tests/test_watch_manifest_location.py — impact

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.

· 7 more finding(s) on lines outside this diff (see the check run).

@shashank-100 shashank-100 changed the title fix(watch): write label sidecars atomically, signatures before labels fix(watch,cli): publish label sidecars atomically, labels before signatures Sep 26, 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.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).


Graphify review — findings

Makes the community-label and membership-signature sidecar writes atomic (temp + rename) in both _rebuild_code and the CLI cluster path, so a crash mid-write can't publish a half-written sidecar—a torn one is unparseable and the staleness guard falls back to the count heuristic. Enforces writing labels.json before its .sig sidecar, since the guard compares saved signatures against ones recomputed from the current clustering; publishing signatures first would leave a matching sidecar beside stale labels that the guard reads as "nothing changed" and silently keeps outdated names.

No blocking issues surfaced.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 665 functions depend on the 449 functions this change touches.

Health — this change adds coupling hotspots:

  • new: _rebuild_code() — 114 callers, 51 callees
  • new: dispatch_command() — 2 callers, 124 callees
  • new: _stale_graph_sources() — 7 callers, 6 callees
  • new: watch() — 5 callers, 7 callees
  • new: _run_hook_guard() — 4 callers, 8 callees
  • new: _reconcile_graph_html() — 6 callers, 5 callees
  • new: _reconcile_existing_graph() — 1 callers, 8 callees
  • new: _reconcile_markdown_links() — 1 callers, 6 callees
  • …and 1 more — each is listed as a finding

Verification — 665 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: 611 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

26 of 244 test file(s) selected (11%) via static blast radius.

  • tests/test_affected_cli.py — impact
  • tests/test_agents_platform.py — impact
  • tests/test_codebuddy.py — impact
  • tests/test_devin.py — impact
  • tests/test_explain_cli.py — impact
  • tests/test_extract_cli.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_install.py — impact
  • tests/test_install_references.py — impact
  • tests/test_labeling.py — impact
  • tests/test_merge_chunks_validation.py — impact
  • tests/test_multigraph_diagnostics.py — impact
  • tests/test_no_dedup_flag.py — impact
  • tests/test_partial_cache.py — impact
  • tests/test_path_cli.py — impact
  • tests/test_query_cli.py — impact
  • tests/test_query_induced_edges.py — impact
  • tests/test_stale_prune.py — impact
  • tests/test_unverified_semantic_shrink.py — impact
  • tests/test_watch.py — impact, changed-test
  • tests/test_watch_manifest_location.py — impact

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.

· 9 more finding(s) on lines outside this diff (see the check run).

@shashank-100
shashank-100 force-pushed the fix/atomic-labels-sig-writes branch from dd914d5 to 7a8ebce Compare September 26, 2026 14:06

@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.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Formal verification. 1 change(s) tested, no difference found (not proven).


Graphify review — findings

Makes both the code rebuild and the cluster-only CLI path write the labels file and its .sig membership sidecar atomically (temp + rename) instead of truncating in place, so a kill mid-write can never publish a half-written, unparseable sidecar. Enforces writing labels before the signature sidecar in _rebuild_code and dispatch_command, since publishing signatures first and crashing would leave a sidecar describing the new clustering beside old labels — which the staleness guard recomputes as matching and silently keeps stale names. Also trims the CI matrix to Python 3.10 and 3.12.

No blocking issues surfaced.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 742 functions depend on the 508 functions this change touches.

Health — this change adds coupling hotspots:

  • new: _rebuild_code() — 145 callers, 56 callees
  • new: main() — 98 callers, 3 callees
  • new: dispatch_command() — 2 callers, 126 callees
  • new: _stale_graph_sources() — 7 callers, 6 callees
  • new: watch() — 5 callers, 7 callees
  • new: _run_hook_guard() — 4 callers, 8 callees
  • new: _reconcile_graph_html() — 6 callers, 5 callees
  • new: _reconcile_existing_graph() — 1 callers, 8 callees
  • …and 2 more — each is listed as a finding

Verification — 742 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: 680 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

302 of 302 test file(s) selected (100%) via static blast radius.

Escalated to a full run for safety — the selection is not trustworthy on its own (see below). CI should run the whole suite.

  • tests/test_affected_cli.py — impact, full-run-safety
  • tests/test_affected_member_seed.py — full-run-safety
  • tests/test_agents_platform.py — impact, full-run-safety
  • tests/test_analyze.py — full-run-safety
  • tests/test_anthropic_custom_endpoint.py — full-run-safety
  • tests/test_antigravity_install.py — full-run-safety
  • tests/test_apm_fallback_version.py — full-run-safety
  • tests/test_architecture_doc.py — full-run-safety
  • tests/test_astro_extraction.py — full-run-safety
  • tests/test_astro_import_ids.py — full-run-safety
  • tests/test_atomic_canvas_export.py — full-run-safety
  • tests/test_atomic_version_stamp.py — full-run-safety
  • tests/test_atomic_writes.py — full-run-safety
  • tests/test_backend_env_isolation.py — full-run-safety
  • tests/test_backend_extras.py — full-run-safety
  • tests/test_benchmark.py — full-run-safety
  • tests/test_benchmark_raw_graph.py — full-run-safety
  • tests/test_build.py — full-run-safety
  • tests/test_build_merge_dedup_scope.py — full-run-safety
  • tests/test_build_merge_hyperedges_and_prune.py — full-run-safety
  • tests/test_build_merge_shrink_guard.py — full-run-safety
  • tests/test_builtin_global_type_refs.py — full-run-safety
  • tests/test_cache.py — full-run-safety
  • tests/test_callflow_html.py — full-run-safety
  • tests/test_cargo_introspect.py — full-run-safety
  • tests/test_cargo_missing_manifest.py — full-run-safety
  • tests/test_carried_hyperedge_remap.py — full-run-safety
  • tests/test_case_sensitive_resolution.py — full-run-safety
  • tests/test_charmap_encoding.py — full-run-safety
  • tests/test_chunking.py — full-run-safety
  • tests/test_cjs_module_extension.py — full-run-safety
  • tests/test_claude_cli_backend.py — full-run-safety
  • tests/test_claude_md.py — full-run-safety
  • tests/test_cli_broken_pipe.py — full-run-safety
  • tests/test_cli_export.py — full-run-safety
  • tests/test_cli_help.py — full-run-safety
  • tests/test_cluster.py — full-run-safety
  • tests/test_cobol_extractor.py — full-run-safety
  • tests/test_codebuddy.py — impact, full-run-safety
  • tests/test_community_hub_labels.py — full-run-safety
  • tests/test_community_labels_skill.py — full-run-safety
  • tests/test_confidence.py — full-run-safety
  • tests/test_corrupt_graph_json.py — full-run-safety
  • tests/test_cpp_nested_and_cli.py — full-run-safety
  • tests/test_cpp_objc_cross_file_calls.py — full-run-safety
  • tests/test_cpp_preprocess.py — full-run-safety
  • tests/test_cross_extension_reexport_self_cycle.py — full-run-safety
  • tests/test_cross_language_call_resolution.py — full-run-safety
  • tests/test_cross_repo_external_call_guards.py — full-run-safety
  • tests/test_cross_repo_member_calls.py — full-run-safety
  • … and 252 more

non-code file(s) changed (.github/workflows/ci.yml) → running the full suite for safety (a code graph can't see config/fixture/data deps)

changed code file(s) with no mapped test (.github/workflows/ci.yml) — a coverage gap or a missing link — running the full suite rather than only the selected tests

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.

Formal verification

Could not verify: Could not verify dispatch\_command.

The verifier did not have enough to check dispatch\_command, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 23 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly SystemExit — names the real obstacle, not a sampling gap)

No difference found (not proven): No behavior difference found in \_rebuild\_code (not a proof).

The verifier ran both versions of \_rebuild\_code on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

· 10 more finding(s) on lines outside this diff (see the check run).

@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.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Formal verification. 1 change(s) tested, no difference found (not proven).


Graphify review — findings

Makes label-sidecar publishing crash-safe in both the watch rebuild (_rebuild_code) and the cluster-only CLI path (dispatch_command): the report, labels.json, and its .sig are now written via write_text_atomic (temp + rename) instead of truncate-in-place, and labels always land before the signature sidecar so an interrupted run leaves a trailing sidecar the staleness guard reads as a mismatch and re-labels, rather than a signatures-first sidecar that matches the new clustering beside stale names and passes silently. Adds test_rebuild_code_sidecar_writes_are_atomic_and_labels_first, which tracks os.replace/open calls to assert every sidecar is renamed rather than written in place and that labels precede signatures. Trims the CI Python matrix to 3.10 and 3.12.

No blocking issues surfaced.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 742 functions depend on the 508 functions this change touches.

Health — this change adds coupling hotspots:

  • new: _rebuild_code() — 145 callers, 56 callees
  • new: main() — 98 callers, 3 callees
  • new: dispatch_command() — 2 callers, 126 callees
  • new: _stale_graph_sources() — 7 callers, 6 callees
  • new: watch() — 5 callers, 7 callees
  • new: _run_hook_guard() — 4 callers, 8 callees
  • new: _reconcile_graph_html() — 6 callers, 5 callees
  • new: _reconcile_existing_graph() — 1 callers, 8 callees
  • …and 2 more — each is listed as a finding

Verification — 742 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: 680 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

302 of 302 test file(s) selected (100%) via static blast radius.

Escalated to a full run for safety — the selection is not trustworthy on its own (see below). CI should run the whole suite.

  • tests/test_affected_cli.py — impact, full-run-safety
  • tests/test_affected_member_seed.py — full-run-safety
  • tests/test_agents_platform.py — impact, full-run-safety
  • tests/test_analyze.py — full-run-safety
  • tests/test_anthropic_custom_endpoint.py — full-run-safety
  • tests/test_antigravity_install.py — full-run-safety
  • tests/test_apm_fallback_version.py — full-run-safety
  • tests/test_architecture_doc.py — full-run-safety
  • tests/test_astro_extraction.py — full-run-safety
  • tests/test_astro_import_ids.py — full-run-safety
  • tests/test_atomic_canvas_export.py — full-run-safety
  • tests/test_atomic_version_stamp.py — full-run-safety
  • tests/test_atomic_writes.py — full-run-safety
  • tests/test_backend_env_isolation.py — full-run-safety
  • tests/test_backend_extras.py — full-run-safety
  • tests/test_benchmark.py — full-run-safety
  • tests/test_benchmark_raw_graph.py — full-run-safety
  • tests/test_build.py — full-run-safety
  • tests/test_build_merge_dedup_scope.py — full-run-safety
  • tests/test_build_merge_hyperedges_and_prune.py — full-run-safety
  • tests/test_build_merge_shrink_guard.py — full-run-safety
  • tests/test_builtin_global_type_refs.py — full-run-safety
  • tests/test_cache.py — full-run-safety
  • tests/test_callflow_html.py — full-run-safety
  • tests/test_cargo_introspect.py — full-run-safety
  • tests/test_cargo_missing_manifest.py — full-run-safety
  • tests/test_carried_hyperedge_remap.py — full-run-safety
  • tests/test_case_sensitive_resolution.py — full-run-safety
  • tests/test_charmap_encoding.py — full-run-safety
  • tests/test_chunking.py — full-run-safety
  • tests/test_cjs_module_extension.py — full-run-safety
  • tests/test_claude_cli_backend.py — full-run-safety
  • tests/test_claude_md.py — full-run-safety
  • tests/test_cli_broken_pipe.py — full-run-safety
  • tests/test_cli_export.py — full-run-safety
  • tests/test_cli_help.py — full-run-safety
  • tests/test_cluster.py — full-run-safety
  • tests/test_cobol_extractor.py — full-run-safety
  • tests/test_codebuddy.py — impact, full-run-safety
  • tests/test_community_hub_labels.py — full-run-safety
  • tests/test_community_labels_skill.py — full-run-safety
  • tests/test_confidence.py — full-run-safety
  • tests/test_corrupt_graph_json.py — full-run-safety
  • tests/test_cpp_nested_and_cli.py — full-run-safety
  • tests/test_cpp_objc_cross_file_calls.py — full-run-safety
  • tests/test_cpp_preprocess.py — full-run-safety
  • tests/test_cross_extension_reexport_self_cycle.py — full-run-safety
  • tests/test_cross_language_call_resolution.py — full-run-safety
  • tests/test_cross_repo_external_call_guards.py — full-run-safety
  • tests/test_cross_repo_member_calls.py — full-run-safety
  • … and 252 more

non-code file(s) changed (.github/workflows/ci.yml) → running the full suite for safety (a code graph can't see config/fixture/data deps)

changed code file(s) with no mapped test (.github/workflows/ci.yml) — a coverage gap or a missing link — running the full suite rather than only the selected tests

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.

Formal verification

Could not verify: Could not verify dispatch\_command.

The verifier did not have enough to check dispatch\_command, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 23 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly SystemExit — names the real obstacle, not a sampling gap)

No difference found (not proven): No behavior difference found in \_rebuild\_code (not a proof).

The verifier ran both versions of \_rebuild\_code on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

· 10 more finding(s) on lines outside this diff (see the check run).

safishamsi pushed a commit that referenced this pull request Sep 29, 2026
…atures

Publish the community-label and signature sidecars via the existing
atomic write helper and write labels before the .sig, so an interruption
between the two leaves the .sig trailing (which the staleness guard reads
as a mismatch and safely re-labels) rather than silently keeping stale
labels for a clustering that no longer exists.

Cherry-picked from #3853 by @shashank-100; the unrelated CI-matrix change
(dropping Python 3.13/3.14) in that PR was omitted.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
safishamsi added a commit that referenced this pull request Sep 29, 2026
Atomic label sidecars (#3853), docx table/all-text extraction (#3833),
wiki index-collision (#3818) and escaped wikilink aliases (#3772),
community-listing real-node filter (#3836), warn-once on missing pypdf
extra (#3710), plus the --help logo banner + app.graphify.com line.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.72 (now on PyPI) via an authorship-preserving cherry-pick, so your commit keeps contributor-graph credit. Thanks @shashank-100! Label/signature sidecars published atomically, labels before signatures. (The unrelated CI-matrix change was omitted on land.)

Release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.72

@safishamsi safishamsi closed this Sep 29, 2026
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.

2 participants