Fix time.sleep double-counting on Python 3.13+ - #12
Merged
adriaardila merged 1 commit intoJul 20, 2026
Merged
Conversation
time.sleep gained its own native sys.audit event in 3.13, so aiocop's own wrapper duplicated it. Only patch time.sleep below 3.13; recognize it unconditionally in BLOCKING_EVENTS_DICT regardless of source.
adriaardila
self-requested a review
July 20, 2026 14:35
adriaardila
approved these changes
Jul 20, 2026
adriaardila
left a comment
Collaborator
There was a problem hiding this comment.
Hey! Just checked it and you are correct. Nice catch and thanks for the PR.
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 #11
time.sleep()gained a nativesys.auditevent in Python 3.13, causing aiocop's wrapper to emit a duplicate event and inflate severity scores.Changes
time.sleep()on Python versions earlier than 3.13 (audit_patcher.py)time.sleepunconditionally inBLOCKING_EVENTS_DICT, regardless of whether the event originates from aiocop or the Python runtime (blocking_io.py)time.sleep()as an example of a function without a native audit eventNote
Low Risk
Targeted version gate and explicit event registration with regression tests; no auth or data-path changes.
Overview
Fixes inflated severity when
time.sleepruns on Python 3.13+, where the runtime already emits a nativesys.auditevent while aiocop’s patch wrapper was emitting a second one.time.sleepis only monkey-patched on Python < 3.13 (audit_patcher.py). On 3.13+, detection relies on the built-in audit event instead of the wrapper.time.sleepstays inBLOCKING_EVENTS_DICTon all versions (blocking_io.py), so sleep is still scored as heavy whether the event comes from the patch or from CPython.Docs and tests were updated: version-specific patching behavior is documented, and regression tests assert a single
time.sleepevent per call and thatget_patched_functions()only liststime.sleepbelow 3.13.Reviewed by Cursor Bugbot for commit 75b7f3a. Bugbot is set up for automated code reviews on this repo. Configure here.