Skip to content

fix(watch): preserve direct calls to unchanged files during incremental updates - #2439

Closed
aryanbonigala wants to merge 1 commit into
Graphify-Labs:v8from
aryanbonigala:fix/2406-incremental-cross-file-edges
Closed

aryanbonigala wants to merge 1 commit into
Graphify-Labs:v8from
aryanbonigala:fix/2406-incremental-cross-file-edges

Conversation

@aryanbonigala

Copy link
Copy Markdown
Contributor

Summary

Incremental rebuilds previously re-extracted only the changed files. The shared direct-call resolver therefore lacked the unchanged target nodes it needed to bind a plain foo() to its definition in another file.

Reconciliation correctly removed the changed source's old AST edges — that part was never wrong — but with the callee absent from the extraction batch, the missing direct call could not be regenerated. The result: a cross-file calls edge that a full build resolves silently disappears after an incremental update, and only returns on the next full rebuild. (The file-level imports edge survived, because the JS/Python symbol-resolution pass reads the import target off disk rather than off the node list — which is why the loss was easy to miss.)

This patch supplies a read-only AST context containing unchanged, live, in-corpus nodes exclusively to the shared direct-call resolver:

  • Fresh changed-file nodes remain authoritative — on any id collision the freshly extracted node wins.
  • Context nodes are not parsed, not returned, not persisted, and not treated as newly extracted. They extend the resolver's label/file indexes and nothing else; all_nodes is untouched and raw_calls still come solely from the re-extracted paths.
  • Context is scoped to AST-tier nodes only, excludes any file in this run's extract targets, excludes deleted files, and excludes sources no longer in the scanned corpus — so a renamed or removed file can never remain a resolver target.
  • Removed calls, removed imports, removed targets, and deleted files still remove their old edges. Preserving stale outgoing edges was explicitly not the approach, and there are tests asserting the edge disappears when the call is deleted.
  • If the persisted graph is unreadable or exceeds the size cap, resolution falls back to the changed batch alone (pre-existing behavior).

Scope

This is intentionally a narrow fix.

Addresses #2406
Related to #2437
Related to #2438

Testing

All runs on uv run --frozen, with the OpenAI extra synced via uv sync --frozen --group dev --extra openai. uv.lock is unchanged.

Command Result
pytest tests/test_watch.py -q 97 passed, 2 skipped, 2 xfailed
pytest tests/test_js_import_resolution.py tests/test_extract.py -q 222 passed, 1 skipped
pytest tests/test_ollama_retry_cap.py -q 4 passed
pytest -q (full suite) 3915 passed, 35 skipped, 2 xfailed
ruff check graphify tests All checks passed!
git diff --check clean (no output, exit 0)

The two xfail(strict=True) tests are the admitted scope gaps above, and each corresponds to one of the newly filed follow-up issues:

They are strict on purpose: whoever closes either issue will be told to delete the marker rather than leave it silently stale.

New passing coverage added alongside them:

  • TypeScript and Python cross-file direct call preserved across an incremental rebuild.
  • Edge is removed when the call is removed (no stale-edge workaround).
  • Edge is not resolved when the import evidence is gone.
  • Fresh nodes win when the target file also changed.
  • Deleted target file is excluded from the resolution context.
  • Only changed files are extracted (incremental contract).
  • Repeat incremental rebuilds are idempotent, and match a from-scratch full build.

@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.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Graphify reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).


Graphify review — findings

This PR adds a new optional direct_call_resolution_context_nodes parameter to graphify.extract.extract(), which supplies read-only AST nodes from files not being re-extracted so the shared direct cross-file call resolution pass can extend its label/file indexes without parsing, mutating, or emitting those nodes. In graphify/watch.py, _rebuild_code is updated to build this context list from the persisted graph during incremental rebuilds (filtering to AST-tier nodes from unchanged, non-deleted, still-present source files) and pass it into extract(). The test file adds coverage for incremental rebuild scenarios around cross-file call edges, plus a number of related watch/rationale test cases. The stated intent is to prevent changed→unchanged direct calls edges from being dropped during incremental rebuilds, with member calls and indirect calls explicitly left out of scope.

No blocking issues surfaced. 2 lower-confidence candidates did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 1443 functions depend on the 456 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: _rebuild_code() — 78 callers, 49 callees

Verification — 1443 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 1316 function(s) in the blast radius were not formally verified this run

· 1 more finding(s) on lines outside this diff (see the check run).

safishamsi added a commit that referenced this pull request Aug 5, 2026
… preservation, extract crash recovery; bump to 0.9.33

#2411 (thanks @JensD-git): key the C# partial-class merge on assembly
(nearest ancestor .csproj/.fsproj/.vbproj) in addition to namespace and
name, so same-name partial classes in different assemblies stay distinct
while genuine partial halves within one project still merge. Fixes a
0.9.32 regression from #2332.

#2437/#2438 (thanks @aryanbonigala, builds on PR #2439): incremental
rebuilds no longer drop member-call and indirect_call edges from a
changed file into an unchanged target. Re-resolution now sees the
unchanged corpus (nodes, contains/method edges, and _callable markers,
which now persist to graph.json like _origin); edges to a genuinely
removed target are still evicted.

#2444/#2445 (thanks @Baziar, builds on PRs #2461/#2458): a
BrokenProcessPool triggers the sequential fallback instead of being
swallowed per future, a failed worker file is retried sequentially
rather than merged as empty, and a whole-pass AST failure on a fresh
build exits non-zero instead of writing a zero-node graph
(--allow-partial opts into a best-effort partial graph).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.33 (graphifyy==0.9.33 on PyPI). Your approach (widening the resolver context to the persisted unchanged-file nodes, AST-tier only, excluding extract targets and deleted/out-of-corpus sources, failing open on an unreadable graph) is the base of the fix, and I extended it to also cover member calls (#2437) and indirect_call (#2438) by threading the unchanged contains/method edges and persisting the _callable markers. Credited in the release notes. Thanks @aryanbonigala, this was a really clean starting point.

@safishamsi safishamsi closed this Aug 5, 2026
PerryLin-0420 pushed a commit to PerryLin-0420/graphify-decouple that referenced this pull request Aug 13, 2026
… preservation, extract crash recovery; bump to 0.9.33

Graphify-Labs#2411 (thanks @JensD-git): key the C# partial-class merge on assembly
(nearest ancestor .csproj/.fsproj/.vbproj) in addition to namespace and
name, so same-name partial classes in different assemblies stay distinct
while genuine partial halves within one project still merge. Fixes a
0.9.32 regression from Graphify-Labs#2332.

Graphify-Labs#2437/Graphify-Labs#2438 (thanks @aryanbonigala, builds on PR Graphify-Labs#2439): incremental
rebuilds no longer drop member-call and indirect_call edges from a
changed file into an unchanged target. Re-resolution now sees the
unchanged corpus (nodes, contains/method edges, and _callable markers,
which now persist to graph.json like _origin); edges to a genuinely
removed target are still evicted.

Graphify-Labs#2444/Graphify-Labs#2445 (thanks @Baziar, builds on PRs Graphify-Labs#2461/Graphify-Labs#2458): a
BrokenProcessPool triggers the sequential fallback instead of being
swallowed per future, a failed worker file is retried sequentially
rather than merged as empty, and a whole-pass AST failure on a fresh
build exits non-zero instead of writing a zero-node graph
(--allow-partial opts into a best-effort partial graph).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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.

2 participants