Anubis. Server. Session. Scheduler
(anubis_mcp v1.14.0)
Copy Markdown
Request scheduling engine for a session.
Owns the single in-flight request slot, the FIFO request queue, callbacks deferred while a request is in flight, and cancellation of in-flight or queued requests. At most one request executes at a time per session: while one runs, competing requests queue and competing casts/infos are deferred, then drained in order once the in-flight request completes.
State fields (in_flight, request_queue, deferred_callbacks,
pending_requests) live in the Session's state map; this module
transforms them and performs the side effects (task spawn, monitors,
caller replies, logging, telemetry) at the edges. Anubis.Server.Session
delegates to this module and supplies callbacks to prepare frames and to
apply drained deferred items back into its own dispatch paths.
Summary
Functions
Handles a notifications/cancelled notification, cancelling either the
in-flight request or any queued entries matching the request ID.
Defers a cast or info message to be applied once the in-flight request completes.
Dispatches the request immediately when no request is in flight, otherwise appends it to the request queue.
Handles completion of the in-flight request task: decodes the handler result, replies to the caller, drains deferred callbacks, and dispatches the next queued request.
Handles a crash of the in-flight request task, replying to the caller with an internal error before finalizing.
Replies to the in-flight and queued callers with the given error during session termination, terminating the in-flight worker task.
Types
@type callbacks() :: %{frame: frame_fn(), apply_deferred: apply_deferred_fn()}
@type deferred_callback() :: {:cast | :info, term()}
@type frame_fn() :: (state(), map() | nil -> Anubis.Server.Frame.t())
@type queued_request() :: {map(), map(), GenServer.from()}
@type state() :: map()
Functions
Handles a notifications/cancelled notification, cancelling either the
in-flight request or any queued entries matching the request ID.
@spec defer(state(), deferred_callback()) :: state()
Defers a cast or info message to be applied once the in-flight request completes.
@spec enqueue_or_dispatch(map(), map(), GenServer.from(), state(), callbacks()) :: {:noreply, state()}
Dispatches the request immediately when no request is in flight, otherwise appends it to the request queue.
@spec handle_completion(reference(), term(), state(), callbacks()) :: {:noreply, state()} | {:stop, term(), state()}
Handles completion of the in-flight request task: decodes the handler result, replies to the caller, drains deferred callbacks, and dispatches the next queued request.
Handles a crash of the in-flight request task, replying to the caller with an internal error before finalizing.
@spec reply_pending(state(), Anubis.MCP.Error.t()) :: :ok
Replies to the in-flight and queued callers with the given error during session termination, terminating the in-flight worker task.