-
Notifications
You must be signed in to change notification settings - Fork 0
fix(runner): Preserve isolated verification artifacts #2
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,22 +16,26 @@ class WorktreeProvisioner: | |
| def __init__(self, base_repo: str | Path, *, tmp_root: str | Path | None = None) -> None: | ||
| self.base_repo = Path(base_repo).resolve() | ||
| self.tmp_root = Path(tmp_root).resolve() if tmp_root else None | ||
| self._tempdir: tempfile.TemporaryDirectory[str] | None = None | ||
| self._tempdir: Path | None = None | ||
| self.path: Path | None = None | ||
|
|
||
| def provision(self) -> Path: | ||
| if not self.base_repo.exists() or not self.base_repo.is_dir(): | ||
| raise FileNotFoundError(f"base repo does not exist: {self.base_repo}") | ||
|
|
||
| self.cleanup() | ||
| self._tempdir = tempfile.TemporaryDirectory(prefix="safe-mini-", dir=self.tmp_root) | ||
| target = Path(self._tempdir.name) / "repo" | ||
| ignore = shutil.ignore_patterns(".git", "__pycache__", ".pytest_cache", ".mypy_cache") | ||
| shutil.copytree(self.base_repo, target, ignore=ignore) | ||
| home = target / ".agent-home" | ||
| home.mkdir(mode=0o700, exist_ok=True) | ||
| self.path = target | ||
| return target | ||
| self._tempdir = Path(tempfile.mkdtemp(prefix="safe-mini-", dir=self.tmp_root)) | ||
| try: | ||
| target = self._tempdir / "repo" | ||
| ignore = shutil.ignore_patterns(".git", "__pycache__", ".pytest_cache", ".mypy_cache") | ||
| shutil.copytree(self.base_repo, target, ignore=ignore) | ||
| home = target / ".agent-home" | ||
| home.mkdir(mode=0o700, exist_ok=True) | ||
| self.path = target | ||
| return target | ||
| except Exception: | ||
| self.cleanup() | ||
| raise | ||
|
|
||
| def env_for(self, cwd: Path) -> dict[str, str]: | ||
| return { | ||
|
|
@@ -43,7 +47,8 @@ def env_for(self, cwd: Path) -> dict[str, str]: | |
|
|
||
| def cleanup(self) -> None: | ||
| if self._tempdir is not None: | ||
| self._tempdir.cleanup() | ||
| if self._tempdir.exists(): | ||
| shutil.rmtree(self._tempdir) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When an agent creates a directory without read/execute permissions (for example, Useful? React with 👍 / 👎. |
||
| self._tempdir = None | ||
|
Comment on lines
49
to
52
|
||
| self.path = None | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If copying is interrupted by
KeyboardInterruptor anotherBaseException, this handler is skipped and the rawmkdtempdirectory has no finalizer, so a potentially large partial worktree remains permanently in the temp root. The formerTemporaryDirectoryobject supplied that fallback cleanup; ensure the new allocation is also removed while propagating non-Exceptioninterruptions.Useful? React with 👍 / 👎.