Skip to content

SWF(bug): stop instructions carrying over via previous_response_id - #60

Merged
maplepaladin73 merged 3 commits into
mainfrom
devin/1795378314-responses-instructions-carryover
Nov 22, 2026
Merged

maplepaladin73 merged 3 commits into
mainfrom
devin/1795378314-responses-instructions-carryover

Conversation

@maplepaladin73

@maplepaladin73 maplepaladin73 commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

On /v1/responses, a turn resumed with previous_response_id now uses only its own instructions: before, the previous turn's instructions were replayed too, so they stayed in effect and new ones were added as a second system message. OpenAI documents that instructions are not carried over.

Root cause: lower_responses_to_chat inserts instructions as a synthetic system message at position 0 of the lowered messages. Both the blocking (api/responses.rs) and streaming (api/responses_stream.rs) handlers then saved chat_req.messages as-is as the stored transcript. The next turn replayed that transcript, request-scoped instructions included.

Fix: both handlers save the transcript through one helper, response_input_transcript, which drops only that instructions message (placed after any conversation prefix). Explicit system messages in input or the conversation stay in the transcript.

Conversation appends: the blocking and streaming appenders worked out which items were new by skipping the stored conversation's item count. The replayed prefix (from_conversation_item) drops non-message items, so it can be shorter than that count. Once the instructions message no longer filled the gap, that skip would have dropped the new user message. Both appenders now skip conversation_prefix.len(), the length of the prefix that was actually replayed.

Test plan

New api/responses_instructions_tests.rs calls the real Responses handlers with store=true and the real ResponseStore / ConversationStore. Only the scheduler replies are stubbed. The tests cover blocking and streaming, with previous_response_id and with conversation. Turn A sets instructions "X". Turn B either replaces them with "Y" or sends none. Each test checks that A's stored transcript has no "X", that B's prompt to the model has "Y" exactly once (or no system message when B sends none), and that explicit conversation system messages are kept. Two more tests start from a conversation holding one item the replay drops; they check that the new user input is appended and the instructions are not.

Instructions tests fail before the fix (new tests run against the old responses.rs / responses_stream.rs):

test api::responses_instructions_tests::blocking_previous_instructions ... FAILED
test api::responses_instructions_tests::streaming_previous_instructions ... FAILED
test api::responses_instructions_tests::streaming_conversation_instructions ... FAILED
test api::responses_instructions_tests::blocking_conversation_instructions ... FAILED

stored A retained instructions X

test result: FAILED. 0 passed; 4 failed; 0 ignored; 0 measured; 3233 filtered out

Filtered-prefix tests fail before the append fix:

test api::responses_instructions_tests::blocking_filtered_conversation_prefix ... FAILED
test api::responses_instructions_tests::streaming_filtered_conversation_prefix ... FAILED

new user input missing from conversation append: []

All pass after both fixes:

test api::responses_instructions_tests::blocking_previous_instructions ... ok
test api::responses_instructions_tests::streaming_previous_instructions ... ok
test api::responses_instructions_tests::blocking_conversation_instructions ... ok
test api::responses_instructions_tests::streaming_conversation_instructions ... ok
test api::responses_instructions_tests::blocking_filtered_conversation_prefix ... ok
test api::responses_instructions_tests::streaming_filtered_conversation_prefix ... ok

Full spark bin suite: test result: ok. 3225 passed; 0 failed; 14 ignored.

Try it:

bash scripts/ci_gpu_stubs.sh && ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo test -p spark-server --bin spark responses_instructions_tests
  • cargo fmt --all -- --check
  • ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo clippy --workspace --tests (exit 0)
  • bash scripts/check-license-headers.sh (4264 valid, 0 invalid)
  • typos (clean)
  • Tested against a real model / hardware: not done, the GPU hosts are reserved
  • Added tests

Notes for reviewers

  • Untested: no live model or GPU run. Responses stored before this change still contain their old instructions message, so resuming from one replays it once. New turns are stored clean.
  • The handler finds the instructions message by its index, conversation_prefix.len(). That depends on lowering inserting instructions at position 0, which the comment in responses_lowering.rs now notes.

CLA


Software Factory opened this PR for Robert
Implemented in session Stop instructions carrying over via previous_response_id
Review with Devin · Open in Devin Desktop


maplepaladin73 and others added 2 commits November 22, 2026 20:17
…e_id

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Devin Review found 1 finding. Devin automatically fixed it.

Fixed by Devin (1)
  • Conversation appends silently lose user input — Valid: appenders skipped the stored item count, not the filtered replay prefix. Both paths now skip conversation_prefix.len(); blocking+streaming regression tests added.

View findings in Devin Review · Follow Devin's work

Devin Review

@maplepaladin73
maplepaladin73 merged commit 8712822 into main Nov 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant