Skip to content

fix(watch): keep a re-extracted file's type stub on the id a full build gives it - #5800

Open
0xkaushik-ai wants to merge 2 commits into
Graphify-Labs:v8from
0xkaushik-ai:fix/incremental-type-stub-ids
Open

0xkaushik-ai wants to merge 2 commits into
Graphify-Labs:v8from
0xkaushik-ai:fix/incremental-type-stub-ids

Conversation

@0xkaushik-ai

@0xkaushik-ai 0xkaushik-ai commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5797.

A type no file defines (Swift Int, Scala String, an unresolved Foo in Rust or Go) is a sourceless stub. A full build salts one copy per referencing file when two files reference it (a_swift_int, b_swift_int) and keeps the bare int when only one does. An incremental run re-extracted the edited file alone, so nothing collided in the batch and its copy went back to int, while the other file stayed on b_swift_int. Deleting one of two holders went the other way: the survivor stayed salted where a full build has int.

_id_collision_partners already pulls id-colliding files into one batch, but it recognises a salted node by its source_file. A stub is stored with source_file: "" and its origin_file hint is stripped before output, so the search never saw it.

Fix

  • watch.py, _salted_stub_holders: reads a stored stub's owner from its edges. A salted copy is referenced from one file only, its id starts with that file's make_id(<path>) prefix, and the rest of the id is the id of its label; anything else is left out. The label check keeps out a bare stub whose own name starts like the path (a type A_Swift_Int in A.swift), which the review bot caught on the first commit.
  • resolution.py, _disambiguate_colliding_node_ids(context_stub_ids=...): a sourceless batch stub whose id an unchanged, still-scanned file holds salted is salted with its own path, as if both files were in the batch. A source-backed node is never touched by this. Both incremental paths (update in watch.py, extract in cli.py) pass the set through the new extract(resolution_context_stub_ids=...).
  • watch.py, _id_collision_partners: when a target or deleted file shared a stub with exactly one unchanged file, that file is re-extracted, because it may end up the only holder and must return to the bare id.

I did not add stub holders to the existing partner closure. In a Swift repo that would re-extract every file that mentions String on each edit. With this change an edit re-extracts no extra file while two other holders exist, and one extra file otherwise.

Not covered

  • A file that references a type for the first time while exactly one unchanged file holds it bare (int): the unchanged file should become a_swift_int, but nothing identifies it before extraction. The new file's own copy is unaffected by this PR. A third holder joining two salted ones is covered.
  • A repeated graphify extract still keeps the old, now unreferenced stub node ([Bug]: repeated graphify extract keeps an orphaned base-class stub after its referrer resolves it #5726). Edges match a full build; the end-to-end tests leave such orphans out of the node comparison on the extract path only and say so.
  • A graph already drifted by this bug is not repaired until a full rebuild.

Tests: tests/test_incremental_type_stub_ids.py

  • End to end, 11 cases on update and extract --no-cluster, each compared with a fresh full build: edit one of two holders (Swift, Scala, Rust), delete one of two (Swift, Go), the edited file drops the reference, a third holder is added, a re-extracted partner keeps its other salted stubs, and a type whose name only looks salted. On v8 16 of the 22 fail; the other 6 guard against over-salting (two remaining holders, the look-alike name) and pass on v8. With the fix all pass.
  • Unit: owner detection from edges and label, partner selection (last other holder only), and that a context id salts a lone stub but not a source-backed node.
  • My differential harness (127 incremental-vs-full scenarios): the Swift, Scala, Rust and Go type-stub scenarios go from mismatch to match, nothing else changes.
# from the worktree, with the project venv and PYTHONPATH set to the worktree
python -m pytest tests/test_incremental_type_stub_ids.py -q   # 28 passed
python -m pytest tests/ -q -n 6                               # 13092 passed, 124 skipped, 5 xfailed
ruff check graphify/watch.py graphify/cli.py graphify/extract.py graphify/extractors/resolution.py tests/test_incremental_type_stub_ids.py   # clean
pyright graphify/watch.py graphify/extractors/resolution.py   # 42 errors, the same count as on v8

🤖 Generated with Claude Code

…ld gives it

A type no file defines (Swift `Int`, Scala `String`) is a sourceless stub. A
full build salts one copy per referencing file (`a_swift_int`, `b_swift_int`)
when two files reference it, and keeps the bare `int` for a single one. An
incremental run re-extracted the edited file alone, so its copy went back to
`int` while the other stayed salted; deleting one of two holders left the
survivor salted (Graphify-Labs#5797).

The stored stub has no source_file and its origin_file hint is not persisted,
so the id-collision partner search never saw it. Its owner is now read from
its edges. extract() is told which stub ids an unchanged file holds salted and
salts a batch stub of the same id too, so no other file is re-extracted for
it. Only when a target or deleted file shared a stub with exactly one
unchanged file is that file re-extracted, since it may end up the only holder.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify review View in Graphify

Review before merging · Merge confidence 4/5

1 bug · High impact

Incremental extraction now tracks salted sourceless stubs held by unchanged files and passes their bare IDs into collision handling.

P2  Hashed stub IDs are missed for paths that normalize alike · watch.py:300

Code graph · 6418 functions depend on this change
  • 3 functions became more coupled. dispatch_command() (8 callers), _disambiguate_colliding_node_ids() (6 callers), _id_collision_partners() (3 callers).
  • 473 of 693 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed e4efcc5 · 1 of 1 earlier findings resolved

Comment thread graphify/watch.py Resolved
The owner's path prefix alone marked a stored stub as salted, so the bare stub
of a type named `A_Swift_Int` in A.swift read as a salted `Int`, and another
file's lone `Int` was salted against it. The rest of the id now has to be the
id of the stub's label.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Comment thread graphify/watch.py
Comment on lines +297 to +300
continue
source, prefix = owner
if not nid.startswith(prefix) or len(nid) == len(prefix):
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2  Hashed stub IDs are missed for paths that normalize alike

When distinct paths normalize to the same ID prefix, editing or adding a file that references the same type can leave its stub unsalted even though a full build salts it.

Update _salted_stub_holders in graphify/watch.py to recognize hash-suffixed IDs.

Evidence · checked against the code

Expected: The unchanged holder is detected and the re-extracted stub is salted consistently with a full build.
Actually: The holder detector rejects the hash-suffixed ID, so the new stub can remain bare and differ from the full-build ID.

  • Independent source review: The helper’s ordinary salted-stub test covers paths without the hash suffix and does not exercise normalized-path collisions. The collision-partner logic also uses _salted_stub_holders, so it does not recover the omitted hashed holder through that route. No inspected guard compensates for the missed context ID.
  • This affects paths whose normalized IDs collide and whose stubs are salted with the disambiguator's hash; ordinary path salts are recognized.
Prompt to fix with AI
In graphify/watch.py, _salted_stub_holders (lines 297-300):
Problem: Hashed stub IDs are missed for paths that normalize alike
Expected: The unchanged holder is detected and the re-extracted stub is salted consistently with a full build.
Actually: The holder detector rejects the hash-suffixed ID, so the new stub can remain bare and differ from the full-build ID.
Fix it at the cause, and add a test that fails without the fix.

Graphify · Checked against the code · View in Graphify

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: incremental update gives a re-extracted file's type-reference nodes (Int, String) different ids than a full build (Swift, Scala)

1 participant