Skip to content

fix(gateway): fallback immediately on Telegram finalized edit flood control - #55869

Open
johnwalke wants to merge 1 commit into
NousResearch:mainfrom
johnwalke:fix/telegram-overflow-flood-duplicate
Open

fix(gateway): fallback immediately on Telegram finalized edit flood control#55869
johnwalke wants to merge 1 commit into
NousResearch:mainfrom
johnwalke:fix/telegram-overflow-flood-duplicate

Conversation

@johnwalke

Copy link
Copy Markdown

Summary

  • Enter Telegram streaming fallback immediately when any finalized edit hits flood control, including overflow split first-chunk edits (finalize=True, is_turn_final=False).
  • Preserve the already-visible prefix and send only the missing tail on final fallback, avoiding repeated full-response delivery.
  • Adds regression coverage for the overflow split + RetryAfter path and updates the final cleanup edit expectation to match delivered-content state.

Test plan

  • PYTHONPATH=. python3 -m pytest tests/gateway/test_telegram_overflow_partial.py tests/gateway/test_stream_consumer_fresh_final.py -q -o addopts=

Notes

This targets a Telegram duplicate-delivery bug where flood-controlled finalized edits previously went through the generic retry loop before fallback. Retrying finalized edits wastes Telegram flood budget and delays the tail message; fallback is already the safer path once visible content exists.

…st-chunk edit

When overflow split first-chunk edit hits flood control (RetryAfter),
the old code only handled finalize=True + is_turn_final=True, missing
the overflow-split path (finalize=True, is_turn_final=False).

Change the guard from 'finalize and is_turn_final' to 'finalize' so ANY
finalize-d edit that hits flood immediately enters fallback mode instead
of wasting 3 flood-strike retries. Fallback preserves the visible prefix
and sends only the missing tail on got_done.

Fixes:
- No full final duplicate (only tail sent)
- State flags (final_content_delivered / already_sent) consistent
- Flood control does not cause duplicate spam
- Immediate fallback on first flood strike (no 3-strike delay)

New regression test: test_flood_on_overflow_split_first_chunk_enters_fallback_immediately
Updated existing test: test_failed_final_cleanup_edit_marks_visible_content_delivered

All 157 stream-consumer tests GREEN.
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter P2 Medium — degraded but workaround exists sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Jun 30, 2026

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for isolating the overflow-first-chunk flood path. The premise remains on current main: the split loop calls _send_or_edit(..., finalize=True, is_turn_final=False) in gateway/stream_consumer.py:727-730, while immediate fallback still requires is_turn_final in gateway/stream_consumer.py:1871-1879.

Problems

  • gateway/stream_consumer.py:1595 changes the policy for every adapter: if finalize: bypasses the existing Telegram opt-in capability gate. Current main scopes immediate final fallback through FALLBACK_ON_FINAL_EDIT_FLOOD; preserve that boundary while covering the overflow case.
  • tests/gateway/test_telegram_overflow_partial.py:157-214 uses a generic mock and calls the consumer directly. It does not run the real Telegram oversized-final route in plugins/platforms/telegram/adapter.py:3980-3984 / _edit_overflow_split, so it cannot validate the prefix retained after a first-chunk failure.

Suggested changes

  • Make overflow immediate fallback adapter-capability-gated rather than unconditional.
  • Add a real TelegramAdapter overflow/RetryAfter regression and a non-opt-in adapter control.

Automated hermes-sweeper review.

self._MAX_FLOOD_STRIKES,
self._current_edit_interval,
)
if finalize:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finalize is also used by non-Telegram adapters and interim segment finalization. Please retain an explicit adapter capability gate when extending immediate fallback to the overflow-first-chunk case; current main scopes this behavior through FALLBACK_ON_FINAL_EDIT_FLOOD.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants