Skip to content

fix: file-log rotation never fires again after process start - #2284

Open
raajkumars wants to merge 1 commit into
exo-explore:mainfrom
raajkumars:fix/log-rotation-blocking
Open

fix: file-log rotation never fires again after process start#2284
raajkumars wants to merge 1 commit into
exo-explore:mainfrom
raajkumars:fix/log-rotation-blocking

Conversation

@raajkumars

Copy link
Copy Markdown

Summary

The per-process file log's rotation trigger, introduced in #1438, is a generator that returns True exactly once and False forever after (_once_then_never). loguru calls the rotation callable on every message, so this correctly rotates once on startup — giving a fresh log file each run — but then silently disables every subsequent rotation for the rest of the process's life. The retention/compression settings on the same logger.add() call imply ongoing rotation is happening; it never is, so the log file grows without bound on a long-running process.

Fix

Replace the generator with a stateful rotation policy (_rotation_policy): still force-rotate on the first message (preserving the original fresh-log-per-run intent), then rotate again once the file crosses 200MB — the check the generator never actually performed despite the retention/compression config being set up as if it had. The threshold is currently hardcoded (_ROTATION_MAX_BYTES), not exposed as a CLI flag or env var.

Tests

Added src/exo/shared/tests/test_logging_rotation.py, 5 tests against the new policy directly (no I/O, a minimal fake file object standing in for what loguru passes to the rotation callable):

  • first call always rotates regardless of size
  • second call does not rotate while under the size threshold
  • rotates once file size + message length crosses the threshold
  • only the first call ever forces a rotation (no repeated startup-style behavior)
  • a tell() raising OSError is handled without propagating

All pass. ruff check, ruff format --check, and basedpyright are clean on both changed files.

The per-process file log's rotation trigger, introduced in exo-explore#1438, is a
generator that returns True exactly once and False forever after.
loguru calls the rotation callable on every message, so this correctly
rotated once on startup (a fresh log file per run) but then silently
disabled every subsequent rotation for the rest of the process's life.
The retention and compression settings on that same logger.add() call
implied ongoing rotation was happening; it never was, so a long-running
process's log file grows without bound.

Replace the generator with a stateful rotation policy: still rotate
once on the first message (preserving the fresh-log-per-run behavior),
then rotate again once the file crosses 200MB (hardcoded, not
currently exposed as a setting) -- the check the generator never
actually performed despite the retention/compression config being set
up as if it had.

Added unit tests for the new policy: startup rotation, no rotation
under the size threshold, rotation once the threshold is crossed,
no repeated startup-style rotation, and no crash if the file handle's
tell() raises.
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.

1 participant