fix: re-derive the live busy text mode after a non-profile /busy change

Review finding (quality pass): on a single-profile gateway,
_handle_busy_command set _busy_input_mode but left _busy_text_mode
stale, so the adapter refresh a line later re-read the old value —
/busy queue persisted to config but live text messages kept
interrupting until restart. The profile path already re-derives both
from the fresh config; the non-profile path now does the same via
_load_busy_text_mode() (busy_input_mode is the source of truth,
run.py:9877). Regression assertion added to test_set_mode_persists;
verified red without the production fix.
This commit is contained in:
kshitijk4poor
2026-08-29 19:51:42 +05:30
committed by kshitij
parent 740994a903
commit 0d02f0d1dc
2 changed files with 21 additions and 0 deletions

View File

@@ -4287,6 +4287,12 @@ class GatewaySlashCommandsMixin:
)
else:
self._busy_input_mode = arg
# busy_input_mode is the source of truth for the text mode
# too (run.py:_load_busy_text_mode) — re-derive it so the
# adapter refresh below doesn't read a stale value and keep
# interrupting after e.g. /busy queue (config IS saved; only
# the live session lagged until restart).
self._busy_text_mode = self._load_busy_text_mode()
adapter = self._adapter_for_source(event.source)
if adapter is not None:

View File

@@ -68,11 +68,26 @@ class TestBusyCommandPersistence:
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)
runner._busy_text_mode = "interrupt"
monkeypatch.setattr("cli.save_config_value", lambda k, v: True)
# The handler re-derives _busy_text_mode from the saved config;
# emulate the write that the mocked save_config_value skipped.
monkeypatch.setattr(
gateway_run,
"_load_gateway_runtime_config",
lambda: {"display": {"busy_input_mode": new_mode}},
)
monkeypatch.delenv("HERMES_GATEWAY_BUSY_TEXT_MODE", raising=False)
monkeypatch.delenv("HERMES_GATEWAY_BUSY_INPUT_MODE", raising=False)
event = _make_event(f"/busy {new_mode}")
result = await runner._handle_busy_command(event)
assert new_mode in str(result).lower()
assert runner._busy_input_mode == new_mode
# busy_input_mode is the source of truth for the text mode: /busy
# queue must stop live text messages from interrupting (#97932).
assert runner._busy_text_mode == (
"queue" if new_mode == "queue" else "interrupt"
)
@pytest.mark.asyncio
async def test_save_failure_preserves_mode(self, monkeypatch):