Skip to content

fix: strip stale reasoning item IDs from local session history#3582

Open
Oxygen56 wants to merge 1 commit into
openai:mainfrom
Oxygen56:fix/stale-reasoning-item-ids
Open

fix: strip stale reasoning item IDs from local session history#3582
Oxygen56 wants to merge 1 commit into
openai:mainfrom
Oxygen56:fix/stale-reasoning-item-ids

Conversation

@Oxygen56
Copy link
Copy Markdown

@Oxygen56 Oxygen56 commented Jun 5, 2026

Summary

When reasoning items are stored in a local session (SQLiteSession, etc.) and later replayed as model input, their server-assigned IDs (rs_xxx) point to content that no longer exists on the server. This causes 404 errors.

This PR adds strip_stale_reasoning_item_ids() which removes the id field from reasoning items, and wires it into prepare_input_with_session() for all session types EXCEPT OpenAIConversationsSession.

Changes

  1. run_internal/items.py — new strip_stale_reasoning_item_ids() function
  2. run_internal/session_persistence.py — calls it on history items from non-Conversations sessions
  3. tests/test_session_reasoning_items.py — 5 test cases

Fixes #2020

When reasoning items are stored in a local session (SQLiteSession, etc.)
and later replayed as model input, their server-assigned IDs point to
content that no longer exists on the server. This causes 404 errors:
'Item with id rs_xxx not found'.

Add strip_stale_reasoning_item_ids() which removes the 'id' field from
reasoning items. Wire it into prepare_input_with_session() for all
session types EXCEPT OpenAIConversationsSession (where the server
manages item identity).

The existing ReasoningItemIdPolicy='omit' already allows users to opt
out of reasoning IDs entirely. This fix handles the common default case
where IDs are preserved but become stale in local storage.

Fixes openai#2020
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2cecee7060

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +97 to +98
if not is_openai_conversation_session:
converted_history = strip_stale_reasoning_item_ids(converted_history)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor explicit preserve policy for session history

When a caller uses a local session with RunConfig(reasoning_item_id_policy="preserve"), this unconditional strip runs before the config is consulted, so persisted reasoning items are sent without their IDs even though the public policy says "preserve" keeps IDs. This makes local session behavior inconsistent with generated same-run history and prevents callers who explicitly need ID preservation from opting out; pass the resolved policy into session preparation or only apply this mitigation when preservation was not requested.

Useful? React with 👍 / 👎.

@seratch seratch added duplicate This issue or pull request already exists feature:sessions labels Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists feature:sessions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Item with id rs_ not found

2 participants