Skip to content

fix(streaming): adaptive backoff + cursor strip to prevent message truncation#7683

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-38060157
Apr 11, 2026
Merged

fix(streaming): adaptive backoff + cursor strip to prevent message truncation#7683
teknium1 merged 1 commit into
mainfrom
hermes/hermes-38060157

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Fixes messages cutting/stopping mid-response on Telegram when streaming is enabled.

Root cause: The default edit_interval: 0.3s was too aggressive for Telegram's rate limits (~1 edit/s per message). When flood control triggered during streaming:

  1. Edits were permanently disabled after a single failure
  2. The cursor () was stuck in the last visible message
  3. The fallback continuation send could also hit flood control, losing the rest of the response
  4. already_sent=True prevented the base gateway from re-sending, so the truncated message was all the user saw

Changes (2 files, +117/-25):

gateway/stream_consumer.py

  • Adaptive backoff: On flood-control edit failures, double the edit interval (up to 10s cap) instead of immediately disabling edits. Only permanently disable after 3 consecutive failures (_MAX_FLOOD_STRIKES)
  • Cursor strip on fallback entry: Best-effort edit to remove the cursor from the last visible message when entering fallback mode
  • Fallback send retry: _send_fallback_final retries each chunk once on flood-control failures (3s delay)
  • _send_or_edit returns bool: The overflow split loop now checks the return value to avoid truncating accumulated text when an edit fails (was silently dropping content)
  • Default StreamConsumerConfig.edit_interval → 1.0s

gateway/config.py

  • Default StreamingConfig.edit_interval → 1.0s (both dataclass default and from_dict fallback)

Test plan

  • All 25 stream consumer tests pass
  • Full gateway test suite: 2473 passed (16 pre-existing failures in unrelated tests)
  • Existing test test_fallback_final_splits_long_continuation_without_dropping_text (the flood-control content-loss scenario) continues to pass

User impact

Users who have streaming.enabled: true in their gateway config should see significantly fewer truncated messages. Users with existing streaming.edit_interval: 0.3 in their config will keep their setting (the config default change only affects new installs or unset values).

…uncation

Telegram flood control during streaming caused messages to be cut off
mid-response. The old behavior permanently disabled edits after a single
flood-control failure, losing the remainder of the response.

Changes:
- Adaptive backoff: on flood-control edit failures, double the edit interval
  instead of immediately disabling edits. Only permanently disable after 3
  consecutive failures (_MAX_FLOOD_STRIKES).
- Cursor strip: when entering fallback mode, best-effort edit to remove the
  cursor (▉) from the last visible message so it doesn't appear stuck.
- Fallback send retry: _send_fallback_final retries each chunk once on
  flood-control failures (3s delay) before giving up.
- Default edit_interval increased from 0.3s to 1.0s. Telegram rate-limits
  edits at ~1/s per message; 0.3s was virtually guaranteed to trigger flood
  control on any non-trivial response.
- _send_or_edit returns bool so the overflow split loop knows not to
  truncate accumulated text when an edit fails (prevents content loss).

Fixes: messages cutting/stopping mid-response on Telegram, especially
with streaming enabled.
@teknium1 teknium1 merged commit d760729 into main Apr 11, 2026
3 of 4 checks passed
forsonny pushed a commit to forsonny/hermes-agent that referenced this pull request Apr 11, 2026
…trol backoff

Merge upstream/main (3 commits):
- fix(streaming): adaptive backoff + cursor strip to prevent message truncation (NousResearch#7683)
  Telegram flood control during streaming caused messages to be cut off.
  New: adaptive backoff (double interval on flood, cap at 10s), cursor strip
  on fallback entry, retry on fallback send, default edit_interval 1.0s.
- fix: unify openai-codex model list from codex_models.py (NousResearch#7844)
- fix(matrix): pass required args to MemoryCryptoStore for mautrix >=0.21 (NousResearch#7848)

Add 33 tests for the new streaming flood control behavior:
- TestIsFloodError (7): flood/retry/rate detection, false positives
- TestSendOrEditReturnValues (9): bool return values for all scenarios
- TestAdaptiveBackoffDirect (6): progressive backoff, strike tracking, reset
- TestTryStripCursor (4): cursor cleanup on fallback entry
- TestFallbackFinalRetry (1): retry on flood during fallback send
- TestDefaultEditInterval (3): config defaults
- TestFloodStrrikesState (3): initialization state

Self-improve: automated improvement
forsonny pushed a commit to forsonny/hermes-agent that referenced this pull request Apr 11, 2026
…i provider, community bug fixes)

- fix(vision): auto-resize oversized images + preserve aspect ratio
- feat: warn when compression model context is too small (NousResearch#7894)
- refactor(auxiliary): config.yaml priority over env vars (NousResearch#7889)
- fix: three high-impact community bugs (NousResearch#5819, NousResearch#6893, NousResearch#3388)
- fix(streaming): adaptive backoff + cursor strip (NousResearch#7683)
- fix(weixin): keep multi-line messages in single bubble
- fix(matrix): pass required args for mautrix >=0.21
- feat(xiaomi): add Xiaomi MiMo as first-class provider
- feat(migration): preview-then-confirm UX + docs
- fix: unify openai-codex model list
- docs: MiMo docs + compression context warning docs

Self-improve: automated improvement
Tommyeds pushed a commit to Tommyeds/hermes-agent that referenced this pull request Apr 12, 2026
…uncation (NousResearch#7683)

Telegram flood control during streaming caused messages to be cut off
mid-response. The old behavior permanently disabled edits after a single
flood-control failure, losing the remainder of the response.

Changes:
- Adaptive backoff: on flood-control edit failures, double the edit interval
  instead of immediately disabling edits. Only permanently disable after 3
  consecutive failures (_MAX_FLOOD_STRIKES).
- Cursor strip: when entering fallback mode, best-effort edit to remove the
  cursor (▉) from the last visible message so it doesn't appear stuck.
- Fallback send retry: _send_fallback_final retries each chunk once on
  flood-control failures (3s delay) before giving up.
- Default edit_interval increased from 0.3s to 1.0s. Telegram rate-limits
  edits at ~1/s per message; 0.3s was virtually guaranteed to trigger flood
  control on any non-trivial response.
- _send_or_edit returns bool so the overflow split loop knows not to
  truncate accumulated text when an edit fails (prevents content loss).

Fixes: messages cutting/stopping mid-response on Telegram, especially
with streaming enabled.
ulasbilgen pushed a commit to ulasbilgen/hermes-adhd-agent that referenced this pull request May 1, 2026
…uncation (NousResearch#7683)

Telegram flood control during streaming caused messages to be cut off
mid-response. The old behavior permanently disabled edits after a single
flood-control failure, losing the remainder of the response.

Changes:
- Adaptive backoff: on flood-control edit failures, double the edit interval
  instead of immediately disabling edits. Only permanently disable after 3
  consecutive failures (_MAX_FLOOD_STRIKES).
- Cursor strip: when entering fallback mode, best-effort edit to remove the
  cursor (▉) from the last visible message so it doesn't appear stuck.
- Fallback send retry: _send_fallback_final retries each chunk once on
  flood-control failures (3s delay) before giving up.
- Default edit_interval increased from 0.3s to 1.0s. Telegram rate-limits
  edits at ~1/s per message; 0.3s was virtually guaranteed to trigger flood
  control on any non-trivial response.
- _send_or_edit returns bool so the overflow split loop knows not to
  truncate accumulated text when an edit fails (prevents content loss).

Fixes: messages cutting/stopping mid-response on Telegram, especially
with streaming enabled.
aj-nt pushed a commit to aj-nt/hermes-agent that referenced this pull request May 1, 2026
…uncation (NousResearch#7683)

Telegram flood control during streaming caused messages to be cut off
mid-response. The old behavior permanently disabled edits after a single
flood-control failure, losing the remainder of the response.

Changes:
- Adaptive backoff: on flood-control edit failures, double the edit interval
  instead of immediately disabling edits. Only permanently disable after 3
  consecutive failures (_MAX_FLOOD_STRIKES).
- Cursor strip: when entering fallback mode, best-effort edit to remove the
  cursor (▉) from the last visible message so it doesn't appear stuck.
- Fallback send retry: _send_fallback_final retries each chunk once on
  flood-control failures (3s delay) before giving up.
- Default edit_interval increased from 0.3s to 1.0s. Telegram rate-limits
  edits at ~1/s per message; 0.3s was virtually guaranteed to trigger flood
  control on any non-trivial response.
- _send_or_edit returns bool so the overflow split loop knows not to
  truncate accumulated text when an edit fails (prevents content loss).

Fixes: messages cutting/stopping mid-response on Telegram, especially
with streaming enabled.
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…uncation (NousResearch#7683)

Telegram flood control during streaming caused messages to be cut off
mid-response. The old behavior permanently disabled edits after a single
flood-control failure, losing the remainder of the response.

Changes:
- Adaptive backoff: on flood-control edit failures, double the edit interval
  instead of immediately disabling edits. Only permanently disable after 3
  consecutive failures (_MAX_FLOOD_STRIKES).
- Cursor strip: when entering fallback mode, best-effort edit to remove the
  cursor (▉) from the last visible message so it doesn't appear stuck.
- Fallback send retry: _send_fallback_final retries each chunk once on
  flood-control failures (3s delay) before giving up.
- Default edit_interval increased from 0.3s to 1.0s. Telegram rate-limits
  edits at ~1/s per message; 0.3s was virtually guaranteed to trigger flood
  control on any non-trivial response.
- _send_or_edit returns bool so the overflow split loop knows not to
  truncate accumulated text when an edit fails (prevents content loss).

Fixes: messages cutting/stopping mid-response on Telegram, especially
with streaming enabled.
olympus-terminal pushed a commit to olympus-terminal/hermes-agent that referenced this pull request May 16, 2026
…uncation (NousResearch#7683)

Telegram flood control during streaming caused messages to be cut off
mid-response. The old behavior permanently disabled edits after a single
flood-control failure, losing the remainder of the response.

Changes:
- Adaptive backoff: on flood-control edit failures, double the edit interval
  instead of immediately disabling edits. Only permanently disable after 3
  consecutive failures (_MAX_FLOOD_STRIKES).
- Cursor strip: when entering fallback mode, best-effort edit to remove the
  cursor (▉) from the last visible message so it doesn't appear stuck.
- Fallback send retry: _send_fallback_final retries each chunk once on
  flood-control failures (3s delay) before giving up.
- Default edit_interval increased from 0.3s to 1.0s. Telegram rate-limits
  edits at ~1/s per message; 0.3s was virtually guaranteed to trigger flood
  control on any non-trivial response.
- _send_or_edit returns bool so the overflow split loop knows not to
  truncate accumulated text when an edit fails (prevents content loss).

Fixes: messages cutting/stopping mid-response on Telegram, especially
with streaming enabled.
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…uncation (NousResearch#7683)

Telegram flood control during streaming caused messages to be cut off
mid-response. The old behavior permanently disabled edits after a single
flood-control failure, losing the remainder of the response.

Changes:
- Adaptive backoff: on flood-control edit failures, double the edit interval
  instead of immediately disabling edits. Only permanently disable after 3
  consecutive failures (_MAX_FLOOD_STRIKES).
- Cursor strip: when entering fallback mode, best-effort edit to remove the
  cursor (▉) from the last visible message so it doesn't appear stuck.
- Fallback send retry: _send_fallback_final retries each chunk once on
  flood-control failures (3s delay) before giving up.
- Default edit_interval increased from 0.3s to 1.0s. Telegram rate-limits
  edits at ~1/s per message; 0.3s was virtually guaranteed to trigger flood
  control on any non-trivial response.
- _send_or_edit returns bool so the overflow split loop knows not to
  truncate accumulated text when an edit fails (prevents content loss).

Fixes: messages cutting/stopping mid-response on Telegram, especially
with streaming enabled.
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
…uncation (NousResearch#7683)

Telegram flood control during streaming caused messages to be cut off
mid-response. The old behavior permanently disabled edits after a single
flood-control failure, losing the remainder of the response.

Changes:
- Adaptive backoff: on flood-control edit failures, double the edit interval
  instead of immediately disabling edits. Only permanently disable after 3
  consecutive failures (_MAX_FLOOD_STRIKES).
- Cursor strip: when entering fallback mode, best-effort edit to remove the
  cursor (▉) from the last visible message so it doesn't appear stuck.
- Fallback send retry: _send_fallback_final retries each chunk once on
  flood-control failures (3s delay) before giving up.
- Default edit_interval increased from 0.3s to 1.0s. Telegram rate-limits
  edits at ~1/s per message; 0.3s was virtually guaranteed to trigger flood
  control on any non-trivial response.
- _send_or_edit returns bool so the overflow split loop knows not to
  truncate accumulated text when an edit fails (prevents content loss).

Fixes: messages cutting/stopping mid-response on Telegram, especially
with streaming enabled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant