fix(gateway): avoid duplicated Responses history#18995
Closed
thelumiereguy wants to merge 1 commit into
Closed
Conversation
6b4ef85 to
fcf659a
Compare
Contributor
|
Merged via #21185 with your commit cherry-picked onto current main — your authorship is preserved in git log via rebase-merge. Thanks @thelumiereguy, clean fix and great repro case. |
12 tasks
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.
Closes the gap: Responses continuation history duplicates prior turns
Problem
/v1/responsessupports stateful continuation throughprevious_response_id, but the API server treatedAIAgent.run_conversation()'sresult["messages"]as a turn-local suffix. In practice that value is the full internal transcript: previous history, the current user message, and new assistant/tool messages.The persistence path rebuilt
conversation_history + current userand then appendedresult["messages"], so each chained response stored the previous transcript twice. Long chains grew roughly exponentially and could trigger unnecessary context compression before otherwise small follow-up requests.The non-streaming response body had a related replay issue: output extraction walked the full transcript and could re-emit old tool call artifacts from earlier
previous_response_idturns.Fix
result["messages"].conversation_history + current user.Behaviour table
old + user + old + user + newold + user + newScope
/v1/responsespersistence ingateway/platforms/api_server.pytests/gateway/test_api_server.pyNo
run_agent.pycontract change:run_conversation()still returns the canonical full transcript used by CLI, TUI, ACP, gateway, and batch paths.Test plan
scripts/run_tests.sh tests/gateway/test_api_server.py -q127 passed, 81 warningsType of Change
References
gateway/platforms/api_server.py:_build_response_conversation_historygateway/platforms/api_server.py:_response_messages_turn_start_indexgateway/platforms/api_server.py:_extract_output_itemstest_previous_response_id_stores_full_agent_transcript_once,test_previous_response_id_outputs_only_current_turn_items,test_streamed_previous_response_id_stores_full_agent_transcript_once