Claude Code Claude Opus 4.6 commited on
Commit
a17fe15
·
1 Parent(s): f3021f4

Claude Code: Improve Cain startup diagnostics and error handling

Browse files

- Add detailed logging for openclaw and brain imports at startup
- Add startup_checks to status file to track import status
- Improve entrypoint.sh to ensure /data directory is writable
- Add error field to status file to capture actual errors

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

Files changed (2) hide show
  1. app.py +22 -1
  2. entrypoint.sh +5 -0
app.py CHANGED
@@ -414,6 +414,11 @@ try:
414
  "stage": "RUNNING_A2A_READY",
415
  "last_updated": datetime.utcnow().isoformat() + "+00:00",
416
  "agent": "cain",
 
 
 
 
 
417
  "a2a": {
418
  "endpoint": "/a2a/jsonrpc",
419
  "enabled": True,
@@ -421,6 +426,15 @@ try:
421
  }
422
  }
423
 
 
 
 
 
 
 
 
 
 
424
  # Write to primary location (OPENCLAW_DATA_DIR)
425
  status_path = os.environ.get('CAIN_STATUS_PATH', '/data/cain_status.json')
426
  Path(status_path).parent.mkdir(parents=True, exist_ok=True)
@@ -460,10 +474,17 @@ except Exception as e:
460
  try:
461
  import openclaw
462
  print(f">>> CAIN: openclaw imported from {openclaw.__file__}", flush=True)
 
463
  from agents import brain_minimal
464
  print(">>> CAIN: brain_minimal module available", flush=True)
 
 
 
 
465
  except Exception as e:
466
- print(f">>> CAIN WARNING: Could not import brain modules at startup: {e}", flush=True)
 
 
467
 
468
  # ============================================================================
469
  # STARTUP DIAGNOSTIC ENDPOINT
 
414
  "stage": "RUNNING_A2A_READY",
415
  "last_updated": datetime.utcnow().isoformat() + "+00:00",
416
  "agent": "cain",
417
+ "error": None,
418
+ "startup_checks": {
419
+ "openclaw_imported": False,
420
+ "brain_imported": False
421
+ },
422
  "a2a": {
423
  "endpoint": "/a2a/jsonrpc",
424
  "enabled": True,
 
426
  }
427
  }
428
 
429
+ # Check if openclaw and brain can be imported
430
+ try:
431
+ import openclaw
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)
 
474
  try:
475
  import openclaw
476
  print(f">>> CAIN: openclaw imported from {openclaw.__file__}", flush=True)
477
+ print(f">>> CAIN: sys.path includes: {sys.path[:3]}", flush=True)
478
  from agents import brain_minimal
479
  print(">>> CAIN: brain_minimal module available", flush=True)
480
+ print(f">>> CAIN: brain_minimal has get_brain: {hasattr(brain_minimal, 'get_brain')}", flush=True)
481
+ except ImportError as e:
482
+ print(f">>> CAIN ERROR: ImportError at startup: {e}", flush=True)
483
+ print(f">>> CAIN ERROR: sys.path = {sys.path}", flush=True)
484
  except Exception as e:
485
+ print(f">>> CAIN WARNING: Could not import brain modules at startup: {type(e).__name__}: {e}", flush=True)
486
+ import traceback
487
+ traceback.print_exc()
488
 
489
  # ============================================================================
490
  # STARTUP DIAGNOSTIC ENDPOINT
entrypoint.sh CHANGED
@@ -6,6 +6,10 @@ set -e
6
  mkdir -p /app/frontend
7
  mkdir -p /data/frontend
8
 
 
 
 
 
9
  echo "=========================================="
10
  echo "Cain Starting..."
11
  echo "=========================================="
@@ -13,6 +17,7 @@ echo "Timestamp: $(date -u +"%Y-%m-%dT%H:%M:%SZ")"
13
  echo "PORT: ${PORT:-7860}"
14
  echo "Working Directory: $(pwd)"
15
  echo "Python Version: $(python --version)"
 
16
  echo "=========================================="
17
 
18
  # Change to app directory
 
6
  mkdir -p /app/frontend
7
  mkdir -p /data/frontend
8
 
9
+ # Ensure /data is writable and exists
10
+ mkdir -p /data
11
+ chmod 777 /data 2>/dev/null || true
12
+
13
  echo "=========================================="
14
  echo "Cain Starting..."
15
  echo "=========================================="
 
17
  echo "PORT: ${PORT:-7860}"
18
  echo "Working Directory: $(pwd)"
19
  echo "Python Version: $(python --version)"
20
+ echo "Data directory: $(ls -la /data 2>&1 | head -5)"
21
  echo "=========================================="
22
 
23
  # Change to app directory