Repository navigation
extract: hold the per-repo rebuild lock for the whole pipeline - #1
Conversation
Two `graphify extract` runs (or an extract racing a watcher/hook rebuild) on one graphify-out/ interleave cache saves and clobber graph.json. extract now takes the same advisory flock _rebuild_code takes, immediately after the output dir exists, and holds it to the end of the command. A contended run prints the holder's PID and waits up to GRAPHIFY_LOCK_TIMEOUT seconds (default 600) via a new bounded-wait mode on _rebuild_lock (the kernel only offers skip or wait-forever, so the deadline is polled in userspace), then exits 1 instead of hanging forever behind a wedged rebuild. The lock is acquired exactly once — flock is per-open-file-description, so re-entry in the same process would self-deadlock — and SystemExit unwinds the context manager, so the unlink-on-release contract holds on every exit path. Co-Authored-By: Claude Fable 5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f7c5899aa2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| fcntl.flock(fh.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) | ||
| acquired = True |
There was a problem hiding this comment.
Keep the lock pathname bound to the acquired inode
When a timed waiter opens the lock file while another process owns it, the current owner unlocks and then unlinks that pathname during release; this waiter can subsequently acquire the still-open but now unlinked inode here. While its extraction is running, a third extract/update recreates .rebuild.lock, locks a different inode, and runs concurrently, allowing the graph/cache corruption this change is intended to prevent. Ensure a successful waiter still owns the inode currently referenced by lock_path (or change the unlink protocol) before entering the pipeline.
Useful? React with 👍 / 👎.
What:
graphify extractnow takes the same advisory file lock (flock ongraphify-out/.rebuild.lock) that the watcher and git-hook rebuilds already take, and holds it for the entire extract pipeline.Why: extract and the watcher share
graphify-out/. Two writers racing on one output dir interleave cache saves and clobbergraph.json. With the lock, a second run waits its turn: it prints who holds the lock (PID), waits up toGRAPHIFY_LOCK_TIMEOUTseconds (default 600), and exits with a clear error instead of hanging forever behind a wedged rebuild.Tests:
tests/test_extract_lock.py(5 tests) — lock held during extract, contended-run wait, timeout exit, lock released on failure paths. All offline; the LLM/subprocess layers are mocked.🤖 Generated with Claude Code