mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-09-30 10:23:14 +00:00
fix: recover from sandbox connection failures by recreating sandbox and re-cloning repo
This commit is contained in:
parent
84ae60ad49
commit
3066b3fc84
1 changed files with 25 additions and 0 deletions
|
|
@ -26,6 +26,8 @@ from deepagents.backends.protocol import SandboxBackendProtocol
|
|||
from langchain_openai import ChatOpenAI
|
||||
|
||||
from .encryption import decrypt_token
|
||||
from langsmith.sandbox import SandboxClientError
|
||||
|
||||
from .integrations.langsmith import create_langsmith_sandbox
|
||||
from .middleware import (
|
||||
ToolErrorMiddleware,
|
||||
|
|
@ -242,6 +244,29 @@ async def get_agent(config: RunnableConfig) -> Pregel: # noqa: PLR0915
|
|||
repo_dir = await _clone_or_pull_repo_in_sandbox(
|
||||
sandbox_backend, repo_owner, repo_name, github_token
|
||||
)
|
||||
except SandboxClientError:
|
||||
logger.warning(
|
||||
"Cached sandbox is no longer reachable for thread %s, recreating sandbox",
|
||||
thread_id,
|
||||
)
|
||||
SANDBOX_BACKENDS.pop(thread_id, None)
|
||||
await client.threads.update(
|
||||
thread_id=thread_id,
|
||||
metadata={"sandbox_id": SANDBOX_CREATING},
|
||||
)
|
||||
try:
|
||||
sandbox_backend = await asyncio.to_thread(create_langsmith_sandbox)
|
||||
repo_dir = await _clone_or_pull_repo_in_sandbox(
|
||||
sandbox_backend, repo_owner, repo_name, github_token
|
||||
)
|
||||
await client.threads.update(
|
||||
thread_id=thread_id,
|
||||
metadata={"repo_dir": repo_dir},
|
||||
)
|
||||
except Exception:
|
||||
logger.exception("Failed to recreate sandbox after connection failure")
|
||||
await client.threads.update(thread_id=thread_id, metadata={"sandbox_id": None})
|
||||
raise
|
||||
except Exception:
|
||||
logger.exception("Failed to pull repo in cached sandbox")
|
||||
raise
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue