agents icon indicating copy to clipboard operation
agents copied to clipboard

Shared http session total timeout regressed to aiohttp's 300s default (#6941 reverted by #6977)

Open aniketwaghh opened this issue 3 months ago • 1 comments

Bug Description

#6941 raised the shared aiohttp.ClientSession total timeout to 900s because aiohttp's total is cumulative over the whole operation, body included, so a still-flowing streaming response is cancelled once it is reached.

#6977 ("fix: retry recording upload connection failures") reverted it. That PR is about recording uploads and its diff to utils/http_context.py is a pure deletion with no replacement:

-# aiohttp's total is cumulative over the whole operation, body consumption included,
-# so a still-flowing streaming response is cancelled once it's reached. sock_connect is
-# restated because a bare ClientTimeout(total=...) drops aiohttp's 30s default to None.
-_DEFAULT_TIMEOUT = aiohttp.ClientTimeout(total=900, sock_connect=30)
...
-            g_session = aiohttp.ClientSession(
-                proxy=http_proxy, connector=connector, timeout=_DEFAULT_TIMEOUT
-            )
+            g_session = aiohttp.ClientSession(proxy=http_proxy, connector=connector)

It looks like a stale branch: #6977 was likely cut before #6941 landed, and the merge took the older copy of the file.

The reason nobody noticed is that the same commit also removed the test that guarded it (tests/test_http_context_helper.py, -7 lines), which asserted session.timeout.total == 900. With the assertion gone, CI stayed green.

Current behavior

On cdb37ad:

async with http_context.open() as s:
    print(s.timeout.total)        # 300
    print(s.timeout.sock_connect) # 30

300 is aiohttp.client.DEFAULT_TIMEOUT.total, so the shared session is back to the library default and every consumer of http_context inherits a 5-minute cap on total operation time again. sock_connect=30 survives only because it is aiohttp's own default, not because the code sets it.

Expected behavior

What #6941 established: total=900, with sock_connect=30 restated explicitly (a bare ClientTimeout(total=...) drops aiohttp's 30s connect default to None).

Steps to reproduce

python - <<'PY'
import aiohttp, asyncio
from livekit.agents.utils import http_context

async def main():
    async with http_context.open() as s:
        print("total:", s.timeout.total, "sock_connect:", s.timeout.sock_connect)
    print("aiohttp default total:", aiohttp.client.DEFAULT_TIMEOUT.total)

asyncio.run(main())
PY
total: 300 sock_connect: 30
aiohttp default total: 300

Expected total: 900.

Package Versions

main @ cdb37ad

Note

Happy to open the PR restoring the constant and its test — say the word if you would rather handle it, since both PRs are yours, @chenghao-mou.

aniketwaghh avatar Aug 29 '26 10:08 aniketwaghh

Retracting this — I was wrong, apologies for the noise.

#6977 did not revert #6941 by accident. Its description says so directly: "Keep the 900-second timeout on this upload only. Other users of the shared HTTP session use aiohttp defaults again." It also added test_shared_session_uses_aiohttp_default_timeout, which pins the shared session to aiohttp's default on purpose. So total == 300 on main is the intended behavior, the long timeout now scoped to the recording upload where a non-idempotent POST needs it.

I read the diff and the commit subject and inferred a stale-branch merge without reading #6977's description, which stated the intent plainly. That was careless. Closing.

aniketwaghh avatar Aug 29 '26 10:08 aniketwaghh