Skip to content

Leave/join messages appear in wrong channel, uses global instead of per-agent tracking #48

@markheck-solutions

Description

@markheck-solutions

I was working in a custom channel with both agents and their disconnect/reconnect messages were showing up in both my channel and #general seemingly at random.

Claude dug into it and applied the following fix, which has been stable all day now:

The cause is _last_active_channel in app.py (line 490). It's a single global variable that gets overwritten every time any agent or user sends a message in any channel:

_last_active_channel: str = "general"  # last channel any message was sent in

When the crash timeout fires and posts a leave message, it uses this global:

store.add(name, f"{name} disconnected (timeout)", msg_type="leave", channel=_last_active_channel)

So the leave goes to whichever channel had the most recent activity server-wide, not the channel the departing agent was actually in.

Fix: track a per-agent last channel in mcp_bridge.py, update it from chat_send and chat_join, and look it up when posting leave messages instead of using the global.

# mcp_bridge.py
_agent_last_channel: dict[str, str] = {}  # agent_name -> last channel they sent/joined

def get_agent_channel(name: str) -> str:
    return _agent_last_channel.get(name, "general")
# app.py - all three leave message calls
store.add(name, f"{name} disconnected (timeout)", msg_type="leave", channel=mcp_bridge.get_agent_channel(name))

Also, chat_join was hardcoded to post to "general" regardless of the channel parameter passed in. That should use the passed channel.

Environment:

  • agentchattr v0.3.2 (3e71d42)
  • WSL2 (Ubuntu 24.04) on Windows
  • Python 3.12.3, Node v24.14.0
  • Claude Code 2.1.83, Codex CLI 0.116.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions