openclaw - 💡(How to fix) Fix session.tool / session.message events don't carry originating sessionKey for subagent sessions [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#57928Fetched 2026-04-08 01:56:03
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0

When a subagent (spawned via sessions_spawn) makes tool calls, the resulting session.tool and session.message events broadcast over the gateway WebSocket do not include the child session's sessionKey. They arrive attributed to the parent session (agent:main:main).

This makes it impossible for operator clients (macOS app, web UI) to attribute tool calls to specific subagents for nested visualization.

Root Cause

When a subagent (spawned via sessions_spawn) makes tool calls, the resulting session.tool and session.message events broadcast over the gateway WebSocket do not include the child session's sessionKey. They arrive attributed to the parent session (agent:main:main).

This makes it impossible for operator clients (macOS app, web UI) to attribute tool calls to specific subagents for nested visualization.

RAW_BUFFERClick to expand / collapse

Summary

When a subagent (spawned via sessions_spawn) makes tool calls, the resulting session.tool and session.message events broadcast over the gateway WebSocket do not include the child session's sessionKey. They arrive attributed to the parent session (agent:main:main).

This makes it impossible for operator clients (macOS app, web UI) to attribute tool calls to specific subagents for nested visualization.

Current Behavior

  • subagent.spawned events correctly include parentSessionKey and child sessionKey
  • session.tool events from subagents carry the parent sessionKey instead of the child's ❌
  • session.message events (containing toolCall content) from subagents carry the parent sessionKey
  • Subscribing via sessions.messages.subscribe with the child session key does not produce events with the child's key

Expected Behavior

session.tool and session.message events should include the originating sessionKey so operator clients can:

  1. Attribute tool calls to specific subagents
  2. Render nested tool activity inside branch cards
  3. Support recursive visibility (subagent → sub-subagent → tool calls)

Use Case

We're building a native macOS control center app that shows a live orchestration theater. Branch cards show subagent spawns. We want to nest each subagent's tool calls inside its branch card — like watching a swarm's 6 workers fan out with their individual search/read/exec calls visible.

The branch hierarchy works (spawn events carry parent/child keys). The tool attribution doesn't (tool events lose the child context).

Suggested Fix

Include the originating session key in tool event broadcasts. Something like:

  • Add originSessionKey or sourceSessionKey field to session.tool / session.message payloads
  • Or preserve the child sessionKey in the existing sessionKey field instead of replacing it with the parent's

Environment

  • OpenClaw 2026.3.24
  • Gateway protocol v3
  • macOS operator client connecting via WebSocket

extent analysis

Fix Plan

To fix the issue, we need to modify the session.tool and session.message event broadcasts to include the child session's sessionKey. We can achieve this by adding a new field originSessionKey to the event payloads.

Code Changes

# In the event broadcasting code
def broadcast_session_tool_event(session, tool_data):
    event = {
        'sessionKey': session.key,  # Use the child session's key
        'tool': tool_data,
        'originSessionKey': session.key  # Add the child session's key
    }
    # Broadcast the event

def broadcast_session_message_event(session, message_data):
    event = {
        'sessionKey': session.key,  # Use the child session's key
        'message': message_data,
        'originSessionKey': session.key  # Add the child session's key
    }
    # Broadcast the event

Configuration Changes

No configuration changes are required for this fix.

Verification

To verify that the fix worked, you can:

  • Subscribe to session.tool and session.message events using the child session key
  • Check that the events received include the child session's sessionKey in the originSessionKey field
  • Verify that the operator client can attribute tool calls to specific subagents and render nested tool activity inside branch cards

Extra Tips

  • Make sure to update the event broadcasting code to use the child session's key instead of the parent's key
  • Consider adding logging or debugging statements to verify that the correct session key is being used in the event broadcasts
  • Test the fix thoroughly to ensure that it works as expected in different scenarios and use cases.

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