Spaces:
Sleeping
Sleeping
Claude Code Claude Opus 4.6 commited on
Commit ·
9b83d7e
1
Parent(s): d808b0d
Claude Code: Fix Cain - resolve NameError in read_current_stage()
Browse filesThe read_current_stage() function in health_monitor.py was referencing
the 'stage' variable before it was defined, causing a NameError.
Fixed by moving stage assignment before the health field check.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
openclaw/.openclaw/health_monitor.py
CHANGED
|
@@ -941,6 +941,10 @@ def read_current_stage() -> str:
|
|
| 941 |
with open(status_file) as f:
|
| 942 |
data = json.load(f)
|
| 943 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 944 |
# CRITICAL: Check 'health' field first (authoritative source added in recent fix)
|
| 945 |
# If health field is present and is "ERROR", treat as error regardless of error field
|
| 946 |
# This prevents the "Error: unknown" display issue where error=null but health=ERROR
|
|
@@ -958,7 +962,6 @@ def read_current_stage() -> str:
|
|
| 958 |
|
| 959 |
# Fallback: Check for error field (legacy behavior)
|
| 960 |
error = data.get('error')
|
| 961 |
-
stage = data.get('stage', data.get('current_state', 'UNKNOWN'))
|
| 962 |
|
| 963 |
# CRITICAL: Treat null, None, empty string, or "unknown" string as HEALTHY
|
| 964 |
# Only append _ERROR if there's an actual error message (non-empty, not "unknown")
|
|
|
|
| 941 |
with open(status_file) as f:
|
| 942 |
data = json.load(f)
|
| 943 |
|
| 944 |
+
# CRITICAL FIX: Get stage FIRST before checking health field
|
| 945 |
+
# This fixes NameError where 'stage' was referenced before assignment
|
| 946 |
+
stage = data.get('stage', data.get('current_state', 'UNKNOWN'))
|
| 947 |
+
|
| 948 |
# CRITICAL: Check 'health' field first (authoritative source added in recent fix)
|
| 949 |
# If health field is present and is "ERROR", treat as error regardless of error field
|
| 950 |
# This prevents the "Error: unknown" display issue where error=null but health=ERROR
|
|
|
|
| 962 |
|
| 963 |
# Fallback: Check for error field (legacy behavior)
|
| 964 |
error = data.get('error')
|
|
|
|
| 965 |
|
| 966 |
# CRITICAL: Treat null, None, empty string, or "unknown" string as HEALTHY
|
| 967 |
# Only append _ERROR if there's an actual error message (non-empty, not "unknown")
|