fix: preserve ThinkingPart fields in OpenCode storage round-trip (#156) - #417
Closed
Million-mo wants to merge 1 commit into
Closed
fix: preserve ThinkingPart fields in OpenCode storage round-trip (#156)#417Million-mo wants to merge 1 commit into
Million-mo wants to merge 1 commit into
Conversation
ThinkingPart.id, provider_name, signature, and provider_details were silently dropped during OpenCode storage serialization. The write path (provider.py) only saved content as ReasoningPart.text, and the read path (helpers.py) only restored content — all other fields defaulted to None. This caused send-back to degrade to tags mode: pydantic-ai's _map_response_thinking_part() checks id + provider_name to decide between field mode (reasoning_content) and tags mode. Without these fields, thinking content was wrapped in <think> tags instead of sent via the proper reasoning_content field. Fix: store the extra fields in ReasoningPart.metadata during write, and restore them when constructing ThinkingPart during read. The metadata field already exists on ReasoningPart and is a dict[str, Any], making it a natural extensibility bucket without model changes. Backward compatible: old data without metadata produces ThinkingPart with None defaults, same as before.
Owner
Author
|
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.
Summary
Fixes #156
ThinkingPart.id, provider_name, signature, and provider_details were silently dropped during OpenCode storage serialization. The write path only saved content as ReasoningPart.text, and the read path only restored content — all other fields defaulted to None.
This caused send-back to degrade to tags mode: pydantic-ai checks id + provider_name to decide between field mode (reasoning_content) and tags mode. Without these fields, thinking content was wrapped in tags instead of sent via the proper reasoning_content field.
Fix
Store the extra fields in ReasoningPart.metadata during write, and restore them when constructing ThinkingPart during read. The metadata field already exists on ReasoningPart and is a dict[str, Any], making it a natural extensibility bucket without model changes.
Changes
Backward Compatibility
Old data without metadata produces ThinkingPart with None defaults — same behavior as before this fix.
Test Plan
Relationship to #155 and #174
Three independent fixes, no overlap.