Fix type assertion bug in handleClusterMessage
All checks were successful
CI / build (pull_request) Successful in 16s
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:
@@ -177,18 +177,29 @@ func (dvm *DistributedVM) handleClusterMessage(msg *nats.Msg) {
|
|||||||
switch clusterMsg.Type {
|
switch clusterMsg.Type {
|
||||||
case "load_model":
|
case "load_model":
|
||||||
// Handle model loading from other nodes
|
// Handle model loading from other nodes
|
||||||
// Note: Payload comes as interface{} from JSON, need type assertion
|
// Re-marshal and unmarshal to convert map[string]interface{} to concrete type
|
||||||
// In practice, this would deserialize to the proper model type
|
payloadBytes, err := json.Marshal(clusterMsg.Payload)
|
||||||
if model, ok := clusterMsg.Payload.(RuntimeModel); ok {
|
if err != nil {
|
||||||
dvm.localRuntime.LoadModel(model)
|
return
|
||||||
}
|
}
|
||||||
|
var model ModelPayload
|
||||||
|
if err := json.Unmarshal(payloadBytes, &model); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dvm.localRuntime.LoadModel(&model)
|
||||||
|
|
||||||
case "route_message":
|
case "route_message":
|
||||||
// Handle message routing from other nodes
|
// Handle message routing from other nodes
|
||||||
// Note: Similar type handling needed here
|
// Re-marshal and unmarshal to convert map[string]interface{} to concrete type
|
||||||
if message, ok := clusterMsg.Payload.(RuntimeMessage); ok {
|
payloadBytes, err := json.Marshal(clusterMsg.Payload)
|
||||||
dvm.localRuntime.SendMessage(message)
|
if err != nil {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
var message MessagePayload
|
||||||
|
if err := json.Unmarshal(payloadBytes, &message); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dvm.localRuntime.SendMessage(&message)
|
||||||
|
|
||||||
case "rebalance":
|
case "rebalance":
|
||||||
// Handle shard rebalancing requests
|
// Handle shard rebalancing requests
|
||||||
|
|||||||
@@ -147,3 +147,29 @@ type RuntimeMessage interface {
|
|||||||
// GetType returns the message type identifier
|
// GetType returns the message type identifier
|
||||||
GetType() string
|
GetType() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ModelPayload is a concrete type for JSON-unmarshaling RuntimeModel payloads.
|
||||||
|
// Use this when receiving model data over the network.
|
||||||
|
type ModelPayload struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetID implements RuntimeModel
|
||||||
|
func (m *ModelPayload) GetID() string { return m.ID }
|
||||||
|
|
||||||
|
// GetName implements RuntimeModel
|
||||||
|
func (m *ModelPayload) GetName() string { return m.Name }
|
||||||
|
|
||||||
|
// MessagePayload is a concrete type for JSON-unmarshaling RuntimeMessage payloads.
|
||||||
|
// Use this when receiving message data over the network.
|
||||||
|
type MessagePayload struct {
|
||||||
|
TargetActorID string `json:"targetActorId"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTargetActorID implements RuntimeMessage
|
||||||
|
func (m *MessagePayload) GetTargetActorID() string { return m.TargetActorID }
|
||||||
|
|
||||||
|
// GetType implements RuntimeMessage
|
||||||
|
func (m *MessagePayload) GetType() string { return m.Type }
|
||||||
|
|||||||
Reference in New Issue
Block a user