From 19c52a9425aa66c891b1ff35408c732a43f1dbf6 Mon Sep 17 00:00:00 2001 From: "Abiba (pi)" Date: Wed, 8 Jul 2026 17:57:14 +0000 Subject: [PATCH] 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. --- plugins/platforms/zulip/adapter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/platforms/zulip/adapter.py b/plugins/platforms/zulip/adapter.py index 7e48173..d84685b 100644 --- a/plugins/platforms/zulip/adapter.py +++ b/plugins/platforms/zulip/adapter.py @@ -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 @@ -103,7 +104,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: