Repository navigation
Conversation
rewriteJSONModel decoded the whole request into map[string]any to set "model" and re-encoded it, which sorted the keys of every object. Tool schemas reached the engine with their properties in alphabetical order, so the chat template rendered a different prompt than the client sent. Decode only the top level into map[string]json.RawMessage: nested values are forwarded as sent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013aCoWcBiA8g3FWfhBQBqKT
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.
What changes
To set
model,rewriteJSONModeldecoded the request body intomap[string]anyand re-encoded it. Go encodes map keys in sorted order, so every object in the request reached the engine with its keys in alphabetical order, including thepropertiesof each tool schema.This PR decodes only the top level, into
map[string]json.RawMessage:modelis replaced as before;Why it matters
Chat templates render tool parameters in the order their keys arrive, so the engine saw a different prompt from the one the client sent. Small models are sensitive to that.
LiquidAI LFM3 1.7B (Q8_0, llama.cpp b12352, thinking off) was asked for an edit whose arguments quote
<parameter=…>markup, with the same request 8 times per row:json.dumps(sort_keys=True))}appended tonew_string}appended tonew_stringCompatibility
modelvalue.encoding/jsondoes forRawMessage.Verification
TestRewriteJSONModel_KeepsNestedKeyOrderis new. It fails onmain("tool properties reordered") and passes with this change.gofmt -l internal/is clean.go vet ./...passes.go test -race ./internal/...passes, 27 packages, on Go 1.26.11.🤖 Generated with Claude Code
https://claude.ai/code/session_013aCoWcBiA8g3FWfhBQBqKT