fix(sdk): coerce string board vars to numeric types before JSON config parsing#12
Merged
Merged
Conversation
…g parsing
Board template variables like ${board.temperature} can resolve to Go
strings (e.g. "0.5") when the board var is stored as a string or goes
through the Resolve string-interpolation path. The JSON round-trip in
ConfigFromMap / RoundConfigFromMap then fails because encoding/json
cannot unmarshal a JSON string into *float64 or int64.
Add CoerceMapForStruct[T], a generic helper that uses reflection on
T's json tags to convert parseable string values to the target field
types (float64, int64, bool, etc.) before marshaling. Unparseable
strings (e.g. unresolved "${board.missing}" refs) are left untouched
so the downstream json.Unmarshal correctly surfaces the error.
Applied to all three JSON round-trip sites:
- llm.RoundConfigFromMap
- node.ConfigFromMap (LLMConfig)
- bindings.mergeRoundConfig
Made-with: Cursor
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
${board.temperature}can resolve to Go strings (e.g."0.5") when the board var is stored as a string or goes through theResolvestring-interpolation path. The JSON round-trip (json.Marshal→json.Unmarshal) inConfigFromMap/RoundConfigFromMapthen fails becauseencoding/jsoncannot unmarshal a JSON string into*float64orint64.CoerceMapForStruct[T], a generic reflection-based helper that readsT's json tags to convert parseable string values to the expected field types (float64,int64,bool, etc.) before marshaling. Unparseable strings (e.g. unresolved${board.missing}refs) are left untouched so downstreamjson.Unmarshalcorrectly surfaces the error.llm.RoundConfigFromMap,node.ConfigFromMap, andbindings.mergeRoundConfig.Test plan
CoerceMapForStructunit tests: nil input, string→float/int/uint/bool, pointer fields, non-string passthrough, invalid/empty strings kept, string fields untouched, input map immutability, extra keys passthroughRoundConfigFromMap: string temperature/max_tokens/json_mode parsed correctly, unresolved ref returns error, input map not mutatednode.ConfigFromMap: same string coercion coverage + unresolved ref errormergeRoundConfig: string overrides from script layer merged correctlygo test ./...passes (sdk + internal)Made with Cursor