Skip to content

Conversation

@renvins
Copy link

@renvins renvins commented Nov 10, 2025

Summary

Fixes session management for OpenAI Responses API when using Zero Data Retention (store=False) with load-balanced instances. Previously, reasoning item IDs were saved to sessions, causing "reasoning item not found" errors when subsequent requests were routed to different OpenAI instances.

Problem:
When using the OpenAI Responses API with store=False (ZDR mode) and reasoning enabled (response_include=["reasoning.encrypted_content"]), the API returns reasoning items with instance-specific IDs (e.g., rs_07162bf5faaac0660...). These IDs are temporary references to reasoning content stored in the memory of the specific OpenAI instance that generated them. When the SDK's session management saves these items to persistent storage and replays them in a subsequent request, if that request is load-balanced to a different OpenAI instance, the new instance cannot resolve the ID, resulting in an error.

Root Cause:
Even with store=False, OpenAI assigns instance-specific IDs to reasoning items. These IDs act as cryptographic references to encrypted reasoning content temporarily held in the memory of the specific instance. The encrypted_content field, however, is universally decryptable by any OpenAI instance using shared internal keys.

Solution:
Modified _save_result_to_session() in src/agents/run.py to conditionally strip the id field from reasoning items when store=False before persisting them to session storage. This ensures that only portable information (the encrypted_content) is saved.

The fix:

  • Checks if a reasoning item has store=False set in the agent's model settings
  • Strips the instance-specific id field before saving to session
  • Preserves the encrypted_content field, which is universally decryptable
  • Keeps IDs intact when store=True or None (default), as those reference valid server-side conversation state

Issue number

Closes #2063

User Scenario

Before Fix:

Turn 1 → Instance A → Returns reasoning{id: rs_A123, encrypted_content: xxx}
         ↓
Session saves both id and encrypted_content
         ↓
Turn 2 → Instance B → Receives id: rs_A123 → ❌ Error: "reasoning item not found"

After Fix:

Turn 1 → Instance A → Returns reasoning{id: rs_A123, encrypted_content: xxx}
         ↓
Session saves ONLY encrypted_content (id stripped)
         ↓
Turn 2 → Instance B → Receives only encrypted_content → ✅ Success: decrypts and continues

The chosen approach balances correctness, backward compatibility, and minimal API surface changes.

…g by removing instance-specific IDs for reasoning types when store setting is disabled.
Copy link

@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.

ℹ️ 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".

@renvins
Copy link
Author

renvins commented Nov 10, 2025

Now tests should be all ok!

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.

Responses API ZDR still stores the reasoning items

2 participants