Repository navigation
fix(model): preserve thought signatures across JSON persistence round-trips - #2910
Merged
jujn merged 8 commits intoSep 12, 2026
Merged
Conversation
chaucerj
force-pushed
the
fix/thought-signature-persistence
branch
2 times, most recently
from
August 30, 2026 13:28
9daeaf3 to
548dfc1
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…-trips Gemini 3 requires thought signatures to be replayed with function calls. They are stored as byte[] in ToolUseBlock metadata, but a JSON persistence round-trip (session save/load) restores them as a Base64 String, so the converters' instanceof checks silently dropped them and the next request failed with 400 INVALID_ARGUMENT from the server. - GeminiMessageConverter: decode Base64 String signatures back to byte[] - OpenAIMessageConverter: normalize byte[] signatures to Base64 String (covers the in-memory cross-provider path) and restore reasoning detail metadata that comes back from persistence as a LinkedHashMap Verified against the live gemini-3-flash-preview API: replaying a function call without its signature returns 400 "Function call is missing a thought_signature in functionCall parts"; replaying it with the signature returns 200. Co-Authored-By: Claude Code <[email protected]>
chaucerj
force-pushed
the
fix/thought-signature-persistence
branch
from
August 30, 2026 13:53
548dfc1 to
442b02a
Compare
HarnessAgentDynamicHookBuilderTest failed once in agentscope-harness (own surefire JVM, unrelated to this change; another PR hit the same 1-error-in-844 flake on a different harness test the same day). No code change. Co-Authored-By: Claude Code <[email protected]>
Adds a no-metadata ToolUseBlock case to both converter test classes, exercising the null-metadata guards left as partial branches by the previous coverage pass. Patch coverage is now 100% of changed lines. Co-Authored-By: Claude Code <[email protected]>
ToolUseBlock normalizes null metadata to an empty map, so the null-side of the metadata guards is unreachable and cannot be covered. The actual partial branches were: - GeminiMessageConverter: a signature value that is neither byte[] nor String (now covered by a non-string signature test) - OpenAIMessageConverter: a ThinkingBlock details list whose entries cannot be restored (now covered), and a dead !candidate.isEmpty() check in the fallback-signature scan - toSignatureString never returns an empty string, so the check is dropped. Co-Authored-By: Claude Code <[email protected]>
…-persistence Sync with latest main (f96cdc7), including the openai-java 4.52.0 bump. No code changes; merge was conflict-free. Co-Authored-By: Claude Code <[email protected]>
…-persistence Sync with main (b436110): picks up the rag-simple apiKey ambiguity fix (agentscope-ai#2912) so CI can go green again. No code changes of our own. Co-Authored-By: Claude Code <[email protected]>
oss-maintainer
approved these changes
Sep 3, 2026
oss-maintainer
left a comment
Collaborator
There was a problem hiding this comment.
LGTM. fix(model): preserve thought signatures across JSON persistence round-trips — change looks correct and clean.
Automated review by github-manager-bot
This was referenced Sep 13, 2026
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.
Fixes #2909
Problem
Gemini 3 requires
thought_signatureto be replayed with eachfunctionCall. The parsers store signatures asbyte[](and reasoning details as typedOpenAIReasoningDetail) in block metadata, but any JSON persistence round-trip (agent session save/load throughJsonUtils/Jackson) restores them as a Base64String/LinkedHashMap. The converters'instanceofchecks silently dropped the values, so the next request went out without signatures and the API rejected it:Fix
GeminiMessageConverter— besidesbyte[], accept a non-empty Base64Stringsignature and decode it back tobyte[]; non-Base64 values are skipped with a warning instead of failing.OpenAIMessageConverter— extract two small normalizers:toSignatureString: accepts both the Base64Stringform and the in-memorybyte[]form (the latter also fixes the cross-provider path where a Gemini/OpenRouter parser producedbyte[]and the OpenAI converter dropped it entirely).toReasoningDetail: accepts the typedOpenAIReasoningDetailand theLinkedHashMapform restored from persistence, converting back viaJsonUtils.Tests
New
@Tag("unit")test classes:GeminiThoughtSignaturePersistenceTest— byte[] attached directly; signature restored afterJsonUtilstoJson/fromJson round-trip (asserts equal bytes); non-Base64 string ignored.OpenAIThoughtSignatureTest— byte[] signature converted to Base64; tool signature +reasoningDetailkept after round-trip;ThinkingBlockreasoning details kept after round-trip.6/6 new tests pass; the existing
GeminiMessageConverterTest+OpenAIMessageConverterTestsuites (83 tests) still pass against the patched classes.Verification
Reproduced end-to-end against the live
gemini-3-flash-previewAPI with two second-turn payloads identical except for the signature:thoughtSignature: HTTP400— "Function call is missing a thought_signature in functionCall parts..."thoughtSignature: HTTP200, normal answer.Before this fix, the round-tripped state produced exactly the first (400) payload.