Skip to content

feat: add concurrent S3 message reading to list_messages#1422

Closed
Unshure wants to merge 2 commits intomainfrom
agent-tasks/1416
Closed

feat: add concurrent S3 message reading to list_messages#1422
Unshure wants to merge 2 commits intomainfrom
agent-tasks/1416

Conversation

@Unshure
Copy link
Copy Markdown
Member

@Unshure Unshure commented Jan 5, 2026

Motivation

Session managers that store messages in S3 can experience slow performance when listing many messages, as each message is read sequentially from S3. For sessions with dozens or hundreds of messages, this sequential reading creates a significant performance bottleneck that impacts user experience and system responsiveness.

Changes

This PR modifies the S3SessionManager.list_messages() method to read S3 objects concurrently, providing substantial performance improvements for sessions with multiple messages.

The implementation uses the existing run_async() utility to spawn a threaded event loop, then leverages asyncio.to_thread() and asyncio.gather() to perform concurrent S3 reads. The external API remains completely synchronous, requiring no changes to consuming code.

Public API Changes

None. The external API signature and behavior of list_messages() remain unchanged:

def list_messages(
    self, session_id: str, agent_id: str, limit: Optional[int] = None, offset: int = 0, **kwargs: Any
) -> List[SessionMessage]:
    """List messages for an agent with pagination from S3.
    
    Uses concurrent async reading for improved performance when reading multiple messages.
    """

Breaking Changes

None. This is a backward-compatible performance improvement.

Implementation Notes

Initially explored using aiobotocore for native async S3 operations, but discovered that the moto library used for testing doesn't fully support aiobotocore's async client. Switched to asyncio.to_thread() approach which:

  • Provides the same concurrent execution benefits
  • Maintains full compatibility with existing test infrastructure
  • Requires no additional dependencies
  • Works seamlessly with the existing boto3 client

Resolves #1416

Improves performance when listing messages by reading S3 objects concurrently
using asyncio.to_thread and asyncio.gather. The list_messages method now spawns
a threaded async event loop to perform concurrent reads while maintaining the
synchronous external API.

This change provides significant performance benefits for sessions with many
messages without requiring any changes to consuming code or tests.
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 5, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/strands/session/s3_session_manager.py 83.33% 2 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@Unshure
Copy link
Copy Markdown
Member Author

Unshure commented Jan 14, 2026

No longer relevant

@Unshure Unshure closed this Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Async reading from S3 Session Manager List Message

2 participants