Skip to content

fix(logging): restore configured levels after suppression - #8215

Merged
Vidit Ostwal (Vidit-Ostwal) merged 2 commits into
crewAIInc:mainfrom
lakers-abing:fix/restore-suppressed-logger-level
Oct 26, 2026
Merged

Vidit Ostwal (Vidit-Ostwal) merged 2 commits into
crewAIInc:mainfrom
lakers-abing:fix/restore-suppressed-logger-level

Conversation

@lakers-abing

@lakers-abing lakers-abing commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Related issue

Fixes #8214

Summary

Restore the logger's configured level when suppress_logging() exits, including after exceptions and interruptions. Previously, a failed ChromaDB query could leave its logger at ERROR, hiding subsequent warnings. Successful calls also replaced NOTSET with the parent's current effective level, disabling later inheritance.

Save logger.level and restore it in finally. Preserve the existing stdout/stderr redirection and UserWarning suppression. Five regression cases cover normal exit, ordinary errors, interruption, and parent-level changes after inherited-level restoration.

Verification

  • Tests added or updated for the changed behavior

  • Relevant tests and quality checks pass locally

  • Before the fix: 4 failed, 1 passed in test_logger_utils.py.

  • After the fix: 58 passed across that file and the existing ChromaDB suites.

  • Ruff check and format: passed for the changed source; formatting also checked for the test file.

  • Strict mypy on logger_utils.py: passed.

  • git diff --check: passed.

Fresh Python 3.13.15 environment installed with uv sync --locked --package crewai --group dev. Pytest used -n 0 -q and the repository's network block. A local launcher redirected import-time credential storage to a temporary directory; all CrewAI modules were imported normally. No live providers were called. The full repository suite was not run.

Validated again on 2026-10-20 after rebasing onto upstream main at 4f4573706ea4afee6c4da4c31cfb9622a4495ab7: 58 related tests passed; Ruff lint/format, strict mypy and whitespace checks passed. The final PR head is 0062db8; the two changed source/test files are byte-for-byte identical to the previously reviewed head.

Additional context

AI assistance: OpenAI Codex inspected the production callers and prior contributions, wrote the fix and behavioral tests, and ran the checks above. This PR is AI-generated and requires the llm-generated label.

This change restores sequential context-manager behavior; it does not redesign process-wide logging concurrency.


Note

Low Risk
Narrow change to a logging helper used around ChromaDB calls; behavior is more correct on failure with regression tests and no auth or data-path impact.

Overview
Fixes suppress_logging() so it always puts the target logger back to how it was configured, including when the wrapped block raises or is interrupted.

The context manager now saves logger.level (not the effective level) and restores it in a finally block, so a failed ChromaDB query no longer leaves the logger stuck at ERROR, and loggers using NOTSET keep inheriting from the parent after suppression. Stdout/stderr redirection and UserWarning suppression are unchanged.

Adds test_logger_utils.py with parametrized tests for normal exit, errors, KeyboardInterrupt, and NOTSET inheritance after failures.

Reviewed by Cursor Bugbot for commit e63764d. Bugbot is set up for automated code reviews on this repo. Configure here.

@strix-security

strix-security Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Strix Security Review

Warning

This pull request has 75 commits after the last Strix review (2c9355c). Strix has not reviewed these changes.
Automatic review on push is off for this repository. To review the latest changes, tag @strix-security in a comment, or turn on re-review on push.

No security issues found.

Review summary

Reviewed the logging-suppression fix in lib/crewai/src/crewai/utilities/logger_utils.py and its new test file. The change restores the logger's configured level (via logger.level instead of getEffectiveLevel()) in a finally block, preserving NOTSET inheritance and ensuring restoration on exceptions. The modified code handles only internal, hardcoded logger names and levels, reaches no security-sensitive sink, and introduces no injection, data exposure, auth, crypto, or access-control concerns. The pre-existing non-atomicity of setLevel under concurrency is unchanged and out of scope, with no demonstrable security impact. No security vulnerabilities were identified.

Updated for 2c9355c.


Reviewed by Strix
Re-run review · Configure security review settings

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5fa5e0d7-4066-4ec5-97ba-7e826f660674
📥 Commits

Reviewing files that changed from the base of the PR and between 2c9355c and e63764d.

📒 Files selected for processing: 1
  • lib/crewai/tests/utilities/test_logger_utils.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

suppress_logging now restores the logger’s configured level after normal or exceptional exits. Added tests cover restoration after errors and interruptions, and preservation of NOTSET inheritance.

Changes: Logger level restoration

Layer / File(s) Summary
Restore logger levels after suppression
lib/crewai/src/crewai/utilities/logger_utils.py, lib/crewai/tests/utilities/test_logger_utils.py
suppress_logging saves the configured level and restores it in finally. Tests cover normal exit, exceptions, interruptions, and inherited levels. Existing stdout/stderr redirection and UserWarning suppression remain unchanged.

Suggested reviewers: joaomdmoura

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to e6376

The supplied evidence identifies no issue requiring resolution before merge.

Pre-merge checks: Passed 5
Check name Status Explanation
Description check Passed The description includes the required Related issue, Summary, Verification, and Additional context sections. It identifies issue #8214, explains the fix, documents verification results and limitations…
Title check Passed The title clearly and concisely describes the main change: restoring configured logger levels after suppression.
Linked Issues check Passed The pull request satisfies the coding requirements in issue #8214. suppress_logging() saves logger.level and restores it in finally, including after exceptions and KeyboardInterrupt. This pres…
Out of Scope Changes check Passed The changes are limited to logger_utils.py and focused regression tests. The production change implements issue #8214. The tests verify its required behavior. No unrelated changes are identified.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files.
Full details: Description check

Explanation

The description includes the required Related issue, Summary, Verification, and Additional context sections. It identifies issue #8214, explains the fix, documents verification results and limitations, and provides relevant context.

Full details: Linked Issues check

Explanation

The pull request satisfies the coding requirements in issue #8214. suppress_logging() saves logger.level and restores it in finally, including after exceptions and KeyboardInterrupt. This preserves NOTSET inheritance and leaves exception propagation unchanged. The existing stdout/stderr redirection and UserWarning suppression remain. The regression tests cover normal exit, errors, interruption, and parent-level changes.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@lakers-abing

Copy link
Copy Markdown
Contributor Author

This PR and issue #8214 were prepared with OpenAI Codex, as disclosed in both descriptions. My account cannot apply repository labels (HTTP 403). Could a maintainer please add llm-generated to both? Thank you.

@lakers-abing
lakers-abing force-pushed the fix/restore-suppressed-logger-level branch from 2c9355c to e63764d Compare October 18, 2026 14:53
@lakers-abing

Copy link
Copy Markdown
Contributor Author

Rebased onto current upstream main (40bb2d3b586e8367d206090cc62df5242206008f) and added docstrings describing the logger fixture and both regression tests. Every function in the two touched files now has a docstring (5/5 by local AST inspection); the remote CodeRabbit result still needs its next run.

Revalidated on Python 3.13.15 with uv sync --locked --package crewai --group dev:

  • Logging regression file plus existing ChromaDB suites: 58 passed.
  • Ruff check on the production file and format check on both files: passed.
  • Strict mypy on logger_utils.py: passed.
  • git diff --check: passed.

Pytest used -n 0 -q and the repository network block. The local launcher redirected import-time credential/data/cache paths to a fresh temporary directory; CrewAI modules were imported normally, and the logging implementation was not stubbed. No live providers or full repository suite were run. The production logging file is byte-for-byte identical to the previous PR head. Commit identity was also corrected to my GitHub-linked account.

@lakers-abing
lakers-abing force-pushed the fix/restore-suppressed-logger-level branch 2 times, most recently from 72a12d0 to 0062db8 Compare October 20, 2026 14:41
@Vidit-Ostwal
Vidit Ostwal (Vidit-Ostwal) force-pushed the fix/restore-suppressed-logger-level branch from 0062db8 to b155ff7 Compare October 26, 2026 16:59

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Vidit-Ostwal
Vidit Ostwal (Vidit-Ostwal) merged commit 5d4f45b into crewAIInc:main Oct 26, 2026
88 of 90 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your first contribution to CrewAI, lakers-abing!

We really appreciate the time and care you put into this PR. Your work is now part of CrewAI — welcome to the contributor community.

Want to share your contribution? Totally optional:

Share on X · Share the PR on LinkedIn

If the links don't work, feel free to copy and personalize this:

I just made my first contribution to @crewAIInc!

Excited to help build the future of AI agents with CrewAI.

https://github.com/crewAIInc/crewAI/pull/8215

#OpenSource #AI #CrewAI

If you share, we'd love to see it — tag crewAI (@crewAIInc) on X and CrewAI on LinkedIn.

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.

[BUG] suppress_logging leaves logger levels changed after exit

2 participants