Claude Code Claude Opus 4.6 commited on
Commit
af8fa37
·
1 Parent(s): 8ebbd80

Claude Code: Fix path resolution - prioritize /app/cain_status.json to align with Docker WORKDIR

Browse files
Files changed (1) hide show
  1. error_handlers.py +9 -17
error_handlers.py CHANGED
@@ -76,33 +76,25 @@ def _get_base_dir() -> Path:
76
 
77
  def _resolve_status_file() -> Path:
78
  """Find cain_status.json by searching common locations."""
79
- # Priority 1: CAIN_STATUS_PATH env var (direct path or set by app.py)
80
- # Trust this completely if set - don't second-guess it
 
 
 
 
81
  env_path = os.environ.get('CAIN_STATUS_PATH')
82
  if env_path:
83
  return Path(env_path)
84
 
85
- # Priority 2: Use OPENCLAW_DATA_DIR (set in Docker)
86
  base_dir = _get_base_dir()
87
  candidate = base_dir / "cain_status.json"
88
- # Check if directory is writable (file will be created if needed)
89
  if candidate.parent.exists() and os.access(candidate.parent, os.W_OK):
90
  return candidate
91
 
92
- # Priority 3: Search relative to this script's location
93
  script_dir = Path(os.path.dirname(__file__))
94
- relative_paths = [
95
- script_dir / "cain_status.json", # Script directory
96
- script_dir / ".openclaw" / "cain_status.json", # .openclaw subdir
97
- script_dir / ".openclaw" / "agents" / "cain_status.json", # agents subdir
98
- script_dir.parent / "cain_status.json",
99
- ]
100
- for candidate in relative_paths:
101
- if candidate.exists():
102
- return candidate
103
-
104
- # Default: use base_dir/cain_status.json (will be created if needed)
105
- return _get_base_dir() / "cain_status.json"
106
 
107
  STATUS_FILE = _resolve_status_file()
108
 
 
76
 
77
  def _resolve_status_file() -> Path:
78
  """Find cain_status.json by searching common locations."""
79
+ # Priority 1: /app/cain_status.json (Docker WORKDIR - primary location)
80
+ app_path = Path("/app/cain_status.json")
81
+ if app_path.parent.exists() and os.access(app_path.parent, os.W_OK):
82
+ return app_path
83
+
84
+ # Priority 2: CAIN_STATUS_PATH env var (direct override)
85
  env_path = os.environ.get('CAIN_STATUS_PATH')
86
  if env_path:
87
  return Path(env_path)
88
 
89
+ # Priority 3: OPENCLAW_DATA_DIR with writable check
90
  base_dir = _get_base_dir()
91
  candidate = base_dir / "cain_status.json"
 
92
  if candidate.parent.exists() and os.access(candidate.parent, os.W_OK):
93
  return candidate
94
 
95
+ # Priority 4: Script directory as final fallback
96
  script_dir = Path(os.path.dirname(__file__))
97
+ return script_dir / "cain_status.json"
 
 
 
 
 
 
 
 
 
 
 
98
 
99
  STATUS_FILE = _resolve_status_file()
100