openclaw - ✅(Solved) Fix Sub-agent exec output not returned to parent session [1 pull requests, 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#57965Fetched 2026-04-08 01:55:33
View on GitHub
Comments
0
Participants
1
Timeline
9
Reactions
1
Author
Participants
Timeline (top)
mentioned ×3referenced ×3subscribed ×2cross-referenced ×1
  • Was working before ~March 29, 2026
  • Sub-agents run in isolated sessions
  • streamTo: "parent" is set in spawn config
  • This breaks persistent agents that rely on sub-agents for terminal work — they must ask users to paste command output manually

Root Cause

  • Was working before ~March 29, 2026
  • Sub-agents run in isolated sessions
  • streamTo: "parent" is set in spawn config
  • This breaks persistent agents that rely on sub-agents for terminal work — they must ask users to paste command output manually

Fix Action

Fixed

PR fix notes

PR #58035: fix(subagents): include exec tool result output in parent completion events

Description (problem / solution / changelog)

Summary

  • When a sub-agent runs exec commands, selectSubagentOutputText prioritized the assistant's summary text over raw tool result stdout/stderr — if the LLM's final response didn't echo the output verbatim, the parent session lost the actual data
  • Now accumulates all tool result texts and combines them with the assistant summary, so the parent always receives exec stdout/stderr
  • Also handles a nested content array format in extractToolResultText that could silently return empty string

Context

I had no idea why I was being tagged in an OpenClaw issue as I've never previously contributed here — turns out the reporter wrote @exec as a topic tag at the bottom of the issue. But I was bored tonight, so here's a fix.

Fixes #57965.

Test plan

  • New test: exec tool result included alongside final assistant summary
  • New test: multiple exec tool results all preserved in output
  • New test: nested AgentToolResult content object extracted correctly
  • Existing subagent-announce.capture-completion-reply.test.ts — 7/7 pass
  • Existing subagent-announce.test.ts — 5/5 pass
  • Existing subagent-announce.timeout.test.ts + dispatch + queue — 29/29 pass
  • pnpm build, pnpm check, pnpm tsgo all clean

This fix was developed with assistance from Claude Opus 4.6.

Changed files

  • src/agents/subagent-announce-output.ts (modified, +33/-1)
  • src/agents/subagent-announce.capture-completion-reply.test.ts (modified, +119/-0)

Code Example

wc -c /Users/luna/.openclaw/agents/midas/workspace/RISK_PARAMS.json
RAW_BUFFERClick to expand / collapse

Bug Description

When a persistent agent spawns a sub-agent (runtime=subagent) that runs exec commands, the exec runs successfully (confirmed via token counts) but the stdout/stderr output is NOT returned to the parent session. The parent session only sees the tool call metadata, not the actual command output.

Environment

  • OpenClaw version: 2026.3.28 (f9b1079)
  • macOS: Darwin 25.3.0 (arm64)
  • Node: v22.22.1

Steps to Reproduce

  1. Have a persistent agent with sessions_spawn and subagents in tools.allow
  2. Spawn a sub-agent with runtime=subagent and a task containing exec commands
  3. The sub-agent runs (token counts confirm execution)
  4. The completion event returns to parent, but stdout/stderr is empty — parent gets the tool call structure instead of the actual output

Example

Parent spawns sub-agent to run:

wc -c /Users/luna/.openclaw/agents/midas/workspace/RISK_PARAMS.json

Sub-agent executes (confirmed), but parent receives no output — just the tool metadata.

Expected vs Actual

  • Expected: Sub-agent exec stdout/stderr returned to parent session in completion event
  • Actual: stdout/stderr empty in completion event; parent can't see command output

Context

  • Was working before ~March 29, 2026
  • Sub-agents run in isolated sessions
  • streamTo: "parent" is set in spawn config
  • This breaks persistent agents that rely on sub-agents for terminal work — they must ask users to paste command output manually

Tags

@agents @subagents @exec

extent analysis

Fix Plan

To resolve the issue of stdout/stderr output not being returned to the parent session from a sub-agent, we need to modify the sub-agent spawn configuration and ensure proper output streaming.

Step-by-Step Solution:

  1. Verify streamTo Configuration: Ensure that streamTo is set to "parent" in the sub-agent spawn configuration to stream output back to the parent session.
  2. Update Sub-Agent Spawn Code: Modify the code that spawns the sub-agent to include the correct options for streaming output. For example:

const subagentOptions = { runtime: 'subagent', task: { // Your exec command here exec: 'wc -c /Users/luna/.openclaw/agents/midas/workspace/RISK_PARAMS.json' }, streamTo: 'parent' // Ensure this is set to stream output to the parent };

3. **Handle Output in Parent Session**: In the parent session, ensure you are handling the output from the sub-agent correctly. This might involve parsing the completion event to extract stdout/stderr.

#### Example Code Snippet:
```javascript
// Assuming you have a function to spawn a sub-agent
function spawnSubagent(options) {
  // Implementation to spawn the sub-agent with given options
  // Ensure options include streamTo: 'parent'
}

// Example usage
const subagentOptions = {
  runtime: 'subagent',
  task: {
    exec: 'wc -c /Users/luna/.openclaw/agents/midas/workspace/RISK_PARAMS.json'
  },
  streamTo: 'parent'
};

spawnSubagent(subagentOptions).then(completionEvent => {
  // Handle completionEvent to extract stdout/stderr
  const output = completionEvent.stdout; // or completionEvent.stderr
  console.log(output);
});

Verification

To verify that the fix worked, spawn a sub-agent with the updated configuration and check if the parent session receives the stdout/stderr output as expected. You can do this by:

  • Running the modified code and checking the console output or logs.
  • Using debugging tools to inspect the completion event and verify it contains the expected output.

Extra Tips

  • Ensure your OpenClaw version is up-to-date, as fixes for similar issues might be included in newer versions.
  • Review the documentation for spawning sub-agents and handling output to ensure you're using the latest and correct methods.
  • If issues persist, consider enabling verbose logging or debugging to get more detailed information about the execution and output streaming process.

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