Skip to content

test(watch): stop the watcher test clock from breaking subprocess waits - #5449

Closed
Deepjyoti-Sarmah wants to merge 2 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:test/watch-helper-clock
Closed

Deepjyoti-Sarmah wants to merge 2 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:test/watch-helper-clock

Conversation

@Deepjyoti-Sarmah

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes intermittent failures in the watcher tests, which have made CI red on
several PRs since the suite went parallel (013a646):

FAILED tests/test_language_override_lifecycle.py::test_watch_...
FileNotFoundError: ... '/graphify-out/graph.json'

Example: this run on #5446,
with 7 failures in two files.

drive_watch did monkeypatch.setattr(watch_mod.time, "sleep", pump). That is
the shared time module, so time.sleep changed for the whole process:

_rebuild_code -> _git_head -> subprocess.run(git, timeout=3)
   git not reaped yet -> subprocess calls time.sleep(0.001)
   -> pump() has no events left -> KeyboardInterrupt
   -> rebuild aborted before graph.json is written

It is a race with git exiting, so load makes it likelier. The helper now
replaces the name time in watch.py only.

df0d002a  test(watch): pin the watcher helper's clock to watch()
6824a1cb  fix(watch): replace the clock in watch.py only in drive_watch

Marking these tests serial would not be enough: on v8 the two files also
failed without xdist, in 8 of 8 runs on a machine under CPU load.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

The invariant: the helper's clock controls only watch()'s own loop. Anything
else that sleeps during a rebuild gets the real clock.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

Merge Danger

Door: two-way. Only tests/test_language_override_lifecycle.py changes.

Blast radius: the tests that use drive_watch, in two files.

Limitations

  • If watch.py starts using another time function, the helper's stand-in
    needs it too. The tests would fail with AttributeError.
  • The new test forces the sleep that POSIX subprocess waits do. Windows waits
    differently, so it would not catch this there.

How was this tested?

The new test starts a child that closes its pipes and lives 0.3 s longer, so
subprocess has to sleep during the rebuild.

new test, 10 runs
    without the fix  -> 10 failed
    with the fix     -> 0 failed
the two watcher files, -n 4, 15 runs
    v8 (013a6461)    -> 13 runs failed
    with the fix     -> 0 runs failed
the two watcher files, no xdist, under CPU load, 8 runs
    v8               -> 8 runs failed
    with the fix     -> 0 runs failed
pytest tests/ -n 4 -m "not serial"   (TMPDIR=/dev/shm)
    this branch      -> 11879 passed, 122 skipped, 1 xfailed
pytest tests/ -m serial
    this branch      -> 20 passed
ruff check tests/test_language_override_lifecycle.py
    -> All checks passed

A trace of 4 parallel v8 runs had 17 test failures, and every unexpected sleep
came from _git_head. The full suite at -n 4 also passed once on v8, so one
green run alone proves little.

Python 3.13 on Linux. Not tested: Windows.

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (N/A: no skill fragments touched.)
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages. (No trailer in the commit messages.)

drive_watch replaces time.sleep for the whole process. A subprocess wait during
the rebuild then runs the fake clock and aborts the rebuild. Force that wait.
Patching watch_mod.time.sleep patched the shared time module, so waiting for git
in _git_head could raise KeyboardInterrupt before graph.json was written. The
parallel CI runs hit this often; a loaded serial run hits it too.
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @Deepjyoti-Sarmah. 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.11 and 3.13, and that the change keeps extraction deterministic.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 24, 2026

@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 review View in Graphify

Nothing blocking · 2 possible issues to check · Merge confidence 5/5

2 possible issues to check · Medium impact

2 possible issues we couldn't confirm

They don't change the score.

Code graph · 35 functions depend on this change
  • 2 of 620 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed 6824a1c · Full report in the Graphify check

@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.120 (authorship-preserving cherry-pick). This also turned out to be the root-cause fix for the watch-test flakiness under the parallel suite — the global time.sleep patch was breaking the subprocess waits a rebuild performs. Thanks @Deepjyoti-Sarmah!

@safishamsi safishamsi closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants