openclaw - 💡(How to fix) Fix [Feature]: Background sub-agent spawn mode — parent session completes immediately while children run async [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#62478Fetched 2026-04-08 03:03:42
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Add a sub-agent spawn mode where the parent's run completes immediately after dispatching children, leaving the parent session free to accept new user messages while sub-agents work in the background. Results are delivered asynchronously via injected messages, notifications, or kanban updates.

Root Cause

Add a sub-agent spawn mode where the parent's run completes immediately after dispatching children, leaving the parent session free to accept new user messages while sub-agents work in the background. Results are delivered asynchronously via injected messages, notifications, or kanban updates.

Fix Action

Fix / Workaround

Add a sub-agent spawn mode where the parent's run completes immediately after dispatching children, leaving the parent session free to accept new user messages while sub-agents work in the background. Results are delivered asynchronously via injected messages, notifications, or kanban updates.

Code Example

User sends message
Parent spawns child 1 (returns immediately with runId)
Parent spawns child 2 (returns immediately)
Parent calls agent.wait(child1)BLOCKS
Child 1 completes → announcement delivered
Parent calls agent.wait(child2)BLOCKS
Child 2 completes → announcement delivered
Parent synthesizes and responds
User can finally send another message

---

User sends message
Parent spawns child 1 (mode: "background")
Parent spawns child 2 (mode: "background")  
Parent responds: "I've started both tasks. I'll update you when they're done."
Parent's run completes (final) ← session is now FREE
User can chat normally
[Later] Child 1 finishes → result injected as message / notification / kanban update
[Later] Child 2 finishes → result injected as message / notification / kanban update
RAW_BUFFERClick to expand / collapse

Summary

Add a sub-agent spawn mode where the parent's run completes immediately after dispatching children, leaving the parent session free to accept new user messages while sub-agents work in the background. Results are delivered asynchronously via injected messages, notifications, or kanban updates.

Problem

When a parent agent spawns sub-agents via sessions_spawn, the parent's turn stays alive for the entire duration of the sub-agent work — it calls agent.wait(childRunId) which blocks until all children complete. During this time:

  • The user cannot send new messages — the parent session has an active run, so chat.send is rejected
  • The UI appears frozen — even though children are working independently on separate sessions
  • Simple follow-ups are impossible — "what's the status?", "also do X", or just casual chatting must wait until all orchestration completes

This is the #1 UX complaint for desktop/chat interfaces built on OpenClaw (e.g. Cookie OS). Long-running sub-agent tasks (web research, multi-step file processing, complex analysis) can take minutes, during which the entire chat is locked.

Current behavior

User sends message
  → Parent spawns child 1 (returns immediately with runId)
  → Parent spawns child 2 (returns immediately)
  → Parent calls agent.wait(child1) — BLOCKS
  → Child 1 completes → announcement delivered
  → Parent calls agent.wait(child2) — BLOCKS
  → Child 2 completes → announcement delivered
  → Parent synthesizes and responds
  → User can finally send another message

sessions_yield gets close but the parent's lifecycle is still coupled to the children — the parent is suspended waiting for wake events, not truly free.

Proposed behavior

A new parameter on sessions_spawn — e.g. mode: "background" or detach: true:

User sends message
  → Parent spawns child 1 (mode: "background")
  → Parent spawns child 2 (mode: "background")  
  → Parent responds: "I've started both tasks. I'll update you when they're done."
  → Parent's run completes (final) ← session is now FREE
  → User can chat normally
  → [Later] Child 1 finishes → result injected as message / notification / kanban update
  → [Later] Child 2 finishes → result injected as message / notification / kanban update

Implementation notes

Most infrastructure already exists:

  • Async spawnspawnSubagentDirect() already returns immediately with status: "accepted"
  • Separate sessions — children already run on isolated sessions (agent:X:subagent:UUID)
  • Announcement systemsubagent-announce.ts already formats completion results
  • SubagentRegistry — already tracks child runs independently
  • Task systemtask-executor.ts provides durable lifecycle tracking

What's needed:

  1. New spawn parameter (mode: "background" or detach: true) in SpawnSubagentParams
  2. Skip expectsCompletionMessage: true for background spawns — parent doesn't wait
  3. On child completion, deliver results through an async channel:
    • Option A: Inject as a new user/system message into the parent session (like cron job results do)
    • Option B: Write to kanban task / memory note
    • Option C: Emit a gateway event that control UIs can surface as a notification
  4. System prompt guidance for when to use background vs. foreground spawning

Use case

Cookie OS — an Electron desktop app using OpenClaw as its agent runtime — provides a chat interface where users interact with their agent. When sub-agents are working, the entire chat is locked. Users expect to keep conversing while background work proceeds. The OpenClaw gateway enforces one active run per session, so this cannot be worked around at the client level.

Related issues

  • #55481 — HTTP endpoint for fire-and-forget spawn (external callers). Our issue is about the in-session agent experience.
  • #53483 — Auto-yield parent after mode=run ACP spawn. Addresses a related symptom but doesn't free the parent session.
  • #38626 — Subagent lifecycle observability. Complementary — background spawns would benefit from better observability.
  • #46413 — Long task notification after WebSocket disconnect. Related delivery problem.

extent analysis

TL;DR

Implement a new spawn mode in sessions_spawn that allows the parent agent to complete its run immediately after dispatching children, enabling asynchronous result delivery and freeing the parent session to accept new user messages.

Guidance

  • Introduce a new parameter in SpawnSubagentParams, such as mode: "background" or detach: true, to enable background spawning of sub-agents.
  • Modify the sessions_spawn function to skip waiting for completion messages when the mode parameter is set to "background", allowing the parent agent to complete its run immediately.
  • Implement an asynchronous channel to deliver results from completed sub-agents, such as injecting messages into the parent session, writing to kanban tasks, or emitting gateway events.
  • Update the SubagentRegistry and task system to track and manage background sub-agent runs independently.

Example

// Example of updated sessions_spawn function with background mode
function sessions_spawn(params: SpawnSubagentParams) {
  if (params.mode === "background") {
    // Spawn sub-agent and return immediately
    spawnSubagentDirect(params);
    // Complete parent agent's run
    return { status: "completed" };
  } else {
    // Existing foreground spawn behavior
    const childRunId = spawnSubagentDirect(params);
    // Wait for completion message
    return agent.wait(childRunId);
  }
}

Notes

The implementation of background spawning will require careful consideration of result delivery and error handling to ensure a seamless user experience. Additionally, the system prompt guidance for when to use background vs. foreground spawning will need to be updated to reflect the new functionality.

Recommendation

Apply the workaround by implementing the new spawn mode in sessions_spawn, as this will address the primary issue of the parent agent's run being blocked by waiting for sub-agent completion. This change will enable asynchronous result delivery and free the parent session to accept new user messages.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING