Claude Code Claude Opus 4.6 commited on
Commit
8283992
·
1 Parent(s): 2dc609c

Claude Code: Fix Cain error field handling - clear stale 'unknown' at startup

Browse files

- Add missing /app/cain_status.json and /app/data/cain_status.json to cleanup paths
- Always clean stale 'unknown' errors regardless of timestamp (fix: was only cleaning if older)
- Ensure all status file locations are covered for consistent error field handling

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

Files changed (2) hide show
  1. app.py +11 -5
  2. entrypoint.sh +2 -2
app.py CHANGED
@@ -459,6 +459,8 @@ try:
459
  _possible_status_paths = [
460
  Path("/app/openclaw/.openclaw/agents/cain_status.json"), # Nested structure (Docker)
461
  Path("/app/.openclaw/agents/cain_status.json"), # Legacy flat structure
 
 
462
  _script_dir / "openclaw" / ".openclaw" / "agents" / "cain_status.json",
463
  _script_dir / ".openclaw" / "agents" / "cain_status.json",
464
  ]
@@ -466,19 +468,23 @@ try:
466
  try:
467
  # Create parent directory if it doesn't exist
468
  p.parent.mkdir(parents=True, exist_ok=True)
469
- # Check if file exists and has stale "unknown" error - clean it
470
  if p.exists():
471
  try:
472
  with open(p, 'r') as f:
473
  existing_data = json.load(f)
474
- # Only overwrite if it has a stale "unknown" error
475
  existing_error = existing_data.get('error')
476
- if isinstance(existing_error, str) and existing_error.strip().lower() in ('unknown', 'none', 'null', ''):
 
 
 
 
477
  with open(p, 'w') as f:
478
  json.dump(status_data, f, indent=2)
479
- print(f">>> CAIN: Cleaned stale error at {p}", flush=True)
480
  # Also update if our status is newer
481
- elif status_data.get('last_updated') > existing_data.get('last_updated', ''):
482
  with open(p, 'w') as f:
483
  json.dump(status_data, f, indent=2)
484
  print(f">>> CAIN: Updated status at {p}", flush=True)
 
459
  _possible_status_paths = [
460
  Path("/app/openclaw/.openclaw/agents/cain_status.json"), # Nested structure (Docker)
461
  Path("/app/.openclaw/agents/cain_status.json"), # Legacy flat structure
462
+ Path("/app/cain_status.json"), # App root
463
+ Path("/app/data/cain_status.json"), # App data subdirectory
464
  _script_dir / "openclaw" / ".openclaw" / "agents" / "cain_status.json",
465
  _script_dir / ".openclaw" / "agents" / "cain_status.json",
466
  ]
 
468
  try:
469
  # Create parent directory if it doesn't exist
470
  p.parent.mkdir(parents=True, exist_ok=True)
471
+ # Check if file exists and has stale "unknown" error - ALWAYS clean it
472
  if p.exists():
473
  try:
474
  with open(p, 'r') as f:
475
  existing_data = json.load(f)
476
+ # CRITICAL: Always overwrite if it has a stale "unknown" error, regardless of timestamp
477
  existing_error = existing_data.get('error')
478
+ has_stale_error = (
479
+ isinstance(existing_error, str) and
480
+ existing_error.strip().lower() in ('unknown', 'none', 'null', '')
481
+ )
482
+ if has_stale_error:
483
  with open(p, 'w') as f:
484
  json.dump(status_data, f, indent=2)
485
+ print(f">>> CAIN: Cleaned stale 'unknown' error at {p}", flush=True)
486
  # Also update if our status is newer
487
+ elif status_data.get('last_updated', '') > existing_data.get('last_updated', ''):
488
  with open(p, 'w') as f:
489
  json.dump(status_data, f, indent=2)
490
  print(f">>> CAIN: Updated status at {p}", flush=True)
entrypoint.sh CHANGED
@@ -56,8 +56,8 @@ status_files = [
56
  Path('/data/cain_status.json'), # Primary (OPENCLAW_DATA_DIR)
57
  Path('/app/openclaw/.openclaw/agents/cain_status.json'), # Nested structure
58
  Path('/app/.openclaw/agents/cain_status.json'), # Legacy flat structure
59
- # Additional paths that app.py might use (for consistency)
60
- Path('/app/cain_status.json'),
61
  ]
62
 
63
  cleaned = 0
 
56
  Path('/data/cain_status.json'), # Primary (OPENCLAW_DATA_DIR)
57
  Path('/app/openclaw/.openclaw/agents/cain_status.json'), # Nested structure
58
  Path('/app/.openclaw/agents/cain_status.json'), # Legacy flat structure
59
+ Path('/app/cain_status.json'), # App root
60
+ Path('/app/data/cain_status.json'), # App data subdirectory
61
  ]
62
 
63
  cleaned = 0