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 eaff315782
commit b759c7fb97
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

View File

@@ -177,3 +177,29 @@ type RuntimeMessage interface {
// GetType returns the message type identifier
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 }