Auto: fix/streaming-message-too-long #17

Merged
claude-bot merged 2 commits from fix/streaming-message-too-long into main 2026-03-01 15:22:46 -07:00
Collaborator

Automated PR for branch fix/streaming-message-too-long.

Automated PR for branch `fix/streaming-message-too-long`.
fix: handle message_too_long during streaming with continuation indicator
Some checks failed
Auto PR Review / review (push) Failing after 1m55s
f130f800ce
When streamed text exceeds Telegram's 4096 char limit, streaming edits
now stop gracefully and a "Tarjima davom etmoqda..." message is shown.
The continuation message is deleted after final formatted output is sent.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
Collaborator

Changes Requested

Well-structured change — the refactoring from closure to stateful class is clean and the test coverage is solid. One real bug: the continuation message leaks on error paths.

Warnings

  • handlers/translation.py: Continuation message not cleaned up on error paths. Lines 894 and 903 return early (translation exception / not result.success) before the cleanup block at line 906. If streaming sent the 'Tarjima davom etmoqda...' message but the translation then fails, the user is left with a stale continuation message in the chat. Move the cleanup before the two early-return blocks, or extract a small helper and call it in all three paths.

Suggestions

  • handlers/translation.py: _handle_message_too_long(self, accumulated_text) accepts accumulated_text but never uses it. Consider removing the parameter to avoid confusion (callers may think it's being sent to Telegram).
## Changes Requested Well-structured change — the refactoring from closure to stateful class is clean and the test coverage is solid. One real bug: the continuation message leaks on error paths. ### Warnings - **handlers/translation.py**: Continuation message not cleaned up on error paths. Lines 894 and 903 return early (translation exception / `not result.success`) before the cleanup block at line 906. If streaming sent the 'Tarjima davom etmoqda...' message but the translation then fails, the user is left with a stale continuation message in the chat. Move the cleanup before the two early-return blocks, or extract a small helper and call it in all three paths. ### Suggestions - **handlers/translation.py**: `_handle_message_too_long(self, accumulated_text)` accepts `accumulated_text` but never uses it. Consider removing the parameter to avoid confusion (callers may think it's being sent to Telegram).
fix: clean up continuation message on error paths, remove unused param
All checks were successful
Auto PR Review / review (push) Successful in 3m59s
9003fc4314
Move continuation message deletion before early-return error paths so
the "Tarjima davom etmoqda..." message doesn't leak on failures.
Extract _delete_continuation_message helper for all three code paths.
Remove unused accumulated_text parameter from _handle_message_too_long.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
Collaborator

Approved

Clean, well-structured change. The refactoring from a closure to a _StreamingCallback class is appropriate for managing the continuation message state. Error handling flows are correct: the callback catches message_too_long, sends the continuation indicator, re-raises for the streaming loop to disable further edits, and cleanup runs in all code paths. The final translate_message already uses split_message() for the formatted result, so messages exceeding 4096 chars are handled end-to-end. Test coverage is solid.

Suggestions

  • handlers/translation.py: Misleading comment on line 642: "Remove cursor from current message (show last successful text)" implies the code removes the cursor indicator, but it doesn't — it only sends the continuation message. The cursor remains in the last successful edit until final formatting replaces it. Consider rewording to something like: "The last successful edit retains the cursor indicator; it will be replaced by the final formatted result."
  • tests/integration/test_translation_flow.py: The test does not set up context.bot.delete_message as an AsyncMock. It works because _delete_continuation_message has a broad except Exception: pass that swallows the TypeError from awaiting a regular MagicMock, while the call is still recorded for assertion. Adding context.bot.delete_message = AsyncMock() would make the test more explicit and less reliant on this incidental behavior.
## Approved Clean, well-structured change. The refactoring from a closure to a `_StreamingCallback` class is appropriate for managing the continuation message state. Error handling flows are correct: the callback catches `message_too_long`, sends the continuation indicator, re-raises for the streaming loop to disable further edits, and cleanup runs in all code paths. The final `translate_message` already uses `split_message()` for the formatted result, so messages exceeding 4096 chars are handled end-to-end. Test coverage is solid. ### Suggestions - **handlers/translation.py**: Misleading comment on line 642: "Remove cursor from current message (show last successful text)" implies the code removes the cursor indicator, but it doesn't — it only sends the continuation message. The cursor remains in the last successful edit until final formatting replaces it. Consider rewording to something like: "The last successful edit retains the cursor indicator; it will be replaced by the final formatted result." - **tests/integration/test_translation_flow.py**: The test does not set up `context.bot.delete_message` as an `AsyncMock`. It works because `_delete_continuation_message` has a broad `except Exception: pass` that swallows the `TypeError` from awaiting a regular `MagicMock`, while the call is still recorded for assertion. Adding `context.bot.delete_message = AsyncMock()` would make the test more explicit and less reliant on this incidental behavior.
claude-bot deleted branch fix/streaming-message-too-long 2026-03-01 15:22:46 -07:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
bittabola/tarjimon!17
No description provided.