Skip to content

fix(config): derive and validate dynamic pool bounds at validation time - #2217

Merged
jerome-benoit merged 8 commits into
mainfrom
fix/2207-dynamic-pool-bounds
Nov 27, 2026
Merged

jerome-benoit merged 8 commits into
mainfrom
fix/2207-dynamic-pool-bounds

Conversation

@jerome-benoit

@jerome-benoit jerome-benoit commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

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 are DEFAULT_POOL_MIN_SIZE = max(1, floor(cpus / 2)) and DEFAULT_POOL_MAX_SIZE = max(min, round(cpus * 1.5)) (src/worker/WorkerConstants.ts), while poolifier's dynamic pool requires min < 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

WorkerConfigurationSchema validates poolMinSize and poolMaxSize independently (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 opaque RangeError.

Fix

Resolve the bounds at validation time (validateConfiguration, after the strict schema parse):

  • Both explicit: must be strictly ordered (min < max), else a ConfigurationValidationError with structured field errors on worker.poolMaxSize.
  • Only poolMinSize: the maximum is derived — max(default, min + 1); a minimum at the safe-integer ceiling is rejected (no strictly larger safe integer exists).
  • Only poolMaxSize: the minimum is derived — min(default, max - 1); a maximum of 1 is rejected (no positive minimum below the maximum exists).
  • None explicit: validation leaves both bounds absent; the CPU-based defaults apply during runtime defaulting.

Fixed-pool and workerSet configurations are returned unchanged (fixedPool consumes only poolMaxSize; workerSet ignores both bounds). The effective process type defaults to workerSet when 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 with min >= 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).

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
autofix-ci Bot and others added 5 commits November 27, 2026 17:27
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
jerome-benoit force-pushed the fix/2207-dynamic-pool-bounds branch from d0de8ff to 2eedd74 Compare November 27, 2026 18:40
- 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'.
@jerome-benoit
jerome-benoit merged commit f76cf88 into main Nov 27, 2026
44 checks passed
@jerome-benoit
jerome-benoit deleted the fix/2207-dynamic-pool-bounds branch November 27, 2026 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] dynamicPool: setting only worker.poolMinSize or worker.poolMaxSize can fail at startup depending on the CPU count

1 participant