Skip to content

watch: _rebuild_code overwrites semantic nodes instead of merging with existing graph #253

Closed

Description

@Joseph94m

Problem

_rebuild_code() in watch.py does a full AST-only rebuild and writes the
result directly to graph.json, overwriting any semantic nodes previously
extracted from docs/papers by the full /graphify pipeline.

In a mixed repo (code + markdown docs), every code file save destroys the
semantic layer (INFERRED edges, rationale nodes, cross-doc surprises,
hyperedges, community labels).

Reproduction

  1. Run /graphify . on a repo with code + markdown docs
  2. Note node/edge count (e.g. 473 nodes, 428 edges, 28 INFERRED)
  3. Start python3 -m graphify.watch . --debounce 3
  4. Edit any code file and save
  5. Graph is now AST-only (e.g. 345 nodes, 307 edges, 0 INFERRED)

Expected behavior

_rebuild_code should:

  1. Load the existing graph.json
  2. Remove only AST-derived nodes/edges
  3. Re-extract AST from code files
  4. Merge new AST nodes into the graph alongside existing semantic nodes
  5. Write the merged result

Workaround

Don't use --watch on mixed repos. Use /graphify . --update instead.

Activity

  1. Joseph94m commented on Apr 12, 2026

    @Joseph94m
    Author

    The README describes --watch as:

    Auto-sync (--watch) - run in a background terminal and the graph updates itself as your codebase changes. Code file saves trigger an instant rebuild (AST only, no LLM). Doc/image changes notify you to run --update for the LLM re-pass.

    "The graph updates itself" implies an incremental merge, consistent with how --update is described separately:

    /graphify ./raw --update - re-extract only changed files, merge into existing graph

    But --watch doesn't merge. _rebuild_code builds a new graph from AST-only data and overwrites graph.json entirely. On a mixed repo (code + docs), this silently destroys all semantic nodes, INFERRED edges, hyperedges, and community labels from the prior /graphify run.

    The distinction between --update (merge) and --watch (overwrite) is not documented and contradicts the "auto-sync" framing.

  2. added a commit that references this issue on Apr 12, 2026
  3. safishamsi commented on Apr 12, 2026

    @safishamsi
    Member

    Fixed in v0.4.3. _rebuild_code now loads the existing graph.json before overwriting — it keeps all non-code nodes (docs, papers, images) and their edges, then merges in fresh AST results. Semantic nodes from a full /graphify run survive code file saves.

  4. added a commit that references this issue on Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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