Python: fix CopilotStudioAgent LineTooLong on large activities - #7417
Python: fix CopilotStudioAgent LineTooLong on large activities#7417giles17 wants to merge 1 commit into
Conversation
Bump microsoft-agents-copilotstudio-client to >=1.2.0,<2 and forward a configurable read_bufsize (default 1 MiB) to the underlying aiohttp ClientSession via ConnectionSettings.client_session_settings. Copilot Studio streams each activity as a single SSE data line, so activities larger than aiohttp's 512 KB per-line limit previously raised aiohttp.http_exceptions.LineTooLong. Adds a client_session_settings parameter to CopilotStudioAgent and unit tests covering the default, override, and partial-settings cases. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 2766dc09-ab5f-4adc-8627-98361d7ccef0
There was a problem hiding this comment.
Pull request overview
This PR addresses aiohttp.http_exceptions.LineTooLong failures when Copilot Studio streams large SSE data: lines by increasing the aiohttp per-line buffer used by the underlying Copilot Studio client. It does this at the framework layer by forwarding client_session_settings into ConnectionSettings and defaulting read_bufsize to 1 MiB for internally constructed clients.
Changes:
- Bumps
microsoft-agents-copilotstudio-clientdependency to>=1.2.0,<2to rely on theConnectionSettings.client_session_settingspassthrough. - Adds a
client_session_settingskeyword-only parameter toCopilotStudioAgentand injects a defaultread_bufsize(DEFAULT_READ_BUFSIZE = 1 MiB) when not explicitly provided. - Adds unit tests covering the default behavior, explicit overrides, and partial settings merging.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| python/packages/copilotstudio/agent_framework_copilotstudio/_agent.py | Adds client_session_settings plumbing and a default read_bufsize to prevent LineTooLong on large SSE activities. |
| python/packages/copilotstudio/pyproject.toml | Updates the Copilot Studio client dependency range to a version that supports session settings passthrough. |
| python/packages/copilotstudio/tests/test_copilot_agent.py | Adds tests validating default injection and preservation/override behavior for client_session_settings. |
There was a problem hiding this comment.
Automated Code Review
Reviewers: 5 | Confidence: 81%
✓ Correctness
No actionable issues found in this dimension.
✓ Security Reliability
No actionable issues found in this dimension.
✓ Test Coverage
No actionable issues found in this dimension.
✓ Failure Modes
No actionable issues found in this dimension.
✗ Design Approach
The buffer-size change fixes the convenience constructor path, but it does not cover the package’s documented explicit-settings/client configuration flow. As written, users who follow those supported examples can still hit the same
LineTooLongfailure on large activities, so I would ask for this gap to be addressed before merging.
Flagged Issues
-
python/packages/copilotstudio/agent_framework_copilotstudio/_agent.py:167-175only injectsclient_session_settingswhenCopilotStudioAgentconstructsConnectionSettingsitself. The package's documented explicit configuration paths inpython/packages/copilotstudio/README.md:63-73andpython/samples/02-agents/providers/copilotstudio/README.md:76-85still construct a defaultConnectionSettings/CopilotClient, so large SSE activities remain on the old 512 KB per-line limit there.
Automated review by giles17's agents
| cloud=cloud, | ||
| copilot_agent_type=agent_type, | ||
| custom_power_platform_cloud=custom_power_platform_cloud, | ||
| client_session_settings=resolved_session_settings, |
There was a problem hiding this comment.
This only fixes the internally-built-client path. The package's own explicit configuration examples still create ConnectionSettings(...) and CopilotStudioAgent(client=client) without client_session_settings (python/packages/copilotstudio/README.md:63-73, python/samples/02-agents/providers/copilotstudio/README.md:76-85), so a >512 KB activity will still fail with LineTooLong there. Please either apply the same default when settings is supplied (and client is not), or update the documented explicit path and add coverage for it.
|
Flagged issue
Source: automated DevFlow PR review |
Motivation & Context
Calling a
CopilotStudioAgentfails withaiohttp.http_exceptions.LineTooLong: 400when anactivity is larger than 512 KB — for example, fetching a sizeable payload from a Salesforce
connector in Copilot Studio. Copilot Studio streams each activity as a single Server-Sent-Events
data:line, and the underlyingmicrosoft-agents-copilotstudio-clientreads the response line byline. Under
aiohttp, line-based reading enforces aread_bufsize-derived per-line limit (512 KB atthe default buffer), so any single activity above that limit aborts the turn.
The upstream client maintainers confirmed this is expected behavior and advise configuring the
underlying aiohttp
ClientSessionviaConnectionSettings.client_session_settingsrather thanchanging the client. This PR does exactly that in the framework layer.
Description & Review Guide
What are the major changes?
microsoft-agents-copilotstudio-clientfrom>=0.3.1,<0.3.2to>=1.2.0,<2— theConnectionSettings.client_session_settingspassthrough required for this fix first shipped in0.7.0and is present through the latest1.2.0.client_session_settingsparameter toCopilotStudioAgent. When the agent builds theclient internally, it forwards these settings to the aiohttp
ClientSessionand defaultsread_bufsizetoDEFAULT_READ_BUFSIZE(1 MiB), lifting aiohttp's per-line limit well above the512 KB default. Users can override
read_bufsize(or pass other session settings); the parameteris ignored when a pre-built
clientorsettingsis supplied.while preserving other keys) cases.
What is the impact of these changes?
LineTooLong.0.3.x→1.x). The client APIs the agent uses(
ConnectionSettings,CopilotClient(settings, token),ask_question,start_conversation) arestable across
0.7.0–1.2.0, no other package in the workspace depends onmicrosoft-agents-*,and the upstream
1.0.0–1.2.0release notes are additive for this client (theazure-coreremoval from
hosting-coredrives most of theuv.lockchurn).What do you want reviewers to focus on?
uv.lockchanges, and the choice of1.2.0as thefloor versus a more conservative pin.
Related Issue
Fixes #7257
There is an existing open PR (#7321) for this issue that fixes it by monkeypatching
CopilotClient.post_requestto re-implement chunk-based SSE parsing. This PR takes theupstream-recommended approach instead: it raises aiohttp's buffer via
ConnectionSettings.client_session_settingsand avoids globally patching a third-party class (whichwould also silently mask the client's newer behavior on any future dependency bump).
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.