Skip to content

Python: fix CopilotStudioAgent LineTooLong on large activities - #7417

Draft
giles17 wants to merge 1 commit into
microsoft:mainfrom
giles17:fix-copilotstudio-linetoolong
Draft

Python: fix CopilotStudioAgent LineTooLong on large activities#7417
giles17 wants to merge 1 commit into
microsoft:mainfrom
giles17:fix-copilotstudio-linetoolong

Conversation

@giles17

@giles17 giles17 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Motivation & Context

Calling a CopilotStudioAgent fails with aiohttp.http_exceptions.LineTooLong: 400 when an
activity 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 underlying microsoft-agents-copilotstudio-client reads the response line by
line. Under aiohttp, line-based reading enforces a read_bufsize-derived per-line limit (512 KB at
the 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 ClientSession via ConnectionSettings.client_session_settings rather than
changing the client. This PR does exactly that in the framework layer.

Description & Review Guide

  • What are the major changes?

    • Bump microsoft-agents-copilotstudio-client from >=0.3.1,<0.3.2 to >=1.2.0,<2 — the
      ConnectionSettings.client_session_settings passthrough required for this fix first shipped in
      0.7.0 and is present through the latest 1.2.0.
    • Add a client_session_settings parameter to CopilotStudioAgent. When the agent builds the
      client internally, it forwards these settings to the aiohttp ClientSession and defaults
      read_bufsize to DEFAULT_READ_BUFSIZE (1 MiB), lifting aiohttp's per-line limit well above the
      512 KB default. Users can override read_bufsize (or pass other session settings); the parameter
      is ignored when a pre-built client or settings is supplied.
    • Add unit tests covering the default, explicit override, and partial-settings (default injected
      while preserving other keys) cases.
  • What is the impact of these changes?

    • Copilot Studio activities larger than 512 KB now stream without raising LineTooLong.
    • The public API gains one optional keyword-only parameter; existing call sites are unaffected.
    • The dependency floor moves across a major (0.3.x1.x). The client APIs the agent uses
      (ConnectionSettings, CopilotClient(settings, token), ask_question, start_conversation) are
      stable across 0.7.01.2.0, no other package in the workspace depends on microsoft-agents-*,
      and the upstream 1.0.01.2.0 release notes are additive for this client (the azure-core
      removal from hosting-core drives most of the uv.lock churn).
  • What do you want reviewers to focus on?

    • The dependency floor bump and the resulting uv.lock changes, and the choice of 1.2.0 as the
      floor 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_request to re-implement chunk-based SSE parsing. This PR takes the
upstream-recommended approach instead: it raises aiohttp's buffer via
ConnectionSettings.client_session_settings and avoids globally patching a third-party class (which
would also silently mask the client's newer behavior on any future dependency bump).

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

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
Copilot AI review requested due to automatic review settings July 30, 2026 03:08
@giles17
giles17 temporarily deployed to github-app-auth July 30, 2026 03:08 — with GitHub Actions Inactive
@giles17
giles17 temporarily deployed to github-app-auth July 30, 2026 03:08 — with GitHub Actions Inactive
@giles17
giles17 temporarily deployed to github-app-auth July 30, 2026 03:08 — with GitHub Actions Inactive
@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Jul 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-client dependency to >=1.2.0,<2 to rely on the ConnectionSettings.client_session_settings passthrough.
  • Adds a client_session_settings keyword-only parameter to CopilotStudioAgent and injects a default read_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.

@github-actions

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/copilotstudio/agent_framework_copilotstudio
   _agent.py97396%191, 269, 301
TOTAL45854447590% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
9468 34 💤 0 ❌ 0 🔥 2m 24s ⏱️

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 LineTooLong failure 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-175 only injects client_session_settings when CopilotStudioAgent constructs ConnectionSettings itself. The package's documented explicit configuration paths in python/packages/copilotstudio/README.md:63-73 and python/samples/02-agents/providers/copilotstudio/README.md:76-85 still construct a default ConnectionSettings/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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

Copy link
Copy Markdown
Contributor

Flagged issue

python/packages/copilotstudio/agent_framework_copilotstudio/_agent.py:167-175 only injects client_session_settings when CopilotStudioAgent constructs ConnectionSettings itself. The package's documented explicit configuration paths in python/packages/copilotstudio/README.md:63-73 and python/samples/02-agents/providers/copilotstudio/README.md:76-85 still construct a default ConnectionSettings/CopilotClient, so large SSE activities remain on the old 512 KB per-line limit there.


Source: automated DevFlow PR review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: aiohttp.http_exceptions.LineTooLong: 400, message: Got more than 524288 bytes when reading: b'data:

2 participants