docs/automation/tasks.md
Background tasks track work that runs outside your main conversation session: ACP runs, subagent spawns, isolated cron job executions, and CLI-initiated operations.
Tasks do not replace sessions, cron jobs, or heartbeats — they are the activity ledger that records what detached work happened, when, and whether it succeeded.
<Note> Not every agent run creates a task. Heartbeat turns and normal interactive chat do not. All cron executions, ACP spawns, subagent spawns, and CLI agent commands do. </Note>queued → running → terminal (succeeded, failed, timed_out, cancelled, or lost).openclaw tasks list shows all tasks; openclaw tasks audit surfaces issues.# Filter by runtime or status
openclaw tasks list --runtime acp
openclaw tasks list --status running
```
# Change notification policy for a task
openclaw tasks notify <lookup> state_changes
```
# Preview or apply maintenance
openclaw tasks maintenance
openclaw tasks maintenance --apply
```
| Source | Runtime type | When a task record is created | Default notify policy |
|---|---|---|---|
| ACP background runs | acp | Spawning a child ACP session | done_only |
| Subagent orchestration | subagent | Spawning a subagent via sessions_spawn | done_only |
| Cron jobs (all types) | cron | Every cron execution (main-session and isolated) | silent |
| CLI operations | cli | openclaw agent commands that run through the gateway | silent |
| Agent media jobs | cli | Session-backed music_generate/video_generate runs | silent |
Session-backed `music_generate` and `video_generate` runs also use `silent` notify policy. They still create task records, but completion is handed back to the original agent session as an internal wake so the agent can write the follow-up message and attach the finished media itself. Group/channel completions follow the normal visible-reply policy, so the agent uses the message tool when source delivery requires it.
stateDiagram-v2
[*] --> queued
queued --> running : agent starts
running --> succeeded : completes ok
running --> failed : error
running --> timed_out : timeout exceeded
running --> cancelled : operator cancels
queued --> lost : session gone > 5 min
running --> lost : session gone > 5 min
| Status | What it means |
|---|---|
queued | Created, waiting for the agent to start |
running | Agent turn is actively executing |
succeeded | Completed successfully |
failed | Completed with an error |
timed_out | Exceeded the configured timeout |
cancelled | Stopped by the operator via openclaw tasks cancel |
lost | The runtime lost authoritative backing state after a 5-minute grace period |
Transitions happen automatically — when the associated agent run ends, the task status updates to match.
Agent run completion is authoritative for active task records. A successful detached run finalizes as succeeded, ordinary run errors finalize as failed, and timeout or abort outcomes finalize as timed_out. If an operator already cancelled the task, or the runtime already recorded a stronger terminal state such as failed, timed_out, or lost, a later success signal does not downgrade that terminal status.
lost is runtime-aware:
openclaw agent runs also finalize from their run result, so completed runs
do not sit active until the sweeper marks them lost.When a task reaches a terminal state, OpenClaw notifies you. There are two delivery paths:
Direct delivery — if the task has a channel target (the requesterOrigin), the completion message goes straight to that channel (Telegram, Discord, Slack, etc.). For subagent completions, OpenClaw also preserves bound thread/topic routing when available and can fill a missing to / account from the requester session's stored route (lastChannel / lastTo / lastAccountId) before giving up on direct delivery.
Session-queued delivery — if direct delivery fails or no origin is set, the update is queued as a system event in the requester's session and surfaces on the next heartbeat.
<Tip> Task completion triggers an immediate heartbeat wake so you see the result quickly — you do not have to wait for the next scheduled heartbeat tick. </Tip>That means the usual workflow is push-based: start detached work once, then let the runtime wake or notify you on completion. Poll task state only when you need debugging, intervention, or an explicit audit.
Control how much you hear about each task:
| Policy | What is delivered |
|---|---|
done_only (default) | Only terminal state (succeeded, failed, etc.) — this is the default |
state_changes | Every state transition and progress update |
silent | Nothing at all |
Change the policy while a task is running:
openclaw tasks notify <lookup> state_changes
Output columns: Task ID, Kind, Status, Delivery, Run ID, Child Session, Summary.
The lookup token accepts a task ID, run ID, or session key. Shows the full record including timing, delivery state, error, and terminal summary.
For ACP and subagent tasks, this kills the child session. For CLI-tracked tasks, cancellation is recorded in the task registry (there is no separate child runtime handle). Status transitions to `cancelled` and a delivery notification is sent when applicable.
Surfaces operational issues. Findings also appear in `openclaw status` when issues are detected.
| Finding | Severity | Trigger |
| ------------------------- | ---------- | ------------------------------------------------------------------------------------------------------------ |
| `stale_queued` | warn | Queued for more than 10 minutes |
| `stale_running` | error | Running for more than 30 minutes |
| `lost` | warn/error | Runtime-backed task ownership disappeared; retained lost tasks warn until `cleanupAfter`, then become errors |
| `delivery_failed` | warn | Delivery failed and notify policy is not `silent` |
| `missing_cleanup` | warn | Terminal task with no cleanup timestamp |
| `inconsistent_timestamps` | warn | Timeline violation (for example ended before started) |
Use this to preview or apply reconciliation, cleanup stamping, and pruning for tasks and Task Flow state.
Reconciliation is runtime-aware:
- ACP/subagent tasks check their backing child session.
- Subagent tasks whose child session has a restart-recovery tombstone are marked lost instead of being treated as recoverable backing sessions.
- Cron tasks check whether the cron runtime still owns the job, then recover terminal status from persisted cron run logs/job state before falling back to `lost`. Only the Gateway process is authoritative for the in-memory cron active-job set; offline CLI audit uses durable history but does not mark a cron task lost solely because that local Set is empty.
- Chat-backed CLI tasks check the owning live run context, not just the chat session row.
Completion cleanup is also runtime-aware:
- Subagent completion best-effort closes tracked browser tabs/processes for the child session before announce cleanup continues.
- Isolated cron completion best-effort closes tracked browser tabs/processes for the cron session before the run fully tears down.
- Isolated cron delivery waits out descendant subagent follow-up when needed and suppresses stale parent acknowledgement text instead of announcing it.
- Subagent completion delivery prefers the latest visible assistant text; if that is empty it falls back to sanitized latest tool/toolResult text, and timeout-only tool-call runs can collapse to a short partial-progress summary. Terminal failed runs announce failure status without replaying captured reply text.
- Cleanup failures do not mask the real task outcome.
Use these when the orchestrating Task Flow is the thing you care about rather than one individual background task record.
/tasks)Use /tasks in any chat session to see background tasks linked to that session. The board shows active and recently completed tasks with runtime, status, timing, and progress or error detail.
When the current session has no visible linked tasks, /tasks falls back to agent-local task counts so you still get an overview without leaking other-session details.
For the full operator ledger, use the CLI: openclaw tasks list.
openclaw status includes an at-a-glance task summary:
Tasks: 3 queued · 2 running · 1 issues
The summary reports:
queued + runningfailed + timed_out + lostacp, subagent, cron, cliBoth /status and the session_status tool use a cleanup-aware task snapshot: active tasks are preferred, stale completed rows are hidden, and recent failures only surface when no active work remains. This keeps the status card focused on what matters right now.
Task records persist in SQLite at:
$OPENCLAW_STATE_DIR/tasks/runs.sqlite
The registry loads into memory at gateway start and syncs writes to SQLite for durability across restarts.
The Gateway keeps the SQLite write-ahead log bounded by using SQLite's default
autocheckpoint threshold plus periodic and shutdown TRUNCATE checkpoints.
A sweeper runs every 60 seconds and handles four things:
<Steps> <Step title="Reconciliation"> Checks whether active tasks still have authoritative runtime backing. ACP/subagent tasks use child-session state, cron tasks use active-job ownership, and chat-backed CLI tasks use the owning run context. If that backing state is gone for more than 5 minutes, the task is marked `lost`. </Step> <Step title="ACP session repair"> Closes terminal or orphaned parent-owned one-shot ACP sessions, and closes stale terminal or orphaned persistent ACP sessions only when no active conversation binding remains. </Step> <Step title="Cleanup stamping"> Sets a `cleanupAfter` timestamp on terminal tasks (endedAt + 7 days). During retention, lost tasks still appear in audit as warnings; after `cleanupAfter` expires or when cleanup metadata is missing, they are errors. </Step> <Step title="Pruning"> Deletes records past their `cleanupAfter` date. </Step> </Steps> <Note> **Retention:** terminal task records are kept for **7 days**, then automatically pruned. No configuration needed. </Note>See [Task Flow](/automation/taskflow) for details.
See [Cron Jobs](/automation/cron-jobs).
See [Heartbeat](/gateway/heartbeat).