Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(backend): handle missing product headers gracefully

Steven Enamakel3c5664df19ab
diff --git a/crates/openhuman-tinyhumans/src/backend/headers.rs b/crates/openhuman-tinyhumans/src/backend/headers.rs
index bb49d6d273..f48922974c 100644
--- a/crates/openhuman-tinyhumans/src/backend/headers.rs
+++ b/crates/openhuman-tinyhumans/src/backend/headers.rs
@@ -3,20 +3,17 @@
//!
//! Every request that reaches the hosted backend carries the same three
//! attribution headers regardless of which transport sends it: `x-core-version`
-//! (this crate), `x-tauri-version` (the desktop shell, when it hosts the core)
-//! and `x-sdk-name` (the product identity from [`crate::api::product`]). The
-//! header *policy* is OpenHuman's, so it lives here in the core; the
-//! [`BackendTransport`](crate::api::transport::BackendTransport)
-//! implementation that actually performs the request — the SDK-backed one in
-//! `openhuman-tinyhumans`, or the test-only plain client — builds its
-//! `reqwest::Client` from these helpers so the wire shape cannot drift between
-//! them.
+//! (the workspace version the core ships as), `x-tauri-version` (the desktop
+//! shell, when it hosts the core) and `x-sdk-name` (the product identity from
+//! [`crate::backend::product`]). This is TinyHumans header policy, so it lives
+//! with the TinyHumans transport; the core only asks the installed
+//! [`BackendTransport`](openhuman_core::backend::BackendTransport) for them.
use anyhow::{Context, Result};
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
use std::time::Duration;
-use crate::api::transport::TransportProfile;
+use openhuman_core::backend::TransportProfile;
/// Upper bound on the `x-core-version` / `x-tauri-version` header values. A
/// version string is short; anything longer is a misconfigured environment and
@@ -51,7 +48,7 @@ pub(crate) fn sanitize_client_version(raw: &str) -> Option<String> {
///
/// Set at the transport level rather than per request because some callers
/// drive a raw `reqwest::Client` themselves (multipart STT upload via
-/// [`BackendOAuthClient::raw_client`](crate::api::rest::BackendOAuthClient::raw_client))
+/// [`BackendClient::raw_client`](openhuman_core::backend::BackendClient::raw_client))
/// and that traffic needs attributing too.
pub fn attribution_headers() -> Result<HeaderMap> {
let mut headers = HeaderMap::new();
@@ -69,7 +66,7 @@ pub fn attribution_headers() -> Result<HeaderMap> {
);
}
}
- let (name, value) = crate::api::product::product_identity_header();
+ let (name, value) = crate::backend::product::product_identity_header();
headers.insert(name, value);
Ok(headers)
}
@@ -80,16 +77,16 @@ pub fn attribution_headers() -> Result<HeaderMap> {
///
/// Platform-appropriate TLS: Windows → schannel (honors the OS cert store,
/// required for corporate TLS-inspection proxies); macOS / Linux → rustls.
-/// See [`crate::util::tls::tls_client_builder`].
+/// See [`openhuman_core::util::tls::tls_client_builder`].
pub fn backend_client_builder(profile: TransportProfile) -> Result<reqwest::ClientBuilder> {
let timeout = match profile {
- // `BackendOAuthClient` historically allowed 120 s: it fronts slow
+ // `BackendClient` historically allowed 120 s: it fronts slow
// control-plane calls (billing summaries, integration token handoffs).
TransportProfile::Api => Duration::from_secs(120),
// `/agent-integrations/*` tool calls were always capped at 60 s.
TransportProfile::Integrations => Duration::from_secs(60),
};
- Ok(crate::util::tls::tls_client_builder()
+ Ok(openhuman_core::util::tls::tls_client_builder()
.default_headers(attribution_headers()?)
.http1_only()
.timeout(timeout)
diff --git a/crates/openhuman-tinyhumans/src/backend/product.rs b/crates/openhuman-tinyhumans/src/backend/product.rs
index 9c3a5b5b32..d609b441ab 100644
--- a/crates/openhuman-tinyhumans/src/backend/product.rs
+++ b/crates/openhuman-tinyhumans/src/backend/product.rs
@@ -7,7 +7,7 @@
//! (`src/utils/sdkSource.ts` in `tinyhumansai/backend`) to attribute the call.
//!
//! The identity is process-wide rather than a constructor parameter because
-//! [`crate::api::rest::BackendOAuthClient`] is built at ~35 call sites spread
+//! [`BackendClient`](openhuman_core::backend::BackendClient) is built at ~35 call sites spread
//! across the domains, none of which an embedding product owns. Threading a
//! parameter through would mean editing every one of them. Instead a host sets
//! the identity once during startup, before it builds any backend client:
@@ -23,7 +23,7 @@
//! A build that never calls the setter sends [`DEFAULT_PRODUCT_IDENTITY`], so
//! behaviour is unchanged for any host that does not opt in.
//!
-//! The shape mirrors [`crate::config::schema::proxy`]'s runtime
+//! The shape mirrors `openhuman_core::config::schema::proxy`'s runtime
//! proxy config — a `OnceLock<RwLock<_>>` holding a defaulted value — rather
//! than a bare `OnceLock<T>`, which could only ever be set once per process and
//! would make the override untestable without poisoning the test binary.
@@ -39,7 +39,7 @@ pub const DEFAULT_PRODUCT_IDENTITY: &str = "openhuman";
/// Upper bound on the emitted header value. Mirrors the cap
/// `sanitize_client_version` applies to `x-core-version` in
-/// [`crate::api::rest`].
+/// [`openhuman_core::backend`].
const PRODUCT_IDENTITY_MAX_LEN: usize = 64;
/// A product identity that is always safe to send as a header value.
@@ -106,7 +106,7 @@ fn slot() -> &'static RwLock<ProductIdentity> {
/// Set the product identity for this process.
///
/// Call once during startup, before the first backend client is constructed.
-/// [`crate::api::rest::BackendOAuthClient`] and `IntegrationClient` read the
+/// [`BackendClient`](openhuman_core::backend::BackendClient) and `IntegrationClient` read the
/// identity into their default headers at construction, so a later call does
/// not retroactively re-tag clients that already exist.
pub fn set_product_identity(identity: ProductIdentity) {
@@ -153,7 +153,7 @@ pub fn product_identity_headers() -> HeaderMap {
///
/// The identity is process state, so a module-local lock cannot prevent
/// cross-module races: `api::product`, `api::rest` and
-/// `crate::integrations` tests all touch it from parallel test threads, and
+/// `openhuman_core::integrations` tests all touch it from parallel test threads, and
/// a test asserting the `openhuman` default would flake against a test that has
/// installed an override. Every test that touches the identity must take THIS
/// lock and restore the default before releasing it.