Skip to content

Class: LaneScheduler<TIn> ​

Defined in: runtime/lane/lane-scheduler.ts:30

Stateful lane scheduler managing deduplication, priority aging, .waitFor() DAG barriers, .maxCostUsd() budgets, tracker sync, and .onSignal() rewinds (SPEC.md §3.10).

Enforces lane.concurrency across active 'RUNNING' items while allowing 'SUSPENDED' items to yield their slot.

Type Parameters ​

Type ParameterDefault typeDescription
TInunknownValidated lane work item input type.

Constructors ​

Constructor ​

ts
new LaneScheduler<TIn>(config): LaneScheduler<TIn>;

Defined in: runtime/lane/lane-scheduler.ts:53

Creates a new LaneScheduler bound to config.lane.

Initializes shared lock, continuation, pool, and service managers when not explicitly injected.

Parameters ​

ParameterTypeDescription
configLaneSchedulerConfig<TIn>Lane scheduler configuration and stores.

Returns ​

LaneScheduler<TIn>

Methods ​

computeEffectivePriority() ​

ts
computeEffectivePriority(item, nowMs?): number;

Defined in: runtime/lane/lane-scheduler.ts:71

Computes the effective numeric scheduling priority for item at nowMs (SPEC.md §3.10).

Combines LANE_PRIORITY_WEIGHTS[lane.priority], item.priorityBoost, and aging steps.

Parameters ​

ParameterTypeDescription
itemLaneQueuedItemState<TIn>Queued item state to score.
nowMs?numberCurrent epoch timestamp in milliseconds.

Returns ​

number

Effective priority weight.


enforceRunBudget() ​

ts
enforceRunBudget(runId, addedCostUsd): Promise<{
  allowed: boolean;
  newLimitUsd?: number;
}>;

Defined in: runtime/lane/lane-scheduler.ts:414

Enforces the lane's .maxCostUsd(limitUsd, approver) ceiling on an active run (SPEC.md §3.10).

Pages approver via HumanAdapter.requestDecision: raises limit on approval (when nextLimit > item.costUsd) or cancels the run via Drain Barrier.

Parameters ​

ParameterTypeDescription
runIdstringActive run identifier.
addedCostUsdnumberAdditional USD cost incurred.

Returns ​

Promise<{ allowed: boolean; newLimitUsd?: number; }>

Budget enforcement outcome.


enqueueItem() ​

ts
enqueueItem(options): Promise<LaneQueuedItemState<TIn>>;

Defined in: runtime/lane/lane-scheduler.ts:142

Enqueues or deduplicates a work item by lane.keyMapper(input) and persists its run record in LedgerStore (SPEC.md §3.10).

Transitions the item to 'WAITING' when prerequisite dependsOn keys are not yet 'COMPLETED', or 'QUEUED' when ready.

Parameters ​

ParameterTypeDescription
optionsEnqueueLaneItemOptions<TIn>Work item input and optional scheduling overrides.

Returns ​

Promise<LaneQueuedItemState<TIn>>

Enqueued or existing item state.


getItemsByKey() ​

ts
getItemsByKey(): ReadonlyMap<string, LaneQueuedItemState<TIn>>;

Defined in: runtime/lane/lane-scheduler.ts:482

Returns a snapshot of all tracked items in this lane.

Used by HarnessRuntimeController.getActiveRuns() and test assertions.

Returns ​

ReadonlyMap<string, LaneQueuedItemState<TIn>>

Map of itemKey to LaneQueuedItemState.


handleSignalRewind() ​

ts
handleSignalRewind<TPayload>(
   signalId, 
   payload, 
   itemKey?
): Promise<boolean>;

Defined in: runtime/lane/lane-scheduler.ts:441

Handles a live .onSignal(signal, ...) event correlated to an item in this lane (SPEC.md §3.10).

Updates item.input via handler.updateMapper and executes executeHierarchicalRewindDrain.

Type Parameters ​

Type ParameterDescription
TPayloadSignal payload type.

Parameters ​

ParameterTypeDescription
signalIdstringEmitted signal identifier.
payloadTPayloadValidated signal payload.
itemKey?stringOptional target itemKey.

Returns ​

Promise<boolean>

True if a matching handler was triggered.


pollTrackerOnce() ​

ts
pollTrackerOnce(): Promise<readonly LaneQueuedItemState<TIn>[]>;

Defined in: runtime/lane/lane-scheduler.ts:116

Polls lane.tracker once, filters raw issues through fromIssue, and enqueues non-undefined work items (SPEC.md §3.10).

Skips external issues for which fromIssue(issue) returns undefined or whose itemKey is already tracked.

Returns ​

Promise<readonly LaneQueuedItemState<TIn>[]>

Newly enqueued lane item states.


recoverBootRecord() ​

ts
recoverBootRecord(bootRecord): Promise<LaneQueuedItemState<TIn>>;

Defined in: runtime/lane/lane-scheduler.ts:195

Registers or updates a crash-recovered InterruptedStepBootRecord on this lane so it resumes on the next scheduling pass (SPEC.md §3.10).

Parses and validates bootRecord.inputJson against lane.inputSchema, attaches bootRecord, and marks the item 'SUSPENDED' or 'QUEUED'.

Parameters ​

ParameterTypeDescription
bootRecordInterruptedStepBootRecordNon-terminal boot record returned by LedgerStore.getInterruptedStepsOnBoot().

Returns ​

Promise<LaneQueuedItemState<TIn>>

Recovered lane item state.


scheduleNextReadyRuns() ​

ts
scheduleNextReadyRuns(nowMs?): Promise<readonly FlowRunResult[]>;

Defined in: runtime/lane/lane-scheduler.ts:240

Evaluates .waitFor() prerequisite barriers and schedules ready 'QUEUED' / 'SUSPENDED' items up to lane.concurrency (SPEC.md §3.10).

Transitions waiting items whose prerequisites failed/cancelled to waitFor.onAbandonedState and executes ready flows.

Parameters ​

ParameterTypeDescription
nowMs?numberTimestamp used for priority aging calculations.

Returns ​

Promise<readonly FlowRunResult[]>

Flow run results for runs completed in this scheduling pass.


syncTrackerState() ​

ts
syncTrackerState(
   itemKey, 
   canonicalKey, 
   rawExit?
): Promise<void>;

Defined in: runtime/lane/lane-scheduler.ts:94

Mirrors an internal lifecycle state key ('queued', 'running', 'waiting', 'errored', 'cancelled', or 'exit:<state>') to TrackerAdapter (SPEC.md §2.8 & §3.10).

Looks up canonicalKey (and fallback rawExit for 'exit:<state>') in lane.tracker.stateMappings.

Parameters ​

ParameterTypeDescription
itemKeystringWork item key to update on the external tracker.
canonicalKeystringCanonical internal state key.
rawExit?stringOptional raw exit state fallback when canonicalKey starts with 'exit:'.

Returns ​

Promise<void>

Resolves once the external tracker state is updated.

Released under the MIT License.