Add upper-limit support to WorkerPool size — Closes #132#133
Merged
conradbzura merged 3 commits intowool-labs:mainfrom Mar 27, 2026
Merged
Add upper-limit support to WorkerPool size — Closes #132#133conradbzura merged 3 commits intowool-labs:mainfrom
conradbzura merged 3 commits intowool-labs:mainfrom
Conversation
8f44638 to
ebe1191
Compare
ebe1191 to
0041100
Compare
conradbzura
commented
Mar 27, 2026
3257020 to
9ceeb93
Compare
b0485b9 to
6a069e0
Compare
Lease specifies the maximum number of additional discovered workers the pool will accept. The total pool capacity is size + lease when both are set, or just lease for durable (discovery-only) pools. The lease is a cap on admission, not a reservation. Zero is allowed when size is set (caps at exactly the spawn count) but rejected for discovery-only pools where it would be nonsensical. WorkerProxy enforces lease > 0 since it always receives the computed total (size + lease), never the raw zero. Size resolution is extracted to a typed module-level _resolve_size helper. The sentinel guards worker-updated events for never-added workers.
Cover the lease parameter across all pool modes including default and durable. Zero lease accepted with size, rejected for discovery-only. WorkerProxy lease validation tested independently. Includes drop-then-add and update-for-rejected-worker tests. Uses _drain_discovery helper polling proxy.workers instead of accessing private sentinel state.
Both READMEs explain the lease parameter with examples for hybrid and durable modes. Clarify that the lease count is a cap on admission, not a reservation — discovered workers may serve multiple pools and slots are not guaranteed to stay filled.
6a069e0 to
ae2f009
Compare
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
Add a
leaseparameter toWorkerPoolthat caps how many additional discovered workers the pool will accept. The total pool capacity issize + leasewhen both are set, or justleasefor durable (discovery-only) pools. Zero is allowed whensizeis set (caps at exactly the spawn count) but rejected for discovery-only pools. The lease count is a cap on admission, not a reservation — discovered workers may serve multiple pools simultaneously, and there is no guarantee that a leased slot will remain filled for the life of the pool. Omittingleasepreserves existing behavior (unbounded).The cap is enforced at the
WorkerProxysentinel level — the single point through which all discovered workers flow into the loadbalancer.WorkerProxyenforceslease > 0independently since it always receives the computed total (size + lease), never the raw zero. The sentinel guardsworker-updatedevents for never-added workers to prevent stale updates leaking through the cap. Theleasevalue survives pickling via__reduce__so the cap is preserved across nested routine dispatch.Size resolution is extracted to a typed module-level
_resolve_sizehelper to eliminate duplicated validation across match arms.Closes #132
Proposed changes
Lease parameter and validation (pool.py)
Add
lease: int | None = Noneto all three__init__overloads and the implementation signature. Reject negative lease values universally; reject zero lease only for discovery-only pools where it would be nonsensical. Extract a_resolve_size(size: int) -> intmodule-level helper that resolvessize=0to CPU count and validatessize >= 0. Computemax_workers = size + leasein each match arm after size resolution, forwarding the total toWorkerProxyin all four branches — including the durable branch which passes the rawleasesince there is no spawn count to add.Cap enforcement in the worker sentinel (proxy.py)
Add a
lease: int | Noneparameter toWorkerProxywith its own< 1validation and:paramdocumentation. In the sentinel, skip"worker-added"discovery events when the loadbalancer already holds>= leaseworkers. Guard"worker-updated"events so updates for never-added workers (rejected by the cap) are silently dropped rather than passed to the loadbalancer. Includeleasein__reduce__so the cap survives pickling for nested routine dispatch.Documentation (README.md, src/wool/runtime/worker/README.md)
Update both the root README and worker subpackage README to explain the
leaseparameter with code examples for hybrid and durable pool modes. Clarify that the lease count is a cap on admission, not a reservation.Test cases
TestWorkerPoolTestWorkerPoolTestWorkerPoolTestWorkerPoolTestWorkerPoolTestWorkerPoollease=6(size + lease)TestWorkerPoollease=6(size + lease)TestWorkerPoollease=6TestWorkerPoollease=cpu_count+4TestWorkerPoollease=NoneTestWorkerPoolTestWorkerPoolTestWorkerProxylease=0TestWorkerProxylease=-1TestWorkerProxylease=5TestWorkerProxylease=2and 3 worker-added eventsTestWorkerProxylease=Noneand 3 worker-added eventsTestWorkerProxylease=2at capacity, worker-updated eventTestWorkerProxylease=2at capacity, drop then addTestWorkerProxylease=1, rejected worker then updatedTestWorkerProxylease=2