Expand description
The Worker trait — the shared interface for the execution units
each spawner keeps internally.
§Roles — the boundary between the Engine view and the Spawner’s
internal view
- Engine view. Only
SpawnerAdapteris visible. The engine does not know about Workers, and it does not care about their shape. - Spawner’s internal view. Each
SpawnerAdapter::spawnbuilds a concrete Worker internally (ChildProcessWorker/ClosureWorker/OperatorWorkerand friends), type-erases it asBox<dyn Worker>, and returns that. This trait fixes the interface so the Worker shape does not drift between spawner implementations.
§Worker lifetime semantics
The current contract is “one spawn = one worker = one join”. At
spawn() time the worker has already spun up an internal tokio task
(it is already running); the caller just needs to join() and wait
for the completion signal. The value comes from
engine.output_tail(task_id, attempt) via OutputEvent::Final
— the oneshot channel carries the signal, not the
value.
Extending to “one worker = N invocations” (calling the same worker
multiple times while the token’s TTL is alive) is a carry on a
separate axis. That was the original design intent
v6.md:174, but the shape was collapsed for the sake of implementation
simplicity. The route when it is needed: add
async fn invoke(&mut self, token, prompt) -> WorkerResult to the
trait and redefine join as “the last invocation’s completion plus
cleanup”.
§WorkerJoinHandler — the canonical shape shared by the three
spawners today
All three current spawners (Shell / InProc / Operator) call
tokio::spawn internally and push their completion signal through a
oneshot channel. WorkerJoinHandler is the helper that wraps that
shape into a dyn Worker. We share the helper until spawner
implementations need to define their own Worker structs; further
specialisation is a future carry.
Modules§
- adapter
- The second stage of the two-stage pipeline:
SpawnerAdapter. - agent_
block - AgentBlock — headless agent execution. This is an axis separate from
Operator (the MainAI-coupled path); when coupling is needed, wrap it
at the middleware layer (
crate::middleware). - baseline
- Baseline agent — the canonical
RustFnworker for bootstrap and smoke tests. - output
- Output path.
- process_
spawner ProcessSpawner— a general-purposeSpawnerAdapterimplementation that spawns an arbitrary binary (or a one-line shell command) and runs it as a worker. The thin path for wrapping an agent-block CLI, an LLM CLI, a random binary, or a shell script as a worker.
Structs§
- Middleware
Worker - Generic Worker used only on the middleware (
wrap_join) wrap path, so kind-agnostic post-processing wrap results can be returned asBox<dyn Worker>. Unlike a per-kind Worker, this does not represent “a specific kind’s execution” — it is a thin wrapper that layers a post-processor on top of an existing Worker. - Worker
Join Handler - Handler for a Worker’s async completion signal. A building
block; it does not implement
Workeritself. Holds the(worker_id, cancel token, oneshot receiver)triple and is embedded by every per-kind Worker (AgentBlockWorker/LuaWorker/RustFnWorker/ProcessWorker/OperatorWorker).
Traits§
- Worker
- Shared interface for the execution units spawners launch internally.
Functions§
- wrap_
join - Helper that wraps the inner Worker’s
join()completion signal in a post-processor and returns a freshBox<dyn Worker>. All the middleware wrap paths (Audit / MainAI / Senior / LongHold / Lua after-hook, and so on) go through this helper for consistency.