fix: avoid stale object-id dedupe in server conversation tracker#3621
Open
chutch wants to merge 1 commit into
Open
fix: avoid stale object-id dedupe in server conversation tracker#3621chutch wants to merge 1 commit into
chutch wants to merge 1 commit into
Conversation
Author
|
Design note: a pure |
Author
|
@seratch Do you think we can rely on the uniqueness of |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OpenAIServerConversationTrackerkept long-livedset[int]state for object ids insent_itemsandserver_items.prepare_inputused those ids to skip generated items:That is unsafe after the original object is gone, because CPython can reuse the same address for a
later allocation. A fresh
function_call_outputcan then be treated as already sent and omittedfrom the next server-managed continuation request, which leaves the provider with a function call
but no output.
This changes the in-process identity tracking to keep object references instead of raw
id()integers:
sent_itemsandserver_itemsnow store the tracked objects.is, not equality.rewind_inputremoves the exact tracked object when an input is rewound.The existing stable dedupe layers are unchanged: provider item ids, server tool-call ids, and
fingerprints still handle their existing retry/resume cases.
This is related to #2798 / #2800, but covers a different live path. #2800 removed one hydrated
initial-input identity seeding path during resume; it did not change the live
prepare_inputidentity check,
mark_input_as_sent, ortrack_server_items.Tradeoffs
The tracker now retains the tracked objects for the tracker's lifetime, rather than retaining only
integer ids. That is intentional for correctness, but it can keep large tool-output objects alive
longer in very long runs. Identity membership is also a linear scan instead of a set lookup; the
tracked collections are expected to be small in normal runs.
Test plan
test_prepare_input_keeps_fresh_tool_output_when_stale_identity_matches, parametrized oversent_itemsandserver_items. The test fails on currentorigin/mainwithAssertionError: assert 'call_FRESH' in []and passes with this change.test_prepare_input_dedupes_same_delivered_tool_output_objectto preserve the existingsame-object dedupe behavior after delivery.
PYTHONPATH=/private/tmp/oai-agents-stable-keys/src python -m pytest tests/test_server_conversation_tracker.pyPYTHONPATH=/private/tmp/oai-agents-stable-keys/src python -m pytest tests/test_oaiconv_resume_response_id.py tests/test_agent_runner.py::test_conversation_id_only_sends_new_items_multi_turn tests/test_agent_runner.py::test_conversation_id_only_sends_new_items_multi_turn_streamedPYTHONPATH=/private/tmp/oai-agents-stable-keys/src python -m pytest tests/test_agent_runner.pypython -m ruff check .python -m ruff format --check .PYTHONPATH=/private/tmp/oai-agents-stable-keys/src python -m mypy src/agents/run_internal/oai_conversation.py tests/test_server_conversation_tracker.pypyright --project pyrightconfig.json src/agents/run_internal/oai_conversation.py tests/test_server_conversation_tracker.pyCloses #3620