17ba992108
Fixes #88532. A multiplexed gateway serves every profile from one process, but SessionStore bound a single SessionDB during __init__: self._db = SessionDB() SessionDB(db_path=None) resolves _default_db_path() at call time and does follow the context-local HERMES_HOME override, so the path machinery was already correct. The problem was when it ran: at construction, on the process's own root home, long before any inbound event enters _profile_runtime_scope. Every profile's rows therefore landed in the root state.db, even though the scope had redirected get_hermes_home() correctly for the turn (that helper's own docstring lists "sessions" among what it scopes). The rows still carry the right profile_name, stamped from source.profile by the same handler, so nothing in the data looks wrong. The only visible symptom is the desktop listing a profile's session under the default bot: _open_session_db_for_profile opens profiles/<name>/state.db, which never received the write. Look the handle up through a property instead, resolving the active scope per access and caching one handle per resolved path so a hot inbound path opens SQLite once per profile rather than once per message. Construction stays under the cache lock so a concurrent first message on a profile cannot open and then leak a second handle. Assignment is preserved as an explicit pin, which is what the existing suites rely on when they install a fake handle or disable the DB with store._db = None, and a pin keeps winning across scope changes. Behavior is unchanged when no profile scope is active, so single-profile gateways resolve exactly the path they did before. This does not migrate rows that already landed in the root store; those stay where they are.