openclaw - 💡(How to fix) Fix [Bug] orchestrator mode (maxSpawnDepth=2): sub-agent final output not announced to main session [2 comments, 3 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#52174Fetched 2026-04-08 01:14:44
View on GitHub
Comments
2
Participants
3
Timeline
2
Reactions
0
Timeline (top)
commented ×2

Fix Action

Workaround

None confirmed. Not using an orchestrator (spawning all workers directly from main session) works, but defeats the purpose of the orchestrator pattern for complex multi-step workflows.

Code Example

{
    "agents": {
      "defaults": {
        "subagents": {
          "maxSpawnDepth": 2,
          "maxChildrenPerAgent": 5
        }
      }
    }
  }

---

[msg/assistant] Spawned all 4 grandchild agents in parallel. Waiting for their results...
[msg/user] (grandchild completion event: 减法)
[msg/assistant] - Agent 3 (减法):23-9=?14 | Waiting for remaining 3...
[msg/user] (grandchild completion event: 乘法)
[msg/assistant] - Agent 1 (乘法):9×8=?72 | Waiting for remaining 2...
[msg/user] (grandchild completion event: 加法)
[msg/assistant] - Agent 2 (加法):7+8=?15 | Waiting for remaining 1...
[msg/user] (grandchild completion event: 除法)
[msg/assistant] All 4 grandchild agents completed! Outputting final JSON:
[{"agent": "1", "question": "9×8=?", "answer": "72"}, {"agent": "2", "question": "7+8=?", "answer": "15"}, {"agent": "3", "question": "23-9=?", "answer": "14"}, {"agent": "4", "question": "18÷3=?", "answer": "6"}]
RAW_BUFFERClick to expand / collapse

Bug Description

When using the orchestrator pattern (maxSpawnDepth: 2), the depth-1 sub-agent correctly receives completion events from depth-2 grandchild agents and correctly aggregates their results. However, the sub-agent's final aggregated output is not announced to the main session — only the first assistant message is pushed.

Environment

  • OpenClaw: 2026.3.13
  • Configuration:
    {
      "agents": {
        "defaults": {
          "subagents": {
            "maxSpawnDepth": 2,
            "maxChildrenPerAgent": 5
          }
        }
      }
    }

Steps to Reproduce

  1. Spawn a depth-1 sub-agent with mode: "run", maxSpawnDepth: 2 configured
  2. The sub-agent spawns 4 depth-2 grandchild agents in parallel
  3. Grandchild agents complete and send completion events to the depth-1 sub-agent
  4. Depth-1 sub-agent correctly receives all 4 completion events, aggregates results, and outputs final JSON
  5. Main session only receives the first message from the sub-agent ("Spawned all 4...""), NOT the final aggregated JSON

Expected Behavior

Per the Sub-Agents documentation:

Depth-2 worker finishes → announces to its parent (depth-1 orchestrator) Depth-1 orchestrator receives the announce, synthesizes results, finishes → announces to main Main agent receives the announce and delivers to the user

The depth-1 orchestrator's final output (after collecting all depth-2 results) should be announced to the main session.

Actual Behavior

The announce to the main session contains only the depth-1 sub-agent's first assistant message (the one output immediately after spawning children). The final assistant message (containing aggregated results after all grandchild completion events are processed) is never announced.

Transcript Evidence

Sub-agent session log shows:

[msg/assistant] Spawned all 4 grandchild agents in parallel. Waiting for their results...
[msg/user] (grandchild completion event: 减法)
[msg/assistant] - Agent 3 (减法): ✅ 23-9=? → 14 | Waiting for remaining 3...
[msg/user] (grandchild completion event: 乘法)
[msg/assistant] - Agent 1 (乘法): ✅ 9×8=? → 72 | Waiting for remaining 2...
[msg/user] (grandchild completion event: 加法)
[msg/assistant] - Agent 2 (加法): ✅ 7+8=? → 15 | Waiting for remaining 1...
[msg/user] (grandchild completion event: 除法)
[msg/assistant] All 4 grandchild agents completed! Outputting final JSON:
[{"agent": "1", "question": "9×8=?", "answer": "72"}, {"agent": "2", "question": "7+8=?", "answer": "15"}, {"agent": "3", "question": "23-9=?", "answer": "14"}, {"agent": "4", "question": "18÷3=?", "answer": "6"}]

Main session only received: "Spawned all 4 grandchild agents in parallel. Waiting for their results..."

Possible Cause

The announce mechanism appears to push the first assistant message immediately after the sub-agent yields (or after its first turn), rather than waiting for the sub-agent to naturally finish after processing all child completion events.

Workaround

None confirmed. Not using an orchestrator (spawning all workers directly from main session) works, but defeats the purpose of the orchestrator pattern for complex multi-step workflows.

extent analysis

Fix Plan

To fix the issue, we need to modify the announce mechanism to wait for the sub-agent to finish processing all child completion events before sending the final output to the main session.

Here are the steps:

  • Update the announce function in the sub-agent to check if all child completion events have been processed before sending the final output.
  • Add a flag to track whether all child completion events have been processed.
  • Set the flag to true when all child completion events have been processed.
  • Use the flag to determine whether to send the final output or not.

Example code:

// Update the announce function
function announce(output) {
  if (allChildrenCompleted) {
    // Send the final output to the main session
    mainSession.send(output);
  } else {
    // Do not send the output yet
  }
}

// Add a flag to track whether all child completion events have been processed
let allChildrenCompleted = false;

// Set the flag to true when all child completion events have been processed
function onChildCompletion(event) {
  // Process the child completion event
  // ...
  if (allChildrenCompletedCallback()) {
    allChildrenCompleted = true;
    // Send the final output to the main session
    announce(finalOutput);
  }
}

// Function to check if all child completion events have been processed
function allChildrenCompletedCallback() {
  // Check if all child completion events have been processed
  // ...
  return true; // or false
}

Verification

To verify that the fix worked, you can test the orchestrator pattern with the updated announce function and check if the main session receives the final aggregated output from the sub-agent.

  • Spawn a depth-1 sub-agent with mode: "run" and maxSpawnDepth: 2 configured.
  • The sub-agent spawns 4 depth-2 grandchild agents in parallel.
  • The grandchild agents complete and send completion events to the depth-1 sub-agent.
  • The depth-1 sub-agent receives all 4 completion events, aggregates the results, and outputs the final JSON.
  • The main session should receive the final aggregated output from the sub-agent.

Extra Tips

  • Make sure to update the announce function correctly to wait for all child completion events to be processed before sending the final output.
  • Test the orchestrator pattern thoroughly to ensure that it works as expected with the updated announce function.

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

openclaw - 💡(How to fix) Fix [Bug] orchestrator mode (maxSpawnDepth=2): sub-agent final output not announced to main session [2 comments, 3 participants]