The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(inference): reject reserved keys in provider_options
Steven Enamakel09427425bc1b
diff --git a/crates/openhuman-core/src/inference/host_runtime/ops/complete_once.rs b/crates/openhuman-core/src/inference/host_runtime/ops/complete_once.rsindex 72f9acc89b..b32b07f373 100644--- a/crates/openhuman-core/src/inference/host_runtime/ops/complete_once.rs+++ b/crates/openhuman-core/src/inference/host_runtime/ops/complete_once.rs@@ -64,6 +64,14 @@ pub async fn complete_once(.to_string(),);}+ // `provider_options` is forwarded untouched, so a `tools` key there would+ // reach the provider even though `request.tools` is empty above. The typed+ // request fields own these keys.+ if let Some(key) = reserved_provider_option(&request.provider_options) {+ return Err(format!(+ "complete_once: provider_options may not set `{key}`; use the typed request fields"+ ));+ }let model_id = request.model.as_deref()@@ -93,6 +101,27 @@ pub async fn complete_once(.map_err(|e| format!("complete_once: {e}"))}+/// Body keys that `provider_options` may not carry: the tool surface (which+/// this op refuses) and the fields the typed request already sets.+const RESERVED_PROVIDER_OPTIONS: &[&str] = &[+ "model",+ "messages",+ "tools",+ "tool_choice",+ "functions",+ "function_call",+ "response_format",+ "stream",+];++fn reserved_provider_option(options: &serde_json::Value) -> Option<&'static str> {+ let object = options.as_object()?;+ RESERVED_PROVIDER_OPTIONS+ .iter()+ .copied()+ .find(|key| object.contains_key(*key))+}+#[cfg(test)]#[path = "complete_once_tests.rs"]mod tests;diff --git a/crates/openhuman-core/src/inference/host_runtime/ops/complete_once_tests.rs b/crates/openhuman-core/src/inference/host_runtime/ops/complete_once_tests.rsindex 8cfbab0c8f..27c2efad2b 100644--- a/crates/openhuman-core/src/inference/host_runtime/ops/complete_once_tests.rs+++ b/crates/openhuman-core/src/inference/host_runtime/ops/complete_once_tests.rs@@ -140,3 +140,13 @@ async fn requires_a_model() {.unwrap_err();assert!(err.contains("request.model is required"), "{err}");}++#[tokio::test]+async fn refuses_tools_smuggled_through_provider_options() {+ let mut request = ModelRequest::new(vec![Message::user("hi")]).with_model("m".to_string());+ request.provider_options = json!({"tools": [{"type": "function"}]});+ let err = complete_once(&unreachable_endpoint(), request)+ .await+ .expect_err("tools must not reach the provider via provider_options");+ assert!(err.contains("provider_options may not set `tools`"), "{err}");+}diff --git a/crates/openhuman-embed/src/complete.rs b/crates/openhuman-embed/src/complete.rsindex 04e1b4621e..ec1df094ef 100644--- a/crates/openhuman-embed/src/complete.rs+++ b/crates/openhuman-embed/src/complete.rs@@ -365,6 +365,11 @@ fn parse_json_reply(text: &str) -> Option<Value> {}/// What a [`CompletionObserver`] sees for each call.+///+/// The request and response carry the full message text, images and model+/// output, because that is what the host sent and got back. The route bearer+/// is never included. An observer that exports traces decides what leaves the+/// process, and should redact content if its sink must not hold it.#[derive(Debug)]pub struct CompletionTrace<'a> {/// The request as the host built it. The route's bearer is never part of@@ -461,23 +466,48 @@ impl Completer {async fn dispatch(&self, request: CompletionRequest) -> Result<CompletionResponse, CoreError> {let endpoint = self.checked_endpoint(&request)?;let format = request.response_format.clone();+ let model = request.model.clone();+ log::debug!(+ "[embed] complete start method={COMPLETE} model={model} messages={}",+ request.messages.len()+ );let call = openhuman_core::inference::host_runtime::ops::complete_once(&endpoint,request.into_wire(),);+ let started = std::time::Instant::now();let response = match self.timeout {- Some(limit) => tokio::time::timeout(limit, call)- .await- .map_err(|_| CoreError::Rpc {- method: COMPLETE,- message: format!("timed out after {}ms", limit.as_millis()),- })?,+ Some(limit) => match tokio::time::timeout(limit, call).await {+ Ok(outcome) => outcome,+ Err(_) => {+ // Metadata only: method, model and elapsed time, never content.+ log::warn!(+ "[embed] complete timed out method={COMPLETE} model={model} limit_ms={} elapsed_ms={}",+ limit.as_millis(),+ started.elapsed().as_millis()+ );+ return Err(CoreError::Rpc {+ method: COMPLETE,+ message: format!("timed out after {}ms", limit.as_millis()),+ });+ }+ },None => call.await,}- .map_err(|message| CoreError::Rpc {- method: COMPLETE,- message,+ .map_err(|message| {+ log::warn!(+ "[embed] complete failed method={COMPLETE} model={model} elapsed_ms={}",+ started.elapsed().as_millis()+ );+ CoreError::Rpc {+ method: COMPLETE,+ message,+ }})?;+ log::debug!(+ "[embed] complete ok method={COMPLETE} model={model} elapsed_ms={}",+ started.elapsed().as_millis()+ );Ok(CompletionResponse::from_wire(response, format.as_ref()))}