Python: fix LineTooLong error in CopilotStudioAgent - #7321
Python: fix LineTooLong error in CopilotStudioAgent#7321Mahajan-Sachin wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses aiohttp’s LineTooLong failure mode when Copilot Studio returns very large SSE data: lines by replacing line-based streaming reads with chunk-based processing in the Copilot Studio Python integration, and adds a regression test that exercises a >512KB SSE line.
Changes:
- Monkeypatches
microsoft_agents.copilotstudio.client.CopilotClient.post_requestto consume SSE responses via raw chunks rather than line iteration. - Adds an async aiohttp test server that emits a 600KB
data:line and validates the client can parse it without raisingLineTooLong.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| python/packages/copilotstudio/agent_framework_copilotstudio/_agent.py | Monkeypatches CopilotClient SSE streaming read logic to avoid aiohttp’s line-length limit. |
| python/packages/copilotstudio/tests/test_line_too_long_bug.py | Adds regression test for >512KB SSE data: line handling. |
@microsoft-github-policy-service agree |
|
@microsoft-github-policy-service agree |
|
@copilot please check now |
|
Hey @Mahajan-Sachin please can you address the failing checks? |
…nto fix-copilot-studio-linetoolong
|
Hi @giles17, I've addressed the failing check:
Could you please approve the workflow runs so the CI checks can verify them on GitHub? Ready for review whenever you're free! |
Motivation & Context
This PR resolves Issue #7257 where calling
CopilotStudioAgentfails withaiohttp.http_exceptions.LineTooLong: 400when receiving streaming response data larger than 512KB (for example, when fetching a large payload from a Salesforce connector in Copilot Studio).The root cause is that the underlying dependency
microsoft-agents-copilotstudio-clientimplementsCopilotClient.post_requestusing line-based iteration (async for line in response.content:). Underaiohttp, line-based reading triggers a hardcoded limit of524288bytes (512 KB) for any single line.Proposed Changes
Since the client is an external dependency, we fix this in the framework layer by monkeypatching the client's HTTP request handler:
Monkeypatch
CopilotClient.post_request:post_requestinsideagent_framework_copilotstudio/_agent.pyto read the response content in raw chunks viaresponse.content.iter_any().\n) to parse SSE activities. This avoids line-limit exceptions entirely and handles lines of arbitrary length.reportPrivateUsagewarning with an inline comment, since monkeypatching requires access to the client's protected_current_conversation_idfield.Added Regression Test:
packages/copilotstudio/tests/test_line_too_long_bug.py.Testing & Validation
Unit Tests:
uv run pytest packages/copilotstudio/tests/test_line_too_long_bug.py # 1 passed in 0.17scopilotstudiopackage test suite:Static Analysis:
uv run poe check -P copilotstudio # All formatting, lint, Pyright, MyPy, Ty, and Zuban tasks passedCloses #7257