Skip to content

[Bug]: Incremental rebuild gives an edited file a different id when its same-stem sibling is unchanged #5505

Backlog

Description

@amslezak

Pre-flight checks

  • I have checked the Troubleshooting section in the README

What happened?

An incremental rebuild gives an edited file a different id than a full build gives it, when that file shares its id with a file that did not change. graphify update, the git hook and watch all take this path, so the graph drifts further from a full build with each update.

foo.c and foo.h both collapse to foo, and _disambiguate_colliding_node_ids salts them to foo_c_foo and foo_h_foo. When only foo.c changes, extract() sees foo.c alone, finds no collision, and keeps the bare foo. The edges into and out of the edited file then use an id that a full build never makes.

I expected the incremental graph to match a full build of the same tree.

Steps to reproduce

import json, tempfile
from pathlib import Path
from graphify.watch import _rebuild_code

root = Path(tempfile.mkdtemp()) / "proj"
root.mkdir()
(root / "foo.h").write_text("int foo(void);\n")
(root / "foo.c").write_text('#include "foo.h"\nint foo(void) { return 1; }\n')
(root / "main.c").write_text('#include "foo.h"\nint main(void) { return foo(); }\n')

def file_ids():
    g = json.loads((root / "graphify-out/graph.json").read_text())
    return sorted(n["id"] for n in g["nodes"] if n.get("source_file", "").endswith(n.get("label", "\0")))

_rebuild_code(root, no_cluster=True, acquire_lock=False, force=True)
print("full build:      ", file_ids())
(root / "foo.c").write_text((root / "foo.c").read_text() + "/* edited */\n")
_rebuild_code(root, changed_paths=[root / "foo.c"], no_cluster=True, acquire_lock=False, force=True)
print("after foo.c edit:", file_ids())

Error output or graph output

full build:       ['foo_c_foo', 'foo_h_foo', 'main']
after foo.c edit: ['foo', 'foo_h_foo', 'main']

Graphify version

0.9.120

Operating System

macOS

Python Version

3.12.15

Installation Method

uv tool, editable install from source

Additional Environment Details

No provider variables set. AST extraction only. Reproduced in a clean temporary directory.

Additional context

  • Real-world impact: in a Drupal theme, each Single Directory Component keeps card.twig beside card.scss, so every component collides. After a few graphify update runs, 47 of 475 include and import edges pointed at placeholder nodes, and graphify affected missed real consumers.
  • Related: Changed-files incremental rebuild drops cross-file dependency edges (hook install / watch affected) #3570 reports that incremental rebuilds are not edge-equivalent to a full build. This is a separate cause.
  • The fix I'm running: extract() passes resolution_context_nodes to _disambiguate_colliding_node_ids. A context node whose id is the salted form of a batch id or edge target (_make_id(source_key) + "_" + old_id) counts as a collider. The batch is then salted and routed the way a full build does it. With the fix, the theme's incremental graph matches a full build edge for edge. I can open a PR with the fix and a regression test.

Activity

  1. github-actions commented on Nov 25, 2026

    @github-actions

    Thanks for opening this issue, @amslezak. 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.

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