Repository navigation
fix(agent): bound crawler response bodies to 4 MiB - #18677
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe crawler now limits response bodies to 4 MiB. It reads one extra byte to detect overflow, returns an error with the HTTP status, and skips HTML extraction. Tests verify direct and JSON error results. ChangesCrawler response limit
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The crawler now limits decompressed response bodies to 4 MiB and returns a structured error for oversized responses, preventing unbounded buffering; no actionable merge-blocking risk remains after normal checks and review. Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…g it The Invoke node caps the response body with io.LimitReader, but it reported success whenever the cap bit: limited := io.LimitReader(resp.Body, maxInvokeResponseBody) bodyBytes, err := io.ReadAll(limited) A truncated body is indistinguishable from a complete one to every downstream canvas step. Invoke is the generic HTTP node operators wire to arbitrary endpoints, so a response over 16 MiB was handed to the workflow as a 16 MiB success: a cut JSON payload parsed into missing fields, or a cut page fed to the next component as if whole, with no error anywhere in the run. Measured against a server returning 16 MiB + 4 KiB: Invoke returned success with a result of exactly 16777216 bytes. Read one byte past the cap and report the overflow instead, which keeps "exactly at the limit" distinguishable from "over the limit". This is the same shape the agent tools already use for HTTP response bodies after infiniflow#18677 — crawler.go and akshare.go both reject an oversized response rather than return a truncated one — so this brings the third call site in line instead of introducing a new convention. The failure is returned as a Go error, matching the adjacent "Invoke: read body" failure and every other non-SSRF failure in this component. The _ERROR output shape stays reserved for the SSRF guard, which is the one case the canvas is documented to route around. No behaviour change for responses at or under the cap, which are still returned whole. The three new tests cover oversized, exactly-at-cap, and just-under-cap; the existing 14 Invoke tests pass unchanged.
…g it The Invoke node caps the response body with io.LimitReader, but it reported success whenever the cap bit: limited := io.LimitReader(resp.Body, maxInvokeResponseBody) bodyBytes, err := io.ReadAll(limited) A truncated body is indistinguishable from a complete one to every downstream canvas step. Invoke is the generic HTTP node operators wire to arbitrary endpoints, so a response over 16 MiB was handed to the workflow as a 16 MiB success: a cut JSON payload parsed into missing fields, or a cut page fed to the next component as if whole, with no error anywhere in the run. Measured against a server returning 16 MiB + 4 KiB: Invoke returned success with a result of exactly 16777216 bytes. Read one byte past the cap and report the overflow instead, which keeps "exactly at the limit" distinguishable from "over the limit". This is the same shape the agent tools already use for HTTP response bodies after infiniflow#18677 — crawler.go and akshare.go both reject an oversized response rather than return a truncated one — so this brings the third call site in line instead of introducing a new convention. The failure is returned as a Go error, matching the adjacent "Invoke: read body" failure and every other non-SSRF failure in this component. The _ERROR output shape stays reserved for the SSRF guard, which is the one case the canvas is documented to route around. No behaviour change for responses at or under the cap, which are still returned whole. The three new tests cover oversized, exactly-at-cap, and just-under-cap; the existing 14 Invoke tests pass unchanged.
Summary
The Go web crawler currently reads the full upstream response with
io.ReadAllbefore parsing it. A large or streaming page can therefore grow memory usage across the response buffer, HTML DOM, extracted text, and model-facing JSON.This change:
io.LimitReader(limit + 1);_ERRORtogether with a Go error before HTML parsing when the response exceeds the limit;httptestregression for a 4 MiB + 1 byte response.The 4 MiB budget follows the existing AkShare tool convention.
#16165 touches the same files as part of a larger harness refactor, while its current head retains the same unbounded read. This guard is independent of that refactor.
Testing
CGO_ENABLED=0 go test ./internal/agent/tool -run '^TestCrawler_' -count=1CGO_ENABLED=0 go vet ./internal/agent/toolgofmt -d internal/agent/tool/crawler.go internal/agent/tool/crawler_test.gogit diff --check