Async streaming response wrappers leak an unawaited coroutine when not entered
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
Research direction
Start in src/browserbase/_response.py:632-637 and 669-685, comparing AsyncResponseContextManager with the synchronous ResponseContextManager. Reproduce the discarded, unentered manager case from the issue, then add a lifecycle test showing that no unawaited-coroutine warning is emitted and that entering the manager still performs the expected request.
Written by the indexing model from the issue text.
Description
Description
The async .with_streaming_response wrappers create the endpoint coroutine immediately, before the returned context manager is entered. If the context manager is conditionally discarded or never entered, Python emits RuntimeWarning: coroutine ... was never awaited.
This differs from the synchronous wrapper, which stores a callable and does not invoke the endpoint until __enter__.
Code reference
src/browserbase/_response.py:669-685AsyncResponseContextManagerstores an already-createdAwaitableatsrc/browserbase/_response.py:632-637
Reproduction
import asyncio
import gc
import warnings
from browserbase import AsyncBrowserbase
async def main():
client = AsyncBrowserbase(api_key="test")
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
cm = client.sessions.with_streaming_response.create(project_id="p")
del cm
gc.collect()
await asyncio.sleep(0)
print([str(w.message) for w in caught])
await client.close()
asyncio.run(main())
Actual output includes:
coroutine 'AsyncSessionsResource.create' was never awaited
No HTTP request is needed to reproduce this.
Expected behavior
Creating and discarding an unentered response context manager should not allocate an unawaited coroutine or emit a resource warning. The async manager could retain a callable/partial and invoke it lazily from __aenter__, matching ResponseContextManager.
Why it matters
Warnings are promoted to errors in many test suites, and conditional streaming code can produce noisy, nondeterministic resource warnings. This path currently has no direct lifecycle test.
- Dominant language
- Python
- Stars
- 93
- Forks
- 16
- Avg merge
- 11m
- Merged PRs (30d)
- 3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from browserbase/sdk-python
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
browserbase/sdk-python#182 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
browserbase/sdk-python#180 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
browserbase/sdk-python#179 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
browserbase/sdk-python#178 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
browserbase/sdk-python#176 ·
All issues in browserbase/sdk-python
Similar issues
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
simonw/sqlite-utils#872 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100