Skip to content

fix(core): survive concurrent Windows log cleanup - #1218

Merged
phernandez merged 2 commits into
mainfrom
codex/windows-log-cleanup-race
Aug 9, 2026
Merged

fix(core): survive concurrent Windows log cleanup#1218
phernandez merged 2 commits into
mainfrom
codex/windows-log-cleanup-race

Conversation

@phernandez

Copy link
Copy Markdown
Member

Why

What Changed

  • Treat stale Windows log files that disappear during timestamp lookup as already pruned, allowing cleanup and logging setup to continue.
  • Make the regression fixture keep file enumeration on the real filesystem, then trigger deletion specifically during the sort-key stat.
  • Assert that the simulated race actually occurred so the test proves the production handler.

Implementation Details

  • The first commit preserves @overgoy as author, retains the contributor DCO sign-off, and records original commit a00200e624162c62bfef6d00b44ba28d9030c7ad with cherry-pick -x.
  • The production change from fix(core): survive a stale Windows log deleted mid-cleanup (#1211) #1215 remains unchanged. The second, separately signed maintainer commit only corrects and strengthens its regression test.
  • This branch starts from current main, so it also includes changes landed after the contributor branch was created.

Testing

Automated

  • uv run --python 3.12 pytest tests/utils/test_setup_logging.py::test_setup_logging_survives_a_stale_log_deleted_mid_cleanup -q before the maintainer fix: reproduced RecursionError.
  • Same Python 3.12 targeted test after the fix: passed.
  • uv run --python 3.12 pytest tests/utils/test_setup_logging.py -q: 10 passed.
  • uv run pytest tests/utils/ -q: 166 passed.
  • just fast-check: passed.

Manual

  • No manual Windows run; the filesystem race is exercised deterministically at the failing boundary.

Risks / Follow-ups

overgoy and others added 2 commits August 9, 2026 12:41
Windows log files are per-PID, so every launch prunes the same shared
directory, and concurrent launches are the normal case for the Claude Code
plugin: several editor sessions plus a session-start hook each start a
process. The unlink in _cleanup_windows_log_files is guarded against another
launch removing a file first; the stat in the sort key that precedes it was
not, so FileNotFoundError escaped through setup_logging and ended the process
during logging setup.

When that process was the MCP server, the client saw the stdio connection
close a couple of seconds after launch and the session silently had no
basic-memory tools, while the bundled skills and slash commands went on
instructing against tools that were not there.

The sort key now treats a file that has already gone as oldest, which puts it
in the delete slice, where unlink is already guarded against the same race.

The test stands in for the racing launch by deleting the file during the stat
it is about to be sorted by.

Signed-off-by: overgoy <32526203+overgoy@users.noreply.github.com>
(cherry picked from commit a00200e)
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez
phernandez merged commit bc5e6af into main Aug 9, 2026
25 checks passed
@phernandez
phernandez deleted the codex/windows-log-cleanup-race branch August 9, 2026 18:14
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.

Windows: MCP server can die at startup on a log-cleanup race in _cleanup_windows_log_files

2 participants