← Back to Pull requests

Fix three races in how the pool counts and hands out workers #452

Closed
unknown closed this pull request without merging on Nov 30, 2026 06:12 UTC
View on GitHub
unknown unknown commented on Nov 30, 2026 04:41 UTC
Author

Four small races in how the pool counts and hands out workers. Each has a deterministic test that forces the interleaving and fails on main. No API change.

1. A pool at its minimum can drop below it. done_with_process reads the busy count and then the idle count. A second worker that finishes in between is in both, so the first one looks surplus and is stopped. The default pool (no min_workers, so the minimum is max_workers) is affected too: it loses a worker until the next get_process finds none idle and starts one. Fixed by reading both counts under _workers_lock.

2. A task can wait although the pool has room. get_process starts a worker for a task and then takes one from the queue. Another task can take that worker first, and the first then waits on the queue for a busy worker to return. Fixed by starting and taking under a new lock, _checkout_lock. When the pool really is full, the wait happens outside it.

3. clear_workers can block. It checks empty() and then calls a blocking get(); a task can take the last worker in between. Fixed with get_nowait.

4. clear_workers can strand a task. A task counts one idle worker and so does not start one; the clear takes that worker first; the task then waits with nothing busy and nothing idle. Fixed by having the clear take each worker under _checkout_lock. Workers are stopped outside it and still one at a time, so a worker returned during the clear is cleared too.

Cost. Worker starts are now one at a time per pool. Starting one took 0.3 ms at the median and 6.5 ms at worst with forkserver here (spawn 0.7 and 14.8, fork 0.5 and 1.4).

Tests. tests/test_worker_accounting.py. Reverting each fix on its own fails its test.

The full suite passes on Python 3.10, 3.11, 3.12, 3.13, 3.14 and 3.14t with the GIL off (203 passed on each, 3.14t four times). The new tests ran 60 times, four at a time, on each of 3.10, 3.13 and 3.14t without a failure. black is clean.

Next

Agreed in the review: an opt-in idle timeout in its own PR (minimum read live, most recently used order only when it is set, no thread otherwise), then a stop deadline in its own PR. The refresh of kept workers is under discussion below.

Diff: 279 lines (+209 / -70) across 3 files Reviewer: cjrh Review duration: 90m
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 279 lines diff across 3 files
0.40
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
56%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.337
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #452"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 56.8% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 39.6% (MEDIUM) · Higher = larger blast radius
39.6%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 56.8% · Lower = rushed or shallow review
56.8%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 17.1% · Safe to merge
17.1%
Repository