Files
hermes-webui/tests/test_webui_runtime_diagnostics.py
T
2b457f1646 Release: cap StreamChannel offline replay buffer (#5788) (#5849)
Bounded deque(maxlen) drop-oldest so a disconnect-without-cancel can't grow the
per-turn offline replay buffer unbounded (per-abandoned-turn OOM risk, #4633 family).
Dropped frames recovered via run-journal last_event_id replay path.

Deep-review gate: Codex SAFE (journal-recovery verified end-to-end), 20 own + 1106
regression tests green. Crown-jewel streaming path.

Co-authored-by: t <a@b>
Co-authored-by: ai-ag2026 <ai-ag2026@users.noreply.github.com>
2026-07-09 12:26:05 -07:00

53 lines
1.7 KiB
Python

from api.config import STREAMS, STREAMS_LOCK, create_stream_channel
from api.routes import _stream_runtime_diagnostics
def test_stream_channel_exposes_buffer_and_subscriber_counts():
channel = create_stream_channel()
channel.put_nowait(("token", {"text": "offline"}))
assert channel.diagnostic_snapshot() == {
"subscriber_count": 0,
"offline_buffered_events": 1,
"offline_dropped_events": 0,
}
subscriber = channel.subscribe()
try:
snapshot = channel.diagnostic_snapshot()
assert snapshot["subscriber_count"] == 1
assert snapshot["offline_buffered_events"] == 1
assert subscriber.get_nowait()[0] == "token"
finally:
channel.unsubscribe(subscriber)
def test_stream_runtime_diagnostics_summarizes_active_stream_channels():
channel = create_stream_channel()
channel.put_nowait(("token", {"text": "offline"}))
subscriber = channel.subscribe()
try:
with STREAMS_LOCK:
previous = dict(STREAMS)
STREAMS.clear()
STREAMS["stream-one"] = channel
try:
payload = _stream_runtime_diagnostics()
finally:
with STREAMS_LOCK:
STREAMS.clear()
STREAMS.update(previous)
assert payload["active_streams"] == 1
assert payload["total_subscribers"] == 1
assert payload["total_offline_buffered_events"] == 1
assert payload["streams"] == [
{
"stream_id": "stream-one",
"subscriber_count": 1,
"offline_buffered_events": 1,
}
]
finally:
channel.unsubscribe(subscriber)