Add poll-loop liveness watchdog to auto-restart wedged workers#411
Closed
manan164 wants to merge 1 commit into
Closed
Add poll-loop liveness watchdog to auto-restart wedged workers#411manan164 wants to merge 1 commit into
manan164 wants to merge 1 commit into
Conversation
Workers occasionally stop polling and stay stopped until manually restarted. The poll loop runs poll + execute + update on one thread (a single event loop for async workers); if a poll/update call never returns (e.g. a stale keep-alive connection silently dropped by a proxy/LB/NAT, which never reaches the server so server metrics stay clean) or a blocking call freezes the loop, polling halts with no error. TaskHandler already supervises and restarts worker processes, but only when is_alive()==False (task_handler.py). A wedged-but-alive process is invisible to it, so the worker stays dead until an operator restarts it. This adds a liveness watchdog to both TaskRunner and AsyncTaskRunner: run_once() records a monotonic heartbeat each iteration (a healthy loop reaches it within ms even at full capacity), and a daemon thread (so a frozen loop can't block it) exits the process via os._exit when the loop has been silent past CONDUCTOR_WORKER_POLL_STALL_TIMEOUT_SECONDS (default 300s, 0 to disable). The existing supervisor then restarts it, turning a permanent stall into a few-second blip. This is a defense-in-depth backstop for the symptom, not a root-cause fix: it auto-recovers a stalled worker regardless of why it wedged, and its critical log points operators at capturing a stack dump (py-spy dump --pid) to diagnose the underlying blocked call. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
Contributor
Author
|
Closing — the watchdog is a band-aid, not a root-cause fix. Reverting to diagnose the actual cause first. |
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.
Problem
Workers occasionally stop polling and stay stopped until manually restarted (reported by a customer running async workers, HTTP/1.1,
thread_count=8, fast ~10ms tasks; server metrics clean during the stall).The poll loop runs poll → execute → update on a single thread (one event loop for async workers). If an SDK→server HTTP call never returns — e.g. a stale keep-alive connection silently dropped by a proxy/LB/NAT (no RST), which never reaches the server so server metrics stay clean — or a blocking call freezes the loop, polling halts with no error and no crash.
TaskHandleralready supervises and restarts worker processes, but only whenprocess.is_alive()==False. A wedged-but-alive process is invisible to it, so the worker stays dead until an operator restarts it.What this changes
Adds a poll-loop liveness watchdog to both
TaskRunnerandAsyncTaskRunner:run_once()records a monotonic heartbeat each iteration. A healthy loop reaches it within milliseconds even at full capacity (a busy loop still spins), so this does not false-positive on legitimately busy workers.os._exit(70)once the loop has been silent pastCONDUCTOR_WORKER_POLL_STALL_TIMEOUT_SECONDS(default 300s,0disables).restart_on_failure) then restarts the worker — turning a permanent stall into a few-second blip.Scope / honesty
This is a defense-in-depth backstop for the symptom, not a root-cause fix. It auto-recovers a stalled worker regardless of why it wedged. The critical log it emits points operators at capturing a stack dump (
py-spy dump --pid <pid>) to diagnose the underlying blocked call.Empirically, the httpx transport the SDK uses does time out and self-heal on a half-open connection (verified locally), so the bounded-stall case already recovers; this watchdog covers the permanent-wedge case that the supervisor's
is_alive()-only check cannot.Config
CONDUCTOR_WORKER_POLL_STALL_TIMEOUT_SECONDS3000disablesTests
tests/unit/automator/test_poll_stall_watchdog.py— env parsing, stall/fresh/disabled/shutdown decision logic for both runners. All 13 pass; existing 52 runner tests still pass.🤖 Generated with Claude Code