Skip to content

WebSocket channel silently drops media from inbound messages #3674

@ivelin

Description

@ivelin

Summary

The WebSocketChannel._dispatch_envelope() ignores the media field from inbound WebSocket message envelopes. When a client sends a message with file/image attachments via the media JSON field, the paths are silently dropped — the agent never receives them.

Steps to Reproduce

  1. Start a nanobot container with WebSocket channel enabled
  2. Connect a client via WebSocket at ws://host:8765
  3. Subscribe by sending: {"event": "attach", "chat_id": "test"}
  4. Send a message WITH a media attachment:
    {
      "type": "message",
      "chat_id": "test",
      "content": "analyze this image",
      "media": ["/path/to/image.jpg"]
    }
  5. The agent responds as if no image was attached — the media field is completely ignored

Root Cause

In nanobot/channels/websocket.py, the _dispatch_envelope method extracts content from the envelope but never extracts media. The _handle_message() call is missing media=media:

# Current (broken):
if t == "message":
    cid = envelope.get("chat_id")
    content = envelope.get("content")
    ...
    await self._handle_message(
        sender_id=client_id,
        chat_id=cid,
        content=content,
        metadata={...},
    )

Fix

PR #3673 adds:

  1. media = envelope.get("media") extraction from the envelope
  2. Allow media-only messages (content can be empty if media is present)
  3. Pass media to _handle_message()
  4. Safe content default with or ""

Impact

Any nanobot running with WebSocket channel cannot receive media attachments from clients. The HTTP streaming channel (OpenAI API on port 18791) works because it receives media via the standard OpenAI message format, but the WebSocket channel is broken for media.

Workaround

Route media messages through the OpenAI-compatible API (nanobot serve on port 18791) instead of the WebSocket channel, or apply the patch from PR #3673.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions