Skip to content

fix(agent): bound crawler response bodies to 4 MiB - #18677

Merged
yuzhichang merged 1 commit into
infiniflow:mainfrom
Lem0nTea2002:fix/crawler-response-size-limit
Aug 25, 2026
Merged

yuzhichang merged 1 commit into
infiniflow:mainfrom
Lem0nTea2002:fix/crawler-response-size-limit

Conversation

@Lem0nTea2002

Copy link
Copy Markdown
Contributor

Summary

The Go web crawler currently reads the full upstream response with io.ReadAll before 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:

  • caps the decompressed response body at 4 MiB with io.LimitReader(limit + 1);
  • returns the existing structured _ERROR together with a Go error before HTML parsing when the response exceeds the limit;
  • adds a local httptest regression 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=1
  • CGO_ENABLED=0 go vet ./internal/agent/tool
  • gofmt -d internal/agent/tool/crawler.go internal/agent/tool/crawler_test.go
  • git diff --check

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Aug 24, 2026
@coderabbitai

coderabbitai Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b542d9ee-44d6-4098-932f-a0cced439123

📥 Commits

Reviewing files that changed from the base of the PR and between f37b6fc and 4f7925f.

📒 Files selected for processing (2)
  • internal/agent/tool/crawler.go
  • internal/agent/tool/crawler_test.go

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The 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.

Changes

Crawler response limit

Layer / File(s) Summary
Response limit enforcement
internal/agent/tool/crawler.go
The crawler limits response reads to 4 MiB plus one byte. Oversized responses return a response too large error before HTML extraction.
Oversized response validation
internal/agent/tool/crawler_test.go
Tests verify direct error propagation and the expected error in the JSON result.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 4f792

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: yuzhichang

Poem

I’m a rabbit guarding bytes,
Four MiB beneath moonlit nights.
One extra byte hops into view,
Big responses get turned back too.
Clean HTML waits in gentle light.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: limiting crawler response bodies to 4 MiB.
Description check ✅ Passed The description includes the required Summary section and clearly explains the problem, solution, scope, and testing performed.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@JinHai-CN
JinHai-CN requested a review from yuzhichang August 25, 2026 03:44
@yuzhichang yuzhichang added the ci Continue Integration label Aug 25, 2026
@yuzhichang
yuzhichang merged commit bb488db into infiniflow:main Aug 25, 2026
9 checks passed
Tong-bit-art added a commit to Tong-bit-art/ragflow that referenced this pull request Nov 11, 2026
…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.
Tong-bit-art added a commit to Tong-bit-art/ragflow that referenced this pull request Nov 11, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants