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

@Epochex Epochex commented May 27, 2026

Copy link
Copy Markdown

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

bombert commented May 28, 2026

Copy link
Copy Markdown

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

Epochex commented May 28, 2026

Copy link
Copy Markdown
Author

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

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open for 10 days with no activity.

@github-actions github-actions Bot added the stale label Jun 8, 2026
@Epochex

Epochex commented Jun 8, 2026

Copy link
Copy Markdown
Author

Still relevant. The requested empty-summary case was added in 13e004c with a focused regression test; this is waiting for maintainer review now.

@github-actions github-actions Bot removed the stale label Jun 9, 2026
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