Claude Code Claude Opus 4.6 commited on
Commit
6487910
·
1 Parent(s): e56588b

Claude Code: Fix A2A communication - correct status file path resolution

Browse files

- Fix health_monitor.py to check CAIN_STATUS_PATH first (matches app.py)
- Fix error_handlers.py to use same path priority order
- This ensures consistent status file reads/writes across all modules

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

error_handlers.py CHANGED
@@ -94,20 +94,36 @@ def _resolve_status_file() -> Path:
94
  if env_path:
95
  return Path(env_path)
96
 
97
- # Priority 2: /app/.openclaw/agents/cain_status.json (actual location)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  openclaw_status = Path(__file__).parent / ".openclaw" / "agents" / "cain_status.json"
99
  if openclaw_status.exists():
100
  return openclaw_status
101
 
102
- # Priority 3: /app/cain_status.json (legacy location)
103
  app_path = Path("/app/cain_status.json")
 
 
104
 
105
- # Priority 4: Script directory as final fallback
106
- if not app_path.parent.exists():
107
- script_dir = Path(os.path.dirname(__file__))
108
- return script_dir / "cain_status.json"
109
-
110
- return app_path
111
 
112
  STATUS_FILE = _resolve_status_file()
113
 
 
94
  if env_path:
95
  return Path(env_path)
96
 
97
+ # Priority 2: CAIN_STATUS_FILE env var (legacy)
98
+ env_path = os.environ.get('CAIN_STATUS_FILE')
99
+ if env_path:
100
+ return Path(env_path)
101
+
102
+ # Priority 3: OPENCLAW_DATA_DIR + cain_status.json
103
+ data_dir = os.environ.get('OPENCLAW_DATA_DIR')
104
+ if data_dir:
105
+ data_path = Path(data_dir) / "cain_status.json"
106
+ if data_path.exists():
107
+ return data_path
108
+
109
+ # Priority 4: /data/cain_status.json (Docker volume mount, default)
110
+ data_path = Path("/data/cain_status.json")
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")
121
+ if app_path.parent.exists():
122
+ return app_path
123
 
124
+ # Priority 7: Script directory as final fallback
125
+ script_dir = Path(os.path.dirname(__file__))
126
+ return script_dir / "cain_status.json"
 
 
 
127
 
128
  STATUS_FILE = _resolve_status_file()
129
 
openclaw/.openclaw/health_monitor.py CHANGED
@@ -777,30 +777,44 @@ def reset_health_monitor():
777
 
778
  def _find_status_file() -> Path:
779
  """Dynamically locate cain_status.json using multiple fallback strategies."""
780
- # Strategy 1: Use environment variable if set (highest priority)
 
 
 
 
 
781
  env_path = os.environ.get("CAIN_STATUS_FILE")
782
  if env_path:
783
  return Path(env_path)
784
 
785
- # Strategy 2: Relative to health_monitor.py (in .openclaw/ directory)
786
- # In workspace: openclaw/.openclaw/health_monitor.py -> openclaw/.openclaw/agents/
787
- # In Docker: /app/openclaw/.openclaw/health_monitor.py -> /app/openclaw/.openclaw/agents/
 
 
 
 
 
 
 
 
 
 
788
  base_dir = Path(__file__).parent.resolve()
789
  relative_path = base_dir / "agents" / "cain_status.json"
790
  if relative_path.exists():
791
  return relative_path
792
 
793
- # Strategy 3: From /app root (Docker) or workspace root (local)
794
- # Handles cases where health_monitor.py might be imported from different locations
795
- workspace_root = base_dir.parent.parent # Go up two levels from .openclaw/
796
  if workspace_root.name == "openclaw":
797
- workspace_root = workspace_root.parent # Go up one more level
798
  root_path = workspace_root / "openclaw" / ".openclaw" / "agents" / "cain_status.json"
799
  if root_path.exists():
800
  return root_path
801
 
802
- # Strategy 4: Fall back to the expected path (may not exist, but that's OK)
803
- return relative_path
804
 
805
 
806
  def read_current_stage() -> str:
 
777
 
778
  def _find_status_file() -> Path:
779
  """Dynamically locate cain_status.json using multiple fallback strategies."""
780
+ # Strategy 1: CAIN_STATUS_PATH (set by app.py, highest priority)
781
+ env_path = os.environ.get("CAIN_STATUS_PATH")
782
+ if env_path:
783
+ return Path(env_path)
784
+
785
+ # Strategy 2: CAIN_STATUS_FILE (legacy, for compatibility)
786
  env_path = os.environ.get("CAIN_STATUS_FILE")
787
  if env_path:
788
  return Path(env_path)
789
 
790
+ # Strategy 3: OPENCLAW_DATA_DIR + cain_status.json
791
+ data_dir = os.environ.get("OPENCLAW_DATA_DIR")
792
+ if data_dir:
793
+ data_path = Path(data_dir) / "cain_status.json"
794
+ if data_path.exists():
795
+ return data_path
796
+
797
+ # Strategy 4: /data/cain_status.json (Docker volume mount)
798
+ data_path = Path("/data/cain_status.json")
799
+ if data_path.exists():
800
+ return data_path
801
+
802
+ # Strategy 5: Relative to health_monitor.py (in .openclaw/ directory)
803
  base_dir = Path(__file__).parent.resolve()
804
  relative_path = base_dir / "agents" / "cain_status.json"
805
  if relative_path.exists():
806
  return relative_path
807
 
808
+ # Strategy 6: From /app root (Docker) or workspace root (local)
809
+ workspace_root = base_dir.parent.parent
 
810
  if workspace_root.name == "openclaw":
811
+ workspace_root = workspace_root.parent
812
  root_path = workspace_root / "openclaw" / ".openclaw" / "agents" / "cain_status.json"
813
  if root_path.exists():
814
  return root_path
815
 
816
+ # Strategy 7: Fall back to /data/cain_status.json (default for Docker)
817
+ return Path("/data/cain_status.json")
818
 
819
 
820
  def read_current_stage() -> str: