graphify icon indicating copy to clipboard operation
graphify copied to clipboard

[Bug]: skill full build (SKILL.md Step 4/5) still uses build_from_json and skips entity dedup, so the next --update re-shapes untouched files (skill counterpart of #769)

Open Stashub opened this issue 1 month ago • 1 comments

Pre-flight checks

  • [x] I have checked the Troubleshooting section in the README

What happened?

The skill's full build still calls build_from_json() directly (SKILL.md Step 4 and the Step 5 re-export), so it never runs deduplicate_entities(). Every other build path does:

  • graphify extract full rebuild: build([merged], dedup=True) (fixed in #769, commit 579e1cc, "making it symmetric with the incremental path")
  • skill --update: build_merge(..., dedup=True) (default)

So the same extraction gives a different graph depending on which path built it. In practice the first skill --update after a skill full build silently merges nodes that belong to files the update never touched, and graph.json changes topology for reasons unrelated to the edit. This is the skill-side counterpart of #769.

Expected: the skill full build produces the same graph as graphify extract and as a subsequent --update would, i.e. Step 4 and Step 5 build through build([extraction], dedup=True, root=..., directed=...).

Steps to reproduce

mkdir reproB && cd reproB
python - <<'EOF'
import copy
from graphify.build import build_from_json, build, build_merge
from graphify.cluster import cluster
from graphify.export import to_json
import os

def frag(stem):
    src = f"docs/{stem}.md"
    e = lambda s, t: {"source": s, "target": t, "relation": "references",
                      "confidence": "EXTRACTED", "confidence_score": 1.0, "source_file": src}
    return {"nodes": [
        {"id": f"docs_{stem}", "label": f"{stem}.md", "file_type": "document", "source_file": src},
        {"id": f"docs_{stem}_contract_446", "label": "Contract No. 446", "file_type": "concept", "source_file": src},
        {"id": f"docs_{stem}_acme_corp", "label": "ACME Corp.", "file_type": "concept", "source_file": src}],
        "edges": [e(f"docs_{stem}", f"docs_{stem}_contract_446"),
                  e(f"docs_{stem}_contract_446", f"docs_{stem}_acme_corp")],
        "hyperedges": []}

A, B = frag("lot_a"), frag("lot_b")
merged = {"nodes": A["nodes"] + B["nodes"], "edges": A["edges"] + B["edges"], "hyperedges": []}

# 1) skill full build (SKILL.md Step 4)
G1 = build_from_json(copy.deepcopy(merged), root=".", directed=False)
print("skill full build (build_from_json):", G1.number_of_nodes())

# 2) graphify extract full rebuild path
G2 = build([copy.deepcopy(A), copy.deepcopy(B)], root=".", directed=False)
print("CLI extract (build):", G2.number_of_nodes())

# 3) skill --update after only lot_b.md changed (references/update.md)
os.makedirs("graphify-out", exist_ok=True)
to_json(G1, cluster(G1), "graphify-out/graph.json")
G3 = build_merge([copy.deepcopy(B)], graph_path="graphify-out/graph.json", root=".", directed=False)
print("skill --update (build_merge):", G3.number_of_nodes())
EOF

Error output or graph output

skill full build (build_from_json): 6
[graphify] Deduplicated 2 node(s) (2 exact).
[graphify] Replaced 3 node(s) from re-extracted source file(s).
CLI extract (build): 4
[graphify] Deduplicated 2 node(s) (2 exact).
skill --update (build_merge): 4

(stderr and stdout interleave, so the "Replaced" line belongs to step 3.)

In step 3 only lot_b.md was re-extracted, yet docs_lot_b_contract_446 / docs_lot_b_acme_corp were folded into the lot_a nodes, an effect the full build never applied.

Real-world numbers: on a 465-node docs graph (three sibling cost estimates sharing a contract, an object code, and the people who signed them), deduplicate_entities collapses 8 nodes (7 exact, 1 fuzzy) that the skill full build had left split across files. Those 8 merges would appear only on the next --update, attributed to whatever file happened to change.

Graphify version

0.9.89 (also v8 at e8eb76e7)

Operating System

Linux

Python Version

3.13

Installation Method

uv tool install (recommended)

Additional Environment Details

No provider keys set; semantic extraction done by the host agent (Claude Code skill flow).

Additional context

  • Related: #769 (same asymmetry, fixed for the CLI only), #296 (cross-file canonicalization), #3094 (cross-file guard semantics that build() already applies).
  • The #479 shrink guard needs no special handling: Step 5 re-exports the same extraction through the same builder, so the node count matches Step 4.

Stashub avatar Oct 13 '26 17:10 Stashub

Thanks for opening this issue, @Stashub. A maintainer will take a look soon.

If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

github-actions[bot] avatar Oct 13 '26 17:10 github-actions[bot]