Repository navigation
fix(traces): create a saved view exclusively, so a file that appears after the name check is never replaced - #265
Merged
Conversation
…after the name check is never replaced save_trace checked that the name was free, read and filtered the source, then opened the destination with "w". A file created in between was truncated and replaced. The destination is now opened with "x": a FileExistsError gives the same "already exists" message, and a write that fails after the create removes the partial file.
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.
Closes #260
What
save_tracechecked that the name was free withos.path.exists, then read and filtered the source trace, then opened the destination with"w". A file created in between, for example by a second tab saving under the default name, was truncated and replaced..claude/rules/traces.mdsays the save refuses to overwrite anything at all.The destination is now opened with
"x"(exclusive create), so the check and the create are one step:FileExistsErrorgives the same "already exists; nothing was overwritten." message and the same redirect. The separateos.path.existscheck is gone, since the create covers it.Touches
routes (
web/traces.py) · tests (ui_tests/test_save_trace_exclusive.py)Verified
In a rootless Podman container (
python:3.12):python3 app/tests/parallel.py: 3104 tests in 157 modules, OK.pip install -r app/requirements.txt, thenpython3 app/tests/parallel.py app/ui_tests: 557 tests in 57 modules, OK.app/ui_tests/test_save_trace_exclusive.py, two tests:trace.filtered_document) keeps its content, and the page says the name exists;ENOSPC) leaves no file, and the page shows the error.web/traces.pyfrom main, both tests fail: the other file holds the saved view, and the view is left behind.Risk