Amir Mahla
commited on
Commit
·
c5e2e1f
1
Parent(s):
1f6a70d
FIX pre-commit
Browse files
cua2-core/src/cua2_core/app.py
CHANGED
|
@@ -21,7 +21,7 @@ async def lifespan(app: FastAPI):
|
|
| 21 |
if not os.getenv("HF_TOKEN"):
|
| 22 |
raise ValueError("HF_TOKEN is not set")
|
| 23 |
|
| 24 |
-
num_workers = int(os.getenv("NUM_WORKERS", "1"))
|
| 25 |
# max_sandboxes = int(600 / num_workers)
|
| 26 |
max_sandboxes = 600
|
| 27 |
|
|
|
|
| 21 |
if not os.getenv("HF_TOKEN"):
|
| 22 |
raise ValueError("HF_TOKEN is not set")
|
| 23 |
|
| 24 |
+
# num_workers = int(os.getenv("NUM_WORKERS", "1"))
|
| 25 |
# max_sandboxes = int(600 / num_workers)
|
| 26 |
max_sandboxes = 600
|
| 27 |
|
cua2-core/src/cua2_core/services/agent_service.py
CHANGED
|
@@ -204,7 +204,13 @@ class AgentService:
|
|
| 204 |
sandbox = response.sandbox
|
| 205 |
break
|
| 206 |
elif response.state == "max_sandboxes_reached":
|
| 207 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
# Log progress every 10 attempts
|
| 209 |
if attempt > 0 and attempt % 10 == 0:
|
| 210 |
logger.info(
|
|
@@ -215,7 +221,13 @@ class AgentService:
|
|
| 215 |
# Final cleanup attempt before raising error
|
| 216 |
await self.sandbox_service.cleanup_stuck_creating_sandboxes()
|
| 217 |
await self.sandbox_service.cleanup_expired_ready_sandboxes()
|
| 218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
|
| 220 |
data_dir = self.active_tasks[message_id].trace_path
|
| 221 |
user_content = self.active_tasks[message_id].instruction
|
|
|
|
| 204 |
sandbox = response.sandbox
|
| 205 |
break
|
| 206 |
elif response.state == "max_sandboxes_reached":
|
| 207 |
+
(
|
| 208 |
+
available_count,
|
| 209 |
+
non_available_count,
|
| 210 |
+
) = await self.sandbox_service.get_sandbox_counts()
|
| 211 |
+
raise Exception(
|
| 212 |
+
f"No sandbox available: pool limit reached (available: {available_count}, non-available: {non_available_count}, max: {self.max_sandboxes})"
|
| 213 |
+
)
|
| 214 |
# Log progress every 10 attempts
|
| 215 |
if attempt > 0 and attempt % 10 == 0:
|
| 216 |
logger.info(
|
|
|
|
| 221 |
# Final cleanup attempt before raising error
|
| 222 |
await self.sandbox_service.cleanup_stuck_creating_sandboxes()
|
| 223 |
await self.sandbox_service.cleanup_expired_ready_sandboxes()
|
| 224 |
+
(
|
| 225 |
+
available_count,
|
| 226 |
+
non_available_count,
|
| 227 |
+
) = await self.sandbox_service.get_sandbox_counts()
|
| 228 |
+
raise Exception(
|
| 229 |
+
f"No sandbox available: pool limit reached (available: {available_count}, non-available: {non_available_count}, max: {self.max_sandboxes})"
|
| 230 |
+
)
|
| 231 |
|
| 232 |
data_dir = self.active_tasks[message_id].trace_path
|
| 233 |
user_content = self.active_tasks[message_id].instruction
|
cua2-core/src/cua2_core/services/sandbox_service.py
CHANGED
|
@@ -363,6 +363,22 @@ class SandboxService:
|
|
| 363 |
|
| 364 |
return len(expired_sandboxes_to_kill)
|
| 365 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
async def cleanup_sandboxes(self):
|
| 367 |
sandboxes_to_kill = []
|
| 368 |
|
|
|
|
| 363 |
|
| 364 |
return len(expired_sandboxes_to_kill)
|
| 365 |
|
| 366 |
+
async def get_sandbox_counts(self) -> tuple[int, int]:
|
| 367 |
+
"""
|
| 368 |
+
Get the count of available (ready) and non-available (creating) sandboxes.
|
| 369 |
+
|
| 370 |
+
Returns:
|
| 371 |
+
Tuple of (available_count, non_available_count)
|
| 372 |
+
"""
|
| 373 |
+
async with self.sandbox_lock:
|
| 374 |
+
ready_count = len(self.sandboxes)
|
| 375 |
+
creating_count = sum(
|
| 376 |
+
1
|
| 377 |
+
for meta in self.sandbox_metadata.values()
|
| 378 |
+
if meta.get("state") == "creating"
|
| 379 |
+
)
|
| 380 |
+
return (ready_count, creating_count)
|
| 381 |
+
|
| 382 |
async def cleanup_sandboxes(self):
|
| 383 |
sandboxes_to_kill = []
|
| 384 |
|