diff --git a/plugin/pheby/hermes_bridge.py b/plugin/pheby/hermes_bridge.py index 691a217..fb3340c 100644 --- a/plugin/pheby/hermes_bridge.py +++ b/plugin/pheby/hermes_bridge.py @@ -134,7 +134,7 @@ async def create_conversation(server: Any, name: Optional[str]) -> str: if store is not None: try: await asyncio.to_thread( - store.get_or_create_session, _source_for(cid), False, False) + store.get_or_create_session, _source_for(cid)) if name: await rename_conversation(cid, name) except Exception: diff --git a/plugin/pheby/server.py b/plugin/pheby/server.py index 941ac82..2e2747d 100644 --- a/plugin/pheby/server.py +++ b/plugin/pheby/server.py @@ -173,6 +173,14 @@ class PhebyServer: # ── WebSocket handler ──────────────────────────────────────────────── async def _handle_ws(self, request: web.Request) -> web.WebSocketResponse: + # Bind server/adapter identity to THIS task's context. ContextVars set + # in adapter.connect() do not propagate into aiohttp handler tasks, so + # every per-connection task must bind them itself — hermes_bridge's + # _current_server()/_current_adapter() resolve from here in all + # message handlers and agent-thread callbacks. + hermes_bridge.set_server(self) + if self.adapter is not None: + hermes_bridge.set_adapter(self.adapter) ws = web.WebSocketResponse(max_msg_size=proto.MAX_WS_MESSAGE_BYTES, heartbeat=30.0, autoping=True) await ws.prepare(request)