Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/openharness/swarm/in_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ async def start_in_process_teammate(
)
set_teammate_context(ctx)

mailbox = TeammateMailbox(team_name=config.team, agent_id=agent_id)
# Poll the inbox keyed by the bare agent name — that is where the leader's
# send_message() delivers, not the fully-qualified ``name@team`` id.
mailbox = TeammateMailbox(team_name=config.team, agent_id=config.name)

logger.debug("[in_process] %s: starting", agent_id)

Expand Down
42 changes: 42 additions & 0 deletions tests/test_swarm/test_in_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
from __future__ import annotations

from pathlib import Path
from types import SimpleNamespace

import pytest

from openharness.swarm.in_process import (
InProcessBackend,
TeammateAbortController,
TeammateContext,
get_teammate_context,
set_teammate_context,
start_in_process_teammate,
)
from openharness.swarm.types import TeammateMessage, TeammateSpawnConfig

Expand Down Expand Up @@ -155,6 +158,45 @@ async def test_send_message_invalid_agent_id_raises(backend):
await backend.send_message("no-at-sign", TeammateMessage(text="hi", from_agent="l"))


async def test_teammate_receives_message_sent_by_leader(backend, tmp_path, monkeypatch):
# send_message writes to the inbox keyed by the bare agent name, so the
# running teammate must poll that same inbox. Regression guard for the key
# mismatch where start_in_process_teammate polled "name@team" instead and
# every leader -> teammate message was silently dropped.
monkeypatch.setattr(Path, "home", lambda: tmp_path)
config = TeammateSpawnConfig(
name="rcvr",
team="myteam",
prompt="wait",
cwd="/tmp",
parent_session_id="s",
)

await backend.send_message(
"rcvr@myteam", TeammateMessage(text="work on it", from_agent="leader")
)

# Drive a single query turn so the teammate drains its mailbox exactly once.
async def fake_run_query(query_context, messages):
yield SimpleNamespace(type="text"), None

monkeypatch.setattr("openharness.engine.query.run_query", fake_run_query)

await start_in_process_teammate(
config=config,
agent_id="rcvr@myteam",
abort_controller=TeammateAbortController(),
query_context=object(),
)

from openharness.swarm.mailbox import TeammateMailbox

inbox = TeammateMailbox(team_name="myteam", agent_id="rcvr")
assert await inbox.read_all(unread_only=True) == []
delivered = await inbox.read_all(unread_only=False)
assert any(m.payload.get("content") == "work on it" for m in delivered)


# ---------------------------------------------------------------------------
# active_agents / shutdown_all
# ---------------------------------------------------------------------------
Expand Down
Loading