Repository navigation
fix: refuse a conversation turn that resends a stored item before inference - #562
Baiiiiiiiiii wants to merge 1 commit into
Conversation
…erence Signed-off-by: Baiiiiiiiiii <2002paipai@gmail.com>
| // The conversation's items are prepended to the input, so resending one of them repeats it in the input. | ||
| let new_ids: HashSet<&str> = ctx.new_input_items.iter().filter_map(InOutItem::id).collect(); | ||
| if let Some(id) = items.iter().filter_map(InOutItem::id).find(|id| new_ids.contains(id)) { | ||
| return Err(ExecutorError::duplicate_input_item(id)); |
There was a problem hiding this comment.
I think the proper fix is to let exec_ctx.conv_handler.rehydrate to gate the duplication. similar to how exec_ctx.response_handler.rehydrate calls on resolve_input_items that way there is only one single iterator in the history of items. seems like this adds overhead to the rehydration path but if during rehydration we can identify duplicate and avoid it then we can avoid overhead
|
|
||
| impl ExecutorError { | ||
| /// The error `OpenAI` returns for a model input that holds the item `id` twice. | ||
| pub(crate) fn duplicate_input_item(id: &str) -> Self { |
There was a problem hiding this comment.
I think there is already an error type specific for duplicate item or conflict error perhaps it can be reused?
|
I took a closer look and noticed a correct solution is to resolve the turn's input against the history it continues inside OpenAI accepts the same resend with Suggested changes:
|
|
the new |
|
Thank you for the detailed design! I'll rework the PR as you suggested:
I'll also add the four cases to the |
Summary
A client that keeps its whole history and passes
conversationresends items the conversation already holds, as in the function-calling guide's loop. The gateway ran inference, then failed with500 failed to persist response(#561). Nowfrom_conversationrefuses such a turn before inference, with the duplicate-input error the gateway already returns for an id repeated in one request.ARCHITECTURE.mdstates the rule.Changes by API
/v1/responses)conversationturn whoseinputrepeats one of the conversation's items returns400 invalid_request_error,param: "input",code: null, "Duplicate item found with id …", before inference. Before: 500 after inference; a stream sent the answer, then anerrorevent. Astore: falseturn like this used to complete, with the item twice in the model's input; it now gets the same 400.Test Plan
Evidence. Recorded in
response-replayed-items-openai.yaml: t6 is OpenAI's 400 for an id repeated in one input, the error this PR returns; t3 is OpenAI's 200 for a stored item sent back withoutconversation, which this PR does not change. Documented: theconversationreference says the conversation's items "are prepended toinput_items". Quoted, not recorded: openai-agents-python#1789 quotes the same 400 for this request in September 2025.No new recording: I have no OpenAI API key. The recording this needs: extend the
replayed-itemsscenario inrecord_cassette.pywith a conversation turn that calls a function tool, then the resend (user message, the storedfunction_call, its output), once withstore: trueand once withstore: false. Then runRESPONSES_RECORD_SET=all RESPONSES_SCENARIO=replayed-items bash crates/agentic-server-core/tests/cassettes/record_responses_api_cassettes.sh. I did not see OpenAI's reply forstore: false. If the recording differs, I will match the gateway to it.conversation_turn_resending_a_stored_item_is_refused_before_inference, 3 cases. Each resends the stored function call with its output. It checks the 400 body, zero inference requests and an unchanged conversation. Then it sends only the output and gets the answer.store: truefailed to persist response, after 1 inference requeststore: true,stream: trueerrorevent, after 1 inference requeststore: falseOn main, the model's input held the resent item twice in all three cases.
conversation_turn_accepts_items_stored_in_another_conversation: the same items sent to a new conversation still complete.cargo test --locked: 3172 passed, 0 failed.cargo clippy --all-targets -- -D warnings: clean.pre-commit run --all-files: passed.