Skip to content

Fix time.sleep double-counting on Python 3.13+ - #12

Merged
adriaardila merged 1 commit into
Feverup:masterfrom
hadizamani021:fix/time-sleep-double-counting-py313
Jul 20, 2026
Merged

Fix time.sleep double-counting on Python 3.13+#12
adriaardila merged 1 commit into
Feverup:masterfrom
hadizamani021:fix/time-sleep-double-counting-py313

Conversation

@hadizamani021

@hadizamani021 hadizamani021 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #11

time.sleep() gained a native sys.audit event in Python 3.13, causing aiocop's wrapper to emit a duplicate event and inflate severity scores.

Changes

  • Only patch time.sleep() on Python versions earlier than 3.13 (audit_patcher.py)
  • Recognize time.sleep unconditionally in BLOCKING_EVENTS_DICT, regardless of whether the event originates from aiocop or the Python runtime (blocking_io.py)
  • Updated documentation and docstrings that described time.sleep() as an example of a function without a native audit event
  • Added tests verifying the exact number of emitted events (not just event detection) across Python 3.10–3.13

Note

Low Risk
Targeted version gate and explicit event registration with regression tests; no auth or data-path changes.

Overview
Fixes inflated severity when time.sleep runs on Python 3.13+, where the runtime already emits a native sys.audit event while aiocop’s patch wrapper was emitting a second one.

time.sleep is 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.sleep stays in BLOCKING_EVENTS_DICT on 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.sleep event per call and that get_patched_functions() only lists time.sleep below 3.13.

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

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
adriaardila self-requested a review July 20, 2026 14:35

@adriaardila adriaardila left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hey! Just checked it and you are correct. Nice catch and thanks for the PR.

@adriaardila
adriaardila merged commit 4451d4a into Feverup:master Jul 20, 2026
5 checks passed
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.

time.sleep is double-counted on Python 3.13+ — it already has a native audit event

2 participants