hermes - 💡(How to fix) Fix Telegram message splitting can slice UTF-16 surrogate pairs, causing delivery failures [1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#11466Fetched 2026-04-18 06:00:54
View on GitHub
Comments
1
Participants
1
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
closed ×1commented ×1

Error Message

On Telegram, long messages that contain emojis outside the Basic Multilingual Plane (e.g. 🎩 ) can fail to deliver with the error: The underlying exception is:

Root Cause

In , uses to find an initial split point that respects UTF-16 boundaries when . However, it then tries to find a natural break point by scanning backwards for newlines or spaces:

This backward scan does not re-validate that the new still lands on a valid surrogate-pair boundary. As a result, the split can land in the middle of a 2-unit UTF-16 character, leaving an isolated surrogate like in the chunk. The Telegram Bot API rejects the message, and after retries the gateway gives up.

RAW_BUFFERClick to expand / collapse

Bug Description

On Telegram, long messages that contain emojis outside the Basic Multilingual Plane (e.g. 🎩 ) can fail to deliver with the error:

The underlying exception is:

Root Cause

In , uses to find an initial split point that respects UTF-16 boundaries when . However, it then tries to find a natural break point by scanning backwards for newlines or spaces:

This backward scan does not re-validate that the new still lands on a valid surrogate-pair boundary. As a result, the split can land in the middle of a 2-unit UTF-16 character, leaving an isolated surrogate like in the chunk. The Telegram Bot API rejects the message, and after retries the gateway gives up.

Impact

Any long response on Telegram that includes emoji such as 🎩, 😀, 🚀, etc. and exceeds (4096 UTF-16 code units) can trigger this failure.

Suggested Fix

After adjusting to a natural break point, clamp it back to the nearest safe boundary using (or equivalent logic) before taking the chunk slice.

Environment

  • Hermes Agent: latest main (commit at time of report)
  • Platform: Telegram
  • Model: any (observed with advisor responses, but not model-specific)

extent analysis

TL;DR

Adjust the message splitting logic to ensure that the split point respects UTF-16 boundaries, especially for emojis outside the Basic Multilingual Plane.

Guidance

  • Review the code that splits long messages to identify where the backward scan for natural break points is performed and adjust it to re-validate UTF-16 boundaries.
  • Consider using a library or function that handles Unicode characters and surrogate pairs correctly to find safe split points.
  • Test the adjusted logic with messages containing emojis like 🎩 to verify that the issue is resolved.
  • Ensure that the fix does not introduce any performance issues or affect the delivery of messages without emojis.

Example

No specific code example can be provided without the exact codebase, but the adjustment should involve using a function similar to String.prototype.codePointAt() or equivalent logic to clamp the split point to a valid UTF-16 boundary.

Notes

The fix might require additional handling for edge cases, such as messages that are exactly at the 4096 UTF-16 code unit limit or contain sequences of emojis that could still cause issues after the initial fix.

Recommendation

Apply the workaround by adjusting the message splitting logic to respect UTF-16 boundaries, as this directly addresses the root cause of the issue and should prevent message delivery failures on Telegram due to emojis.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - 💡(How to fix) Fix Telegram message splitting can slice UTF-16 surrogate pairs, causing delivery failures [1 comments, 1 participants]