Skip to main content

spawn_task_run

Function spawn_task_run 

Source
pub fn spawn_task_run(
    registry: Arc<SessionRegistry>,
    llm: Arc<dyn InferenceAdapter>,
    params: TaskRunParams,
) -> Result<(), RpcError>
Expand description

Reserve the session’s execution slot and spawn the background run.

Why: the single entry point task::protocol::task_run calls. Reserving the slot SYNCHRONOUSLY (before any tokio::spawn) is what makes “a second overlapping task.run on the same session is rejected” observable to the CALLER of the second request, not just internally. What: calls registry.begin_execution (propagating session_not_found/ invalid_argument — already terminal / already running — verbatim), then spawns [run_and_record] and immediately attaches the real JoinHandle back onto the registry (see SessionRegistry::attach_execution_handle’s docs for why that is a separate call). Test: task::executor::tests::spawn_task_run_rejects_second_overlapping_run; the full run is exercised by tests/task_e2e.rs.