Skip to content

sem_edges reads wrong key from graph.json #269

Description

@Joseph94m

Problem

The edge merge logic in watch.py _rebuild_code() reads from existing.get("edges", []) but graph.json uses the key "links" (NetworkX node-link format). This means sem_edges is always an empty list and all semantic edges are silently dropped on every watcher rebuild.
This is the root cause behind #253 and #261. The fixes in 0.4.3, 0.4.4, and 0.4.5 added correct merge logic but all read from the wrong key, so the edge preservation never actually executes.
Node preservation works (reads "nodes", correct key). Hyperedge preservation works (reads "hyperedges", correct key). Only edge preservation is broken.

Fix

One line in watch.py, line 46:

# Before (broken)
sem_edges = [e for e in existing.get("edges", [])
# After (working)
sem_edges = [e for e in existing.get("links", existing.get("edges", []))

Falls back to "edges" for safety in case a future version changes the key.

Verification

Tested locally by patching the installed 0.4.5 watch.py:

Metric Baseline Unpatched watcher Patched watcher
Total nodes 587 588 588
Total links 534 396 531
INFERRED 49 13 47
AMBIGUOUS 2 0 2
Edges touching docs 138 3 138
Doc INFERRED 35 1 35
Hyperedges 22 22 22
Patched watcher preserves nearly all semantic edges. The small delta (534 vs 531 links, 49 vs 47 INFERRED) is from edge deduplication during rebuild, not data loss.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions