Repository navigation
fix(config): derive and validate dynamic pool bounds at validation time - #2217
Merged
Merged
Conversation
With worker.processType: "dynamicPool", an omitted pool bound fell back to its own CPU-based default, independently of the other bound. A configuration setting only one bound could then be valid on one machine and fail on another, or fail outright: poolifier rejects min >= max in the pool constructor, deep inside the Bootstrap constructor, with an opaque RangeError. Resolve the bounds at validation time instead: - Both explicit: must be strictly ordered (min < max), else a ConfigurationValidationError with structured field errors. - Only poolMinSize: the maximum is derived (max(default, min + 1)). - Only poolMaxSize: the minimum is derived (min(default, max - 1)); a maximum of 1 is rejected (the minimum would be 0). - None explicit: CPU-based defaults apply unchanged. Fixed-pool and workerSet configurations are returned unchanged: fixedPool consumes only the maximum and workerSet ignores both bounds. README defaults table now shows the CPU-based formulas and documents the per-mode bounds semantics. Fixes #2207
A minimum at the safe-integer boundary made the derived maximum unrepresentable (2^53, outside safe integers); it sailed past schema parsing and failed at boot with an unstructured RangeError from poolifier. The resolver now rejects configuredMin >= Number.MAX_SAFE_INTEGER with a structured ConfigurationValidationError (phase: 'schema', path worker.poolMinSize). Tests: rename new block to the 'should ...' convention; cover the CPU-floor/cap branches (min below/above the defaults), max-only 2 -> min 1, omitted processType, and the safe-integer guard. Fixes #2207
- Error message and README now say 'no larger safe integer exists' instead of 'non-representable' / 'above the safe-integer range' (2^53 is representable but outside the safe-integer range). - Omitted-processType test now uses a reversed pair so it actually discriminates the intended workerSet default from a wrong dynamicPool routing. - New test pinning the CPU-default-win side of the minimum derivation.
Assert poolMinSize = MAX_SAFE_INTEGER - 1 derives poolMaxSize = MAX_SAFE_INTEGER (the boundary acceptance path that was previously only covered by the rejection test).
jerome-benoit
force-pushed
the
fix/2207-dynamic-pool-bounds
branch
from
November 27, 2026 18:40
d0de8ff to
2eedd74
Compare
- ValidationPhase JSDoc now names the dynamic-pool bounds resolution (ordering, safe-integer ceiling, derivation and rejection) that the 'schema' phase also performs. - Near-ceiling test title reflects the input (one below the ceiling); redundant isSafeInteger assertion removed (strictEqual to MAX_SAFE_INTEGER already implies safety).
- Maximum-of-one message now names the actual violated constraint (a positive minimum smaller than the maximum) instead of claiming min < max is unmet (0 < 1 would satisfy that inequality). - Resolver JSDoc distinguishes explicit-bounds validation and single-bound derivation from the both-omitted case (validation leaves bounds absent; defaults apply later). - README dynamicPool bullet: state the two derivation cases with the exact formulas and the both-omitted case separately. - validateConfiguration JSDoc: mention dynamic-pool bounds resolution in the pipeline and bounds failures alongside schema/migration failures. - fixed-pool/workerSet test titles use 'leave bounds unchanged' instead of 'ignore bounds'.
Merged
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.
Closes #2207
Problem
With
worker.processType: "dynamicPool", each pool bound omitted from the configuration falls back to its own CPU-based default, independently of the other bound (Bootstrap.ts:poolMinSize ?? DEFAULT_POOL_MIN_SIZE,poolMaxSize ?? DEFAULT_POOL_MAX_SIZE). The defaults areDEFAULT_POOL_MIN_SIZE = max(1, floor(cpus / 2))andDEFAULT_POOL_MAX_SIZE = max(min, round(cpus * 1.5))(src/worker/WorkerConstants.ts), while poolifier's dynamic pool requiresmin < max.A configuration that sets only one bound can be valid on one machine and fail on another, and the configuration schema accepts it because each key is checked on its own. The README also claimed static defaults of 4 / 16.
Root cause
WorkerConfigurationSchemavalidatespoolMinSizeandpoolMaxSizeindependently (z.number().int().positive().optional()), with no cross-field refinement for dynamic pools. The bounds are filled independently at several layers (Configuration.ts,Bootstrap.ts,WorkerFactory.ts— all with the CPU-based constants), and nothing checks their relationship. The failure surfaces in poolifier's dynamic-pool constructor, deep inside the Bootstrap constructor, with an opaqueRangeError.Fix
Resolve the bounds at validation time (
validateConfiguration, after the strict schema parse):min < max), else aConfigurationValidationErrorwith structured field errors onworker.poolMaxSize.poolMinSize: the maximum is derived —max(default, min + 1); a minimum at the safe-integer ceiling is rejected (no strictly larger safe integer exists).poolMaxSize: the minimum is derived —min(default, max - 1); a maximum of 1 is rejected (no positive minimum below the maximum exists).Fixed-pool and workerSet configurations are returned unchanged (fixedPool consumes only
poolMaxSize; workerSet ignores both bounds). The effective process type defaults toworkerSetwhen omitted.Also centralizes the default process type (
DEFAULT_WORKER_PROCESS_TYPE) and updates the README defaults table (static 4/16 → CPU-based formulas) and the process-model section (per-mode bounds semantics).Tests
17 regression tests in
tests/utils/ConfigurationValidation.test.ts(dynamic pool bounds resolution): derive max from min, derive min from max, reject max=1 without min, reject explicit pairs withmin >= max(two forms), keep valid explicit pair, omit bounds (defaults later), leave bounds unchanged in fixedPool/workerSet, legacy alias keys derive canonical bounds, plus safe-integer-ceiling and default-process-type boundaries.Validation: ConfigurationValidation 69/69 · config-related suites 254/254 · Configuration 15/15 · typecheck/eslint/build green.
Breaking change
No. Public signatures unchanged. Behavior for dynamic pool configurations with a single bound changes from startup-time failure (unvalidated pair vs the CPU-based defaults) to validation-time derivation when possible — and to a structured field error when not (maximum of 1, minimum at the safe-integer ceiling).
AI-generated code
Code and tests were developed with AI assistance (SAP Open Source AI contribution guideline — the author is responsible for compliance with the tool's terms and for licensing, per the SAP AI contribution guideline).