Repository navigation
studio: keep a resumed turn's provider metadata through the continuation merge - #9684
Merged
danielhanchen merged 2 commits intoAug 26, 2026
Merged
Conversation
append_assistant_turn merges a continuation into the trailing partial rather than appending, so role alternation survives. It did that by assigning the new message into the slot, which drops every key the partial carried and the continuation does not repeat. extra_content is exactly such a key. It is the namespaced envelope a translator reads back: google for Gemini's thought signatures and native parts, plus anthropic and openai_codex_reasoning. Gemini pins the text part's signature back on from that field alone, so a resumed turn replayed without it is rejected rather than merely degraded. Merge over the existing message instead. A key the continuation does set still wins, so this cannot resurrect a stale value. The same line also mutated the caller's dict in place, so a caller that read the message back after the call saw text it never wrote. Six of the eight call sites are tool-result replay across the GGUF, safetensors and external loops, and the merge path itself is reached by the continuation feature from #8064, so this is not specific to any one of them.
This was referenced Aug 25, 2026
danielhanchen
added a commit
to shimmyshimmer/unsloth-staging-4
that referenced
this pull request
Aug 25, 2026
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Member
Author
|
Confirmed this on main, where chat_template_helpers.py still overwrites the last conversation entry so a resumed turn loses extra_content and the caller's dict gets mutated. Will get this reviewed. |
danielhanchen
deleted the
fix/continuation-merge-drops-provider-extra-content
branch
August 26, 2026 05:58
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.
The bug
append_assistant_turn(studio/backend/core/inference/chat_template_helpers.py) merges a continuation into the trailing partial rather than appending, so that role alternation survives. It did that by assigning the new message into the slot:That replaces the resumed turn, so every key the partial carried and the continuation does not repeat is dropped.
extra_contentis exactly such a key. It is the namespaced envelope a translator reads back on the way out, and there are three namespaces in the tree today:google(15 sites, Gemini thought signatures and native parts),anthropic(11 sites) andopenai_codex_reasoning. The field's own schema inmodels/inference.pydescribes it as "provider-specific extra fields the translator may read".For Gemini the consequence is hard rather than cosmetic.
studio_tool_loop.pysays it plainly:Observed on
main:The signature is gone, and the second line is a separate defect: the same statement mutates the dict the caller passed in, so a caller that reads it back afterwards sees text it never wrote.
The fix
Merge over the existing message instead of replacing it.
After:
Namespace agnostic on purpose. Special casing
extra_content["google"]would have leftanthropicandopenai_codex_reasoningbroken and set the same trap for the next provider that adds one.Scope
This is not specific to any one loop. Six of the eight
append_assistant_turncall sites are tool-result replay across the GGUF, safetensors and external loops, and the merge path itself is reached by the continue-a-partial-response feature from #8064, which is independent of tool calling entirely.Tests
Three added to
tests/test_chat_template_continuation.py:test_a_resumed_partial_keeps_the_metadata_the_continuation_does_not_repeat- fails on maintest_a_merge_leaves_the_callers_message_alone- fails on maintest_a_continuation_still_wins_on_a_key_it_does_repeat- passes on both, guarding the fix against over-correcting into resurrecting a stale valueVerified both directions:
Found while looking at #9125, but it is independent of that PR and of tool-call nudging, so it is split out to land on its own.