Fix type assertion bug in handleClusterMessage
All checks were successful
CI / build (pull_request) Successful in 16s

JSON unmarshal produces map[string]interface{}, not concrete types.
Added ModelPayload and MessagePayload concrete types that implement
RuntimeModel and RuntimeMessage interfaces respectively.

The handleClusterMessage now re-marshals and unmarshals the payload
to convert from map[string]interface{} to the proper concrete type.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-10 16:41:40 +01:00
parent 8c02b63dc7
commit a33ef47a39
2 changed files with 44 additions and 7 deletions

View File

@@ -177,18 +177,29 @@ func (dvm *DistributedVM) handleClusterMessage(msg *nats.Msg) {
switch clusterMsg.Type {
case "load_model":
// Handle model loading from other nodes
// Note: Payload comes as interface{} from JSON, need type assertion
// In practice, this would deserialize to the proper model type
if model, ok := clusterMsg.Payload.(RuntimeModel); ok {
dvm.localRuntime.LoadModel(model)
// Re-marshal and unmarshal to convert map[string]interface{} to concrete type
payloadBytes, err := json.Marshal(clusterMsg.Payload)
if err != nil {
return
}
var model ModelPayload
if err := json.Unmarshal(payloadBytes, &model); err != nil {
return
}
dvm.localRuntime.LoadModel(&model)
case "route_message":
// Handle message routing from other nodes
// Note: Similar type handling needed here
if message, ok := clusterMsg.Payload.(RuntimeMessage); ok {
dvm.localRuntime.SendMessage(message)
// Re-marshal and unmarshal to convert map[string]interface{} to concrete type
payloadBytes, err := json.Marshal(clusterMsg.Payload)
if err != nil {
return
}
var message MessagePayload
if err := json.Unmarshal(payloadBytes, &message); err != nil {
return
}
dvm.localRuntime.SendMessage(&message)
case "rebalance":
// Handle shard rebalancing requests