[zephyr] Fix coordinator loop crash causing silent pipeline hangs#4008
Merged
[zephyr] Fix coordinator loop crash causing silent pipeline hangs#4008
Conversation
yonromai
commented
Mar 23, 2026
| def _log_status(self) -> None: | ||
| alive = sum(1 for s in self._worker_states.values() if s in {WorkerState.READY, WorkerState.BUSY}) | ||
| dead = sum(1 for s in self._worker_states.values() if s in {WorkerState.FAILED, WorkerState.DEAD}) | ||
| with self._lock: |
Contributor
Author
There was a problem hiding this comment.
FYI @rjpower : Claude told me this ^ race condition killed my tokenize job, and after I told it that it's very unlikely to trigger, it accepted that the cause of the tokenization job failing was likely something else (hence additional logging in #4006 ). It still insisted this race condition can occur (see test) and bullied me into opening this PR.
Collaborator
There was a problem hiding this comment.
seems legit. if we have 2000 workers, and log_status happens to trigger around when a worker pings?
rjpower
approved these changes
Mar 23, 2026
| def _log_status(self) -> None: | ||
| alive = sum(1 for s in self._worker_states.values() if s in {WorkerState.READY, WorkerState.BUSY}) | ||
| dead = sum(1 for s in self._worker_states.values() if s in {WorkerState.FAILED, WorkerState.DEAD}) | ||
| with self._lock: |
Collaborator
There was a problem hiding this comment.
seems legit. if we have 2000 workers, and log_status happens to trigger around when a worker pings?
) _log_status() iterated _worker_states without the lock, racing with register_worker() on RPC threads. The resulting RuntimeError killed the coordinator daemon thread silently — no abort, no _fatal_error — so _wait_for_stage() hung forever on the last in-flight shard. Fix: snapshot shared state under the lock in _log_status(), and wrap the coordinator loop body in try/except that routes crashes through abort() so pipelines fail fast instead of hanging. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
82802c0 to
cdb72c8
Compare
Helw150
pushed a commit
that referenced
this pull request
Apr 8, 2026
) ## Summary Fixes #3996. The coordinator daemon thread could crash from an unhandled `RuntimeError` (dict mutation during iteration), killing heartbeat checking and causing pipelines to hang at N-1/N with no error. - **`_log_status()`**: snapshot `_worker_states` under `self._lock` before iterating - **`_coordinator_loop()`**: wrap loop body in `try/except` that calls `abort()`, so any crash sets `_fatal_error` and unblocks `_wait_for_stage` immediately ## Test plan - [x] `test_coordinator_loop_crash_aborts_pipeline` — verified red before patch, green after: injected crash sets `_fatal_error` instead of silently killing the thread - [x] All 29 local execution tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: yoblin <268258002+yoblin@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
Fixes #3996. The coordinator daemon thread could crash from an unhandled
RuntimeError(dict mutation during iteration), killing heartbeat checking and causing pipelines to hang at N-1/N with no error._log_status(): snapshot_worker_statesunderself._lockbefore iterating_coordinator_loop(): wrap loop body intry/exceptthat callsabort(), so any crash sets_fatal_errorand unblocks_wait_for_stageimmediatelyTest plan
test_coordinator_loop_crash_aborts_pipeline— verified red before patch, green after: injected crash sets_fatal_errorinstead of silently killing the thread🤖 Generated with Claude Code