Spaces:
Sleeping
Sleeping
Claude Code Claude Opus 4.6 commited on
Commit ·
a86d37e
1
Parent(s): 1967ae7
Claude Code: Fix health_monitor.py status file path resolution
Browse files- Add _find_status_file() function with multi-strategy lookup
- Matches error_handlers.py dynamic path resolution approach
- Fixes 'UNKNOWN' error when health_monitor can't find cain_status.json
- Supports both local workspace and Docker container environments
- Adds CAIN_STATUS_FILE environment variable override support
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
openclaw/.openclaw/health_monitor.py
CHANGED
|
@@ -775,14 +775,41 @@ def reset_health_monitor():
|
|
| 775 |
_global_monitor = None
|
| 776 |
|
| 777 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 778 |
def read_current_stage() -> str:
|
| 779 |
"""
|
| 780 |
Read Cain's current stage from cain_status.json.
|
| 781 |
Returns a simple status string.
|
| 782 |
"""
|
| 783 |
try:
|
| 784 |
-
|
| 785 |
-
status_file = Path(__file__).parent / "agents" / "cain_status.json"
|
| 786 |
with open(status_file) as f:
|
| 787 |
data = json.load(f)
|
| 788 |
return data.get('stage', data.get('current_state', 'UNKNOWN'))
|
|
|
|
| 775 |
_global_monitor = None
|
| 776 |
|
| 777 |
|
| 778 |
+
def _find_status_file() -> Path:
|
| 779 |
+
"""Dynamically locate cain_status.json using multiple fallback strategies."""
|
| 780 |
+
# Strategy 1: Use environment variable if set (highest priority)
|
| 781 |
+
env_path = os.environ.get("CAIN_STATUS_FILE")
|
| 782 |
+
if env_path:
|
| 783 |
+
return Path(env_path)
|
| 784 |
+
|
| 785 |
+
# Strategy 2: Relative to health_monitor.py (in .openclaw/ directory)
|
| 786 |
+
# In workspace: openclaw/.openclaw/health_monitor.py -> openclaw/.openclaw/agents/
|
| 787 |
+
# In Docker: /app/openclaw/.openclaw/health_monitor.py -> /app/openclaw/.openclaw/agents/
|
| 788 |
+
base_dir = Path(__file__).parent.resolve()
|
| 789 |
+
relative_path = base_dir / "agents" / "cain_status.json"
|
| 790 |
+
if relative_path.exists():
|
| 791 |
+
return relative_path
|
| 792 |
+
|
| 793 |
+
# Strategy 3: From /app root (Docker) or workspace root (local)
|
| 794 |
+
# Handles cases where health_monitor.py might be imported from different locations
|
| 795 |
+
workspace_root = base_dir.parent.parent # Go up two levels from .openclaw/
|
| 796 |
+
if workspace_root.name == "openclaw":
|
| 797 |
+
workspace_root = workspace_root.parent # Go up one more level
|
| 798 |
+
root_path = workspace_root / "openclaw" / ".openclaw" / "agents" / "cain_status.json"
|
| 799 |
+
if root_path.exists():
|
| 800 |
+
return root_path
|
| 801 |
+
|
| 802 |
+
# Strategy 4: Fall back to the expected path (may not exist, but that's OK)
|
| 803 |
+
return relative_path
|
| 804 |
+
|
| 805 |
+
|
| 806 |
def read_current_stage() -> str:
|
| 807 |
"""
|
| 808 |
Read Cain's current stage from cain_status.json.
|
| 809 |
Returns a simple status string.
|
| 810 |
"""
|
| 811 |
try:
|
| 812 |
+
status_file = _find_status_file()
|
|
|
|
| 813 |
with open(status_file) as f:
|
| 814 |
data = json.load(f)
|
| 815 |
return data.get('stage', data.get('current_state', 'UNKNOWN'))
|