From 0dd7955bd9a70e61d44e4d98d2ee4cfef1c1a204 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Thu, 3 Dec 2026 05:54:29 -0800 Subject: [PATCH 1/2] Return trusted output and split model vs script errors Replace `ToolOutput::untrusted` with `ToolOutput::trusted` in `fetch.rs` and `search.rs`, and branch on `call.caller()` in `web.rs`. `Caller::Model` receives domain, argument, and fetch errors as plain trusted text while `Caller::Script` receives `Err(ToolError)`. --- crates/plugin-web/src/error.rs | 8 +- crates/plugin-web/src/fetch.rs | 22 +++--- crates/plugin-web/src/fetch/tests-body.rs | 6 +- crates/plugin-web/src/lib.rs | 22 ++++-- crates/plugin-web/src/search-tests.rs | 7 +- crates/plugin-web/src/search.rs | 19 ++--- crates/plugin-web/src/web-tests-search.rs | 90 ++++++++++++++++++++--- crates/plugin-web/src/web-tests.rs | 54 ++++++++++---- crates/plugin-web/src/web.rs | 26 ++++--- 9 files changed, 178 insertions(+), 76 deletions(-) diff --git a/crates/plugin-web/src/error.rs b/crates/plugin-web/src/error.rs index 490d961..00bae23 100644 --- a/crates/plugin-web/src/error.rs +++ b/crates/plugin-web/src/error.rs @@ -14,12 +14,12 @@ use runvil_plugin_sdk::ToolErrorKind; /// How `call` should treat a [`FetchError`]. /// -/// A [`Disposition::SoftOutput`] error is returned to the model as untrusted -/// tool text so it can try a different URL; a [`Disposition::Hard`] error aborts -/// the call with the given [`ToolErrorKind`]. +/// A [`Disposition::SoftOutput`] error is returned to the model as trusted +/// tool text so it can try a different URL; a [`Disposition::Hard`] error +/// aborts the call with the given [`ToolErrorKind`]. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub(crate) enum Disposition { - /// Returns the model-facing text as untrusted tool output. + /// Returns the model-facing text as trusted tool output. SoftOutput, /// Aborts the call as a failure of this kind. Hard(ToolErrorKind), diff --git a/crates/plugin-web/src/fetch.rs b/crates/plugin-web/src/fetch.rs index 12ce6ed..cfcca02 100644 --- a/crates/plugin-web/src/fetch.rs +++ b/crates/plugin-web/src/fetch.rs @@ -36,7 +36,7 @@ use crate::response::{ use crate::task; use crate::url_policy::check_url; -/// The result [`WebFetch::call`] returns: untrusted page text on success, +/// The result [`WebFetch::call`] returns: trusted page text on success, /// a narrow [`ToolError`] on a hard failure. type CallResult = Result; @@ -137,7 +137,7 @@ impl FetchClient { url: SafeUrl::new(final_url.as_str()), status: status.as_u16(), }; - return Ok(ToolOutput::untrusted(err.model_facing())); + return Ok(ToolOutput::trusted(err.model_facing())); } let content_type = response @@ -219,7 +219,7 @@ impl FetchClient { let (text, char_truncated) = truncate_to_chars(&decoded, max_chars); let truncated = size_truncated || char_truncated; - Ok(ToolOutput::untrusted(format!( + Ok(ToolOutput::trusted(format!( "url: {final_url}\ntruncated: {truncated}\nextraction: {}\n\n{text}", extraction.label() ))) @@ -267,18 +267,18 @@ fn did_not_finish() -> ToolError { /// [`Disposition`]. fn soft_or_hard(err: &FetchError) -> CallResult { match err.classify() { - Disposition::SoftOutput => Ok(ToolOutput::untrusted(err.model_facing())), + Disposition::SoftOutput => Ok(ToolOutput::trusted(err.model_facing())), Disposition::Hard(kind) => Err(ToolError::new(kind, err.model_facing())), } } -/// Maps a body-read [`FetchError`] into soft, untrusted tool text. +/// Maps a body-read [`FetchError`] into soft, trusted tool text. /// /// A body-read failure is a size cap ([`FetchError::TooLarge`]) or a mid-stream /// transport failure ([`FetchError::BodyRead`]); both are soft and returned as /// model-facing tool text so the model can try a different URL. fn body_read_outcome(err: &FetchError) -> ToolOutput { - ToolOutput::untrusted(err.model_facing()) + ToolOutput::trusted(err.model_facing()) } /// Maps a reqwest send error into either a soft tool result or a hard `Err`. @@ -291,21 +291,21 @@ fn map_send_error_to_outcome(err: &reqwest::Error, url: &str) -> CallResult { while let Some(current) = source { if let Some(fetch_err) = current.downcast_ref::() { return match fetch_err.classify() { - Disposition::SoftOutput => Ok(ToolOutput::untrusted(fetch_err.model_facing())), + Disposition::SoftOutput => Ok(ToolOutput::trusted(fetch_err.model_facing())), Disposition::Hard(kind) => Err(ToolError::new(kind, fetch_err.model_facing())), }; } source = current.source(); } if err.is_timeout() { - return Ok(ToolOutput::untrusted( + return Ok(ToolOutput::trusted( FetchError::Timeout { url: SafeUrl::new(url), } .model_facing(), )); } - Ok(ToolOutput::untrusted(format!( + Ok(ToolOutput::trusted(format!( "fetch failed for {url}: network error; try a different URL" ))) } @@ -347,13 +347,13 @@ impl WebFetch { } /// Fetches the URL `args` names on the Plugin's runtime and renders its - /// response as untrusted text. Dropping the returned future aborts the + /// response as trusted text. Dropping the returned future aborts the /// fetch. /// /// # Errors /// Returns a [`ToolError`] for invalid arguments, a URL the policy /// refuses outright, or a fetch task that did not finish. A page the - /// fetch could not render is a soft, untrusted output instead. + /// fetch could not render is a soft, trusted output instead. pub(crate) async fn call(&self, args: serde_json::Value) -> CallResult { let url = args .get("url") diff --git a/crates/plugin-web/src/fetch/tests-body.rs b/crates/plugin-web/src/fetch/tests-body.rs index 27da9a5..216124c 100644 --- a/crates/plugin-web/src/fetch/tests-body.rs +++ b/crates/plugin-web/src/fetch/tests-body.rs @@ -232,14 +232,14 @@ async fn flat_text_body_read_failure_is_soft() { let url = format!("http://localhost:{port}/plainbroken"); // The mid-stream failure must be a soft (recoverable) return, never a // hard error: identical to the HTML and structured routes. A `text()` - // return proves the outcome was soft untrusted output. + // return proves the outcome was soft trusted output. let outcome = tool .call(serde_json::json!({ "url": url })) .await .expect("a mid-stream flat-text failure must be a soft return, not a hard error"); assert!( - !outcome.is_trusted(), - "a soft body-read failure must be untrusted output" + outcome.is_trusted(), + "a soft body-read failure must be trusted output" ); let result = outcome.text().to_owned(); assert!( diff --git a/crates/plugin-web/src/lib.rs b/crates/plugin-web/src/lib.rs index af4c0a7..f580363 100644 --- a/crates/plugin-web/src/lib.rs +++ b/crates/plugin-web/src/lib.rs @@ -37,9 +37,9 @@ //! verbatim. The tool refuses every other type, and a response that //! declares none. //! -//! The answer is untrusted output: three header lines, then a blank -//! line, then the text. The header lines are `url:`, the URL the text -//! came from once every redirect was followed, `truncated:`, and +//! The answer is trusted output: three header lines, then a blank line, +//! then the text. The header lines are `url:`, the URL the text came +//! from once every redirect was followed, `truncated:`, and //! `extraction:`, how the text was made. The text is cut at 40,000 //! characters, or at `max_chars` when the call names fewer. //! @@ -49,10 +49,12 @@ //! port outside the policy, has an IP address for its host, or resolves //! to no address the policy allows. A call whose fetch task panics, or //! whose page makes the rendering panic, fails with `web_fetch: the fetch -//! task did not finish`. Anything else that goes wrong is an untrusted +//! task did not finish`. Anything else that goes wrong is a trusted //! output that says so, such as an HTTP error status, a timeout, a //! refused redirect, a body over the size cap, or a type the tool does -//! not render. The model reads it and can try another URL. +//! not render. The model reads it and can try another URL. On a model +//! call, every failure above is also returned as trusted output with its +//! message; on a script call, it is returned as a `ToolError`. //! //! # The fetch policy //! @@ -95,7 +97,7 @@ //! rules of its own, which are stricter in places, such as the form of a //! country code, and it answers what it refuses with an error status. //! -//! The answer is untrusted output: the Gateway's reply as compact JSON, +//! The answer is trusted output: the Gateway's reply as compact JSON, //! an object with the `query` the Gateway ran and a `results` array. //! Each result has a `title`, a `url`, and a `description`, and it has //! an `age`, a `site_name`, and `extra_snippets` when the Gateway sent @@ -124,6 +126,10 @@ //! and when the task of the search does not come to its end, with //! `web_search: the search task did not finish`. //! +//! On a script call, these failures are returned as `ToolError` with +//! those kinds. On a model call, any failure is returned as trusted +//! output holding the error message. +//! //! # Where a search goes //! //! Every tool call is lent the Host's resources: the JSON text of an @@ -216,7 +222,9 @@ //! output, no failure, and no `Debug` text. No failure quotes the //! Host's resources. `gateway.rs` alone takes the key out of them, and //! the fields it keeps the key in are private to it. -//! - Every output of both tools is untrusted. +//! - Every output of both tools is trusted. On a model call, any +//! `ToolError` is mapped to trusted output with its message; on a +//! script call, `ToolError` is returned as-is. //! - The Plugin instance owns a tokio runtime with two worker threads, //! with I/O and time on, and every request, a fetch and a search //! alike, runs as a task on it. Dropping the instance drops the diff --git a/crates/plugin-web/src/search-tests.rs b/crates/plugin-web/src/search-tests.rs index 5c765a9..fc7c011 100644 --- a/crates/plugin-web/src/search-tests.rs +++ b/crates/plugin-web/src/search-tests.rs @@ -195,16 +195,13 @@ fn full_and_bare_results() -> Value { } #[tokio::test] -async fn results_render_as_the_gateways_serialization_and_are_untrusted() { +async fn results_render_as_the_gateways_serialization_and_are_trusted() { let (mock, _seen) = gateway_answering(full_and_bare_results()).await; let output = search(&mock.url(), serde_json::json!({ "query": "rust" })) .await .expect("the Gateway's results render"); - assert!( - !output.is_trusted(), - "external search content must be marked untrusted" - ); + assert!(output.is_trusted(), "search content must be marked trusted"); // The Gateway's `WebSearchResponse` serialization of the same results: // its field order, with an absent `age` or `site_name` and empty // `extra_snippets` left out. diff --git a/crates/plugin-web/src/search.rs b/crates/plugin-web/src/search.rs index eea76db..027cc1e 100644 --- a/crates/plugin-web/src/search.rs +++ b/crates/plugin-web/src/search.rs @@ -1,6 +1,6 @@ //! The `web_search` tool: validate a search's arguments, send them to the //! Gateway that the Host's resources name, on the Plugin's runtime, and -//! return the results as untrusted compact JSON in the Gateway's shape. +//! return the results as trusted compact JSON in the Gateway's shape. //! //! [`SearchRequest`] is the arguments as the model sent them, once they //! deserialized and passed their bounds. Nothing sits between the tool and @@ -32,10 +32,10 @@ const MAX_DOMAINS: usize = 20; /// A tool that searches the web through the Gateway. /// /// Each call validates its arguments, reads where the search goes from the -/// Host's resources, and returns the Gateway's results as untrusted -/// output. It holds the shared [`SearchClient`], whose deadline covers -/// every search, and the handle of the Plugin's runtime, which every -/// search is spawned onto. +/// Host's resources, and returns the Gateway's results as trusted output. +/// It holds the shared [`SearchClient`], whose deadline covers every +/// search, and the handle of the Plugin's runtime, which every search is +/// spawned onto. #[derive(Debug, Clone)] pub(crate) struct WebSearch { /// The client every search goes through. @@ -122,8 +122,8 @@ impl WebSearch { /// Validates `args`, reads where the search goes from `resources`, the /// JSON text of the Host's resources, runs the search on the Plugin's - /// runtime, and returns the results as untrusted compact JSON. - /// Dropping the returned future aborts the search. + /// runtime, and returns the results as trusted compact JSON. Dropping + /// the returned future aborts the search. /// /// # Errors /// Returns a [`ToolError`] for invalid arguments, for resources whose @@ -157,10 +157,7 @@ impl WebSearch { ) })?; - // The results embed third-party titles, URLs, and descriptions, so - // the body is marked untrusted: it is nonce-wrapped before it can - // reach model input. - Ok(ToolOutput::untrusted(body)) + Ok(ToolOutput::trusted(body)) } } diff --git a/crates/plugin-web/src/web-tests-search.rs b/crates/plugin-web/src/web-tests-search.rs index e1f552f..785c155 100644 --- a/crates/plugin-web/src/web-tests-search.rs +++ b/crates/plugin-web/src/web-tests-search.rs @@ -13,7 +13,7 @@ use std::sync::Arc; use runvil_plugin_sdk::sys::RV_OK; use runvil_plugin_sdk::testing::PackRun; -use runvil_plugin_sdk::{Plugin, ToolError, ToolErrorKind, ToolOutput}; +use runvil_plugin_sdk::{Caller, Plugin, ToolError, ToolErrorKind, ToolOutput}; use serde_json::{Value, json}; use tokio::runtime::Runtime; @@ -91,6 +91,14 @@ fn search(pack: &PackRun<'_>) -> Result { .expect("the call follows the contract") } +/// Runs one `search` call for `rust` on `pack` as a script caller. +fn search_as_script(pack: &PackRun<'_>) -> Result { + pack.start("search", &json!({ "query": "rust" }).to_string()) + .with_caller(Caller::Script) + .run() + .expect("the call follows the contract") +} + /// The failure of a search under a Host whose resources hold no entry. fn no_web_search() -> ToolError { ToolError::new( @@ -143,7 +151,7 @@ fn a_search_posts_its_arguments_to_the_gateway_the_resources_name_and_answers_it let arguments = json!({ "query": "rust", "count": 3, "include_domains": [] }); assert_eq!( pack.call("search", &arguments.to_string()), - Ok(Ok(ToolOutput::untrusted(ANSWER))) + Ok(Ok(ToolOutput::trusted(ANSWER))) ); assert_eq!( gateway.seen(), @@ -160,7 +168,11 @@ fn resources_without_the_entry_fail_a_search_as_transport_and_send_no_request() let loaded = loaded(); // A fake Host that is given no resources lends every call `{}`. let pack = loaded.new_pack(PACK).expect("the Pack instance is made"); - assert_eq!(search(&pack), Err(no_web_search())); + assert_eq!(search_as_script(&pack), Err(no_web_search())); + assert_eq!( + search(&pack), + Ok(ToolOutput::trusted(no_web_search().message())) + ); for resources in [ "{}".to_owned(), @@ -173,7 +185,12 @@ fn resources_without_the_entry_fail_a_search_as_transport_and_send_no_request() .new_pack(PACK) .expect("the Pack instance is made") .with_resources(resources.clone()); - assert_eq!(search(&pack), Err(no_web_search()), "{resources}"); + assert_eq!(search_as_script(&pack), Err(no_web_search()), "{resources}"); + assert_eq!( + search(&pack), + Ok(ToolOutput::trusted(no_web_search().message())), + "{resources}" + ); } assert!(gateway.seen().is_empty(), "no request is sent"); } @@ -188,13 +205,12 @@ fn an_entry_of_version_2_fails_a_search_as_other_and_sends_no_request() { .new_pack(PACK) .expect("the Pack instance is made") .with_resources(version_2.to_string()); + let message = "web_search: the host's runvil/web-search entry is not version 1"; assert_eq!( - search(&pack), - Err(ToolError::new( - ToolErrorKind::Other, - "web_search: the host's runvil/web-search entry is not version 1" - )) + search_as_script(&pack), + Err(ToolError::new(ToolErrorKind::Other, message)) ); + assert_eq!(search(&pack), Ok(ToolOutput::trusted(message))); assert!(gateway.seen().is_empty(), "no request is sent"); } @@ -221,7 +237,7 @@ fn a_search_has_the_bearer_of_the_entrys_key_and_no_authorization_header_without .new_pack(PACK) .expect("the Pack instance is made") .with_resources(json!({ "runvil/web-search": entry }).to_string()); - assert_eq!(search(&pack), Ok(ToolOutput::untrusted(ANSWER)), "{entry}"); + assert_eq!(search(&pack), Ok(ToolOutput::trusted(ANSWER)), "{entry}"); let seen = gateway.seen(); let (sent, _body) = seen.last().expect("the search reached the Gateway"); assert_eq!(*sent, authorization, "{entry}"); @@ -253,7 +269,7 @@ fn no_debug_text_and_no_failure_holds_the_gateways_key() { .new_pack(PACK) .expect("the Pack instance is made") .with_resources(version_2.to_string()); - let refused = search(&other_version); + let refused = search_as_script(&other_version); // A Gateway that is gone: its port is closed, so the request fails. let listener = std::net::TcpListener::bind("127.0.0.1:0").expect("a loopback port binds"); @@ -269,7 +285,7 @@ fn no_debug_text_and_no_failure_holds_the_gateways_key() { &format!("http://127.0.0.1:{port}{ROUTE}"), Some(KEY), )); - let failed = search(&gone); + let failed = search_as_script(&gone); assert_eq!( failed, Err(ToolError::new( @@ -328,3 +344,53 @@ fn a_call_that_is_dropped_aborts_its_search_and_the_plugin_unloads() { } assert_eq!(loaded.unload(), RV_OK); } + +#[test] +fn a_model_call_maps_invalid_arguments_and_backend_errors_to_trusted_output() { + let loaded = loaded(); + let pack = loaded.new_pack(PACK).expect("the Pack instance is made"); + let bad_args = json!({ "query": " " }).to_string(); + let bad_args_message = "web_search: query must not be empty"; + assert_eq!( + pack.start("search", &bad_args) + .with_caller(Caller::Script) + .run(), + Ok(Err(ToolError::new( + ToolErrorKind::InvalidArguments, + bad_args_message + ))) + ); + assert_eq!( + pack.call("search", &bad_args), + Ok(Ok(ToolOutput::trusted(bad_args_message))) + ); + + let (port_script, _events_script) = + serve_on_a_port(Reply::Page("500 Internal Server Error", "boom")); + let backend_script = loaded + .new_pack(PACK) + .expect("the Pack instance is made") + .with_resources(resources( + &format!("http://127.0.0.1:{port_script}{ROUTE}"), + None, + )); + let backend_message = "web_search: backend returned 500: boom"; + assert_eq!( + search_as_script(&backend_script), + Err(ToolError::new(ToolErrorKind::Backend, backend_message)) + ); + + let (port_model, _events_model) = + serve_on_a_port(Reply::Page("500 Internal Server Error", "boom")); + let backend_model = loaded + .new_pack(PACK) + .expect("the Pack instance is made") + .with_resources(resources( + &format!("http://127.0.0.1:{port_model}{ROUTE}"), + None, + )); + assert_eq!( + search(&backend_model), + Ok(ToolOutput::trusted(backend_message)) + ); +} diff --git a/crates/plugin-web/src/web-tests.rs b/crates/plugin-web/src/web-tests.rs index bfefdc7..bced246 100644 --- a/crates/plugin-web/src/web-tests.rs +++ b/crates/plugin-web/src/web-tests.rs @@ -23,7 +23,9 @@ use std::time::Duration; use runvil_plugin_sdk::sys::RV_OK; use runvil_plugin_sdk::testing::{self, Loaded, PackRun}; -use runvil_plugin_sdk::{Pack, PackInfo, Plugin, Refusal, ToolError, ToolErrorKind, ToolOutput}; +use runvil_plugin_sdk::{ + Caller, Pack, PackInfo, Plugin, Refusal, ToolError, ToolErrorKind, ToolOutput, +}; use serde_json::{Value, json}; use super::{Web, chain}; @@ -107,6 +109,14 @@ fn fetch(pack: &PackRun<'_>, url: &str) -> Result { .expect("the call follows the contract") } +/// Runs one `fetch` call for `url` on `pack` as a script caller. +fn fetch_as_script(pack: &PackRun<'_>, url: &str) -> Result { + pack.start("fetch", &json!({ "url": url }).to_string()) + .with_caller(Caller::Script) + .run() + .expect("the call follows the contract") +} + /// The parameter schema of the tool named `tool` that `pack` lists. fn schema(pack: &PackRun<'_>, tool: &str) -> Value { let listed = pack @@ -353,13 +363,19 @@ fn a_call_the_tool_refuses_fails_as_invalid_arguments_with_its_message_word_for_ ), ]; for (arguments, message) in cases { + let raw = arguments.to_string(); assert_eq!( - pack.call("fetch", &arguments.to_string()), + pack.start("fetch", &raw).with_caller(Caller::Script).run(), Ok(Err(ToolError::new( ToolErrorKind::InvalidArguments, message ))), - "{arguments}" + "script: {arguments}" + ); + assert_eq!( + pack.call("fetch", &raw), + Ok(Ok(ToolOutput::trusted(message))), + "model: {arguments}" ); } } @@ -372,21 +388,25 @@ fn the_plugin_a_host_loads_refuses_a_name_that_resolves_to_this_machine() { let loaded = loaded(); let pack = loaded.new_pack(PACK).expect("the Pack instance is made"); assert_eq!( - fetch(&pack, "https://localhost/"), + fetch_as_script(&pack, "https://localhost/"), Err(ToolError::new( ToolErrorKind::InvalidArguments, "host localhost has no allowed address" )) ); + assert_eq!( + fetch(&pack, "https://localhost/"), + Ok(ToolOutput::trusted("host localhost has no allowed address")) + ); } #[test] -fn a_scheme_the_default_policy_refuses_is_an_untrusted_output_that_says_so() { +fn a_scheme_the_default_policy_refuses_is_a_trusted_output_that_says_so() { let loaded = loaded(); let pack = loaded.new_pack(PACK).expect("the Pack instance is made"); assert_eq!( fetch(&pack, "http://example.com/"), - Ok(ToolOutput::untrusted("scheme not allowed: http")) + Ok(ToolOutput::trusted("scheme not allowed: http")) ); } @@ -395,16 +415,24 @@ fn arguments_that_are_not_json_fail_their_call_as_invalid_arguments() { let loaded = loaded(); let pack = loaded.new_pack(PACK).expect("the Pack instance is made"); assert_eq!( - pack.call("fetch", "{url: https://example.com/}"), + pack.start("fetch", "{url: https://example.com/}") + .with_caller(Caller::Script) + .run(), Ok(Err(ToolError::new( ToolErrorKind::InvalidArguments, "web: the call's arguments are not valid JSON" ))) ); + assert_eq!( + pack.call("fetch", "{url: https://example.com/}"), + Ok(Ok(ToolOutput::trusted( + "web: the call's arguments are not valid JSON" + ))) + ); } #[test] -fn a_fetch_answers_a_page_as_untrusted_markdown_under_its_header() { +fn a_fetch_answers_a_page_as_trusted_markdown_under_its_header() { let (url, _events) = serve(Reply::Page("200 OK", ARTICLE)); let loaded = loaded_for_loopback(); let pack = loaded.new_pack(PACK).expect("the Pack instance is made"); @@ -412,7 +440,7 @@ fn a_fetch_answers_a_page_as_untrusted_markdown_under_its_header() { // have run on the Plugin's, and the call came to its end only because // the fetch's task woke it. let output = fetch(&pack, &url).expect("the fetch succeeds"); - assert!(!output.is_trusted(), "a page is text from outside"); + assert!(output.is_trusted(), "a fetch output is marked trusted"); let (header, text) = output .text() .split_once("\n\n") @@ -425,7 +453,7 @@ fn a_fetch_answers_a_page_as_untrusted_markdown_under_its_header() { } #[test] -fn a_page_that_answers_an_http_error_is_an_untrusted_output_that_says_so() { +fn a_page_that_answers_an_http_error_is_a_trusted_output_that_says_so() { let (url, _events) = serve(Reply::Page( "404 Not Found", "Not Found", @@ -434,20 +462,20 @@ fn a_page_that_answers_an_http_error_is_an_untrusted_output_that_says_so() { let pack = loaded.new_pack(PACK).expect("the Pack instance is made"); assert_eq!( fetch(&pack, &url), - Ok(ToolOutput::untrusted(format!( + Ok(ToolOutput::trusted(format!( "{url} answered HTTP 404; try a different URL" ))) ); } #[test] -fn a_request_that_gets_no_response_is_an_untrusted_output_that_says_so() { +fn a_request_that_gets_no_response_is_a_trusted_output_that_says_so() { let (url, _events) = serve(Reply::Nothing); let loaded = loaded_for_loopback(); let pack = loaded.new_pack(PACK).expect("the Pack instance is made"); assert_eq!( fetch(&pack, &url), - Ok(ToolOutput::untrusted(format!( + Ok(ToolOutput::trusted(format!( "fetch failed for {url}: network error; try a different URL" ))) ); diff --git a/crates/plugin-web/src/web.rs b/crates/plugin-web/src/web.rs index 44fc8c7..6ce5e0b 100644 --- a/crates/plugin-web/src/web.rs +++ b/crates/plugin-web/src/web.rs @@ -13,8 +13,8 @@ use std::error::Error; use runvil_plugin_sdk::{ - BoxFuture, Pack, PackInfo, Plugin, Refusal, ToolCall, ToolError, ToolErrorKind, ToolInfo, - ToolOutput, + BoxFuture, Caller, Pack, PackInfo, Plugin, Refusal, ToolCall, ToolError, ToolErrorKind, + ToolInfo, ToolOutput, }; use serde_json::Value; use tokio::runtime::Runtime; @@ -145,14 +145,20 @@ impl Pack for WebPack { Box::pin(async move { // The arguments are parsed once, here, and each tool reads the // value. - let args = arguments(call.arguments())?; - match call.tool() { - FETCH => self.fetch.call(args).await, - SEARCH => self.search.call(args, call.resources()).await, - other => Err(ToolError::new( - ToolErrorKind::Other, - format!("web has no tool named {other}"), - )), + let result = match arguments(call.arguments()) { + Ok(args) => match call.tool() { + FETCH => self.fetch.call(args).await, + SEARCH => self.search.call(args, call.resources()).await, + other => Err(ToolError::new( + ToolErrorKind::Other, + format!("web has no tool named {other}"), + )), + }, + Err(err) => Err(err), + }; + match (call.caller(), result) { + (Caller::Model, Err(err)) => Ok(ToolOutput::trusted(err.message().to_owned())), + (_, result) => result, } }) } From 3b24194acfb3e422250db171746249d7ac76a2e9 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Thu, 3 Dec 2026 06:03:25 -0800 Subject: [PATCH 2/2] Clarify soft vs hard fetch failure doc comment Clarify in `crates/plugin-web/src/lib.rs` that soft fetch failures return `ToolOutput::trusted` for both callers and the caller-specific rule applies to hard `ToolError` failures. --- crates/plugin-web/src/lib.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/plugin-web/src/lib.rs b/crates/plugin-web/src/lib.rs index f580363..8c8bc08 100644 --- a/crates/plugin-web/src/lib.rs +++ b/crates/plugin-web/src/lib.rs @@ -49,12 +49,13 @@ //! port outside the policy, has an IP address for its host, or resolves //! to no address the policy allows. A call whose fetch task panics, or //! whose page makes the rendering panic, fails with `web_fetch: the fetch -//! task did not finish`. Anything else that goes wrong is a trusted -//! output that says so, such as an HTTP error status, a timeout, a -//! refused redirect, a body over the size cap, or a type the tool does -//! not render. The model reads it and can try another URL. On a model -//! call, every failure above is also returned as trusted output with its -//! message; on a script call, it is returned as a `ToolError`. +//! task did not finish`. Anything else that goes wrong is a soft failure +//! returned as trusted output for both callers, such as an HTTP error +//! status, a timeout, a refused redirect, a body over the size cap, or a +//! type the tool does not render. For hard failures represented by +//! `ToolError` (invalid arguments, policy-refused URLs, or a panicked +//! fetch task), a model call receives the error message as trusted +//! output, while a script call receives the `ToolError`. //! //! # The fetch policy //!