AgentaMerged

Bounding Slack media downloads

Enforce attachment limits as bytes arrive, instead of downloading the full Slack response before checking its size.

A size check after an eager download is too late to bound the download itself. Slack media could be fetched in full before the adapter compared the response length with max_bytes.

The merged fix switches the file request to HTTPX streaming and applies the limit while reading chunks. Oversized responses return without consuming the rest of the stream.

Agenta illustration of Slack media passing through a download size boundary
Agenta · contribution overview

Metadata is a hint. Streamed bytes are the boundary.

Slack’s file metadata can be missing or understate the actual content. The response can also omit Content-Length. Neither is a sufficient substitute for checking the bytes actually read.

Slack file URLCheck usable size headersRead decoded chunksWithin limit? Append.
Over limit? Stop.
The accumulated-byte check remains authoritative even when size metadata is absent or misleading.
Streamed byte limit · Python
data = bytearray()
async for chunk in response.aiter_bytes():
    if max_bytes is not None and len(data) + len(chunk) > max_bytes:
        return None
    data.extend(chunk)

The guard checks the next chunk before appending it to the accumulated buffer. Content exactly at the limit remains valid; content above it is rejected. The asynchronous response context closes the stream on early return and on errors.

Preserve the existing download contract

A usable, oversized Content-Length still permits rejection before reading the body. That shortcut is used only when there is no content encoding: a compressed response’s header length is not the same as its decoded content length.

The streamed-byte guard remains in place regardless of metadata. For gzip responses, it applies to the bytes yielded by aiter_bytes(), rather than trusting the compressed wire size.

  • Bot-token authentication, redirects, and the existing timeout remain in place.
  • An HTML login response is still treated as denied file access.
  • The existing MIME-type fallback is preserved.
  • Response cleanup does not close the shared HTTPX client.

Tests for early termination and cleanup

The regressions use controlled asynchronous byte streams, so tests can inspect how much was consumed and whether the stream was closed. They cover missing or understated file-size metadata, size boundaries, Content-Length handling, gzip responses, and cleanup when a stream raises.

Reported local validationResult
Slack unit suite216 passed
Focused streaming regression cases6 passed
Ruff formatting and git diff --checkPassed
Lint comparisonNo new violations; existing violations remain

Merged upstream

PR #7701 was merged into Agenta’s release/v0.123.0 branch on 24 October 2026 (IST). The implementation and regression tests are now part of the upstream repository.

View implementation & discussion ↗
PR status checked .
Mahaboob AshrafSoftware & AI Engineer · Hyderabad, India

Frequently asked questions

Why is Content-Length not enough?

It can be absent, understated, or describe compressed rather than decoded bytes. The patch keeps a streamed-byte check even when metadata is available.

What happens when the attachment exceeds the limit?

The adapter returns None without appending the chunk that would exceed the accumulated-buffer limit. Exiting the HTTPX response context closes the stream.

Were real Slack downloads tested?

No. The reported validation uses mocked HTTPX responses and controlled streams. The PR explicitly records live Slack downloads as untested.

LET’S CONNECT

LET’S TALK ABOUTWHAT’S NEXT.

I’m open to contracts, internships, and remote engineering roles.

STRAIGHT TO MY INBOX