Skip to content

feat(web): optional fetch backend for web_fetch via TOLE_WEB_FETCH_URL - #542

Merged
ajianaz merged 2 commits into
developfrom
feat/web-fetch-backend
Nov 10, 2026
Merged

ajianaz merged 2 commits into
developfrom
feat/web-fetch-backend

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

What

With TOLE_WEB_FETCH_URL set, web_fetch asks that backend for the page instead of fetching directly, so JS-rendered and bot-protected pages can work. It stays a ReadOnly tool with the same trust model as web_search. Unset: the direct fetcher is untouched. Closes #532.

Why

web_fetch is direct HTTPS only (no JavaScript, no browser), so many real pages come back empty. #215/#436 gave search a configurable backend; fetch had none. Doing it through MCP would make every page fetch a Write approval.

Changes

  • web.rs: new WebBackendFetchTool registered under the name web_fetch instead of WebFetchTool when TOLE_WEB_FETCH_URL is set (WebFetchTool itself is not modified, so the unset case is byte-for-byte the same).
    • Contract: GET {url}?url=<target> → {"content": "..."}; TOLE_WEB_FETCH_METHOD=POST sends {"url": "<target>"}; TOLE_WEB_FETCH_HEADERS (Name=${VAR}, same parser and rules as the search headers, now parametrized by variable name so errors name the right variable); TOLE_WEB_FETCH_FIELDS='content=<field>'. A malformed value fails startup.
    • The target is vetted before anything is sent: https only, no credentials in the URL, host must resolve to public addresses (TOLE_WEB_ALLOW_PRIVATE=1 opts out as for direct fetch). A refused target never reaches the backend.
    • Backend only, no direct fallback (the issue's proposal; revisit with data). Backend redirects are not followed; headers go only to the backend; errors never carry a header value. The backend's JSON envelope is bounded to 1 MiB and the text is truncated to the direct-fetch limits (512 KiB, 20k chars).
    • Output keeps the direct fetcher's shape (url, content_type, truncated, text).
  • tool_roster.rs: choose the backend tool when configured.
  • README row, threat model paragraph (new disclosure: the target URL goes to the backend operator; the local check is not a DNS-rebinding defense at the backend), CHANGELOG.

Open questions from the issue (decisions taken here)

  • Fallback order: backend only. Format hint to the backend: not sent. Tool description: the summary says a fetch backend is attached ("may render JavaScript-heavy pages").
  • The response shape of a specific real backend is not verified; TOLE_WEB_FETCH_FIELDS exists for that.

Testing

  • cargo fmt, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace (1150 passed)
  • Local cora review --staged: not run (cora is not installed in this environment); the CI Cora Review job is the verdict.
  • 5 new tests with a local mock backend: off unless configured and 6 malformed-config cases fail with the variable named; 9 bad targets (http, credentials, loopback, localhost, private, link-local, file, ftp, missing) are refused and the mock sees no connection; GET sends the percent-encoded target and the header only to the backend; POST body; a failing backend's error does not contain the header value; truncation, missing field, non-JSON and oversize envelope.
  • Mutation: removing the target vetting makes the refusal test fail (it tries the real target and hangs without network instead of returning quickly).
  • Not tested: a real backend, and the roster choice end to end (the roster change is a two-arm match).

Related Issues

Closes #532. Related: #215, #436.


Generated by Claude Code

#532)

With TOLE_WEB_FETCH_URL set, web_fetch asks that backend for pages that need a real browser. ReadOnly, same trust model as web_search. The target is vetted locally first (https only, no credentials, public host) and nothing is sent if it fails. Unset: the direct fetcher is unchanged.
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

ajianaz commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Cora's finding is real and fixed in the next push: truncated was computed only against the byte cap while the text is also cut to 20,000 characters, so a response between the two caps was reported complete. It is now true when either cap cuts, and a test covers the in-between case (it fails without the fix). The direct fetcher has the same flag logic; I left it unchanged here to keep its behavior byte-for-byte as the issue requires.

Also: the earlier Test failure was serve_approvals::approval_allow_round_trip_executes_the_work, which this PR does not touch (the test reads approved.txt right after polling busy, which can still be false just after 202 resuming). I re-ran the job once; it will re-run again on this push.


Generated by Claude Code

@ajianaz
ajianaz merged commit 98ea0f2 into develop Nov 10, 2026
15 of 16 checks passed
ajianaz added a commit that referenced this pull request Nov 10, 2026
…pproval round trip (#543)

## What

Fixes the flaky
`serve_approvals::approval_allow_round_trip_executes_the_work` (it
failed on CI for #539 and #542, both times unrelated to the PR's diff).

## Why

After `POST /approvals/{id}/decision` returns `202 resuming`, the test
waited for the resumed turn by polling `GET /sessions/{sid}/status`
until `busy != true`. Right after the 202 the resume may not have set
`busy` yet, so the very first read says "not busy", the loop exits at
once, the queue entry already reads `approved`, and the file assertion
runs before the replayed `write_file` has landed ("the approved write
must have executed"). A "not busy" read proves nothing at that moment.

## Changes

- `crates/tole-cli/tests/serve_approvals.rs`: poll for the effect itself
(`approved.txt`, up to 10 s), then keep the existing wait for the
session to settle. No production code and no assertion weakened: the
same checks run, after the condition they depend on.

## Testing

- [x] Reproduced under CPU load (6 busy loops on 4 cores),
`approval_allow_round_trip` run 25 times in a row: **old code failed
9/25, the fix 0/25**.
- [x] `cargo fmt --check`, `cargo clippy -p tole-cli --all-targets -D
warnings`, `cargo test -p tole-cli --test serve_approvals` (3 passed).
- [ ] Local `cora review --staged`: not run (cora is not installed in
this environment); the CI Cora Review job is the verdict.

## Not included: the `tui_e2e` /quit race

An earlier CI failure suggested tests send `/quit\r` before the turn is
idle (the text would be queued as steering input instead of running as a
command), and adding `t.idle()` before `/quit` looked like the fix. I
could not reproduce it: 23 runs of the old `tui_e2e` binary under
heavier load (8 busy loops, 8 test threads) all passed, so that change
is not in this PR. It should be revisited if it fails on CI again, with
the failing test name in hand.

## Related Issues

Related to #539 and #542 (CI failures that were not theirs).

---
_Generated by [Claude
Code](https://claude.ai/code/session_01GwJr9GzLbDFeXo3HZHZpyP)_

Co-authored-by: Claude <[email protected]>
@ajianaz
ajianaz deleted the feat/web-fetch-backend branch November 11, 2026 04:10
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.

feat(web): optional backend for web_fetch (JS-heavy and blocked pages), mirroring web_search

2 participants