Module: Mistri::Dispatchers
- Defined in:
- lib/mistri/dispatchers.rb
Overview
How a background child actually executes. The spawn tool hands every dispatcher two things: a versioned serializable spec (name, session_id, parent_session_id, type, instructions, tool_names, model, task) and a runner closure that invokes the host runtime factory inside this process.
In-process dispatchers just call the runner. A queue dispatcher ignores the runner, enqueues the spec, and its job reconstructs the pieces from host registries and calls SubAgent.run_dispatched:
dispatcher: ->(spec, _runner) { ChildRunJob.perform_async(spec) }
The runner invokes the host factory inside the worker and keeps the spawn-time event sink. In-process children stream to whoever watched the spawn; that sink must outlive the parent's turn (a broadcast lambda does, a request-scoped object may not) and hears from the worker's thread, concurrently with the parent's own events. The gem's sinks tolerate that; a custom one must too.