openclaw - 💡(How to fix) Fix feat: sessions_send should include sourceSession in chat.history message metadata [1 comments, 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#51007Fetched 2026-04-08 01:05:39
View on GitHub
Comments
1
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×2commented ×1

Fix Action

Fix / Workaround

Workaround (current)

Code Example

{
  "role": "user",
  "content": "GO",
  "timestamp": 1234567890
}

---

{
  "role": "user",
  "content": "GO",
  "timestamp": 1234567890,
  "sourceSession": "agent:mentor:asuka-deck"
}

---

[Inter-session message] sourceSession=agent:mentor:asuka-deck
GO
RAW_BUFFERClick to expand / collapse

Problem

When an agent uses sessions_send to send a message to another agent, the receiving agent's chat.history stores the message with role: "user" but without any information about the source session.

This makes it impossible for frontend clients (like AsukaDeck) to distinguish:

  • Messages sent by the human user (KEN)
  • Messages injected by another agent via sessions_send (Komuken → Asuka)

Current behavior

chat.history response:

{
  "role": "user",
  "content": "GO",
  "timestamp": 1234567890
}

The OpenClaw UI layer shows [Inter-session message] sourceSession=agent:mentor:asuka-deck as a prefix in the conversation view, but this prefix is not included in the raw content field returned by chat.history or the chat WebSocket event.

Desired behavior

Include sourceSession in the message metadata so frontend clients can use it:

Option 1: Metadata field

{
  "role": "user",
  "content": "GO",
  "timestamp": 1234567890,
  "sourceSession": "agent:mentor:asuka-deck"
}

Option 2: Content prefix (backwards-compatible)

[Inter-session message] sourceSession=agent:mentor:asuka-deck
GO

Include the same prefix in the raw content that the UI already displays.

Use Case

Multi-agent AsukaDeck: A React frontend for OpenClaw that displays conversations between a human user and multiple AI agents. Without sourceSession info, we cannot color-code or label messages by agent identity without relying on LLM-generated prefixes (fragile, violates design principles).

Impact

  • Any multi-agent setup where agents communicate via sessions_send and a frontend client needs to display message attribution
  • Growing use case as multi-agent workflows become more common

Workaround (current)

Requiring LLMs to manually prefix all messages with 【Agent Name → Target】 — brittle and LLM-dependent.

extent analysis

Fix Plan

To address the issue, we will modify the sessions_send endpoint to include the sourceSession information in the message metadata. We will implement Option 1: Metadata field.

Step-by-Step Solution

  • Modify the sessions_send endpoint to accept an optional sourceSession parameter.
  • Update the chat.history response to include the sourceSession field.
  • Modify the chat WebSocket event to include the sourceSession field.

Example Code

# Modified sessions_send endpoint
def sessions_send(session_id, content, source_session=None):
    # ...
    message = {
        "role": "user",
        "content": content,
        "timestamp": timestamp,
    }
    if source_session:
        message["sourceSession"] = source_session
    # ...

# Updated chat.history response
def chat_history(session_id):
    # ...
    messages = []
    for message in db.query(Message).filter_by(session_id=session_id):
        message_data = {
            "role": message.role,
            "content": message.content,
            "timestamp": message.timestamp,
        }
        if message.source_session:
            message_data["sourceSession"] = message.source_session
        messages.append(message_data)
    return messages

# Modified chat WebSocket event
def chat_websocket_event(session_id, message):
    # ...
    event_data = {
        "role": message.role,
        "content": message.content,
        "timestamp": message.timestamp,
    }
    if message.source_session:
        event_data["sourceSession"] = message.source_session
    # ...

Verification

To verify the fix, send a message using the sessions_send endpoint with the sourceSession parameter. Then, retrieve the chat.history response and check that the sourceSession field is included in the message metadata. Additionally, verify that the chat WebSocket event includes the sourceSession field.

Extra Tips

  • Ensure that the sourceSession parameter is properly validated and sanitized to prevent potential security vulnerabilities.
  • Consider adding additional logging or monitoring to track the usage of the sourceSession feature.
  • Review the documentation for the sessions_send endpoint and chat.history response to ensure that they accurately reflect the changes made.

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 feat: sessions_send should include sourceSession in chat.history message metadata [1 comments, 1 participants]