Fix process-pool readiness under uneven worker startup - #982
Draft
bradhilton wants to merge 3 commits into
Draft
bradhilton wants to merge 3 commits into
bradhilton wants to merge 3 commits into
Conversation
This branch has not been deployed
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.
Process-pool startup used N short identity tasks as a census of N workers. With uneven imports, one early worker can finish several tasks before another is ready, causing the dispatcher to disable a healthy process backend. A public four-worker run returned only two distinct warmup PIDs despite startup evidence from all four children; a deterministic two-worker regression reproduces that race.
Pass a spawn-context barrier through each worker initializer so every readiness task occupies a distinct worker until all workers arrive. Keep the distinct-PID check, a shared 60-second parent wait deadline and bounded child barrier, and cleanup of the exact failed executor on startup/submission failure. Healthy waiter cancellation leaves the shared pool usable. Adaptive routing, worker limits, fallback policy, tokenization and result ordering remain unchanged. The timeout bounds readiness waits, not synchronous process creation.
Cleanup also coordinates with the executor manager: that thread can reap a child before publishing its exit status, while concurrent joins transiently report the child alive. Capture the manager before shutdown and give it the remaining final reap window, outside its shutdown lock and without self-joining. Killing workers and waiting for their manager share that final one-second window; a blocked manager cannot extend it. This does not add a guarantee of shutting down arbitrarily blocked user callback threads.
Validation: 14 focused controls pass, including delayed initialization, cancelled waiter/reuse, initializer failure, duplicate PID refusal, shared timeout, public fallback, spawned-family cleanup, original exception identity, a deterministic real-worker concurrent-reap regression, and the shared cleanup deadline/self-join boundaries. Eight inherited ordering/grouping/nonmutation/rebinding/error controls are retained. Ruff and focused type checks pass. The failed CI cleanup case and its causal reproduction remain retained; its assertion was preserved.
A separate finite public CPU run exercised the prior readiness implementation at naturally selected process widths 4, 8 and 16, with all 30 calls preserving complete results, source ownership and all masks. That run predates this final cleanup-only correction and does not prove production throughput or authorize a worker-limit change.