Skip to content

[Bugfix] Fix Responses API instructions leaking through previous_response_id#37727

Open
he-yufeng wants to merge 1 commit intovllm-project:mainfrom
he-yufeng:fix/responses-api-instructions-leak
Open

[Bugfix] Fix Responses API instructions leaking through previous_response_id#37727
he-yufeng wants to merge 1 commit intovllm-project:mainfrom
he-yufeng:fix/responses-api-instructions-leak

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

Fixes #37697

What's the problem

When using /v1/responses with previous_response_id, the instructions from the prior response carry over into the new response. Per the OpenAI spec, instructions should NOT carry over:

"When using along with previous_response_id, the instructions from a previous response will not be carried over to the next response."

Root cause

construct_input_messages() in responses/utils.py prepends request_instructions as a system message, then the full messages list (including that system message) gets stored in msg_store. When the next request references previous_response_id, those stored messages — old system message included — are retrieved and extended into the new conversation. The new request also adds its own instructions, so you end up with both old and new system messages.

Fix

Filter out system messages when pulling prev_msg from the store in construct_input_messages(). One-line change: messages.extend(prev_msg) becomes messages.extend(m for m in prev_msg if m.get("role") != "system").

This ensures each request only uses its own instructions, regardless of what the previous response had. Works correctly for all cases: new instructions provided, no instructions provided, or no previous response at all.

Test plan

  • Added 4 unit tests in tests/entrypoints/openai/responses/test_responses_utils.py covering:
    • Old system message stripped when new instructions provided
    • Old system message stripped when no instructions provided
    • Non-system messages (user/assistant) preserved correctly
    • Baseline: no previous messages works as before

…onse_id

Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a bug where instructions from a previous response would leak into a new response when using previous_response_id. The change in vllm/entrypoints/openai/responses/utils.py correctly filters out system messages from the previous message history, aligning with the specification that instructions should not be carried over. New unit tests have been added in tests/entrypoints/openai/responses/test_responses_utils.py to validate the fix across various scenarios. The changes appear correct and are appropriately tested.

@mergify mergify bot added frontend bug Something isn't working labels Mar 21, 2026
# Add the previous messages.
messages.extend(prev_msg)
# Filter out system messages from previous conversation -- per the
# OpenAI spec, instructions should NOT carry over across responses.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Is there any related OpenAI spec documentation for this? Could you share the link?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! From the OpenAI API Reference — Create Response, the instructions parameter description states:

When used along with previous_response_id, the instructions from a previous response will not be carried over to the next response. This makes it simple to swap out system (or developer) messages in new responses.

The Text Generation guide also reinforces this — the instructions parameter only applies to the current response, and instructions from previous turns will not be present in the context when using previous_response_id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working frontend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: openai v1/responses api instructions from prior response leak through previous_response_id

2 participants