Conversation
supermemory_profile_search is async, but without the optional aiohttp extra it falls back to requests.post, which blocks whatever event loop awaited it for the whole request. aiohttp is not installed by default, so on a plain pip install every memory search on the async path stalls the caller's loop. The fallback now runs requests.post through asyncio.to_thread. The new test forces the fallback and fails if the request holds the loop.
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.
supermemory_profile_search is async, but without aiohttp it falls back to requests.post, which holds the event loop for the whole request. aiohttp is only in the
asyncextra and requests is a hard dependency, so a plainpip install supermemory-openai-sdkalways lands on the fallback.numbers
Local server that takes 2s to answer the profile search, with a ticker on the same loop that should fire every 50ms. Longest gap between ticks:
#1503 fixes which path AsyncOpenAI takes and this fixes the path it lands on, so a default install needs both. #1503's branch is behind main, so I applied its dispatch check to main for those two rows.
fix
await asyncio.to_thread(requests.post, ...). to_thread is 3.9+, which matches requires-python.test
test_requests_fallback_does_not_block_event_loop in tests/test_middleware.py forces the fallback by setting aiohttp to None in sys.modules, and makes requests.post wait on an event that only the loop can set. It fails on main with "requests.post blocked the event loop" and passes here. The rest of the package suite is unchanged, 32 passed and 11 skipped.