Repository navigation
Description
Problem
Before PR #244
State events and conversational events were naturally separated by actorId:
# create_session used a prefixed actorId
create_event(actorId="session_my-session-id", payload=[{"blob": ...}])
# create_agent used a prefixed actorId
create_event(actorId="agent_my-agent-id", payload=[{"blob": ...}])
# create_message used the regular actorId
create_event(actorId="my-actor-id", payload=[{"conversational": ...}])So when list_messages called list_events with actorId="my-actor-id", it only got conversational events back. State events lived under different actorIds and were invisible to this query. max_results counted only
what mattered.
After PR #244
Everything now uses the same actorId, with metadata distinguishing state events:
# create_session — same actorId, metadata marks it as state
create_event(
actorId="my-actor-id", # ← same as messages now
metadata={"stateType": {"stringValue": "SESSION"}},
payload=[{"blob": ...}],
)
# create_agent — same actorId, metadata marks it as state
create_event(
actorId="my-actor-id", # ← same as messages now
metadata={"stateType": {"stringValue": "AGENT"}, "agentId": {"stringValue": "..."}},
payload=[{"blob": ...}],
)
# create_message — same actorId, no metadata
create_event(actorId="my-actor-id", payload=[{"conversational": ...}])Potential Issues
list_messages in session_manager.py fetches events without any metadata filter:
events = self.memory_client.list_events(
memory_id=self.config.memory_id,
actor_id=self.config.actor_id,
session_id=session_id,
max_results=max_results, # ← this now includes state events in the count
)Since all events share the same actorId now, this query returns both conversational AND state events. The API returned max_results events total, some of which were state events. Those get discarded by the converter, so the final list is shorter than what the caller asked for.
Concrete example
A session with 1 session state event, 2 agent state events, and 20 conversational messages. Customer calls list_messages(limit=10):
max_results= limit + offset = 10list_eventsreturns 10 events: 3 state + 7 conversationalevents_to_messagesdiscards the 3 state events → 7 messages- Customer gets 7 messages, expected 10
Customer does not get a pagination token, so they assume 7 is all that exists, and doesn't know there are more.
Acceptance Criteria
- customer should be given nextToken, or should always get maxResults exactly if more results exist.
- unit tests and/or integration verifying fix of the bug.
Activity
hiSandog commentedon Jul 14, 2026
For “bug: incorrect pagination in Memory Session Manager 'list_messages'”, the
list_messagesreproduction could become a table-driven test covering an empty result, one full page, and a final partial page. That would pin down cursor termination as well as the reported failure at the page boundary.ekumar96 commentedon Oct 30, 2026
We hit a related, more severe case of this on the no-limit path that Strands uses for every restore, so I'm adding it here instead of opening a new issue.
RepositorySessionManager.initializecallslist_messages(session_id, agent_id, offset=conversation_manager.removed_message_count)with nolimit. Onmain(3707a9f, v1.25.2):session_manager.py:785:max_results = (limit + offset) if limit else MAX_FETCH_ALL_RESULTS, so the read is capped at the newest 10,000 events, counting SESSION/AGENT state events as described above.session_manager.py:796-799:messages[offset:]is applied to that capped window, not to the full history. Strands (andFileSessionManager) treatoffsetas an index into the full message list.session_manager.py:801-803: any exception is logged and returned as[], so a failed read looks like an empty session.Impact, reproduced live (Strands agent restoring from AgentCore Memory, Claude Sonnet 4.6 on Bedrock; sessions with 10,100 messages = 10,102 events; a 9,600-message control session restored correctly):
NullConversationManager: the restore returns the newest 10,000 messages, so the oldest are dropped silently. The agent then sends more than 10,000 messages and Bedrock rejects every turn with a misleadingValidationException: The additional field role conflicts with an existing field. Each failed turn still journals its user message, so the session can't recover.SlidingWindowConversationManager(150)(storedremoved_message_count9,951): the restore returns 47 messages instead of 150, with no error. That's roughly150 − (events − 10,000), so from about 10,150 events on it returns zero messages and the agent silently loses all context.Minimal repro
Suggested fix
limit is None, paginate all events and applyoffsetto the full message list. If a safety cap is needed, raise when it's hit instead of truncating.limitcase).SessionException) instead of returning[].MAX_FETCH_ALL_RESULTSevents and a nonzerooffset. Also, thelist_eventsdocstring says "chronological order", but the results come back newest first.A session gets there after roughly 3,300 short turns, and much sooner for agent loops with many tool calls.