Spaces:
Sleeping
Sleeping
Claude Code Claude Opus 4.6 commited on
Commit ·
749b560
1
Parent(s): 7a5b921
Claude Code: Fix A2A communication - pre-initialize worker_state in minimal mode
Browse filesRoot cause: 3-second delay in state transition caused A2A communication failures
during startup. Health endpoint returned STARTING stage while parent agent
expected RUNNING.
Fix: Pre-initialize _worker_state to RUNNING_A2A_READY in minimal mode at
module import time, eliminating the delay and ensuring immediate A2A readiness.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
app.py
CHANGED
|
@@ -108,8 +108,8 @@ async def lifespan(app: FastAPI):
|
|
| 108 |
if STARTUP_MODE == "minimal":
|
| 109 |
logger.info("[LIFESPAN] MINIMAL MODE: Skipping worker spawn - uvicorn will start immediately")
|
| 110 |
_worker_process = None
|
| 111 |
-
#
|
| 112 |
-
|
| 113 |
else:
|
| 114 |
logger.info("[LIFESPAN] Starting up - spawning brain_minimal.py worker process...")
|
| 115 |
try:
|
|
@@ -205,6 +205,15 @@ _worker_state = {
|
|
| 205 |
"last_heartbeat": None,
|
| 206 |
}
|
| 207 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
class HeartbeatRequest(BaseModel):
|
| 209 |
worker_pid: int
|
| 210 |
worker_mode: str
|
|
|
|
| 108 |
if STARTUP_MODE == "minimal":
|
| 109 |
logger.info("[LIFESPAN] MINIMAL MODE: Skipping worker spawn - uvicorn will start immediately")
|
| 110 |
_worker_process = None
|
| 111 |
+
# NOTE: State already pre-initialized to RUNNING_A2A_READY at module level
|
| 112 |
+
# No need for background transition task
|
| 113 |
else:
|
| 114 |
logger.info("[LIFESPAN] Starting up - spawning brain_minimal.py worker process...")
|
| 115 |
try:
|
|
|
|
| 205 |
"last_heartbeat": None,
|
| 206 |
}
|
| 207 |
|
| 208 |
+
# CRITICAL FIX: In minimal mode, pre-initialize to A2A ready state
|
| 209 |
+
# This eliminates the 3-second delay during which A2A communication fails
|
| 210 |
+
if STARTUP_MODE == "minimal":
|
| 211 |
+
_worker_state.update({
|
| 212 |
+
"stage": "RUNNING_A2A_READY",
|
| 213 |
+
"worker_active": True, # Mark active immediately for health checks
|
| 214 |
+
})
|
| 215 |
+
logger.info("[INIT] Minimal mode: Pre-initialized worker_state to RUNNING_A2A_READY")
|
| 216 |
+
|
| 217 |
class HeartbeatRequest(BaseModel):
|
| 218 |
worker_pid: int
|
| 219 |
worker_mode: str
|