Repository navigation
fix(dedup): give a real source location priority over richness in pick_winner - #3786
ayushcodes10 wants to merge 9 commits into
Conversation
source_file and source_location are both in the set of keys the richness score deliberately ignores, since Graphify-Labs#3372 added that score to compare actual content, not placement. That leaves richness with no way to tell a real, located declaration apart from a source less stub that happens to carry a couple of incidental bookkeeping keys, letting the stub out score and replace the genuine record purely on field count. Provenance is now checked ahead of richness in the survivor scoring tuple, so a node with a real source location always wins over one without. This only changes the outcome when the two sides actually disagree on provenance; every case where both, or neither, side carries a source file keeps the exact ordering the richness fix already established. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_017qfdzgbA5KedGEjD1AayNh
One test is the issue's own exact reproduction, a source less stub that genuinely out scores a real located declaration on field count alone, checked in both argument orders. A companion test confirms the provenance tiebreak stays inert when both candidates carry a source file, so the existing richness then length ordering this file already established is untouched. The first test was checked against the pre fix code and failed there as expected. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_017qfdzgbA5KedGEjD1AayNh
Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_017qfdzgbA5KedGEjD1AayNh
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 1 advisory finding(s) below merit a look before merge.
Graphify review — findings
Adds a provenance tiebreak to dedup's survivor selection so _pick_winner prefers a node with a real source_file over a source-less stub, checked ahead of _content_richness() and behind the existing chunk-suffix check. This fixes cases where a stub carrying incidental keys (external/type/_origin) out-scored a genuine located declaration on field count alone (#3775); when both or neither side has a source file, the prior richness-then-ID-length ordering is unchanged.
Worth a look
- Provenance winner check ignores source_location —
graphify/dedup.py:1098· 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 — 666 functions depend on the 288 functions this change touches.
Health — this change adds coupling hotspots:
- new:
deduplicate_entities()— 77 callers, 24 callees - new:
build_merge()— 76 callers, 14 callees - new:
build()— 52 callers, 6 callees - new:
main()— 98 callers, 3 callees - new:
dispatch_command()— 2 callers, 125 callees - new:
_prune()— 9 callers, 3 callees - new:
_llm_tiebreak()— 1 callers, 10 callees - new:
test_poisoned_manifest_is_healed()— 0 callers, 6 callees
Verification — 666 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: 435 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
298 of 298 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— full-run-safetytests/test_affected_member_seed.py— full-run-safetytests/test_agents_platform.py— full-run-safetytests/test_analyze.py— full-run-safetytests/test_anthropic_custom_endpoint.py— full-run-safetytests/test_antigravity_install.py— full-run-safetytests/test_apm_fallback_version.py— full-run-safetytests/test_architecture_doc.py— full-run-safetytests/test_astro_extraction.py— full-run-safetytests/test_astro_import_ids.py— full-run-safetytests/test_atomic_canvas_export.py— full-run-safetytests/test_atomic_version_stamp.py— full-run-safetytests/test_atomic_writes.py— full-run-safetytests/test_backend_env_isolation.py— full-run-safetytests/test_backend_extras.py— full-run-safetytests/test_benchmark.py— full-run-safetytests/test_benchmark_raw_graph.py— full-run-safetytests/test_build.py— impact, full-run-safetytests/test_build_merge_dedup_scope.py— impact, full-run-safetytests/test_build_merge_hyperedges_and_prune.py— impact, full-run-safetytests/test_build_merge_shrink_guard.py— impact, full-run-safetytests/test_builtin_global_type_refs.py— full-run-safetytests/test_cache.py— full-run-safetytests/test_callflow_html.py— full-run-safetytests/test_cargo_introspect.py— full-run-safetytests/test_cargo_missing_manifest.py— full-run-safetytests/test_carried_hyperedge_remap.py— impact, full-run-safetytests/test_case_sensitive_resolution.py— full-run-safetytests/test_charmap_encoding.py— full-run-safetytests/test_chunking.py— full-run-safetytests/test_cjs_module_extension.py— full-run-safetytests/test_claude_cli_backend.py— full-run-safetytests/test_claude_md.py— full-run-safetytests/test_cli_broken_pipe.py— full-run-safetytests/test_cli_export.py— full-run-safetytests/test_cli_help.py— full-run-safetytests/test_cluster.py— full-run-safetytests/test_cobol_extractor.py— full-run-safetytests/test_codebuddy.py— full-run-safetytests/test_community_hub_labels.py— full-run-safetytests/test_community_labels_skill.py— full-run-safetytests/test_confidence.py— full-run-safetytests/test_corrupt_graph_json.py— impact, full-run-safetytests/test_cpp_nested_and_cli.py— full-run-safetytests/test_cpp_objc_cross_file_calls.py— full-run-safetytests/test_cpp_preprocess.py— full-run-safetytests/test_cross_extension_reexport_self_cycle.py— impact, full-run-safetytests/test_cross_language_call_resolution.py— full-run-safetytests/test_cross_repo_external_call_guards.py— full-run-safetytests/test_cross_repo_member_calls.py— full-run-safety- … and 248 more
non-code file(s) changed (
CHANGELOG.md) → running the full suite for safety (a code graph can't see config/fixture/data deps)
changed code file(s) with no mapped test (
CHANGELOG.md) — 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.
· 8 more finding(s) on lines outside this diff (see the check run).
source_location is richness ignored the same way source_file already is, so two candidates that both carry a source_file could still be ordered by field count alone, letting a record with no real location out score one that also knows exactly where in the file it lives. The codebase genuinely emits source_location as None on some records, so this is a real distinction, not a hypothetical one. The tiebreak now checks source_location as a second provenance step, after source_file and before richness, and only changes the outcome when the two sides disagree on having one. Fixes review finding on PR 3786.
Covers the review finding directly: a record with a source_file but no source_location must not lose to a richer, unlocated stub that also carries a source_file, and the tiebreak must stay inert when both sides already have a real location, preserving the existing richness ordering there. Confirmed against pre fix code via git stash: the direct repro test fails there and passes only with the fix applied.
|
Good catch — real gap, fixed. source_location is richness-ignored the same way source_file already is, so two candidates that both carry a source_file could still be ordered by field count alone: a record with a real source_location could lose to a richer stub that has a source_file but no location. The codebase genuinely emits source_location as None on some records (see _merge_missing_attributes's own comment), so this isn't hypothetical. Extended the tiebreak with a second provenance step, checked after source_file and before richness: a node with a source_location beats one without, and it only changes the outcome when the two sides disagree on having one — every case where both (or neither) have a location keeps the existing richness ordering. Regression tests cover the exact shape (a located record vs. a richer unlocated-but-sourced stub) and confirm the tiebreak stays inert when both sides have a location. Full suite (5781 passed) is green. |
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 1 advisory finding(s) below merit a look before merge.
Graphify review — findings
Reorders entity-dedup survivor selection in _pick_winner to rank provenance ahead of content richness: a node with a source_file now always beats one without, and among two that both have one, a node with a real source_location beats one whose location is None. This stops a source-less (or unlocated) stub that happens to carry a few incidental bookkeeping keys from out-scoring and replacing a genuine located declaration purely on _content_richness() field count. When both sides agree on provenance, the existing richness-then-shorter-ID ordering decides exactly as before.
Worth a look
- Stray source_location overrides richness even without source_file —
graphify/dedup.py:1106· 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 — 670 functions depend on the 292 functions this change touches.
Health — this change adds coupling hotspots:
- new:
deduplicate_entities()— 77 callers, 24 callees - new:
build_merge()— 76 callers, 14 callees - new:
build()— 52 callers, 6 callees - new:
main()— 98 callers, 3 callees - new:
dispatch_command()— 2 callers, 125 callees - new:
_prune()— 9 callers, 3 callees - new:
_llm_tiebreak()— 1 callers, 10 callees - new:
test_poisoned_manifest_is_healed()— 0 callers, 6 callees
Verification — 670 functions in the blast radius were not formally verified this run (proofs are advisory here).
Health delta baseline: last indexed commit 4c73561 (diverged from this PR's base — delta is approximate).
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: 439 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
298 of 298 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— full-run-safetytests/test_affected_member_seed.py— full-run-safetytests/test_agents_platform.py— full-run-safetytests/test_analyze.py— full-run-safetytests/test_anthropic_custom_endpoint.py— full-run-safetytests/test_antigravity_install.py— full-run-safetytests/test_apm_fallback_version.py— full-run-safetytests/test_architecture_doc.py— full-run-safetytests/test_astro_extraction.py— full-run-safetytests/test_astro_import_ids.py— full-run-safetytests/test_atomic_canvas_export.py— full-run-safetytests/test_atomic_version_stamp.py— full-run-safetytests/test_atomic_writes.py— full-run-safetytests/test_backend_env_isolation.py— full-run-safetytests/test_backend_extras.py— full-run-safetytests/test_benchmark.py— full-run-safetytests/test_benchmark_raw_graph.py— full-run-safetytests/test_build.py— impact, full-run-safetytests/test_build_merge_dedup_scope.py— impact, full-run-safetytests/test_build_merge_hyperedges_and_prune.py— impact, full-run-safetytests/test_build_merge_shrink_guard.py— impact, full-run-safetytests/test_builtin_global_type_refs.py— full-run-safetytests/test_cache.py— full-run-safetytests/test_callflow_html.py— full-run-safetytests/test_cargo_introspect.py— full-run-safetytests/test_cargo_missing_manifest.py— full-run-safetytests/test_carried_hyperedge_remap.py— impact, full-run-safetytests/test_case_sensitive_resolution.py— full-run-safetytests/test_charmap_encoding.py— full-run-safetytests/test_chunking.py— full-run-safetytests/test_cjs_module_extension.py— full-run-safetytests/test_claude_cli_backend.py— full-run-safetytests/test_claude_md.py— full-run-safetytests/test_cli_broken_pipe.py— full-run-safetytests/test_cli_export.py— full-run-safetytests/test_cli_help.py— full-run-safetytests/test_cluster.py— full-run-safetytests/test_cobol_extractor.py— full-run-safetytests/test_codebuddy.py— full-run-safetytests/test_community_hub_labels.py— full-run-safetytests/test_community_labels_skill.py— full-run-safetytests/test_confidence.py— full-run-safetytests/test_corrupt_graph_json.py— impact, full-run-safetytests/test_cpp_nested_and_cli.py— full-run-safetytests/test_cpp_objc_cross_file_calls.py— full-run-safetytests/test_cpp_preprocess.py— full-run-safetytests/test_cross_extension_reexport_self_cycle.py— impact, full-run-safetytests/test_cross_language_call_resolution.py— full-run-safetytests/test_cross_repo_external_call_guards.py— full-run-safetytests/test_cross_repo_member_calls.py— full-run-safety- … and 248 more
non-code file(s) changed (
CHANGELOG.md) → running the full suite for safety (a code graph can't see config/fixture/data deps)
changed code file(s) with no mapped test (
CHANGELOG.md) — 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.
· 8 more finding(s) on lines outside this diff (see the check run).
A stray source_location with no source_file, a location pointing at an unstated file, which _merge_missing_attributes can produce by backfilling one field but not the other when a survivors own source_file is an empty string rather than None, was still granted an edge over a fully bare candidate by the location tiebreak, even though neither side actually has real provenance. The tiebreak now only counts source_location when source_file is present too, so a location with no file falls through to richness like any other bare field would. Fixes review finding on PR 3786.
Covers the review finding directly: a candidate with a source_location but no source_file must not out rank a fully bare, richer candidate. Confirmed against pre fix code via git stash, the test fails there and passes only with the fix applied.
|
Good catch — real gap, fixed. A stray `source_location` with no `source_file` (a location pointing at an unstated file — possible if a survivor's own `source_file` is an empty string rather than `None` when `_merge_missing_attributes` backfills only one of the two fields) was still granted an edge over a fully bare candidate by the location tiebreak, even though neither side has real provenance. The tiebreak now only counts `source_location` when `source_file` is present too — since a location dimension only ever changes the outcome when both sides already agree on having a `source_file` (the `source_file` check runs first and decides the case otherwise), this doesn't touch any of the cases this PR was meant to fix, it only closes the stray-location edge case. Regression test confirms a stray-location-no-file candidate no longer out-ranks a richer, fully bare one. Full suite (5782 passed) is green. |
There was a problem hiding this comment.
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
Prioritizes real provenance over content richness when _pick_winner selects the canonical dedup survivor: a node with a source_file beats one without, and among nodes that both have one, a node that also has a source_location wins — but a source_location only counts when a source_file is present, so a stray location with no file grants no edge over a bare candidate. This closes a gap where a source-less stub carrying incidental bookkeeping keys (external/type/_origin) could out-score and replace a genuine located declaration purely on field count, since source_file/source_location are excluded from _content_richness(). Richness-then-length ordering still decides whenever the two sides agree on provenance, so the existing #3372 behaviour is unchanged.
No blocking issues surfaced.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 672 functions depend on the 294 functions this change touches.
Health — this change adds coupling hotspots:
- new:
deduplicate_entities()— 77 callers, 24 callees - new:
build_merge()— 76 callers, 14 callees - new:
build()— 52 callers, 6 callees - new:
main()— 98 callers, 3 callees - new:
dispatch_command()— 2 callers, 125 callees - new:
_prune()— 9 callers, 3 callees - new:
_llm_tiebreak()— 1 callers, 10 callees - new:
test_poisoned_manifest_is_healed()— 0 callers, 6 callees
Verification — 672 functions in the blast radius were not formally verified this run (proofs are advisory here).
Health delta baseline: last indexed commit 4c73561 (diverged from this PR's base — delta is approximate).
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: 441 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
298 of 298 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— full-run-safetytests/test_affected_member_seed.py— full-run-safetytests/test_agents_platform.py— full-run-safetytests/test_analyze.py— full-run-safetytests/test_anthropic_custom_endpoint.py— full-run-safetytests/test_antigravity_install.py— full-run-safetytests/test_apm_fallback_version.py— full-run-safetytests/test_architecture_doc.py— full-run-safetytests/test_astro_extraction.py— full-run-safetytests/test_astro_import_ids.py— full-run-safetytests/test_atomic_canvas_export.py— full-run-safetytests/test_atomic_version_stamp.py— full-run-safetytests/test_atomic_writes.py— full-run-safetytests/test_backend_env_isolation.py— full-run-safetytests/test_backend_extras.py— full-run-safetytests/test_benchmark.py— full-run-safetytests/test_benchmark_raw_graph.py— full-run-safetytests/test_build.py— impact, full-run-safetytests/test_build_merge_dedup_scope.py— impact, full-run-safetytests/test_build_merge_hyperedges_and_prune.py— impact, full-run-safetytests/test_build_merge_shrink_guard.py— impact, full-run-safetytests/test_builtin_global_type_refs.py— full-run-safetytests/test_cache.py— full-run-safetytests/test_callflow_html.py— full-run-safetytests/test_cargo_introspect.py— full-run-safetytests/test_cargo_missing_manifest.py— full-run-safetytests/test_carried_hyperedge_remap.py— impact, full-run-safetytests/test_case_sensitive_resolution.py— full-run-safetytests/test_charmap_encoding.py— full-run-safetytests/test_chunking.py— full-run-safetytests/test_cjs_module_extension.py— full-run-safetytests/test_claude_cli_backend.py— full-run-safetytests/test_claude_md.py— full-run-safetytests/test_cli_broken_pipe.py— full-run-safetytests/test_cli_export.py— full-run-safetytests/test_cli_help.py— full-run-safetytests/test_cluster.py— full-run-safetytests/test_cobol_extractor.py— full-run-safetytests/test_codebuddy.py— full-run-safetytests/test_community_hub_labels.py— full-run-safetytests/test_community_labels_skill.py— full-run-safetytests/test_confidence.py— full-run-safetytests/test_corrupt_graph_json.py— impact, full-run-safetytests/test_cpp_nested_and_cli.py— full-run-safetytests/test_cpp_objc_cross_file_calls.py— full-run-safetytests/test_cpp_preprocess.py— full-run-safetytests/test_cross_extension_reexport_self_cycle.py— impact, full-run-safetytests/test_cross_language_call_resolution.py— full-run-safetytests/test_cross_repo_external_call_guards.py— full-run-safetytests/test_cross_repo_member_calls.py— full-run-safety- … and 248 more
non-code file(s) changed (
CHANGELOG.md) → running the full suite for safety (a code graph can't see config/fixture/data deps)
changed code file(s) with no mapped test (
CHANGELOG.md) — 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.
· 8 more finding(s) on lines outside this diff (see the check run).
Complete the skillgen --watch INPUT_PATH injection fix in the add-watch reference (#3742), preserve cross-file edges on incremental update (#3812), stop C# type references resolving to same-named non-type nodes (#3815), prefer a real source location over richness in dedup (#3786), and resolve Maven inherited groupId + ${...} properties in pom.xml (#3823). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Shipped in v0.9.68 (now on PyPI) via an authorship-preserving cherry-pick, so your commit keeps contributor-graph credit. Thanks @ayushcodes10! Dedup now prefers a real source location over richness when picking the survivor. |
Fixes #3775.
_pick_winner()picks the canonical survivor among colliding node records, ranked by_content_richness(). That score deliberately excludessource_file/source_location(per #3372, richness compares actual content, not placement) — but that means it has no way to tell a real, located declaration apart from a source-less stub that happens to carry a couple of incidental bookkeeping keys (external/type/_origin). The stub can out-score and replace the genuine record purely on field count.Reproduced the issue's own exact repro directly against fresh
upstream/v8in an isolated worktree before touching anything: a stub withsource_file: ""(richness 3) beats a real node withsource_file/source_locationset (richness 2), and_pick_winnerreturns the stub.Fix (the issue's own suggestion, correct and minimal): add a provenance tiebreak to the scoring tuple, ahead of richness but after the existing chunk-suffix check — a node with a real
source_filealways wins over one without. Only changes the outcome when the two sides disagree on provenance; every case where both (or neither) side has a source file keeps the exact#3372richness-then-length ordering.Scoped correctly: code-type nodes never reach
_pick_winnerat all (deduplicate_entitiesskipsfile_type == "code"), so this only affects concept/document/paper/image nodes from the semantic extraction path — confirmed, not assumed.Two regression tests in
tests/test_dedup_survivor_richness.py: the issue's exact repro (checked in both argument orders), and a companion confirming the tiebreak stays inert when both candidates already carry a source file (proving the fix doesn't disturb the existing#3372ordering). The first test checked to fail against pre-fix code viagit stashfirst. Full suite is green aside from the same 16 pre-existing failures from the Erlang/R/Solidity/VB.NET extractor tests needing optional grammar packages not installed in my environment (unrelated, already noted on other recent PRs).🤖 Generated with Claude Code
https://claude.ai/code/session_017qfdzgbA5KedGEjD1AayNh