Claude Code Claude Opus 4.6 commited on
Commit
9174d25
·
1 Parent(s): 1158971

Claude Code: Fix error field handling - explicitly set null on healthy state

Browse files

- app.py: Explicitly set error=None when imports succeed
- brain_minimal.py: Add note that error field is deliberately reset on state updates
- Both files: Add _note explaining error=null means healthy

This ensures the error field is always null (not "unknown" string) when Cain is healthy.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

app.py CHANGED
@@ -432,9 +432,14 @@ try:
432
  status_data["startup_checks"]["openclaw_imported"] = True
433
  from agents import brain_minimal
434
  status_data["startup_checks"]["brain_imported"] = True
 
 
435
  except Exception as e:
436
  status_data["error"] = f"{type(e).__name__}: {e}"
437
 
 
 
 
438
  # Write to primary location (OPENCLAW_DATA_DIR)
439
  status_path = os.environ.get('CAIN_STATUS_PATH', '/data/cain_status.json')
440
  Path(status_path).parent.mkdir(parents=True, exist_ok=True)
 
432
  status_data["startup_checks"]["openclaw_imported"] = True
433
  from agents import brain_minimal
434
  status_data["startup_checks"]["brain_imported"] = True
435
+ # CRITICAL: Explicitly set error to null when imports succeed
436
+ status_data["error"] = None
437
  except Exception as e:
438
  status_data["error"] = f"{type(e).__name__}: {e}"
439
 
440
+ # Add explanatory note about error field semantics
441
+ status_data["_note"] = "error=null means healthy - null or 'unknown' string are both treated as 'no error'"
442
+
443
  # Write to primary location (OPENCLAW_DATA_DIR)
444
  status_path = os.environ.get('CAIN_STATUS_PATH', '/data/cain_status.json')
445
  Path(status_path).parent.mkdir(parents=True, exist_ok=True)
openclaw/.openclaw/agents/brain_minimal.py CHANGED
@@ -240,10 +240,12 @@ class AgentStateMachine:
240
  "current_state": self._state.value,
241
  "last_updated": datetime.utcnow().isoformat() + "+00:00",
242
  "agent": self._agent_name,
243
- "error": None # Explicitly clear error when state machine updates
 
244
  }
245
 
246
  # Preserve stage, a2a, and startup_checks fields if they existed
 
247
  if existing_stage:
248
  status_data["stage"] = existing_stage
249
  if existing_a2a:
 
240
  "current_state": self._state.value,
241
  "last_updated": datetime.utcnow().isoformat() + "+00:00",
242
  "agent": self._agent_name,
243
+ "error": None, # CRITICAL: Explicitly clear error when state machine updates (null = healthy)
244
+ "_note": "error=null means healthy - treated as 'no error'"
245
  }
246
 
247
  # Preserve stage, a2a, and startup_checks fields if they existed
248
+ # NOTE: We deliberately DO NOT preserve the error field - always reset to None on state updates
249
  if existing_stage:
250
  status_data["stage"] = existing_stage
251
  if existing_a2a: