refactor(#101): extract systemd watchdog group to sd_watchdog.py - #198
Merged
Conversation
Behavior-preserving extraction of the three systemd-integration helpers from main.py into a dedicated sd_watchdog.py module (#101 / #135): - `_sd_notify` — NOTIFY_SOCKET datagram (READY=1, WATCHDOG=1, …) - `_watchdog_interval`— WATCHDOG_USEC → seconds budget - `_watchdog_loop` — health-gated keepalive coroutine main.py re-exports all three under their original `_`-prefixed names, so the lifespan startup and existing callers are untouched. `watchdog_loop` reaches back into main's namespace (`_repair_state`, `_mp`, `_sd_notify`, `_log`) via a function-local `import main`, so tests/test_watchdog_rebuild.py — which patches `main._sd_notify` / `main._mp._get_collection` and mutates `main._repair_state` — keeps passing with no edits. Same lazy-import pattern as fast_intercept (#133) and daemon_tools (#131). Module is named `sd_watchdog` (not `watchdog`) on purpose: a top-level `watchdog.py` on the daemon's sys.path would shadow the pip `watchdog` package that watcher.py imports for its filesystem observers. main.py: 3161 → 3116 lines. Full suite green (582 passed, 1 skipped). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Incremental progress on the
main.pydecomposition (#101 / status doc #135). One slice, behavior-preserving — not a full split.What moved
The three systemd-integration helpers from the top of
main.py→ a dedicatedsd_watchdog.py:_sd_notifyNOTIFY_SOCKETdatagram (READY=1, WATCHDOG=1, …)_watchdog_intervalWATCHDOG_USEC→ seconds budget_watchdog_loopmode=rebuildrepair)Logic is byte-identical — only the names
_watchdog_loopreaches back for (_repair_state,_mp,_sd_notify,_log) becamemain.-qualified.How tests stay green without edits
main.pyre-exports all three under their original_-prefixed names.watchdog_loopresolves main's mutable module state (_repair_state,_mp) and the notifier (_sd_notify) at call time via a function-localimport main, sotests/test_watchdog_rebuild.py— which doespatch.object(main, "_sd_notify"),patch.object(main._mp, "_get_collection"), and mutatesmain._repair_state— keeps passing untouched. Same lazy-import pattern documented forfast_intercept(#133) anddaemon_tools(#131).Naming note
The module is
sd_watchdog, notwatchdog, on purpose: a top-levelwatchdog.pyon the daemon'ssys.pathshadows the pipwatchdogpackage thatwatcher.pyimports for its filesystem observers (verified the shadow occurs, then renamed to avoid it).Verification
main.py: 3161 → 3116 linespython -c "import main"+import watcher(pipwatchdogresolves toInotifyObserver, not the local module) — both cleantests/test_watchdog_rebuild.py— 4 passed🤖 Generated with Claude Code