Skip to content

fix(watch): don't drop full rebuilds when the lock is busy (#4274) - #4276

Closed
smngvlkz wants to merge 1 commit into
Graphify-Labs:v8from
smngvlkz:fix/4274-queue-full-rebuild-requests
Closed

smngvlkz wants to merge 1 commit into
Graphify-Labs:v8from
smngvlkz:fix/4274-queue-full-rebuild-requests

Conversation

@smngvlkz

@smngvlkz smngvlkz commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4274.

Problem

#1059 made incremental rebuild requests survive lock contention by queueing their paths in .pending_changes. Two gaps remained in _rebuild_code:

  1. Full-corpus requests were dropped. A full request (post-checkout hook, watch) that lost the non-blocking lock queued nothing, returned False, and still logged changes queued. The lock holder only covered its own change set, so files touched by the checkout never reached the graph.
  2. Full rebuilds never drained late work. The late-arrival drain was skipped for full rebuilds ("a full rebuild already saw everything"), but that only holds for files changed before the corpus walk. Paths a post-commit hook queued after the walk stayed in .pending_changes until some unrelated rebuild ran.

Fix

  • A full request that cannot take the lock leaves a .pending_full marker beside .pending_changes (_queue_pending_full / _drain_pending_full).
  • When the lock holder starts, a queued marker upgrades the run to a full rebuild (which supersedes queued incremental paths).
  • The late-arrival drain now runs after every rebuild, full or incremental. A marker that appears mid-run triggers one more full pass; queued paths trigger an incremental pass. Still bounded by _PENDING_DRAIN_MAX_PASSES.
  • changes queued is printed only when something was actually queued (an empty change set now logs nothing to queue).

Behaviour change worth noting: an incremental holder that finds a full request waiting now does a full rebuild instead of its incremental one. Slower for that one run, but it's the only way the full request gets honoured.

Verification

  • Both repro scripts from Full-corpus rebuild requests are dropped on lock contention (log says "changes queued"), and a full rebuild never drains late incremental work #4274 pass after the change: the contended full request leaves the marker, and the late g_added_late function lands in graph.json with .pending_changes empty afterwards.
  • 5 new regression tests in tests/test_watch.py. All 5 fail on v8 HEAD and pass with this change:
    • full request queues a marker on contention
    • empty change set does not claim "changes queued"
    • incremental holder runs a full pass for a marker queued mid-run
    • incremental holder upgrades to full when a marker is already queued
    • full rebuild drains incremental work queued mid-run
  • tests/test_watch.py: 186 passed, 3 skipped. Hook/watch/rebuild subset (-k "hook or watch or rebuild or pending"): 615 passed, 13 skipped.

Thanks to @Ethan-JY-Park for the detailed report and repro scripts.

@smngvlkz
smngvlkz requested a review from safishamsi as a code owner October 10, 2026 08:32
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @smngvlkz. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@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 reviewed this change.

Formal verification could not match the changed code to the code graph, so it may not have checked the code this PR changed.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.

Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 not verified).

Formal verification. PR-changed functions: 0/1 verified (0 proven, 0 may-equivalent, 0 distinguished) · 1 not verified (1 unsupported).

Not verified on this run: \_rebuild\_code (unsupported).


Graphify review — findings

Fixes full-corpus rebuild requests (watcher, post-checkout hook) being silently dropped when another rebuild holds the lock: they now leave a .pending_full marker. The lock-holder consumes the marker and runs a full pass, either upgrading its own incremental run or adding one more pass before releasing. Full rebuilds now also drain work that arrives mid-run, and an empty change set prints "nothing to queue" instead of claiming "changes queued".

Worth a look

  • Queued full rebuild can be missed after the final empty drain — graphify/watch.py:1654 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 708 functions depend on the 474 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: _rebuild_code() — 167 callers, 58 callees

Verification — 708 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: 515 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

17 of 361 test file(s) selected (5%) via static blast radius.

  • tests/test_cache_stale_import_target.py — impact
  • tests/test_elixir_import_resolution.py — impact
  • tests/test_elixir_qualified_calls.py — impact
  • tests/test_elixir_unqualified_call_scope.py — impact
  • tests/test_export_direction.py — impact
  • tests/test_external_stub_endpoints.py — impact
  • tests/test_incremental_unscanned_placeholders.py — impact
  • tests/test_kotlin_grammar.py — impact
  • tests/test_labeling.py — impact
  • tests/test_markdown_code_spans.py — impact
  • tests/test_no_cluster_undeclared_endpoints.py — impact
  • tests/test_python_inherited_method_calls.py — impact
  • tests/test_skill_persisted_scan_options.py — impact
  • tests/test_terraform_modules.py — impact
  • tests/test_watch.py — impact, changed-test
  • tests/test_watch_identity_cache.py — impact
  • tests/test_watch_manifest_location.py — impact

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Formal verification

Could not verify: Could not verify \_rebuild\_code.

The verifier did not have enough to check \_rebuild\_code, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: nondeterministic output (both versions disagreed with themselves on the witness) — not a behaviour change; a function whose output is not a function of its inputs (random / time / uuid / os.urandom, or state carried across calls) cannot be soundly distinguished by execution, so this tier abstains for the whole function

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

@FolatheDuckofDuckingburg FolatheDuckofDuckingburg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This PR cleanly fixes #4274 by introducing a

.pending_full

marker mechanism that ensures full-corpus rebuild requests are no longer dropped during lock contention.

@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.87, just released to PyPI as graphifyy 0.9.87. Landed via an authorship-preserving cherry-pick (so the commit keeps your name and counts on your contributor graph) rather than a branch merge, which is why GitHub marks this closed rather than merged. Thanks @smngvlkz!

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.

Full-corpus rebuild requests are dropped on lock contention (log says "changes queued"), and a full rebuild never drains late incremental work

3 participants