Repository navigation
fix(guard): don't refuse a write when dedup folded a saved node into a twin (#4940) - #4952
Deepjyoti-Sarmah wants to merge 4 commits into
Conversation
… a real loss (Graphify-Labs#4940) The guard compares saved semantic ids against the new graph. A fix for Graphify-Labs#4940 must excuse ids that entity dedup folded into a twin without excusing ids that are simply gone. These three cases pass today and fence the guard's existing job before it is touched: an update with nothing merged or lost writes; a saved node that vanished is refused and named; a re-extracted node dropped after the merge is refused.
…ify-Labs#4940) The write guard has to know whether a saved id disappeared because dedup folded it into a survivor or because the node was lost, and dedup is the only place that knows. Add an optional remap_out dict that is filled with {merged-away id: surviving id}. Callers that do not pass it see no change.
…abs#4940) build() passes remap_out to entity dedup and stashes the result on G.graph['_dedup_remap'], next to the existing _dedup_collapsed count. take_dedup_remap() reads and removes it. to_json drops it before node_link_data runs, because that would otherwise write G.graph into graph.json. Nothing reads the map yet.
…raphify-Labs#4940) to_json refused a valid --update when entity dedup merged a re-extracted node into a twin: the saved id was no longer in the new graph, so the Graphify-Labs#479 guard called it lost and the previous graph.json stayed on disk. Treat a saved id as present when dedup folded it into a survivor that is in the new graph. A survivor that is itself gone excuses nothing, so a real loss beside a merge is still refused and only it is named. The node-count check gets the same allowance, counting N merged ids as N - 1 when the survivor is new this run and N when it is a saved id. Full rebuilds were refused the same way and are fixed by the same change.
|
Thanks for the pull request, @Deepjyoti-Sarmah. 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. |
There was a problem hiding this comment.
Graphify reviewed this change.
Worth a look — the grounded gate found no coupling regressions or blocking issues, but 2 advisory finding(s) below merit a look before merge.
Not checked: tests were not run; formal verification proved 0 of 4 changed function(s) (2 sampled, not proven, 2 not verified).
Formal verification. PR-changed functions: 2/4 verified (0 proven, 2 may-equivalent, 0 distinguished) · 2 not verified (2 vacuous).
Not verified on this run: build (vacuous: never exercised), deduplicate\_entities (vacuous: never exercised).
Graphify review — findings
Fixes the #479 shrink guard refusing --update writes when entity dedup had folded saved nodes into a twin. deduplicate_entities now reports each {merged-away id: survivor id} pair through remap_out, build stashes that map on the graph, and to_json reads it and strips it before serialization. The lost-node check and the node-count check then both treat a saved id folded into a surviving node as one node rather than a loss, while a missing survivor still counts as lost. The count allowance from _dedup_shrink_allowance matches saved ids by exact membership, whereas the lost-node check tolerates renames, so the two can disagree. The remap is also consumed at the top of to_json, before the guard can refuse the write.
Worth a look
- to_json consumes dedup remap before a failed write —
graphify/export.py:310· Escalate · medium- NOT verified (no proof, no reproducing execution) — needs human review
- Shrink allowance uses exact id membership while the lost-node check tolerates renames —
graphify/build.py:191· Escalate · medium- NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 2226 functions depend on the 286 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
deduplicate_entities()— 121 callers, 32 callees - worse:
build_merge()— 104 callers, 16 callees - worse:
to_json()— 94 callers, 13 callees - worse:
build()— 90 callers, 6 callees - worse:
_lost_saved_semantic_nodes()— 19 callers, 6 callees - new:
_merge_and_write()— 9 callers, 4 callees
Verification — 2226 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: 1590 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
144 of 490 test file(s) selected (29%) via static blast radius.
tests/test_4874_jvm_resolution.py— impacttests/test_affected_cli.py— impacttests/test_affected_path_file_node.py— impacttests/test_affected_seed_reference_forms.py— impacttests/test_alias_folding.py— impacttests/test_analyze.py— impacttests/test_atomic_canvas_export.py— impacttests/test_atomic_writes.py— impacttests/test_backend_opt_in.py— impacttests/test_benchmark.py— impacttests/test_benchmark_raw_graph.py— impacttests/test_benchmark_real_query.py— impacttests/test_build.py— impacttests/test_build_located_semantic_identity.py— impacttests/test_build_merge_dedup_scope.py— impacttests/test_build_merge_hyperedges_and_prune.py— impacttests/test_build_merge_shrink_guard.py— impacttests/test_c_include_resolution.py— impacttests/test_carried_hyperedge_remap.py— impacttests/test_charmap_encoding.py— impacttests/test_chunking.py— impacttests/test_claude_cli_backend.py— impacttests/test_cli_export.py— impacttests/test_cluster.py— impacttests/test_community_labels_skill.py— impacttests/test_compact_graph_json.py— impacttests/test_confidence.py— impacttests/test_confidence_score_output.py— impacttests/test_corrupt_graph_json.py— impacttests/test_cpp_objc_cross_file_calls.py— impacttests/test_cross_extension_reexport_self_cycle.py— impacttests/test_cross_repo_external_call_guards.py— impacttests/test_csharp_method_owner_labels.py— impacttests/test_csharp_object_creation.py— impacttests/test_dedup.py— impacttests/test_dedup_remaps_hyperedges.py— impacttests/test_dedup_shrink_refuses_force_write.py— impacttests/test_dedup_survivor_richness.py— impacttests/test_definition_file_portability.py— impacttests/test_duplicate_annotation_edges.py— impacttests/test_edge_also_seen.py— impacttests/test_evidence_binding.py— impacttests/test_export.py— impacttests/test_export_control_characters.py— impacttests/test_export_direction.py— impacttests/test_export_idempotent_writes.py— impacttests/test_export_path_length.py— impacttests/test_ext_tagged_id_clash.py— impacttests/test_external_stub_endpoints.py— impacttests/test_extract.py— impact- … and 94 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.
Formal verification
No difference found (not proven): No behavior difference found in \_lost\_saved\_semantic\_nodes (not a proof).
The verifier ran both versions of \_lost\_saved\_semantic\_nodes 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.
Could not verify: Could not verify build.
The verifier did not have enough to check build, 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 9 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — names the real obstacle, not a sampling gap)
Could not verify: Could not verify deduplicate\_entities.
The verifier did not have enough to check deduplicate\_entities, 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 11 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)
No difference found (not proven): No behavior difference found in to\_json (not a proof).
The verifier ran both versions of to\_json 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.
· 2 grounded finding(s) anchored inline below; 4 more finding(s) on lines outside this diff (see the check run).
| @@ -303,7 +303,10 @@ def existing_graph_node_count(path: "str | Path"): | |||
| def to_json(G: nx.Graph, communities: dict[int, list[str]], output_path: str, *, force: bool = False, built_at_commit: str | None = None, community_labels: dict[int, str] | None = None, original_links: "list[dict] | None" = None) -> bool: | |||
There was a problem hiding this comment.
to_json()
fans out to 13 callees (efferent coupling); 94 callers depend on it (afferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
| to_json(G, {0: [n["id"] for n in nodes]}, str(path), force=True) | ||
|
|
||
|
|
||
| def _merge_and_write(tmp_path, saved, fresh, saved_edges=(), tamper=None): |
There was a problem hiding this comment.
_merge_and_write()
9 callers depend on it (afferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
|
Landed in 0.9.101 (published to PyPI), cherry-picked with your authorship preserved. Fixes #4940. Thanks @Deepjyoti-Sarmah. |
What does this PR do?
Fixes #4940.
The #479 write guard in
to_jsoncalls a saved node lost when its id is missing from the new graph. Entity dedup also removes ids. It folds a re-extracted node into a twin, and the content lives on under the twin's id. So an--updatethat re-extractedGLOSSARY.mdalone was refused, andgraph.jsonstayed stale. A full rebuild that merged the same twins was refused the same way.This change has dedup report which ids it merged away, carries that map to
to_json, and lets the guard count a merged id as present when its survivor is in the new graph:build_merge build - deduplicate_entities + deduplicate_entities(remap_out=remap) + G.graph["_dedup_remap"] = remap to_json + dedup_remap = take_dedup_remap(G) # also keeps it out of graph.json _lost_saved_semantic_nodes(saved, new) + saved id in remap and survivor in new graph -> not lost node-count check + allowance: N merged ids = N-1 if the survivor is new, N if it is savedA survivor that is itself gone excuses nothing. A real loss next to a merge is still refused, and only that id is named.
The node-count check needed the same allowance. When two saved ids merge into one survivor that is new this run, the count drops by one with nothing lost, and the id check alone still refused it.
Type of change
Evidence
Before: on
upstream/v8(32e5efe9), the issue's scenario.After:
The full suite ran serially with
PYTHONPATH=/var/tmp/wt-4940-fix, so subprocess CLI tests imported this worktree and not the installed package.Verification & Invariants
The invariant: the guard may refuse a write, but only when content is gone, never because an id was merged into a twin that is still there.
The tests assert on what reaches
graph.jsonand on whetherto_jsonwrote, so they hold for any fix of this bug. They pin:graph.json.I tried two other fixes against the same scenarios. Comparing against the pre-dedup node set turns the guard off, because
build_merge's input already holds every saved node. Keeping dedup from dropping ids thatgraph.jsonholds leaves the twins unmerged, and the next full rebuild hits the same refusal.Known limitations:
watch._check_shrinkhas its own copy of the guard. It works on dicts and has no graph to carry the map, so agraphify updatethat goes through it can still refuse a merge. That needs a separate change.--allow-dedup-shrink, Default dedup=True + force=True on every normal run leaves the #479 shrink guard permanently bypassed unless --no-dedup is known and passed #3774). It is not touched.How was this tested?
Branch
fix/4940-shrink-guard-dedup-mergeis based onupstream/v8(32e5efe9). It has four commits:Merge Danger
Door: Two-way.
The default path is unchanged when dedup merges nothing. No cache schema bump and no graph format change. Reverting restores the old guard.
Blast Radius: Write guard.
Every graph written through
to_jsonpasses this guard, so a mistake here either blocks a good write or lets a bad one through. The guard excuses an id only when its survivor is in the new graph, and the control tests pin the refusals. After merge, a graph that dedup has already shrunk by merging twins is written instead of refused, so an--updatethat was stuck on a stalegraph.jsonnow lands. Extraction, ignore rules and secret filtering are unchanged.Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. No source fragments changed.