Skip to content

fix: lower Telegram text fragment aggregation threshold from 4000 to 3600 chars#26264

Closed
Sid-Qin wants to merge 1 commit intoopenclaw:mainfrom
Sid-Qin:fix/telegram-fragment-threshold-too-high
Closed

fix: lower Telegram text fragment aggregation threshold from 4000 to 3600 chars#26264
Sid-Qin wants to merge 1 commit intoopenclaw:mainfrom
Sid-Qin:fix/telegram-fragment-threshold-too-high

Conversation

@Sid-Qin
Copy link
Contributor

@Sid-Qin Sid-Qin commented Feb 25, 2026

Summary

  • Problem: Telegram splits structured content (Markdown, heredoc, ### headings) earlier than the hard 4096-char limit. First fragments around ~3900 chars were not recognized as "near-limit" because the aggregation threshold was set at 4000 chars.
  • Why it matters: Users pasting long structured messages in Telegram saw each fragment processed as a separate message with separate replies, instead of being aggregated into one.
  • What changed: Lowered TELEGRAM_TEXT_FRAGMENT_START_THRESHOLD_CHARS from 4000 to 3600 in src/telegram/bot-handlers.ts.
  • What did NOT change: Fragment timing, max gap, max parts, or total chars limits remain the same. Only the initial detection threshold is lowered.

Change Type (select all)

  • Bug fix

Scope (select all touched areas)

  • Integrations

Linked Issue/PR

User-visible / Behavior Changes

Telegram long-message aggregation now triggers reliably for structured content that Telegram splits at ~3800-4000 chars, instead of only triggering when the first fragment exceeds 4000 chars.

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • Integration/channel: Telegram

Steps

  1. Send a long structured Markdown message (~4000+ chars) in Telegram
  2. Telegram splits it into 2+ fragments
  3. Observe that OpenClaw aggregates all fragments into one message

Expected

  • Single aggregated message processed by the agent

Actual (before fix)

  • Each fragment processed separately with separate replies

Evidence

  • Failing test/log before + passing after
  • New test "aggregates fragments when first part is ~3900 chars" added and passing

Human Verification (required)

  • Verified scenarios: New test with 3900-char first fragment confirms aggregation works
  • Edge cases checked: Existing tests with 4050-char fragments still pass (above new threshold)
  • What you did not verify: Live Telegram environment testing

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: Revert the single constant back to 4000
  • Files/config to restore: src/telegram/bot-handlers.ts
  • Known bad symptoms: Short independent messages (~3600-4000 chars) being incorrectly buffered

Risks and Mitigations

  • Risk: Independent short messages (3600-4000 chars) might be incorrectly buffered
    • Mitigation: Aggregation also requires sequential message IDs within the timing gap; standalone messages flush after the gap timer (1500ms default)

Greptile Summary

Lowered Telegram text fragment aggregation threshold from 4000 to 3600 chars to catch structured messages that Telegram splits earlier than the hard limit.

  • Modified TELEGRAM_TEXT_FRAGMENT_START_THRESHOLD_CHARS constant in src/telegram/bot-handlers.ts:100
  • Added test case covering 3900-char first fragment (previously below threshold)
  • Existing test with 4050-char fragment still passes (above new threshold)

Confidence Score: 5/5

  • Safe to merge - single constant change with comprehensive test coverage
  • Simple threshold adjustment (4000→3600) with clear rationale, no logic changes, and test coverage for both old and new threshold boundaries. Aggregation safety preserved via timing gap and message ID checks.
  • No files require special attention

Last reviewed commit: 0594daa

…3600 chars

Telegram splits structured messages (Markdown, heredoc) earlier than
the 4096-char limit.  With the previous 4000-char threshold, first
fragments around ~3900 chars were not recognized as near-limit and
subsequent parts were processed as separate messages.

Lowering to 3600 ensures aggregation starts reliably for all content
types that Telegram may split.

Closes openclaw#26237

Co-authored-by: Cursor <cursoragent@cursor.com>
thebtf pushed a commit to thebtf/openclaw that referenced this pull request Feb 25, 2026
openclaw#25988

- openclaw#26229: replace Agent with EnvHttpProxyAgent in global undici dispatcher
  so HTTP_PROXY/HTTPS_PROXY env vars are respected for all outbound fetch
  calls (regression fix from openclaw#25682 that overwrote proxy-aware dispatcher)

- openclaw#26264: lower text fragment aggregation threshold 4000→3600 chars to
  reliably catch structured content that Telegram splits at ~3800 chars

- openclaw#25988: fail closed group allowlist against DM pairing store — group
  sender checks now use only explicit groupAllowFrom config, not the DM
  pairing store (security: DM-paired senders cannot bypass group allowlist)
@openclaw-barnacle
Copy link

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle bot added the stale Marked as stale due to inactivity label Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram size: XS stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Telegram inbound long-message aggregation fails when first fragment is below near-limit threshold (~4000 chars)

2 participants