Skip to content

MemorySession.get_last_k_turns(branch_name=...) fails with ParamValidationError for includeParentBranches=None #760

Backlog

Description

@chaitanya0305

Describe the bug
MemorySession.get_last_k_turns() defaults include_parent_branches to None. When a branch_name other than "main" is passed, MemorySessionManager.get_last_k_turns() puts that value into the list_events branch filter. boto3 requires includeParentBranches to be a bool, so the call fails before any request is sent:

botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter filter.branch.includeParentBranches, value: None, type: <class 'NoneType'>, valid types: <class 'bool'>

So reading the last turns of a branch through a MemorySession does not work unless the caller also passes include_parent_branches explicitly. The equivalent MemorySession.list_events(branch_name=...) works, because its default is False.

To Reproduce
Offline, with botocore's Stubber:

from botocore.stub import Stubber
from bedrock_agentcore.memory.session import MemorySessionManager

m = MemorySessionManager("mymemory-abcdefgh12", region_name="us-east-1")
s = m.create_memory_session("actor-1", "session-1")

with Stubber(m._data_plane_client) as st:
    st.add_response("list_events", {"events": []})
    print(s.list_events(branch_name="alt"))          # [] - works

with Stubber(m._data_plane_client) as st:
    st.add_response("list_events", {"events": []})
    print(s.get_last_k_turns(k=3, branch_name="alt"))  # ParamValidationError

Expected behavior
session.get_last_k_turns(k=3, branch_name="alt") returns the turns of branch alt (here []), the same as manager.get_last_k_turns(actor_id, session_id, k=3, branch_name="alt").

Root cause
src/bedrock_agentcore/memory/session.py:1236 (MemorySession.get_last_k_turns):

include_parent_branches: Optional[bool] = None,

It is passed straight to MemorySessionManager.get_last_k_turns, which builds
{"branch": {"name": branch_name, "includeParentBranches": include_parent_branches}} (session.py:814-815). The manager method and MemorySession.list_events both default to False. The None default came in with #108.

Environment

  • bedrock-agentcore 1.28.0 (main at 9ab8cea). Affected since v1.0.0.
  • Python 3.12, boto3/botocore current.

Additional context
Fix: change the default to include_parent_branches: bool = False. A tested fix with a Stubber-based regression test is ready on branch chaitanya0305:fix/memory-session-get-last-k-turns-parent-branches.

Activity

  1. added
    bug
    on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions