Keep `openai_previous_response_id` chaining when a rewrite-mode instruction changes beside an `on_change='append'` block

Merged
DO
1mo ago
+167-22

With openai_previous_response_id, OpenAIResponsesModel stopped chaining when a rewrite-mode instruction block changed during a run that also had an on_change='append' block. The change opens a new instruction window, and prepare_messages renders the append-mode framing into ModelRequest.instructions only for requests in the current window. So the earlier requests' instructions were framed when their response's digest was recorded, and unframed when it was checked on the next request. The check saw a changed history, and every later request in the run was sent without previous_response_id.

A request's instructions aren't part of what the server holds: with previous_response_id, the instructions of an earlier response aren't carried over, and each request sends its own. So the digest now leaves them out, the same way it leaves out the application-only metadata fields. A digest recorded before this change, which covers them, is still accepted, so a stored conversation keeps its chain across the upgrade.

The issue also asks for a way to observe or override a chain boundary; that is left for a separate discussion.

Tests:

  • test_openai_previous_response_id_keeps_chaining_when_a_rewritten_block_changes_beside_an_append_block: the issue's reproduction, with an append-mode block and a rewrite-mode block that changes after each tool call. It sends None for the second and third requests without the fix.
  • test_openai_previous_response_id_continues_from_a_digest_that_covers_instructions: a response whose digest was recorded the old way, over a request with instructions, is still continued. It fails without the legacy comparison.

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
  • PR title is fit for the release changelog.

šŸ¤– Generated with Claude Code