Skip to content

The agent that grows with you

fix(gateway): apply busy mode per profile

Samuel Odio8d1d193f1151
diff --git a/gateway/run.py b/gateway/run.py
index 85ad9266dbe..93bf4160d9a 100644
--- a/gateway/run.py
+++ b/gateway/run.py
@@ -17206,6 +17206,7 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew
"kanban": self._handle_kanban_command,
"subgoal": self._handle_subgoal_command,
"heartbeat": self._handle_heartbeat_command,
+ "busy": self._handle_busy_command,
"yolo": self._handle_yolo_command,
"verbose": self._handle_verbose_command,
"footer": self._handle_footer_command,
diff --git a/gateway/slash_commands.py b/gateway/slash_commands.py
index 71d42e9c131..f1cdaea2ca9 100644
--- a/gateway/slash_commands.py
+++ b/gateway/slash_commands.py
@@ -4256,7 +4256,7 @@ class GatewaySlashCommandsMixin:
"""
arg = event.get_command_args().strip().lower()
if not arg or arg == "status":
- mode = self._busy_input_mode
+ mode = self._effective_busy_input_mode(event.source)
if mode == "queue":
behavior = "queues for next turn"
elif mode == "steer":
@@ -4275,28 +4275,36 @@ class GatewaySlashCommandsMixin:
)
# Persist before mutate
- try:
- from cli import save_config_value
- if save_config_value("display.busy_input_mode", arg):
- self._busy_input_mode = arg
- if arg == "queue":
- behavior = "Messages will be queued for the next turn while Hermes is busy."
- elif arg == "steer":
- behavior = "Messages will be steered into the current run (after the next tool call)."
- else:
- behavior = "Messages will interrupt the current run while Hermes is busy."
- return EphemeralReply(
- f"Busy input mode set to **`{arg}`** (saved)." + "\n"
- f"_{behavior}_"
+ from cli import save_config_value
+ if save_config_value("display.busy_input_mode", arg):
+ profile_name = self._busy_profile_name_for_source(event.source)
+ if profile_name:
+ from gateway.run import _load_gateway_runtime_config
+
+ self._snapshot_profile_busy_modes(
+ profile_name,
+ _load_gateway_runtime_config(),
)
else:
- return EphemeralReply(
- f"Busy input mode could not be saved to config. Mode unchanged."
- )
- except Exception as e:
- logger.warning("Failed to save busy_input_mode: %s", e)
+ self._busy_input_mode = arg
+
+ adapter = self._adapter_for_source(event.source)
+ if adapter is not None:
+ adapter._busy_text_mode = self._effective_busy_text_mode(event.source)
+
+ if arg == "queue":
+ behavior = "Messages will be queued for the next turn while Hermes is busy."
+ elif arg == "steer":
+ behavior = "Messages will be steered into the current run (after the next tool call)."
+ else:
+ behavior = "Messages will interrupt the current run while Hermes is busy."
+ return EphemeralReply(
+ f"Busy input mode set to **`{arg}`** (saved)." + "\n"
+ f"_{behavior}_"
+ )
+ else:
return EphemeralReply(
- f"Could not save busy input mode: {e}. Mode unchanged."
+ f"Busy input mode could not be saved to config. Mode unchanged."
)
async def _handle_footer_command(self, event: MessageEvent) -> str:
diff --git a/tests/gateway/test_busy_command.py b/tests/gateway/test_busy_command.py
index 42c03b93e4a..7236541dcc5 100644
--- a/tests/gateway/test_busy_command.py
+++ b/tests/gateway/test_busy_command.py
@@ -32,20 +32,18 @@ class TestBusyCommand:
"""Test /busy command dispatch without config persistence."""
@pytest.mark.asyncio
- async def test_status_returns_current_mode(self):
- """/busy status shows the current busy mode."""
- runner = _make_runner(busy_mode="queue")
- event = _make_event("/busy status")
- result = await runner._handle_busy_command(event)
- assert "queue" in str(result).lower()
-
- @pytest.mark.asyncio
- async def test_bare_busy_shows_status(self):
- """/busy without arguments shows status."""
- runner = _make_runner(busy_mode="steer")
- event = _make_event("/busy")
+ @pytest.mark.parametrize(
+ ("command", "busy_mode"),
+ [("/busy status", "queue"), ("/busy", "steer")],
+ )
+ async def test_status_returns_current_mode(self, command, busy_mode):
+ """Bare /busy and /busy status show the current busy mode."""
+ runner = _make_runner(busy_mode=busy_mode)
+ event = _make_event(command)
result = await runner._handle_busy_command(event)
- assert "steer" in str(result).lower()
+ reply_text = str(result).lower()
+ assert busy_mode in reply_text
+ assert "busy" in reply_text
@pytest.mark.asyncio
async def test_busy_invalid_arg(self):
@@ -55,55 +53,26 @@ class TestBusyCommand:
result = await runner._handle_busy_command(event)
assert "unknown" in str(result).lower()
- @pytest.mark.asyncio
- async def test_busy_toggle_messages(self):
- """Status response includes the mode and behavior."""
- runner = _make_runner(busy_mode="queue")
- event = _make_event("/busy status")
- result = await runner._handle_busy_command(event)
- reply_text = str(result)
- assert "queue" in reply_text.lower()
- assert "busy" in reply_text.lower()
-
-
class TestBusyCommandPersistence:
"""Test /busy persistence with mocked save_config_value."""
@pytest.mark.asyncio
- async def test_set_queue_persists(self, monkeypatch):
- """/busy queue saves config and updates mode."""
- runner = _make_runner(busy_mode="interrupt")
- monkeypatch.setattr(
- "cli.save_config_value", lambda k, v: True
- )
- event = _make_event("/busy queue")
- result = await runner._handle_busy_command(event)
- assert "queue" in str(result).lower()
- assert runner._busy_input_mode == "queue"
-
- @pytest.mark.asyncio
- async def test_set_steer_persists(self, monkeypatch):
- """/busy steer saves config and updates mode."""
- runner = _make_runner(busy_mode="queue")
- monkeypatch.setattr(
- "cli.save_config_value", lambda k, v: True
- )
- event = _make_event("/busy steer")
- result = await runner._handle_busy_command(event)
- assert "steer" in str(result).lower()
- assert runner._busy_input_mode == "steer"
-
- @pytest.mark.asyncio
- async def test_set_interrupt_persists(self, monkeypatch):
- """/busy interrupt saves config and updates mode."""
- runner = _make_runner(busy_mode="queue")
- monkeypatch.setattr(
- "cli.save_config_value", lambda k, v: True
- )
- event = _make_event("/busy interrupt")
+ @pytest.mark.parametrize(
+ ("initial_mode", "new_mode"),
+ [
+ ("interrupt", "queue"),
+ ("queue", "steer"),
+ ("queue", "interrupt"),
+ ],
+ )
+ async def test_set_mode_persists(self, monkeypatch, initial_mode, new_mode):
+ """Each supported /busy mode is saved and applied."""
+ runner = _make_runner(busy_mode=initial_mode)
+ monkeypatch.setattr("cli.save_config_value", lambda k, v: True)
+ event = _make_event(f"/busy {new_mode}")
result = await runner._handle_busy_command(event)
- assert "interrupt" in str(result).lower()
- assert runner._busy_input_mode == "interrupt"
+ assert new_mode in str(result).lower()
+ assert runner._busy_input_mode == new_mode
@pytest.mark.asyncio
async def test_save_failure_preserves_mode(self, monkeypatch):
@@ -116,19 +85,3 @@ class TestBusyCommandPersistence:
result = await runner._handle_busy_command(event)
assert "unchanged" in str(result).lower()
assert runner._busy_input_mode == "steer"
-
- @pytest.mark.asyncio
- async def test_save_exception_preserves_mode(self, monkeypatch):
- """When save_config_value raises, mode is unchanged."""
- runner = _make_runner(busy_mode="interrupt")
-
- def _raise(*args, **kwargs):
- raise RuntimeError("disk full")
-
- monkeypatch.setattr(
- "cli.save_config_value", _raise
- )
- event = _make_event("/busy steer")
- result = await runner._handle_busy_command(event)
- assert "Could not save" in str(result)
- assert runner._busy_input_mode == "interrupt"
diff --git a/tests/gateway/test_multiplex_busy_input_mode.py b/tests/gateway/test_multiplex_busy_input_mode.py
index 5e3d8af1bd9..779d5730154 100644
--- a/tests/gateway/test_multiplex_busy_input_mode.py
+++ b/tests/gateway/test_multiplex_busy_input_mode.py
@@ -6,6 +6,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
import pytest
+import gateway.run as gateway_run
from gateway.config import GatewayConfig, Platform, PlatformConfig
from gateway.platforms.base import (
BasePlatformAdapter,
@@ -178,6 +179,47 @@ async def test_secondary_profile_busy_mode_controls_priority_path(
assert session_key not in adapter._pending_messages
+async def test_busy_status_dispatches_through_active_session_path(tmp_path):
+ """A running session still dispatches /busy through its normal handler."""
+ runner = _runner(default_mode="interrupt")
+ await _load_profile_snapshot(runner, tmp_path / "research", "queue")
+ event = _event(profile="research")
+ event.text = "/busy status"
+ session_key = runner._session_key_for_source(event.source)
+ runner._running_agents[session_key] = MagicMock()
+
+ response = await runner._handle_message(event)
+
+ assert "queue" in str(response).lower()
+
+
+async def test_busy_change_updates_only_routed_profile(tmp_path, monkeypatch):
+ """A profile-scoped /busy change refreshes its snapshot and adapter."""
+ runner = _runner(default_mode="interrupt")
+ adapter = await _load_profile_snapshot(
+ runner,
+ tmp_path / "research",
+ "queue",
+ )
+ event = _event(profile="research")
+ event.text = "/busy steer"
+ monkeypatch.setattr("cli.save_config_value", lambda _key, _value: True)
+ monkeypatch.setattr(
+ gateway_run,
+ "_load_gateway_runtime_config",
+ lambda: {"display": {"busy_input_mode": "steer"}},
+ )
+
+ response = await runner._handle_busy_command(event)
+
+ assert "steer" in str(response).lower()
+ assert runner._busy_input_mode == "interrupt"
+ assert runner._effective_busy_input_mode(event.source) == "steer"
+ assert adapter._busy_text_mode == "interrupt"
+
+
@pytest.mark.asyncio
@pytest.mark.parametrize(
("default_mode", "secondary_mode", "queued"),