fix(zulip): account for TRUNCATION_NOTICE overhead in _truncate

The truncation notice '[...truncated at Zulip limit]' was appended AFTER
slicing at MAX_ZULIP_MESSAGE (10000), causing the final message to exceed
Zulip's API limit. This fix subtracts the notice length from the slice so
the total stays within bounds.

(cherry picked from commit 19c52a9425)
This commit is contained in:
Abiba (pi)
2026-09-25 15:25:54 +00:00
committed by Mumuni
parent 3db0d74620
commit 2c4136daf8
+2 -1
View File
@@ -67,6 +67,7 @@ DEFAULT_STREAM = "agent-hub"
DEFAULT_ALL_BOTS_USER_ID = 1
DEFAULT_POLL_INTERVAL = 3.0
MAX_ZULIP_MESSAGE = 10000
TRUNCATION_NOTICE = "\n\n[...truncated at Zulip limit]"
ECHO_TAG_PREFIX = "hermes-zulip-"
RECONNECT_BACKOFF = [2, 5, 10, 30, 60]
DEDUP_WINDOW = 300 # 5 minutes
@@ -120,7 +121,7 @@ def _truncate(text: str, limit: int = MAX_ZULIP_MESSAGE) -> str:
"""Truncate to Zulip's message limit with notice."""
if len(text) <= limit:
return text
return text[:limit] + "\n\n[...truncated at Zulip limit]"
return text[:limit - len(TRUNCATION_NOTICE)] + TRUNCATION_NOTICE
def _parse_zulip_timestamp(ts: Any) -> datetime: