Last updated: 2026-11-17

Scheduler

Request

All API Sections

Request lifecycle management for concurrent inference serving.

Each incoming API request maps to a Request that tracks its state through prefill, decode, and completion phases.

3 exports 5 methods src/scheduler/request.zig

3 exports shown

enum

RequestState

#
pub const RequestState = enum

Request processing state machine.

Valid transitions: pending → prefilling → decoding → completed, with cancelled reachable from any active state and failed reachable from prefilling or decoding.

src/scheduler/request.zig:13

struct

GenerationParams

#
pub const GenerationParams = struct

Memory Layout

Size: 40 bytes (alignment: 8)

Offset Size Align Field Type
16 4 4 max_tokens u32
20 4 4 temperature f32
24 4 4 top_p f32
28 4 4 top_k u32
32 1 1 stream bool
0 16 8 stop_sequences []const []const u8

Generation parameters from the API request.

src/scheduler/request.zig:29

struct

Request

#
pub const Request = struct

Memory Layout

Size: 176 bytes (alignment: 16)

Offset Size Align Field Type
48 8 8 id u64
168 1 1 state scheduler.request.RequestState
56 16 8 prompt_tokens []const u32
72 32 8 generated_tokens array_list.Aligned(u32,null)
104 40 8 params scheduler.request.GenerationParams
160 8 4 slot_id ?u32
0 16 16 created_at_ns i128
16 32 16 first_token_ns ?i128
144 16 8 allocator mem.Allocator

A single inference request with its lifecycle state.

src/scheduler/request.zig:45

Methods

5

method

Request.init

#
pub fn init(allocator: std.mem.Allocator, id: u64, prompt_tokens: []const u32, params: GenerationParams) Request

Create a new request in the pending state with the given prompt and parameters.

Parameters
allocator
Allocator for the generated token buffer.
id
Unique request identifier.
prompt_tokens
Tokenized prompt (owned by the caller).
params
Generation parameters (max_tokens, temperature, etc.).
Returns

A Request ready to be submitted to the scheduler.

src/scheduler/request.zig:73

method

Request.transition

#
pub fn transition(self: *Request, new_state: RequestState) !void

Advance the request through the state machine.

Parameters
self
Request to transition.
new_state
Target state (must be a valid successor of the current state).
Returns

error.InvalidTransition if the transition is not allowed by the state machine.

src/scheduler/request.zig:91

method

Request.appendToken

#
pub fn appendToken(self: *Request, token: u32) !void

Append a generated token and record the first-token timestamp if unset.

Parameters
self
Request to append to.
token
Generated token ID to add.

src/scheduler/request.zig:105

method

Request.shouldStop

#
pub fn shouldStop(self: *const Request, eos_token_id: u32) bool

Check if generation should stop (max_tokens reached or EOS token emitted).

Parameters
self
Request to check.
eos_token_id
End-of-sequence token ID.
Returns

True if generation should stop.

src/scheduler/request.zig:116

method

Request.deinit

#
pub fn deinit(self: *Request) void

Release the generated token buffer owned by this request.

Parameters
self
Request to tear down.

src/scheduler/request.zig:127