fix(gateway): isolate hosted-room state in shared-state.db — profile gateways must not write master state.db

gateway.hosted_rooms.default_db_path() resolved profile gateways
(~/.hermes/profiles/<name>/) to the ROOT state.db, making every profile
gateway process a long-lived writer on the master session store. Across a
6-gateway fleet this was the recurring multi-writer corruption vector
(WAL/FTS collisions during bot-gateway restart storms, observed 2026-09-03
with four state.db corruptions in five weeks fleet-wide; upstream refs
#100896, #100313, #102827).

Move hosted_room* tables to a dedicated root shared-state.db so profile
gateways never open state.db writable. Single-gateway installs are
unaffected (same file semantics, different filename); multi-profile fleets
stop sharing the master store.

Verified live in production: deployed 2026-09-04, zero I/O-error /
reopen-race events across 9h+ of active multi-gateway load (previously
~1 failure per 2-3 min).

Co-authored-by: Rik <rik.sedd@gmail.com>
This commit is contained in:
Rik authored and Teknium committed 2026-09-11 06:21:48 -07:00
1 parent 52fb4e0877
commit 0e422e0ece
1 file changed
+13 -2
+13 -2
View File
@@ -396,10 +396,21 @@ def _schema_is_current(conn: sqlite3.Connection) -> bool:
def default_db_path() -> Path:
"""Return the gateway-wide state database for the active install."""
"""Return the hosted-room coordination database for the active install.
Profile gateways (``~/.hermes/profiles/<name>/``) resolve to the shared
ROOT ``shared-state.db`` instead of the master ``state.db``: hosted-room
coordination is the only thing this module owns, and pointing profile
gateways at the master session store makes every profile process a
long-lived writer on state.db — the recurring multi-writer corruption
vector observed across a 6-gateway fleet (state.db WAL/FTS collisions
during bot-gateway restart storms, 2026-09-03). Keeping the hosted_room*
tables in a dedicated file means profile gateways never open the master
session store writable.
"""
from hermes_constants import get_hermes_home
home = get_hermes_home()
return (home.parent.parent if home.parent.name == "profiles" else home) / "state.db"
return (home.parent.parent if home.parent.name == "profiles" else home) / "shared-state.db"
def local_authority_gateway_id() -> str: