Skip to content

fix(traces): create a saved view exclusively, so a file that appears after the name check is never replaced - #265

Merged
harenome merged 1 commit into
ThinkFlowLab:mainfrom
harenome:fix/save-trace-exclusive
Nov 20, 2026
Merged

harenome merged 1 commit into
ThinkFlowLab:mainfrom
harenome:fix/save-trace-exclusive

Conversation

@harenome

Copy link
Copy Markdown
Collaborator

Closes #260

What

save_trace checked that the name was free with os.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.md says 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:

  • A FileExistsError gives the same "already exists; nothing was overwritten." message and the same redirect. The separate os.path.exists check is gone, since the create covers it.
  • The view is serialised before the file is created, and a write that fails after the create removes the partial file.

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, then python3 app/tests/parallel.py app/ui_tests: 557 tests in 57 modules, OK.
  • New app/ui_tests/test_save_trace_exclusive.py, two tests:
    • a file created while the route filters the source (inside trace.filtered_document) keeps its content, and the page says the name exists;
    • a write that fails after the create (an injected ENOSPC) leaves no file, and the page shows the error.
  • With web/traces.py from main, both tests fail: the other file holds the saved view, and the view is left behind.

Risk

  • A taken name is now reported after the source is read and filtered, not before. The message and redirect are the same; only a broken source with a taken name now reports the source error first.
  • The view is held in memory as one string before it is written. A saved view is the size of its source trace, which the route already loads whole.

…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.
@harenome
harenome merged commit 2d7b982 into ThinkFlowLab:main Nov 20, 2026
2 checks passed
@harenome
harenome deleted the fix/save-trace-exclusive branch November 20, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Traces: saving a view can overwrite a file that appears after the name check

1 participant