mirror of
https://github.com/usestrix/strix.git
synced 2026-08-23 03:12:37 +02:00
refactor: simplify tool server to asyncio tasks with per-agent isolation
- Replace multiprocessing/threading with single asyncio task per agent - Add task cancellation: new request cancels previous for same agent - Add per-agent state isolation via ContextVar for Terminal, Browser, Python managers - Add posthog telemetry for tool execution errors (timeout, http, sandbox) - Fix proxy manager singleton pattern - Increase client timeout buffer over server timeout - Add context.py to Dockerfile
This commit is contained in:
@@ -5,6 +5,7 @@ from typing import Any
|
||||
import httpx
|
||||
|
||||
from strix.config import Config
|
||||
from strix.telemetry import posthog
|
||||
|
||||
|
||||
if os.getenv("STRIX_SANDBOX_MODE", "false").lower() == "false":
|
||||
@@ -20,7 +21,8 @@ from .registry import (
|
||||
)
|
||||
|
||||
|
||||
SANDBOX_EXECUTION_TIMEOUT = float(Config.get("strix_sandbox_execution_timeout") or "120")
|
||||
_SERVER_TIMEOUT = float(Config.get("strix_sandbox_execution_timeout") or "120")
|
||||
SANDBOX_EXECUTION_TIMEOUT = _SERVER_TIMEOUT + 30
|
||||
SANDBOX_CONNECT_TIMEOUT = float(Config.get("strix_sandbox_connect_timeout") or "10")
|
||||
|
||||
|
||||
@@ -82,14 +84,17 @@ async def _execute_tool_in_sandbox(tool_name: str, agent_state: Any, **kwargs: A
|
||||
response.raise_for_status()
|
||||
response_data = response.json()
|
||||
if response_data.get("error"):
|
||||
posthog.error("tool_execution_error", f"{tool_name}: {response_data['error']}")
|
||||
raise RuntimeError(f"Sandbox execution error: {response_data['error']}")
|
||||
return response_data.get("result")
|
||||
except httpx.HTTPStatusError as e:
|
||||
posthog.error("tool_http_error", f"{tool_name}: HTTP {e.response.status_code}")
|
||||
if e.response.status_code == 401:
|
||||
raise RuntimeError("Authentication failed: Invalid or missing sandbox token") from e
|
||||
raise RuntimeError(f"HTTP error calling tool server: {e.response.status_code}") from e
|
||||
except httpx.RequestError as e:
|
||||
error_type = type(e).__name__
|
||||
posthog.error("tool_request_error", f"{tool_name}: {error_type}")
|
||||
raise RuntimeError(f"Request error calling tool server: {error_type}") from e
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user