Repository navigation
fix(pi): restore a snapshot of an empty workspace - #311
Merged
earakely-scale merged 1 commit intoOct 22, 2026
Merged
Conversation
_unpack extracted the workspace archive into a staging directory and then iterated it, but an empty workspace's archive has no members, so extractall never created the directory and iterdir raised FileNotFoundError: loading the snapshot failed with HTTP 500 after the existing workspace contents had already been removed. Create the staging directory before extracting, as the OpenHands agent does. Closes scaleapi#285 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
|
Thanks for making these fixes! |
earakely-scale
approved these changes
Oct 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Closes #285
PiAgent.load_snapshotrestores the workspace with_unpack, which extracts the archive into a staging directory and then iterates it. The archive of an empty workspace has no members, sotarfile.extractallnever creates the staging directory, andstaging.iterdir()raisedFileNotFoundError.PUT /ext/snapshottherefore failed with HTTP 500 and the conversation was not installed for the target context. The A2A validator's snapshot step hits this, since it snapshots an agent that hasn't written to its workspace.It's slightly worse than "nothing happens":
_unpackremoves the workspace's current contents before it iterates the staging directory. So a non-empty workspace restored from an empty snapshot ends up emptied anyway, while the request reports a failure.The fix creates the staging directory before extracting (
staging.mkdir()at the top of thetry), so an empty archive restores as an empty workspace. That's the approach the issue suggests and the one the OpenHands agent (#281) uses. A failed extraction still leaves the workspace untouched (test_a_workspace_archive_that_fails_to_extract_changes_nothing), and thefinallystill removes the staging directory.How it was tested
test_an_empty_workspace_archive_restores_an_empty_workspace:_packan empty directory,_unpackit over a workspace holding one file, and expect an empty workspace. It fails onmainwith theFileNotFoundErrorfrom the issue and passes here.main:FileNotFoundErroris raised and the workspace's file is already gone. With this change the restore completes and leaves an empty workspace.pytest tst/unit/agents/pi: 41 passed (40 onmainplus the new test).ruff checkclean on both files.Found and fixed with Claude Code. The runs above were executed locally.
🤖 Generated with Claude Code


Confidence Score: 5/5
This PR appears safe to merge.Summary
Creates the staging directory before extracting a Pi workspace snapshot, so an empty archive restores successfully.
Reviews (1) · Last reviewed commit: "fix(pi): restore a snapshot of an empty ..." · Reviewed by Greptile