Expand description
Daemon-owned background task execution (#2056): wires the session/event
layer (#2054/#2055) to the existing engine (agent_loop/runner/tools/
llm) — the M1 control-plane cut line.
Why: run_task (the CLI’s tcode run-task) already proves this engine
end-to-end, but it runs synchronously, in the calling process, and
renders a RunReport for a terminal. A daemon-driven task must instead
run as a background task the triggering RPC does NOT block on, stream
its progress live to session.attached clients via the #2055 event
envelope, and persist its outcome onto the Session for a future
session.get_transcript (#2058). This module is new glue, NOT a fork of
the engine: it builds the exact same PM-delegates-to-engineer shape
run_task::execute_run_task does (see that module’s doc comment), reusing
agent_loop::AgentLoop, runner::InProcessAgentRunner, tools::*, and
run_task’s own public RecordingLlmClient/TurnRecord/
aggregate_usage_per_role/resolve_agent_model_slug machinery — only the
orchestration shell (spawn-and-report vs. run-and-render) differs.
What: TaskRunParams carries one run’s inputs; spawn_task_run is
the single entry point task::protocol::task_run calls — it reserves the
session’s execution slot synchronously (rejecting a second overlapping
run before any background work starts), then hands the actual run off to
a tokio::spawn’d task that builds both loops (attaching the #2056
SessionToolEventSink + a shared cancel flag to BOTH the PM’s and the
delegated engineer’s AgentLoop), drives the PM loop, prices the
transcript PER ROLE against each role’s own resolved model via
run_task::aggregate_usage_per_role (#1475 bug 1 — this daemon path and
the legacy CLI path now share the ONE implementation, so they can never
independently drift), persists the outcome, and transitions the session
to its terminal state.
Test: task::executor::tests::*; the full flow end-to-end (a real
subprocess) in tests/task_e2e.rs.
Structs§
- Task
RunParams - Inputs to start one background task execution.
Constants§
- ENGINEER_
AGENT_ NAME - Hardcoded delegated engineer agent name, matching the
run_task/fixture convention used across this crate (<agents_dir>/python-engineer.md). A future ticket may make this configurable pertask.runcall.
Functions§
- spawn_
task_ run - Reserve the session’s execution slot and spawn the background run.