Skip to content

feat: make webfetch max response size configurable - #46812

Closed
RaviTharuma wants to merge 12 commits into
anomalyco:devfrom
RaviTharuma:feat/webfetch-max-response-size
Closed

RaviTharuma wants to merge 12 commits into
anomalyco:devfrom
RaviTharuma:feat/webfetch-max-response-size

Conversation

@RaviTharuma

Copy link
Copy Markdown

Issue for this PR

Closes #15459

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Webfetch currently hard-caps the HTTP body at 5MB. This PR adds webfetch.max_response_size in ConfigV1 (positive int, bytes). The default stays 5MB. Larger pages can be fetched without editing source.

How did you verify your code works?

Unit tests for resolveMaxResponseSize in packages/opencode.

Screenshots / recordings

N/A — not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Prefer config webfetch.max_response_size when set, else a positive-int
OPENCODE_WEBFETCH_MAX_SIZE, else the 5MB default so #15459 is fully closed.

Signed-off-by: Ravi Tharuma <RaviTharuma@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 2, 2026 13:46
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

I found one potentially related PR:

PR #45937: fix(webfetch): preserve specific errors and preview oversized responses (fixes #45929)

  • Why it's related: This PR also addresses webfetch response handling, specifically dealing with oversized responses. It may be addressing similar issues with response size limits that your PR configures.

You may want to check if PR #45937 is already merged or if there's any overlap in the functionality being addressed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new configurable size limit still allows fully buffering oversized responses (when Content-Length is missing/incorrect) and needs input validation/error-message improvements to make the feature reliable and diagnosable.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds configuration support for WebFetch’s maximum HTTP response size so users can raise the previous 5MB hard-cap via ConfigV1 and an environment variable, while keeping the default at 5MB.

Changes:

  • Introduces webfetch.max_response_size in ConfigV1 (bytes, positive int) with a default of 5MB.
  • Updates the webfetch tool to resolve the limit from config/env and enforce it during fetch.
  • Adds unit tests for resolveMaxResponseSize precedence and env parsing behavior.
File summaries
File Description
packages/opencode/src/tool/webfetch.ts Adds max-response-size resolution (config/env/default) and applies it to WebFetch size checks.
packages/opencode/test/tool/webfetch.test.ts Adds unit tests for limit resolution behavior and env var handling.
packages/core/src/v1/config/config.ts Extends ConfigV1 schema with webfetch.max_response_size (PositiveInt, bytes) and documentation.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/opencode/src/tool/webfetch.ts
Comment thread packages/opencode/src/tool/webfetch.ts
Comment thread packages/opencode/src/tool/webfetch.ts
@RaviTharuma

Copy link
Copy Markdown
Author

@copilot-pull-request-reviewer re-review: Content-Length is enforced before buffering; PositiveInt config rejects 0/negative; oversized error text is the existing webfetch message with the configured cap.

@RaviTharuma RaviTharuma closed this by deleting the head repository Sep 24, 2026
kvnloo pushed a commit to kvnloo/opencode that referenced this pull request Sep 26, 2026
Add webfetch.max_response_size (config) and OPENCODE_WEBFETCH_MAX_SIZE
(env) overrides. Default remains 5MB; invalid env values fall back.
Fork repair for #57 — tip still lacked sealed anomalyco#46799/anomalyco#46812.
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.

[FEATURE]: Make webfetch MAX_RESPONSE_SIZE configurable

2 participants