Skip to content

[BUG] S3SessionManager throwing RuntimeError: asyncio.run() cannot be called from a running event loop #1012

@drobbins-ancile

Description

@drobbins-ancile

Checks

  • I have updated to the lastest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Strands Version

1.11.0

Python Version

3.12.11

Operating System

macOS 26.0.1

Installation Method

pip

Steps to Reproduce

  1. Configure an S3 Session Manager
  2. Attempt to continue a conversation in the same thread
  3. Error message is generated RuntimeError: asyncio.run() cannot be called from a running event loop

Expected Behavior

The agent will retrieve the session memory and continue the conversation without error.

Actual Behavior

An error message is generated:
RuntimeError: asyncio.run() cannot be called from a running event loop

Additional Context

This started with the most recent version of Strands and appears to be related to PR 897

The issue does not occur when using a version of the strands SDK prior to this change.

Here's a sample of the traceback:

  File "/usr/local/lib/python3.12/site-packages/strands/session/session_manager.py", line 26, in <lambda>
    registry.add_callback(AgentInitializedEvent, lambda event: self.initialize(event.agent))
                          │                             │      │    │          │     └ <strands.agent.agent.Agent object at 0x7f4f842701a0>
                          │                             │      │    │          └ AgentInitializedEvent(agent=<strands.agent.agent.Agent object at 0x7f4f842701a0>)
                          │                             │      │    └ <function RepositorySessionManager.initialize at 0x7f4f883b7880>
                          │                             │      └ <strands.session.s3_session_manager.S3SessionManager object at 0x7f4f84264320>
                          │                             └ AgentInitializedEvent(agent=<strands.agent.agent.Agent object at 0x7f4f842701a0>)
                          └ <class 'strands.hooks.events.AgentInitializedEvent'>
  File "/usr/local/lib/python3.12/site-packages/strands/session/repository_session_manager.py", line 143, in initialize
    session_messages = self.session_repository.list_messages(
                       │    │                  └ <function S3SessionManager.list_messages at 0x7f4f883d8fe0>
                       │    └ <strands.session.s3_session_manager.S3SessionManager object at 0x7f4f84264320>
                       └ <strands.session.s3_session_manager.S3SessionManager object at 0x7f4f84264320>
  File "/usr/local/lib/python3.12/site-packages/strands/session/s3_session_manager.py", line 288, in list_messages
    return asyncio.run(self._load_messages_concurrently(message_keys))
           │       │   │    │                           └ ['SDIGRelease/session_U064PUW33KM_1759966201.348549/agents/agent_default/messages/message_0.json', 'SDIGRelease/session_U064P...
           │       │   │    └ <function S3SessionManager._load_messages_concurrently at 0x7f4f883d9080>
           │       │   └ <strands.session.s3_session_manager.S3SessionManager object at 0x7f4f84264320>
           │       └ <function run at 0x7f4f97af56c0>
           └ <module 'asyncio' from '/usr/local/lib/python3.12/asyncio/__init__.py'>
  File "/usr/local/lib/python3.12/asyncio/runners.py", line 191, in run
    raise RuntimeError(
RuntimeError: asyncio.run() cannot be called from a running event loop

Possible Solution

No response

Related Issues

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions