Skip to content

fix: retain bounded prefixes of large web pages - #122

Open
weiddeng wants to merge 3 commits into
mainfrom
codex/truncate-large-web-pages
Open

weiddeng wants to merge 3 commits into
mainfrom
codex/truncate-large-web-pages

Conversation

@weiddeng

@weiddeng weiddeng commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Problem

A static web page larger than 1 MiB currently fails entirely, so the model receives no useful text even though S-Code returns at most 24 KiB of extracted web content.

Outcome

Content Current behavior After #115
Web page ≤ 1 MiB Success Success
Web page > 1 MiB Request fails; no result Success using the first 1 MiB; truncated: true
Web text sent to the model At most 24 KiB At most 24 KiB (unchanged)
PDF ≤ 8 MiB Accepted by the size check Accepted by the size check
PDF > 8 MiB and ≤ 16 MiB Rejected for size Accepted if otherwise valid
PDF > 16 MiB Rejected for size Rejected; partial PDFs are not processed

web_open stops downloading at its existing 1 MiB boundary, removes only an incomplete UTF-8 character at the cutoff, and safely extracts text from unfinished HTML. Its byte count and SHA-256 describe the retained valid prefix. Public PDF tools still require the whole file and now share one 16 MiB limit across download and isolated parsing.

Validation

  • cargo test --locked -p s-code-execution — 98 passed
  • strict Clippy for s-code-execution and s-code-daemon
  • Rust formatting and generated-documentation checks
  • community secret and documentation-link checks

Fixes #115

Large web pages currently fail at the 1 MiB limit and return nothing. Retain the bounded prefix instead, while raising complete public PDF downloads to 16 MiB.

| Content | Current behavior | After #115 |
| --- | --- | --- |
| Web page ≤ 1 MiB | Success | Success |
| Web page > 1 MiB | Request fails; no result | Success using the first 1 MiB; `truncated: true` |
| Web text sent to the model | At most 24 KiB | At most 24 KiB (unchanged) |
| PDF ≤ 8 MiB | Accepted by the size check | Accepted by the size check |
| PDF > 8 MiB and ≤ 16 MiB | Rejected for size | Accepted if otherwise valid |
| PDF > 16 MiB | Rejected for size | Rejected; partial PDFs are not processed |

More details: Stop network reads at the existing web cap, repair only an incomplete trailing UTF-8 character, and parse unfinished HTML. `body_bytes` and `sha256` describe the retained valid prefix. PDFs share one 16 MiB limit across download and isolated parsing.

Signed-off-by: Wei Deng <wdeng@wustl.edu>
@weiddeng
weiddeng requested a review from sl-7qx as a code owner October 1, 2026 22:15
@weiddeng

weiddeng commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

@felixwang could you please review this and LGTM if it looks good?

@al2wang al2wang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this. I reviewed 0e531a3; its only non-merge commit is f5e0585. I have one point: a small decoding and metadata defect. It is not a security issue and I don't see it as blocking.

A stray Content-Length decides truncation for a chunked body (crates/execution/src/web.rs:320-330). When a response has both Transfer-Encoding: chunked and Content-Length, hyper frames it by the chunked coding, as RFC 9112 §6.3 requires. The header stays in the map, though, and the new code reads it. I sent a complete 5-byte chunked body with Content-Length: 2097152:

  • hello comes back with truncated: true, so a complete page is reported as partial.
  • hello\xC3 comes back as "hello". Without the stray header, the same body fails with InvalidUtf8.

Response::content_length() follows the framing hyper actually used. It returns None here and Some(n) for a body that really is length-delimited. It also covers the same older check on the PDF path. I tried this change locally, together with removing the now-unused CONTENT_LENGTH import. Both cases then behave correctly, and fmt, clippy and the 98 existing execution tests plus one regression test pass:

let declared_too_large = response
    .content_length()
    .is_some_and(|length| length > kind.max_body_bytes() as u64);

Two regression tests would pin it: the chunked hello case expecting truncated: false, and the hello\xC3 case expecting InvalidUtf8. The oversize test only sends 87 bytes past the cap, so it may also be worth keeping two fixtures I used:

  • a body of exactly 1 MiB, then exactly 1 MiB + 1 byte, each with and without Content-Length;
  • an endless body, wrapped in tokio::time::timeout.

What else I tested:

  • With a declared oversize length, a continuous endless body, or a chunk crossing the cap, web_open returned exactly 1,048,576 bytes with truncated: true in under 50 ms.
  • Exactly 1 MiB followed by a clean end returned truncated: false.
  • One boundary behaves differently. An unknown-length body that pauses at exactly 1,048,576 bytes waits for one more read and fails on the 5 s read timeout, as a pause anywhere before the cap does.
  • Incomplete-character repair and unfinished-HTML extraction behaved as described.
  • Locally, fmt, clippy -D warnings and the s-code-execution (98) and s-code-daemon (230) tests pass.

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.

proposal: read the first 1 MiB of a larger web page instead of failing

2 participants