Deprecate size parameter on WorkerPool in favor of spawn#135
Merged
conradbzura merged 5 commits intowool-labs:mainfrom Mar 28, 2026
Merged
Deprecate size parameter on WorkerPool in favor of spawn#135conradbzura merged 5 commits intowool-labs:mainfrom
conradbzura merged 5 commits intowool-labs:mainfrom
Conversation
The size/lease pair reads ambiguously — size could mean total pool capacity rather than the number of spawned workers. Renaming to spawn makes the semantics explicit. WorkerPool(spawn=N) is the primary API. WorkerPool(size=N) continues to work but emits a DeprecationWarning. Passing both raises TypeError. All internal references (_resolve_spawn, match arms, _worker_context) now use spawn as the canonical name. BREAKING CHANGE: _resolve_size renamed to _resolve_spawn; error message changed from "Size must be non-negative" to "Spawn must be non-negative"
All existing tests now use spawn= instead of size= to exercise the primary API. Four new tests cover the deprecation path: warning emission, no-warning for spawn, TypeError on both, and value forwarding from size to spawn.
Five new tests cover the deprecated size parameter interacting with other code paths: negative value forwarding, zero/CPU-count resolution, hybrid mode with discovery, lease combination, and stacklevel correctness. Two stale test names referencing "size" are also fixed.
Replace size with spawn in all examples, the mode table, and the architecture diagram. Add lease as a column in the mode table and split the spawn/lease explanation into separate paragraphs for clarity.
This was referenced Mar 28, 2026
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
Rename the
sizeparameter onWorkerPooltospawnacross all three__init__overloads and internal implementation. Thesize/leaseparameter pair read ambiguously —sizecould refer to total pool capacity rather than the number of spawned workers. The newspawnname makes the semantics explicit:spawnis how many workers the pool starts,leaseis how many additional discovered workers it accepts.WorkerPool(size=N)continues to work at runtime via aDeprecationWarning, and type checkers (pyright, mypy) flag it at static analysis time via PEP 702@deprecatedoverloads. Passing bothsizeandspawnraisesTypeError. All internal references (_resolve_spawn,_worker_context, match arms) and README documentation usespawnas the canonical name.Closes #134
Proposed changes
Rename
sizetospawnin the implementation signatureReplace
sizewithspawnin all three@overloadsignatures (ephemeral, durable, hybrid) and the implementation body. Rename the_resolve_sizehelper to_resolve_spawnand update its error message from"Size must be non-negative"to"Spawn must be non-negative". The_worker_contextmethod parameter and all match-arm bindings now usespawn.Add runtime deprecation bridge for
sizeThe implementation signature accepts both
spawnandsizeas optional parameters. Whensizeis provided alone, emit aDeprecationWarningatstacklevel=2(pointing to the caller's frame) and forward the value tospawn. When both are provided, raiseTypeError.Update README documentation
Replace
sizewithspawnin all code examples across the worker, discovery, and load-balancer READMEs. Update the mode table to usespawnas the column header and rewrite the spawn/lease explanation for clarity.Test cases
TestWorkerPoolsizeparameter is passedWorkerPoolis initializedDeprecationWarningTestWorkerPoolspawnparameter is passedWorkerPoolis initializedDeprecationWarningis emittedTestWorkerPoolsizeandspawnparameters are providedWorkerPoolis initializedTypeErrorTestWorkerPoolsizeparameter with value 4WorkerPoolis initializedspawn=4TestWorkerPoolsizeparameter with value -1WorkerPoolis initializedDeprecationWarningand raiseValueErrorTestWorkerPoolsizeparameter with value 0 and CPU count availableWorkerPoolis initializedDeprecationWarningand create a valid poolTestWorkerPoolsizeparameter and a discovery serviceWorkerPoolis initializedDeprecationWarningand create a valid poolTestWorkerPoolsizeparameter with value 4 and lease of 8WorkerPoolis initializedDeprecationWarningand create a valid poolTestWorkerPoolsizeparameter is passedWorkerPoolis initialized