Claude Code Claude Opus 4.6 commited on
Commit
9a04435
·
1 Parent(s): 07b8a4e

Claude Code: Improve status file initialization robustness

Browse files

- Create parent directories for brain status file if missing
- Add fallback directory creation with error handling
- Prioritize Docker structure paths for consistency

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

Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -432,20 +432,27 @@ try:
432
  # Try multiple possible locations with fallback
433
  _script_dir = Path(os.path.abspath(os.path.dirname(__file__)))
434
  _possible_status_paths = [
 
435
  Path("/app/.openclaw/agents/cain_status.json"), # Legacy flat structure
436
- Path("/app/openclaw/.openclaw/agents/cain_status.json"), # Nested structure
437
- _script_dir / ".openclaw" / "agents" / "cain_status.json",
438
  _script_dir / "openclaw" / ".openclaw" / "agents" / "cain_status.json",
 
439
  ]
440
  brain_status_path = None
441
  for p in _possible_status_paths:
442
- if p.parent.exists():
 
 
443
  brain_status_path = p
444
  break
 
 
445
  if brain_status_path:
446
- with open(brain_status_path, 'w') as f:
447
- json.dump(status_data, f, indent=2)
448
- print(f">>> CAIN: Brain status file also updated at {brain_status_path}", flush=True)
 
 
 
449
  except Exception as e:
450
  print(f">>> CAIN WARNING: Could not update status file: {e}", flush=True)
451
 
 
432
  # Try multiple possible locations with fallback
433
  _script_dir = Path(os.path.abspath(os.path.dirname(__file__)))
434
  _possible_status_paths = [
435
+ Path("/app/openclaw/.openclaw/agents/cain_status.json"), # Nested structure (Docker)
436
  Path("/app/.openclaw/agents/cain_status.json"), # Legacy flat structure
 
 
437
  _script_dir / "openclaw" / ".openclaw" / "agents" / "cain_status.json",
438
+ _script_dir / ".openclaw" / "agents" / "cain_status.json",
439
  ]
440
  brain_status_path = None
441
  for p in _possible_status_paths:
442
+ # Create parent directory if it doesn't exist
443
+ try:
444
+ p.parent.mkdir(parents=True, exist_ok=True)
445
  brain_status_path = p
446
  break
447
+ except Exception:
448
+ continue
449
  if brain_status_path:
450
+ try:
451
+ with open(brain_status_path, 'w') as f:
452
+ json.dump(status_data, f, indent=2)
453
+ print(f">>> CAIN: Brain status file also updated at {brain_status_path}", flush=True)
454
+ except Exception as e:
455
+ print(f">>> CAIN WARNING: Could not write brain status file: {e}", flush=True)
456
  except Exception as e:
457
  print(f">>> CAIN WARNING: Could not update status file: {e}", flush=True)
458