Skip to content

fix(desktop): rotate backend.log instead of truncating it on launch - #298

Merged
thcp merged 1 commit into
mainfrom
fix/desktop-log-rotation
Jul 17, 2026
Merged

fix(desktop): rotate backend.log instead of truncating it on launch#298
thcp merged 1 commit into
mainfrom
fix/desktop-log-rotation

Conversation

@thcp

@thcp thcp commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Closes #278. Phase 1 of #272 — plan: #272 (comment) (PR-1B).

What

prepare_backend_stdio ran fs::File::create(log_path), truncating the previous session's backend.log on every launch. The natural user response to a crash is "restart and retry" — which erased exactly the evidence needed to diagnose it (this is why the Mac Mini "Audio processing failed" reporter had nothing to paste).

New rotate_log(log_path, 3): backend.logbackend.log.1backend.log.2, oldest dropped, then the session opens a fresh append-mode log as before.

Two Windows-specific details handled:

  • fs::rename fails when the destination exists on Windows → the oldest generation is remove_file'd first, then the rest shift up.
  • All operations are best-effort (let _ =) — a locked file must never block app launch; worst case we append to the old log, which still beats truncating it.

Validation

  • cargo clippy via WSL: compiles clean; the 3 existing warnings are pre-existing (main.rs:72/232/972), none in this change. (PR CI does not build the Rust desktop app.)
  • Manual check after merge: launch the app twice → backend.log.1 holds the prior session.

🤖 Generated with Claude Code

fs::File::create zeroed the previous session's log on every launch. The
natural response to a crashed session is "restart and retry" -- which
destroyed exactly the evidence needed to diagnose the crash (the Mac
Mini "audio processing failed" report had nothing to paste because of
this).

backend.log now rotates to backend.log.1 / backend.log.2 (oldest
dropped) before the new session opens it. All renames are best-effort:
a locked file on Windows must never block launch -- worst case we
append to the old file, which still beats truncating it. The oldest
generation is removed first because Windows fs::rename fails when the
destination exists.

Closes #278
@thcp
thcp merged commit 60959e7 into main Jul 17, 2026
8 checks passed
@thcp
thcp deleted the fix/desktop-log-rotation branch July 17, 2026 00:21
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.

Desktop truncates backend.log on every launch

1 participant