Repository navigation
fix(sandbox): accumulate successive writes in SandboxFileIO write mode - #126
Open
pcbeingused333 wants to merge 1 commit into
Open
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
write_file replaces the whole file, so each write() in 'w' mode dropped earlier blocks. Keep the accumulated content and only update it after write_file succeeds, so a failed write that is retried is not duplicated. Covers sync and async.
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.
Fixes the loss of earlier blocks when a file opened with
fs.open(path, "w")is written more than once.Root cause
SandboxFileIO.write/AsyncSandboxFileIO.writecallwrite_filewith only the new block inwmode, andwrite_filereplaces the whole remote file. Afterwrite("first\n"); write("second\n")the file contains onlysecond\n. Append mode already reads the existing content, so it was not affected.Fix
The handle keeps what it has written so far and sends the accumulated content on each
write()(sync and async). Mixingstrandbytesin one handle raisesTypeError, as append mode already does.Reproduction
Testing
pytest koyeb/sandbox/test_filesystem.py -k "accumulates or retry_after": before the change the twoaccumulatestests (sync and async) fail; after it all four pass. The tworetry_aftertests guard the new accumulated state: a failedwrite_filedoes not record the content, so retrying the samewritedoes not duplicate it.koyeb/sandbox/test_filesystem.py: 147 passed.AI assistance was used to prepare this change and its tests.