Skip to content

pi: loading a snapshot of an empty workspace fails with FileNotFoundError #285

Open

Description

@VascoSch92

What happened?

Loading a pi snapshot whose workspace was empty fails with HTTP 500. PiAgent.load_snapshot restores the workspace with _unpack (src/agent_env/agents/agents/pi/pi_agent.py, line 333), which extracts the archive into a staging directory and then iterates it. An empty workspace's archive has no members, so tarfile.extractall never creates the staging directory, and staging.iterdir() raises FileNotFoundError. The workspace is left as it was, and the conversation is not installed for the target context.

The A2A validator's snapshot step saves the workspace of an agent that has not written to it, so it hits this path.

Reproduction on main (95a3a16):

import pathlib, tempfile
from tst.unit.agents.pi.agent import pi_agent

root = pathlib.Path(tempfile.mkdtemp())
(root / "empty").mkdir()
workspace = root / "ws"
workspace.mkdir()
pi_agent._pack(root / "empty", root / "w.tar.gz")
pi_agent._unpack(root / "w.tar.gz", workspace)

Suggested fix: create the staging directory before extracting (staging.mkdir() at the top of the try), so an empty archive restores as an empty workspace; a regression test can save and load a snapshot of an empty workspace. The OpenHands agent proposed in #281 had the same code and the same bug, fixed there this way.

Output and errors

FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/.../ws/.pi-a2a-restore-cb277f41ab7b4b20aaad1d5f17f53dec'

Output of agent-env plugin list

agent-env 0.9.1341 · uv project at .../agentenv-framework
config: (none)

PACKAGE             VERSION   PROVIDES                                      STATUS
agentenv-framework  0.9.1341  bundle agents, bundle echo-mcp, bundle hello  ok

Operating system

macOS 26.5 (arm64). The bug does not depend on the platform.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions