fix: prevent duplicate re-persistence of tool output items in session store#3925
fix: prevent duplicate re-persistence of tool output items in session store#3925AAliKKhan wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b8b8bc9cc3
ℹ️ 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".
| missing_outputs = [ | ||
| item | ||
| for item in new_items | ||
| for item in new_items[:already_persisted] |
There was a problem hiding this comment.
Stop re-saving already-persisted tool outputs
When a streaming turn has already saved a tool_call_output_item and a later save is called with the cumulative new_items list plus newly produced items, this slice iterates exactly over the already-persisted prefix; the condition then prepends that old tool output to new_run_items, so session.add_items() writes it again and the duplicate-growth bug remains. The scan needs to exclude already-persisted items rather than select them, or track saved items after conversion/persistence filtering.
AGENTS.md reference: AGENTS.md:L112-L112
Useful? React with 👍 / 👎.
In save_result_to_session, the missing_outputs scan searched the entire new_items list for tool_call_output_items not yet in new_run_items. This caused already-persisted tool outputs to be re-prepended on every streaming save call, leading to unbounded session storage growth. The fix limits the scan to the already-persisted portion of the list.