fix(mcp): narrow time.sleep mock target to tools.mcp_tool to stop background-thread mock pollution - #27589
Merged
Merged
Conversation
Contributor
🔎 Lint report:
|
3 tasks
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
Final remaining failure on main Tests workflow.
tests/tools/test_mcp_stability.py::TestStdioPidTracking::test_kill_orphaned_uses_sigkill_when_availablegot'sleep' called 225571 timesin CI but passed locally. Classic global-patch interaction with concurrent threads.Root cause
_kill_orphaned_mcp_children()didimport time as _timeinside the function body and called_time.sleep(2). The test patched the globaltime.sleepwithunittest.mock.patch("time.sleep")— which replacestime.sleepfor the entire process. Background daemon threads fromtools/process_registry.py:1055andtools/terminal_tool.py:1331(both running periodic 1s-cadence reaper loops) suddenly hit a MagicMock instead of real sleep, looped as fast as possible, and accumulated ~225k spuriouscall(1)entries during the 2s the patch context was open.Local runs only see this when those background loops are warm; CI runners have them up earlier in the process lifecycle so the race fires reliably.
Changes
tools/mcp_tool.py— drop theimport time as _timeinside_kill_orphaned_mcp_children; use the module-leveltimeimport (top of file). Production semantics unchanged.tests/tools/test_mcp_stability.py— bothtest_kill_orphaned_*tests now patchtools.mcp_tool.time.sleepinstead oftime.sleep, so the mock is scoped to the production module'stimereference only. Background threads in other modules sleep normally.Validation
scripts/run_tests.sh tests/tools/test_mcp_stability.py -q→ 16/16 pass.After this, main's Tests workflow should be green for the first time in many hours.