Claude Code Claude Opus 4.6 commited on
Commit
1967ae7
·
1 Parent(s): 2ae943a

Claude Code: Fix STATUS_FILE path resolution - use dynamic multi-strategy lookup

Browse files

- Replace hardcoded path assumption with dynamic _find_status_file() function
- Add 4 fallback strategies: env var, relative path, adjacent dir, default
- Works both locally (/tmp/claude-workspace) and in Docker (/app)
- Supports CAIN_STATUS_FILE environment variable override

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

Files changed (1) hide show
  1. error_handlers.py +27 -2
error_handlers.py CHANGED
@@ -58,8 +58,33 @@ async def generic_exception_handler(request: Request, exc: Exception) -> JSONRes
58
 
59
 
60
  # Configuration path - cain_status.json location
61
- # Uses absolute path based on this file's location (works both locally and in container)
62
- STATUS_FILE = Path(__file__).parent / "openclaw" / ".openclaw" / "agents" / "cain_status.json"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
 
65
  def handle_status_file_read() -> Dict[str, Any]:
 
58
 
59
 
60
  # Configuration path - cain_status.json location
61
+ # Uses dynamic path resolution that works both locally and in Docker container
62
+ # Tries multiple strategies to find the status file
63
+ def _find_status_file() -> Path:
64
+ """Dynamically locate cain_status.json using multiple fallback strategies."""
65
+ # Strategy 1: Use environment variable if set (highest priority)
66
+ env_path = os.environ.get("CAIN_STATUS_FILE")
67
+ if env_path:
68
+ return Path(env_path)
69
+
70
+ # Strategy 2: Relative to this file's parent directory
71
+ # In workspace: error_handlers.py -> openclaw/.openclaw/agents/
72
+ # In Docker: /app/error_handlers.py -> /app/openclaw/.openclaw/agents/
73
+ base_dir = Path(__file__).parent.resolve()
74
+ relative_path = base_dir / "openclaw" / ".openclaw" / "agents" / "cain_status.json"
75
+ if relative_path.exists():
76
+ return relative_path
77
+
78
+ # Strategy 3: Check if we're in the openclaw directory already
79
+ # Handles cases where error_handlers.py might be in openclaw/
80
+ agents_dir = base_dir / ".openclaw" / "agents" / "cain_status.json"
81
+ if agents_dir.exists():
82
+ return agents_dir
83
+
84
+ # Strategy 4: Fall back to the expected path (may not exist, but that's OK)
85
+ return relative_path
86
+
87
+ STATUS_FILE = _find_status_file()
88
 
89
 
90
  def handle_status_file_read() -> Dict[str, Any]: