Repository navigation
fix(logging): isolate per-run log handlers and prevent root logger pollution (#295) - #608
Merged
codelion merged 1 commit intoNov 23, 2026
Conversation
…llution (algorithmicsuperintelligence#295) - Move OpenEvolve logging from the global root logger to the 'openevolve' package logger with propagate=False, avoiding host application namespace pollution. - Add current_run_id ContextVar and RunIsolationFilter to ensure handlers only emit records matching their active OpenEvolve run context during concurrent or sequential execution. - Prevent LoggerPrefixFilter from stacking prefixes when records pass through multiple handlers with different prefixes. - Implement _cleanup_logging(), close(), and __del__() to detach handlers and close file descriptors on completion or garbage collection. - Add comprehensive unit and regression tests in tests/test_parallel_logging_isolation.py.
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.
Summary
Fixes #295: Running multiple
OpenEvolveinstances concurrently or sequentially in the same Python process previously caused loggers to be clobbered because all handlers attached directly to the global root logger without run isolation filters.Key Changes
root_logger = logging.getLogger()to the package loggerpkg_logger = logging.getLogger("openevolve")withpropagate = False.current_run_idContextVarandRunIsolationFilterinopenevolve/utils/logging_utils.py.OpenEvolveinstance generates a uniquerun_idand attaches aRunIsolationFilter(self.run_id)to itsFileHandlerandStreamHandler.__init__andrun()scope logging tocurrent_run_id, guaranteeing that concurrentasyncioruns only emit into their respective log files and console streams without duplicate emissions.LoggerPrefixFilterto preserverecord._openevolve_orig_nameso applying filters with different prefixes across handlers does not stack prefixes (e.g.,RUN2.RUN1.openevolve.controller)._cleanup_logging(),close(), and__del__()toOpenEvolve, automatically detaching handlers fromopenevolveand closing open file descriptors whenrun()finishes, on explicitclose(), or upon garbage collection.openevolve/cli.pyso--log-levelupdates both the root andopenevolvepackage loggers.Testing & Verification
tests/test_parallel_logging_isolation.py:TestRunIsolationFilterUnit: verifies matching, non-matching, and un-scoped filter behavior.test_root_logger_is_not_polluted: verifies root logger handlers are not touched.test_concurrent_runs_do_not_cross_write_logs: verifies two concurrentOpenEvolveruns executed viaasyncio.gatheronly log to their respective log files.test_console_output_is_not_duplicated_across_instances: verifies console output is emitted only once per message.test_cleanup_removes_and_closes_handlers: verifies handlers are removed and file descriptors closed.test_run_lifecycle_manages_logging_context_and_cleanup: verifiesawait controller.run()sets run context and cleans up on completion.test_logger_prefix_does_not_stack: verifies prefixes do not nest across multiple filters.tests/test_logger_prefix.pyandtests/test_coevolution.pycontinue to pass (31/31 passed).black --checkandisort --check.