Skip to content

The agent that grows with you

fix(api): the hosted-room binding and the delete-time image sweep run off the owner loop

Teknium27f3a49137b1
diff --git a/gateway/platforms/api_server.py b/gateway/platforms/api_server.py
index 3b4a85ff776..00ca98459b9 100644
--- a/gateway/platforms/api_server.py
+++ b/gateway/platforms/api_server.py
@@ -3211,10 +3211,10 @@ class APIServerAdapter(OpenAICompatRoutesMixin, BasePlatformAdapter):
store = getattr(runner, "session_store", None)
if store is not None:
await asyncio.to_thread(store.remove_by_session_id, session_id)
- # Retirement erased the chat's image references; bytes nothing else holds go too. On
- # the loop, like API image capture + admission, so no fresh capture is collected early.
+ # Retirement erased the chat's image references; bytes nothing else holds go too. Off the
+ # loop like every other media release: its holder check and unlink are one write txn.
from gateway.session_ingress_media import collect_unheld_api_images
- collect_unheld_api_images(db)
+ await asyncio.to_thread(collect_unheld_api_images, db)
return web.json_response({"object": "hermes.session.deleted", "id": session_id, "deleted": bool(deleted)})
@_require_auth
diff --git a/gateway/platforms/api_server_room_dispatch.py b/gateway/platforms/api_server_room_dispatch.py
index 2fea6366ab0..8be1714c38c 100644
--- a/gateway/platforms/api_server_room_dispatch.py
+++ b/gateway/platforms/api_server_room_dispatch.py
@@ -29,10 +29,12 @@ async def _ensure_hosted_member_session(self, dispatch: Any) -> str:
from gateway.session_authorities import active_authority
authority = active_authority(self.gateway_runner)
if authority is not None:
- from gateway.session_api import bind_api_session
+ from gateway.session_api import bind_api_steps, run_steps_off_loop
if db is not authority.db:
raise RuntimeError('profile_mismatch')
- return bind_api_session(authority, session_id, hosted_dispatch=dispatch.as_mapping()).session_id
+ # The binding transaction runs off the owner loop, in admission order (as API admission does).
+ return (await run_steps_off_loop(authority, bind_api_steps(
+ authority, session_id, hosted_dispatch=dispatch.as_mapping()))).session_id
def atomic(conn):
row = conn.execute("SELECT id, title, source FROM sessions WHERE id=?", (session_id,)).fetchone()