From 63d024dc45156d1ab0067a135dab776ce5dd6328 Mon Sep 17 00:00:00 2001 From: carlotestor Date: Fri, 18 Sep 2026 11:40:51 +0000 Subject: [PATCH] feat(sidebar): make the visible-session window size configurable CLI_VISIBLE_SESSION_LIMIT is hardcoded to 20. That constant also bounds how many delegated subagent children can render at once, since a child only nests when its parent row is in the same payload, so operators running wide delegate_task fan-outs cannot see all children without editing the source. Read it from HERMES_WEBUI_VISIBLE_SESSION_LIMIT via the existing _env_int helper, keeping 20 as the default. --- api/models.py | 6 ++++- tests/test_visible_session_limit_env.py | 35 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 tests/test_visible_session_limit_env.py diff --git a/api/models.py b/api/models.py index 84a91b9c..99226cb4 100644 --- a/api/models.py +++ b/api/models.py @@ -48,7 +48,11 @@ from api.agent_sessions import ( from api.process_event_utils import stamp_message_source logger = logging.getLogger(__name__) -CLI_VISIBLE_SESSION_LIMIT = 20 +# Size of the interactive sidebar recency window. Also bounds how many +# delegated subagent children can be rendered at once, since a child only +# nests when it wins a slot in this window. Override with +# HERMES_WEBUI_VISIBLE_SESSION_LIMIT. +CLI_VISIBLE_SESSION_LIMIT = _cfg._env_int("HERMES_WEBUI_VISIBLE_SESSION_LIMIT", 20) # How many messageful cron sessions to surface in the project-chip layer. # Needs to exceed CLI_VISIBLE_SESSION_LIMIT so older cron runs stay # addressable even when many newer non-cron sessions dominate the default diff --git a/tests/test_visible_session_limit_env.py b/tests/test_visible_session_limit_env.py new file mode 100644 index 00000000..178465f5 --- /dev/null +++ b/tests/test_visible_session_limit_env.py @@ -0,0 +1,35 @@ +"""CLI_VISIBLE_SESSION_LIMIT is overridable via HERMES_WEBUI_VISIBLE_SESSION_LIMIT. + +The sidebar recency window also bounds how many delegated subagent children can +render at once, since a child only nests when its row wins a slot in the same +payload. Operators running wide fan-outs need to raise it without editing code. +""" + +import importlib + + +def _reload_limit(monkeypatch, value): + if value is None: + monkeypatch.delenv("HERMES_WEBUI_VISIBLE_SESSION_LIMIT", raising=False) + else: + monkeypatch.setenv("HERMES_WEBUI_VISIBLE_SESSION_LIMIT", value) + import api.models as models + + return importlib.reload(models).CLI_VISIBLE_SESSION_LIMIT + + +def test_defaults_to_20_when_unset(monkeypatch): + assert _reload_limit(monkeypatch, None) == 20 + + +def test_env_override_raises_the_window(monkeypatch): + assert _reload_limit(monkeypatch, "64") == 64 + + +def test_invalid_value_falls_back_to_default(monkeypatch): + assert _reload_limit(monkeypatch, "bogus") == 20 + + +def test_zero_and_negative_fall_back_to_default(monkeypatch): + assert _reload_limit(monkeypatch, "0") == 20 + assert _reload_limit(monkeypatch, "-5") == 20