Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ reports/

# Typescript
.env

# Pipeline artifacts and worktrees
.artifacts/
.worktrees/
Binary file removed control-plane/.DS_Store
Binary file not shown.
Binary file removed control-plane/internal/.DS_Store
Binary file not shown.
36 changes: 18 additions & 18 deletions control-plane/internal/handlers/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,43 +61,43 @@ type ErrorResponse struct {
func SetMemoryHandler(storageProvider MemoryStorage) gin.HandlerFunc {
return func(c *gin.Context) {
ctx := c.Request.Context()
logger.Logger.Debug().Msg("🔍 MEMORY_HANDLER_DEBUG: SetMemoryHandler called")
logger.Logger.Debug().Str("operation", "set_memory").Str("handler", "SetMemoryHandler").Msg("handler invoked")

var req SetMemoryRequest
if err := c.ShouldBindJSON(&req); err != nil {
logger.Logger.Debug().Err(err).Msg("🔍 MEMORY_HANDLER_DEBUG: JSON binding failed")
logger.Logger.Debug().Err(err).Str("operation", "bind_request").Msg("failed to bind JSON request")
c.JSON(http.StatusBadRequest, ErrorResponse{
Error: "invalid_request",
Message: err.Error(),
Code: http.StatusBadRequest,
})
return
}
logger.Logger.Debug().Msgf("🔍 MEMORY_HANDLER_DEBUG: Request parsed successfully: key=%s", req.Key)
logger.Logger.Debug().Str("operation", "parse_request").Str("key", req.Key).Msg("request parsed")

scope, scopeID := resolveScope(c, req.Scope)
logger.Logger.Debug().Msgf("🔍 MEMORY_HANDLER_DEBUG: Scope resolved: scope=%s, scopeID=%s", scope, scopeID)
logger.Logger.Debug().Str("operation", "resolve_scope").Str("scope", scope).Str("scope_id", scopeID).Msg("scope resolved")

// Get existing memory value for event publishing
logger.Logger.Debug().Msg("🔍 MEMORY_HANDLER_DEBUG: Getting existing memory value...")
logger.Logger.Debug().Str("operation", "get_existing").Str("key", req.Key).Msg("retrieving existing memory value")
var previousData json.RawMessage
if existingMemory, err := storageProvider.GetMemory(ctx, scope, scopeID, req.Key); err == nil {
previousData = existingMemory.Data
}
logger.Logger.Debug().Msg("🔍 MEMORY_HANDLER_DEBUG: Existing memory check completed")
logger.Logger.Debug().Str("operation", "get_existing").Bool("exists", previousData != nil).Msg("existing memory check completed")

logger.Logger.Debug().Msg("🔍 MEMORY_HANDLER_DEBUG: Marshaling data to JSON...")
logger.Logger.Debug().Str("operation", "marshal_data").Str("key", req.Key).Msg("marshaling data to JSON")
dataJSON, err := marshalDataWithLogging(req.Data, "memory_data")
if err != nil {
logger.Logger.Error().Err(err).Msg("❌ MEMORY_MARSHAL_ERROR: Failed to marshal memory data")
logger.Logger.Error().Err(err).Str("operation", "marshal").Str("key", req.Key).Msg("failed to marshal memory data")
c.JSON(http.StatusBadRequest, ErrorResponse{
Error: "marshal_error",
Message: err.Error(),
Code: http.StatusBadRequest,
})
return
}
logger.Logger.Debug().Msgf("🔍 MEMORY_HANDLER_DEBUG: JSON marshaling successful, length: %d", len(dataJSON))
logger.Logger.Debug().Str("operation", "marshal_data").Int("size_bytes", len(dataJSON)).Msg("data marshaled successfully")

now := time.Now()
memory := &types.Memory{
Expand All @@ -108,22 +108,22 @@ func SetMemoryHandler(storageProvider MemoryStorage) gin.HandlerFunc {
CreatedAt: now,
UpdatedAt: now,
}
logger.Logger.Debug().Msg("🔍 MEMORY_HANDLER_DEBUG: Memory object created")
logger.Logger.Debug().Str("operation", "create_memory_object").Str("key", req.Key).Msg("memory object created")

logger.Logger.Debug().Msg("🔍 MEMORY_HANDLER_DEBUG: Calling storageProvider.SetMemory...")
logger.Logger.Debug().Str("operation", "store_memory").Str("key", req.Key).Msg("storing memory to backend")
if err := storageProvider.SetMemory(ctx, memory); err != nil {
logger.Logger.Debug().Err(err).Msg("🔍 MEMORY_HANDLER_DEBUG: SetMemory failed")
logger.Logger.Debug().Err(err).Str("operation", "store_memory").Str("key", req.Key).Msg("failed to store memory")
c.JSON(http.StatusInternalServerError, ErrorResponse{
Error: "storage_error",
Message: err.Error(),
Code: http.StatusInternalServerError,
})
return
}
logger.Logger.Debug().Msg("🔍 MEMORY_HANDLER_DEBUG: SetMemory completed successfully")
logger.Logger.Debug().Str("operation", "store_memory").Str("key", req.Key).Msg("memory stored successfully")

// Publish memory change event
logger.Logger.Debug().Msg("🔍 MEMORY_HANDLER_DEBUG: Creating memory change event...")
logger.Logger.Debug().Str("operation", "create_event").Str("action", "set").Str("key", req.Key).Msg("creating memory change event")
event := &types.MemoryChangeEvent{
Type: "memory_change",
Scope: scope,
Expand All @@ -140,18 +140,18 @@ func SetMemoryHandler(storageProvider MemoryStorage) gin.HandlerFunc {
}

// Store event (don't fail the request if event storage fails)
logger.Logger.Debug().Msg("🔍 MEMORY_HANDLER_DEBUG: Storing event...")
logger.Logger.Debug().Str("operation", "store_event").Str("key", req.Key).Msg("storing memory change event")
if err := storageProvider.StoreEvent(ctx, event); err != nil {
// Log error but continue
logger.Logger.Warn().Err(err).Msg("Warning: Failed to store memory change event")
} else if err := storageProvider.PublishMemoryChange(ctx, *event); err != nil {
logger.Logger.Warn().Err(err).Msg("Warning: Failed to publish memory change event")
}
logger.Logger.Debug().Msg("🔍 MEMORY_HANDLER_DEBUG: Event storage completed")
logger.Logger.Debug().Str("operation", "store_event").Str("key", req.Key).Msg("event storage completed")

logger.Logger.Debug().Msg("🔍 MEMORY_HANDLER_DEBUG: Sending response...")
logger.Logger.Debug().Str("operation", "send_response").Str("key", req.Key).Msg("sending response")
c.JSON(http.StatusOK, memory)
logger.Logger.Debug().Msg("🔍 MEMORY_HANDLER_DEBUG: Response sent successfully")
logger.Logger.Debug().Str("operation", "send_response").Str("key", req.Key).Msg("response sent")
}
}

Expand Down
8 changes: 4 additions & 4 deletions control-plane/internal/handlers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import (
// marshalDataWithLogging marshals data to JSON with proper error handling and logging
func marshalDataWithLogging(data interface{}, fieldName string) ([]byte, error) {
if data == nil {
logger.Logger.Debug().Msgf("🔍 MARSHAL_DEBUG: %s is nil, returning null", fieldName)
logger.Logger.Debug().Str("operation", "marshal").Str("field_name", fieldName).Bool("is_nil", true).Msg("field is nil")
return []byte("null"), nil
}

// Log the type and content of data being marshaled
logger.Logger.Debug().Msgf("🔍 MARSHAL_DEBUG: Marshaling %s (type: %T)", fieldName, data)
logger.Logger.Debug().Str("operation", "marshal").Str("field_name", fieldName).Str("type", fmt.Sprintf("%T", data)).Msg("marshaling field")

// Attempt to marshal with detailed error reporting
jsonData, err := json.Marshal(data)
if err != nil {
logger.Logger.Error().Err(err).Msgf("❌ MARSHAL_ERROR: Failed to marshal %s (type: %T): %v", fieldName, data, data)
logger.Logger.Error().Err(err).Str("operation", "marshal").Str("field_name", fieldName).Str("type", fmt.Sprintf("%T", data)).Msg("failed to marshal field")
return nil, fmt.Errorf("failed to marshal %s: %w", fieldName, err)
}

logger.Logger.Debug().Msgf("✅ MARSHAL_SUCCESS: Successfully marshaled %s (%d bytes): %s", fieldName, len(jsonData), string(jsonData))
logger.Logger.Debug().Str("operation", "marshal").Str("field_name", fieldName).Int("size_bytes", len(jsonData)).Msg("field marshaled successfully")
return jsonData, nil
}
Binary file removed control-plane/internal/storage/.DS_Store
Binary file not shown.
Binary file removed control-plane/web/.DS_Store
Binary file not shown.
Loading