fix(sandbox): run post-rename cleanup as the editor's bound user#3536
Open
vidigoat wants to merge 1 commit into
Open
fix(sandbox): run post-rename cleanup as the editor's bound user#3536vidigoat wants to merge 1 commit into
vidigoat wants to merge 1 commit into
Conversation
In WorkspaceEditor.apply_operation, an update_file with move_to writes the renamed file as self._user but removed the original path with a bare self._session.rm(destination), dropping the user. Every other session call in the editor threads user=self._user, so on a non-default user the cleanup ran as the wrong identity (permission error mid-rename, or removal under the wrong privileges leaving the original orphaned). Pass user=self._user. Adds a regression test asserting the move cleanup runs as the bound user. Signed-off-by: Vidit Patankar <vidit.patankar16@gmail.com>
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.
Summary
In
WorkspaceEditor.apply_operation(src/agents/sandbox/apply_patch.py), anupdate_fileoperation withmove_towrites the renamed file as the editor's bound user but removes the original path with a bareself._session.rm(destination)— dropping the user:Every other session call in this class threads
user=self._user(delete_fileat line 71, reads,mkdir,write). This one cleanup was the only exception, so when aWorkspaceEditor/SandboxApplyPatchToolis bound to a non-default user, the post-rename removal ran under the wrong identity — a permission error mid-operation (after the new file is already written), or a removal under the wrong privileges that leaves the original file orphaned and the rename half-applied.Fix
Pass
user=self._user, matching the siblingdelete_filepath and every other session call.Test
Added
test_editor_runs_move_cleanup_as_bound_user, which runs anupdate_filewithmove_tothroughUserRecordingApplyPatchSessionand asserts the cleanuprmruns as the bound user. It fails on the previous code (rm_users == [None]) and passes with the fix.Verified locally: