Spaces:
Sleeping
Sleeping
Claude Code Claude Opus 4.6 commited on
Commit ·
00a0b93
1
Parent(s): 6487910
Claude Code: Fix A2A communication - preserve stage field in status updates
Browse files- brain_minimal.py: Preserve stage and a2a fields when updating status
- app.py: Write status to both /data and /app/.openclaw/agents locations
- Ensures A2A_READY stage is not overwritten by brain state updates
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- app.py +13 -4
- openclaw/.openclaw/agents/brain_minimal.py +18 -0
app.py
CHANGED
|
@@ -402,7 +402,8 @@ print(">>> CAIN: A2A diagnostics at /a2a/diagnostics", flush=True)
|
|
| 402 |
try:
|
| 403 |
import json
|
| 404 |
from datetime import datetime
|
| 405 |
-
|
|
|
|
| 406 |
status_data = {
|
| 407 |
"current_state": "idle",
|
| 408 |
"stage": "RUNNING_A2A_READY",
|
|
@@ -414,12 +415,20 @@ try:
|
|
| 414 |
"status": "ready"
|
| 415 |
}
|
| 416 |
}
|
| 417 |
-
|
| 418 |
-
|
|
|
|
| 419 |
Path(status_path).parent.mkdir(parents=True, exist_ok=True)
|
| 420 |
with open(status_path, 'w') as f:
|
| 421 |
json.dump(status_data, f, indent=2)
|
| 422 |
-
print(f">>> CAIN: Status file updated: stage=RUNNING_A2A_READY", flush=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 423 |
except Exception as e:
|
| 424 |
print(f">>> CAIN WARNING: Could not update status file: {e}", flush=True)
|
| 425 |
|
|
|
|
| 402 |
try:
|
| 403 |
import json
|
| 404 |
from datetime import datetime
|
| 405 |
+
from pathlib import Path
|
| 406 |
+
|
| 407 |
status_data = {
|
| 408 |
"current_state": "idle",
|
| 409 |
"stage": "RUNNING_A2A_READY",
|
|
|
|
| 415 |
"status": "ready"
|
| 416 |
}
|
| 417 |
}
|
| 418 |
+
|
| 419 |
+
# Write to primary location (OPENCLAW_DATA_DIR)
|
| 420 |
+
status_path = os.environ.get('CAIN_STATUS_PATH', '/data/cain_status.json')
|
| 421 |
Path(status_path).parent.mkdir(parents=True, exist_ok=True)
|
| 422 |
with open(status_path, 'w') as f:
|
| 423 |
json.dump(status_data, f, indent=2)
|
| 424 |
+
print(f">>> CAIN: Status file updated at {status_path}: stage=RUNNING_A2A_READY", flush=True)
|
| 425 |
+
|
| 426 |
+
# Also write to brain_minimal's status file location for consistency
|
| 427 |
+
brain_status_path = Path("/app/.openclaw/agents/cain_status.json")
|
| 428 |
+
if brain_status_path.parent.exists():
|
| 429 |
+
with open(brain_status_path, 'w') as f:
|
| 430 |
+
json.dump(status_data, f, indent=2)
|
| 431 |
+
print(f">>> CAIN: Brain status file also updated at {brain_status_path}", flush=True)
|
| 432 |
except Exception as e:
|
| 433 |
print(f">>> CAIN WARNING: Could not update status file: {e}", flush=True)
|
| 434 |
|
openclaw/.openclaw/agents/brain_minimal.py
CHANGED
|
@@ -222,12 +222,30 @@ class AgentStateMachine:
|
|
| 222 |
|
| 223 |
def _update_status_file(self):
|
| 224 |
"""Update cain_status.json with current state and timestamp."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
status_data = {
|
| 226 |
"current_state": self._state.value,
|
| 227 |
"last_updated": datetime.utcnow().isoformat() + "+00:00",
|
| 228 |
"agent": self._agent_name
|
| 229 |
}
|
| 230 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
try:
|
| 232 |
with open(self._status_file, "w") as f:
|
| 233 |
json.dump(status_data, f, indent=2)
|
|
|
|
| 222 |
|
| 223 |
def _update_status_file(self):
|
| 224 |
"""Update cain_status.json with current state and timestamp."""
|
| 225 |
+
# Read existing status file to preserve stage and a2a fields
|
| 226 |
+
existing_stage = None
|
| 227 |
+
existing_a2a = None
|
| 228 |
+
try:
|
| 229 |
+
if self._status_file.exists():
|
| 230 |
+
with open(self._status_file, "r") as f:
|
| 231 |
+
existing_data = json.load(f)
|
| 232 |
+
existing_stage = existing_data.get("stage")
|
| 233 |
+
existing_a2a = existing_data.get("a2a")
|
| 234 |
+
except Exception:
|
| 235 |
+
pass # If read fails, we'll create new status without stage/a2a
|
| 236 |
+
|
| 237 |
status_data = {
|
| 238 |
"current_state": self._state.value,
|
| 239 |
"last_updated": datetime.utcnow().isoformat() + "+00:00",
|
| 240 |
"agent": self._agent_name
|
| 241 |
}
|
| 242 |
|
| 243 |
+
# Preserve stage and a2a fields if they existed
|
| 244 |
+
if existing_stage:
|
| 245 |
+
status_data["stage"] = existing_stage
|
| 246 |
+
if existing_a2a:
|
| 247 |
+
status_data["a2a"] = existing_a2a
|
| 248 |
+
|
| 249 |
try:
|
| 250 |
with open(self._status_file, "w") as f:
|
| 251 |
json.dump(status_data, f, indent=2)
|