The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): park invalid hot-profile configs
Brian Fernstromf18fab4e9225
diff --git a/gateway/run_profile_reconcile.py b/gateway/run_profile_reconcile.pyindex 52df18d051e..bcdedf44321 100644--- a/gateway/run_profile_reconcile.py+++ b/gateway/run_profile_reconcile.py@@ -169,6 +169,7 @@ class GatewayProfileReconcileMixin:current[name] = live[name]claimed = self._live_resource_claims(active)transient_failed = set()+ config_parked = set()for name in added + changed:# Only acknowledge the configuration observed before connecting;# a setup save during an awaited handshake needs another scan.@@ -176,10 +177,16 @@ class GatewayProfileReconcileMixin:try:connected = await self._start_one_profile_adapters(name, current[name], claimed)except MultiplexConfigError as exc:- # Boot refuses to run with such a profile; at runtime we park just this profile.+ # Runtime config refusal is a real park, not an adapter-less served profile:+ # withdraw the authority/tickets, release the reservation and publish the+ # terminal parked verdict. A control-socket rescan can explicitly retry it.logger.error("[MULTIPLEX] Profile '%s' not served: %s", name, exc)- connected = 0- sigs[name] = scan_signature+ home = current.pop(name)+ await self._unserve_profile(name, home)+ park_profile(self, name, str(exc))+ result["parked"].append(name)+ config_parked.add(name)+ continueexcept Exception:logger.error("[MULTIPLEX] Failed to start adapters for profile '%s'", name, exc_info=True)connected = 0@@ -194,6 +201,8 @@ class GatewayProfileReconcileMixin:else:logger.info("[MULTIPLEX] Re-scanned profile '%s' after config/.env change (%s adapter(s) connected)", name, connected)result["rescanned"].append(name)+ if config_parked:+ added = [name for name in added if name not in config_parked]self._served_profile_signatures = sigs# A profile deleted while an adapter above was still connecting must not be recorded back# (the deleter's signal timed out against this lock and rmtree already ran).diff --git a/tests/gateway/test_multiplex_hot_serve.py b/tests/gateway/test_multiplex_hot_serve.pyindex aa3a05826b3..bc265ba6a44 100644--- a/tests/gateway/test_multiplex_hot_serve.py+++ b/tests/gateway/test_multiplex_hot_serve.py@@ -329,7 +329,7 @@ async def test_transient_start_failure_is_retried_on_next_reconcile(tmp_path, mo# The deliberate park stays distinct: a MultiplexConfigError is acknowledged, not retried.from gateway.run import MultiplexConfigError- delta_dir = _mkprofile(home, "delta", "DISCORD_BOT_TOKEN=delta-token\n")+ _mkprofile(home, "delta", "DISCORD_BOT_TOKEN=delta-token\n")parked = []async def park(name, profile_home, claimed):@@ -337,10 +337,24 @@ async def test_transient_start_failure_is_retried_on_next_reconcile(tmp_path, moraise MultiplexConfigError("open dm_policy")runner._start_one_profile_adapters = park- await runner.reconcile_served_profiles()- await runner.reconcile_served_profiles()+ first_park = await runner.reconcile_served_profiles()+ second_park = await runner.reconcile_served_profiles()assert parked == ["delta"]- assert runner._served_profile_signatures["delta"] == profile_serve_signature(delta_dir)+ assert first_park["parked"] == ["delta"]+ assert "delta" not in first_park["served_profiles"]+ assert second_park["parked"] == []+ assert "delta" not in runner._served_profile_signatures+ assert "delta" in runner.session_runtime_descriptor["parked_profiles"]++ # A previously served profile that becomes invalid is withdrawn through+ # the same ownership path rather than left routable without adapters.+ (home / "profiles" / "alpha" / "config.yaml").write_text(+ "model: {default: changed}\n", encoding="utf-8"+ )+ changed_park = await runner.reconcile_served_profiles()+ assert changed_park["parked"] == ["alpha"]+ assert "alpha" not in changed_park["served_profiles"]+ assert "alpha" in runner.session_runtime_descriptor["parked_profiles"]@pytest.mark.asynciodiff --git a/tests/gateway/test_multiplex_hot_serve_live.py b/tests/gateway/test_multiplex_hot_serve_live.pyindex de901fee755..e70c65aae24 100644--- a/tests/gateway/test_multiplex_hot_serve_live.py+++ b/tests/gateway/test_multiplex_hot_serve_live.py@@ -261,3 +261,40 @@ def test_broken_secondary_state_db_parks_only_that_profile(mux):stop(proc)finally:stop(proc, expect=None)+++def test_invalid_hot_profile_config_is_parked_and_unserved(mux):+ """A runtime MultiplexConfigError withdraws both new and previously served secondaries.++ This exercises the real gateway runtime: authority/ticket publication happens before adapter+ config validation, so the regression left an invalid profile routable even though its adapters+ never started.+ """+ root = mux['root']+ proc, desc = start_daemon(mux)+ try:+ invalid = json.loads(json.dumps(mux['config']))+ invalid['whatsapp'] = {'enabled': True, 'dm_policy': 'open'}++ added = root / 'profiles' / 'invalid-hot'+ added.mkdir(parents=True, mode=0o700)+ (added / 'config.yaml').write_text(json.dumps(invalid), encoding='utf-8')+ result = control(root, 'rescan-profiles')+ desc = control(root, 'identify')+ assert result['parked'] == ['invalid-hot'], (result, tail(mux))+ assert added.resolve() not in served_homes(desc), desc+ assert 'invalid-hot' in desc.get('parked_profiles', {}), desc+ assert 'invalid-hot' not in recorded_served(root)++ # The same contract applies to a secondary that was already published and then edited+ # into an invalid configuration.+ assert mux['boot'].resolve() in served_homes(desc)+ (mux['boot'] / 'config.yaml').write_text(json.dumps(invalid), encoding='utf-8')+ result = control(root, 'rescan-profiles')+ desc = control(root, 'identify')+ assert result['parked'] == ['boot'], (result, tail(mux))+ assert mux['boot'].resolve() not in served_homes(desc), desc+ assert 'boot' in desc.get('parked_profiles', {}), desc+ assert 'boot' not in recorded_served(root)+ finally:+ stop(proc, expect=None)