Skip to content

fix: cap in-process PDF URL downloads and clarify trust_urls docs - #1679

Closed
HarshRajSinghania wants to merge 4 commits into
RailtownAI:mainfrom
HarshRajSinghania:fix/pdf-download-size-cap-and-docs
Closed

HarshRajSinghania wants to merge 4 commits into
RailtownAI:mainfrom
HarshRajSinghania:fix/pdf-download-size-cap-and-docs

Conversation

@HarshRajSinghania

Copy link
Copy Markdown

Summary

Addresses the two concrete items in #1646:

  1. Size-limited streaming download for URL attachments. encode() (used for in-process PDF URL downloads when trust_urls=True) now reads the response in 8 KiB chunks and enforces a default maximum of 32 MB (DEFAULT_MAX_DOWNLOAD_BYTES). The limit is configurable via the new max_bytes keyword argument. Exceeding it raises ValueError before the full body is materialised in memory.

  2. Accurate trust_urls documentation. Updated docs/documentation/agent_design/llms/modalities.md so it no longer claims that image URLs never perform in-process network I/O. It now states that trust_urls=False only covers railtracks' own fetches (PDF downloads and HEAD probes), while certain litellm/provider paths may still fetch some image URLs.

The broader single-fetch-policy work that would also cover litellm remains tracked under #1347.

Motivation

Issue #1646 (help wanted / good first issue) notes that the PDF download path does an unbounded url.read() and that the docs overstate the SSRF protection provided by trust_urls=False.

Implementation notes

  • Streaming is used only for the URL case; local files are unchanged.
  • The constant and parameter default keep the change backwards-compatible for existing callers.
  • A unit test verifies that an oversize response is rejected.

Testing

pip install -e packages/railtracks pytest
python -m pytest packages/railtracks/tests/unit_tests/llm/test_encoding.py -q

Result: 39 passed.

No other files were modified. Existing functionality for local files, data URIs, and error paths is preserved.

Harsh Raj Singhania added 4 commits October 12, 2026 13:08
Add a default 32 MB limit (configurable via max_bytes) to in-process URL downloads in encode(), streaming the response in chunks instead of a single read() to prevent unbounded memory use.

Update modalities.md to accurately describe that trust_urls=False only covers railtracks' own fetches; some provider/litellm paths may still fetch certain image URLs.

Closes the immediate items in RailtownAI#1646. The broader single-fetch-policy work remains in RailtownAI#1347.
Replace placeholder with full implementation: stream URL downloads with 32MB default max_bytes limit in encode(). Update modalities.md for accurate trust_urls description. Add regression test for size limit.
@CoronRing

Copy link
Copy Markdown
Collaborator

Thanks for picking this up, @HarshRajSinghania! There was already a draft for this issue, #1677, opened before yours. It covers the same two items and also passes the cap through Attachment/UserMessage as attachment_max_mb, which #1646 asked for. So I'm closing this one as a duplicate to avoid two competing fixes. Sorry for the overlap; the draft wasn't linked on the issue, so it was easy to miss. If you'd like another one, the issues labelled good first issue are open, and please leave a comment on the one you pick so we can assign it to you.

Cheers!

@CoronRing CoronRing self-assigned this Oct 12, 2026
@CoronRing

CoronRing commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

The PR will be closed in 1 day, unless you have a different opinion that you wish to discuss =D

@CoronRing CoronRing closed this Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants