The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(gateway): share the profile-scope key between scope entry and heartbeat restore
kshitijk4poor1e643524cb77
diff --git a/gateway/run_heartbeat_restore.py b/gateway/run_heartbeat_restore.pyindex 6a3595a3718..b8dbc459ce7 100644--- a/gateway/run_heartbeat_restore.py+++ b/gateway/run_heartbeat_restore.py@@ -19,13 +19,6 @@ def _watched_homes(runner, default_home) -> list:return list(dict.fromkeys(Path(home) for home in homes))-def _scope_key(runner, origin) -> str:- """Profile home ``_profile_scope_for_source`` would bind for ``origin`` (one key when not multiplexed)."""- if getattr(getattr(runner, "config", None), "multiplex_profiles", False):- return str(runner._resolve_profile_home_for_source(origin))- return ""--async def restore_heartbeat_watches(runner) -> None:"""Retryable startup/poll scan; failed reads never prune existing watches.@@ -60,7 +53,7 @@ async def restore_heartbeat_watches(runner) -> None:continuetry:source = runner._restored_source(entry)- by_scope.setdefault(_scope_key(runner, source), []).append((entry, source))+ by_scope.setdefault(runner._profile_scope_key_for_source(source), []).append((entry, source))except Exception:logger.debug("heartbeat restore for %s failed", entry.session_key, exc_info=True)for group in by_scope.values():diff --git a/gateway/run_turn.py b/gateway/run_turn.pyindex 9db244ffb56..b5a1cc283a9 100644--- a/gateway/run_turn.py+++ b/gateway/run_turn.py@@ -2251,10 +2251,20 @@ class GatewayTurnMixin:(``multiplex_profiles`` off) still binds once a hosted room has flipped the process-widecredential guard — see ``_standalone_launch_scope``."""from gateway.run import _profile_runtime_scope- if getattr(getattr(self, "config", None), "multiplex_profiles", False):- return _profile_runtime_scope(self._resolve_profile_home_for_source(source))+ home_key = self._profile_scope_key_for_source(source)+ if home_key is not None:+ return _profile_runtime_scope(home_key)return self._standalone_launch_scope()+ def _profile_scope_key_for_source(self, source: SessionSource) -> Optional[str]:+ """Profile home ``_profile_scope_for_source`` binds for ``source``, or ``None`` when it falls+ back to the standalone launch scope. The single owner of that branch condition: callers that+ group work per scope (heartbeat restore) key on this so they cannot drift from the scope+ actually entered."""+ if getattr(getattr(self, "config", None), "multiplex_profiles", False):+ return str(self._resolve_profile_home_for_source(source))+ return None+@staticmethoddef _standalone_launch_scope():"""Scope for a standalone gateway's own (launch-profile) work: a no-op until the process hosts