Skip to content

fix(sdk): coerce string board vars to numeric types before JSON config parsing#12

Merged
lIang70 merged 1 commit into
mainfrom
fix/coerce-string-board-vars-for-config-parsing
Apr 16, 2026
Merged

fix(sdk): coerce string board vars to numeric types before JSON config parsing#12
lIang70 merged 1 commit into
mainfrom
fix/coerce-string-board-vars-for-config-parsing

Conversation

@lIang70

@lIang70 lIang70 commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • 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 (json.Marshaljson.Unmarshal) in ConfigFromMap / RoundConfigFromMap then fails because encoding/json cannot unmarshal a JSON string into *float64 or int64.
  • Add CoerceMapForStruct[T], a generic reflection-based helper that reads T'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 downstream json.Unmarshal correctly surfaces the error.
  • Applied to all three JSON round-trip call sites: llm.RoundConfigFromMap, node.ConfigFromMap, and bindings.mergeRoundConfig.

Test plan

  • CoerceMapForStruct unit 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 passthrough
  • RoundConfigFromMap: string temperature/max_tokens/json_mode parsed correctly, unresolved ref returns error, input map not mutated
  • node.ConfigFromMap: same string coercion coverage + unresolved ref error
  • mergeRoundConfig: string overrides from script layer merged correctly
  • Full go test ./... passes (sdk + internal)

Made with Cursor

…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
@lIang70
lIang70 merged commit 3990511 into main Apr 16, 2026
8 checks passed
@lIang70
lIang70 deleted the fix/coerce-string-board-vars-for-config-parsing branch April 16, 2026 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant