From ecbaebf451ce366939cda8159a71939e57e02cfc Mon Sep 17 00:00:00 2001 From: taylanbakircioglu Date: Mon, 26 Jan 2026 15:25:15 +0300 Subject: [PATCH] feat: report invalid config format errors to backend for UI display When config content doesn't look like valid HAProxy config (missing global/defaults/frontend/backend/listen keywords), agent now reports this to backend via config-validation-failed endpoint. This catches backend-side config generation errors (like Python exceptions) that prevented actual HAProxy config from being generated. Changes: - Add invalid config format detection and reporting in daemon mode - Use same curl pattern as existing HAProxy validation failure reporting - Same endpoint, headers, error handling, and spam prevention - Follows exact existing pattern for consistency - Does not affect self-upgrade flow (runs before upgrade check) Both linux and macos scripts updated identically. --- backend/utils/agent_scripts/linux_install.sh | 22 ++++++++++++++++++++ backend/utils/agent_scripts/macos_install.sh | 22 ++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/backend/utils/agent_scripts/linux_install.sh b/backend/utils/agent_scripts/linux_install.sh index c2f1396..45c3df9 100644 --- a/backend/utils/agent_scripts/linux_install.sh +++ b/backend/utils/agent_scripts/linux_install.sh @@ -2824,6 +2824,28 @@ CONFIG_RESPONSE_EOF log "ERROR" "DAEMON: Configuration content does not appear to be valid HAProxy config" log "DEBUG" "DAEMON: Config preview: ${daemon_config_content:0:200}..." config_is_valid=false + + # CRITICAL: Report this error to backend for UI display + # This catches backend-side config generation errors (Python exceptions, etc.) + config_error_preview="${daemon_config_content:0:500}" + if [[ -n "$config_version" && "$config_version" != "$last_validation_failed_version" ]]; then + log "INFO" "DAEMON: Reporting invalid config format to backend..." + curl -k -s -X POST "$MANAGEMENT_URL/api/agents/$AGENT_NAME/config-validation-failed" \ + -H "Content-Type: application/json" \ + -H "X-API-Key: $CURRENT_AGENT_TOKEN" \ + -d "{\"status\": \"invalid_config_format\", \"version\": \"$config_version\", \"validation_error\": $(echo "Configuration does not appear to be valid HAProxy config. Content preview: $config_error_preview" | jq -Rs .)}" \ + >/dev/null 2>&1 + + if [ $? -eq 0 ]; then + log "INFO" "DAEMON: Invalid config notification sent to backend" + else + log "WARN" "DAEMON: Failed to send invalid config notification to backend" + fi + + # Mark this version as validation failed to prevent repeated error logs + # (same pattern as existing HAProxy validation failure at line ~3022) + last_validation_failed_version="$config_version" + fi fi # Only process config if it's valid diff --git a/backend/utils/agent_scripts/macos_install.sh b/backend/utils/agent_scripts/macos_install.sh index cbffff8..db7d2b6 100644 --- a/backend/utils/agent_scripts/macos_install.sh +++ b/backend/utils/agent_scripts/macos_install.sh @@ -2772,6 +2772,28 @@ CONFIG_RESPONSE_EOF log "ERROR" "DAEMON: Configuration content does not appear to be valid HAProxy config" log "DEBUG" "DAEMON: Config preview: ${daemon_config_content:0:200}..." config_is_valid=false + + # CRITICAL: Report this error to backend for UI display + # This catches backend-side config generation errors (Python exceptions, etc.) + config_error_preview="${daemon_config_content:0:500}" + if [[ -n "$config_version" && "$config_version" != "$last_validation_failed_version" ]]; then + log "INFO" "DAEMON: Reporting invalid config format to backend..." + curl -k -s -X POST "$MANAGEMENT_URL/api/agents/$AGENT_NAME/config-validation-failed" \ + -H "Content-Type: application/json" \ + -H "X-API-Key: $CURRENT_AGENT_TOKEN" \ + -d "{\"status\": \"invalid_config_format\", \"version\": \"$config_version\", \"validation_error\": $(echo "Configuration does not appear to be valid HAProxy config. Content preview: $config_error_preview" | jq -Rs .)}" \ + >/dev/null 2>&1 + + if [ $? -eq 0 ]; then + log "INFO" "DAEMON: Invalid config notification sent to backend" + else + log "WARN" "DAEMON: Failed to send invalid config notification to backend" + fi + + # Mark this version as validation failed to prevent repeated error logs + # (same pattern as existing HAProxy validation failure at line ~2965) + last_validation_failed_version="$config_version" + fi fi # Only process config if it's valid