Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/agent_env/agents/agents/pi/pi_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ def _unpack(archive: Path, directory: Path) -> None:
inside it first, so one that fails to extract leaves the contents as they were."""
staging = directory / f".pi-a2a-restore-{uuid.uuid4().hex}"
try:
# An empty workspace's archive has no members, so extraction creates nothing.
staging.mkdir()
with tarfile.open(archive) as tar:
tar.extractall(staging, filter="data")
for child in directory.iterdir():
Expand Down
14 changes: 14 additions & 0 deletions tst/unit/agents/pi/test_pi_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,20 @@ def test_a_workspace_archive_that_fails_to_extract_changes_nothing(tmp_path: Pat
assert [path.name for path in workspace.iterdir()] == ["keep.txt"]


def test_an_empty_workspace_archive_restores_an_empty_workspace(tmp_path: Path) -> None:
empty = tmp_path / "empty"
empty.mkdir()
archive = tmp_path / "workspace.tar.gz"
pi_agent._pack(empty, archive)
workspace = tmp_path / "ws"
workspace.mkdir()
(workspace / "later.txt").write_text("written after the snapshot")

pi_agent._unpack(archive, workspace)

assert list(workspace.iterdir()) == []


def test_restoring_the_workspace_waits_for_no_running_task(
tmp_path: Path, record: Path, objects: dict[str, bytes]
) -> None:
Expand Down
Loading