#background job for long running tasks
1 messages · Page 1 of 1 (latest)
Yes, kind of, but the native shape is not “background a skill” directly.
For 2026.4.20, the built-in options are:
-
Best fit:
sessions_spawn/ subagents- Runs the work in a child agent session
- Creates a background task
- When it finishes, OpenClaw announces back to the original chat/thread
- Default notify policy is
done_only
-
For a single long shell command:
execwithyieldMsorbackground:true- The command keeps running after the turn ends
- With
tools.exec.notifyOnExit: true(default), OpenClaw queues an exec completion wake so the agent can reply when it exits - Caveat:
processstate is in memory only, so it is less durable than task-backed runs
-
If it should run later / on a schedule: isolated cron
- Creates task records too
- Can announce or webhook on completion
So for your upgrade flow (backup + docker build + diagnostics), I’d recommend:
- Start a subagent for the whole upgrade job
- Let that subagent use
execinternally for the heavy shell work - Let OpenClaw push the final result back when done
That gives you native tracking plus completion notification, without keeping the original turn hanging open.
Docs:
- https://docs.openclaw.ai/tools/subagents
- https://docs.openclaw.ai/automation/tasks
- https://docs.openclaw.ai/tools/exec
- https://docs.openclaw.ai/automation/cron-jobs
If you want, I can sketch the exact pattern for an “upgrade skill” implementation.
sure.. that would be helpful
Yep, on 2026.4.20 I’d build it like this:
Recommended pattern
Parent skill
- Validate inputs
- Spawn a subagent with
sessions_spawn - Immediately tell the user “started, I’ll report back here”
- Let the child do the heavy work and finish with a clean summary
Child subagent
- Runs backup, diagnostics, docker build, verification
- Uses
execfor the real shell steps - When it finishes, OpenClaw posts the completion back to the original chat
Why this is the best fit
If you only do exec background=true in the main skill, it works, but:
- it is not a first-class background task record
- process state is in memory only
- it is less ideal for multi-step upgrade workflows
For “backup + build + snapshot + report back”, sessions_spawn is the cleaner native path.
Minimal shape
Parent skill logic:
If the requested upgrade flow will take more than ~1 minute or has multiple phases:
- call sessions_spawn
- label it clearly
- set a generous runTimeoutSeconds
- do not wait in a poll loop
- reply that the upgrade job has started and completion will be posted here
Example spawn:
{
"task": "Run the upgrade workflow for this project. Steps: (1) create a backup, (2) collect a diagnostic snapshot, (3) run docker build, (4) verify health, (5) report final status back to the user with key logs/artifacts. Use exec for shell commands. Stop on fatal errors, but still summarize partial progress.",
"label": "upgrade-job",
"mode": "run",
"cleanup": "keep",
"runTimeoutSeconds": 7200
}
Then reply something like:
Started the upgrade job. I’ll post the result here when it finishes.
Nice extras
- Users can inspect active jobs with
/tasksoropenclaw tasks list - If you want more than final completion, switch notify policy to
state_changes - If you want a dedicated follow-up thread/session, use
thread: trueandmode: "session"
Practical rule of thumb
- One long shell command →
execwithyieldMs/background:true - Multi-step workflow with completion notification →
sessions_spawn - Run later / on schedule → cron
Docs: