fix(logging): use ConcurrentRotatingFileHandler to fix Windows rollover PermissionError (#44873) - #44904
Closed
tuancookiez-hub wants to merge 1 commit into
Conversation
…ver()`` fails with ``PermissionError [WinError 32]`` whenever any other thread holds an append-mode handle — which is always in Hermes. Result: stderr gets a full traceback on every ``emit()`` and ``agent.log`` pins at the 5 MiB threshold. Swap in ``concurrent_log_handler.ConcurrentRotatingFileHandler`` (copy-then-truncate on Windows, atomic rename on POSIX) and wrap ``doRollover`` in ``try/except PermissionError`` as defense in depth. Tests updated to use the new module-level ``_ROTATING_BASE`` selector. Closes NousResearch#44873
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #44873.
Summary
RotatingFileHandler.doRollover()raisesPermissionError [WinError 32]on Windows when background threads (gateway, agent loop, TTS, subagent
RPC) hold concurrent handles to
agent.log, producing noisy tracebackson every log emit and pinning the file at the 5 MiB threshold.
The fix swaps stdlib
RotatingFileHandlerforconcurrent_log_handler.ConcurrentRotatingFileHandler, which usescopy-then-truncate on Windows (works while the source is open) and
keeps the atomic rename on POSIX. Same constructor signature, drop-in
replacement, no API change.
As defense in depth, the existing
doRolloveroverride now wrapssuper().doRollover()intry/except PermissionErrorso any futuretransient failure is swallowed silently instead of spamming stderr.
Changes (4 files, ~134 lines)
hermes_logging.py— parent class swap,try/exceptwrap, idempotency check, docstringpyproject.toml— exact-pinnedconcurrent-log-handler==0.9.29with justification commentuv.lock— lock entry for the new dep +portalockertests/test_hermes_logging.py—isinstancechecks updated to use the new_ROTATING_BASEselectorVerification
Multi-thread Windows repro at
maxBytes=256:Test suite: 60/62 pass. The 2
test_managed_mode_*failures arepre-existing on Windows (Python's
os.chmodis a no-op for Unixpermission bits) and out of scope per the project's one-fix-per-PR
convention.
Tradeoffs
Django and AWS CLI for the same reason. Could be gated as an
extras_require(win-only) but every Windows install hits this onceagent.logreaches 5 MiB, so base install seems right..__filename.lockfiles next to each log (multi-processsafety). Harmless; same pattern stdlib's
SMTPHandleruses.