fix(gateway): clean up stale telegram stream previews after fresh fin… - #40162
Closed
Swarmplestill wants to merge 1 commit into
Closed
fix(gateway): clean up stale telegram stream previews after fresh fin…#40162Swarmplestill wants to merge 1 commit into
Swarmplestill wants to merge 1 commit into
Conversation
…al send When a Telegram streamed preview is visible but the final edit_message(finalize=True) hits long flood control (retry_after > 5s), the adapter returns SendResult(success=False). The stream consumer does not mark _final_response_sent / _final_content_delivered, so the gateway falls back to a normal final send, producing a near-duplicate message. Register a post_delivery_callback that deletes the stale preview bubble after the fresh final message lands. This ensures users see one canonical answer instead of preview + near-duplicate final. Test: FailingFinalizePreviewAdapter + StreamingFinalizeFailureAgent verify callback registration and stale preview deletion.
19 tasks
Contributor
|
Thanks for the focused reproduction and cleanup proposal. This is now implemented on
Automated hermes-sweeper review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes a visible UX bug where Telegram users receive two near-identical messages — a stale streamed preview bubble and a fresh final bubble — when the final
edit_message(finalize=True)hits long flood control (retry_after > 5s).Root cause: When Telegram's
edit_message(finalize=True)fails with flood control, the adapter returnsSendResult(success=False). The stream consumer does not mark_final_response_sent/_final_content_delivered, so the gateway falls back to a normal final send — producing a duplicate instead of replacing the preview.Fix: Register a
post_delivery_callbackthat deletes the stale preview bubble after the fresh final message lands. Uses existingregister_post_delivery_callbackandsafe_schedule_threadsafeAPIs — no new dependencies.Related Issue
No existing issue — bug discovered and reproduced in production.
Type of Change
Changes Made
gateway/run.py: Addedelifblock (~line 19246) that detects stale streamed previews (already_sent=Truebut no_streamed/_previewed/_content_deliveredconfirmation) and registers a post-delivery callback to delete the stale bubble after the fresh final message landstests/gateway/test_run_progress_topics.py: AddedFailingFinalizePreviewAdapter,StreamingFinalizeFailureAgent, andtest_run_agent_registers_cleanup_for_stale_stream_previewHow to Test
pytest tests/gateway/test_run_progress_topics.py -q— 29 passedpytest tests/gateway/test_stream_consumer.py tests/gateway/test_run_progress_topics.py -q— 121 passedscripts/check-windows-footguns.py gateway/run.py tests/gateway/test_run_progress_topics.py— no issuesChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/A