Skip to content

fix(session): strip reasoning item ids from session history#3514

Open
Epochex wants to merge 2 commits into
openai:mainfrom
Epochex:fix/session-strip-reasoning-item-ids-2020
Open

fix(session): strip reasoning item ids from session history#3514
Epochex wants to merge 2 commits into
openai:mainfrom
Epochex:fix/session-strip-reasoning-item-ids-2020

Conversation

@Epochex
Copy link
Copy Markdown

@Epochex Epochex commented May 27, 2026

Fixes #2020

Session-backed runs can end up replaying reasoning items with server-assigned rs_... IDs from prior turns. Those IDs are not guaranteed to be stable across turns, and replaying them can trigger a 404 ("Item with id 'rs_...' not found") in a subsequent responses.create call.

This change strips the id field from reasoning items loaded from non-Conversations sessions before building model input, so the reasoning payload can still be replayed without relying on server-side item retention.

Tests:

  • uv run ruff format src/agents/run_internal/session_persistence.py tests/test_agent_runner.py
  • uv run ruff check src/agents/run_internal/session_persistence.py tests/test_agent_runner.py
  • uv run pyright --project pyrightconfig.json src/agents/run_internal/session_persistence.py tests/test_agent_runner.py
  • uv run pytest tests/test_agent_runner.py -q

@bombert
Copy link
Copy Markdown

bombert commented May 28, 2026

Hi Epochex:

Could you add this check in the _strip_reasoning_item_ids_from_history_item for this case?

# Drop the item entirely if summary is missing or empty if not sanitized.get("summary"): return None

`
{
"input":[
{
"content":"User id is u_123. Help me choose the best subscription plan.",
"role":"user"
},
{
"id":"rs_0b61d86498c245ce016a17c138fc588199b2a78d6a1b3a6776",
"summary":[

     ],
     "type":"reasoning"
  }

]
}
`

@Epochex
Copy link
Copy Markdown
Author

Epochex commented May 28, 2026

Done in 13e004c. I changed the session-history sanitizer to drop replayed reasoning items when summary is missing or empty, while still preserving reasoning items that have a summary and stripping only their id.

Ran:
uv run pytest tests/test_agent_runner.py::test_prepare_input_with_session_strips_reasoning_item_ids_from_history tests/test_agent_runner.py::test_prepare_input_with_session_drops_reasoning_items_without_summary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Item with id rs_ not found

3 participants