Skip to content

Watch: an emitter that dies before the first liveness tick is never reported - #1064

Closed
loonister1 wants to merge 3 commits into
tirth8205:stagingfrom
loonister1:fix/891-watch-an-emitter-that-dies-before-the-fi
Closed

loonister1 wants to merge 3 commits into
tirth8205:stagingfrom
loonister1:fix/891-watch-an-emitter-that-dies-before-the-fi

Conversation

@loonister1

Copy link
Copy Markdown
Contributor

check_liveness now distinguishes a thread that never ran (ident is None, still not a corpse) from one that ran and stopped, instead of requiring a previous tick to have recorded it alive. That closes the hole where an emitter dying between scheduling and the first tick could never be recorded as live and therefore never as dead, so a registration-time failure such as inotify ENOSPC now reaches the existing reschedule-once-then-report path rather than leaving a directory unwatched behind a healthy crg-daemon status.

Fixes #891

Testing

[targeted; 3 commit(s) checked individually] $ /Users/m2/Documents/PW/github-bot/work/tirth8205__code-review-graph/891/.venv/bin/python -m pytest -q --no-header tests/test_incremental.py tests/test_watch_robustness.py

Notes for reviewers

Three things to check, in order.

Liveness could only report a thread that a previous tick had recorded as
alive, so an emitter that stopped between being scheduled and the first
tick was never recorded and could never be reported. inotify watch
exhaustion fails exactly there: the watcher kept running, health kept
saying "alive", and that directory was never watched.

A stopped thread with an ident has run, which separates the corpse from
the emitter caught between construction and start without needing a tick
to have seen it alive.
Pins the case the liveness check could not reach: a scheduled watch whose
emitter stops before any tick sees it alive is noticed and rescheduled
instead of leaving the directory unwatched behind a healthy status.
@tirth8205

Copy link
Copy Markdown
Owner

Thank you for this PR. You found a real problem in the watcher.

I ran your new test on the old base and on staging. It fails on the old base. It passes on staging with no changes. So your test catches the bug.

The fix is already on staging, in commit d5eb1bc. It uses the same Thread.ident check. It shipped in v2.3.9. Issue #891 is already closed.

So I will not merge this PR. I will close it because the fix is already in.

Thank you again for your help.

Copilot AI 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.

🟢 Approval recommended

No active review issues were identified for the fix addressing watch threads that stop before the first liveness check.

No open issues 🎉

What changed in this PR

Fixes #891 by detecting watch threads that ran and stopped before the first liveness check, allowing them to enter the existing recovery and reporting path.

Changes:

  • Uses thread identity instead of previously observed liveness to detect stopped threads, while still ignoring unstarted threads.
  • Adds a regression test confirming an early emitter death triggers rescheduling.
  • Documents the fix in the changelog.
File Description
tests/​test_watch_robustness.py Tests emitter death before the first liveness check.
code_review_graph/​incremental.py Detects stopped threads without requiring a prior live observation.
CHANGELOG.md Records the early emitter-death detection fix.

Review effort: Balanced

@tirth8205

Copy link
Copy Markdown
Owner

Thank you for this. The same Thread.ident check landed in d5eb1bc (#988, shipped in 2.3.9), and your test passes on staging unchanged, so #891 is fixed. Closing as already done.

@tirth8205 tirth8205 closed this Nov 9, 2026
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.

watch: an emitter that dies before the first liveness tick is never reported

3 participants