From 48a4201f40c475f54461600fe1f6946ccd462b42 Mon Sep 17 00:00:00 2001 From: Stephen Chin <1290231+steveonjava@users.noreply.github.com> Date: Wed, 26 Aug 2026 03:39:58 -0700 Subject: [PATCH] fix(compaction): preserve switch compatibility fixtures Keep model-switch callers compatible with result objects created before runtime_capabilities was added, and do not roll back minimal agents that lack optional LM Studio helpers. Preserve rollback for real helper failures. --- agent/agent_runtime_helpers.py | 33 +++++++++++++++++++++------------ cli.py | 8 +++++--- gateway/slash_commands.py | 6 ++++-- tui_gateway/server.py | 2 +- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/agent/agent_runtime_helpers.py b/agent/agent_runtime_helpers.py index 6a2e0f2b8d..c5eb9b34fc 100644 --- a/agent/agent_runtime_helpers.py +++ b/agent/agent_runtime_helpers.py @@ -3227,23 +3227,32 @@ def switch_model( except Exception: _destination_context_intent = None agent._config_context_length = _destination_context_intent - try: - _runtime_context_length = agent._ensure_lmstudio_runtime_loaded( - _destination_context_intent - ) - except Exception: - _restore_snapshot() - raise - if agent._lmstudio_load_was_unverified(_runtime_context_length): + if hasattr(agent, "_ensure_lmstudio_runtime_loaded"): + try: + _runtime_context_length = agent._ensure_lmstudio_runtime_loaded( + _destination_context_intent + ) + except Exception: + _restore_snapshot() + raise + else: + _runtime_context_length = None + if ( + hasattr(agent, "_lmstudio_load_was_unverified") + and agent._lmstudio_load_was_unverified(_runtime_context_length) + ): logger.warning( "LM Studio model activation was rejected or completed without a " "verifiable active context length during model switch; continuing " "with configured context" ) - _effective_context_length = agent._effective_lmstudio_context_length( - _destination_context_intent, - _runtime_context_length, - ) + if hasattr(agent, "_effective_lmstudio_context_length"): + _effective_context_length = agent._effective_lmstudio_context_length( + _destination_context_intent, + _runtime_context_length, + ) + else: + _effective_context_length = _destination_context_intent # ── Re-evaluate prompt caching ── # Refresh the custom-provider snapshot from the config just loaded above diff --git a/cli.py b/cli.py index f92fd5d4cb..256e3b23e0 100644 --- a/cli.py +++ b/cli.py @@ -10306,7 +10306,9 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin, CLIBillingMixin): api_key=_reset_result.api_key, base_url=_reset_result.base_url, api_mode=_reset_result.api_mode, - capabilities=_reset_result.runtime_capabilities, + capabilities=getattr( + _reset_result, "runtime_capabilities", None + ), ) self.model = _reset_result.new_model self.provider = _reset_result.target_provider @@ -11626,7 +11628,7 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin, CLIBillingMixin): api_key=result.api_key, base_url=result.base_url, api_mode=result.api_mode, - capabilities=result.runtime_capabilities, + capabilities=getattr(result, "runtime_capabilities", None), ) except Exception as exc: # The agent rolled itself back to the old working model/client. @@ -12017,7 +12019,7 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin, CLIBillingMixin): api_key=result.api_key, base_url=result.base_url, api_mode=result.api_mode, - capabilities=result.runtime_capabilities, + capabilities=getattr(result, "runtime_capabilities", None), ) except Exception as exc: # Agent rolled itself back; roll the CLI back too and abort so a diff --git a/gateway/slash_commands.py b/gateway/slash_commands.py index b8ce7cc616..627ff37f0e 100644 --- a/gateway/slash_commands.py +++ b/gateway/slash_commands.py @@ -1950,7 +1950,9 @@ class GatewaySlashCommandsMixin: api_key=result.api_key, base_url=result.base_url, api_mode=result.api_mode, - capabilities=result.runtime_capabilities, + capabilities=getattr( + result, "runtime_capabilities", None + ), ) except Exception as exc: # The in-place swap rolled the agent back to the @@ -2265,7 +2267,7 @@ class GatewaySlashCommandsMixin: api_key=result.api_key, base_url=result.base_url, api_mode=result.api_mode, - capabilities=result.runtime_capabilities, + capabilities=getattr(result, "runtime_capabilities", None), ) except Exception as exc: # In-place swap rolled the agent back to the OLD working diff --git a/tui_gateway/server.py b/tui_gateway/server.py index e4b70649ea..8fc646a377 100644 --- a/tui_gateway/server.py +++ b/tui_gateway/server.py @@ -6348,7 +6348,7 @@ def _apply_model_switch( api_key=result.api_key, base_url=result.base_url, api_mode=result.api_mode, - capabilities=result.runtime_capabilities, + capabilities=getattr(result, "runtime_capabilities", None), ) except Exception as exc: # The in-place swap rolled the agent back to the old working