Worker Types
Spacebot supports two worker modes:Fire-and-Forget
Runs a task once and returns a result. Used for one-shot jobs: summarization, memory recall, shell commands.
Interactive
Long-running worker that accepts follow-up input from the channel. Used for coding sessions, debugging, complex multi-step tasks.
Creating Workers
Channels create workers via thespawn_worker tool:
The work to delegate. Be specific—this becomes the worker’s initial prompt.
fire_and_forget (default) or interactiveMaximum execution time (1-3600 seconds). Fire-and-forget workers enforce this strictly. Interactive workers can exceed it with user approval.
Skill names to highlight in the worker’s system prompt (e.g.,
["github", "docker"])Worker Lifecycle
Spawn
Channel calls
spawn_worker. A new worker process starts with a fresh history and task-specific tools.Execute
Worker runs in segments of 25 turns. After each segment, context usage is checked. If approaching 70% of the context window, older history is compacted.
Compaction
Programmatic summarization removes oldest messages, replacing them with a recap of tool calls and results. No LLM involved—just truncation with a summary marker.
src/agent/worker.rs
State Machine
Workers follow a strict state transition model:InvalidStateTransition errors.
Interactive Workers
Interactive workers stay alive for follow-up:- Create
- Follow-up
- Inspect
WaitingForInput, the channel can send more input via route.
Context Management
Workers run in segments with automatic compaction:src/agent/worker.rs
Worker Tools
Workers get task-specific tools—no channel management, no memory tools:shell
Execute shell commands
file
Read/write/list files
exec
Run subprocesses
browser
Web automation
web_search
Brave Search API
set_status
Update status message
task_update
Update assigned task
read_skill
Load skill content
MCP tools
Dynamic tools from MCP servers
Sandboxing
Workers run in a sandboxed environment:- File operations restricted to
workspace_dir - Shell commands wrapped via
Sandbox::wrap()(firejail, bubblewrap, or nsjail on Linux) - Symlinks blocked to prevent TOCTOU races
- Dangerous env vars (
LD_PRELOAD,PYTHONPATH, etc.) filtered out
src/sandbox.rs
Sandboxing is best-effort. On Windows and macOS, or when no sandbox backend is available, workers run with workspace path restrictions only.
Status Updates
Workers report their status via theset_status tool:
- Channel status blocks (if the worker was spawned by that channel)
- Worker inspection output
- Process event stream
Failure Logging
When a worker fails, it writes a structured log tologs_dir:
- ErrorsOnly (default)
- All
- AllSeparate
Only failed workers write logs.
agent.toml
Worker Transcripts
All worker executions persist a compressed transcript blob to theworker_runs table:
- Full message history (compacted + active)
- Tool calls with arguments
- Tool results
- Status transitions
Pluggable Workers
Workers are pluggable. A worker can be:- Rig agent with shell/file/exec tools (default)
- OpenCode subprocess (see OpenCode Integration)
- Any external process that accepts a task and reports status
spawn_worker.rs and update the WorkerMode enum.
Performance Notes
Workers are CPU-bound
Workers are CPU-bound
Each worker is a separate tokio task. LLM calls dominate execution time. Workers run concurrently—spawn as many as your LLM provider rate limits allow.
Compaction is programmatic
Compaction is programmatic
No LLM call for compaction. We truncate oldest messages and insert a recap. Fast and deterministic.
Tool output is truncated
Tool output is truncated
Outputs over 50KB are truncated with a notice. Keeps token usage bounded without losing information (the worker can re-read with offset/limit).
Fire-and-forget workers clean up
Fire-and-forget workers clean up
When a fire-and-forget worker completes, its history is serialized to the
worker_runs table and the in-memory state is dropped. No lingering processes.