Skip to content

fix: remove reset in sandbox runner #714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/codegen/runner/clients/codebase_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def _wait_for_server(self, timeout: int = 30, interval: float = 0.3) -> None:
def _get_envs(self) -> dict:
envs = os.environ.copy()
codebase_envs = {
"REPOSITORY_LANGUAGE": self.repo_config.language.value,
"REPOSITORY_OWNER": self.repo_config.organization_name,
"REPOSITORY_PATH": str(self.repo_config.repo_path),
"REPOSITORY_OWNER": self.repo_config.organization_name,
"REPOSITORY_LANGUAGE": self.repo_config.language.value,
"GITHUB_TOKEN": SecretsConfig().github_token,
}

Expand Down
21 changes: 0 additions & 21 deletions src/codegen/runner/sandbox/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from codegen.runner.sandbox.runner import SandboxRunner
from codegen.shared.exceptions.compilation import UserCodeException
from codegen.shared.logging.get_logger import get_logger
from codegen.shared.performance.stopwatch_utils import stopwatch

logger = get_logger(__name__)

Expand All @@ -34,13 +33,10 @@ async def dispatch(self, request: TRequest, call_next: RequestResponseEndpoint)
return await call_next(request)

async def process_request(self, request: TRequest, call_next: RequestResponseEndpoint) -> TResponse:
background_tasks = BackgroundTasks()
try:
logger.info(f"> (CodemodRunMiddleware) Request: {request.url.path}")
self.runner.codebase.viz.clear_graphviz_data()
response = await call_next(request)
background_tasks.add_task(self.cleanup_after_codemod, is_exception=False)
response.background = background_tasks
return response

except UserCodeException as e:
Expand All @@ -52,21 +48,4 @@ async def process_request(self, request: TRequest, call_next: RequestResponseEnd
message = f"Unexpected error for {request.url.path}"
logger.exception(message)
res = JSONResponse(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, content={"detail": message, "error": str(e), "traceback": traceback.format_exc()})
background_tasks.add_task(self.cleanup_after_codemod, is_exception=True)
res.background = background_tasks
return res

async def cleanup_after_codemod(self, is_exception: bool = False):
if is_exception:
# TODO: instead of committing transactions, we should just rollback
logger.info("Committing pending transactions due to exception")
self.runner.codebase.ctx.commit_transactions(sync_graph=False)
await self.reset_runner()

@stopwatch
async def reset_runner(self):
logger.info("=====[ reset_runner ]=====")
logger.info(f"Syncing runner to commit: {self.runner.commit} ...")
self.runner.codebase.checkout(commit=self.runner.commit)
self.runner.codebase.clean_repo()
self.runner.codebase.checkout(branch=self.runner.codebase.default_branch, create_if_missing=True)
6 changes: 3 additions & 3 deletions src/codegen/runner/sandbox/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ async def lifespan(server: FastAPI):
global server_info
global runner

default_repo_config = RepositoryConfig()
repo_name = default_repo_config.full_name or default_repo_config.name
server_info = ServerInfo(repo_name=repo_name)
try:
default_repo_config = RepositoryConfig()
repo_name = default_repo_config.full_name or default_repo_config.name
server_info = ServerInfo(repo_name=repo_name)
logger.info(f"Starting up sandbox fastapi server for repo_name={repo_name}")
repo_config = RepoConfig(
name=default_repo_config.name,
Expand Down
Loading