fix(messaging): reuse a group's live session instead of recreating per open

create_session and create_session_with_access_check closed the group's active
session and opened a new one on every call. A group is meant to have ONE live
session (groups.active_session_id) that all participants post into, so this
churned a single conversation across many sessions — the smoke run showed ~one
session per message, and the CEO could not hold a conversation in a channel.

Both now reuse the live session when one is active and only open a fresh one
when none is (closed via timeout / boundary / merge), matching the existing
get_or_create_active_session contract.
This commit is contained in:
Renn F
2026-06-04 06:42:21 +02:00
parent 0ac3e9e233
commit 2db9741ff6
2 changed files with 23 additions and 10 deletions
+8 -4
View File
@@ -1655,15 +1655,15 @@ async def test_close_session_handles_bus_failure(msg_setup: dict) -> None:
# ---------------------------------------------------------------------------
# create_session_with_access_check — closes prior active + privileged path
# create_session_with_access_check — reuses the group's live session
# ---------------------------------------------------------------------------
@pytest.mark.asyncio
async def test_create_session_with_access_check_closes_prior(
async def test_create_session_with_access_check_reuses_active(
msg_setup: dict,
) -> None:
"""Existing ACTIVE session is closed before creating new one."""
"""A group has ONE live session; opening again reuses it (no churn)."""
svc = msg_setup["svc"]
aid = msg_setup["agent_id"]
ch = await svc.create_channel(_channel_req(uuid4().hex[:6]))
@@ -1683,7 +1683,11 @@ async def test_create_session_with_access_check_closes_prior(
timeout_seconds=300,
),
)
assert new_sess.id != prior.id
# Same live session is returned, not a fresh one — and it stays active.
assert new_sess.id == prior.id
refetched = await svc.get_session(prior.id)
assert refetched is not None
assert refetched.status == SessionStatus.ACTIVE
# ---------------------------------------------------------------------------