Scheduler
The search engine beneath Search: the shared tree, branching gates, and allocation sessions.
Observations
Section titled “Observations”Keep the evidence used to allocate continuations at one checkpoint: completed and pending purchases, plus running statistics of completed suffix returns. Evidence counts can differ from purchase counts because earlier rollouts also supply observations.
Definition
Fields
Observations.m_alloc
Section titled “Observations.m_alloc”Observations.n_eff
Section titled “Observations.n_eff”AllocationLedger
Section titled “AllocationLedger”Track completed and pending continuations at each node. Allocation sessions for the same tree share these counts.
Definition
AllocationLedger.init
Section titled “AllocationLedger.init”AllocationLedger.bind
Section titled “AllocationLedger.bind”AllocationLedger.counts
Section titled “AllocationLedger.counts”AllocationLedger.record
Section titled “AllocationLedger.record”Hook for recording the evidence from a completed expansion. The base implementation does nothing; RolloutLedger overrides it to record returns from continuation suffixes.
AllocationSession
Section titled “AllocationSession”Choose checkpoints and track their continuations within one pass. Implement choose() for a custom selection rule; the shared lifecycle handles completion, failure, and cancellation.
Definition
AllocationSession.init
Section titled “AllocationSession.init”AllocationSession.start
Section titled “AllocationSession.start”AllocationSession.stop
Section titled “AllocationSession.stop”AllocationSession.choose
Section titled “AllocationSession.choose”Required implementation.
AllocationSession.select
Section titled “AllocationSession.select”AllocationSession.active
Section titled “AllocationSession.active”AllocationSession.complete
Section titled “AllocationSession.complete”AllocationSession.fail
Section titled “AllocationSession.fail”AllocationSession.cancel
Section titled “AllocationSession.cancel”AllocationSession.selected
Section titled “AllocationSession.selected”AllocationSession.completed
Section titled “AllocationSession.completed”AllocationSession.released
Section titled “AllocationSession.released”Budget
Section titled “Budget”Stop launching continuations when the configured turn, rollout, node, or goal limit is reached.
Definition
Budget.init
Section titled “Budget.init”Budget.turns_spent
Section titled “Budget.turns_spent”Turns realized, plus one per failure.
A dead expansion records no turns — it produced no payload to read them off —
so a turn cap counting successes alone would never deplete against an expander
that always fails, and the loop would re-select and re-fail forever. Charging a
turn for the attempt is the same protection max_rollouts gets by counting
failures, and it is a floor: a rollout that died partway spent at least that.
Budget.remaining
Section titled “Budget.remaining”ConcurrencyGating
Section titled “ConcurrencyGating”Limit simultaneous continuations from each checkpoint while allowing more continuations after earlier ones finish.
A checkpoint can have two active continuations. A completed continuation releases its slot for another one.
Definition
ConcurrencyGating.init
Section titled “ConcurrencyGating.init”ConcurrencyGating.gate
Section titled “ConcurrencyGating.gate”Expander
Section titled “Expander”Define how one selected node produces a chain of child payloads. This is the scheduler’s interface to task execution.
Definition
Expander.expand
Section titled “Expander.expand”Required implementation.
The children, plus metadata to record on each node they become.
The metadata rides back with the payloads rather than being written by the
expander itself, because the payloads exist before the nodes do. An expander
with nothing to record answers {}.
FifoSession
Section titled “FifoSession”Maintain the state for one FIFO pass and choose the first eligible checkpoint from the frontier.
Definition
FifoSession.choose
Section titled “FifoSession.choose”Reserve and release branch capacity for a node without blocking the scheduler.
Definition
Gate.init
Section titled “Gate.init”Gate.in_use
Section titled “Gate.in_use”Gate.available
Section titled “Gate.available”Whether a branch may launch from node right now.
Gate.reserve
Section titled “Gate.reserve”Claim a slot (on launch).
Gate.release
Section titled “Gate.release”Free a slot (on completion).
GatingPolicy
Section titled “GatingPolicy”Decide how many expansions a checkpoint may launch. Implement gate to vary branch limits by checkpoint or depth.
Definition
GatingPolicy.gate
Section titled “GatingPolicy.gate”Required implementation.
Hold one tree payload, its parent and children, critic predictions, and scheduling metadata.
Definition
Fields
NodeScorer
Section titled “NodeScorer”Batch a critic’s predictions for new checkpoints through the execution services. The collector creates one; a search scores each new checkpoint before it can be selected.
Predictions are stored on each node as its critic prior, separate from observed returns. The critic’s context() renders each checkpoint as input.
Definition
NodeScorer.init
Section titled “NodeScorer.init”NodeScorer.score
Section titled “NodeScorer.score”Predict values for payloads in one batched call, preserving order.
A critic that answers with the wrong number of predictions raises here, inside the callers’ guards, so the fault costs an estimate rather than the run.
NodeScorer.write
Section titled “NodeScorer.write”File scores on nodes, pairwise.
PASS_KEY
Section titled “PASS_KEY”The node-metadata key recording which search phase created a node. Preparation trains only on edges created by search.
Definition
Payload
Section titled “Payload”Define the state properties required by the tree scheduler. RolloutState supplies the harness implementation.
Definition
Payload.forkable
Section titled “Payload.forkable”May the scheduler branch (expand) at this node.
Payload.done
Section titled “Payload.done”Whether this payload is terminal.
Payload.reward
Section titled “Payload.reward”The default ranking score (used by SchedulerState.best).
RankedSession
Section titled “RankedSession”An allocation session that ranks checkpoints. Implement score(); the session selects the eligible checkpoint with the highest score. Most extensions implement Priority instead, which builds this session for you.
Definition
RankedSession.score
Section titled “RankedSession.score”Required implementation.
RankedSession.eligible
Section titled “RankedSession.eligible”RankedSession.choose
Section titled “RankedSession.choose”Reservation
Section titled “Reservation”Identify one launched continuation. Two reservations from the same checkpoint track two separate continuations still in progress.
Definition
Fields
RolloutExpander
Section titled “RolloutExpander”Fork an isolated rollout, run it forward, and return its checkpoint chain to the scheduler.
Definition
RolloutExpander.init
Section titled “RolloutExpander.init”RolloutExpander.expand
Section titled “RolloutExpander.expand”RolloutExpander.start
Section titled “RolloutExpander.start”Convenience: build the search root from a prompt (keeps the Agent here).
Scheduler
Section titled “Scheduler”Coordinate concurrent expansions, allocation sessions, branching gates, and critic passes over a tree.
Definition
Scheduler.init
Section titled “Scheduler.init”Scheduler.run
Section titled “Scheduler.run”Search from a root payload until termination, and return the tree it grew.
Scheduler.run_on
Section titled “Scheduler.run_on”Search over an existing (possibly shared) tree until termination.
Lets other code run concurrently over the same state under
state.lock. Gating comes from state.gating (set
when the state was built), not this scheduler’s own default.
Returns the very state it was handed. The tree is the result: its
terminals and its best node are questions asked of it
(SchedulerState.terminals, SchedulerState.best), and a record
that answered them once at return froze them at the moment the run stopped —
which is exactly wrong for the caller that runs a second pass over the same
tree, as every later search pass does.
Termination ends the launching, not the run: once remaining() is 0 the
loop drains — it keeps awaiting and integrating what is already in flight until
nothing is, and only then returns (see the module docstring for why, and for the
overshoot that buys). The in-flight expansions are cancelled only when the
caller cancels, or when something escapes the loop.
SchedulerState
Section titled “SchedulerState”Store the search tree and the frontier of nodes currently available for expansion.
Definition
Fields
SchedulerState.root
Section titled “SchedulerState.root”A fresh state seeded with the initial payload as the tree root.
SchedulerState.selectable
Section titled “SchedulerState.selectable”Whether node may be expanded: forkable, live, and its gate has a slot.
SchedulerState.refresh
Section titled “SchedulerState.refresh”Recompute one node’s frontier membership (idempotent, order-preserving).
SchedulerState.add_child
Section titled “SchedulerState.add_child”Attach one payload as a child of parent_id and index it.
SchedulerState.attach_chain
Section titled “SchedulerState.attach_chain”Link a rollout’s payloads as a descendant line under parent_id.
The first payload becomes a child of parent_id (a new branch); each later
payload is a child of the previous (the step line). Returns the new nodes.
SchedulerState.regate
Section titled “SchedulerState.regate”Re-mint every gate under a new policy and rebuild the frontier.
Gates are minted once, when a node is added, so a node that filled its
discovery width has no slot left — correct while discovery runs, and exactly
wrong for a later pass that must launch from those same nodes. This is the
whole pass-boundary mechanism the tree needs: one explicit transition, called
between passes under lock, rather than per-pass gate bookkeeping smeared
through the loop.
SchedulerState.record_failure
Section titled “SchedulerState.record_failure”SchedulerState.terminals
Section titled “SchedulerState.terminals”Every node whose payload ended the episode naturally.
SchedulerState.best
Section titled “SchedulerState.best”The highest-reward terminal node, or None if nothing finished.
Ranked by the payload’s own reward — the one score every payload has. A caller
ranking by anything else (a critic channel, a custom key) is choosing among
terminals and can say so in its own terms.
SchedulerState.describe
Section titled “SchedulerState.describe”The tree, one node per line, with any actor weights from batch joined.
See focus.export.format_tree for the line format.
SchedulerView
Section titled “SchedulerView”Read the rollout tree, its eligible checkpoints, and collection statistics. Priorities and estimators read this view to inspect parent-child relationships.
Wrap the tree returned by Collector.search(). Here, children contains the root’s direct branches, while descendants iterates through its whole subtree.
Definition
Fields
SchedulerView.stats
Section titled “SchedulerView.stats”SchedulerView.failures
Section titled “SchedulerView.failures”Return failed expansions as (node_id, repr(exception)) pairs. The returned tuple is a snapshot of the failures recorded so far.
SchedulerView.nodes
Section titled “SchedulerView.nodes”Every node in the tree.
SchedulerView.selectable
Section titled “SchedulerView.selectable”SchedulerView.frontier_size
Section titled “SchedulerView.frontier_size”SchedulerView.iter_frontier
Section titled “SchedulerView.iter_frontier”Iterate over eligible nodes without copying the frontier. Hold the tree lock while using this iterator.
SchedulerView.frontier
Section titled “SchedulerView.frontier”Eligible nodes in insertion order: each is live, forkable, and has an available gate slot.
SchedulerView.arrival
Section titled “SchedulerView.arrival”When node last became selectable, as a position in arrival order.
SchedulerView.node
Section titled “SchedulerView.node”Look up a node by ID, returning None if it is absent.
SchedulerView.root
Section titled “SchedulerView.root”The tree’s root node, which holds the starting state for this prompt.
SchedulerView.children
Section titled “SchedulerView.children”Return a node’s direct children in the order they were attached.
SchedulerView.terminals
Section titled “SchedulerView.terminals”Return nodes whose environment state has ended the episode.
SchedulerView.path_to
Section titled “SchedulerView.path_to”Return the parent chain ending at node, in root-to-node order. For a node in this tree, both root and node are included. A chain disconnected from this tree’s root produces a path that does not begin at the root.
SchedulerView.descendants
Section titled “SchedulerView.descendants”Iterate depth-first over all nodes below node, excluding the node itself. The iterator is lazy, so callers can stop as soon as they find a match.
SchedulerView.len
Section titled “SchedulerView.len”Termination
Section titled “Termination”Define how many additional continuations the scheduler may launch from its current state.
The scheduler can launch one continuation while the tree has fewer than 100 nodes. A continuation can add several nodes, so this is an admission rule rather than an exact final tree-size bound.
Definition
Termination.remaining
Section titled “Termination.remaining”Required implementation.
Rollouts still launchable now: 0 = stop, positive = cap, None = none.
The scheduler counts in-flight rollouts against a returned cap, so a rollout budget is a hard cap — completed + in-flight never exceeds it.
0 ends the launching, not the run: the scheduler then drains what is
already in flight and integrates it normally (finished rollouts are the
expensive half, and cancelling them at the budget threw away up to one episode
per slot). The first 0 is latched — this is never asked again on that run,
so a predicate a drained result would flip back cannot re-open the pass — and
the stats a caller reads afterwards include everything the drain integrated.
WidthGating
Section titled “WidthGating”Cap the total number of direct child branches from each checkpoint, counting completed and in-flight branches together.
Each checkpoint gets at most three direct branches. Completed children continue to count against this cap.
Definition
WidthGating.init
Section titled “WidthGating.init”WidthGating.gate
Section titled “WidthGating.gate”ValuePrediction
Section titled “ValuePrediction”Pair a critic score with the exact serialized context used to compute it.
Definition
Fields
token_entropies
Section titled “token_entropies”Compute the per-token proxy -p log(p) from finite token log probabilities.
Definition
STAT_FAILURES
Section titled “STAT_FAILURES”Name the scheduler statistic counting failed expansions.
Definition
STAT_NODES
Section titled “STAT_NODES”Name the scheduler statistic counting tree nodes.
Definition
STAT_ROLLOUTS
Section titled “STAT_ROLLOUTS”Name the scheduler statistic counting rollouts.
Definition
STAT_SCORE_FAILURES
Section titled “STAT_SCORE_FAILURES”Name the scheduler statistic counting critic-scoring failures.
Definition
STAT_TURNS
Section titled “STAT_TURNS”Name the scheduler statistic counting task transitions.
Definition
edge_duration
Section titled “edge_duration”The number of task transitions on the edge into a node: the in the discount that refined values and segment TD advantages apply to a successor’s value.
Definition
edge_return
Section titled “edge_return”Compute the discounted return along a node’s incoming edge.
Definition
finished_below
Section titled “finished_below”Enumerate completed trajectories reachable below a checkpoint.
Definition
finished_through
Section titled “finished_through”Check whether a completed trajectory passes through a node, including the node itself.
Definition