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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user