Skip to content

Class: PoolManager ​

Defined in: runtime/pools/pool-manager.ts:25

Runtime capacity pool scheduler managing run-sticky account seat affinity, HTTP 429 rate-limit failover, and empirical 'escalate-on-retry' model selection (SPEC.md §3.2).

Ensures that all turns and child forks within a runId stick to the same account seat until rate-limited (429), while escalating model tiers on retries or low empirical completion rates.

Constructors ​

Constructor ​

ts
new PoolManager(): PoolManager;

Returns ​

PoolManager

Methods ​

recordModelOutcome() ​

ts
recordModelOutcome(
   poolId, 
   candidateId, 
   succeeded
): void;

Defined in: runtime/pools/pool-manager.ts:148

Records a completed or failed execution outcome for candidateId in poolId.

Updates sampleCount and successCount used by 'escalate-on-retry' (minSuccessRate / minSamples).

Parameters ​

ParameterTypeDescription
poolIdstringIdentifier of the model pool.
candidateIdstringIdentifier of the model candidate (model.modelId or model.alias).
succeededbooleanTrue when the model execution completed and passed evaluation.

Returns ​

void


recordRateLimit429() ​

ts
recordRateLimit429(
   poolId, 
   candidateId, 
   resetAtMs
): void;

Defined in: runtime/pools/pool-manager.ts:128

Records an HTTP 429 rate-limit cooldown until resetAtMs for candidateId in poolId.

Automatically evicts any run-sticky seat affinity pointing to candidateId so subsequent turns fail over to another seat or fallbackItem.

Parameters ​

ParameterTypeDescription
poolIdstringIdentifier of the capacity pool.
candidateIdstringIdentifier of the rate-limited seat or model (seat.id or model.modelId).
resetAtMsnumberEpoch timestamp in milliseconds when the rate limit resets.

Returns ​

void


releaseRunSeats() ​

ts
releaseRunSeats(runId): void;

Defined in: runtime/pools/pool-manager.ts:164

Releases all sticky seat bindings associated with runId across all managed pools.

Invoked when a flow run reaches a terminal exit state.

Parameters ​

ParameterTypeDescription
runIdstringCompleted or terminated flow run identifier.

Returns ​

void


selectModel() ​

ts
selectModel<TModel>(
   modelOrPool, 
   runId, 
   options?
): TModel;

Defined in: runtime/pools/pool-manager.ts:91

Resolves a single ModelASTNode or selects a candidate from a model PoolNode for runId.

Evaluates 'escalate-on-retry', standard, or custom pool strategies using retryAttempt and empirical completion rates tracked per model candidate.

Type Parameters ​

Type ParameterDescription
TModel extends ModelASTNodeModel AST node type.

Parameters ​

ParameterTypeDefault valueDescription
modelOrPoolTModel | PoolNode<TModel>undefinedDirect model node or model pool node.
runIdstringundefinedActive flow run identifier.
options?| number | PoolModelSelectionOptions0Retry attempt number or selection options.

Returns ​

TModel

Selected model AST node.


selectSeat() ​

ts
selectSeat<TSeat>(
   pool, 
   runId, 
   nowMs?
): TSeat;

Defined in: runtime/pools/pool-manager.ts:43

Selects an account seat from pool for runId, preserving run-sticky seat affinity when healthy.

Reuses the seat previously bound to runId unless that seat is currently rate-limited past nowMs, in which case it fails over via pool.strategy or pool.fallbackItem.

Type Parameters ​

Type ParameterDescription
TSeat extends AccountSeatASTNodeAccount seat AST node type.

Parameters ​

ParameterTypeDescription
poolPoolNode<TSeat>Account seat pool AST node.
runIdstringActive flow run identifier for seat affinity.
nowMs?numberOptional epoch timestamp in milliseconds (defaults to Date.now()).

Returns ​

TSeat

Selected account seat AST node.

Released under the MIT License.