fix: strip stale reasoning item IDs from local session history#3582
fix: strip stale reasoning item IDs from local session history#3582Oxygen56 wants to merge 1 commit into
Conversation
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
There was a problem hiding this comment.
💡 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".
| if not is_openai_conversation_session: | ||
| converted_history = strip_stale_reasoning_item_ids(converted_history) |
There was a problem hiding this comment.
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 👍 / 👎.
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
Fixes #2020