Skip to content

watch: 0.4.3 merge fix still drops cross-type edges and loses code nodes #261

Description

@Joseph94m

@safishamsi - follow up #253

What 0.4.3 fixed

The 0.4.3 merge logic now loads the existing graph.json, identifies code nodes by file_type == "code", and preserves non-code nodes (doc, image, paper) and their mutual edges. It also preserves hyperedges. Before 0.4.3, the watcher did a full overwrite and everything semantic was destroyed (0 INFERRED, 0 doc nodes, 0 hyperedges). That part is now working:

  • Doc nodes: 92 -> 92 (preserved)
  • Image nodes: 6 -> 6 (preserved)
  • Hyperedges: 11 -> 11 (preserved)

What 0.4.3 did NOT fix

Two problems remain:

1. Cross-type edges (code <-> doc) are dropped

The edge filter in _rebuild_code keeps only edges where neither endpoint is a code node:

sem_edges = [e for e in existing.get("edges", [])
             if e.get("source") not in code_ids and e.get("target") not in code_ids]

Most INFERRED edges connect a code node to a doc node (e.g. a doc explaining a function's rationale). These are all dropped because one endpoint is always a code ID.

Suggested fix - preserve any edge that is INFERRED/AMBIGUOUS, plus pure semantic edges:

sem_edges = [e for e in existing.get("edges", [])
             if e.get("confidence") in ("INFERRED", "AMBIGUOUS")
             or (e.get("source") not in code_ids and e.get("target") not in code_ids)]

Note: I am not 100% sure about the unintended effect these changes may have.

2. AST re-extraction produces fewer code nodes than full pipeline

Full /graphify . found 506 code nodes. The watcher rebuild found only 423 (-83). Most of the loss is .vue file nodes (28 -> 5) and their child functions (139 -> 74 sourced from .vue). The watcher's file discovery may differ from the full pipeline's detection step.

Reproduction (0.4.3 confirmed)

pip show graphifyy  # Version: 0.4.3
  1. Run /graphify . on a mixed repo (Go + TypeScript + Vue + markdown docs)
  2. Record baseline
  3. Start python3 -m graphify.watch . --debounce 3
  4. Edit one .ts file and save
  5. Compare graph
Metric Before watcher After watcher Delta
Total nodes 604 521 -83
Code nodes 506 423 -83
Doc nodes 92 92 0
Total links 560 396 -164
EXTRACTED 532 383 -149
INFERRED 27 13 -14
AMBIGUOUS 1 0 -1
Edges touching doc nodes 98 3 -95
Hyperedges 11 11 0
.vue file nodes 28 5 -23

Expected behavior

After a watcher rebuild:

  • Doc/image nodes: unchanged (working)
  • Hyperedges: unchanged (working)
  • INFERRED/AMBIGUOUS edges: unchanged (broken - lost 14/1)
  • Cross-type edges (code <-> doc): unchanged (broken - lost 95)
  • Code node count: same as full pipeline (broken - lost 83)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions