From 3dd73dce03e275d3563f0e94dbeb69bb30087973 Mon Sep 17 00:00:00 2001 From: OoO Date: Tue, 28 Apr 2026 12:13:44 +0800 Subject: [PATCH] fix: missing sqlalchemy text import and _ssh_exec in ElephantAlpha --- services/elephant_alpha_autonomous_engine.py | 28 +++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/services/elephant_alpha_autonomous_engine.py b/services/elephant_alpha_autonomous_engine.py index 846ce80..0e81e6e 100644 --- a/services/elephant_alpha_autonomous_engine.py +++ b/services/elephant_alpha_autonomous_engine.py @@ -26,6 +26,7 @@ from datetime import datetime, timedelta from enum import Enum from typing import Dict, List, Any, Optional +from sqlalchemy import text from services.logger_manager import SystemLogger from services.elephant_alpha_orchestrator import elephant_orchestrator, StrategicDecision from database.manager import get_session @@ -662,7 +663,32 @@ class ElephantAlphaAutonomousEngine: except Exception as e: self._log.error("Telegram escalation failed (non-blocking): %s", e) - # ---- Helpers ---- + # ---- Resource Optimization ---- + def _ssh_exec(self, cmd: str, timeout: int = 60) -> tuple: + """Execute command via SSH jump host.""" + import subprocess + import shlex + + full_cmd = [ + "ssh", + "-p", str(SSH_PORT), + "-i", SSH_KEY_PATH, + "-o", "StrictHostKeyChecking=no", + "-o", "ConnectTimeout=10", + f"{SSH_JUMP_USER}@{SSH_JUMP_HOST}", + cmd + ] + try: + res = subprocess.run( + full_cmd, + capture_output=True, + text=True, + timeout=timeout + ) + return res.returncode, res.stdout, res.stderr + except Exception as e: + return -1, "", str(e) + def _is_circuit_open(self) -> bool: cb = self._circuit_breaker_state if cb["failures"] >= self._cb_threshold: