Repository navigation
Conversation
The GRAPHIFY_REBUILD_TIMEOUT watchdog in both embedded rebuild bodies was guarded by hasattr(signal, 'SIGALRM') with no else branch, so on Windows it never armed and a hung rebuild survived indefinitely -- the exact tail case the Graphify-Labs#791 timeout was added to catch. Fall back to a daemon threading.Timer that prints the same message and calls os._exit(1). The hard exit is deliberate: the process is already stuck, so a clean shutdown may itself be blocked, and _rebuild_lock degrades to a no-op yield on platforms without fcntl, so there is no lock to leave stale.
There was a problem hiding this comment.
Pull request overview
This PR fixes GRAPHIFY_REBUILD_TIMEOUT being a no-op on Windows by adding a portable watchdog fallback to the embedded post-commit and post-checkout rebuild bodies, ensuring hung rebuild subprocesses are terminated even when signal.SIGALRM is unavailable.
Changes:
- Added a
threading.Timer-based watchdog fallback (usingos._exit(1)) whenSIGALRMis not present, in both embedded rebuild bodies. - Updated the embedded scripts’ imports to include
threading. - Added an AST-structural test that enforces the fallback lives specifically in the
elsebranch of theSIGALRMcheck and includes boththreading.Timerandos._exit.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
graphify/hooks.py |
Arms the rebuild timeout on Windows by adding a threading.Timer watchdog fallback in both embedded rebuild bodies. |
tests/test_hooks.py |
Adds an AST-based regression test ensuring the non-SIGALRM timeout fallback exists and is structured correctly. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The post-checkout body logs with [graphify] throughout, but the new non-SIGALRM fallback used [graphify hook], so the same timeout read differently depending on the platform. The post-commit body does use [graphify hook] everywhere, so only the checkout copy was wrong. Assert each body uses a single log prefix so this cannot drift again.
|
Thanks @Rishet11. Shipped in v0.9.26 (cherry-picked to v8 as ca3113a, 0da6929 to preserve your authorship). Closed-unmerged here, but it is in the release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.26 |
Problem
GRAPHIFY_REBUILD_TIMEOUTis a silent no-op on Windows, so a hung rebuild survives indefinitely — the exact tail case the #791 timeout was added to catch.Both embedded rebuild bodies in
graphify/hooks.py(_REBUILD_BODY_COMMIT,_REBUILD_BODY_CHECKOUT) armed the watchdog like this:Root cause:
signal.SIGALRMdoes not exist on Windows and there is noelsebranch, so the whole guard is skipped and no watchdog is ever armed. The env var is read, then ignored.@epocamx measured this on a real repo with a ~20-min auto-commit daemon: 916 rebuild starts, 909 clean finishes, 0 timeout lines ever logged, 7 starts with no matching finish, and at one snapshot 16 detached rebuild processes still alive 10+ hours past their logged completion, regardless of the
GRAPHIFY_REBUILD_TIMEOUTvalue.Fix
Nest the existing check and add a
threading.Timerfallback for the non-SIGALRM case, in both bodies (the two blocks were byte-identical, and remain so):threadingadded to each body's existingimport os, signal, sysline.Three notes on the choices, since they are deliberate:
os._exit(1)rather than an exception. The process being killed is already stuck, so a clean shutdown may itself be blocked. It is also safe here specifically:_rebuild_lockingraphify/watch.py"falls back to a no-op yield(True) on platforms without fcntl (Windows)" (its own docstring), so on the only platform that reaches this branch there is no lock to leave stale.graph.jsonwrites go throughwrite_json_atomic, so an abrupt exit cannot truncate a good graph.print.os._exitskips the surroundingexcept TimeoutErrorhandler that logs on the POSIX path, so without it the kill would be silent. Message text and destination match the SIGALRM path exactly;flush=Truebecauseos._exitskips the normal stdio flush.daemon = True, and the timer is never cancelled. This is a one-shot hook script, so the daemon thread dies with the interpreter on a normal finish and cannot fire after the rebuild it guards has already exited.Both bodies are carried inside a shell double-quoted
-c "..."argument, so the added lines contain no",$, backtick or backslash, and no'''—test_rebuild_bodies_are_shell_quote_safecovers this and passes.Testing
Added
test_rebuild_bodies_arm_a_timeout_without_sigalrmintests/test_hooks.py, parametrized over both bodies so patching only one still fails.It asserts structurally via
ast, not by substring presence: it finds theifwhose test mentions'SIGALRM', requires a non-emptyorelse, and requiresthreading.Timerandos._exitto appear inside thatorelse. I verified it actually fails on wrong implementations:tests/test_hooks.py:12 failed, 48 passed, versus12 failed, 46 passedbefore the change — the same 12 pre-existing failures, plus my 2 new cases. Those 12 are local to my machine (a broken editable install:uv run graphify --helpfails withModuleNotFoundError: No module named 'graphify'both with and without this change), not introduced here.Full suite, same environment, both commits:
Collected count rises by exactly 2. No new failures; one pre-existing failure flipped to pass, which looks flaky and is unrelated.
Scope
Hook rebuild bodies only.
graphify watchhas its own timeout path and is untouched — happy to extend this there in a follow-up if you'd like it covered too.Fixes #2148