-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Labels
Description
Please read this first
- Have you read the docs?Agents SDK docs
- Yes
- Have you searched for related issues? Others may have faced similar issues.
- Yes
Describe the bug
When two items are logged at the same millisecond, session items are retrieved inconsistently, resulting in type errors from openai responses api.
{
"error": "Error code: 400 - {'error': {'message': \"Item 'msg_0cc6d91adc6c29b10068efd94b03d481978b2f6ab1fdde86a5' of type 'message' was provided without its required 'reasoning' item: 'rs_0cc6d91adc6c29b10068efd916e8188197b28245c3ac31cc5c'.\", 'type': 'invalid_request_error', 'param': 'input', 'code': None}}"
}
Sample thread
1046 thr_0a886bc9 {"id":"rs_0cc6d91adc6c29b10068efd916e8188197b28245c3ac31cc5c","summary":"...","type":"summary_text"}],"type":"reasoning"} 2025-10-15 17:26:39.132483
1047 thr_0a886bc9 {"id":"msg_0cc6d91adc6c29b10068efd94b03d481978b2f6ab1fdde86a5","content":[{"annotations":[],"text":"...","type":"output_text","logprobs":[]}],"role":"assistant","status":"completed","type":"message"} 2025-10-15 17:26:39.132483
Debug information
- Agents SDK version: (e.g.
v0.0.3
)
version = "0.3.3" - Python version (e.g. Python 3.10)
python:3.11.7-slim-bullseye
Repro steps
Ideally provide a minimal python script that can be run to reproduce the bug.
Expected behavior
Sessions should continue without error.
Patch I used locally that seems to help:
if limit is None:
stmt = (
select(self._messages.c.message_data)
.where(self._messages.c.session_id == self.session_id)
.order_by(
self._messages.c.created_at.asc(),
self._messages.c.id.asc(),
)
)
openai-agents-python/src/agents/extensions/memory/sqlalchemy_session.py
Lines 193 to 208 in cfddc7c
async with self._session_factory() as sess: | |
if limit is None: | |
stmt = ( | |
select(self._messages.c.message_data) | |
.where(self._messages.c.session_id == self.session_id) | |
.order_by(self._messages.c.created_at.asc()) | |
) | |
else: | |
stmt = ( | |
select(self._messages.c.message_data) | |
.where(self._messages.c.session_id == self.session_id) | |
# Use DESC + LIMIT to get the latest N | |
# then reverse later for chronological order. | |
.order_by(self._messages.c.created_at.desc()) | |
.limit(limit) | |
) |