-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Problem
The summarizer was using the synchronous anthropic.Anthropic client inside an async handler. When messages.create() was called, it blocked the entire asyncio event loop for the duration of the API call (~80-90 seconds), preventing aiogram from polling Telegram for updates.
This caused:
TelegramNetworkError: HTTP Client says - Request timeout error— aiogram's long-polling connection timed out while the event loop was blockedFailed to parse Claude response as JSON— themax_tokens=4096limit was too low for 56 messages, causing Claude's response to be truncated mid-JSON
Symptoms
[ERROR] bot.summarizer: Failed to parse Claude response as JSON: { "topics": [ ...truncated...
[ERROR] aiogram.dispatcher: Failed to fetch updates - TelegramNetworkError: HTTP Client says - Request timeout error
[INFO] aiogram.event: Update id=454771996 is handled. Duration 92243 ms
Fix (commit 18e0207)
- Switched from
anthropic.Anthropic(sync) toanthropic.AsyncAnthropicso the API call yields to the event loop - Increased
max_tokensfrom 4096 to 8192 to prevent response truncation - Added a warning log when
stop_reason != "end_turn"to detect future truncation issues
Lesson
Always use async SDK clients (AsyncAnthropic, AsyncOpenAI, etc.) inside async frameworks like aiogram to avoid blocking the event loop.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels