`logfire clean --logs` fails on Windows with `PermissionError` and leaves the credentials file in place

Open
#2,797 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@AdityaSreevatsaK is already working on this.

Since Nov 12, 2026.

  • #2803 by @AdityaSreevatsaK — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
cli, testing

Research direction

Start in logfire/_internal/cli/__init__.py, reading _cli_logging() and parse_clean around the files_to_delete loop. Reproduce with logfire clean --logs --yes on Windows and inspect test_clean[y] and test_clean[yes]. Done means cleanup removes the log, credentials, and read token without raising PermissionError; a linked open pull request already addresses this issue.

Written by the indexing model from the issue text.

Description

On Windows 11 with Python 3.11.9, at 90356e1 on main, in a directory containing .logfire/logfire_credentials.json, running logfire clean --logs --yes fails:

File ".../logfire/_internal/cli/__init__.py", line 132, in parse_clean
    file.unlink(missing_ok=True)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: '...\.logfire\log.txt'

logfire_credentials.json is still there afterwards. _cli_logging() keeps a logging.FileHandler open on LOGFIRE_LOG_FILE for the whole command, and parse_clean runs inside it and unlinks that same file. POSIX allows deleting an open file, Windows does not. The log file is first in files_to_delete, so the loop stops before it reaches the credentials and read token.

This is also why test_clean[y] and test_clean[yes] fail on Windows.

Two possible fixes: close the log handler before deleting the log file, or delete the log file after the logging context has exited. I am happy to send a small PR with a regression test, whichever you prefer.

Investigated with AI assistance (Claude Code). I ran and checked the results above myself.

Dominant language
Python
Stars
4.5k
Forks
365
Avg merge
1d 8h
Merged PRs (30d)
153

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pydantic/logfire

All issues in pydantic/logfire

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.