-
Notifications
You must be signed in to change notification settings - Fork 4.2k
fix(session_persistence): count persisted items after filtering unpersistable conversation items #3580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(session_persistence): count persisted items after filtering unpersistable conversation items #3580
Changes from all commits
51e42ef
cc47d8d
3e20b7e
5f050e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -280,6 +280,10 @@ async def save_result_to_session( | |
| if missing_outputs: | ||
| new_run_items = missing_outputs + new_run_items | ||
|
|
||
| # Raw retry offset: count the run items we consumed from this turn, | ||
| # not just the subset that was actually persisted. | ||
| new_run_items_raw_count = len(new_run_items) | ||
|
|
||
| input_list: list[TResponseInputItem] = [] | ||
| if original_input: | ||
| input_list = normalize_input_items_for_api( | ||
|
|
@@ -322,6 +326,11 @@ async def save_result_to_session( | |
| if is_openai_conversation_session and items_to_save: | ||
| items_to_save = [_sanitize_openai_conversation_item(item) for item in items_to_save] | ||
|
|
||
| if is_openai_conversation_session: | ||
| items_to_save = [ | ||
| item for item in items_to_save if not _is_unpersistable_for_openai_conversation(item) | ||
| ] | ||
|
Comment on lines
+329
to
+332
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In the resumed-run path I checked ( Useful? React with 👍 / 👎. |
||
|
|
||
| serialized_to_save: list[str] = [ | ||
| _fingerprint_or_repr(item, ignore_ids_for_matching=ignore_ids_for_matching) | ||
| for item in items_to_save | ||
|
|
@@ -336,20 +345,25 @@ async def save_result_to_session( | |
| serialized_to_save_counts[serialized] -= 1 | ||
| saved_run_items_count += 1 | ||
|
|
||
| if is_openai_conversation_session: | ||
| items_to_save = [ | ||
| item for item in items_to_save if not _is_unpersistable_for_openai_conversation(item) | ||
| ] | ||
| returned_count = ( | ||
| new_run_items_raw_count | ||
| if is_openai_conversation_session and run_state is None | ||
| else saved_run_items_count | ||
| ) | ||
|
|
||
| if len(items_to_save) == 0: | ||
| if run_state: | ||
| run_state._current_turn_persisted_item_count = already_persisted + saved_run_items_count | ||
| run_state._current_turn_persisted_item_count = ( | ||
| already_persisted + new_run_items_raw_count | ||
| ) | ||
|
Comment on lines
+356
to
+358
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For non-OpenAI sessions, a Useful? React with 👍 / 👎. |
||
| return saved_run_items_count | ||
|
|
||
| await session.add_items(items_to_save) | ||
|
|
||
| if run_state: | ||
| run_state._current_turn_persisted_item_count = already_persisted + saved_run_items_count | ||
| run_state._current_turn_persisted_item_count = ( | ||
| already_persisted + new_run_items_raw_count | ||
| ) | ||
|
Comment on lines
+364
to
+366
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When an OpenAI Conversations turn has an unpersistable reasoning item before a persistable item, Useful? React with 👍 / 👎. |
||
|
|
||
| if response_id and is_openai_responses_compaction_aware_session(session): | ||
| has_local_tool_outputs = any( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For
OpenAIConversationsSessionturns where an unpersistable reasoning item precedes a persistable item, this filtering makessaved_run_items_countexclude the reasoning item even though_current_turn_persisted_item_countis later used as a slice index into the original, unfilterednew_itemslist (new_items[already_persisted:]). For example, after saving[bad reasoning, assistant message], the counter becomes1; a retry/resume starts at raw index 1 and saves the already-persisted assistant message again, causing duplicate session items. The accounting needs either a separate raw-item offset or filtering before the slice/counting logic so retries skip the same items that were already considered.Useful? React with 👍 / 👎.