json.Unmarshal into result fails on any type mismatch anywhere in the object. If a future release emits "input_tokens": 1234.0, or turns session_id into an object, a run that completed normally is reported as StopFailed/StopUnknown.
That fails safe — ERROR, never FAIL — and it fails much harder than it needs to: every field is lost because one moved. Decoding fields independently once type == "result" is confirmed would degrade instead of collapsing, keeping the cost and the session identifier from a result whose token counts changed shape.
json.Unmarshalintoresultfails on any type mismatch anywhere in the object. If a future release emits"input_tokens": 1234.0, or turnssession_idinto an object, a run that completed normally is reported asStopFailed/StopUnknown.That fails safe — ERROR, never FAIL — and it fails much harder than it needs to: every field is lost because one moved. Decoding fields independently once
type == "result"is confirmed would degrade instead of collapsing, keeping the cost and the session identifier from a result whose token counts changed shape.