Skip to content

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

Closed

Description

@Ethan-JY-Park

Version: graphifyy 0.9.82 · macOS 26.2 (arm64) · Python 3.11.15
Related: #1059 (incremental requests are now queued — this is the part that fix left out), #4273 (separate lock bug)

What happens

_rebuild_code in graphify/watch.py queues only incremental requests before trying the non-blocking lock:

  • L1602-1603: if changed_paths is not None and not block_on_lock: _queue_pending(...)
  • L1604-1608: if the lock is busy, it prints Rebuild already in progress for ... - changes queued. and returns False.
  • L1627-1631: the late-arrival drain runs only if merged is not None, i.e. only when the lock holder was an incremental rebuild ("A full rebuild already saw everything").

That leaves two gaps.

1. A full-corpus request that loses the lock is dropped, and the log says it was queued.
The post-checkout hook body (hooks.py:280, _rebuild_code(_root, force=_force)) and watch (watch.py:2624, _rebuild_code(watch_path)) both ask for a full rebuild with the non-blocking lock. If a post-commit rebuild (or anything else) holds the lock at that moment, nothing is queued, the call returns False, and the message still says changes queued. The running incremental rebuild covers only its own changed paths, so the files the checkout touched never reach the graph.

2. Incremental work queued while a full rebuild runs is not applied by that rebuild.
"A full rebuild already saw everything" holds only for files changed before it walked the corpus. A post-commit hook that fires after the walk queues its paths in .pending_changes; the full rebuild then skips the drain, so those paths stay queued and are missing from the graph until some later rebuild happens to run.

Repro (no git repo needed)

Gap 1 (repro_full_rebuild_drop.py):

import multiprocessing as mp, tempfile, time
from pathlib import Path
from graphify.watch import _rebuild_code, _rebuild_lock

def hold(out, seconds):
    with _rebuild_lock(out, blocking=True):
        time.sleep(seconds)

if __name__ == "__main__":
    root = Path(tempfile.mkdtemp())
    (root / "a.py").write_text("def f():\n    return 1\n", encoding="utf-8")
    out = root / "graphify-out"
    p = mp.Process(target=hold, args=(out, 2.0)); p.start(); time.sleep(0.5)
    full_ok = _rebuild_code(root)                     # post-checkout / watch call
    print("full rebuild returned:", full_ok, "| queued:", (out / ".pending_changes").exists())
    inc_ok = _rebuild_code(root, changed_paths=[root / "a.py"])   # post-commit call
    print("incremental rebuild returned:", inc_ok, "| queued:", (out / ".pending_changes").exists())
    p.join()

Output:

[graphify watch] Rebuild already in progress for /private/var/.../tmpwuqtopc8 - changes queued.
full rebuild returned: False | queued: False
[graphify watch] Rebuild already in progress for /private/var/.../tmpwuqtopc8 - changes queued.
incremental rebuild returned: False | queued: True

Gap 2 (repro_late_incremental.py) — the inner full rebuild is slowed after it writes the graph, so the incremental call arrives after the walk:

import json, multiprocessing as mp, tempfile, time
from pathlib import Path
import graphify.watch as w
ORIG = w._rebuild_code

def slow_full(root):
    def slowed(watch_path, **kw):
        if kw.get("acquire_lock") is False and kw.get("changed_paths") is None:
            ok = ORIG(watch_path, **kw); time.sleep(2.0); return ok
        return ORIG(watch_path, **kw)
    w._rebuild_code = slowed   # the outer call looks up the inner call by global name
    ORIG(root)

if __name__ == "__main__":
    root = Path(tempfile.mkdtemp())
    (root / "a.py").write_text("def f():\n    return 1\n", encoding="utf-8")
    out = root / "graphify-out"
    p = mp.Process(target=slow_full, args=(root,)); p.start(); time.sleep(1.0)
    (root / "a.py").write_text("def f():\n    return 1\n\ndef g_added_late():\n    return 2\n", encoding="utf-8")
    print("incremental returned:", ORIG(root, changed_paths=[root / "a.py"]),
          "| queued:", (out / ".pending_changes").exists())
    p.join()
    labels = {str(n.get("label", "")) for n in json.loads((out / "graph.json").read_text())["nodes"]}
    print("after full rebuild finished -> pending still queued:", (out / ".pending_changes").exists(),
          "| g_added_late in graph:", any("g_added_late" in l for l in labels))

Output:

[graphify watch] Rebuild already in progress for /private/var/.../tmpoedfeyzl - changes queued.
incremental returned: False | queued: True
after full rebuild finished -> pending still queued: True | g_added_late in graph: False

Expected

  • A full request that cannot take the lock is recorded (for example a "full" marker next to .pending_changes), and the lock holder runs one more full pass before releasing.
  • After any rebuild finishes — full or incremental — the holder drains .pending_changes that arrived during the run.
  • The "changes queued" message is printed only when something was actually queued.

Activity

  1. github-actions commented on Oct 10, 2026

    @github-actions

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

  2. safishamsi commented on Oct 12, 2026

    @safishamsi
    Member

    Fixed in v0.9.87 (graphifyy 0.9.87 on PyPI) via #4276.

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