fix(gateway): merge Telegram startup media into text turns - #33272
Conversation
d65ec65 to
ed296ee
Compare
|
Follow-up after the first CI run: I updated the branch to resolve adapter extension methods via Additional local verification after the update: /usr/local/lib/hermes-agent/venv/bin/python -m pytest -q -o addopts='' tests/gateway/test_status_command.py
# 14 passed in 1.29s
/usr/local/lib/hermes-agent/venv/bin/python -m pytest -q -o addopts='' tests/gateway/test_status_command.py::test_handle_message_persists_agent_token_counts tests/gateway/test_status_command.py::test_first_run_non_slack_home_channel_onboarding_keeps_direct_command tests/gateway/test_status_command.py::test_handle_message_discards_stale_result_after_session_invalidation
# 3 passed in 1.58s
/usr/local/lib/hermes-agent/venv/bin/python -m pytest -q -o addopts='' tests/gateway/test_telegram_text_photo_startup_merge.py tests/gateway/test_telegram_photo_interrupts.py tests/gateway/test_telegram_text_batching.py tests/gateway/test_telegram_text_batch_perf.py tests/gateway/test_native_image_buffer_isolation.py
# 23 passed, 1 warning in 2.87s
/usr/local/lib/hermes-agent/venv/bin/python -m pytest -q -o addopts='' tests/gateway/test_telegram_documents.py tests/gateway/test_telegram_max_doc_bytes.py tests/gateway/test_telegram_caption_merge.py tests/gateway/test_telegram_text_photo_startup_merge.py
# 60 passed, 1 warning in 5.52s
/usr/local/lib/hermes-agent/venv/bin/python -m ruff check gateway/run.py gateway/platforms/telegram.py tests/gateway/test_telegram_text_photo_startup_merge.py tests/gateway/test_status_command.py
# All checks passed! |
4d5b9b8 to
ee9aee5
Compare
|
Rebuilt this PR on current The refreshed implementation preserves the original fix: before prompt/image preparation, a starting Telegram text turn now waits briefly for same-session image work and steals any pending photo/image-document batches so a back-to-back “text + screenshot” arrives as one multimodal turn instead of text-only + queued image. Local verification:
|
ee9aee5 to
3f83c71
Compare
|
Thanks for rebuilding this after the Telegram adapter migration. The underlying race is present on current main: short text batches can flush at the 0.18s fast-path cap ( Problems
Suggested changes
Automated hermes-sweeper review. |
|
Closing this in favor of #46101. After rebasing #46101 onto current upstream, that branch covers this text+photo startup race and the broader Telegram startup attachment/forwarded-text batching cases in one place, with focused coverage in |
What does this PR do?
Fixes a Telegram cross-modal startup race where a short text message can start an agent turn before a same-session photo finishes downloading and flushing from the photo batch buffer.
The runner now gives Telegram text-only events a short bounded chance to merge same-session image followups before preparing prompt text and native image routing. This preserves the text fast path for normal text-only messages while preventing image-backed questions from becoming text-only turns.
Related Issue
Fixes #33270
Type of Change
Changes Made
gateway/platforms/telegram.py: tracks in-progress same-session image downloads and exposes a helper to pop/merge startup photo-burst and media-group buffers.gateway/run.py: merges same-session Telegram image followups into text-only events before prompt preparation and image routing, including a bounded grace window controlled byHERMES_TELEGRAM_STARTUP_MEDIA_GRACE_SECONDS.tests/gateway/test_telegram_text_photo_startup_merge.py: covers buffered photo batches, in-progress photo downloads, and image followups already queued by the active-session pending path.How to Test
Focused regression commands run:
Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — N/Acli-config.yaml.exampleif I added/changed config keys — N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/AScreenshots / Logs
Sanitized failing order from the production session:
The image was cached locally but did not reach image routing before the turn started.