aws / aws/bedrock-agentcore-sdk-python

bug: incorrect pagination in Memory Session Manager `list_messages`

Đang mở
#346 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
Python
Star
761
Fork
147
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
7

Mô tả

## Problem

### Before PR #244

State events and conversational events were naturally separated by actorId:

```python
# 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:

```python
# 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:

```python
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):

1. `max_results` = limit + offset = 10
2. `list_events` returns 10 events: 3 state + 7 conversational
3. `events_to_messages` discards the 3 state events → 7 messages
4. 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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu trong session_manager.py tại list_messages và kiểm tra cách memory_client.list_events áp dụng max_results cũng như cách events_to_messages loại bỏ các state events. Tái hiện trường hợp có shared actor IDs và các session hoặc agent state events, sau đó bổ sung coverage cho unit test hoặc integration test; hoàn tất khi phân trang trả về các message được yêu cầu hoặc cung cấp một nextToken khi còn message khác.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
api, backend
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
58/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.