Claude Code Claude Opus 4.6 commited on
Commit
6920374
·
1 Parent(s): 1b507fa

Claude Code: Fix Docker path resolution - support nested openclaw structure

Browse files

- Dynamic path resolution with fallbacks for /app/.openclaw vs /app/openclaw/.openclaw
- Update sys.path setup in error_handlers.py to probe multiple locations
- Fix hardcoded brain_status_path in app.py
- Update _resolve_status_file to check nested structure

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

Files changed (2) hide show
  1. app.py +14 -2
  2. error_handlers.py +24 -10
app.py CHANGED
@@ -429,8 +429,20 @@ try:
429
  print(f">>> CAIN: Status file updated at {status_path}: stage=RUNNING_A2A_READY", flush=True)
430
 
431
  # Also write to brain_minimal's status file location for consistency
432
- brain_status_path = Path("/app/.openclaw/agents/cain_status.json")
433
- if brain_status_path.parent.exists():
 
 
 
 
 
 
 
 
 
 
 
 
434
  with open(brain_status_path, 'w') as f:
435
  json.dump(status_data, f, indent=2)
436
  print(f">>> CAIN: Brain status file also updated at {brain_status_path}", flush=True)
 
429
  print(f">>> CAIN: Status file updated at {status_path}: stage=RUNNING_A2A_READY", flush=True)
430
 
431
  # Also write to brain_minimal's status file location for consistency
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)
error_handlers.py CHANGED
@@ -14,12 +14,19 @@ from fastapi.responses import JSONResponse
14
 
15
  # CRITICAL: Set up sys.path for agents imports at module load time
16
  # This ensures `from agents import brain_minimal` works regardless of import order
17
- # Note: Docker WORKDIR is /app, .openclaw is at /app/.openclaw
18
- _openclaw_base_dir = Path(__file__).parent # /app
19
- _openclaw_internal_dir = Path(__file__).parent / ".openclaw" # /app/.openclaw
20
-
21
- # Add /app and /app/.openclaw to sys.path for agents imports
22
- for path_dir in [_openclaw_base_dir, _openclaw_internal_dir]:
 
 
 
 
 
 
 
23
  path_str = str(path_dir)
24
  if path_str not in sys.path and path_dir.exists():
25
  sys.path.insert(0, path_str)
@@ -111,10 +118,17 @@ def _resolve_status_file() -> Path:
111
  if data_path.exists():
112
  return data_path
113
 
114
- # Priority 5: /app/.openclaw/agents/cain_status.json (actual location)
115
- openclaw_status = Path(__file__).parent / ".openclaw" / "agents" / "cain_status.json"
116
- if openclaw_status.exists():
117
- return openclaw_status
 
 
 
 
 
 
 
118
 
119
  # Priority 6: /app/cain_status.json (legacy location)
120
  app_path = Path("/app/cain_status.json")
 
14
 
15
  # CRITICAL: Set up sys.path for agents imports at module load time
16
  # This ensures `from agents import brain_minimal` works regardless of import order
17
+ # Dynamic path resolution with fallbacks for different Docker contexts
18
+ _script_dir = Path(os.path.abspath(os.path.dirname(__file__))) # Absolute path of this script
19
+
20
+ # Try multiple possible locations for .openclaw directory
21
+ _possible_openclaw_paths = [
22
+ _script_dir / ".openclaw", # /app/.openclaw (legacy/flat structure)
23
+ _script_dir / "openclaw" / ".openclaw", # /app/openclaw/.openclaw (nested structure)
24
+ Path("/app/openclaw/.openclaw"), # Absolute Docker path (nested)
25
+ Path("/app/.openclaw"), # Absolute Docker path (flat)
26
+ ]
27
+
28
+ # Add all valid paths to sys.path
29
+ for path_dir in _possible_openclaw_paths:
30
  path_str = str(path_dir)
31
  if path_str not in sys.path and path_dir.exists():
32
  sys.path.insert(0, path_str)
 
118
  if data_path.exists():
119
  return data_path
120
 
121
+ # Priority 5: /app/.openclaw/agents/cain_status.json OR /app/openclaw/.openclaw/agents/cain_status.json
122
+ _script_dir = Path(os.path.abspath(os.path.dirname(__file__)))
123
+ _possible_status_paths = [
124
+ Path("/app/.openclaw/agents/cain_status.json"), # Flat structure
125
+ Path("/app/openclaw/.openclaw/agents/cain_status.json"), # Nested structure
126
+ _script_dir / ".openclaw" / "agents" / "cain_status.json",
127
+ _script_dir / "openclaw" / ".openclaw" / "agents" / "cain_status.json",
128
+ ]
129
+ for openclaw_status in _possible_status_paths:
130
+ if openclaw_status.exists():
131
+ return openclaw_status
132
 
133
  # Priority 6: /app/cain_status.json (legacy location)
134
  app_path = Path("/app/cain_status.json")