Repository navigation
Conversation
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>
|
@felixwang could you please review this and LGTM if it looks good? |
al2wang
left a comment
There was a problem hiding this comment.
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:
hellocomes back withtruncated: true, so a complete page is reported as partial.hello\xC3comes back as"hello". Without the stray header, the same body fails withInvalidUtf8.
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_openreturned exactly 1,048,576 bytes withtruncated: truein 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 warningsand thes-code-execution(98) ands-code-daemon(230) tests pass.
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
truncated: trueweb_openstops 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 passeds-code-executionands-code-daemonFixes #115