Skip to content

The agent that grows with you

fix(groups): a room handed to the gateway is never written to the standalone store while it is down

Teknium63307153bb94
diff --git a/tests/tui_gateway/test_groups_owner_forward.py b/tests/tui_gateway/test_groups_owner_forward.py
index f5a6dee0ac2..c2e9f52e26d 100644
--- a/tests/tui_gateway/test_groups_owner_forward.py
+++ b/tests/tui_gateway/test_groups_owner_forward.py
@@ -150,3 +150,25 @@ def test_a_named_profile_reaches_the_rooms_handed_to_the_root_gateway(home, owne
method, params, reached = owner[-1]
assert (method, reached) == ("groups.state", default_db_path().parent)
assert "profile" not in params # the root gateway answers for its own profile
+
+
+def test_a_handed_room_is_never_renamed_in_the_standalone_store_while_its_gateway_is_down(home, monkeypatch):
+ """A room handed to the gateway lives in the gateway's store; the standalone copy is frozen. With
+ the gateway down, a rename (or any call on that room) is a retryable refusal, never a local
+ write the gateway would never see and the import marker would never copy again."""
+ import sqlite3
+ from gateway.hosted_rooms import default_db_path, list_rooms
+ from gateway.hosted_rooms_gateway_import import import_standalone_rooms
+ from tui_gateway.methods_groups_forward import OWNER_LOST_CODE
+ _discovery(monkeypatch, "absent")
+ srv._methods["groups.create"](1, {"room_id": "room-desk", "name": "Before", "members": MEMBERS})
+ target = default_db_path().with_name("state.db")
+ with sqlite3.connect(target) as conn:
+ conn.execute("CREATE TABLE IF NOT EXISTS state_meta (key TEXT PRIMARY KEY, value TEXT)")
+ assert import_standalone_rooms(target) == 1
+
+ reply = srv._methods["groups.rename"](2, {"room_id": "room-desk", "event_id": "rename-1", "name": "After"})
+
+ assert reply.get("error", {}).get("code") == OWNER_LOST_CODE, reply
+ [kept] = list_rooms(default_db_path(), include_disbanded=True)
+ assert kept["name"] == "Before"
diff --git a/tui_gateway/methods_groups_forward.py b/tui_gateway/methods_groups_forward.py
index 7a06fc67dc5..5a96c7c03aa 100644
--- a/tui_gateway/methods_groups_forward.py
+++ b/tui_gateway/methods_groups_forward.py
@@ -16,8 +16,9 @@ Routing, so no view ever loses a room it listed before:
named profile, its handed rooms read from the root gateway.
The call runs locally only when no gateway serves the profile (``absent``, or an ``incompatible``
-one that never imports). A ``starting``/``draining`` gateway is waited for and any other present
-one is a retryable refusal: a local write then would be hidden from the gateway's list. RoomLink's
+one that never imports) and the room was not handed over: a handed room is never written to the
+standalone store, so with its gateway down every call on it is a retryable refusal. A
+``starting``/``draining`` gateway is waited for and any other present one is a retryable refusal: a local write then would be hidden from the gateway's list. RoomLink's
gateway-to-gateway methods (``groups.peer.*``, replication, promote/demote) stay local.
"""
@@ -164,6 +165,11 @@ def forward(server, rid, method: str, params: dict) -> dict | None:
except ValueError as exc:
return server._err(rid, 4000, str(exc))
if endpoint is None:
+ if holder == "gateway":
+ # Only the gateway's store holds this room; the standalone copy is frozen and never
+ # imported again, so a local call would acknowledge a change the owner never sees.
+ return server._err(rid, OWNER_LOST_CODE, "The Hermes gateway that holds this Group Chat "
+ "is not running. Start it and try again.")
return None
return _call(server, rid, home, endpoint, method, params)