diff --git a/bsky.py b/bsky.py index 6432be5..218c922 100644 --- a/bsky.py +++ b/bsky.py @@ -419,9 +419,16 @@ If you choose to reply, use the add_post_to_bluesky_reply_thread tool. Each call max_steps=100 ) - # Collect the streaming response + # Collect the streaming response with timeout protection all_messages = [] + stream_start_time = time.time() + max_stream_duration = 600 # 10 minutes max + for chunk in message_stream: + # Check for timeout + if time.time() - stream_start_time > max_stream_duration: + logger.warning(f"Stream exceeded {max_stream_duration}s timeout, breaking") + break # Log condensed chunk info if hasattr(chunk, 'message_type'): if chunk.message_type == 'reasoning_message': @@ -606,6 +613,9 @@ If you choose to reply, use the add_post_to_bluesky_reply_thread tool. Each call logger.error(f"Agent error (dict): {chunk.model_dump()}") elif hasattr(chunk, '__dict__'): logger.error(f"Agent error (vars): {vars(chunk)}") + elif chunk.message_type == 'ping': + # Silently ignore ping keepalive messages + logger.debug(f"Received keepalive ping from Letta API") else: # Filter out verbose message types if chunk.message_type not in ['usage_statistics', 'stop_reason']: @@ -1582,8 +1592,15 @@ You may use these blocks as you see fit. Synthesize your recent experiences into synthesis_posts = [] ack_note = None - # Process the streaming response + # Process the streaming response with timeout protection + stream_start_time = time.time() + max_stream_duration = 600 # 10 minutes max + for chunk in message_stream: + # Check for timeout + if time.time() - stream_start_time > max_stream_duration: + logger.warning(f"Synthesis stream exceeded {max_stream_duration}s timeout, breaking") + break if hasattr(chunk, 'message_type'): if chunk.message_type == 'reasoning_message': if SHOW_REASONING: @@ -1669,6 +1686,9 @@ You may use these blocks as you see fit. Synthesize your recent experiences into print(" ──────────────────") for line in chunk.content.split('\n'): print(f" {line}") + elif chunk.message_type == 'ping': + # Silently ignore ping keepalive messages + logger.debug(f"Received keepalive ping from Letta API during synthesis") elif chunk.message_type == 'error_message': # Dump full error object logger.error(f"Synthesis error_message: {chunk}")