The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): run curator/skills-sync housekeeping ticks under each served profile's scope
teknium1b5e8bb72b01a
diff --git a/gateway/run.py b/gateway/run.pyindex 2d19ba5645c..776a4bcf8da 100644--- a/gateway/run.py+++ b/gateway/run.py@@ -4642,7 +4642,7 @@ def _start_gateway_housekeeping("""Background thread for gateway-only periodic chores (NOT cron). Separate from the cron triggerso chores run under any ``CronScheduler`` provider (external scale-to-zero has no 60s loop).Cadences are ticks of ``interval``; inner gates own the real cadence."""- from gateway.run_profile_reconcile import _mcp_config_reconciler+ from gateway.run_profile_reconcile import _mcp_config_reconciler, profile_scoped_chorechores: list[tuple[int, str, Any]] = [# First every tick: re-stamp ``updated_at`` in gateway_state.json so it is a real heartbeat.# ``hermes gateway status`` / ``/api/status`` warn when it ages past 2x ``interval`` with the@@ -4665,9 +4665,10 @@ def _start_gateway_housekeeping(# already ended (#111010). Runs every tick so the outage is bounded by one housekeeping interval.chores.append((1, "Cron ticker supervisor", cron_thread.restart_if_dead))chores += [- (60, "Curator tick", _housekeeping_curator),- (60, "Sync pull tick", _housekeeping_skill_sync),- (60, "Org sync pull tick", _housekeeping_org_skill_sync),+ # Per served profile: each profile has its own skills tree, curator state and Nous login.+ (60, "Curator tick", profile_scoped_chore(runner, _housekeeping_curator)),+ (60, "Sync pull tick", profile_scoped_chore(runner, _housekeeping_skill_sync)),+ (60, "Org sync pull tick", profile_scoped_chore(runner, _housekeeping_org_skill_sync)),(60, "Auto-archive tick", _housekeeping_auto_archive),(1, "Deferred FTS retry tick", _housekeeping_deferred_fts_retry),(1, "gateway housekeeping memory trim", _housekeeping_memory_trim),diff --git a/gateway/run_profile_reconcile.py b/gateway/run_profile_reconcile.pyindex d0da7826eee..b44b2417a3c 100644--- a/gateway/run_profile_reconcile.py+++ b/gateway/run_profile_reconcile.py@@ -242,17 +242,36 @@ def _mcp_config_reconciler(runner=None):logger.info("MCP servers reconciled with config (%s): removed=%s added=%s",label, result["removed"], result["added"])- def _tick() -> None:- from gateway.run import _multiplex_profile_homes, _profile_runtime_scope- config = getattr(runner, "config", None)- if not getattr(config, "multiplex_profiles", False):- _reconcile_current("default")- return- for profile_name, profile_home in _multiplex_profile_homes(config):- with _profile_runtime_scope(Path(profile_home)):- _reconcile_current(str(profile_name))-- return _tick+ return lambda: _for_each_served_profile(runner, _reconcile_current)+++def _for_each_served_profile(runner, body) -> None:+ """Run ``body(profile_label)`` once per served profile, inside that profile's runtime scope.++ Housekeeping runs on a bare thread with no turn on the stack, so nothing binds a profile for it:+ ``get_hermes_home()`` and ``get_secret()`` see the LAUNCH profile's values, and under+ ``gateway.multiplex_profiles`` a fail-closed credential read logs ``no profile secret scope on a+ multiplexed call`` on every tick (the skills-sync pulls resolved Nous credentials this way, four+ WARNINGs per hourly tick per chore). A single-profile gateway runs ``body`` once, unscoped:+ there the process env IS the profile's own value — unless a hosted room already flipped the+ process-wide guard (#112878), in which case the launch profile's OWN scope is bound, as+ ``run_turn.py::_standalone_launch_scope`` does for turns."""+ from gateway.run import _multiplex_profile_homes, _profile_runtime_scope+ config = getattr(runner, "config", None)+ if not getattr(config, "multiplex_profiles", False):+ from gateway.run_turn import GatewayTurnMixin+ with GatewayTurnMixin._standalone_launch_scope():+ body("default")+ return+ for profile_name, profile_home in _multiplex_profile_homes(config):+ with _profile_runtime_scope(Path(profile_home)):+ body(str(profile_name))+++def profile_scoped_chore(runner, chore):+ """Wrap a zero-arg housekeeping chore that reads the profile's home, config or credentials so it+ runs once per served profile under that profile's scope (see ``_for_each_served_profile``)."""+ return lambda: _for_each_served_profile(runner, lambda _label: chore())def migrate_profile_identity_verb(runner):