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 Parameter | Default type | Description |
|---|---|---|
TIn | unknown | Validated lane work item input type. |
Constructors
Constructor
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
| Parameter | Type | Description |
|---|---|---|
config | LaneSchedulerConfig<TIn> | Lane scheduler configuration and stores. |
Returns
LaneScheduler<TIn>
Methods
computeEffectivePriority()
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
| Parameter | Type | Description |
|---|---|---|
item | LaneQueuedItemState<TIn> | Queued item state to score. |
nowMs? | number | Current epoch timestamp in milliseconds. |
Returns
number
Effective priority weight.
enforceRunBudget()
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
| Parameter | Type | Description |
|---|---|---|
runId | string | Active run identifier. |
addedCostUsd | number | Additional USD cost incurred. |
Returns
Promise<{ allowed: boolean; newLimitUsd?: number; }>
Budget enforcement outcome.
enqueueItem()
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
| Parameter | Type | Description |
|---|---|---|
options | EnqueueLaneItemOptions<TIn> | Work item input and optional scheduling overrides. |
Returns
Promise<LaneQueuedItemState<TIn>>
Enqueued or existing item state.
getItemsByKey()
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()
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 Parameter | Description |
|---|---|
TPayload | Signal payload type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
signalId | string | Emitted signal identifier. |
payload | TPayload | Validated signal payload. |
itemKey? | string | Optional target itemKey. |
Returns
Promise<boolean>
True if a matching handler was triggered.
pollTrackerOnce()
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()
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
| Parameter | Type | Description |
|---|---|---|
bootRecord | InterruptedStepBootRecord | Non-terminal boot record returned by LedgerStore.getInterruptedStepsOnBoot(). |
Returns
Promise<LaneQueuedItemState<TIn>>
Recovered lane item state.
scheduleNextReadyRuns()
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
| Parameter | Type | Description |
|---|---|---|
nowMs? | number | Timestamp used for priority aging calculations. |
Returns
Promise<readonly FlowRunResult[]>
Flow run results for runs completed in this scheduling pass.
syncTrackerState()
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
| Parameter | Type | Description |
|---|---|---|
itemKey | string | Work item key to update on the external tracker. |
canonicalKey | string | Canonical internal state key. |
rawExit? | string | Optional raw exit state fallback when canonicalKey starts with 'exit:'. |
Returns
Promise<void>
Resolves once the external tracker state is updated.