Skip to content

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

Merge commit '852dba449ab54e6fe1cf0ddcfc3a29c7cc3f418c' into epic-8092-256-provider-overrides-forkbase

Steven Enamakel3456708dedda
diff --cc Cargo.lock
index 645169fdb9,eff047c914..01b96fc119
--- a/Cargo.lock
+++ b/Cargo.lock
@@@ -3567,7 -3567,7 +3567,7 @@@ dependencies =
"js-sys",
"log",
"wasm-bindgen",
-- "windows-core 0.58.0",
++ "windows-core 0.62.2",
]
[[package]]
@@@ -3579,6 -3579,6 +3579,28 @@@ dependencies =
"cc",
]
++[[package]]
++name = "icu_casemap"
++version = "2.3.0"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "f2edfd120d8445de853cf53a1abec916f638f933a70a6f4bf8f7e2d7b7f884e9"
++dependencies = [
++ "icu_casemap_data",
++ "icu_collections",
++ "icu_locale_core",
++ "icu_properties",
++ "icu_provider",
++ "potential_utf",
++ "writeable",
++ "zerovec",
++]
++
++[[package]]
++name = "icu_casemap_data"
++version = "2.3.0"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "059fcda0fc8d33effc6633a8cf0d8a3c17caf7d7c91918fba9918744f501e4e8"
++
[[package]]
name = "icu_collections"
version = "2.3.0"
@@@ -3587,6 -3587,6 +3609,7 @@@ checksum = "fa68d21081c4a05d5a901a1c62a
dependencies = [
"displaydoc",
"potential_utf",
++ "serde",
"utf8_iter",
"yoke",
"zerofrom",
@@@ -3601,6 -3601,6 +3624,7 @@@ checksum = "d56e28588da92eee5c3201a6eff
dependencies = [
"displaydoc",
"litemap",
++ "serde",
"tinystr",
"writeable",
"zerovec",
@@@ -3655,6 -3655,6 +3679,8 @@@ checksum = "d27bbb9d3abbefac45d55f647c9
dependencies = [
"displaydoc",
"icu_locale_core",
++ "serde",
++ "stable_deref_trait",
"writeable",
"yoke",
"zerofrom",
@@@ -5455,10 -5457,10 +5483,10 @@@ dependencies =
"tinyflows-import",
"tinyflows-module",
"tinyhosts-bus",
-- "tinyinference-core 0.4.1",
-- "tinyinference-decisions 0.4.1",
++ "tinyinference-core 0.5.0",
++ "tinyinference-decisions 0.5.0",
"tinyinference-embeddings",
-- "tinyinference-llm 0.4.1",
++ "tinyinference-llm 0.5.0",
"tinyinference-local",
"tinyinference-providers",
"tinyinference-voice",
@@@ -5544,8 -5547,8 +5573,8 @@@ dependencies =
"tinycomputer-bus",
"tinydocs-bus",
"tinyeventqueues-bus",
-- "tinyinference-core 0.4.1",
-- "tinyinference-llm 0.4.1",
++ "tinyinference-core 0.5.0",
++ "tinyinference-llm 0.5.0",
"tinyinference-local",
"tinyinference-voice",
"tinymcp-bus",
@@@ -5598,7 -5602,7 +5628,7 @@@ dependencies =
"tinyflows-bus",
"tinyflows-module",
"tinyinference-embeddings",
-- "tinyinference-llm 0.4.1",
++ "tinyinference-llm 0.5.0",
"tinymcp-bus",
"tinymemory-api",
"tinymemory-tools",
@@@ -5661,7 -5666,7 +5692,7 @@@ dependencies =
"tempfile",
"tinyagents-harness",
"tinyagents-session",
-- "tinyinference-core 0.4.1",
++ "tinyinference-core 0.5.0",
"tinystoragedrivers",
"tokio",
"tokio-stream",
@@@ -5704,10 -5709,10 +5735,10 @@@ dependencies =
"tinybus",
"tinychannels-bus",
"tinyhumans-sdk",
-- "tinyinference-core 0.4.1",
++ "tinyinference-core 0.5.0",
"tinyinference-embeddings",
"tinyinference-image",
-- "tinyinference-llm 0.4.1",
++ "tinyinference-llm 0.5.0",
"tinyinference-providers",
"tinyinference-video",
"tinyinference-voice",
@@@ -6311,6 -6318,6 +6344,8 @@@ version = "0.1.6
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661"
dependencies = [
++ "serde_core",
++ "writeable",
"zerovec",
]
@@@ -6762,6 -6769,6 +6797,12 @@@ dependencies =
"unicode-width",
]
++[[package]]
++name = "rawzip"
++version = "0.5.2"
++source = "registry+https://github.com/rust-lang/crates.io-index"
++checksum = "ac9999039f74cd73c03158cddfe4362991703c74efe5ce5c8073026f80a5e48c"
++
[[package]]
name = "rdev"
version = "0.5.3"
@@@ -8438,18 -8455,17 +8489,17 @@@ dependencies =
[[package]]
name = "tinyagents-graph"
-version = "2.10.0"
+version = "2.2.0"
dependencies = [
- "anyhow",
"async-trait",
"futures",
"serde",
"serde_json",
"tinyagents-harness",
"tinyagents-tasks",
-- "tinyinference-llm 0.4.1",
++ "tinyinference-llm 0.5.0",
"tinystoragedrivers-core",
- "tinytools",
+ "tinytools 0.6.0",
"tokio",
"tracing",
]
@@@ -8478,15 -8493,14 +8527,15 @@@ dependencies =
"tempfile",
"thiserror 2.0.20",
"tinyagents-definition",
-- "tinyinference-core 0.4.1",
++ "tinyinference-core 0.5.0",
"tinyinference-embeddings",
"tinyinference-image",
-- "tinyinference-llm 0.4.1",
++ "tinyinference-llm 0.5.0",
+ "tinyinference-providers",
"tinyinference-video",
"tinystoragedrivers-core",
- "tinytools",
- "tinytools-agent",
+ "tinytools 0.6.0",
+ "tinytools-agent 0.6.0",
"tinytools-std",
"tokio",
"tracing",
@@@ -8495,20 -8509,38 +8544,39 @@@
"zip 2.4.2",
]
+ [[package]]
+ name = "tinyagents-harness-tools"
-version = "2.10.0"
++version = "2.2.0"
+ dependencies = [
+ "anyhow",
+ "async-trait",
+ "chrono",
+ "chrono-tz",
+ "serde",
+ "serde_json",
+ "tinyagents-harness",
+ "tinyagents-orchestration",
+ "tinyagents-tasks",
- "tinyinference-llm 0.4.1",
++ "tinyinference-llm 0.5.0",
+ "tinytools 0.6.0",
+ "tokio",
+ "tracing",
+ ]
+
[[package]]
name = "tinyagents-hooks"
-version = "2.10.0"
+version = "2.2.0"
dependencies = [
"anyhow",
"async-trait",
"regex",
"serde",
"serde_json",
- "tinyagents-graph",
"tinyagents-harness",
- "tinyinference-llm 0.4.1",
+ "tinyagents-harness-tools",
- "tinyinference-llm 0.4.1",
++ "tinyinference-llm 0.5.0",
+ "tinyinference-providers",
- "tinytools",
+ "tinytools 0.6.0",
"tokio",
"tracing",
]
@@@ -8540,12 -8572,11 +8608,11 @@@ dependencies =
"tinyagents-definition",
"tinyagents-graph",
"tinyagents-harness",
- "tinyagents-runtime",
"tinyagents-session",
"tinyagents-tasks",
-- "tinyinference-llm 0.4.1",
++ "tinyinference-llm 0.5.0",
"tinystoragedrivers-core",
- "tinytools",
+ "tinytools 0.6.0",
"tokio",
"tracing",
"uuid",
@@@ -8561,9 -8592,8 +8628,9 @@@ dependencies =
"serde_json",
"tinyagents-definition",
"tinyagents-harness",
-- "tinyinference-llm 0.4.1",
++ "tinyinference-llm 0.5.0",
+ "tinyinference-providers",
- "tinytools",
+ "tinytools 0.6.0",
]
[[package]]
@@@ -8579,8 -8609,8 +8646,8 @@@ dependencies =
"tinyagents-hooks",
"tinyagents-registry",
"tinyagents-session",
-- "tinyinference-llm 0.4.1",
- "tinytools",
++ "tinyinference-llm 0.5.0",
+ "tinytools 0.6.0",
"tokio",
"tracing",
]
@@@ -8611,16 -8641,16 +8678,13 @@@ dependencies =
[[package]]
name = "tinyagents-tasks"
-version = "2.10.0"
+version = "2.2.0"
dependencies = [
-- "anyhow",
-- "async-trait",
"serde",
"serde_json",
"tinyagents-harness",
-- "tinyinference-llm 0.4.1",
++ "tinyinference-llm 0.5.0",
"tinystoragedrivers-core",
- "tinytools",
- "tinytools 0.6.0",
"tokio",
"tracing",
]
@@@ -8758,11 -8788,11 +8822,13 @@@ dependencies =
[[package]]
name = "tinybus"
--version = "0.1.6"
++version = "0.1.9"
dependencies = [
"async-trait",
"flate2",
++ "icu_casemap",
"libc",
++ "rawzip",
"serde",
"serde_json",
"sha2 0.10.9",
@@@ -8773,13 -8803,13 +8839,13 @@@
"tokio",
"toml 1.1.6+spec-1.1.0",
"tracing",
++ "unicode-normalization",
"ureq",
-- "zip 9.0.5",
]
[[package]]
name = "tinybus-macros"
--version = "0.1.6"
++version = "0.1.9"
dependencies = [
"proc-macro2",
"quote",
@@@ -8788,7 -8818,7 +8854,7 @@@
[[package]]
name = "tinybus-module"
--version = "0.1.6"
++version = "0.1.9"
dependencies = [
"async-trait",
"serde",
@@@ -9297,7 -9327,7 +9363,7 @@@ dependencies =
[[package]]
name = "tinyhumans-sdk"
--version = "0.2.0"
++version = "0.1.0"
dependencies = [
"base64 0.22.1",
"futures",
@@@ -9322,7 -9352,7 +9388,7 @@@ dependencies =
[[package]]
name = "tinyinference-core"
--version = "0.4.1"
++version = "0.5.0"
dependencies = [
"anyhow",
"httpdate",
@@@ -9345,7 -9375,7 +9411,7 @@@ dependencies =
[[package]]
name = "tinyinference-decisions"
--version = "0.4.1"
++version = "0.5.0"
dependencies = [
"async-trait",
"httpdate",
@@@ -9358,7 -9388,7 +9424,7 @@@
[[package]]
name = "tinyinference-embeddings"
--version = "0.4.1"
++version = "0.5.0"
dependencies = [
"anyhow",
"async-trait",
@@@ -9368,7 -9398,7 +9434,7 @@@
"serde",
"serde_json",
"thiserror 2.0.20",
-- "tinyinference-core 0.4.1",
++ "tinyinference-core 0.5.0",
"tokio",
"tracing",
"url",
@@@ -9376,7 -9406,7 +9442,7 @@@
[[package]]
name = "tinyinference-image"
--version = "0.4.1"
++version = "0.5.0"
dependencies = [
"async-trait",
"base64 0.23.1",
@@@ -9385,7 -9415,7 +9451,7 @@@
"serde",
"serde_json",
"thiserror 2.0.20",
-- "tinyinference-core 0.4.1",
++ "tinyinference-core 0.5.0",
"tinystoragedrivers-core",
"tokio",
"tracing",
@@@ -9411,7 -9441,7 +9477,7 @@@ dependencies =
[[package]]
name = "tinyinference-llm"
--version = "0.4.1"
++version = "0.5.0"
dependencies = [
"async-trait",
"axum",
@@@ -9422,10 -9452,9 +9488,10 @@@
"serde",
"serde_json",
"thiserror 2.0.20",
-- "tinyinference-core 0.4.1",
++ "tinyinference-core 0.5.0",
+ "tinyinference-embeddings",
"tinyinference-providers",
- "tinytools-agent",
+ "tinytools-agent 0.6.0",
"tokio",
"tracing",
"uuid",
@@@ -9433,7 -9462,7 +9499,7 @@@
[[package]]
name = "tinyinference-local"
--version = "0.4.1"
++version = "0.5.0"
dependencies = [
"base64 0.23.1",
"futures-util",
@@@ -9444,9 -9473,9 +9510,9 @@@
"serde",
"serde_json",
"thiserror 2.0.20",
-- "tinyinference-core 0.4.1",
++ "tinyinference-core 0.5.0",
"tinyinference-embeddings",
-- "tinyinference-llm 0.4.1",
++ "tinyinference-llm 0.5.0",
"tinyinference-providers",
"tokio",
"tracing",
@@@ -9455,7 -9484,7 +9521,7 @@@
[[package]]
name = "tinyinference-providers"
--version = "0.4.1"
++version = "0.5.0"
dependencies = [
"base64 0.23.1",
"rand 0.10.2",
@@@ -9471,7 -9500,7 +9537,7 @@@
[[package]]
name = "tinyinference-video"
--version = "0.4.1"
++version = "0.5.0"
dependencies = [
"async-trait",
"serde",
@@@ -9484,16 -9513,14 +9550,16 @@@
[[package]]
name = "tinyinference-voice"
--version = "0.4.1"
++version = "0.5.0"
dependencies = [
+ "async-trait",
"base64 0.23.1",
"reqwest 0.12.28",
"schemars",
"serde",
"serde_json",
- "tinyinference-core 0.4.1",
+ "tempfile",
- "tinyinference-core 0.4.1",
++ "tinyinference-core 0.5.0",
"tinyinference-local",
"tokio",
"uuid",
@@@ -9742,7 -9768,7 +9807,7 @@@ dependencies =
"serde_norway",
"sha2 0.11.0",
"thiserror 2.0.20",
- "tinytools",
- "tinytools 0.6.0",
++ "tinytools 0.5.0 (git+https://github.com/tinyhumansai/tinytools?rev=1cd9e9c4a117336e6f42d0c7936ed60e7476d88f)",
"tokio",
"url",
]
@@@ -9917,12 -9944,23 +9982,35 @@@ source = "registry+https://github.com/r
checksum = "b1e27c91459209c2986af3dcf603a5a74a4368754ce37414f59acc971167f643"
dependencies = [
"displaydoc",
++ "serde_core",
"zerovec",
]
+[[package]]
+name = "tinytools"
+version = "0.5.0"
++source = "git+https://github.com/tinyhumansai/tinytools?rev=1cd9e9c4a117336e6f42d0c7936ed60e7476d88f#1cd9e9c4a117336e6f42d0c7936ed60e7476d88f"
++dependencies = [
++ "anyhow",
++ "async-trait",
++ "serde",
++ "serde_json",
++]
++
+ [[package]]
+ name = "tinytools"
+ version = "0.5.0"
+ source = "git+https://github.com/tinyhumansai/tinytools?rev=bd60b9b52f1998b4483b9cf107a72d3338e672f8#bd60b9b52f1998b4483b9cf107a72d3338e672f8"
+ dependencies = [
+ "anyhow",
+ "async-trait",
+ "serde",
+ "serde_json",
+ ]
+
+ [[package]]
+ name = "tinytools"
+ version = "0.6.0"
dependencies = [
"anyhow",
"async-trait",
@@@ -9933,6 -9971,17 +10021,17 @@@
[[package]]
name = "tinytools-agent"
version = "0.5.0"
+ source = "git+https://github.com/tinyhumansai/tinytools?rev=bd60b9b52f1998b4483b9cf107a72d3338e672f8#bd60b9b52f1998b4483b9cf107a72d3338e672f8"
+ dependencies = [
+ "regex",
+ "serde",
+ "serde_json",
- "tinytools 0.5.0",
++ "tinytools 0.5.0 (git+https://github.com/tinyhumansai/tinytools?rev=bd60b9b52f1998b4483b9cf107a72d3338e672f8)",
+ ]
+
+ [[package]]
+ name = "tinytools-agent"
+ version = "0.6.0"
dependencies = [
"regex",
"serde",
@@@ -11440,7 -11489,7 +11539,7 @@@ version = "0.1.11
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
-- "windows-sys 0.61.2",
++ "windows-sys 0.48.0",
]
[[package]]
@@@ -12171,6 -12220,6 +12270,7 @@@ dependencies =
"displaydoc",
"yoke",
"zerofrom",
++ "zerovec",
]
[[package]]
@@@ -12179,6 -12228,6 +12279,7 @@@ version = "0.11.8
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb0464e17806c1d976d5cba29399c7f08e516e279e2ba493f63123b5fca67dd8"
dependencies = [
++ "serde",
"yoke",
"zerofrom",
"zerovec-derive",
@@@ -12246,20 -12295,20 +12347,6 @@@ dependencies =
"zopfli",
]
--[[package]]
--name = "zip"
--version = "9.0.5"
--source = "registry+https://github.com/rust-lang/crates.io-index"
--checksum = "6e04976da629d3b04204ba8105b396a193af8ad2583b2c79bfb3ab8af580a11e"
--dependencies = [
-- "crc32fast",
-- "flate2",
-- "indexmap",
-- "memchr",
-- "nix 0.31.3",
-- "typed-path",
--]
--
[[package]]
name = "zlib-rs"
version = "0.6.8"
diff --cc crates/openhuman-app/Cargo.lock
index f7ab502a15,07f9b15818..29150b0b3f
--- a/crates/openhuman-app/Cargo.lock
+++ b/crates/openhuman-app/Cargo.lock
@@@ -6479,10 -6510,9 +6511,10 @@@ dependencies =
"regex",
"serde",
"serde_json",
- "tinyagents-graph",
"tinyagents-harness",
+ "tinyagents-harness-tools",
"tinyinference-llm",
+ "tinyinference-providers",
"tinytools",
"tokio",
"tracing",
diff --cc crates/openhuman-core/src/config/schema/load/migrate.rs
index b397a46230,fbdcf74e3b..5c433412a3
--- a/crates/openhuman-core/src/config/schema/load/migrate.rs
+++ b/crates/openhuman-core/src/config/schema/load/migrate.rs
@@@ -66,8 -78,21 +78,21 @@@ pub fn redact_url_for_log(raw: &str) -
/// untouched. Routing fields that already contain a `:` are assumed to be
/// in the new `<slug>:<model>` form.
pub(crate) fn migrate_cloud_provider_slugs(config: &mut Config) {
- use super::super::cloud_providers::{builtin_cloud_provider, AuthStyle};
+ use super::super::cloud_providers::builtin_cloud_provider;
+ let legacy_provider_labels = config
+ .cloud_providers
+ .iter()
+ .any(|entry| entry.label.is_empty());
+ let previous_routes = [
+ config.reasoning_provider.clone(),
+ config.agentic_provider.clone(),
+ config.coding_provider.clone(),
+ config.vision_provider.clone(),
+ config.memory_provider.clone(),
+ config.embeddings_provider.clone(),
+ ];
+
for entry in &mut config.cloud_providers {
if entry.label.is_empty() {
entry.label = builtin_cloud_provider(&entry.slug)
diff --cc crates/openhuman-core/src/config/schema/load/mod.rs
index 798d102983,46dec5d55f..526354d91f
--- a/crates/openhuman-core/src/config/schema/load/mod.rs
+++ b/crates/openhuman-core/src/config/schema/load/mod.rs
@@@ -45,15 -58,16 +58,16 @@@ pub(crate) use dirs::default_root_dir_n
// re-export; only the load_tests module needs it visible at this level.
#[cfg(test)]
pub(crate) use dirs::read_active_user_id_checked;
-// Non-test: the keyless cloud embedder (`embeddings::cloud_adapter`)
-// resolves its `OPENHUMAN_WORKSPACE` credential scope through the same
-// workspace→config-dir mapping `config::load` uses, so a legacy `.../workspace`
-// override lands on the sibling `.openhuman` root that holds `auth-profiles.json`.
+// Non-test: the managed embedding factory resolves its credential scope
+// through the same workspace→config-dir mapping `config::load` uses, so a
+// legacy `.../workspace` override lands on the sibling `.openhuman` root that
+// holds `auth-profiles.json`.
pub(crate) use dirs::resolve_config_dir_for_workspace;
- #[cfg(test)]
pub(crate) use dirs::{
- resolve_runtime_config_dirs, resolve_runtime_config_dirs_with, ConfigResolutionSource,
+ load_persisted_workspace_dirs, read_active_user_id_checked_async, ConfigResolutionSource,
};
+ #[cfg(test)]
+ pub(crate) use dirs::{resolve_runtime_config_dirs, resolve_runtime_config_dirs_with};
// PathBuf and Config were in scope via `use super::*` in the original load.rs.
#[cfg(test)]
pub(crate) use super::Config;
diff --cc crates/openhuman-core/src/core/observability_connectivity.rs
index 0000000000,a155d9f2f2..71e3860c14
mode 000000,100644..100644
--- a/crates/openhuman-core/src/core/observability_connectivity.rs
+++ b/crates/openhuman-core/src/core/observability_connectivity.rs
@@@ -1,0 -1,97 +1,96 @@@
+ pub fn is_connectivity_event(event: &sentry::protocol::Event<'_>) -> bool {
+ let texts: Vec<&str> = {
+ let mut v = Vec::with_capacity(2 + event.exception.values.len());
+ if let Some(msg) = event.message.as_deref() {
+ v.push(msg);
+ }
+ if let Some(log) = event.logentry.as_ref().map(|l| l.message.as_str()) {
+ v.push(log);
+ }
+ for exc in &event.exception.values {
+ if let Some(val) = exc.value.as_deref() {
+ v.push(val);
+ }
+ }
+ v
+ };
+ if texts.is_empty() {
+ return false;
+ }
+
+ let lower = texts.join(" ").to_ascii_lowercase();
+
+ // Core HTTP transport errors
+ if lower.contains("connection refused")
+ || lower.contains("connection reset")
+ || lower.contains("connection closed before")
+ || lower.contains("broken pipe")
+ || lower.contains("tls handshake eof")
+ {
+ return true;
+ }
+
+ // Backend / provider gateway errors
+ if lower.contains("502 bad gateway")
+ || lower.contains("504 gateway timeout")
+ || lower.contains("502 gateway timeout")
+ || lower.contains("timeout: 503")
+ || lower.contains("upstream connect error")
+ {
+ return true;
+ }
+
+ // CoreRpcError / HTTP 401 (from frontend — user session issue, not code defect)
+ // Only match bare HTTP 401 (CoreRpcError / fetch), not llm_provider 401
+ // which is handled by the session-expired classifier
+ let domain = event.tags.get("domain").map(String::as_str);
+ if domain != Some("llm_provider")
+ && domain != Some("backend_api")
+ && (lower.contains("http 401")
+ || lower.contains("status: 401")
+ || lower.contains("401 unauthorized"))
+ {
+ return true;
+ }
+
+ // Timeout patterns — scoped to known transient forms so genuine
+ // non-transport timeouts (database locks, inference hangs) still
+ // reach Sentry for investigation.
+ if lower.contains("connection timed out")
+ || lower.contains("request timed out")
+ || lower.contains("deadline has elapsed")
+ || lower.contains("timeout after")
+ {
+ return true;
+ }
+
+ false
+ }
+
+ /// Filter out events from **stale releases** — releases older than
+ /// `MAX_AGE_MINOR_VERSIONS` minor versions behind the current build.
+ ///
+ /// Ancient-client errors are not actionable against the current codebase.
+ /// Target: ~4 issues from releases like v0.54.0 against current v0.58+.
+ #[cfg(feature = "crash-reporting")]
+ pub fn is_stale_release_event(event: &sentry::protocol::Event<'_>) -> bool {
+ // Maximum number of minor versions behind the current release to accept.
+ // Events from clients on releases older than this are dropped.
+ const MAX_AGE_MINOR_VERSIONS: u32 = 6;
+
+ let Some(release) = event.release.as_ref() else {
+ return false;
+ };
+
+ let current = env!("CARGO_PKG_VERSION");
+ parse_version(current).is_some_and(|(current_major, current_minor)| {
+ parse_release_tag(release).is_some_and(|(event_major, event_minor)| {
+ if event_major != current_major {
+ // Different major version = definitely stale (or from the future)
+ return event_major < current_major;
+ }
+ // Same major: check minor version gap
+ current_minor.saturating_sub(event_minor) > MAX_AGE_MINOR_VERSIONS
+ })
+ })
+ }
-
diff --cc crates/openhuman-core/src/core/runtime/context_test_support.rs
index c78bca3c86,ad3eb8f29a..21f9872cf3
--- a/crates/openhuman-core/src/core/runtime/context_test_support.rs
+++ b/crates/openhuman-core/src/core/runtime/context_test_support.rs
@@@ -12,20 -12,12 +12,21 @@@ impl CoreContext
pub(crate) fn for_test(
domains: crate::core::runtime::DomainSet,
workspace_dir: Option<std::path::PathBuf>,
+ ) -> Arc<CoreContext> {
+ Self::for_test_with_host_kind(HostKind::Cli, domains, workspace_dir)
+ }
+
+ /// Test-only constructor with an explicit host policy identity.
+ pub(crate) fn for_test_with_host_kind(
+ host_kind: HostKind,
+ domains: crate::core::runtime::DomainSet,
+ workspace_dir: Option<std::path::PathBuf>,
) -> Arc<CoreContext> {
Arc::new(CoreContext {
- host_kind: HostKind::Cli,
+ host_kind,
workspace_binding: RwLock::new(Arc::new(RwLock::new(WorkspaceBinding {
workspace_dir,
+ config_path: None,
}))),
domains,
tool_groups: Default::default(),
diff --cc crates/openhuman-core/src/doctor/checks/inference_catalog.rs
index 0000000000,a8c75413aa..5031b11ed2
mode 000000,100644..100644
--- a/crates/openhuman-core/src/doctor/checks/inference_catalog.rs
+++ b/crates/openhuman-core/src/doctor/checks/inference_catalog.rs
@@@ -1,0 -1,470 +1,470 @@@
+ //! Read-only, bounded provider catalog inspection for doctor.
+
+ use std::collections::HashMap;
+ use std::hash::{BuildHasher, Hash};
+ use std::sync::{Arc, LazyLock, Mutex};
+ use std::time::{Duration, Instant};
+
+ use async_trait::async_trait;
+
+ use crate::config::schema::cloud_providers::{AuthStyle, CloudProviderCreds};
+ use crate::core::{runtime::CoreContext, Outcome};
+ use crate::doctor::{
+ contract::{DoctorCheck, DoctorCtx, DoctorTier, Finding, FindingSeverity},
+ core::{ModelProbeEntry, ModelProbeOutcome, ModelProbeReport, ModelProbeSummary},
+ };
+ use crate::inference::registry::{
- inspection_catalog, CatalogRequest, InspectionCatalogError, PreparedInspectionCatalog,
++ inspection_catalog, InspectionCatalogError, InspectionCatalogRequest, PreparedInspectionCatalog,
+ };
+
+ const CACHE_TTL: Duration = Duration::from_secs(60);
+ const PROVIDER_CATALOG_TIMEOUT: Duration = Duration::from_secs(10);
+ type CachedCatalog = (
+ Instant,
+ Result<(serde_json::Value, Vec<String>), InspectionCatalogError>,
+ );
+ static CATALOG_CACHE: LazyLock<Mutex<HashMap<u64, CachedCatalog>>> =
+ LazyLock::new(|| Mutex::new(HashMap::new()));
+ static CACHE_HASHER: LazyLock<std::collections::hash_map::RandomState> =
+ LazyLock::new(std::collections::hash_map::RandomState::new);
+
+ fn hash_key<T: Hash>(value: &T) -> u64 {
+ CACHE_HASHER.hash_one(value)
+ }
+
+ fn scope_key(config: &crate::config::Config) -> String {
+ let context = CoreContext::scoped();
+ let scoped_workspace = context
+ .as_ref()
+ .and_then(|context| context.workspace_dir().ok())
+ .unwrap_or_else(|| config.workspace_dir.clone());
+ let tenant = context
+ .as_ref()
+ .and_then(|context| context.profile())
+ .unwrap_or_default();
+ format!(
+ "{}\u{1f}{}\u{1f}{}\u{1f}{}",
+ config.config_path.display(),
+ config.workspace_dir.display(),
+ scoped_workspace.display(),
+ tenant,
+ )
+ }
+
+ fn configured_entries(config: &crate::config::Config) -> Vec<CloudProviderCreds> {
+ let mut entries = config.cloud_providers.clone();
+ let selected = selected_models(config);
+ // The managed route is a configured model source even though it is not a
+ // BYOK row in cloud_providers.
+ if selected
+ .iter()
+ .any(|(_, model)| model.starts_with("openhuman:") || model.starts_with("openrouter/"))
+ && !entries.iter().any(|entry| entry.slug == "openhuman")
+ {
+ entries.push(CloudProviderCreds {
+ id: "openhuman".into(),
+ slug: "openhuman".into(),
+ label: "OpenHuman".into(),
+ endpoint: config.api_url.clone().unwrap_or_default(),
+ auth_style: AuthStyle::OpenhumanJwt,
+ default_model: None,
+ });
+ }
+ entries
+ }
+
+ fn readonly_credential(
+ config: &crate::config::Config,
+ entry: &CloudProviderCreds,
+ ) -> Option<String> {
+ if entry.auth_style == AuthStyle::None || entry.auth_style == AuthStyle::OpenhumanJwt {
+ return None;
+ }
+ let key = crate::inference::provider::factory::auth_key_for_slug(&entry.slug);
+ let profile =
+ crate::security::credentials::AuthService::get_profile_read_only(config, &key, None)
+ .ok()??;
+ let token = match profile.kind {
+ crate::security::credentials::AuthProfileKind::Token => profile.token,
+ crate::security::credentials::AuthProfileKind::OAuth => profile.token_set.and_then(|set| {
+ (!set.is_expiring_within(Duration::from_secs(90))).then_some(set.access_token)
+ }),
+ };
+ token.filter(|token| !token.trim().is_empty())
+ }
+
+ async fn prepare(
+ config: &crate::config::Config,
+ entry: &CloudProviderCreds,
+ ) -> Result<PreparedInspectionCatalog, InspectionCatalogError> {
+ if let Some(listing) = inspection_catalog(&entry.slug) {
+ let client = crate::config::build_runtime_proxy_client_with_timeouts(
+ "providers.list_models",
+ 30,
+ 10,
+ );
+ return listing(
+ config.clone(),
- CatalogRequest {
++ InspectionCatalogRequest {
+ provider_key: String::new(),
+ client,
+ },
+ )
+ .await;
+ }
+ if entry.auth_style == AuthStyle::OpenhumanJwt {
+ return Err(InspectionCatalogError::Unavailable);
+ }
+ let endpoint = entry.endpoint.trim_end_matches('/');
+ let Ok(url) = reqwest::Url::parse(&format!("{endpoint}/models")) else {
+ return Err(InspectionCatalogError::Unavailable);
+ };
+ if !matches!(url.scheme(), "http" | "https") {
+ return Err(InspectionCatalogError::NoCatalog);
+ }
+ let token = readonly_credential(config, entry);
+ let client = match config
+ .cloud_provider_ca_certs
+ .get(entry.slug.trim())
+ .filter(|pem| !pem.is_empty())
+ {
+ Some(pem) => crate::util::tls::client_with_ca_bundle_with_timeouts(
+ pem,
+ "providers.list_models",
+ 30,
+ 10,
+ )
+ .map_err(|_| InspectionCatalogError::Unavailable)?,
+ None => {
+ crate::config::build_runtime_proxy_client_with_timeouts("providers.list_models", 30, 10)
+ }
+ };
+ let provider = entry.slug.clone();
+ let auth_style = entry.auth_style;
+ let frozen_token = token.clone();
+ let fetch_url = url.clone();
+ let fetch = Box::pin(async move {
+ let mut request = client.get(fetch_url);
+ if let Some(token) = frozen_token.as_deref() {
+ request = match auth_style {
+ AuthStyle::Anthropic => request
+ .header("x-api-key", token)
+ .header("anthropic-version", "2023-06-01"),
+ AuthStyle::Bearer => request.bearer_auth(token),
+ AuthStyle::None | AuthStyle::OpenhumanJwt => request,
+ };
+ }
+ let response = request.send().await.map_err(|error| {
+ if error.is_timeout() {
+ InspectionCatalogError::Failure
+ } else {
+ InspectionCatalogError::Unavailable
+ }
+ })?;
+ let status = response.status();
+ if status == reqwest::StatusCode::NOT_FOUND {
+ return Err(InspectionCatalogError::NoCatalog);
+ }
+ if matches!(
+ status,
+ reqwest::StatusCode::UNAUTHORIZED | reqwest::StatusCode::FORBIDDEN
+ ) {
+ return Err(InspectionCatalogError::AuthOrAccess);
+ }
+ if !status.is_success() {
+ return Err(InspectionCatalogError::Failure);
+ }
+ let body = response
+ .json::<serde_json::Value>()
+ .await
+ .map_err(|_| InspectionCatalogError::Failure)?;
+ let models = tinyinference_llm::catalog::parse_models_response(&body)
+ .map_err(|_| InspectionCatalogError::Failure)?;
+ Ok(Outcome::new(
+ serde_json::json!({"models": models}),
+ Vec::new(),
+ ))
+ });
+ Ok(PreparedInspectionCatalog::new(
+ &provider,
+ url.as_str(),
+ token.as_deref(),
+ fetch,
+ ))
+ }
+
+ async fn catalog_for(
+ config: &crate::config::Config,
+ entry: &CloudProviderCreds,
+ use_cache: bool,
+ ) -> Result<(serde_json::Value, Vec<String>), InspectionCatalogError> {
+ match tokio::time::timeout(
+ PROVIDER_CATALOG_TIMEOUT,
+ catalog_for_with_timeout(config, entry, use_cache),
+ )
+ .await
+ {
+ Ok(result) => result,
+ Err(_) => Err(InspectionCatalogError::Failure),
+ }
+ }
+
+ async fn catalog_for_with_timeout(
+ config: &crate::config::Config,
+ entry: &CloudProviderCreds,
+ use_cache: bool,
+ ) -> Result<(serde_json::Value, Vec<String>), InspectionCatalogError> {
+ let prepared = prepare(config, entry).await?;
+ let cache_key = hash_key(&(scope_key(config), entry.slug.clone(), prepared.identity()));
+ if use_cache {
+ if let Some((at, result)) = CATALOG_CACHE
+ .lock()
+ .unwrap_or_else(|e| e.into_inner())
+ .get(&cache_key)
+ {
+ if at.elapsed() < CACHE_TTL {
+ return result.clone();
+ }
+ }
+ }
+ let result = prepared
+ .fetch()
+ .await
+ .map(|outcome| (outcome.value, outcome.logs));
+ CATALOG_CACHE
+ .lock()
+ .unwrap_or_else(|e| e.into_inner())
+ .insert(cache_key, (Instant::now(), result.clone()));
+ result
+ }
+
+ pub async fn doctor_models(config: &crate::config::Config, use_cache: bool) -> ModelProbeReport {
+ let mut entries = Vec::new();
+ for provider in configured_entries(config) {
+ let (outcome, message) = match catalog_for(config, &provider, use_cache).await {
+ Ok((value, _)) => {
+ let models = value
+ .get("models")
+ .and_then(serde_json::Value::as_array)
+ .cloned()
+ .unwrap_or_default();
+ (
+ ModelProbeOutcome::Ok,
+ Some(format!("Catalog returned {} models.", models.len())),
+ )
+ }
+ Err(InspectionCatalogError::AuthOrAccess) => (
+ ModelProbeOutcome::AuthOrAccess,
+ Some("Catalog access was rejected.".into()),
+ ),
+ Err(InspectionCatalogError::NoCatalog) => (
+ ModelProbeOutcome::Skipped,
+ Some("Provider does not expose a models catalog.".into()),
+ ),
+ Err(InspectionCatalogError::Unavailable) => (
+ ModelProbeOutcome::Skipped,
+ Some("A safe read-only catalog is unavailable.".into()),
+ ),
+ Err(InspectionCatalogError::Failure) => (
+ ModelProbeOutcome::Error,
+ Some("Catalog request failed.".into()),
+ ),
+ };
+ entries.push(ModelProbeEntry {
+ provider: provider.slug,
+ outcome,
+ message,
+ });
+ }
+ ModelProbeReport {
+ summary: ModelProbeSummary {
+ ok: entries
+ .iter()
+ .filter(|e| e.outcome == ModelProbeOutcome::Ok)
+ .count(),
+ skipped: entries
+ .iter()
+ .filter(|e| e.outcome == ModelProbeOutcome::Skipped)
+ .count(),
+ auth_or_access: entries
+ .iter()
+ .filter(|e| e.outcome == ModelProbeOutcome::AuthOrAccess)
+ .count(),
+ errors: entries
+ .iter()
+ .filter(|e| e.outcome == ModelProbeOutcome::Error)
+ .count(),
+ },
+ entries,
+ }
+ }
+
+ pub(crate) struct ModelInCatalog;
+ #[async_trait]
+ impl DoctorCheck for ModelInCatalog {
+ fn id(&self) -> &str {
+ "inference/model-in-catalog"
+ }
+ fn category(&self) -> &str {
+ "inference"
+ }
+ fn tier(&self) -> DoctorTier {
+ DoctorTier::Connect
+ }
+ fn is_blocking(&self) -> bool {
+ false
+ }
+ async fn detect(&self, ctx: &DoctorCtx) -> Vec<Finding> {
+ let entries = configured_entries(ctx.config());
+ if entries.is_empty() {
+ return vec![Finding::skipped(
+ self.id(),
+ "No configured inference catalog is available.",
+ "Configure a model provider and rerun doctor.",
+ )];
+ }
+ let mut findings = Vec::new();
+ for entry in entries {
+ let catalog = match catalog_for(ctx.config(), &entry, true).await {
+ Ok((value, _)) => value
+ .get("models")
+ .and_then(serde_json::Value::as_array)
+ .cloned()
+ .unwrap_or_default(),
+ Err(InspectionCatalogError::NoCatalog) => {
+ findings.push(Finding::skipped(
+ self.id(),
+ "Provider has no model catalog route.",
+ "Choose a provider with a read-only models route.",
+ ));
+ continue;
+ }
+ Err(InspectionCatalogError::Unavailable) => {
+ findings.push(Finding::skipped(
+ self.id(),
+ "Safe read-only model catalog is unavailable.",
+ "Reconnect the provider or use doctor.models for details.",
+ ));
+ continue;
+ }
+ Err(InspectionCatalogError::AuthOrAccess) => {
+ findings.push(Finding::new(
+ self.id(),
+ FindingSeverity::Warn,
+ "Provider rejected catalog access.",
+ "Check the selected provider credentials.",
+ ));
+ continue;
+ }
+ Err(InspectionCatalogError::Failure) => {
+ findings.push(Finding::new(
+ self.id(),
+ FindingSeverity::Warn,
+ "Provider catalog could not be read.",
+ "Check provider availability and rerun doctor.",
+ ));
+ continue;
+ }
+ };
+ let ids = catalog
+ .iter()
+ .filter_map(|model| model.get("id").and_then(serde_json::Value::as_str))
+ .collect::<Vec<_>>();
+ let selected = selected_models(ctx.config());
+ for (path, model) in selected
+ .iter()
+ .filter(|(_, model)| {
+ model.starts_with(&format!("{}:", entry.slug))
+ || (entry.slug == "openhuman" && model.starts_with("openrouter/"))
+ })
+ .map(|(path, model)| {
+ (
+ path.as_str(),
+ if model.starts_with("openrouter/") {
+ model.as_str()
+ } else {
+ model
+ .split_once(':')
+ .map(|(_, model)| model)
+ .unwrap_or(model.as_str())
+ },
+ )
+ })
+ {
+ if !ids.contains(&model) {
+ let mut finding = Finding::new(
+ self.id(),
+ FindingSeverity::Warn,
+ format!(
+ "Configured model at {path} is not present in the provider catalog."
+ ),
+ "Choose a model listed by the provider or update this route.",
+ );
+ finding.config_path = Some(path.to_owned());
+ findings.push(finding);
+ }
+ }
+ }
+ findings
+ }
+ }
+
+ fn selected_models(config: &crate::config::Config) -> Vec<(String, String)> {
+ let mut models = Vec::new();
+ if let Some(model) = &config.default_model {
+ models.push(("default_model".to_owned(), model.clone()));
+ }
+ for (index, route) in config.model_routes.iter().enumerate() {
+ models.push((format!("model_routes[{index}].model"), route.model.clone()));
+ }
+ models
+ }
+
+ pub(crate) struct AuthErrors;
+ #[async_trait]
+ impl DoctorCheck for AuthErrors {
+ fn id(&self) -> &str {
+ "inference/auth-errors"
+ }
+ fn category(&self) -> &str {
+ "inference"
+ }
+ fn tier(&self) -> DoctorTier {
+ DoctorTier::Connect
+ }
+ fn is_blocking(&self) -> bool {
+ false
+ }
+ async fn detect(&self, ctx: &DoctorCtx) -> Vec<Finding> {
+ let mut findings = Vec::new();
+ let (errors, has_unscoped) = crate::inference::auth_error_registry::snapshot_for_scope(
+ &ctx.config().workspace_dir,
+ &ctx.config().config_path,
+ ctx.profile(),
+ );
+ for error in errors {
+ findings.push(Finding::new(
+ self.id(),
+ FindingSeverity::Error,
+ format!(
+ "Provider {} has a recorded authentication error.",
+ error.provider
+ ),
+ "Update or reconnect this provider's credentials.",
+ ));
+ }
+ if has_unscoped {
+ findings.push(Finding::new(
+ self.id(),
+ FindingSeverity::Info,
+ "A provider authentication error was recorded outside a known inspection scope.",
+ "Rerun doctor after reproducing the issue in the selected profile.",
+ ));
+ }
+ findings
+ }
+ }
+
+ pub(crate) fn built_in_checks() -> Vec<Arc<dyn DoctorCheck>> {
+ vec![Arc::new(ModelInCatalog), Arc::new(AuthErrors)]
+ }
diff --cc crates/openhuman-core/src/inference/embedding_host/factory.rs
index a4de4dc1a7,8c04c07fca..a65db783e6
--- a/crates/openhuman-core/src/inference/embedding_host/factory.rs
+++ b/crates/openhuman-core/src/inference/embedding_host/factory.rs
@@@ -4,19 -4,17 +4,19 @@@ use std::sync::Arc
use crate::config::Config;
use tinyinference_embeddings::factory::{
-- create_configured_embedding_model, create_default_embedding_model, CredentialResolver,
-- EmbeddingFactorySettings, ManagedModelFactory,
++ CredentialResolver, EmbeddingFactorySettings, ManagedModelFactory,
++ create_configured_embedding_model, create_default_embedding_model,
};
-use tinyinference_embeddings::EmbeddingModel;
+use tinyinference_embeddings::{EmbeddingModel, UnavailableEmbeddingModel};
+use tinyinference_providers::route::custom_provider_string;
-use super::cloud::{credential_scope, UnavailableEmbeddingModel};
use crate::inference::provider::factory::PROVIDER_OPENHUMAN;
-use crate::inference::registry::EmbeddingRequest;
+use crate::inference::registry::ProviderContext;
use crate::security::approval::ApprovalChatContext;
+use crate::security::credentials::embedding_scope::credential_scope;
+use tinyinference_llm::providers::overrides::EmbeddingRequest;
-fn settings(
+pub(super) fn settings(
provider: &str,
model: &str,
dimensions: usize,
@@@ -63,7 -48,32 +63,31 @@@ pub(super) fn managed_factory
})
}
+ fn inspection_managed_factory(config: &Config) -> ManagedModelFactory {
+ let config = config.clone();
+ Arc::new(move |model, dimensions| {
+ let Some(registered) = crate::inference::registry::inspection_embedding(PROVIDER_OPENHUMAN)
+ else {
+ log::debug!("[embeddings::factory] no inspection-safe managed embedder registered");
+ return Ok(Box::new(UnavailableEmbeddingModel::new(model, dimensions)));
+ };
+ let (state_dir, secrets_encrypt) = credential_scope(Some(&config));
++ let context =
++ ProviderContext::for_embedding(Some(&config), None, state_dir, secrets_encrypt);
+ registered(&EmbeddingRequest {
- config: Some(&config),
+ model,
+ dimensions,
- chat: None,
- state_dir,
- secrets_encrypt,
++ context: &context,
+ })
+ .map_err(|_| {
+ tinyinference_embeddings::Error::Validation(
+ "managed embedding inspection is unavailable".to_owned(),
+ )
+ })
+ })
+ }
+
-fn credential_resolver(config: &Config) -> CredentialResolver {
+pub(super) fn credential_resolver(config: &Config) -> CredentialResolver {
let config = config.clone();
Arc::new(move |provider| super::rpc::resolve_api_key(&config, provider))
}
diff --cc crates/openhuman-core/src/inference/embedding_host/mod.rs
index fe45bac5b5,d5b467fdba..41b38fc0ad
--- a/crates/openhuman-core/src/inference/embedding_host/mod.rs
+++ b/crates/openhuman-core/src/inference/embedding_host/mod.rs
@@@ -17,12 -19,16 +17,13 @@@ mod factory
mod rpc;
mod schemas;
-pub use cloud::{
- UnavailableEmbeddingModel, DEFAULT_CLOUD_EMBEDDING_DIMENSIONS, DEFAULT_CLOUD_EMBEDDING_MODEL,
-};
pub use factory::{
- create_embedding_provider_for_chat, create_embedding_provider_with_config,
- create_embedding_provider_with_credentials, default_embedding_provider_for_chat,
- default_embedding_provider_with_config,
+ create_embedding_provider_for_chat, create_embedding_provider_for_inspection,
+ create_embedding_provider_with_config, create_embedding_provider_with_credentials,
+ default_embedding_provider_for_chat, default_embedding_provider_with_config,
};
pub use rpc::provider_from_config;
+ pub(crate) use rpc::{probe_dimensions_for_inspection, InspectionEmbeddingError};
/// A shared embedding provider as this module's factories return it, nameable
/// by hosts that hold one without depending on the embeddings crate.
pub type SharedEmbeddingModel = std::sync::Arc<dyn tinyinference_embeddings::EmbeddingModel>;
diff --cc crates/openhuman-core/src/inference/embedding_host/rpc.rs
index 45e490a0a8,63dd6116ae..a39f94b9da
--- a/crates/openhuman-core/src/inference/embedding_host/rpc.rs
+++ b/crates/openhuman-core/src/inference/embedding_host/rpc.rs
@@@ -10,10 -10,21 +10,11 @@@ mod settings
pub use api_keys::{clear_api_key, set_api_key};
pub use embed::{embed, test_connection};
+ pub(crate) use embed::{probe_dimensions_for_inspection, InspectionEmbeddingError};
pub use settings::{get_settings, update_settings};
-#[cfg(test)]
-use tinyinference_embeddings::probe::redact_secrets;
-
#[cfg(test)]
use settings::remember_active_custom_profile;
-#[cfg(test)]
-use tinyinference_embeddings::probe::{classify_embed_probe, EmbedProbe};
-#[cfg(test)]
-use tinyinference_embeddings::served_models::{
- check_requested_model_served, fetch_served_model_ids, normalize_embed_model_id,
- reject_model_not_served,
-};
use crate::config::Config;
use crate::security::credentials::AuthService;
diff --cc crates/openhuman-core/src/inference/embedding_host/rpc/embed.rs
index 67fd5d86d4,f2da1a3a49..e0fbb5f012
--- a/crates/openhuman-core/src/inference/embedding_host/rpc/embed.rs
+++ b/crates/openhuman-core/src/inference/embedding_host/rpc/embed.rs
@@@ -3,12 -3,11 +3,14 @@@
use crate::config::Config;
use crate::core::Outcome;
--use super::{resolve_api_key, LOG_PREFIX};
++use super::{LOG_PREFIX, resolve_api_key};
use crate::inference::embedding_host::factory::{
- create_embedding_provider_with_config, credential_resolver, managed_factory, settings,
+ create_embedding_provider_for_inspection, create_embedding_provider_with_config,
++ credential_resolver, managed_factory, settings,
};
- use tinyinference_embeddings::verify::{test_embedding_connection_detailed, ConnectionTestError};
+ use tinyinference_embeddings::probe::probe_custom_embeddings;
++use tinyinference_embeddings::verify::{ConnectionTestError, test_embedding_connection_detailed};
+use tinyinference_providers::route::split_custom_provider;
/// Generates embeddings for the given input texts using the currently
/// configured provider.
diff --cc crates/openhuman-core/src/inference/ops/models.rs
index 95c0e6515d,0000000000..cc0c557e29
mode 100644,000000..100644
--- a/crates/openhuman-core/src/inference/ops/models.rs
+++ b/crates/openhuman-core/src/inference/ops/models.rs
@@@ -1,123 -1,0 +1,134 @@@
+use crate::config::rpc as config_rpc;
+use crate::core::runtime::DispatchCtx;
+use crate::core::Outcome;
+use crate::inference::host_runtime as local_runtime;
+use crate::inference::provider as providers;
+use serde_json::Value;
+use tracing::{debug, error, warn};
+
+const LOG_PREFIX: &str = "[inference::ops]";
+
+pub(super) fn is_unknown_provider_user_config(err: &str) -> bool {
+ err.contains("no cloud provider with id or slug")
+}
+
+pub async fn inference_get_client_config(ctx: &DispatchCtx) -> Result<Outcome<Value>, String> {
+ debug!("{LOG_PREFIX} get_client_config:start");
+ let result = config_rpc::load_and_get_client_config_snapshot(ctx).await;
+ match &result {
+ Ok(_) => debug!("{LOG_PREFIX} get_client_config:ok"),
+ Err(err) => warn!(error = %err, "{LOG_PREFIX} get_client_config:error"),
+ }
+ result
+}
+
+pub async fn inference_update_model_settings(
+ ctx: &DispatchCtx,
+ update: config_rpc::ModelSettingsPatch,
+) -> Result<Outcome<Value>, String> {
+ debug!("{LOG_PREFIX} update_model_settings:start");
+ let result = config_rpc::load_and_apply_model_settings(ctx, update).await;
+ match &result {
+ Ok(_) => debug!("{LOG_PREFIX} update_model_settings:ok"),
+ Err(err) => warn!(error = %err, "{LOG_PREFIX} update_model_settings:error"),
+ }
+ result
+}
+
+pub async fn inference_update_local_settings(
+ ctx: &DispatchCtx,
+ update: config_rpc::LocalAiSettingsPatch,
+) -> Result<Outcome<Value>, String> {
+ debug!("{LOG_PREFIX} update_local_settings:start");
+ let result = config_rpc::load_and_apply_local_ai_settings(ctx, update).await;
+ match &result {
+ Ok(_) => {
+ debug!("{LOG_PREFIX} update_local_settings:ok");
+ // The endpoint, provider or models may have changed: drop the
+ // cached probe verdict so the next status poll re-probes the
+ // user's runtime instead of reporting the old endpoint's state.
+ match ctx.load_config().await {
+ Ok(config) => {
+ let runtime = crate::inference::local_runtime_config(&config);
+ local_runtime::global(&config).reset_to_idle(&runtime);
+ debug!("{LOG_PREFIX} update_local_settings:probe_reset");
+ }
+ Err(err) => warn!(
+ error = %err,
+ "{LOG_PREFIX} update_local_settings:probe_reset_skipped (config reload failed)"
+ ),
+ }
+ }
+ Err(err) => warn!(error = %err, "{LOG_PREFIX} update_local_settings:error"),
+ }
+ result
+}
+
- pub async fn inference_list_models(provider_id: &str) -> Result<Outcome<Value>, String> {
++pub async fn inference_list_models(
++ ctx: &DispatchCtx,
++ provider_id: &str,
++) -> Result<Outcome<Value>, String> {
+ debug!(provider_id, "{LOG_PREFIX} list_models:start");
- let result = providers::models::catalog_listing::list_configured_models(provider_id).await;
++ let result = match ctx.load_config().await {
++ Ok(config) => {
++ providers::models::catalog_listing::list_configured_models_from_config(
++ provider_id, &config,
++ )
++ .await
++ }
++ Err(error) => Err(error),
++ };
+ match &result {
+ Ok(_) => debug!("{LOG_PREFIX} list_models:ok"),
+ Err(err) => {
+ if is_unknown_provider_user_config(err) {
+ // User selected a provider id that isn't a registered
+ // cloud provider (e.g. picking "ollama", a local runtime).
+ // Demote to `warn!` so it stays in local logs but doesn't
+ // escalate to Sentry. Targets TAURI-RUST-X (~5740 events).
+ warn!(
+ provider_id,
+ error = %err,
+ "{LOG_PREFIX} list_models:unknown-provider (user-config)"
+ );
+ } else if let Some(kind) = crate::core::observability::expected_error_kind(err) {
+ // Classify at the TYPED SOURCE — run the raw provider error
+ // through the central classifier BEFORE the
+ // `[inference::ops] list_models:error: …` prefix is applied,
+ // then `warn!` so the Sentry tracing layer records at most a
+ // breadcrumb instead of a hard error event.
+ //
+ // TAURI-RUST-8X3: a user pointed a custom OpenAI-compatible
+ // provider at a base URL with no `/models` route, so the
+ // probe returns `provider returned 404: 404 page not found`.
+ // That is a preventable user-state condition (wrong base URL;
+ // the dropdown already surfaces an actionable hint inline) —
+ // not a code bug. The 404 arm of
+ // `is_provider_user_state_message` matched the *raw* error
+ // string fine, but the previous `error!` path captured the
+ // PREFIXED log line, so the demotion never reached Sentry's
+ // classifier. Classifying the raw `err` here removes that
+ // dependency on the log-string shape entirely; any
+ // `ExpectedErrorKind` the central classifier recognizes is
+ // demoted at the source.
+ warn!(
+ provider_id,
+ error = %err,
+ expected_kind = ?kind,
+ "{LOG_PREFIX} list_models:expected (user-config): {err}"
+ );
+ } else {
+ // Real error — embed `{err}` in the format string so
+ // Sentry's event title carries the actionable cause
+ // instead of the opaque `list_models:error` shape that
+ // made TAURI-RUST-X untriageable.
+ error!(
+ provider_id,
+ error = %err,
+ "{LOG_PREFIX} list_models:error: {err}"
+ );
+ }
+ }
+ }
+ result
+}
diff --cc crates/openhuman-core/src/inference/ops_tests.rs
index d0463dab25,75d1f0acdf..94f4975dd6
--- a/crates/openhuman-core/src/inference/ops_tests.rs
+++ b/crates/openhuman-core/src/inference/ops_tests.rs
@@@ -7,6 -6,6 +7,41 @@@ use axum::{routing::post, Json, Router}
use chrono::{Duration, Utc};
use tempfile::tempdir;
++#[tokio::test]
++async fn inference_list_models_uses_the_dispatch_context_config() {
++ use crate::core::runtime::{context::CoreContext, DispatchCtx, DomainSet};
++ use crate::inference::provider::model_listing_test_support::{
++ configure_generic_workspace, spawn_static_models_server,
++ };
++
++ let models_a = r#"{"data":[{"id":"tenant-a-model","owned_by":"fixture"}]}"#;
++ let models_b = r#"{"data":[{"id":"tenant-b-model","owned_by":"fixture"}]}"#;
++ let endpoint_a = spawn_static_models_server(axum::http::StatusCode::OK, models_a).await;
++ let endpoint_b = spawn_static_models_server(axum::http::StatusCode::OK, models_b).await;
++ let workspace_a = tempdir().expect("tenant A workspace");
++ let workspace_b = tempdir().expect("tenant B workspace");
++ let config_a = configure_generic_workspace(&workspace_a, endpoint_a).await;
++ let config_b = configure_generic_workspace(&workspace_b, endpoint_b).await;
++ let ctx_a = DispatchCtx::new(CoreContext::for_test_with_config(
++ DomainSet::full(),
++ config_a,
++ ));
++ let ctx_b = DispatchCtx::new(CoreContext::for_test_with_config(
++ DomainSet::full(),
++ config_b,
++ ));
++
++ let result_a = inference_list_models(&ctx_a, "p_generic_test")
++ .await
++ .expect("tenant A catalog request succeeds");
++ let result_b = inference_list_models(&ctx_b, "p_generic_test")
++ .await
++ .expect("tenant B catalog request succeeds");
++
++ assert_eq!(result_a.value["models"][0]["id"], "tenant-a-model");
++ assert_eq!(result_b.value["models"][0]["id"], "tenant-b-model");
++}
++
fn disabled_config() -> (Config, tempfile::TempDir) {
let tmp = tempdir().expect("tempdir");
let mut config = Config {
diff --cc crates/openhuman-core/src/inference/provider/factory.rs
index 9663e102ad,c69285e687..1ab0f105b1
--- a/crates/openhuman-core/src/inference/provider/factory.rs
+++ b/crates/openhuman-core/src/inference/provider/factory.rs
@@@ -1,8 -1,33 +1,7 @@@
-//! Unified chat-provider factory.
+//! Host adapter for provider construction and access policy. Provider route
+//! grammar and route-kind classification live in TinyInference.
//!
-//! Resolves workload names (e.g. `"reasoning"`, `"summarization"`) to a
-//! crate-native `ChatModel` plus the concrete model id selected for a workload.
-//!
-//! ## Provider-string grammar
-//!
-//! ```text
-//! "openhuman" → the registered managed chat model; model = config.default_model
-//! "cloud" / missing → primary_cloud; legacy custom inference_url wins when
-//! primary still points at OpenHuman after migration
-//! "ollama:<model>[@<temp>]" → local Ollama at config.local_ai.base_url
-//! "lmstudio:<model>[@<temp>]" → local LM Studio
-//! "mlx:<model>[@<temp>]" → local MLX-compatible server
-//! "local-openai:<model>[@<temp>]"→ generic local OpenAI-compatible
-//! "<slug>:<model>[@<temp>]" → cloud_providers entry keyed by slug;
-//! builds the crate-native OpenAI client (Bearer) or
-//! Anthropic flavour depending on auth_style.
-//! ```
-//!
-//! The optional `@<temp>` suffix pins a per-workload temperature override on
-//! the built provider. The model id sent upstream never includes the suffix.
-//!
-//! Unknown slugs and missing-creds configurations produce actionable errors.
-//!
-//! ## Module layout
-//!
-//! - [`tiers`] — managed tier / `hint:*` vocabulary and capability lookups.
//! - [`routing`] — role → configured provider string resolution.
--//! - [`primary_cloud`] — `primary_cloud` / legacy `inference_url` resolution.
//! - [`access_gates`] — privacy-mode, session, and egress chokepoints.
//! - [`credentials`] — auth-profile key lookup for cloud slugs.
//! - [`managed_backend`] — the managed provider resolution (tier pinning, privacy gate, egress) in front of the registered chat model.
@@@ -17,42 -43,68 +16,54 @@@ mod chat_model
mod cloud_slug;
mod cloud_spec;
mod credentials;
-mod discovery;
++mod inspection;
mod local_runtime;
mod managed_backend;
-mod primary_cloud;
mod routing;
mod subprocess_providers;
-mod tiers;
-mod turn_model;
-pub(crate) use chat_model::create_chat_model_with_identity_in_for_inspection;
-pub(crate) use chat_model::create_chat_model_with_model_id_in_for_inspection;
-pub(crate) use chat_model::resolves_to_managed_backend;
++pub(crate) use chat_model::{OpenHumanModelFactory, resolves_to_managed_backend};
pub use chat_model::{
create_chat_model_from_string, create_chat_model_from_string_with_model_id,
create_chat_model_in, create_chat_model_with_model_id_in, probe_inference_readiness,
};
- pub(crate) use chat_model::{resolves_to_managed_backend, OpenHumanModelFactory};
-pub(crate) use credentials::openai_bearer_is_oauth;
-pub use credentials::{auth_key_for_slug, lookup_key_for_slug, redact_endpoint};
-pub(crate) use discovery::model_limits_request;
-pub(crate) use local_runtime::create_local_chat_model_from_string;
-pub(crate) use managed_backend::make_openhuman_backend_model;
-pub(crate) use routing::role_uses_implicit_cloud_fallback;
-pub use routing::{provider_for_role, role_bypasses_managed_credits};
-pub(crate) use tiers::{
- is_known_openhuman_tier, is_raw_passthrough_model, oh_tier_supports_vision,
+pub(crate) use cloud_slug::resolve_cloud_slug_for;
- pub(crate) use cloud_spec::{cloud_provider_spec, CloudCredentialResolver};
++pub(crate) use cloud_spec::{CloudCredentialResolver, cloud_provider_spec};
+pub use credentials::{auth_key_for_slug, lookup_key_for_slug};
+pub(crate) use credentials::{
+ openai_bearer_is_oauth, redact_endpoint_origin, resolve_codex_routing,
};
-pub use tiers::{resolve_model_for_hint, role_for_model_tier};
-pub(crate) use turn_model::{
- create_turn_chat_model, create_turn_chat_model_from_string,
- create_turn_chat_model_from_string_with_native_tools_and_route,
- create_turn_chat_model_with_native_tools_and_route,
++pub(crate) use inspection::{
++ create_chat_model_with_identity_in_for_inspection,
++ create_chat_model_with_model_id_in_for_inspection,
+ };
+pub(crate) use local_runtime::create_local_chat_model_from_string;
+pub(crate) use routing::fallback_diagnostics_for_role;
++pub(crate) use routing::{ConfigRouteSource, workload_router};
+pub use routing::{provider_for_role, role_bypasses_managed_credits};
- pub(crate) use routing::{workload_router, ConfigRouteSource};
-// Factory-internal helpers shared across the submodules (and their tests)
-// through `use super::*`.
+// Factory-internal helpers shared across the implementation modules.
use access_gates::{emit_inference_egress, enforce_local_only_inference};
+ use chat_model::{unresolved_chat_model_error, with_default_temperature};
+#[cfg(test)]
+use cloud_slug::try_create_cloud_slug_chat_model;
- #[cfg(test)]
- use cloud_slug::try_create_cloud_slug_chat_model_from_string;
- use cloud_slug::try_create_cloud_slug_chat_model_from_string_with_native_tools_for;
- use local_runtime::{try_create_local_runtime_chat_model_from_string, OptionalChatModelResult};
- #[cfg(test)]
- pub(crate) use managed_backend::make_openhuman_backend_model_for_thread;
+ use cloud_slug::{
- resolve_cloud_slug, resolve_cloud_slug_with_access, try_create_cloud_slug_chat_model,
- try_create_cloud_slug_chat_model_for_inspection,
- try_create_cloud_slug_chat_model_for_inspection_with_identity,
- try_create_cloud_slug_chat_model_from_string,
- try_create_cloud_slug_chat_model_with_native_tools,
++ resolve_cloud_slug_with_access, try_create_cloud_slug_chat_model_for_inspection_with_identity,
++ try_create_cloud_slug_chat_model_from_string_with_native_tools_for,
+ };
+ use credentials::CredentialAccess;
+ use local_runtime::{
- try_create_local_runtime_chat_model, try_create_local_runtime_chat_model_for_inspection,
- try_create_local_runtime_chat_model_from_string, OptionalChatModelResult,
++ OptionalChatModelResult, try_create_local_runtime_chat_model_for_inspection,
++ try_create_local_runtime_chat_model_from_string,
+ };
+use managed_backend::managed_chat_model_for;
pub(crate) use managed_backend::{
- make_openhuman_backend_model_for_options, make_openhuman_backend_model_for_thread,
+ make_openhuman_backend_model_for_options, make_openhuman_backend_model_for_thread_in,
};
- use subprocess_providers::OpenHumanMcpEndpoint;
-use managed_backend::{managed_chat_model, resolve_managed_model};
-use primary_cloud::{legacy_inference_slug, resolve_primary_cloud_provider_string};
+ use subprocess_providers::{
- prepare_claude_agent_sdk_chat_model, try_create_claude_agent_sdk_chat_model,
- try_create_claude_agent_sdk_chat_model_for_inspection,
- try_create_claude_agent_sdk_chat_model_from_string, try_create_claude_code_chat_model,
++ OpenHumanMcpEndpoint, try_create_claude_agent_sdk_chat_model_for_inspection,
+ try_create_claude_code_chat_model_for_inspection,
- try_create_claude_code_chat_model_from_string,
+ };
-use tiers::{is_abstract_tier_model, managed_default_model};
use tinyinference_providers::route::split_model_and_temperature;
/// Test-only seam: inject a mock [`ChatModel`] so e2e tests can drive the
@@@ -74,21 -126,76 +85,63 @@@ pub mod test_provider_override
#[path = "factory_tests.rs"]
mod factory_tests;
--use crate::config::schema::cloud_providers::AuthStyle;
use crate::config::Config;
-use crate::inference::provider::openai_codex::{
- resolve_openai_codex_routing, resolve_openai_codex_routing_for_inspection,
-};
--use crate::security::credentials::AuthService;
++use crate::config::schema::cloud_providers::AuthStyle;
++use crate::inference::provider::openai_codex::resolve_openai_codex_routing_for_inspection;
use crate::security::egress::EgressLedger;
use std::sync::Arc;
-use tinyagents_harness::providers::claude_agent_sdk::ClaudeAgentSdkProvider;
-use tinyinference_llm::model::{ChatModel, ModelRequest, ModelResponse, ModelStream};
+use tinyinference_llm::model::ChatModel;
use tinyinference_llm::providers::openai::codex::{
-- openai_codex_client_version, openai_codex_user_agent, OPENAI_CODEX_ACCOUNT_HEADER,
-- OPENAI_CODEX_ORIGINATOR, OPENAI_CODEX_ORIGINATOR_HEADER,
++ OPENAI_CODEX_ACCOUNT_HEADER, OPENAI_CODEX_ORIGINATOR, OPENAI_CODEX_ORIGINATOR_HEADER,
++ openai_codex_client_version, openai_codex_user_agent,
};
-use tinyinference_llm::providers::openai::AuthStyle as CompatAuthStyle;
+ /// Opaque per-report identity for an inspection completion. It contains the
+ /// effective endpoint, exact frozen credential, and actual wire model, but
+ /// deliberately has no Debug/Display implementation.
+ #[derive(Clone, Eq, Hash, PartialEq)]
+ pub(crate) struct InspectionRequestIdentity {
+ endpoint: String,
+ credential: String,
+ wire_model: String,
+ }
+
+ impl InspectionRequestIdentity {
+ pub(crate) fn new(endpoint: String, credential: String, wire_model: String) -> Self {
+ Self {
+ endpoint,
+ credential,
+ wire_model,
+ }
+ }
+ }
+
+ /// Whether the resolved inspection route can enforce the requested output
+ /// token ceiling on the provider request.
+ #[derive(Debug, Clone, Copy, Eq, PartialEq)]
+ pub(crate) enum InspectionOutputBudgetCapability {
+ /// The provider request enforces its requested output-token limit.
+ Bounded,
+ /// The provider route cannot express a bounded output-token request.
+ Unsupported,
+ }
+
+ /// Result shape shared by inspection-only provider constructors.
+ type InspectionChatModelResult =
+ Option<anyhow::Result<(Arc<dyn ChatModel<()>>, String, String, String)>>;
+
+ /// Prepared, frozen model plus its opaque deduplication identity.
+ pub(crate) struct PreparedInspectionChatModel {
+ pub(crate) model: Arc<dyn ChatModel<()>>,
+ pub(crate) model_id: String,
+ pub(crate) identity: InspectionRequestIdentity,
+ pub(crate) output_budget: InspectionOutputBudgetCapability,
+ }
+
/// Sentinel meaning "use the OpenHuman backend session JWT".
pub const PROVIDER_OPENHUMAN: &str = "openhuman";
-/// Prefix for Ollama-local providers: `"ollama:<model>"`.
-pub const OLLAMA_PROVIDER_PREFIX: &str = "ollama:";
-/// Prefix for LM Studio-local providers: `"lmstudio:<model>"`.
-pub const LM_STUDIO_PROVIDER_PREFIX: &str = "lmstudio:";
-/// Prefix for MLX-compatible local providers: `"mlx:<model>"`.
-pub const MLX_PROVIDER_PREFIX: &str = "mlx:";
-/// Prefix for OMLX local providers: `"omlx:<model>"`.
-pub const OMLX_PROVIDER_PREFIX: &str = "omlx:";
-/// Prefix for generic local OpenAI-compatible providers: `"local-openai:<model>"`.
-pub const LOCAL_OPENAI_PROVIDER_PREFIX: &str = "local-openai:";
+/// Provider id used for the managed OpenHuman inference backend.
+pub const INFERENCE_BACKEND_ID: &str = PROVIDER_OPENHUMAN;
/// Prefix for the Claude Agent SDK subprocess provider: `"claude_agent_sdk:<model>"`.
pub const CLAUDE_AGENT_SDK_PREFIX: &str = "claude_agent_sdk:";
/// Sentinel for the Claude Agent SDK provider without a model suffix.
diff --cc crates/openhuman-core/src/inference/provider/factory/chat_model.rs
index c92ed40e1b,9c6a5bdf5d..bb658cdb3e
--- a/crates/openhuman-core/src/inference/provider/factory/chat_model.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/chat_model.rs
@@@ -2,388 -2,9 +2,388 @@@
//! default-temperature wrapper, and the unresolved-route error builder.
use super::*;
+use crate::config::ops::resolve_primary_cloud_provider_string;
use crate::core::runtime::DispatchCtx;
-#[cfg(not(test))]
-use crate::inference::provider::factory::access_gates::verify_session_active;
+use tinyagents_harness::host::{
+ BuildOpts, ModelBuildGate, ModelBuildRequest, ModelFactory, ModelPurpose,
+};
+use tinyinference_llm::model::{ModelRequestDefaults, ProfileOverrideModel, ResolvedModelRoute};
+use tinyinference_providers::route::{ProviderRoute, RouteKind};
+
+/// OpenHuman's host policy and construction adapter for a harness turn.
+///
+/// The harness owns turn assembly; this adapter resolves OpenHuman provider
+/// configuration and enforces product access policy for each requested model.
+pub(crate) struct OpenHumanModelFactory<'a> {
+ pub(crate) ctx: &'a DispatchCtx,
+ pub(crate) config: &'a Config,
+ pub(crate) primary_provider: Option<&'a str>,
+ pub(crate) egress: &'a EgressLedger,
+ pub(crate) thread_id: Option<&'a str>,
+ /// Attach OpenHuman's per-turn multimodal providers using the route this
+ /// factory actually selected. One-shot probes do not need host attachments.
+ pub(crate) attach_host_attachments: bool,
+}
+
+impl OpenHumanModelFactory<'_> {
+ fn route_name<'a>(request: &'a ModelBuildRequest, role: &'a str) -> &'a str {
+ request
+ .route
+ .as_deref()
+ .or_else(|| request.model_pin.as_deref().filter(|pin| !pin.is_empty()))
+ .unwrap_or(role)
+ }
+
+ fn provider_for(&self, request: &ModelBuildRequest) -> String {
+ match &request.purpose {
+ ModelPurpose::Primary | ModelPurpose::Summarization => self
+ .primary_provider
+ .map(str::to_owned)
+ .unwrap_or_else(|| provider_for_role(&request.role, self.config)),
+ ModelPurpose::WorkloadTier(_) => provider_for_role(&request.role, self.config),
+ }
+ }
+
+ fn injected(&self, request: &ModelBuildRequest) -> Option<Arc<dyn ChatModel<()>>> {
+ let route = request.route.as_deref();
+ let host_model = self
+ .ctx
+ .host_overrides()
+ .and_then(|local| match &request.purpose {
+ ModelPurpose::Primary => local.model_for(&request.role),
+ ModelPurpose::Summarization => local
+ .role_models
+ .get("summarization")
+ .cloned()
+ .or_else(|| local.model_for(&request.role)),
+ ModelPurpose::WorkloadTier(_) => route
+ .and_then(|route| local.role_models.get(route))
+ .or_else(|| local.role_models.get(&request.role))
+ .cloned(),
+ });
+ if host_model.is_some() {
+ return host_model;
+ }
+ #[cfg(any(test, feature = "e2e-test-support", feature = "rss-bench"))]
+ if let Some(model) = test_provider_override::current() {
+ return Some(model);
+ }
+ None
+ }
+
+ fn build_request(
+ &self,
+ request: &ModelBuildRequest,
+ ) -> anyhow::Result<(Arc<dyn ChatModel<()>>, ResolvedModelRoute)> {
+ let role = request.role.as_str();
+ let pin = request.model_pin.as_deref().unwrap_or("");
+ let provider = self.provider_for(request);
+ if let Some(model) = self.injected(request) {
+ let profile = model.profile().cloned().unwrap_or_default();
+ let route = ResolvedModelRoute::new(
+ profile.provider.as_deref().unwrap_or("injected"),
+ profile.model.as_deref().unwrap_or(pin),
+ Self::route_name(request, role),
+ );
+ return Ok((model, route));
+ }
+
+ let provider_route = ProviderRoute::parse(&provider);
+ let managed = match (&request.purpose, self.primary_provider) {
+ (ModelPurpose::Primary | ModelPurpose::Summarization, Some(provider)) => {
+ let provider = provider.trim();
+ provider.is_empty()
+ || provider == "cloud"
+ || provider == PROVIDER_OPENHUMAN
+ || provider_route
+ .as_ref()
+ .is_some_and(|route| matches!(route.kind(), RouteKind::Managed))
+ }
+ _ => resolves_to_managed_backend(role, self.config),
+ };
+ if managed {
+ let resolved = self.ctx.resolved();
+ let extensions = resolved
+ .as_deref()
+ .map(crate::core::runtime::CoreContext::extensions);
+ let (model, concrete) =
+ super::managed_backend::make_openhuman_backend_model_for_thread_in(
+ extensions,
+ role,
+ self.config,
+ (!pin.is_empty()).then_some(pin),
+ request.opts.native_tools,
+ self.thread_id,
+ self.egress,
+ )?;
+ let concrete = if concrete.trim().is_empty() {
+ pin
+ } else {
+ &concrete
+ };
+ return Ok((
+ model,
+ ResolvedModelRoute::new(
+ PROVIDER_OPENHUMAN,
+ concrete,
+ Self::route_name(request, role),
+ ),
+ ));
+ }
+
+ let resolved = self.ctx.resolved();
+ let context_extensions = resolved
+ .as_deref()
+ .map(crate::core::runtime::CoreContext::extensions);
+ let mut parsed_route = ProviderRoute::parse(&provider);
+ if parsed_route.is_none()
+ && provider
+ .trim()
+ .eq_ignore_ascii_case(CLAUDE_AGENT_SDK_PROVIDER)
+ {
+ parsed_route = Some(ProviderRoute {
+ provider: CLAUDE_AGENT_SDK_PROVIDER.to_owned(),
+ model: self.config.claude_agent_sdk.default_model.clone(),
+ temperature: None,
+ });
+ }
+ if let Some(route) = parsed_route.as_mut() {
+ if !pin.is_empty()
+ && matches!(
+ route.kind(),
+ RouteKind::ClaudeCode | RouteKind::ClaudeAgentSdk
+ )
+ {
+ route.model = pin.to_owned();
+ }
+ }
+ if let Some(route) = parsed_route.as_ref().filter(|route| {
+ matches!(
+ route.kind(),
+ RouteKind::ClaudeCode | RouteKind::ClaudeAgentSdk
+ )
+ }) {
+ if route.temperature.is_some() && matches!(route.kind(), RouteKind::ClaudeCode) {
+ log::warn!(
+ "[providers][chat-factory] claude-code provider: per-model temperature override \
+ is accepted but not wired through to the CLI — the @<temp> suffix is ignored"
+ );
+ }
+ let effective_model = route.model.trim();
+ anyhow::ensure!(
+ !effective_model.is_empty(),
+ "subprocess model route for role '{role}' has an empty model"
+ );
+ let route_kind = route.kind();
+ let egress_name = match route_kind {
+ RouteKind::ClaudeCode => format!(
+ "{}{}",
+ tinyagents_harness::providers::claude_code::PROVIDER_PREFIX,
+ effective_model
+ ),
+ RouteKind::ClaudeAgentSdk => format!("{CLAUDE_AGENT_SDK_PREFIX}{effective_model}"),
+ _ => unreachable!("subprocess route was filtered"),
+ };
+ emit_inference_egress(role, &egress_name, self.egress);
+ let workspace = self
+ .config
+ .config_path
+ .parent()
+ .map(std::path::Path::to_path_buf)
+ .unwrap_or_else(|| self.config.workspace_dir.clone());
+ let context = tinyagents_harness::host::model_factory::SubprocessProviderContext {
+ workspace_dir: workspace,
+ action_dir: self.config.action_dir.clone(),
+ claude_agent_sdk: (&self.config.claude_agent_sdk).into(),
+ mcp_provider: Some(Arc::new(OpenHumanMcpEndpoint)),
+ };
+ let model = tinyagents_harness::host::model_factory::build_claude_subprocess_model(
+ route, &context,
+ )?
+ .ok_or_else(|| anyhow::anyhow!("unsupported subprocess route"))?;
+ let route_provider = route.provider.clone();
+ let resolved_model = effective_model.to_owned();
+ let route = ResolvedModelRoute::new(
+ route_provider,
+ resolved_model,
+ Self::route_name(request, role),
+ );
+ return Ok((model, route));
+ }
+
+ let (model, route_provider, resolved_model) =
+ match parsed_route.as_ref().map(ProviderRoute::kind) {
+ Some(RouteKind::Local(_)) | None
+ if tinyinference_local::profile::kind_from_provider_string(&provider)
+ .is_some() =>
+ {
+ let local = try_create_local_runtime_chat_model_from_string(
+ role,
+ &provider,
+ self.config,
+ self.egress,
+ );
+ let (model, resolved) = match local {
+ Some(result) => result?,
+ None => {
+ return Err(unresolved_chat_model_error_for(
+ role,
+ &provider,
+ self.config,
+ self.egress,
+ context_extensions,
- ))
++ ));
+ }
+ };
+ let provider = model
+ .profile()
+ .and_then(|p| p.provider.clone())
+ .unwrap_or_else(|| "local".into());
+ (model, provider, resolved)
+ }
+ Some(RouteKind::Cloud { .. }) => {
+ let cloud = try_create_cloud_slug_chat_model_from_string_with_native_tools_for(
+ role,
+ &provider,
+ self.config,
+ request.opts.native_tools,
+ self.egress,
+ context_extensions,
+ );
+ let (model, resolved) = match cloud {
+ Some(result) => result?,
+ None => {
+ return Err(unresolved_chat_model_error_for(
+ role,
+ &provider,
+ self.config,
+ self.egress,
+ context_extensions,
- ))
++ ));
+ }
+ };
+ let route_provider = model
+ .profile()
+ .and_then(|p| p.provider.clone())
+ .unwrap_or_else(|| {
+ parsed_route
+ .as_ref()
+ .expect("parsed cloud route")
+ .provider
+ .clone()
+ });
+ (model, route_provider, resolved)
+ }
+ _ => {
+ return Err(unresolved_chat_model_error_for(
+ role,
+ &provider,
+ self.config,
+ self.egress,
+ context_extensions,
+ ));
+ }
+ };
+
+ let route = ResolvedModelRoute::new(
+ route_provider,
+ resolved_model,
+ Self::route_name(request, role),
+ );
+ Ok((model, route))
+ }
+}
+
+fn build_one_shot(
+ ctx: &DispatchCtx,
+ role: &str,
+ provider: Option<&str>,
+ config: &Config,
+) -> anyhow::Result<(Arc<dyn ChatModel<()>>, String)> {
+ let egress = EgressLedger::none();
+ let factory = OpenHumanModelFactory {
+ ctx,
+ config,
+ primary_provider: provider,
+ egress: &egress,
+ thread_id: None,
+ attach_host_attachments: false,
+ };
+ let request = ModelBuildRequest {
+ role: role.to_owned(),
+ route: None,
+ purpose: ModelPurpose::Primary,
+ model_pin: None,
+ opts: BuildOpts {
+ native_tools: true,
+ temperature: None,
+ egress_tag: None,
+ },
+ };
+ factory.check(&request)?;
+ let (model, route) = factory.build(&request)?;
+ Ok((model, route.model))
+}
+
+impl ModelBuildGate for OpenHumanModelFactory<'_> {
+ fn check(&self, request: &ModelBuildRequest) -> tinyagents_harness::Result<()> {
+ // Explicit host model injection is authoritative and has no provider
+ // construction, credential, or egress side effect to gate.
+ if self.injected(request).is_some() {
+ return Ok(());
+ }
+ let provider = self.provider_for(request);
+ enforce_local_only_inference(&request.role, &provider)
+ .map_err(|error| tinyagents_harness::TinyAgentsError::Model(error.to_string()))?;
+ crate::inference::provider::factory::access_gates::verify_provider_session_in(
+ self.ctx,
+ self.config,
+ &provider,
+ )
+ .map_err(|error| tinyagents_harness::TinyAgentsError::Model(error.to_string()))
+ }
+}
+
+impl ModelFactory<()> for OpenHumanModelFactory<'_> {
+ fn build(
+ &self,
+ request: &ModelBuildRequest,
+ ) -> tinyagents_harness::Result<(Arc<dyn ChatModel<()>>, ResolvedModelRoute)> {
+ let (model, route) = self
+ .build_request(request)
+ .map_err(|error| tinyagents_harness::TinyAgentsError::Model(error.to_string()))?;
+ let opts = ModelRequestDefaults {
+ model: (!route.model.is_empty()).then(|| route.model.clone()),
+ temperature: request.opts.temperature,
+ };
+ let mut model = with_request_defaults(model, opts);
+ if self.attach_host_attachments {
+ model = if self.injected(request).is_some() {
+ crate::attachments::provider::wrap_injected(
+ self.ctx,
+ model,
+ Arc::new(self.config.clone()),
+ )
+ } else {
+ crate::attachments::provider::wrap(
+ self.ctx,
+ model,
+ Arc::new(self.config.clone()),
+ &route.model,
+ &route.provider,
+ )
+ };
+ }
+ Ok((model, route))
+ }
+}
+
+fn with_request_defaults(
+ model: Arc<dyn ChatModel<()>>,
+ defaults: ModelRequestDefaults,
+) -> Arc<dyn ChatModel<()>> {
+ Arc::new(ProfileOverrideModel::new_preserving_profile(model).with_defaults(defaults))
+}
/// Build an `Arc<dyn ChatModel>` for the given workload role, under `ctx`.
///
@@@ -604,16 -502,21 +604,34 @@@ pub(super) fn unresolved_chat_model_err
config: &Config,
egress: &EgressLedger,
) -> anyhow::Error {
- unresolved_chat_model_error_with_access(
+ let extensions = crate::core::runtime::CoreContext::current_extensions();
+ unresolved_chat_model_error_for(role, provider, config, egress, extensions.as_ref())
+}
+
+pub(super) fn unresolved_chat_model_error_for(
+ role: &str,
+ provider: &str,
+ config: &Config,
+ egress: &EgressLedger,
+ extensions: Option<&crate::core::slots::Extensions>,
++) -> anyhow::Error {
++ unresolved_chat_model_error_for_access(
+ role,
+ provider,
+ config,
+ egress,
++ extensions,
+ CredentialAccess::Runtime,
+ )
+ }
+
-pub(super) fn unresolved_chat_model_error_with_access(
++pub(super) fn unresolved_chat_model_error_for_access(
+ role: &str,
+ provider: &str,
+ config: &Config,
+ egress: &EgressLedger,
++ extensions: Option<&crate::core::slots::Extensions>,
+ credential_access: CredentialAccess,
) -> anyhow::Error {
let p = provider.trim();
@@@ -637,23 -540,25 +655,23 @@@
}
if p.is_empty() || p == "cloud" {
- return unresolved_chat_model_error_for(
- return unresolved_chat_model_error_with_access(
++ return unresolved_chat_model_error_for_access(
role,
&resolve_primary_cloud_provider_string(config),
config,
egress,
+ extensions,
+ credential_access,
);
}
#[cfg(not(test))]
- if let Err(error) = super::access_gates::verify_session_active(config) {
- return error;
+ if credential_access == CredentialAccess::Runtime {
- if let Err(error) = verify_session_active(config) {
++ if let Err(error) = super::access_gates::verify_session_active(config) {
+ return error;
+ }
}
-- // Preserve the legacy chokepoint's disclosure ordering for invalid custom
-- // routes: after both gates pass, the attempted external destination is
-- // visible even when configuration validation then fails.
emit_inference_egress(role, p, egress);
if let Some((slug, model_with_temperature)) = p.split_once(':') {
@@@ -665,7 -570,13 +683,20 @@@
);
}
let (model, _) = split_model_and_temperature(model_with_temperature);
- return match resolve_cloud_slug_for(role, slug.trim(), &model, config, extensions) {
- return match resolve_cloud_slug_with_access(
- role,
- slug.trim(),
- &model,
- config,
- credential_access,
- ) {
++ let result = match credential_access {
++ CredentialAccess::Runtime => {
++ resolve_cloud_slug_for(role, slug.trim(), &model, config, extensions)
++ }
++ CredentialAccess::Inspection => resolve_cloud_slug_with_access(
++ role,
++ slug.trim(),
++ &model,
++ config,
++ extensions,
++ CredentialAccess::Inspection,
++ ),
++ };
++ return match result {
Err(error) => error,
Ok(_) => anyhow::anyhow!(
"[chat-factory] configured provider '{}' for role '{}' did not produce a crate-native chat model",
diff --cc crates/openhuman-core/src/inference/provider/factory/cloud_slug.rs
index fdab3a56ae,c34ebe5914..5faed297e4
--- a/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rs
@@@ -9,28 -8,54 +9,66 @@@ use crate::inference::provider::factory
use crate::inference::provider::factory::access_gates::verify_session_active;
use crate::inference::provider::fallback_diagnostics;
use tinyinference_llm::providers::anthropic::endpoint_is_anthropic_messages;
+use tinyinference_llm::providers::registry::{
- resolve_slug_model, ProviderBuildOptions, ProviderRegistry,
++ ProviderBuildOptions, ProviderRegistry, resolve_slug_model,
+};
+ type CloudSlugInspectionChatModelResult = Option<
+ anyhow::Result<(
+ Arc<dyn ChatModel<()>>,
+ String,
+ String,
+ String,
+ InspectionOutputBudgetCapability,
+ )>,
+ >;
+
/// Look up a `cloud_providers` entry by slug and build the provider.
/// The shared resolution for a `<slug>:<model>` cloud provider — the cloud
/// `cloud_providers` entry, the effective model id (with `default_model`
/// fallback + abstract-tier remapping), the resolved API key, and the OpenAI
/// codex-oauth routing shared by every cloud `ChatModel` constructor.
-pub(super) struct CloudSlugResolution<'a> {
- pub(super) entry: &'a crate::config::schema::cloud_providers::CloudProviderCreds,
- pub(super) effective_model: String,
- pub(super) key: String,
- pub(super) codex: tinyinference_llm::providers::openai::codex::OpenAiCodexRouting,
+pub(crate) struct CloudSlugResolution<'a> {
+ pub(crate) entry: &'a crate::config::schema::cloud_providers::CloudProviderCreds,
+ pub(crate) effective_model: String,
+ pub(crate) key: String,
+ pub(crate) codex: tinyinference_llm::providers::openai::codex::OpenAiCodexRouting,
}
+ pub(super) fn inspection_output_budget_capability(
+ codex: &tinyinference_llm::providers::openai::codex::OpenAiCodexRouting,
+ ) -> InspectionOutputBudgetCapability {
+ if codex.using_oauth {
+ InspectionOutputBudgetCapability::Unsupported
+ } else {
+ InspectionOutputBudgetCapability::Bounded
+ }
+ }
+
-pub(super) fn resolve_cloud_slug<'a>(
+pub(crate) fn resolve_cloud_slug_for<'a>(
role: &str,
slug: &str,
model: &str,
config: &'a Config,
+ extensions: Option<&crate::core::slots::Extensions>,
+ ) -> anyhow::Result<CloudSlugResolution<'a>> {
- resolve_cloud_slug_with_access(role, slug, model, config, CredentialAccess::Runtime)
++ resolve_cloud_slug_with_access(
++ role,
++ slug,
++ model,
++ config,
++ extensions,
++ CredentialAccess::Runtime,
++ )
+ }
+
+ pub(super) fn resolve_cloud_slug_with_access<'a>(
+ role: &str,
+ slug: &str,
+ model: &str,
+ config: &'a Config,
++ extensions: Option<&crate::core::slots::Extensions>,
+ credential_access: CredentialAccess,
) -> anyhow::Result<CloudSlugResolution<'a>> {
let entry = config.cloud_providers.iter().find(|e| e.slug == slug);
@@@ -153,18 -173,31 +191,38 @@@
entry.auth_style.as_str(),
implicit_fallback
);
- fallback_diagnostics::missing_provider_credentials_message(role, slug, local_chat)
+ fallback_diagnostic.as_ref().map_or_else(
+ || format!("No usable credentials for '{slug}'. Add a key in Connections → LLM."),
+ |diagnostic| {
+ fallback_diagnostics::missing_provider_credentials_message(
+ diagnostic, slug, local_chat,
+ )
+ },
+ )
};
- let key = lookup_key_for_slug(slug, config)
- .map_err(|e| anyhow::anyhow!("{} (underlying error: {e})", missing_credentials()))?;
+ let (key, bearer_is_oauth, oauth_account_id) = if credential_access
+ == CredentialAccess::Inspection
+ && entry.auth_style == AuthStyle::OpenhumanJwt
+ {
+ // The managed model constructor receives its credential later, on
+ // invoke. Its hosted construction callback is config-only and offline.
+ (String::new(), false, None)
+ } else if credential_access == CredentialAccess::Inspection {
+ let credential =
+ super::credentials::lookup_key_for_slug_read_only(slug, config).map_err(|error| {
+ anyhow::anyhow!("{} (underlying error: {error})", missing_credentials())
+ })?;
+ (credential.key, credential.is_oauth, credential.account_id)
+ } else {
+ let key = credential_access
+ .lookup_key_for_slug(slug, config)
+ .map_err(|error| {
+ anyhow::anyhow!("{} (underlying error: {error})", missing_credentials())
+ })?;
+ let is_oauth = slug == "openai" && credential_access.openai_bearer_is_oauth(config);
+ (key, is_oauth, None)
+ };
// A readable auth profile with no key for this slug returns `Ok("")`, which
// would otherwise build a client with an empty bearer and surface as a raw
@@@ -188,9 -218,18 +243,19 @@@
{
anyhow::bail!("{}", missing_credentials());
}
- let bearer_is_oauth = slug == "openai" && openai_bearer_is_oauth(config);
- let codex = resolve_codex_routing(config, slug, &entry.endpoint, &key, bearer_is_oauth)
- .map_err(anyhow::Error::msg)?;
+ let codex = match credential_access {
+ CredentialAccess::Runtime => {
- resolve_openai_codex_routing(config, slug, &entry.endpoint, &key, bearer_is_oauth)
++ let bearer_is_oauth = slug == "openai" && openai_bearer_is_oauth(config);
++ resolve_codex_routing(config, slug, &entry.endpoint, &key, bearer_is_oauth)
+ .map_err(anyhow::Error::msg)?
+ }
+ CredentialAccess::Inspection => resolve_openai_codex_routing_for_inspection(
+ slug,
+ &entry.endpoint,
+ bearer_is_oauth,
+ oauth_account_id,
+ ),
+ };
Ok(CloudSlugResolution {
entry,
@@@ -239,12 -286,59 +304,65 @@@ pub(super) fn try_create_cloud_slug_cha
)
}
-pub(super) fn try_create_cloud_slug_chat_model_for_inspection(
+pub(super) fn try_create_cloud_slug_chat_model_with_native_tools_for(
role: &str,
config: &Config,
+ native_tool_calling: bool,
egress: &EgressLedger,
+ extensions: Option<&crate::core::slots::Extensions>,
+ ) -> OptionalChatModelResult {
+ try_create_cloud_slug_chat_model_with_native_tools_and_access(
+ role,
+ config,
- true,
++ native_tool_calling,
+ egress,
- CredentialAccess::Inspection,
++ extensions,
++ CredentialAccess::Runtime,
+ None,
+ )
+ }
+
+ pub(super) fn try_create_cloud_slug_chat_model_for_inspection_with_identity(
+ role: &str,
+ config: &Config,
++ extensions: Option<&crate::core::slots::Extensions>,
+ ) -> CloudSlugInspectionChatModelResult {
+ let mut identity = None;
+ let mut resolved = provider_for_role(role, config);
+ if resolved.trim().is_empty() || resolved.trim() == "cloud" {
+ resolved = resolve_primary_cloud_provider_string(config);
+ }
+ let result = try_create_cloud_slug_chat_model_from_string_with_native_tools_and_access(
+ role,
+ &resolved,
+ config,
+ true,
+ &EgressLedger::none(),
++ extensions,
+ CredentialAccess::Inspection,
+ Some(&mut identity),
+ )?;
+ Some(result.and_then(|(model, model_id)| {
+ let (endpoint, credential, wire_model, output_budget) = identity.ok_or_else(|| {
+ anyhow::anyhow!("inspection route did not expose its frozen wire identity")
+ })?;
+ if wire_model != model_id {
+ anyhow::bail!("inspection route model identity did not match its constructed model");
+ }
+ Ok((model, model_id, endpoint, credential, output_budget))
+ }))
+ }
+
+ fn try_create_cloud_slug_chat_model_with_native_tools_and_access(
+ role: &str,
+ config: &Config,
+ native_tool_calling: bool,
+ egress: &EgressLedger,
++ extensions: Option<&crate::core::slots::Extensions>,
+ credential_access: CredentialAccess,
+ inspection_identity: Option<
+ &mut Option<(String, String, String, InspectionOutputBudgetCapability)>,
+ >,
) -> OptionalChatModelResult {
// Resolve the role's provider string, expanding the empty / "cloud" sentinel
// to the primary cloud target.
@@@ -258,7 -352,8 +376,9 @@@
config,
native_tool_calling,
egress,
+ extensions,
+ credential_access,
+ inspection_identity,
)
}
@@@ -279,25 -374,28 +399,51 @@@ pub(super) fn try_create_cloud_slug_cha
config: &Config,
native_tool_calling: bool,
egress: &EgressLedger,
+) -> OptionalChatModelResult {
+ let extensions = crate::core::runtime::CoreContext::current_extensions();
- try_create_cloud_slug_chat_model_from_string_with_native_tools_for(
++ try_create_cloud_slug_chat_model_from_string_with_native_tools_and_access(
+ role,
+ provider,
+ config,
+ native_tool_calling,
+ egress,
+ extensions.as_ref(),
++ CredentialAccess::Runtime,
++ None,
+ )
+}
+
+pub(super) fn try_create_cloud_slug_chat_model_from_string_with_native_tools_for(
+ role: &str,
+ provider: &str,
+ config: &Config,
+ native_tool_calling: bool,
+ egress: &EgressLedger,
+ extensions: Option<&crate::core::slots::Extensions>,
+ ) -> OptionalChatModelResult {
+ try_create_cloud_slug_chat_model_from_string_with_native_tools_and_access(
+ role,
+ provider,
+ config,
+ native_tool_calling,
+ egress,
++ extensions,
+ CredentialAccess::Runtime,
+ None,
+ )
+ }
+
+ fn try_create_cloud_slug_chat_model_from_string_with_native_tools_and_access(
+ role: &str,
+ provider: &str,
+ config: &Config,
+ native_tool_calling: bool,
+ egress: &EgressLedger,
++ extensions: Option<&crate::core::slots::Extensions>,
+ credential_access: CredentialAccess,
+ mut inspection_identity: Option<
+ &mut Option<(String, String, String, InspectionOutputBudgetCapability)>,
+ >,
) -> OptionalChatModelResult {
let p = provider.trim().to_string();
@@@ -338,7 -438,7 +486,14 @@@
effective_model,
key,
codex,
- } = match resolve_cloud_slug_for(role, &slug, &raw_model, config, extensions) {
- } = match resolve_cloud_slug_with_access(role, &slug, &raw_model, config, credential_access) {
++ } = match resolve_cloud_slug_with_access(
++ role,
++ &slug,
++ &raw_model,
++ config,
++ extensions,
++ credential_access,
++ ) {
Ok(r) => r,
Err(e) => return Some(Err(e)),
};
@@@ -377,27 -477,46 +532,52 @@@
);
}
AuthStyle::Anthropic | AuthStyle::None => {}
- AuthStyle::OpenhumanJwt => {
+ style
+ if crate::config::schema::cloud_providers::is_hosted_auth_style_for(
+ extensions, style,
+ ) =>
+ {
- #[cfg(not(test))]
- if let Err(error) = verify_backend_session_active(config) {
- return Some(Err(error));
+ if credential_access == CredentialAccess::Runtime {
+ #[cfg(not(test))]
+ if let Err(error) = verify_backend_session_active(config) {
+ return Some(Err(error));
+ }
}
let model_override =
(!effective_model.trim().is_empty()).then_some(effective_model.as_str());
- return Some(managed_chat_model_for(
- extensions,
- role,
- config,
- model_override,
- None,
- native_tool_calling,
- None,
- egress,
- ));
+ return Some(match credential_access {
- CredentialAccess::Runtime => managed_chat_model(
++ CredentialAccess::Runtime => managed_chat_model_for(
++ extensions,
+ role,
+ config,
+ model_override,
+ None,
+ native_tool_calling,
+ None,
+ egress,
+ ),
+ CredentialAccess::Inspection => {
+ match super::managed_backend::managed_chat_model_build_for_inspection(
++ extensions,
+ role,
+ config,
+ model_override,
+ ) {
+ Ok(build) => {
+ if let Some(identity) = inspection_identity.as_deref_mut() {
+ *identity = Some((
+ build.endpoint.clone(),
+ build.credential.clone(),
+ build.model_id.clone(),
+ InspectionOutputBudgetCapability::Bounded,
+ ));
+ }
+ Ok((build.model, build.model_id))
+ }
+ Err(error) => Err(error),
+ }
+ }
+ });
}
AuthStyle::Bearer => {
// The codex routing may re-target the endpoint (OAuth backend).
@@@ -442,44 -556,48 +622,58 @@@
.cloud_provider_ca_certs
.get(&slug)
.filter(|pem| !pem.is_empty())
- {
- Some(pem) => {
- let label = if anthropic_native {
- "provider.anthropic"
- } else {
- "provider.compatible"
- };
- match crate::util::tls::client_with_ca_bundle(pem, label) {
- Ok(http) => Some(http),
- Err(error) => return Some(Err(anyhow::anyhow!(error))),
- }
- }
- None => None,
+ .map(String::as_str);
+ let service_key = if anthropic_native {
+ "provider.anthropic"
+ } else {
+ "provider.compatible"
};
- let auth_style = cloud_spec::registry_auth_style(entry.auth_style)
- .expect("managed JWT entries returned above");
- let chat = cloud_spec::build_cloud_model(cloud_spec::CloudBuild {
- spec: cloud_spec::cloud_provider_spec(entry, &effective_model),
- auth_style,
- key: key.as_str(),
- temperature_override,
- temperature_unsupported_models: config.temperature_unsupported_models.as_slice(),
- native_tool_calling,
- extra_headers: extra_headers.as_slice(),
- extra_query_params: extra_query_params.as_slice(),
- user_agent: user_agent.as_deref(),
- codex: codex_route,
- http,
+ let http_builder = ca_bundle.map(|_| {
+ std::sync::Arc::new(move || {
+ crate::config::apply_runtime_proxy_to_builder(
+ crate::util::tls::tls_client_builder(),
+ service_key,
+ )
+ }) as tinyinference_llm::providers::registry::ProviderHttpClientBuilder<'_>
});
+ let spec = cloud_spec::cloud_provider_spec(entry, &effective_model);
+ log::debug!(
+ "[providers][cloud-spec] build slug={} kind={} auth={:?}",
+ spec.provider,
+ spec.kind.as_str(),
+ entry.auth_style
+ );
+ let chat = ProviderRegistry::new(cloud_spec::CloudCredentialResolver(&key))
+ .build_with(
+ &spec,
+ ProviderBuildOptions {
+ auth_style: Some(entry.auth_style.into()),
+ temperature_override,
+ temperature_unsupported_models: config.temperature_unsupported_models.as_slice(),
+ native_tool_calling: Some(native_tool_calling),
+ extra_headers: extra_headers.as_slice(),
+ extra_query_params: extra_query_params.as_slice(),
+ user_agent: user_agent.as_deref(),
+ codex: codex_route,
+ http_builder,
+ ca_bundle,
+ ..ProviderBuildOptions::default()
+ },
+ )
+ .map_err(|error| anyhow::anyhow!("[chat-factory] {error}"));
+ if let Some(identity) = inspection_identity {
+ let credential = if entry.auth_style == AuthStyle::None {
+ String::new()
+ } else {
+ key.clone()
+ };
+ let output_budget = inspection_output_budget_capability(&codex);
+ *identity = Some((
+ codex.endpoint.clone(),
+ credential,
+ effective_model.clone(),
+ output_budget,
+ ));
+ }
Some(chat.map(|chat| (chat, effective_model)))
}
diff --cc crates/openhuman-core/src/inference/provider/factory/cloud_spec_tests.rs
index 8df8286c07,9cf06d2e33..5ce712f220
--- a/crates/openhuman-core/src/inference/provider/factory/cloud_spec_tests.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/cloud_spec_tests.rs
@@@ -76,22 -74,13 +76,24 @@@ fn discovery_request_carries_bearer_aut
"https://openrouter.ai/api/v1",
AuthStyle::Bearer,
);
- let request =
- cloud_discovery_request(&build(&creds, "m", "sk-or")).expect("openrouter has a listing");
+ let spec = cloud_provider_spec(&creds, "m");
+ let request = ProviderRegistry::new(CloudCredentialResolver("sk-or"))
+ .discovery_request(
+ &spec,
+ &ProviderBuildOptions {
+ auth_style: Some(AuthStyle::Bearer.into()),
+ ..ProviderBuildOptions::default()
+ },
+ )
+ .unwrap()
+ .expect("openrouter has a listing");
assert_eq!(request.endpoint, "https://openrouter.ai/api/v1");
-- assert!(request
-- .headers
-- .iter()
-- .any(|(name, value)| name == "Authorization" && value == "Bearer sk-or"));
++ assert!(
++ request
++ .headers
++ .iter()
++ .any(|(name, value)| name == "Authorization" && value == "Bearer sk-or")
++ );
}
#[test]
@@@ -121,42 -97,9 +123,48 @@@ fn discovery_request_builds_codex_oauth
let oauth = OpenAiCodexRouting {
endpoint: "https://chatgpt.com/backend-api/codex".to_string(),
using_oauth: true,
- account_id: None,
+ account_id: Some("account-123".to_string()),
};
- let mut with_oauth = build(&openai, "gpt", "tok");
- with_oauth.codex = Some(&oauth);
- assert!(cloud_discovery_request(&with_oauth).is_none());
+ let query = [("client_version".to_string(), "0.130.0".to_string())];
+ let spec = cloud_provider_spec(&openai, "gpt");
+ let request = ProviderRegistry::new(CloudCredentialResolver("tok"))
+ .discovery_request(
+ &spec,
+ &ProviderBuildOptions {
+ auth_style: Some(AuthStyle::Bearer.into()),
+ extra_query_params: &query,
+ user_agent: Some("codex_cli_rs/0.0.0 (OpenHuman 0.64.18)"),
+ codex: Some(&oauth),
+ ..ProviderBuildOptions::default()
+ },
+ )
+ .unwrap()
+ .expect("Codex OAuth has a listing");
+ assert_eq!(request.endpoint, "https://chatgpt.com/backend-api/codex");
+ assert_eq!(
+ request.effective_listing_url(),
+ "https://chatgpt.com/backend-api/codex/models?client_version=0.130.0"
+ );
+ assert_eq!(request.model, "gpt");
- assert!(request
- .headers
- .iter()
- .any(|(name, value)| name == "Authorization" && value == "Bearer tok"));
- assert!(request
- .headers
- .iter()
- .any(|(name, value)| name == "ChatGPT-Account-ID" && value == "account-123"));
- assert!(request
- .headers
- .iter()
- .any(|(name, value)| name == "originator" && value == "codex_cli_rs"));
++ assert!(
++ request
++ .headers
++ .iter()
++ .any(|(name, value)| name == "Authorization" && value == "Bearer tok")
++ );
++ assert!(
++ request
++ .headers
++ .iter()
++ .any(|(name, value)| name == "ChatGPT-Account-ID" && value == "account-123")
++ );
++ assert!(
++ request
++ .headers
++ .iter()
++ .any(|(name, value)| name == "originator" && value == "codex_cli_rs")
++ );
+ assert!(request.headers.iter().any(|(name, value)| {
+ name == "User-Agent" && value == "codex_cli_rs/0.0.0 (OpenHuman 0.64.18)"
+ }));
}
diff --cc crates/openhuman-core/src/inference/provider/factory/credentials.rs
index 4d0d117971,a7ea8f816f..aa643de4be
--- a/crates/openhuman-core/src/inference/provider/factory/credentials.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/credentials.rs
@@@ -2,8 -2,196 +2,197 @@@
//! OpenAI OAuth fallback and the scoped legacy `config.api_key` fallback.
use super::*;
+use crate::config::ops::legacy_inference_slug;
+ type ReadOnlyProfileCredential = (
+ String,
+ bool,
+ Option<chrono::DateTime<chrono::Utc>>,
+ Option<String>,
+ );
+
+ /// Credential behavior used by shared model construction. Runtime callers keep
+ /// the established mutable auth-profile store path; doctor inspection uses the
+ /// selected profile's read-only snapshot and never refreshes credentials.
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
+ pub(super) enum CredentialAccess {
+ Runtime,
+ Inspection,
+ }
+
+ impl CredentialAccess {
+ pub(super) fn lookup_key_for_slug(self, slug: &str, config: &Config) -> anyhow::Result<String> {
+ match self {
+ Self::Runtime => lookup_key_for_slug(slug, config),
+ Self::Inspection => {
+ lookup_key_for_slug_read_only(slug, config).map(|credential| credential.key)
+ }
+ }
+ }
+
+ pub(super) fn openai_bearer_is_oauth(self, config: &Config) -> bool {
+ match self {
+ Self::Runtime => openai_bearer_is_oauth(config),
+ Self::Inspection => lookup_key_for_slug_read_only("openai", config)
+ .map(|credential| credential.is_oauth)
+ .unwrap_or(false),
+ }
+ }
+ }
+
+ pub(super) struct ReadOnlyCloudCredential {
+ pub(super) key: String,
+ pub(super) is_oauth: bool,
+ pub(super) account_id: Option<String>,
+ }
+
+ pub(super) fn lookup_key_for_slug_read_only(
+ slug: &str,
+ config: &Config,
+ ) -> anyhow::Result<ReadOnlyCloudCredential> {
+ if slug == crate::config::schema::EPHEMERAL_ROUTE_SLUG {
+ if let Some(route) = config.ephemeral_route.as_ref() {
+ return Ok(ReadOnlyCloudCredential {
+ key: route.api_key.trim().to_string(),
+ is_oauth: false,
+ account_id: None,
+ });
+ }
+ }
+
+ let auth_profile_key = auth_key_for_slug(slug);
+ for provider in [auth_profile_key.as_str(), slug] {
+ if let Some((key, is_oauth, expires_at, account_id)) =
+ read_only_profile_credential(config, provider, None)?
+ {
+ if slug == "openai"
+ && is_oauth
+ && expires_at.is_some_and(|expires_at| {
+ expires_at <= chrono::Utc::now() + chrono::Duration::minutes(2)
+ })
+ {
+ anyhow::bail!("OpenAI OAuth credential requires refresh");
+ }
+ if !key.trim().is_empty() {
+ return Ok(ReadOnlyCloudCredential {
+ key,
+ is_oauth,
+ account_id,
+ });
+ }
+ }
+ }
+
+ // The OAuth login is stored under a named profile rather than the
+ // provider's active API-key profile. Its runtime lookup can refresh and
+ // persist the token; doctor only reports when that refresh would be needed.
+ if slug == "openai" {
+ match read_only_profile_credential(
+ config,
+ crate::security::credentials::openai_oauth::OPENAI_PROVIDER_KEY,
+ Some(crate::security::credentials::openai_oauth::OPENAI_OAUTH_PROFILE_NAME),
+ )? {
+ Some((key, true, expires_at, account_id)) if !key.trim().is_empty() => {
+ if expires_at.is_some_and(|expires_at| {
+ expires_at <= chrono::Utc::now() + chrono::Duration::minutes(2)
+ }) {
+ anyhow::bail!("OpenAI OAuth credential requires refresh");
+ }
+ return Ok(ReadOnlyCloudCredential {
+ key,
+ is_oauth: true,
+ account_id,
+ });
+ }
+ _ => {}
+ }
+ }
+
+ // Preserve the narrowly scoped legacy config.toml fallback without
+ // consulting the mutable auth-profile store.
+ if legacy_inference_slug(config) == Some(slug) {
+ if let Some(config_key) = config
+ .api_key
+ .as_deref()
+ .map(str::trim)
+ .filter(|key| !key.is_empty())
+ {
+ return Ok(ReadOnlyCloudCredential {
+ key: config_key.to_string(),
+ is_oauth: false,
+ account_id: None,
+ });
+ }
+ }
+
+ Ok(ReadOnlyCloudCredential {
+ key: String::new(),
+ is_oauth: false,
+ account_id: None,
+ })
+ }
+
+ fn read_only_profile_credential(
+ config: &Config,
+ provider: &str,
+ profile_override: Option<&str>,
+ ) -> anyhow::Result<Option<ReadOnlyProfileCredential>> {
+ let Some(profile) = crate::security::credentials::AuthService::get_profile_read_only(
+ config,
+ provider,
+ profile_override,
+ )
+ .map_err(read_only_profile_error)?
+ else {
+ return Ok(None);
+ };
+
+ let (token, is_oauth, expires_at, account_id) = match profile.kind {
+ crate::security::credentials::profiles::AuthProfileKind::Token => {
+ (profile.token.unwrap_or_default(), false, None, None)
+ }
+ crate::security::credentials::profiles::AuthProfileKind::OAuth => {
+ let access_token = profile
+ .token_set
+ .as_ref()
+ .map(|tokens| tokens.access_token.trim().to_string())
+ .unwrap_or_default();
+ let account_id = profile
+ .metadata
+ .get("account_id")
+ .map(String::as_str)
+ .map(str::trim)
+ .filter(|value| !value.is_empty())
+ .map(str::to_string)
+ .or_else(|| {
+ tinyinference_providers::oauth::openai_account_id_from_access_token(
+ &access_token,
+ )
+ });
+ (
+ access_token,
+ true,
+ profile.token_set.and_then(|tokens| tokens.expires_at),
+ account_id,
+ )
+ }
+ };
+ Ok(Some((token, is_oauth, expires_at, account_id)))
+ }
+
+ fn read_only_profile_error(
+ error: crate::security::credentials::profiles::ReadOnlyAuthProfileError,
+ ) -> anyhow::Error {
+ match error {
+ crate::security::credentials::profiles::ReadOnlyAuthProfileError::Unavailable => {
+ anyhow::anyhow!("read-only credential profile is unavailable")
+ }
+ crate::security::credentials::profiles::ReadOnlyAuthProfileError::InvalidStore => {
+ anyhow::anyhow!("read-only credential profile store is invalid")
+ }
+ }
+ }
+
/// Auth-profile storage key for a slug-keyed provider.
///
/// New writes use `"provider:<slug>"`. Lookups also try the bare `<slug>`
diff --cc crates/openhuman-core/src/inference/provider/factory/inspection.rs
index 0000000000,0000000000..5a32d96974
new file mode 100644
--- /dev/null
+++ b/crates/openhuman-core/src/inference/provider/factory/inspection.rs
@@@ -1,0 -1,0 +1,126 @@@
++//! Read-only provider preparation for doctor inspections.
++
++use super::*;
++
++/// Build a chat model for static inspection, sharing the runtime constructor
++/// while resolving stored credentials through the read-only profile snapshot.
++/// It never calls the model and never runs runtime session-expiry gates.
++pub(crate) fn create_chat_model_with_model_id_in_for_inspection(
++ ctx: &DispatchCtx,
++ role: &str,
++ config: &Config,
++ temperature: f64,
++) -> anyhow::Result<(Arc<dyn ChatModel<()>>, String)> {
++ let prepared =
++ create_chat_model_with_identity_in_for_inspection(ctx, role, config, temperature)?;
++ Ok((prepared.model, prepared.model_id))
++}
++
++/// Build a model for a live inspection call and preserve the exact resolved
++/// endpoint, frozen credential, and wire-model identity used by that model.
++pub(crate) fn create_chat_model_with_identity_in_for_inspection(
++ ctx: &DispatchCtx,
++ role: &str,
++ config: &Config,
++ temperature: f64,
++) -> anyhow::Result<PreparedInspectionChatModel> {
++ let resolved_context = ctx.resolved();
++ let extensions = resolved_context
++ .as_deref()
++ .map(crate::core::runtime::CoreContext::extensions);
++ let mut resolved = provider_for_role(role, config);
++ if resolved.trim().is_empty() || resolved.trim() == "cloud" {
++ resolved = resolve_primary_cloud_provider_string(config);
++ }
++ if resolves_to_managed_backend(role, config) {
++ let build = managed_backend::managed_chat_model_build_for_inspection(
++ extensions.as_ref(),
++ role,
++ config,
++ None,
++ )?;
++ return Ok(prepared_inspection_model(
++ build.model,
++ build.model_id.clone(),
++ build.endpoint,
++ build.credential,
++ temperature,
++ InspectionOutputBudgetCapability::Bounded,
++ ));
++ }
++ if let Some(result) =
++ try_create_claude_agent_sdk_chat_model_for_inspection(role, &resolved, config)
++ {
++ let (model, model_id, endpoint, credential) = result?;
++ return Ok(prepared_inspection_model(
++ model,
++ model_id.clone(),
++ endpoint,
++ credential,
++ temperature,
++ InspectionOutputBudgetCapability::Bounded,
++ ));
++ }
++ if let Some(result) = try_create_claude_code_chat_model_for_inspection(role, &resolved, config)
++ {
++ let (model, model_id, endpoint, credential) = result?;
++ return Ok(prepared_inspection_model(
++ model,
++ model_id.clone(),
++ endpoint,
++ credential,
++ temperature,
++ InspectionOutputBudgetCapability::Bounded,
++ ));
++ }
++ if let Some(result) = try_create_local_runtime_chat_model_for_inspection(role, config) {
++ let (model, model_id, endpoint, credential) = result?;
++ return Ok(prepared_inspection_model(
++ model,
++ model_id.clone(),
++ endpoint,
++ credential,
++ temperature,
++ InspectionOutputBudgetCapability::Bounded,
++ ));
++ }
++ if let Some(result) = try_create_cloud_slug_chat_model_for_inspection_with_identity(
++ role,
++ config,
++ extensions.as_ref(),
++ ) {
++ let (model, model_id, endpoint, credential, output_budget) = result?;
++ return Ok(prepared_inspection_model(
++ model,
++ model_id.clone(),
++ endpoint,
++ credential,
++ temperature,
++ output_budget,
++ ));
++ }
++ Err(unresolved_chat_model_error_for_access(
++ role,
++ &provider_for_role(role, config),
++ config,
++ &EgressLedger::none(),
++ extensions.as_ref(),
++ CredentialAccess::Inspection,
++ ))
++}
++
++fn prepared_inspection_model(
++ model: Arc<dyn ChatModel<()>>,
++ model_id: String,
++ endpoint: String,
++ credential: String,
++ temperature: f64,
++ output_budget: InspectionOutputBudgetCapability,
++) -> PreparedInspectionChatModel {
++ PreparedInspectionChatModel {
++ model: with_default_temperature(model, temperature),
++ identity: InspectionRequestIdentity::new(endpoint, credential, model_id.clone()),
++ model_id,
++ output_budget,
++ }
++}
diff --cc crates/openhuman-core/src/inference/provider/factory/local_runtime.rs
index a99e1350ca,2e82971887..a9772a3d86
--- a/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs
@@@ -3,8 -3,7 +3,8 @@@
use super::*;
use crate::inference::provider::factory::access_gates::verify_provider_session;
- use tinyinference_llm::providers::openai::build_local_runtime_chat_model;
+use tinyinference_llm::providers::openai::AuthStyle as CompatAuthStyle;
+ use tinyinference_llm::providers::openai::build_local_runtime_chat_model;
/// Local OpenAI-compatible runtimes (Ollama / LM Studio / MLX / OMLX /
/// local-openai) as a crate-native [`ChatModel`] (issue #4727).
@@@ -39,9 -38,47 +39,47 @@@ pub(super) fn try_create_local_runtime_
provider: &str,
config: &Config,
egress: &EgressLedger,
+ ) -> OptionalChatModelResult {
+ try_create_local_runtime_chat_model_from_string_with_identity(
+ role, provider, config, egress, false, None,
+ )
+ }
+
+ pub(super) fn try_create_local_runtime_chat_model_for_inspection(
+ role: &str,
+ config: &Config,
+ ) -> InspectionChatModelResult {
+ let provider = provider_for_role(role, config);
+ let mut identity = None;
+ let result = try_create_local_runtime_chat_model_from_string_with_identity(
+ role,
+ &provider,
+ config,
+ &EgressLedger::none(),
+ true,
+ Some(&mut identity),
+ )?;
+ Some(result.and_then(|(model, model_id)| {
+ let (endpoint, credential, wire_model) = identity.ok_or_else(|| {
+ anyhow::anyhow!("inspection route did not expose its frozen wire identity")
+ })?;
+ if wire_model != model_id {
+ anyhow::bail!("inspection route model identity did not match its constructed model");
+ }
+ Ok((model, model_id, endpoint, credential))
+ }))
+ }
+
+ fn try_create_local_runtime_chat_model_from_string_with_identity(
+ role: &str,
+ provider: &str,
+ config: &Config,
+ egress: &EgressLedger,
+ inspection: bool,
+ inspection_identity: Option<&mut Option<(String, String, String)>>,
) -> OptionalChatModelResult {
use tinyinference_local::local_runtime::{
-- resolve_local_runtime, LocalRuntimeAuth, LocalRuntimeInputs,
++ LocalRuntimeAuth, LocalRuntimeInputs, resolve_local_runtime,
};
// Use the same classifier as privacy and session policy. Canonicalize only
diff --cc crates/openhuman-core/src/inference/provider/factory/managed_backend.rs
index 53b8f29c0e,388013b18f..5cd1b9607a
--- a/crates/openhuman-core/src/inference/provider/factory/managed_backend.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/managed_backend.rs
@@@ -93,13 -99,45 +93,49 @@@ pub(super) fn managed_chat_model_for
default_model,
native_tool_calling,
thread_id,
- egress,
- })
+ context: &context,
+ };
+ Ok((entry.build)(&request)?)
}
+ /// Build a managed model only through the host's explicitly inspection-safe
+ /// callback. This path never falls back to the runtime factory: doing so could
+ /// defer mutable credential access until invoke/stream.
+ pub(super) fn managed_chat_model_for_inspection(
+ role: &str,
+ config: &Config,
+ model_override: Option<&str>,
+ ) -> anyhow::Result<ManagedChatModel> {
- let build = managed_chat_model_build_for_inspection(role, config, model_override)?;
++ let build = managed_chat_model_build_for_inspection(None, role, config, model_override)?;
+ Ok((build.model, build.model_id))
+ }
+
+ pub(super) fn managed_chat_model_build_for_inspection(
++ extensions: Option<&crate::core::slots::Extensions>,
+ role: &str,
+ config: &Config,
+ model_override: Option<&str>,
+ ) -> anyhow::Result<crate::inference::registry::InspectionChatModelBuild> {
+ enforce_local_only_inference(role, PROVIDER_OPENHUMAN)?;
- let Some(factory) = crate::inference::registry::inspection_chat_model(PROVIDER_OPENHUMAN)
++ let Some(factory) =
++ crate::inference::registry::inspection_chat_model_for(extensions, PROVIDER_OPENHUMAN)
+ else {
+ return Err(managed_unavailable_error());
+ };
+ let model = resolve_managed_model(role, config, model_override);
+ (factory)(&crate::inference::registry::ChatModelRequest {
+ role,
+ config,
+ model_override: Some(&model),
+ default_model: None,
+ native_tool_calling: true,
+ thread_id: None,
+ egress: &EgressLedger::none(),
+ })
+ }
+
/// Construct a managed turn model with the explicit OpenHuman thread attached.
+#[cfg(test)]
pub(crate) fn make_openhuman_backend_model_for_thread(
role: &str,
config: &Config,
diff --cc crates/openhuman-core/src/inference/provider/factory/routing_tests.rs
index 109b68a11d,109b68a11d..a871a5d70e
--- a/crates/openhuman-core/src/inference/provider/factory/routing_tests.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/routing_tests.rs
@@@ -1,6 -1,6 +1,6 @@@
use super::*;
--use crate::config::schema::cloud_providers::{AuthStyle, CloudProviderCreds};
use crate::config::Config;
++use crate::config::schema::cloud_providers::{AuthStyle, CloudProviderCreds};
use crate::inference::provider::factory::resolves_to_managed_backend;
fn byok_openai_compatible_entry() -> CloudProviderCreds {
diff --cc crates/openhuman-core/src/inference/provider/factory/subprocess_providers.rs
index 894ac950a1,1198de014b..91c4c98585
--- a/crates/openhuman-core/src/inference/provider/factory/subprocess_providers.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/subprocess_providers.rs
@@@ -1,7 -1,202 +1,91 @@@
- //! OpenHuman's MCP endpoint for TinyAgents' native Claude subprocess builder.
-//! Subprocess-backed providers: the Claude Agent SDK and the Claude Code CLI.
++//! OpenHuman host endpoint adapter and frozen Claude inspection route.
+
+ use super::*;
-use crate::inference::provider::factory::access_gates::verify_provider_session;
++use tinyagents_harness::providers::claude_agent_sdk::ClaudeAgentSdkProvider;
+
-/// Build the Claude Agent SDK subprocess directly as a crate model. This is a
-/// prompt-guided model: TinyAgents owns its text-tool protocol, while the
-/// provider owns only subprocess transport and NDJSON decoding.
-pub(super) fn try_create_claude_agent_sdk_chat_model(
- role: &str,
- config: &Config,
- egress: &EgressLedger,
-) -> OptionalChatModelResult {
- let resolved = provider_for_role(role, config);
- try_create_claude_agent_sdk_chat_model_from_string(role, &resolved, config, egress)
-}
-
-pub(super) fn try_create_claude_agent_sdk_chat_model_from_string(
- role: &str,
- provider: &str,
- config: &Config,
- egress: &EgressLedger,
-) -> OptionalChatModelResult {
- let model = match prepare_claude_agent_sdk_chat_model(role, provider, config)? {
- Ok(model) => model,
- Err(error) => return Some(Err(error)),
- };
- emit_inference_egress(role, &format!("{CLAUDE_AGENT_SDK_PREFIX}{model}"), egress);
- let chat: Arc<dyn ChatModel<()>> = Arc::new(ClaudeAgentSdkProvider::for_model(
- (&config.claude_agent_sdk).into(),
- model.clone(),
- ));
- Some(Ok((chat, model)))
-}
-
-/// Creates a bounded one-shot CLI model only when the explicit environment
-/// credential can be frozen and passed to the inspection-only wrapper.
++/// Builds only an explicitly authenticated, bounded SDK model for doctor.
++/// CLI-managed credentials are never consulted, so inspection cannot inherit
++/// or mutate an interactive provider session.
+ pub(super) fn try_create_claude_agent_sdk_chat_model_for_inspection(
+ role: &str,
+ provider: &str,
+ config: &Config,
+ ) -> InspectionChatModelResult {
+ let model = claude_agent_sdk_model_from_string(provider, config)?;
+ Some((|| {
+ enforce_local_only_inference(role, provider)?;
+ let api_key = std::env::var("ANTHROPIC_API_KEY")
+ .ok()
+ .filter(|value| !value.is_empty());
+ let auth_token = std::env::var("ANTHROPIC_AUTH_TOKEN")
+ .ok()
+ .filter(|value| !value.is_empty());
+ let credential = api_key
+ .as_deref()
+ .or(auth_token.as_deref())
+ .ok_or_else(|| anyhow::anyhow!("explicit Claude API credential is unavailable"))?
+ .to_string();
+ let base_url = std::env::var("ANTHROPIC_BASE_URL")
+ .ok()
+ .filter(|value| !value.is_empty());
+ let endpoint = base_url
+ .as_deref()
+ .unwrap_or("https://api.anthropic.com")
+ .trim_end_matches('/')
+ .to_string();
++ let model_id = model.clone();
+ let auth =
+ tinyagents_harness::providers::claude_agent_sdk::ClaudeAgentSdkInspectionAuth::new(
+ api_key, auth_token, base_url,
+ )?;
- let chat = ClaudeAgentSdkProvider::for_inspection(
++ let model = ClaudeAgentSdkProvider::for_inspection(
+ (&config.claude_agent_sdk).into(),
+ model.clone(),
+ auth,
+ );
+ Ok((
- Arc::new(chat) as Arc<dyn ChatModel<()>>,
- model.clone(),
++ Arc::new(model) as Arc<dyn ChatModel<()>>,
++ model_id,
+ endpoint,
+ credential,
+ ))
+ })())
+ }
+
-pub(super) fn prepare_claude_agent_sdk_chat_model(
- role: &str,
- provider: &str,
- config: &Config,
-) -> Option<anyhow::Result<String>> {
- let model = claude_agent_sdk_model_from_string(provider, config)?;
- if let Err(error) = enforce_local_only_inference(role, provider) {
- return Some(Err(error));
- }
- if let Err(error) = verify_provider_session(config, provider) {
- return Some(Err(error));
- }
- Some(Ok(model))
-}
-
-pub(super) fn claude_agent_sdk_model_from_string(
- provider: &str,
- config: &Config,
-) -> Option<String> {
++fn claude_agent_sdk_model_from_string(provider: &str, config: &Config) -> Option<String> {
+ let provider = provider.trim();
- let model = if provider == CLAUDE_AGENT_SDK_PROVIDER {
- config.claude_agent_sdk.default_model.clone()
++ if provider == CLAUDE_AGENT_SDK_PROVIDER {
++ Some(config.claude_agent_sdk.default_model.clone())
+ } else {
- let model = provider.strip_prefix(CLAUDE_AGENT_SDK_PREFIX)?;
- model.trim().to_string()
- };
- Some(model)
-}
-
-pub(super) fn try_create_claude_code_chat_model(
- role: &str,
- config: &Config,
- model_override: Option<&str>,
- egress: &EgressLedger,
-) -> OptionalChatModelResult {
- let resolved = provider_for_role(role, config);
- try_create_claude_code_chat_model_from_string(role, &resolved, config, model_override, egress)
-}
-
-pub(super) fn try_create_claude_code_chat_model_from_string(
- role: &str,
- provider: &str,
- config: &Config,
- model_override: Option<&str>,
- egress: &EgressLedger,
-) -> OptionalChatModelResult {
- let provider = provider.trim();
- let model_with_temp =
- provider.strip_prefix(tinyagents_harness::providers::claude_code::PROVIDER_PREFIX)?;
- let (configured_model, temperature_override) = split_model_and_temperature(model_with_temp);
- if temperature_override.is_some() {
- log::warn!(
- "[providers][chat-factory] claude-code provider: per-model temperature override \
- is accepted but not wired through to the CLI — the @<temp> suffix is ignored"
- );
- }
- if configured_model.is_empty() {
- return Some(Err(anyhow::anyhow!(
- "[chat-factory] provider string '{}' for role '{}' has an empty model — \
- use 'claude-code:<model-id>'",
- provider,
- role
- )));
- }
- if let Err(error) = enforce_local_only_inference(role, provider) {
- return Some(Err(error));
- }
- if let Err(error) = verify_provider_session(config, provider) {
- return Some(Err(error));
++ Some(
++ provider
++ .strip_prefix(CLAUDE_AGENT_SDK_PREFIX)?
++ .trim()
++ .to_owned(),
++ )
+ }
- let workspace = config
- .config_path
- .parent()
- .map(std::path::Path::to_path_buf)
- .unwrap_or_else(|| config.workspace_dir.clone());
- let effective_model = model_override.unwrap_or(&configured_model).to_string();
- emit_inference_egress(
- role,
- &format!(
- "{}{effective_model}",
- tinyagents_harness::providers::claude_code::PROVIDER_PREFIX
- ),
- egress,
- );
- let chat = match tinyagents_harness::providers::claude_code::ClaudeCodeProvider::from_env(
- effective_model,
- workspace,
- config.action_dir.clone(),
- ) {
- Ok(model) => Arc::new(model.with_mcp_provider(Arc::new(OpenHumanMcpEndpoint)))
- as Arc<dyn ChatModel<()>>,
- Err(error) => return Some(Err(error)),
- };
- Some(Ok((chat, configured_model)))
+ }
+
-/// Uses the same Claude CLI for a one-shot, tool-free inspection request. The
-/// route is unavailable without an explicit API credential; the saved CLI
-/// session is never read.
++/// Claude Code inspection uses the same frozen, tool-free SDK path; it never
++/// reads the CLI's saved session.
+ pub(super) fn try_create_claude_code_chat_model_for_inspection(
+ role: &str,
+ provider: &str,
+ config: &Config,
+ ) -> InspectionChatModelResult {
+ let provider = provider.trim();
- let model_with_temp =
++ let model =
+ provider.strip_prefix(tinyagents_harness::providers::claude_code::PROVIDER_PREFIX)?;
- let (configured_model, _) = split_model_and_temperature(model_with_temp);
- if configured_model.is_empty() {
++ let (model, _) = split_model_and_temperature(model);
++ if model.is_empty() {
+ return Some(Err(anyhow::anyhow!("Claude CLI route has an empty model")));
+ }
- let sdk_provider = format!("{CLAUDE_AGENT_SDK_PREFIX}{configured_model}");
++ let sdk_provider = format!("{CLAUDE_AGENT_SDK_PREFIX}{model}");
+ try_create_claude_agent_sdk_chat_model_for_inspection(role, &sdk_provider, config)
+ }
#[derive(Debug)]
-struct OpenHumanMcpEndpoint;
+pub(super) struct OpenHumanMcpEndpoint;
#[async_trait::async_trait]
impl tinyagents_harness::providers::claude_code::driver::McpEndpointProvider
diff --cc crates/openhuman-core/src/inference/provider/factory_crate_native_defaults_tests.rs
index 0000000000,0000000000..0e11d13955
new file mode 100644
--- /dev/null
+++ b/crates/openhuman-core/src/inference/provider/factory_crate_native_defaults_tests.rs
@@@ -1,0 -1,0 +1,42 @@@
++use super::*;
++
++#[test]
++fn default_temperature_wrapper_preserves_physical_attempt_tracking() {
++ use async_trait::async_trait;
++ use std::sync::Arc;
++ use tinyinference_llm::model::{ModelRequest, ModelResponse};
++
++ struct TrackedModel;
++
++ #[async_trait]
++ impl ChatModel<()> for TrackedModel {
++ fn tracks_physical_attempts(&self) -> bool {
++ true
++ }
++
++ fn has_pre_invocation_admission_gate(&self) -> bool {
++ true
++ }
++
++ async fn invoke(
++ &self,
++ _state: &(),
++ _request: ModelRequest,
++ ) -> tinyinference_llm::Result<ModelResponse> {
++ Ok(ModelResponse::assistant("ok"))
++ }
++ }
++
++ let _guard = crate::inference::inference_test_guard();
++ let _override = test_provider_override::install_model(Arc::new(TrackedModel));
++ let wrapped = create_chat_model_in(
++ &crate::core::runtime::DispatchCtx::ambient(),
++ "chat",
++ &Config::default(),
++ 0.3,
++ )
++ .expect("test override model");
++
++ assert!(wrapped.tracks_physical_attempts());
++ assert!(wrapped.has_pre_invocation_admission_gate());
++}
diff --cc crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs
index eec15d739b,74cd31cd88..2d7a99ef7e
--- a/crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs
+++ b/crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs
@@@ -125,9 -80,9 +125,11 @@@ fn enforce_local_only_inference_errors_
Err(error) => error,
Ok(_) => panic!("direct Claude Code model must preserve the privacy gate"),
};
-- assert!(claude_code_error
-- .to_string()
-- .contains("Local-only privacy mode"));
++ assert!(
++ claude_code_error
++ .to_string()
++ .contains("Local-only privacy mode")
++ );
// Both the default factory and a thread-attached managed picker route must
// hit the managed resolver's privacy gate before any backend client exists.
@@@ -363,363 -367,16 +365,372 @@@ fn explicit_local_provider_string_route
fn try_create_local_runtime_returns_none_for_managed_and_cloud() {
let _guard = crate::inference::inference_test_guard();
// Default config resolves to the managed backend, not a local runtime.
- assert!(super::local_runtime::try_create_local_runtime_chat_model(
- "chat",
- &Config::default(),
- &EgressLedger::none(),
- )
- .is_none());
+ assert!(
- try_create_local_runtime_chat_model("chat", &Config::default(), &EgressLedger::none())
- .is_none()
++ super::local_runtime::try_create_local_runtime_chat_model(
++ "chat",
++ &Config::default(),
++ &EgressLedger::none(),
++ )
++ .is_none()
+ );
// A BYOK cloud slug is not a local runtime either — it falls through to the
// `Provider` path.
let mut cloud = Config::default();
cloud.cloud_providers.push(openai_entry("p_oai", "openai"));
cloud.chat_provider = Some("openai:gpt-4o-mini".to_string());
- assert!(super::local_runtime::try_create_local_runtime_chat_model(
- "chat",
- &cloud,
- &EgressLedger::none(),
- )
- .is_none());
- assert!(try_create_local_runtime_chat_model("chat", &cloud, &EgressLedger::none()).is_none());
++ assert!(
++ super::local_runtime::try_create_local_runtime_chat_model(
++ "chat",
++ &cloud,
++ &EgressLedger::none(),
++ )
++ .is_none()
++ );
+}
+
+#[test]
+fn create_chat_model_routes_plain_bearer_cloud_slug_to_crate_native() {
+ let _guard = crate::inference::inference_test_guard();
+ // DeepSeek is a built-in chat-completions-only Bearer provider: no
+ // `/v1/responses` fallback and no codex-oauth, so it is wire-equivalent and
+ // flips crate-native.
+ let (_tmp, mut config) = isolated_config();
+ config.cloud_providers.push(deepseek_entry("p_ds"));
+ config.chat_provider = Some("deepseek:deepseek-reasoner".to_string());
+ store_fixture_cloud_key(&config, "deepseek");
+ let (model, model_id) =
+ create_chat_model_with_model_id_in(&fixture_library_dispatch(), "chat", &config, 0.7)
+ .expect("bearer cloud create_chat_model must build");
+ assert_eq!(model_id, "deepseek-reasoner");
+ let profile = model
+ .profile()
+ .expect("crate-native cloud model exposes a profile");
+ assert_eq!(profile.provider.as_deref(), Some("deepseek"));
+ // A generic cloud model keeps native tool calling + vision on (unlike the
+ // local runtimes), so this is the crate `OpenAiModel` default profile.
+ assert!(profile.tool_calling);
+}
+
+#[test]
+fn explicit_cloud_provider_string_routes_to_crate_native_model() {
+ let _guard = crate::inference::inference_test_guard();
+ let (_tmp, mut config) = isolated_config();
+ config.cloud_providers.push(deepseek_entry("p_ds"));
+ store_fixture_cloud_key(&config, "deepseek");
+ let model_and_id = crate::core::runtime::CoreContext::sync_scope(
+ fixture_library_dispatch()
+ .resolved()
+ .expect("library context"),
+ || {
+ create_chat_model_from_string_with_model_id(
+ "chat",
+ "deepseek:deepseek-reasoner",
+ &config,
+ 0.7,
+ )
+ },
+ );
+ let (model, model_id) = model_and_id.expect("explicit cloud model must build");
+ assert_eq!(model_id, "deepseek-reasoner");
+ assert_eq!(
+ model
+ .profile()
+ .and_then(|profile| profile.provider.as_deref()),
+ Some("deepseek")
+ );
+}
+
+#[test]
+fn create_chat_model_routes_anthropic_auth_cloud_slug_to_crate_native() {
+ let _guard = crate::inference::inference_test_guard();
+ // Anthropic-auth cloud slugs are always wire-equivalent (their endpoints have
+ // no `/v1/responses`, so the host's dormant fallback is behavior-neutral).
+ let (_tmp, mut config) = isolated_config();
+ config
+ .cloud_providers
+ .push(anthropic_entry("p_anth", "anthropic"));
+ config.chat_provider = Some("anthropic:claude-sonnet-4-6".to_string());
+ store_fixture_cloud_key(&config, "anthropic");
+ let (model, model_id) =
+ create_chat_model_with_model_id_in(&fixture_library_dispatch(), "chat", &config, 0.7)
+ .expect("anthropic cloud create_chat_model must build");
+ assert_eq!(model_id, "claude-sonnet-4-6");
+ assert_eq!(
+ model.profile().and_then(|p| p.provider.as_deref()),
+ Some("anthropic")
+ );
+ // The native Messages API adapter, not the OpenAI-compat flavour: its
+ // cache identity is `anthropic:<base>:<model>`, while the compat client
+ // would report the provider slug with an OpenAI-shaped identity. Only the
+ // native adapter places `cache_control` breakpoints — Anthropic's compat
+ // endpoint documents prompt caching as unsupported.
+ let identity = model.cache_identity().expect("anthropic identifies itself");
+ assert!(
+ identity.starts_with("anthropic:https://api.anthropic.com/v1:claude-sonnet-4-6"),
+ "expected the native Messages adapter, got identity {identity}"
+ );
- assert!(model
- .profile()
- .is_some_and(|p| p.tool_calling && p.streaming));
++ assert!(
++ model
++ .profile()
++ .is_some_and(|p| p.tool_calling && p.streaming)
++ );
+}
+
+/// Text mode (prompt-guided tools) is only implemented on the Chat Completions
+/// adapter, so an Anthropic slug asked for `native_tools = false` keeps the
+/// compat client rather than a native adapter that would ignore the request.
+#[test]
+fn anthropic_auth_cloud_slug_in_text_mode_keeps_the_compat_client() {
+ let _guard = crate::inference::inference_test_guard();
+ let (_tmp, mut config) = isolated_config();
+ config
+ .cloud_providers
+ .push(anthropic_entry("p_anth", "anthropic"));
+ store_fixture_cloud_key(&config, "anthropic");
+ let (model, model_id) = try_create_cloud_slug_chat_model_from_string_with_native_tools(
+ "chat",
+ "anthropic:claude-sonnet-4-6",
+ &config,
+ false,
+ &EgressLedger::none(),
+ )
+ .expect("anthropic slug resolves")
+ .expect("build");
+ assert_eq!(model_id, "claude-sonnet-4-6");
+ let identity = model.cache_identity().unwrap_or_default();
+ assert!(
+ !identity.starts_with("anthropic:https://"),
+ "text mode must not route to the native adapter, got {identity}"
+ );
+ assert!(model.profile().is_some_and(|p| !p.tool_calling));
}
-include!("factory_crate_native_cloud_tests.rs");
+#[test]
+fn configured_openhuman_jwt_slug_routes_to_managed_chat_model() {
+ let _guard = crate::inference::inference_test_guard();
+ install_test_managed_provider();
+ let (_tmp, mut config) = isolated_config();
+ config
+ .cloud_providers
+ .push(fixture_managed_entry("p_fixture"));
+ config.chat_provider = Some("fixture-managed:hint:reasoning".to_string());
+
+ let (_model, model_id) =
+ try_create_cloud_slug_chat_model("chat", &config, &EgressLedger::none())
+ .expect("registered host policy should recognize this route")
+ .expect("registered model should build");
+
+ assert_eq!(model_id, "fixture/managed-default");
+
+ // A concrete catalog id is forwarded verbatim.
+ config.chat_provider = Some("fixture-managed:vendor/pinned".to_string());
+ let (_, pinned_id) = try_create_cloud_slug_chat_model("chat", &config, &EgressLedger::none())
+ .expect("registered host policy should recognize this route")
+ .expect("registered model should build");
+ assert_eq!(pinned_id, "vendor/pinned");
+ crate::inference::registry::unregister_chat_model(
+ crate::inference::provider::factory::PROVIDER_OPENHUMAN,
+ );
+}
+
+#[tokio::test]
+async fn openhuman_jwt_slug_discloses_pinned_model() {
+ use crate::core::events::DomainEvent;
+ use crate::security::egress::{EgressDescriptor, EgressReason};
+ use std::time::Duration;
+
+ let _guard = crate::inference::inference_test_guard_async().await;
+ install_test_managed_provider();
+ crate::core::bus::init().await.expect("bus init");
+ let mut rx = crate::core::bus::BUS.get().unwrap().receiver();
+
+ let marker = "egress-jwt-pinned-marker-v1";
+ let (_tmp, mut config) = isolated_config();
+ config
+ .cloud_providers
+ .push(fixture_managed_entry("p_fixture"));
+ let provider = format!("fixture-managed:{marker}");
+ let _ = try_create_cloud_slug_chat_model_from_string(
+ "chat",
+ &provider,
+ &config,
+ &EgressLedger::none(),
+ )
+ .expect("registered host policy should recognize this route")
+ .expect("registered model should build");
+
+ let sentinel = "egress-jwt-pinned-sentinel-end";
+ crate::core::bus::BUS.publish(DomainEvent::ExternalTransferPending {
+ descriptor: EgressDescriptor::network_fetch(sentinel),
+ thread_id: None,
+ client_id: None,
+ request_id: None,
+ });
+
+ let mut count = 0usize;
+ loop {
+ match tokio::time::timeout(Duration::from_secs(3), rx.recv()).await {
+ Ok(Some(DomainEvent::ExternalTransferPending { descriptor, .. })) => {
+ if descriptor.service == marker {
+ assert_eq!(descriptor.provider_slug, "openhuman");
+ assert!(matches!(descriptor.reason, EgressReason::Inference));
+ count += 1;
+ } else if descriptor.service == sentinel {
+ break;
+ }
+ }
+ Ok(Some(_)) => continue,
+ Ok(None) => panic!("the bus closed before the sentinel arrived"),
+ Err(_) => panic!("timed out before egress sentinel arrived"),
+ }
+ }
+ assert_eq!(
+ count, 1,
+ "JWT construction must disclose its pinned model once"
+ );
+ crate::inference::registry::unregister_chat_model(
+ crate::inference::provider::factory::PROVIDER_OPENHUMAN,
+ );
+}
+
+#[tokio::test]
+async fn native_claude_turn_routes_disclose_pinned_models() {
+ use crate::core::bus::BUS;
+ use crate::core::events::DomainEvent;
+ use crate::security::egress::EgressDescriptor;
+ use std::time::Duration;
+
+ let _guard = crate::inference::inference_test_guard_async().await;
+ crate::core::bus::init().await.expect("bus init");
+ let mut rx = crate::core::bus::BUS.get().unwrap().receiver();
+
+ let configured_sdk = "egress-sdk-configured-marker";
+ let pinned_sdk = "egress-sdk-pinned-marker";
+ let mut sdk_config = Config::default();
+ sdk_config.chat_provider = Some(format!("claude_agent_sdk:{configured_sdk}"));
+ crate::inference::turn_models::TurnModelSource::new_crate_native(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ "chat",
+ Arc::new(sdk_config),
+ )
+ .build(pinned_sdk, 0.0, None, None)
+ .expect("Claude Agent SDK turn set should build");
+
+ let configured_code = "egress-code-configured-marker";
+ let pinned_code = "egress-code-pinned-marker";
+ let mut code_config = Config::default();
+ code_config.chat_provider = Some(format!("claude-code:{configured_code}"));
+ // Egress is disclosed once the effective model is selected, before the
+ // environment probe. The test therefore remains valid on hosts without the
+ // Claude Code CLI.
+ let _ = crate::inference::turn_models::TurnModelSource::new_crate_native(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ "chat",
+ Arc::new(code_config),
+ )
+ .build(pinned_code, 0.0, None, None);
+
+ let sentinel = "egress-native-claude-sentinel-end";
+ BUS.publish(DomainEvent::ExternalTransferPending {
+ descriptor: EgressDescriptor::network_fetch(sentinel),
+ thread_id: None,
+ client_id: None,
+ request_id: None,
+ });
+
+ let mut sdk_count = 0usize;
+ let mut code_count = 0usize;
+ let mut configured_count = 0usize;
+ loop {
+ match tokio::time::timeout(Duration::from_secs(3), rx.recv()).await {
+ Ok(Some(DomainEvent::ExternalTransferPending { descriptor, .. })) => {
+ match descriptor.service.as_str() {
+ service if service == pinned_sdk => {
+ assert_eq!(descriptor.provider_slug, "claude_agent_sdk");
+ sdk_count += 1;
+ }
+ service if service == pinned_code => {
+ assert_eq!(descriptor.provider_slug, "claude-code");
+ code_count += 1;
+ }
+ service if service == configured_sdk || service == configured_code => {
+ configured_count += 1;
+ }
+ service if service == sentinel => break,
+ _ => {}
+ }
+ }
+ Ok(Some(_)) => continue,
+ Ok(None) => panic!("the bus closed before the sentinel arrived"),
+ Err(_) => panic!("timed out before egress sentinel arrived"),
+ }
+ }
+
+ assert_eq!(
+ sdk_count, 1,
+ "SDK route must disclose its pinned model once"
+ );
+ assert_eq!(
+ code_count, 1,
+ "Claude Code route must disclose its pinned model once"
+ );
+ assert_eq!(
+ configured_count, 0,
+ "native Claude routes must not disclose stale configured models"
+ );
+}
+
+#[test]
+fn openhuman_jwt_slug_preserves_forced_text_mode() {
+ let _guard = crate::inference::inference_test_guard();
+ let native_modes = install_test_managed_provider();
+ let (_tmp, mut config) = isolated_config();
+ config
+ .cloud_providers
+ .push(fixture_managed_entry("p_fixture"));
+
+ let (_model, _) = try_create_cloud_slug_chat_model_from_string_with_native_tools(
+ "chat",
+ "fixture-managed:hint:reasoning",
+ &config,
+ false,
+ &EgressLedger::none(),
+ )
+ .expect("registered host policy should recognize this route")
+ .expect("registered model should build");
+
+ assert_eq!(native_modes.lock().unwrap().as_slice(), [false]);
+ crate::inference::registry::unregister_chat_model(
+ crate::inference::provider::factory::PROVIDER_OPENHUMAN,
+ );
+}
+
+#[test]
+fn openhuman_jwt_slug_without_model_preserves_managed_role_tier() {
+ let _guard = crate::inference::inference_test_guard();
+ install_test_managed_provider();
+ let (_tmp, mut config) = isolated_config();
+ config
+ .cloud_providers
+ .push(fixture_managed_entry("p_fixture"));
+
+ let (_model, model_id) = try_create_cloud_slug_chat_model_from_string(
+ "summarization",
+ "fixture-managed:",
+ &config,
+ &EgressLedger::none(),
+ )
+ .expect("registered host policy should recognize this route")
+ .expect("registered model should build");
+
+ assert_eq!(model_id, "fixture/managed-default");
+ crate::inference::registry::unregister_chat_model(
+ crate::inference::provider::factory::PROVIDER_OPENHUMAN,
+ );
+}
+
+#[path = "factory_crate_native_cloud_tests.rs"]
+mod cloud_tests;
++
++#[path = "factory_crate_native_defaults_tests.rs"]
++mod default_temperature_tests;
diff --cc crates/openhuman-core/src/inference/provider/factory_tests.rs
index 3f0e6a0f7d,7a87fe318a..9bbc543ff7
--- a/crates/openhuman-core/src/inference/provider/factory_tests.rs
+++ b/crates/openhuman-core/src/inference/provider/factory_tests.rs
@@@ -3,107 -3,33 +3,132 @@@ use crate::config::schema::cloud_provid
use crate::config::Config;
use crate::security::credentials::AuthService;
use tempfile::TempDir;
+ use wiremock::matchers::{method, path};
+ use wiremock::{Mock, MockServer, ResponseTemplate};
+fn with_library_test_context<T>(f: impl FnOnce() -> T) -> T {
+ let context = crate::core::runtime::CoreContext::for_test_with_host_kind(
+ crate::core::types::HostKind::Library,
+ crate::core::runtime::DomainSet::full(),
+ None,
+ );
+ crate::core::runtime::CoreContext::sync_scope(context, f)
+}
+
+async fn with_library_test_context_async<F: std::future::Future>(
+ f: impl FnOnce() -> F,
+) -> F::Output {
+ let context = crate::core::runtime::CoreContext::for_test_with_host_kind(
+ crate::core::types::HostKind::Library,
+ crate::core::runtime::DomainSet::full(),
+ None,
+ );
+ crate::core::runtime::CoreContext::scope(context, f()).await
+}
+
+struct ManagedRouteFixtureModel;
+
+#[async_trait::async_trait]
+impl ChatModel<()> for ManagedRouteFixtureModel {
+ async fn invoke(
+ &self,
+ _state: &(),
+ _request: tinyinference_llm::model::ModelRequest,
+ ) -> tinyinference_llm::Result<tinyinference_llm::model::ModelResponse> {
+ Ok(tinyinference_llm::model::ModelResponse::assistant(
+ "fixture",
+ ))
+ }
+}
+
+fn install_test_managed_provider() -> Arc<std::sync::Mutex<Vec<bool>>> {
+ use crate::config::schema::cloud_providers::AuthStyle;
+ use crate::inference::registry::{ChatModelEntry, ProviderModelMetadata};
+ use std::sync::Mutex;
+
+ let native_modes = Arc::new(Mutex::new(Vec::new()));
+ let seen = Arc::clone(&native_modes);
+ crate::inference::registry::register_chat_model(
+ crate::inference::provider::factory::PROVIDER_OPENHUMAN,
+ ChatModelEntry {
+ build: Arc::new(move |request| {
+ seen.lock().unwrap().push(request.native_tool_calling);
+ Ok((
+ Arc::new(ManagedRouteFixtureModel),
+ request
+ .model_override
+ .or(request.default_model)
+ .unwrap_or("fixture/managed-default")
+ .to_string(),
+ ))
+ }),
+ probe: None,
+ models: Some(ProviderModelMetadata {
+ default_model: Arc::new(|| Some("fixture/managed-default".into())),
+ role_for_model: Arc::new(|model| {
+ (model == "hint:reasoning").then(|| "reasoning".into())
+ }),
+ is_alias: Arc::new(|model| model == "hint:reasoning"),
+ is_raw_model: Arc::new(|model| !model.starts_with("hint:")),
+ supports_vision: Arc::new(|_| false),
+ resolve_model: Arc::new(|_, config, model| match model {
+ Some("hint:reasoning") => Some("fixture/managed-default".into()),
+ Some(model) if !model.starts_with("hint:") => Some(model.into()),
+ Some(_) => None,
+ None => config
+ .config
+ .default_model
+ .clone()
+ .or_else(|| Some("fixture/managed-default".into())),
+ }),
+ context_window: Arc::new(|_| None),
+ default_pricing: Arc::new(|| None),
+ without_reasoning: Arc::new(|request| request),
+ }),
+ },
+ );
+ crate::config::schema::cloud_providers::register_hosted_cloud_provider_policy(
+ Arc::new(|slug| slug == "fixture-managed"),
+ Arc::new(|style| style == AuthStyle::OpenhumanJwt),
+ );
+ native_modes
+}
+
+fn fixture_managed_entry(id: &str) -> CloudProviderCreds {
+ CloudProviderCreds {
+ id: id.to_string(),
+ slug: "fixture-managed".to_string(),
+ label: "Managed fixture".to_string(),
+ endpoint: "https://fixture.managed.test/v1".to_string(),
+ auth_style: AuthStyle::OpenhumanJwt,
+ default_model: Some("fixture/managed-default".into()),
+ }
+}
+
use crate::inference::provider::factory::access_gates::host_requires_session;
+
+ #[test]
+ fn inspection_codex_oauth_metadata_marks_output_budget_unsupported() {
+ use crate::inference::provider::factory::InspectionOutputBudgetCapability;
+ use tinyinference_llm::providers::openai::codex::OpenAiCodexRouting;
+
+ let codex = OpenAiCodexRouting {
+ endpoint: "https://chatgpt.com/backend-api/codex".into(),
+ using_oauth: true,
+ account_id: Some("acct-test".into()),
+ };
+ assert_eq!(
+ super::cloud_slug::inspection_output_budget_capability(&codex),
+ InspectionOutputBudgetCapability::Unsupported
+ );
+ assert_eq!(
+ super::cloud_slug::inspection_output_budget_capability(&OpenAiCodexRouting::standard(
+ "https://api.openai.com/v1"
+ )),
+ InspectionOutputBudgetCapability::Bounded
+ );
+ }
+
fn create_test_chat_model_from_string(
role: &str,
provider: &str,
diff --cc crates/openhuman-core/src/inference/provider/models/catalog_listing.rs
index 34e59080e4,b2e9036f49..a1a3ca0d33
--- a/crates/openhuman-core/src/inference/provider/models/catalog_listing.rs
+++ b/crates/openhuman-core/src/inference/provider/models/catalog_listing.rs
@@@ -113,16 -78,16 +113,6 @@@ fn no_managed_catalog() -> crate::core:
)
}
--pub async fn list_configured_models(
-- provider_id: &str,
--) -> Result<crate::core::Outcome<serde_json::Value>, String> {
-- let config = crate::config::Config::load_or_init()
-- .await
-- .map_err(|e| e.to_string())?;
--
-- list_configured_models_from_config(provider_id, &config).await
--}
--
pub async fn list_configured_models_from_config(
provider_id: &str,
config: &crate::config::Config,
diff --cc crates/openhuman-core/src/inference/registry.rs
index 8f0ea0c5ea,581c8f6508..fb46efad1c
--- a/crates/openhuman-core/src/inference/registry.rs
+++ b/crates/openhuman-core/src/inference/registry.rs
@@@ -14,10 -14,19 +14,16 @@@
//! The tables know nothing about what a provider talks to. With nothing
//! registered every consult point behaves exactly as before.
- use std::sync::Arc;
+ use std::collections::hash_map::RandomState;
-use std::future::Future;
+ use std::hash::{BuildHasher, Hash, Hasher};
-use std::pin::Pin;
+ use std::sync::{Arc, OnceLock};
+
+ use tinyinference_embeddings::EmbeddingModel;
-use tinyinference_llm::model::discover::DiscoveryRequest;
+ use tinyinference_llm::model::ChatModel;
use crate::config::Config;
-use crate::core::slots::{Extensions, HookSlot};
+ use crate::core::Outcome;
+use crate::core::slots::{Extensions, HookSlot};
use crate::security::approval::ApprovalChatContext;
use crate::security::egress::EgressLedger;
@@@ -25,180 -37,108 +31,244 @@@
// Chat models
// ---------------------------------------------------------------------------
-/// What a registered chat-model factory is asked to build.
-pub struct ChatModelRequest<'a> {
- /// The workload role the route was resolved for (`chat`, `reasoning`, ...).
- pub role: &'a str,
- /// The configuration in force.
- pub config: &'a Config,
- /// The concrete model id the core resolved for this construction (a role
- /// alias such as `hint:coding` has already been translated to the
- /// configured default).
- pub model_override: Option<&'a str>,
- /// The model the turn runs on when the request itself names none.
- pub default_model: Option<&'a str>,
- /// Whether the model should use native tool calling.
- pub native_tool_calling: bool,
- /// The conversation thread this model serves, when it is a turn model.
- pub thread_id: Option<&'a str>,
- /// Where the construction discloses its external transfer.
- pub egress: &'a EgressLedger,
-}
-
-/// Builds a chat model and reports the model id it resolved to.
-pub type ChatModelFactory = Arc<
- dyn for<'a> Fn(&ChatModelRequest<'a>) -> anyhow::Result<(Arc<dyn ChatModel<()>>, String)>
- + Send
- + Sync,
->;
+/// Host state supplied to a native TinyInference provider callback.
+#[derive(Clone)]
+pub struct ProviderContext {
+ /// Configuration selected by the host for this provider call.
+ pub config: Config,
+ /// Egress ledger selected by the host for this provider call.
+ pub egress: EgressLedger,
+ /// Credential and disclosure data for an embedding factory call.
+ pub embedding: Option<EmbeddingCallContext>,
+ /// Request data and log sink for a catalog listing call.
+ pub catalog: Option<CatalogCallContext>,
+}
-/// Asks a provider whether it can serve `role` right now: `(role, model,
-/// config)`, where `model` is the concrete model id the core resolved.
-pub type ReadinessProbe =
- Arc<dyn Fn(String, String, Config) -> BoxFuture<Result<(), String>> + Send + Sync>;
+#[derive(Clone)]
+pub struct EmbeddingCallContext {
+ pub config: Option<Config>,
+ pub chat: Option<ApprovalChatContext>,
+ pub state_dir: std::path::PathBuf,
+ pub secrets_encrypt: bool,
+}
+
+#[derive(Clone)]
+pub struct CatalogCallContext {
+ pub request: CatalogHostRequest,
+ pub logs: Arc<std::sync::Mutex<Vec<String>>>,
+}
-/// A registered chat-model provider.
#[derive(Clone)]
-pub struct ChatModelEntry {
- /// Builds the model.
- pub build: ChatModelFactory,
- /// Optional readiness probe (the flows inference probe).
- pub probe: Option<ReadinessProbe>,
+pub struct CatalogHostRequest {
+ pub provider_key: String,
+ pub client: reqwest::Client,
+}
+
+impl ProviderContext {
+ pub(crate) fn new(config: &Config, egress: &EgressLedger) -> Self {
+ Self {
+ config: config.clone(),
+ egress: egress.clone(),
+ embedding: None,
+ catalog: None,
+ }
+ }
+
+ pub(crate) fn for_embedding(
+ config: Option<&Config>,
+ chat: Option<ApprovalChatContext>,
+ state_dir: std::path::PathBuf,
+ secrets_encrypt: bool,
+ ) -> Self {
+ let base = config.cloned().unwrap_or_default();
+ Self {
+ config: base,
+ egress: EgressLedger::none(),
+ embedding: Some(EmbeddingCallContext {
+ config: config.cloned(),
+ chat,
+ state_dir,
+ secrets_encrypt,
+ }),
+ catalog: None,
+ }
+ }
+
+ pub(crate) fn for_catalog(config: &Config, request: CatalogHostRequest) -> Self {
+ Self {
+ config: config.clone(),
+ egress: EgressLedger::none(),
+ embedding: None,
+ catalog: Some(CatalogCallContext {
+ request,
+ logs: Arc::new(std::sync::Mutex::new(Vec::new())),
+ }),
+ }
+ }
+}
+
+use tinyinference_llm::providers::overrides::{
+ BoxFuture, CatalogEntry, CatalogLimits, CatalogRequest, ChatModelEntry, ChatModelFactory,
+ ChatModelRequest, EmbeddingFactory, EmbeddingRequest, ProviderModelMetadata, ProviderOverrides,
+ ReadinessProbe,
+};
+
+pub(crate) fn provider_overrides(
+ extensions: Option<Extensions>,
+) -> ProviderOverrides<ProviderContext> {
+ let chat_extensions = extensions.clone();
+ let embedding_extensions = extensions.clone();
+ ProviderOverrides::new(
+ move |provider_id| CHAT_MODELS.get_for(chat_extensions.as_ref(), provider_id),
+ move |provider_id| EMBEDDINGS.get_for(embedding_extensions.as_ref(), provider_id),
+ move |provider_id| CATALOGS.get_for(extensions.as_ref(), provider_id),
+ )
+}
+
+pub(crate) fn ambient_provider_overrides() -> ProviderOverrides<ProviderContext> {
+ ProviderOverrides::new(
+ |provider_id| CHAT_MODELS.get(provider_id),
+ |provider_id| EMBEDDINGS.get(provider_id),
+ |provider_id| CATALOGS.get(provider_id),
+ )
+}
+
+/// A provider-neutral semantic category for a backend error.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum BackendErrorKind {
+ RateLimited,
+ InsufficientCredits,
+ UpstreamUnavailable,
+ ModelUnavailable,
+ PayloadTooLarge,
+ ContextLengthExceeded,
+ BadRequest,
+ Internal,
+}
+
+/// Provider-owned classification, with reporting ownership kept separate from
+/// display semantics and the optional canonical backend token.
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct BackendErrorClassification {
+ /// Whether this classifier owns the provider identity itself.
+ pub provider_owned: bool,
+ /// Whether the backend owns the response for duplicate-report purposes.
+ pub backend_owned: bool,
+ /// Whether this client should still report the event (for known client bugs).
+ pub reportable: bool,
+ /// Canonical raw token, including unknown future tokens.
+ pub token: Option<String>,
+ /// Recognized provider-neutral display category.
+ pub kind: Option<BackendErrorKind>,
+ /// Whether a BAD_REQUEST was explicitly marked as malformed.
+ pub malformed_bad_request: bool,
+}
+
+/// Classifies a provider's backend error. `provider` is present at a typed
+/// provider boundary and absent for flattened, string-only host call sites.
+pub type BackendErrorClassifier =
+ Arc<dyn Fn(Option<&str>, &str) -> BackendErrorClassification + Send + Sync>;
+
+static BACKEND_ERROR_CLASSIFIER: HookSlot<BackendErrorClassifier> =
+ HookSlot::new("inference::backend_error_classifier");
+
+/// Registers a backend error classifier process-wide.
+pub fn register_backend_error_classifier(classifier: BackendErrorClassifier) {
+ BACKEND_ERROR_CLASSIFIER.register("default", classifier);
+}
+
+/// Removes the process-wide backend error classifier.
+pub fn unregister_backend_error_classifier() -> bool {
+ BACKEND_ERROR_CLASSIFIER.unregister("default")
+}
+
+/// Registers a backend error classifier for a CoreContext.
+pub fn register_backend_error_classifier_in(
+ extensions: &Extensions,
+ classifier: BackendErrorClassifier,
+) {
+ BACKEND_ERROR_CLASSIFIER.register_in(extensions, "default", classifier);
+}
+
+/// Classifies an error when a host has supplied a classifier.
+pub fn classify_backend_error(
+ provider: Option<&str>,
+ error: &str,
+) -> Option<BackendErrorClassification> {
+ BACKEND_ERROR_CLASSIFIER
+ .get("default")
+ .map(|classifier| classifier(provider, error))
}
-static CHAT_MODELS: HookSlot<ChatModelEntry> = HookSlot::new("inference::chat_models");
+static CHAT_MODELS: HookSlot<ChatModelEntry<ProviderContext>> =
+ HookSlot::new("inference::chat_models");
+ /// A managed chat-model factory that is safe for inspection calls through
+ /// invoke/stream: it must use a frozen, read-only credential snapshot and
+ /// must not refresh or publish credential state.
+ pub type InspectionChatModelFactory = PreparedInspectionChatModelFactory;
+
+ /// An inspection-safe model and the resolved wire identity it invokes.
+ /// `credential` is retained only long enough for the core to build a
+ /// report-local deduplication key; it must never be logged or reported.
+ pub struct InspectionChatModelBuild {
+ /// Frozen chat model that invokes the resolved route.
+ pub model: Arc<dyn ChatModel<()>>,
+ /// Safe provider model identifier selected for the route.
+ pub model_id: String,
+ /// Effective request endpoint used by the model.
+ pub endpoint: String,
+ /// Exact frozen bearer/key used by the model. Never expose in findings.
+ pub credential: String,
+ }
+
+ /// Inspection-safe provider callback. Unlike the runtime callback this must
+ /// return the same frozen route identity used by the model invocation.
+ pub type PreparedInspectionChatModelFactory = Arc<
+ dyn for<'a> Fn(&ChatModelRequest<'a>) -> anyhow::Result<InspectionChatModelBuild> + Send + Sync,
+ >;
+
+ static INSPECTION_CHAT_MODELS: HookSlot<InspectionChatModelFactory> =
+ HookSlot::new("inference::inspection_chat_models");
+
+ /// Registers an inspection-safe managed model factory process-wide.
+ pub fn register_inspection_chat_model(
+ provider_id: impl Into<String>,
+ factory: PreparedInspectionChatModelFactory,
+ ) {
+ INSPECTION_CHAT_MODELS.register(provider_id, factory);
+ }
+
+ /// Registers an inspection-safe managed model factory for the context built
+ /// from `extensions`.
+ pub fn register_inspection_chat_model_in(
+ extensions: &Extensions,
+ provider_id: impl Into<String>,
+ factory: PreparedInspectionChatModelFactory,
+ ) {
+ INSPECTION_CHAT_MODELS.register_in(extensions, provider_id, factory);
+ }
+
+ /// Removes the process-wide inspection-safe managed model factory.
+ pub fn unregister_inspection_chat_model(provider_id: &str) -> bool {
+ INSPECTION_CHAT_MODELS.unregister(provider_id)
+ }
+
+ pub(crate) fn inspection_chat_model(
+ provider_id: &str,
+ ) -> Option<PreparedInspectionChatModelFactory> {
+ INSPECTION_CHAT_MODELS.get(provider_id)
+ }
+
++pub(crate) fn inspection_chat_model_for(
++ extensions: Option<&Extensions>,
++ provider_id: &str,
++) -> Option<PreparedInspectionChatModelFactory> {
++ INSPECTION_CHAT_MODELS.get_for(extensions, provider_id)
++}
++
/// Registers the chat-model provider `provider_id` for the whole process.
-pub fn register_chat_model(provider_id: impl Into<String>, entry: ChatModelEntry) {
+pub fn register_chat_model(provider_id: impl Into<String>, entry: ChatModelEntry<ProviderContext>) {
CHAT_MODELS.register(provider_id, entry);
}
@@@ -218,210 -158,115 +288,250 @@@ pub fn unregister_chat_model(provider_i
}
/// The registered chat-model provider, if any.
-pub(crate) fn chat_model(provider_id: &str) -> Option<ChatModelEntry> {
- let registered = CHAT_MODELS.get(provider_id);
- // Unit tests model "a hosted provider is present" by default, as the old
- // built-in managed backend was; a test that wants the bare core asks for it
- // with `without_managed_provider`.
- #[cfg(test)]
- let registered =
- registered.or_else(|| super::registry_test_support::default_managed_entry(provider_id));
- registered
+pub(crate) fn chat_model(provider_id: &str) -> Option<ChatModelEntry<ProviderContext>> {
+ ambient_provider_overrides().chat_entry(provider_id)
}
-// ---------------------------------------------------------------------------
-// Embeddings
-// ---------------------------------------------------------------------------
+/// The chat-model provider selected by an explicit context, falling back only
+/// to process registration when that context has no entry.
+pub(crate) fn chat_model_for(
+ extensions: Option<&Extensions>,
+ provider_id: &str,
+) -> Option<ChatModelEntry<ProviderContext>> {
+ provider_overrides(extensions.cloned()).chat_entry(provider_id)
+}
-/// What a registered embedding factory is asked to build.
-pub struct EmbeddingRequest<'a> {
- /// The configuration in force, when the caller has one (the credential-only
- /// constructors do not).
- pub config: Option<&'a Config>,
- /// The embedding model id.
- pub model: &'a str,
- /// The vector dimensionality.
- pub dimensions: usize,
- /// The chat turn the call is made in, so disclosures reach that chat.
- pub chat: Option<ApprovalChatContext>,
- /// The directory the caller's credentials live in (the config's credential
- /// scope, or the process default when the caller has no config).
- pub state_dir: std::path::PathBuf,
- /// Whether that credential store is encrypted at rest.
- pub secrets_encrypt: bool,
+/// The registered provider's model hooks, if it has any.
+pub(crate) fn provider_model_hooks(
+ provider_id: &str,
+) -> Option<ProviderModelMetadata<ProviderContext>> {
+ chat_model(provider_id)?.models
}
-/// Builds an embedding model.
-pub type EmbeddingFactory = Arc<
- dyn for<'a> Fn(
- &EmbeddingRequest<'a>,
- ) -> tinyinference_embeddings::Result<Box<dyn EmbeddingModel>>
- + Send
- + Sync,
->;
+/// The registered provider's default model, if it declares one.
+pub fn provider_default_model(provider_id: &str) -> Option<String> {
+ let hooks = provider_model_hooks(provider_id)?;
+ (hooks.default_model)()
+}
-static EMBEDDINGS: HookSlot<EmbeddingFactory> = HookSlot::new("inference::embeddings");
+/// The registered provider's default model selected by an explicit context,
+/// falling back to process registration when that context has no entry.
+pub(crate) fn provider_default_model_for(
+ extensions: Option<&Extensions>,
+ provider_id: &str,
+) -> Option<String> {
+ let hooks = chat_model_for(extensions, provider_id)?.models?;
+ (hooks.default_model)()
+}
+
+/// Default pricing supplied by the registered provider, if any.
+pub fn provider_default_pricing(provider_id: &str) -> Option<(String, f64, f64)> {
+ let hooks = provider_model_hooks(provider_id)?;
+ (hooks.default_pricing)()
+}
+
+/// The workload role assigned to a provider-specific model alias.
+pub fn provider_model_role(provider_id: &str, model: &str) -> Option<String> {
+ let hooks = provider_model_hooks(provider_id)?;
+ (hooks.role_for_model)(model)
+}
+
+pub(crate) fn provider_model_role_for(
+ extensions: Option<&Extensions>,
+ provider_id: &str,
+ model: &str,
+) -> Option<String> {
+ let hooks = chat_model_for(extensions, provider_id)?.models?;
+ (hooks.role_for_model)(model)
+}
+
+/// Whether the provider recognizes `model` as an abstract alias.
+pub fn provider_model_is_alias(provider_id: &str, model: &str) -> bool {
+ provider_model_hooks(provider_id).is_some_and(|hooks| (hooks.is_alias)(model))
+}
+
+pub(crate) fn provider_model_is_alias_for(
+ extensions: Option<&Extensions>,
+ provider_id: &str,
+ model: &str,
+) -> bool {
+ chat_model_for(extensions, provider_id)
+ .and_then(|entry| entry.models)
+ .is_some_and(|hooks| (hooks.is_alias)(model))
+}
+
+/// Whether the provider regards `model` as a concrete id for pass-through.
+pub fn provider_model_is_raw(provider_id: &str, model: &str) -> bool {
+ let model = model.trim();
+ !model.is_empty()
+ && !model.starts_with("hint:")
+ && provider_model_hooks(provider_id).is_none_or(|hooks| (hooks.is_raw_model)(model))
+}
+
+/// Whether the provider says `model` supports image input.
+pub fn provider_model_supports_vision(provider_id: &str, model: &str) -> bool {
+ provider_model_hooks(provider_id).is_some_and(|hooks| (hooks.supports_vision)(model))
+}
+
+pub(crate) fn provider_model_supports_vision_for(
+ extensions: Option<&Extensions>,
+ provider_id: &str,
+ model: &str,
+) -> bool {
+ chat_model_for(extensions, provider_id)
+ .and_then(|entry| entry.models)
+ .is_some_and(|hooks| (hooks.supports_vision)(model))
+}
+
+/// Provider-specific resolution of a role alias, configured default, or pin.
+pub fn resolve_provider_model(
+ provider_id: &str,
+ role: &str,
+ config: &Config,
+ model_override: Option<&str>,
+) -> Option<String> {
+ let hooks = provider_model_hooks(provider_id)?;
+ (hooks.resolve_model)(
+ role,
+ &ProviderContext::new(config, &EgressLedger::none()),
+ model_override,
+ )
+}
+
+pub(crate) fn resolve_provider_model_for(
+ extensions: Option<&Extensions>,
+ provider_id: &str,
+ role: &str,
+ config: &Config,
+ model_override: Option<&str>,
+) -> Option<String> {
+ let hooks = chat_model_for(extensions, provider_id)?.models?;
+ (hooks.resolve_model)(
+ role,
+ &ProviderContext::new(config, &EgressLedger::none()),
+ model_override,
+ )
+}
+
+/// The provider's model-specific context window, if known.
+pub fn provider_model_context_window(provider_id: &str, model: &str) -> Option<u64> {
+ let hooks = provider_model_hooks(provider_id)?;
+ (hooks.context_window)(model)
+}
+
+pub(crate) fn provider_model_context_window_for(
+ extensions: Option<&Extensions>,
+ provider_id: &str,
+ model: &str,
+) -> Option<u64> {
+ let hooks = chat_model_for(extensions, provider_id)?.models?;
+ (hooks.context_window)(model)
+}
+
+/// Applies a provider-specific no-reasoning hint when the provider is installed.
+pub fn provider_request_without_reasoning(
+ provider_id: &str,
+ request: tinyinference_llm::model::ModelRequest,
+) -> tinyinference_llm::model::ModelRequest {
+ match provider_model_hooks(provider_id) {
+ Some(hooks) => (hooks.without_reasoning)(request),
+ None => request,
+ }
+}
+
+/// Registers a generic config normalizer, such as a provider-owned migration
+/// that must also run after the config schema reaches its current version.
+pub type ConfigNormalizer = Arc<dyn Fn(&mut Config) -> bool + Send + Sync>;
+
+static CONFIG_NORMALIZERS: HookSlot<ConfigNormalizer> = HookSlot::new("config::normalizers");
+
+/// Registers a config normalizer for the process.
+pub fn register_config_normalizer(id: impl Into<String>, normalizer: ConfigNormalizer) {
+ CONFIG_NORMALIZERS.register(id, normalizer);
+}
+
+/// Registers a config normalizer for a CoreContext's extensions.
+pub fn register_config_normalizer_in(
+ extensions: &Extensions,
+ id: impl Into<String>,
+ normalizer: ConfigNormalizer,
+) {
+ CONFIG_NORMALIZERS.register_in(extensions, id, normalizer);
+}
+
+/// Runs the currently registered config normalizers and reports whether any
+/// changed the config.
+pub(crate) fn normalize_config(config: &mut Config) -> bool {
+ CONFIG_NORMALIZERS
+ .entries_context_first()
+ .into_iter()
+ .fold(false, |changed, (_, normalize)| {
+ normalize(config) || changed
+ })
+}
+
+// ---------------------------------------------------------------------------
+// Embeddings
+// ---------------------------------------------------------------------------
+
+static EMBEDDINGS: HookSlot<EmbeddingFactory<ProviderContext>> =
+ HookSlot::new("inference::embeddings");
+ /// A managed embedding factory safe for doctor inspection: it uses a frozen
+ /// credential snapshot and never refreshes or publishes credential state.
+ pub type InspectionEmbeddingFactory = EmbeddingFactory;
+
+ static INSPECTION_EMBEDDINGS: HookSlot<InspectionEmbeddingFactory> =
+ HookSlot::new("inference::inspection-embeddings");
+
+ /// Registers a managed embedding factory for read-only credential inspection.
+ pub fn register_inspection_embedding<F>(provider_id: impl Into<String>, factory: F)
+ where
+ F: for<'a> Fn(
+ &EmbeddingRequest<'a>,
+ ) -> tinyinference_embeddings::Result<Box<dyn EmbeddingModel>>
+ + Send
+ + Sync
+ + 'static,
+ {
+ INSPECTION_EMBEDDINGS.register(provider_id, Arc::new(factory));
+ }
+
+ /// Registers an inspection-safe embedding factory for one core context.
+ pub fn register_inspection_embedding_in<F>(
+ extensions: &Extensions,
+ provider_id: impl Into<String>,
+ factory: F,
+ ) where
+ F: for<'a> Fn(
+ &EmbeddingRequest<'a>,
+ ) -> tinyinference_embeddings::Result<Box<dyn EmbeddingModel>>
+ + Send
+ + Sync
+ + 'static,
+ {
+ INSPECTION_EMBEDDINGS.register_in(extensions, provider_id, Arc::new(factory));
+ }
+
+ pub(crate) fn inspection_embedding(provider_id: &str) -> Option<InspectionEmbeddingFactory> {
+ INSPECTION_EMBEDDINGS.get(provider_id)
+ }
+
/// Registers the embedding provider `provider_id` for the whole process.
-pub fn register_embedding<F>(provider_id: impl Into<String>, factory: F)
-where
- F: for<'a> Fn(
- &EmbeddingRequest<'a>,
- ) -> tinyinference_embeddings::Result<Box<dyn EmbeddingModel>>
- + Send
- + Sync
- + 'static,
-{
- EMBEDDINGS.register(provider_id, Arc::new(factory));
+pub fn register_embedding(
+ provider_id: impl Into<String>,
+ factory: EmbeddingFactory<ProviderContext>,
+) {
+ EMBEDDINGS.register(provider_id, factory);
}
-/// Registers the embedding provider `provider_id` for the context built from
-/// `extensions`.
-pub fn register_embedding_in<F>(extensions: &Extensions, provider_id: impl Into<String>, factory: F)
-where
- F: for<'a> Fn(
- &EmbeddingRequest<'a>,
- ) -> tinyinference_embeddings::Result<Box<dyn EmbeddingModel>>
- + Send
- + Sync
- + 'static,
-{
- EMBEDDINGS.register_in(extensions, provider_id, Arc::new(factory));
+/// Registers the embedding provider `provider_id` for the context built from `extensions`.
+pub fn register_embedding_in(
+ extensions: &Extensions,
+ provider_id: impl Into<String>,
+ factory: EmbeddingFactory<ProviderContext>,
+) {
+ EMBEDDINGS.register_in(extensions, provider_id, factory);
}
/// Removes the process-wide embedding provider `provider_id`.
@@@ -461,17 -341,121 +571,140 @@@ pub fn unregister_catalog(provider_id:
}
/// The registered catalog, if any.
-pub(crate) fn catalog(provider_id: &str) -> Option<CatalogEntry> {
- CATALOGS.get(provider_id)
+pub(crate) fn catalog(provider_id: &str) -> Option<CatalogEntry<ProviderContext>> {
+ ambient_provider_overrides().catalog_entry(provider_id)
+}
+
+pub(crate) fn catalog_for(
+ extensions: Option<&Extensions>,
+ provider_id: &str,
+) -> Option<CatalogEntry<ProviderContext>> {
+ provider_overrides(extensions.cloned()).catalog_entry(provider_id)
}
+ /// Safe outcomes from an inspection-only catalog request. Error response
+ /// bodies stay at the adapter boundary so Findings can never echo them.
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
+ pub enum InspectionCatalogError {
+ /// The selected credential was rejected or lacks catalog access.
+ AuthOrAccess,
+ /// The provider does not expose a model-listing route.
+ NoCatalog,
+ /// The selected profile, endpoint, or read-only credential could not be
+ /// inspected safely.
+ Unavailable,
+ /// The catalog request failed for another bounded, safe-to-summarize
+ /// reason.
+ Failure,
+ }
+
+ /// A catalog result is prepared before the doctor consults its cache. The
+ /// opaque identity captures the exact frozen credential and endpoint; the
+ /// lazy future captures those same values and is dropped on a cache hit.
+ ///
+ /// Fields are intentionally private and this type does not implement
+ /// `Debug`, `Serialize`, or `Display`, so credential identities cannot leak
+ /// through reports or logs.
+ pub struct PreparedInspectionCatalog {
+ identity: InspectionCatalogIdentity,
+ fetch: BoxFuture<Result<Outcome<serde_json::Value>, InspectionCatalogError>>,
+ }
+
++/// Host request state used to prepare a cache-safe catalog inspection.
++///
++/// Unlike a normal provider catalog request, inspection resolves credentials
++/// read-only and freezes them before the doctor checks its cache.
++#[derive(Clone)]
++pub struct InspectionCatalogRequest {
++ /// Provider-scoped key selected by the host, if any.
++ pub provider_key: String,
++ /// HTTP client configured by the host for this listing.
++ pub client: reqwest::Client,
++}
++
+ #[derive(Clone, Copy, PartialEq, Eq, Hash)]
+ pub(crate) struct InspectionCatalogIdentity(u64);
+
+ impl PreparedInspectionCatalog {
+ /// Creates a prepared request using a stable, process-keyed identity over
+ /// the provider, effective listing URL, and credential snapshot. The
+ /// fetch future must use the same credential snapshot passed here.
+ pub fn new(
+ provider_id: &str,
+ effective_listing_url: &str,
+ credential: Option<&str>,
+ fetch: BoxFuture<Result<Outcome<serde_json::Value>, InspectionCatalogError>>,
+ ) -> Self {
+ let normalized_url = reqwest::Url::parse(effective_listing_url)
+ .map(|url| url.to_string())
+ .unwrap_or_else(|_| effective_listing_url.to_owned());
+ let credential = credential
+ .map(str::trim)
+ .filter(|credential| !credential.is_empty());
+ static IDENTITY_HASHER: OnceLock<RandomState> = OnceLock::new();
+ let mut hasher = IDENTITY_HASHER.get_or_init(RandomState::new).build_hasher();
+ provider_id.hash(&mut hasher);
+ normalized_url.hash(&mut hasher);
+ credential.hash(&mut hasher);
+ Self {
+ identity: InspectionCatalogIdentity(hasher.finish()),
+ fetch,
+ }
+ }
+
+ pub(crate) fn identity(&self) -> InspectionCatalogIdentity {
+ self.identity
+ }
+
+ /// Runs the prepared request. Callers consult their cache before invoking
+ /// this method; dropping the value leaves the network future unpolled.
+ pub fn fetch(self) -> BoxFuture<Result<Outcome<serde_json::Value>, InspectionCatalogError>> {
+ self.fetch
+ }
+ }
+
+ /// An inspection-safe catalog preparer. It must read credentials without
+ /// refreshing, publishing expiry, or modifying profile state, then freeze the
+ /// credential into the returned request before the core checks its cache.
+ pub type InspectionCatalogListing = Arc<
+ dyn Fn(
+ Config,
- CatalogRequest,
++ InspectionCatalogRequest,
+ ) -> BoxFuture<Result<PreparedInspectionCatalog, InspectionCatalogError>>
+ + Send
+ + Sync,
+ >;
+
+ static INSPECTION_CATALOGS: HookSlot<InspectionCatalogListing> =
+ HookSlot::new("inference::inspection_catalogs");
+
+ /// Registers an inspection-safe catalog preparer for the whole process.
+ pub fn register_inspection_catalog(
+ provider_id: impl Into<String>,
+ listing: InspectionCatalogListing,
+ ) {
+ INSPECTION_CATALOGS.register(provider_id, listing);
+ }
+
+ /// Registers an inspection-safe catalog preparer for a context built from
+ /// `extensions`.
+ pub fn register_inspection_catalog_in(
+ extensions: &Extensions,
+ provider_id: impl Into<String>,
+ listing: InspectionCatalogListing,
+ ) {
+ INSPECTION_CATALOGS.register_in(extensions, provider_id, listing);
+ }
+
+ /// Removes a process-wide inspection-safe catalog preparer.
+ pub fn unregister_inspection_catalog(provider_id: &str) -> bool {
+ INSPECTION_CATALOGS.unregister(provider_id)
+ }
+
+ pub(crate) fn inspection_catalog(provider_id: &str) -> Option<InspectionCatalogListing> {
+ INSPECTION_CATALOGS.get(provider_id)
+ }
+
#[cfg(test)]
#[path = "registry_tests.rs"]
mod tests;
diff --cc crates/openhuman-core/src/inference/registry_tests.rs
index 495ae99858,0b43c58347..ff58761025
--- a/crates/openhuman-core/src/inference/registry_tests.rs
+++ b/crates/openhuman-core/src/inference/registry_tests.rs
@@@ -1,13 -1,11 +1,13 @@@
use super::*;
+use crate::inference::context_window::model_limits_request;
use crate::inference::provider::factory::{
- create_chat_model_from_string, make_openhuman_backend_model_for_thread, PROVIDER_OPENHUMAN,
- create_chat_model_from_string, make_openhuman_backend_model_for_thread, model_limits_request,
- PROVIDER_OPENHUMAN,
++ PROVIDER_OPENHUMAN, create_chat_model_from_string, make_openhuman_backend_model_for_thread,
};
use async_trait::async_trait;
--use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Mutex;
- use tinyinference_llm::model::discover::DiscoveryRequest;
++use std::sync::atomic::{AtomicUsize, Ordering};
+use tinyinference_llm::model::ChatModel;
++use tinyinference_llm::model::discover::DiscoveryRequest;
use tinyinference_llm::model::{ModelRequest, ModelResponse};
type SeenModelRequests = Arc<Mutex<Vec<(String, Option<String>, Option<String>)>>>;
@@@ -231,12 -201,8 +231,12 @@@ fn selecting_the_managed_provider_with_
#[tokio::test]
async fn a_registered_catalog_receives_the_entrys_provider_key() {
use crate::config::schema::cloud_providers::{AuthStyle, CloudProviderCreds};
-- use crate::config::schema::{EphemeralRoute, EPHEMERAL_ROUTE_SLUG};
++ use crate::config::schema::{EPHEMERAL_ROUTE_SLUG, EphemeralRoute};
let seen = Arc::new(Mutex::new(String::new()));
+ crate::config::schema::cloud_providers::register_hosted_cloud_provider_policy(
+ Arc::new(|slug| slug == EPHEMERAL_ROUTE_SLUG),
+ Arc::new(|style| style == AuthStyle::OpenhumanJwt),
+ );
let sink = Arc::clone(&seen);
register_catalog(
PROVIDER_OPENHUMAN,
@@@ -280,3 -236,3 +280,46 @@@
listing.unwrap();
assert_eq!(seen.lock().unwrap().as_str(), "entry-key");
}
++
++#[test]
++fn inspection_model_factory_uses_the_callers_context_before_process_fallback() {
++ use crate::core::slots::Extensions;
++ use crate::inference::registry::{
++ InspectionChatModelBuild, PreparedInspectionChatModelFactory,
++ register_inspection_chat_model, register_inspection_chat_model_in,
++ unregister_inspection_chat_model,
++ };
++
++ let _guard = crate::inference::inference_test_guard();
++ let factory = |endpoint: &'static str| -> PreparedInspectionChatModelFactory {
++ Arc::new(move |_| {
++ Ok(InspectionChatModelBuild {
++ model: Arc::new(FakeModel),
++ model_id: endpoint.to_owned(),
++ endpoint: format!("https://{endpoint}.example/v1"),
++ credential: format!("{endpoint}-credential"),
++ })
++ })
++ };
++ register_inspection_chat_model(PROVIDER_OPENHUMAN, factory("process"));
++ let a = Extensions::new();
++ register_inspection_chat_model_in(&a, PROVIDER_OPENHUMAN, factory("context-a"));
++ let b = Extensions::new();
++ register_inspection_chat_model_in(&b, PROVIDER_OPENHUMAN, factory("context-b"));
++
++ let config = Config::default();
++ let build_a = crate::inference::provider::factory::managed_backend::
++ managed_chat_model_build_for_inspection(Some(&a), "chat", &config, None)
++ .expect("context A inspection provider");
++ let build_b = crate::inference::provider::factory::managed_backend::
++ managed_chat_model_build_for_inspection(Some(&b), "chat", &config, None)
++ .expect("context B inspection provider");
++ let build_process = crate::inference::provider::factory::managed_backend::
++ managed_chat_model_build_for_inspection(None, "chat", &config, None)
++ .expect("process inspection provider");
++ unregister_inspection_chat_model(PROVIDER_OPENHUMAN);
++
++ assert_eq!(build_a.endpoint, "https://context-a.example/v1");
++ assert_eq!(build_b.endpoint, "https://context-b.example/v1");
++ assert_eq!(build_process.endpoint, "https://process.example/v1");
++}
diff --cc crates/openhuman-core/src/inference/schemas/settings_handlers.rs
index a7d10c0eb3,127e93b7e1..1a67452037
--- a/crates/openhuman-core/src/inference/schemas/settings_handlers.rs
+++ b/crates/openhuman-core/src/inference/schemas/settings_handlers.rs
@@@ -192,12 -288,12 +192,12 @@@ pub(super) fn handle_inference_update_l
}
pub(super) fn handle_inference_list_models(
-- _ctx: DispatchCtx,
++ ctx: DispatchCtx,
params: Map<String, Value>,
) -> ControllerFuture {
Box::pin(async move {
let request = deserialize_params::<InferenceListModelsParams>(params)?;
- to_json(crate::inference::ops::inference_list_models(&request.provider_id).await?)
- to_json(crate::inference::rpc::inference_list_models(&request.provider_id).await?)
++ to_json(crate::inference::ops::inference_list_models(&ctx, &request.provider_id).await?)
})
}
diff --cc crates/openhuman-core/src/web_chat/progress_bridge_attribution.rs
index 0000000000,c393395fd9..cd8ce211c0
mode 000000,100644..100644
--- a/crates/openhuman-core/src/web_chat/progress_bridge_attribution.rs
+++ b/crates/openhuman-core/src/web_chat/progress_bridge_attribution.rs
@@@ -1,0 -1,38 +1,37 @@@
+ /// Build the worktree-isolation slice of a `subagent_completed`
+ /// [`SubagentProgressDetail`] (#3376). An empty `changed_files` collapses to
+ /// `None` so the renderer omits an empty "changed files" list rather than
+ /// showing "0 files"; a non-empty list is forwarded verbatim. `worktree_path`
+ /// / `dirty_status` pass through (`None` for non-isolated workers). Split out
+ /// so the empty/non-empty branch is unit-testable without a live DB + channel.
+ fn subagent_worktree_detail(
+ worktree_path: Option<String>,
+ changed_files: Vec<String>,
+ dirty_status: Option<bool>,
+ ) -> SubagentProgressDetail {
+ SubagentProgressDetail {
+ worktree_path,
+ changed_files: if changed_files.is_empty() {
+ None
+ } else {
+ Some(changed_files)
+ },
+ dirty_status,
+ ..Default::default()
+ }
+ }
+
+ /// Trace user attribution for a turn whose stored user payload carries no identity
+ /// (headless / autonomous / freshly booted cores): read the on-disk
+ /// app-session profile and return the user's email (preferred) or backend
+ /// user id. `None` when signed out or the profile is unreadable.
+ fn session_profile_user_attribution(config: &crate::config::Config) -> Option<String> {
+ let state = crate::security::credentials::session_support::build_session_state(config).ok()?;
+ state
+ .user
+ .as_ref()
+ .and_then(|u| u.get("email"))
+ .and_then(serde_json::Value::as_str)
+ .map(str::to_string)
+ .or(state.user_id)
+ }
-
diff --cc crates/openhuman-embed/src/host_internals.rs
index 99d6585870,2f2b9ad451..4a0e80eabc
--- a/crates/openhuman-embed/src/host_internals.rs
+++ b/crates/openhuman-embed/src/host_internals.rs
@@@ -367,22 -378,19 +386,28 @@@ pub mod wallet_backend
/// Model-provider registries: chat models, embeddings, catalogs.
pub mod inference_registry {
pub use openhuman_core::inference::provider::factory::PROVIDER_OPENHUMAN;
- pub use openhuman_core::inference::provider::openhuman_backend_model::REASONING_OFF_METADATA_KEY;
pub use openhuman_core::inference::registry::{
- register_catalog, register_catalog_in, register_chat_model, register_chat_model_in,
- register_embedding, register_embedding_in, register_inspection_catalog,
- register_inspection_catalog_in, register_inspection_chat_model,
- register_inspection_chat_model_in, register_inspection_embedding,
- register_inspection_embedding_in, unregister_catalog, unregister_chat_model,
+ classify_backend_error, provider_default_model, provider_default_pricing,
+ provider_model_context_window, provider_model_is_alias, provider_model_is_raw,
+ provider_model_role, provider_model_supports_vision, provider_request_without_reasoning,
+ register_backend_error_classifier, register_backend_error_classifier_in, register_catalog,
+ register_catalog_in, register_chat_model, register_chat_model_in,
+ register_config_normalizer, register_config_normalizer_in, register_embedding,
- register_embedding_in, resolve_provider_model, unregister_backend_error_classifier,
- unregister_catalog, unregister_chat_model, unregister_embedding,
++ register_embedding_in, register_inspection_catalog, register_inspection_catalog_in,
++ register_inspection_chat_model, register_inspection_chat_model_in,
++ register_inspection_embedding, register_inspection_embedding_in, resolve_provider_model,
++ unregister_backend_error_classifier, unregister_catalog, unregister_chat_model,
+ unregister_embedding, unregister_inspection_catalog, unregister_inspection_chat_model,
+ BackendErrorClassification, BackendErrorClassifier, BackendErrorKind, CatalogCallContext,
- CatalogHostRequest, ConfigNormalizer, EmbeddingCallContext, ProviderContext,
++ CatalogHostRequest, ConfigNormalizer, EmbeddingCallContext, InspectionCatalogError,
++ InspectionCatalogListing, InspectionCatalogRequest, InspectionChatModelBuild, InspectionChatModelFactory,
++ InspectionEmbeddingFactory, PreparedInspectionCatalog,
++ PreparedInspectionChatModelFactory, ProviderContext,
+ };
+ pub use tinyinference_llm::providers::overrides::{
- BoxFuture, CatalogEntry, CatalogLimits, CatalogRequest, ChatModelEntry, ChatModelFactory,
- ChatModelRequest, EmbeddingFactory, EmbeddingRequest, ProviderModelMetadata,
- ProviderOverrides, ReadinessProbe,
+ BoxFuture, CatalogEntry, CatalogLimits, CatalogListing, CatalogRequest, ChatModelEntry,
+ ChatModelFactory, ChatModelRequest, EmbeddingFactory, EmbeddingRequest,
- InspectionCatalogError, InspectionCatalogListing, InspectionChatModelBuild,
- InspectionChatModelFactory, InspectionEmbeddingFactory, PreparedInspectionCatalog,
- PreparedInspectionChatModelFactory, ReadinessProbe,
++ ProviderModelMetadata, ProviderOverrides, ReadinessProbe,
};
}
diff --cc crates/openhuman-tinyhumans/src/inference/managed_catalog.rs
index 5b545d93cb,02a1869e11..98e1b0b908
--- a/crates/openhuman-tinyhumans/src/inference/managed_catalog.rs
+++ b/crates/openhuman-tinyhumans/src/inference/managed_catalog.rs
@@@ -10,7 -10,8 +10,9 @@@
use openhuman_embed::__host::config::Config;
use openhuman_embed::__host::core::Outcome;
use openhuman_embed::__host::inference_registry::{
- BoxFuture, CatalogEntry, CatalogHostRequest, CatalogLimits, CatalogRequest, ProviderContext,
- BoxFuture, CatalogEntry, CatalogLimits, CatalogListing, CatalogRequest, InspectionCatalogError,
- InspectionCatalogListing, PreparedInspectionCatalog,
++ BoxFuture, CatalogEntry, CatalogHostRequest, CatalogLimits, CatalogListing, CatalogRequest,
++ InspectionCatalogError, InspectionCatalogListing, InspectionCatalogRequest,
++ PreparedInspectionCatalog, ProviderContext,
};
use openhuman_embed::__host::security::credentials::session_support::{
classify_session_token, load_app_session_profile, publish_local_session_expiry,
@@@ -30,36 -32,114 +33,131 @@@ use crate::client::endpoint::
const MODELS_PATH: &str = "/openai/v1/models";
/// The registry entry for the managed catalog.
-pub(super) fn entry() -> CatalogEntry {
- let list: CatalogListing = Arc::new(
- |config: Config,
- request: CatalogRequest|
- -> BoxFuture<Result<Outcome<serde_json::Value>, String>> {
- Box::pin(async move { list_models(&config, request).await })
+pub(super) fn entry() -> CatalogEntry<ProviderContext> {
- let list = Arc::new(
++ let list: CatalogListing<ProviderContext> = Arc::new(
+ |request: CatalogRequest<ProviderContext>| -> BoxFuture<Result<serde_json::Value, String>> {
+ Box::pin(async move {
+ let context = request.context;
- let host = context.catalog.as_ref().expect("catalog host context");
++ let host = context
++ .catalog
++ .as_ref()
++ .expect("catalog host context");
+ let outcome = list_models(
+ &context.config,
+ CatalogHostRequest {
+ provider_key: host.request.provider_key.clone(),
+ client: host.request.client.clone(),
+ },
+ )
+ .await?;
+ host.logs
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .extend(outcome.logs);
+ Ok(outcome.value)
+ })
},
);
- let limits: CatalogLimits =
- Arc::new(|model: &str, config: &Config| limits_request(model, config));
+ let limits: CatalogLimits<ProviderContext> =
+ Arc::new(|model: &str, context: &ProviderContext| limits_request(model, &context.config));
CatalogEntry {
list,
limits: Some(limits),
}
}
+ /// Inspection-only variant: freezes a read-only session credential before
+ /// the core consults its cache. This deliberately does not call `list_models`
+ /// or any mutable session/catalog path.
+ pub(super) fn inspection_entry() -> InspectionCatalogListing {
- Arc::new(|config, request| {
++ Arc::new(|config: Config, request: InspectionCatalogRequest| {
+ Box::pin(async move {
+ use openhuman_embed::__host::security::credentials::session_support::{
+ check_session_backend, classify_session_token, load_app_session_profile_read_only,
+ SessionTokenCheck,
+ };
+
+ let profile = load_app_session_profile_read_only(&config)
+ .map_err(|_| InspectionCatalogError::Unavailable)?;
+ check_session_backend(&config, profile.as_ref())
+ .map_err(|_| InspectionCatalogError::Unavailable)?;
+ let session = match classify_session_token(profile.as_ref(), chrono::Utc::now()) {
+ SessionTokenCheck::Live(token) => Some(token),
+ SessionTokenCheck::Absent | SessionTokenCheck::Expired => None,
+ };
+ let provider_key = request.provider_key.trim();
+ let api_key = if provider_key.is_empty() {
+ openhuman_embed::__host::security::credentials::api_key::get_api_key_read_only(
+ &config,
+ )
+ .map_err(|_| InspectionCatalogError::Unavailable)?
+ } else {
+ Some(provider_key.to_owned())
+ };
+ let credential = session
+ .filter(|_| is_safe_endpoint_for_managed_bearer(&catalog_url(&config)))
+ .or_else(|| {
+ api_key.filter(|_| is_managed_endpoint_for_api_key(&catalog_url(&config)))
+ });
+ let url = catalog_url(&config);
+ if credential.is_none() {
+ return Err(InspectionCatalogError::Unavailable);
+ }
+ let client = request.client;
+ let frozen = credential.clone();
+ let fetch_url = url.clone();
+ let fetch = Box::pin(async move {
+ let mut get = client.get(&fetch_url);
+ if let Some(token) = frozen.as_deref() {
+ get = get.header("Authorization", format!("Bearer {token}"));
+ if let Ok(headers) = attribution_headers() {
+ get = get.headers(headers);
+ }
+ }
+ let response = get.send().await.map_err(|error| {
+ if error.is_timeout() {
+ InspectionCatalogError::Failure
+ } else {
+ InspectionCatalogError::Unavailable
+ }
+ })?;
+ let status = response.status();
+ if status == reqwest::StatusCode::NOT_FOUND {
+ return Err(InspectionCatalogError::NoCatalog);
+ }
+ if matches!(
+ status,
+ reqwest::StatusCode::UNAUTHORIZED | reqwest::StatusCode::FORBIDDEN
+ ) {
+ return Err(InspectionCatalogError::AuthOrAccess);
+ }
+ if !status.is_success() {
+ return Err(InspectionCatalogError::Failure);
+ }
+ let body = response
+ .json::<serde_json::Value>()
+ .await
+ .map_err(|_| InspectionCatalogError::Failure)?;
+ if body.get("error").is_some() {
+ return Err(InspectionCatalogError::Failure);
+ }
+ let models =
+ parse_models_response(&body).map_err(|_| InspectionCatalogError::Failure)?;
+ Ok(Outcome::new(
+ serde_json::json!({"models": models}),
+ Vec::new(),
+ ))
+ });
+ Ok(PreparedInspectionCatalog::new(
+ PROVIDER_OPENHUMAN,
+ &url,
+ credential.as_deref(),
+ fetch,
+ ))
+ })
+ })
+ }
+
fn empty_catalog(reason: &str) -> Result<Outcome<serde_json::Value>, String> {
Ok(Outcome::new(
serde_json::json!({ "models": Vec::<serde_json::Value>::new() }),
diff --cc crates/openhuman-tinyhumans/src/inference/managed_catalog_inspection_tests.rs
index 0000000000,eee4d681ab..0d79bde425
mode 000000,100644..100644
--- a/crates/openhuman-tinyhumans/src/inference/managed_catalog_inspection_tests.rs
+++ b/crates/openhuman-tinyhumans/src/inference/managed_catalog_inspection_tests.rs
@@@ -1,0 -1,414 +1,414 @@@
+ use super::super::inspection_entry;
+ use axum::{
+ extract::State,
+ http::{HeaderMap, StatusCode},
+ response::{IntoResponse, Response},
+ routing::get,
+ Json, Router,
+ };
+ use openhuman_embed::__host::config::Config;
+ use openhuman_embed::__host::inference_registry::{
- CatalogRequest, InspectionCatalogError, PreparedInspectionCatalog,
++ InspectionCatalogError, InspectionCatalogRequest, PreparedInspectionCatalog,
+ };
+ use openhuman_embed::__host::security::credentials::session_support::{
+ SESSION_EXPIRES_AT_META, SESSION_ISSUING_BACKEND_META,
+ };
+ use openhuman_embed::__host::security::credentials::{
+ APP_SESSION_PROVIDER, DEFAULT_AUTH_PROFILE_NAME,
+ };
+ use std::sync::{
+ atomic::{AtomicUsize, Ordering},
+ Arc,
+ };
+
+ fn with_backend_env_test_lock(future: impl std::future::Future<Output = ()>) {
+ let _env_lock = crate::backend::url::backend_env_test_lock();
+ tokio::runtime::Builder::new_current_thread()
+ .enable_all()
+ .build()
+ .expect("create current-thread test runtime")
+ .block_on(future);
+ }
+
+ #[derive(Clone)]
+ struct MockManagedCatalog {
+ status: StatusCode,
+ requests: Arc<AtomicUsize>,
+ authorization: Arc<std::sync::Mutex<Vec<Option<String>>>>,
+ }
+
+ async fn catalog_handler(State(state): State<MockManagedCatalog>, headers: HeaderMap) -> Response {
+ state.requests.fetch_add(1, Ordering::SeqCst);
+ state
+ .authorization
+ .lock()
+ .unwrap_or_else(|error| error.into_inner())
+ .push(
+ headers
+ .get("authorization")
+ .and_then(|value| value.to_str().ok())
+ .map(str::to_owned),
+ );
+ if state.status.is_success() {
+ Json(serde_json::json!({
+ "data": [{ "id": "managed-fixture-model", "owned_by": "openrouter" }]
+ }))
+ .into_response()
+ } else {
+ (
+ state.status,
+ Json(serde_json::json!({ "error": "managed fixture rejected the request" })),
+ )
+ .into_response()
+ }
+ }
+
+ async fn spawn_managed_backend(status: StatusCode) -> (String, MockManagedCatalog) {
+ let state = MockManagedCatalog {
+ status,
+ requests: Arc::new(AtomicUsize::new(0)),
+ authorization: Arc::new(std::sync::Mutex::new(Vec::new())),
+ };
+ let app = Router::new()
+ .route("/openai/v1/models", get(catalog_handler))
+ .with_state(state.clone());
+ let listener = tokio::net::TcpListener::bind("127.0.0.1:0")
+ .await
+ .expect("bind local managed-backend fixture");
+ let base = format!("http://127.0.0.1:{}", listener.local_addr().unwrap().port());
+ tokio::spawn(async move {
+ axum::serve(listener, app)
+ .await
+ .expect("serve local managed-backend fixture");
+ });
+ (base, state)
+ }
+
+ struct BackendEnvSnapshot {
+ backend_url: Option<std::ffi::OsString>,
+ vite_backend_url: Option<std::ffi::OsString>,
+ }
+
+ impl BackendEnvSnapshot {
+ fn set(base: &str) -> Self {
+ let snapshot = Self {
+ backend_url: std::env::var_os("BACKEND_URL"),
+ vite_backend_url: std::env::var_os("VITE_BACKEND_URL"),
+ };
+ std::env::set_var("BACKEND_URL", base);
+ std::env::remove_var("VITE_BACKEND_URL");
+ snapshot
+ }
+ }
+
+ impl Drop for BackendEnvSnapshot {
+ fn drop(&mut self) {
+ match self.backend_url.take() {
+ Some(value) => std::env::set_var("BACKEND_URL", value),
+ None => std::env::remove_var("BACKEND_URL"),
+ }
+ match self.vite_backend_url.take() {
+ Some(value) => std::env::set_var("VITE_BACKEND_URL", value),
+ None => std::env::remove_var("VITE_BACKEND_URL"),
+ }
+ }
+ }
+
+ fn temporary_config(base: &str) -> (tempfile::TempDir, Config) {
+ let root = tempfile::tempdir().expect("temporary managed-catalog fixture");
+ let mut config = Config {
+ config_path: root.path().join("config.toml"),
+ workspace_dir: root.path().join("workspace"),
+ action_dir: root.path().join("workspace"),
+ ..Config::default()
+ };
+ config.api_url = None;
+ config.secrets.encrypt = false;
+ config.resolved_endpoints.control_plane_url = Some(base.to_owned());
+ (root, config)
+ }
+
+ fn store_session(
+ config: &Config,
+ token: &str,
+ issuer: &str,
+ expires_at: chrono::DateTime<chrono::Utc>,
+ ) {
+ let mut metadata = std::collections::HashMap::new();
+ metadata.insert(SESSION_ISSUING_BACKEND_META.to_owned(), issuer.to_owned());
+ metadata.insert(SESSION_EXPIRES_AT_META.to_owned(), expires_at.to_rfc3339());
+ let profile_id = format!("{APP_SESSION_PROVIDER}:{DEFAULT_AUTH_PROFILE_NAME}");
+ let now = chrono::Utc::now().to_rfc3339();
+ let mut active_profiles = std::collections::HashMap::new();
+ active_profiles.insert(APP_SESSION_PROVIDER, profile_id.clone());
+ let mut profiles = std::collections::HashMap::new();
+ profiles.insert(
+ profile_id,
+ serde_json::json!({
+ "provider": APP_SESSION_PROVIDER,
+ "profile_name": DEFAULT_AUTH_PROFILE_NAME,
+ "kind": "token",
+ "token": token,
+ "metadata": metadata,
+ "created_at": now,
+ "updated_at": now,
+ }),
+ );
+ let document = serde_json::json!({
+ "schema_version": 1,
+ "updated_at": now,
+ "active_profiles": active_profiles,
+ "profiles": profiles,
+ });
+ std::fs::write(
+ auth_profiles_path(config),
+ serde_json::to_vec(&document).unwrap(),
+ )
+ .expect("seed read-only session profile fixture");
+ }
+
+ fn auth_profiles_path(config: &Config) -> std::path::PathBuf {
+ config
+ .config_path
+ .parent()
+ .expect("fixture config parent")
+ .join("auth-profiles.json")
+ }
+
+ async fn prepare_managed_catalog(
+ config: Config,
+ ) -> Result<PreparedInspectionCatalog, InspectionCatalogError> {
+ let inspect = inspection_entry();
+ inspect(
+ config,
- CatalogRequest {
++ InspectionCatalogRequest {
+ provider_key: String::new(),
+ client: reqwest::Client::new(),
+ },
+ )
+ .await
+ }
+
+ async fn inspect_managed_catalog(
+ config: Config,
+ ) -> Result<openhuman_embed::__host::core::Outcome<serde_json::Value>, InspectionCatalogError> {
+ prepare_managed_catalog(config).await?.fetch().await
+ }
+
+ #[test]
+ fn managed_inspection_catalog_lists_models_with_a_read_only_session() {
+ with_backend_env_test_lock(async {
+ let _registry = crate::registry_test_lock_async().await;
+ let (base, server) = spawn_managed_backend(StatusCode::OK).await;
+ let _env = BackendEnvSnapshot::set(&base);
+ let (_temp, config) = temporary_config(&base);
+ store_session(
+ &config,
+ "fixture-managed-session",
+ &base,
+ chrono::Utc::now() + chrono::Duration::hours(1),
+ );
+ let auth_file_before = std::fs::read(auth_profiles_path(&config)).expect("session fixture");
+
+ let result = inspect_managed_catalog(config.clone())
+ .await
+ .expect("managed inspection should list the catalog");
+
+ assert_eq!(result.value["models"][0]["id"], "managed-fixture-model");
+ assert_eq!(server.requests.load(Ordering::SeqCst), 1);
+ assert_eq!(
+ *server
+ .authorization
+ .lock()
+ .unwrap_or_else(|error| error.into_inner()),
+ vec![Some("Bearer fixture-managed-session".to_owned())]
+ );
+ assert_eq!(
+ std::fs::read(auth_profiles_path(&config)).unwrap(),
+ auth_file_before
+ );
+ });
+ }
+
+ #[test]
+ fn managed_inspection_catalog_classifies_a_401_without_mutating_credentials() {
+ with_backend_env_test_lock(async {
+ let _registry = crate::registry_test_lock_async().await;
+ let (base, server) = spawn_managed_backend(StatusCode::UNAUTHORIZED).await;
+ let _env = BackendEnvSnapshot::set(&base);
+ let (_temp, config) = temporary_config(&base);
+ store_session(
+ &config,
+ "fixture-managed-session",
+ &base,
+ chrono::Utc::now() + chrono::Duration::hours(1),
+ );
+ let auth_file_before = std::fs::read(auth_profiles_path(&config)).expect("session fixture");
+
+ let error = inspect_managed_catalog(config.clone())
+ .await
+ .expect_err("a managed-catalog 401 is an auth/access result");
+
+ assert!(matches!(error, InspectionCatalogError::AuthOrAccess));
+ assert_eq!(server.requests.load(Ordering::SeqCst), 1);
+ assert_eq!(
+ std::fs::read(auth_profiles_path(&config)).unwrap(),
+ auth_file_before
+ );
+ });
+ }
+
+ #[test]
+ fn a_prepared_managed_fetch_uses_the_frozen_session_after_rotation() {
+ with_backend_env_test_lock(async {
+ let _registry = crate::registry_test_lock_async().await;
+ let (base, server) = spawn_managed_backend(StatusCode::OK).await;
+ let _env = BackendEnvSnapshot::set(&base);
+ let (_temp, config) = temporary_config(&base);
+ store_session(
+ &config,
+ "fixture-session-before-rotation",
+ &base,
+ chrono::Utc::now() + chrono::Duration::hours(1),
+ );
+ let auth_file_a_before =
+ std::fs::read(auth_profiles_path(&config)).expect("session A fixture");
+
+ let prepared_a = prepare_managed_catalog(config.clone())
+ .await
+ .expect("read-only prepare should capture session A");
+ assert_eq!(
+ std::fs::read(auth_profiles_path(&config)).unwrap(),
+ auth_file_a_before,
+ "preparing A must not rewrite auth state"
+ );
+ store_session(
+ &config,
+ "fixture-session-after-rotation",
+ &base,
+ chrono::Utc::now() + chrono::Duration::hours(1),
+ );
+ let auth_file_after_rotation =
+ std::fs::read(auth_profiles_path(&config)).expect("rotated session fixture");
+
+ prepared_a
+ .fetch()
+ .await
+ .expect("the prepared request must use its captured session");
+ assert_eq!(
+ std::fs::read(auth_profiles_path(&config)).unwrap(),
+ auth_file_after_rotation,
+ "fetching frozen A must not change the newly stored B credential"
+ );
+ let prepared_b = prepare_managed_catalog(config.clone())
+ .await
+ .expect("a new prepare should see session B");
+ assert_eq!(
+ std::fs::read(auth_profiles_path(&config)).unwrap(),
+ auth_file_after_rotation,
+ "preparing B must not rewrite auth state"
+ );
+ prepared_b
+ .fetch()
+ .await
+ .expect("the second prepared request should use session B");
+ assert_eq!(
+ std::fs::read(auth_profiles_path(&config)).unwrap(),
+ auth_file_after_rotation,
+ "fetching frozen B must not rewrite auth state"
+ );
+
+ assert_eq!(server.requests.load(Ordering::SeqCst), 2);
+ assert_eq!(
+ *server
+ .authorization
+ .lock()
+ .unwrap_or_else(|error| error.into_inner()),
+ vec![
+ Some("Bearer fixture-session-before-rotation".to_owned()),
+ Some("Bearer fixture-session-after-rotation".to_owned())
+ ]
+ );
+ assert_eq!(
+ std::fs::read(auth_profiles_path(&config)).unwrap(),
+ auth_file_after_rotation
+ );
+ });
+ }
+
+ #[test]
+ fn a_session_from_another_backend_is_never_sent_to_the_managed_catalog() {
+ with_backend_env_test_lock(async {
+ let _registry = crate::registry_test_lock_async().await;
+ let (base, server) = spawn_managed_backend(StatusCode::OK).await;
+ let _env = BackendEnvSnapshot::set(&base);
+ let (_temp, config) = temporary_config(&base);
+ store_session(
+ &config,
+ "fixture-session-issued-elsewhere",
+ "http://issuer-a.example",
+ chrono::Utc::now() + chrono::Duration::hours(1),
+ );
+ let auth_file_before = std::fs::read(auth_profiles_path(&config)).expect("session fixture");
+
+ let result = inspect_managed_catalog(config.clone()).await;
+
+ assert!(
+ result.is_err(),
+ "a foreign session must not pass inspection"
+ );
+ assert_eq!(server.requests.load(Ordering::SeqCst), 0);
+ assert_eq!(
+ std::fs::read(auth_profiles_path(&config)).unwrap(),
+ auth_file_before
+ );
+ });
+ }
+
+ #[test]
+ fn an_expired_session_is_skipped_without_broadcast_or_store_mutation() {
+ use openhuman_embed::__host::core::events::DomainEvent;
+
+ with_backend_env_test_lock(async {
+ let _registry = crate::registry_test_lock_async().await;
+ openhuman_embed::__host::core::bus::init()
+ .await
+ .expect("event bus init");
+ let mut events = openhuman_embed::__host::core::bus::BUS
+ .get()
+ .expect("event bus initialized")
+ .receiver();
+ while events.try_recv().is_ok() {}
+
+ let (base, server) = spawn_managed_backend(StatusCode::OK).await;
+ let _env = BackendEnvSnapshot::set(&base);
+ let (_temp, config) = temporary_config(&base);
+ store_session(
+ &config,
+ "fixture-expired-session",
+ &base,
+ chrono::Utc::now() - chrono::Duration::hours(1),
+ );
+ let auth_file_before = std::fs::read(auth_profiles_path(&config)).expect("session fixture");
+
+ let result = inspect_managed_catalog(config.clone()).await;
+
+ assert!(matches!(result, Err(InspectionCatalogError::Unavailable)));
+ assert_eq!(server.requests.load(Ordering::SeqCst), 0);
+ assert_eq!(
+ std::fs::read(auth_profiles_path(&config)).unwrap(),
+ auth_file_before
+ );
+ let published_expiry = std::iter::from_fn(|| events.try_recv().ok()).any(|event| {
+ matches!(
+ event,
+ DomainEvent::SessionExpired { source, .. }
+ if source == "credentials.local_expiry_precheck"
+ )
+ });
+ assert!(
+ !published_expiry,
+ "inspection must not broadcast local expiry"
+ );
+ });
+ }
diff --cc crates/openhuman-tinyhumans/src/inference/managed_catalog_tests.rs
index 588169533a,f8fab61a70..31b74368c6
--- a/crates/openhuman-tinyhumans/src/inference/managed_catalog_tests.rs
+++ b/crates/openhuman-tinyhumans/src/inference/managed_catalog_tests.rs
@@@ -135,74 -94,6 +135,78 @@@ fn with_neither_credential_the_catalog_
);
}
+#[tokio::test]
+async fn managed_catalog_treats_http_401_as_signed_out_only_for_an_attached_session() {
+ let (base_url, authorization) =
+ catalog_server(StatusCode::UNAUTHORIZED, "session token rejected").await;
+ let tmp = TempDir::new().unwrap();
+ let config = catalog_config(&tmp, &base_url);
+ crate::hosted::test_support::store_session(&config, "fixture-live-session");
+
+ let result = list_models(
+ &config,
+ CatalogHostRequest {
+ provider_key: String::new(),
+ client: reqwest::Client::new(),
+ },
+ )
+ .await
+ .expect("a rejected attached session degrades to an empty catalog");
+
+ assert_eq!(result.value["models"], serde_json::json!([]));
+ assert_eq!(
+ authorization.lock().unwrap().as_slice(),
+ [Some("Bearer fixture-live-session".to_string())]
+ );
+}
+
+#[tokio::test]
+async fn managed_catalog_keeps_provider_key_401_as_a_provider_error() {
+ let (base_url, authorization) =
+ catalog_server(StatusCode::UNAUTHORIZED, "provider key rejected").await;
+ let tmp = TempDir::new().unwrap();
+ let config = catalog_config(&tmp, &base_url);
+ without_session(&config);
+
+ let error = list_models(
+ &config,
+ CatalogHostRequest {
+ provider_key: "fixture-provider-key".into(),
+ client: reqwest::Client::new(),
+ },
+ )
+ .await
+ .expect_err("a 401 for a provider key remains actionable");
+
+ assert!(error.contains("provider returned 401"), "{error}");
+ assert_eq!(
+ authorization.lock().unwrap().as_slice(),
+ [Some("Bearer fixture-provider-key".to_string())]
+ );
+}
+
+#[tokio::test]
+async fn managed_catalog_does_not_infer_http_status_from_error_payload_text() {
+ let (base_url, _authorization) =
+ catalog_server(StatusCode::OK, r#"{"error":"401 session expired"}"#).await;
+ let tmp = TempDir::new().unwrap();
+ let config = catalog_config(&tmp, &base_url);
+ crate::hosted::test_support::store_session(&config, "fixture-live-session");
+
+ let error = list_models(
+ &config,
+ CatalogHostRequest {
+ provider_key: String::new(),
+ client: reqwest::Client::new(),
+ },
+ )
+ .await
+ .expect_err("a successful error envelope is not an HTTP 401");
+
+ assert!(error.contains("provider returned error payload"), "{error}");
+ assert!(error.contains("401 session expired"), "{error}");
+}
++
+ #[cfg(test)]
+ #[path = "managed_catalog_inspection_tests.rs"]
+ mod inspection_tests;
diff --cc crates/openhuman-tinyhumans/src/inference/managed_embedding.rs
index 9fb1d922ed,3ff3f7e4cf..64cd0d0be0
--- a/crates/openhuman-tinyhumans/src/inference/managed_embedding.rs
+++ b/crates/openhuman-tinyhumans/src/inference/managed_embedding.rs
@@@ -15,80 -13,189 +15,114 @@@ use super::managed_session::resolve_ses
use crate::backend::url::effective_api_url;
use crate::client::endpoint::is_managed_endpoint_for_api_key;
-/// Host-owned credential resolution and egress disclosure around the
-/// crate-owned cloud transport.
-///
-/// The egress guard (policy check, then the `ExternalTransferPending`
-/// disclosure) runs before the batch reaches the transport, so it can carry the
-/// chat of the turn that made the call. One built without a chat (background
-/// sync, the embedding RPC) still discloses, unrouted.
-pub struct ManagedEmbeddingModel {
- inner: Arc<CloudEmbeddingModel>,
- model: String,
- chat: Option<ApprovalChatContext>,
+/// Builds the owning cloud embedding implementation with the credential scope
+/// and turn context supplied by the inference registry.
+pub(super) fn from_request(request: &EmbeddingRequest<'_, ProviderContext>) -> CloudEmbeddingModel {
+ let context = request
+ .context
+ .embedding
+ .as_ref()
+ .expect("embedding host context");
+ build_cloud_model(
+ context
+ .config
+ .as_ref()
+ .and_then(|config| config.api_url.clone()),
+ context.state_dir.clone(),
+ context.secrets_encrypt,
+ request.model,
+ request.dimensions,
+ context.chat.clone(),
++ None,
+ )
}
-impl ManagedEmbeddingModel {
- /// Builds the embedder for the credential scope `request` carries.
- pub fn from_request(request: &EmbeddingRequest<'_>) -> Self {
- Self::new(
- request.config.and_then(|config| config.api_url.clone()),
- request.state_dir.clone(),
- request.secrets_encrypt,
- request.model,
- request.dimensions,
- request.chat.clone(),
++pub(super) fn from_request_for_inspection(
++ request: &EmbeddingRequest<'_, ProviderContext>,
++) -> tinyinference_embeddings::Result<CloudEmbeddingModel> {
++ let context = request
++ .context
++ .embedding
++ .as_ref()
++ .expect("embedding host context");
++ let config = context.config.as_ref().ok_or_else(|| {
++ tinyinference_embeddings::Error::Validation(
++ "selected managed embedding config is unavailable".to_owned(),
+ )
- }
-
- /// Builds an inspection model with a frozen bearer from the selected
- /// profile. The normal credential store is never consulted at embed time.
- pub fn from_request_for_inspection(
- request: &EmbeddingRequest<'_>,
- ) -> tinyinference_embeddings::Result<Self> {
- let config = request.config.ok_or_else(|| {
- tinyinference_embeddings::Error::Validation(
- "selected managed embedding config is unavailable".to_owned(),
- )
- })?;
- let bearer =
- super::managed_session::managed_bearer_for_inspection(config).map_err(|_| {
- tinyinference_embeddings::Error::Validation(
- "selected managed embedding credential is unavailable".to_owned(),
- )
- })?;
- Ok(Self::new_with_bearer(
- config.api_url.clone(),
- bearer,
- request.model,
- request.dimensions,
- None,
- ))
- }
-
- /// Builds the embedder against `api_url` (or the default backend) with
- /// credentials read from `state_dir`.
- pub fn new(
- api_url: Option<String>,
- state_dir: std::path::PathBuf,
- secrets_encrypt: bool,
- model: &str,
- dimensions: usize,
- chat: Option<ApprovalChatContext>,
- ) -> Self {
- let base_url = format!(
- "{}/openai/v1",
- effective_api_url(&api_url).trim_end_matches('/')
- );
- let key_endpoint = base_url.clone();
- let bearer: BearerResolver = Arc::new(move || {
- // A stored TinyHumans API key is the bearer outright, with the
- // plaintext guard: never put the key on a non-HTTPS, non-loopback wire.
- if let Some(key) =
- openhuman_embed::__host::security::credentials::api_key::get_api_key_in(
- &state_dir,
- secrets_encrypt,
- )
- .map_err(|error| tinyinference_embeddings::Error::Embedding(error.to_string()))?
- {
- if !is_managed_endpoint_for_api_key(&key_endpoint) {
- return Err(tinyinference_embeddings::Error::Validation(format!(
- "refusing to send the TinyHumans API key over a non-HTTPS, non-loopback \
- endpoint: {key_endpoint}"
- )));
- }
- log::debug!("[tinyhumans][embeddings] authenticating with api-key");
- return Ok(key);
- }
- let auth = AuthService::new(&state_dir, secrets_encrypt);
- auth.get_provider_bearer_token(APP_SESSION_PROVIDER, None)
- .map_err(|error| tinyinference_embeddings::Error::Embedding(error.to_string()))?
- .filter(|token| !token.trim().is_empty())
- .ok_or_else(|| {
- tinyinference_embeddings::Error::Validation(
- "No backend session for cloud embeddings: log in to OpenHuman or set a \
- TinyHumans API key"
- .into(),
- )
- })
- });
- let model = model.to_string();
- Self {
- inner: Arc::new(CloudEmbeddingModel::new(
- base_url,
- model.clone(),
- dimensions,
- bearer,
- )),
- model,
- chat,
- }
- }
++ })?;
++ let bearer = super::managed_session::managed_bearer_for_inspection(config).map_err(|_| {
++ tinyinference_embeddings::Error::Validation(
++ "selected managed embedding credential is unavailable".to_owned(),
++ )
++ })?;
++ Ok(build_cloud_model(
++ config.api_url.clone(),
++ context.state_dir.clone(),
++ context.secrets_encrypt,
++ request.model,
++ request.dimensions,
++ None,
++ Some(bearer),
++ ))
++}
+
- fn new_with_bearer(
- api_url: Option<String>,
- bearer_value: String,
- model: &str,
- dimensions: usize,
- chat: Option<ApprovalChatContext>,
- ) -> Self {
- let base_url = format!(
- "{}/openai/v1",
- effective_api_url(&api_url).trim_end_matches('/')
- );
- let bearer: BearerResolver = Arc::new(move || Ok(bearer_value.clone()));
- let model = model.to_owned();
- Self {
- inner: Arc::new(CloudEmbeddingModel::new(
- base_url,
- model.clone(),
- dimensions,
- bearer,
- )),
- model,
- chat,
+fn build_cloud_model(
+ api_url: Option<String>,
+ state_dir: std::path::PathBuf,
+ secrets_encrypt: bool,
+ model: &str,
+ dimensions: usize,
+ chat: Option<ApprovalChatContext>,
++ frozen_bearer: Option<String>,
+) -> CloudEmbeddingModel {
+ let base_url = format!(
+ "{}/openai/v1",
+ effective_api_url(&api_url).trim_end_matches('/')
+ );
+ let key_endpoint = base_url.clone();
+ let bearer: BearerResolver = Arc::new(move || {
++ if let Some(bearer) = frozen_bearer.as_ref() {
++ return Ok(bearer.clone());
+ }
- }
-
- /// This embedder with its egress disclosures routed to `chat` (the turn's
- /// thread and client); `None` leaves them unrouted. Shares the transport,
- /// so it is cheap to do per turn.
- #[cfg(test)]
- #[must_use]
- pub fn routed_to(&self, chat: Option<ApprovalChatContext>) -> Self {
- Self {
- inner: Arc::clone(&self.inner),
- model: self.model.clone(),
- chat,
+ // A stored TinyHumans API key is the bearer outright, with the
+ // plaintext guard: never put the key on a non-HTTPS, non-loopback wire.
+ if let Some(key) = openhuman_embed::__host::security::credentials::api_key::get_api_key_in(
+ &state_dir,
+ secrets_encrypt,
+ )
+ .map_err(|error| tinyinference_embeddings::Error::Embedding(error.to_string()))?
+ {
+ if !is_managed_endpoint_for_api_key(&key_endpoint) {
+ return Err(tinyinference_embeddings::Error::Validation(format!(
+ "refusing to send the TinyHumans API key over a non-HTTPS, non-loopback \
+ endpoint: {}",
+ super::managed_model::endpoint_origin_for_log(&key_endpoint)
+ )));
+ }
+ log::debug!("[tinyhumans][embeddings] authenticating with api-key");
+ return Ok(key);
}
- }
+ resolve_session_bearer(
+ &state_dir,
+ secrets_encrypt,
+ None,
+ "managed_embedding.resolve_bearer",
+ )
+ .map_err(|error| tinyinference_embeddings::Error::Embedding(error.to_string()))
+ });
- fn guard(&self) -> tinyinference_embeddings::Result<()> {
- let egress = EgressDescriptor::embedding("cloud", &self.model);
+ let guarded_model = model.to_owned();
+ let guarded_chat = chat;
+ let egress_guard: EmbeddingEgressGuard = Arc::new(move |_, _| {
+ let egress = EgressDescriptor::embedding("cloud", &guarded_model);
enforce_egress(&egress)
.map_err(|error| tinyinference_embeddings::Error::Embedding(error.to_string()))?;
- emit_external_transfer(self.chat.as_ref(), egress);
+ emit_external_transfer(guarded_chat.as_ref(), egress);
Ok(())
- }
-}
+ });
-#[async_trait::async_trait]
-impl EmbeddingModel for ManagedEmbeddingModel {
- fn name(&self) -> &str {
- self.inner.name()
- }
-
- fn model_id(&self) -> &str {
- self.inner.model_id()
- }
-
- fn dimensions(&self) -> usize {
- self.inner.dimensions()
- }
-
- fn signature(&self) -> String {
- self.inner.signature()
- }
-
- async fn embed(&self, texts: &[String]) -> tinyinference_embeddings::Result<Vec<Vec<f32>>> {
- // Only a batch that will actually leave is guarded: an empty one answers
- // locally, and a blank input is refused by the transport.
- if !texts.is_empty() && texts.iter().all(|text| !text.trim().is_empty()) {
- self.guard()?;
- }
- self.inner.embed(texts).await
- }
+ CloudEmbeddingModel::new(base_url, model.to_owned(), dimensions, bearer)
+ .with_egress_guard(egress_guard)
}
#[cfg(test)]
diff --cc crates/openhuman-tinyhumans/src/inference/managed_model.rs
index 6b552a137a,a553c17d73..5e45756458
--- a/crates/openhuman-tinyhumans/src/inference/managed_model.rs
+++ b/crates/openhuman-tinyhumans/src/inference/managed_model.rs
@@@ -54,84 -165,241 +54,110 @@@ impl ManagedOptions
);
return Ok(key);
}
- if openhuman_embed::__host::platform::llm_gate::is_signed_out() {
- anyhow::bail!(
- "SESSION_EXPIRED: backend session not active — sign in to resume LLM work"
- );
- }
- let auth = AuthService::new(&self.state_dir(), self.options.secrets_encrypt);
- let profile = auth.get_profile(
- APP_SESSION_PROVIDER,
- self.options.auth_profile_override.as_deref(),
- )?;
-
- // #5503: precheck the recorded JWT `exp` BEFORE building a request, the
- // same way `require_live_session_token` guards the backend REST callers.
- // Managed inference used to fire a doomed request on an expired-but-
- // stored token and let the 401 come back — but an expired session can
- // also surface upstream as a misleading "model unavailable", which is a
- // core symptom of #5503 (all tiers "die" over a long session). Failing
- // fast as `session_expired` routes the user to re-auth instead.
- managed_bearer(classify_session_token(profile.as_ref(), chrono::Utc::now()))
- }
-
- /// The managed OpenAI-compatible endpoint, from the configured `api_url`
- /// override or this crate's backend URL defaults.
- pub(super) fn base_url(&self) -> anyhow::Result<String> {
- let base = effective_api_url(&self.api_url);
- Ok(format!("{}/openai/v1", base.trim_end_matches('/')))
- }
-
- /// Resolve the current JWT + base URL and build a fresh crate `OpenAiModel`
- /// (Bearer). Rebuilt per call because the session JWT rotates, but every
- /// build shares one pooled HTTP client ([`managed_inference_http_client`]),
- /// so consecutive calls reuse a warm TLS connection to the backend.
- pub(super) fn build_wire_model(&self) -> tinyinference_llm::Result<OpenAiModel> {
- let token = self
- .resolve_bearer()
- .map_err(|e| TiError::Model(e.to_string()))?;
- let base_url = self.base_url().map_err(|e| TiError::Model(e.to_string()))?;
- // The hosted API is chat-completions only (no `/v1/responses`); auth is a
- // plain bearer JWT. The tier/model rides `request.model`, which the backend
- // resolves — the baked default only applies when a request omits it.
- Ok(
- OpenAiModel::compatible_provider(PROVIDER_LABEL, token, base_url, &self.default_model)
- .with_native_tool_calling(self.native_tool_calling)
- .with_request_options(ProviderRequestOptions {
- http: Some(managed_inference_http_client()),
- ..ProviderRequestOptions::default()
- }),
+ resolve_session_bearer(
+ &self.state_dir(),
+ self.secrets_encrypt,
+ self.auth_profile_override.as_deref(),
+ "openhuman_backend_model.resolve_bearer",
)
}
-
- /// Probe whether the managed backend account actually has a working
- /// inference provider configured, cheaply and without inflating usage
- /// (issue B45 — flows provider-connectivity author gate).
- ///
- /// [`build_wire_model`](Self::build_wire_model) only resolves the session
- /// JWT and builds the request client — it says nothing about whether the
- /// account has a provider API key configured server-side. That only
- /// surfaces on a real completion attempt, as an HTTP 400
- /// `{"success":false,"error":"API key not configured for provider","errorCode":"BAD_REQUEST"}`.
- /// Previously the first time a flows author found this out was mid-run,
- /// deep inside a tinyflows `agent` node. This probe moves that discovery
- /// to author time by issuing one minimal completion (`"ping"`,
- /// `max_tokens: 1`) and classifying the result.
- ///
- /// Fails OPEN on everything except a definitive client-configuration
- /// error: a 5-second timeout, a transport failure, a 5xx, or any other
- /// non-matching provider error all return `Ok(())` so a flaky backend or
- /// slow network never blocks authoring. Only a backend-confirmed "no
- /// provider configured for this account" response returns `Err` —
- /// carrying the backend's own error string so the author sees exactly
- /// what run time would have shown them.
- pub async fn probe_readiness(&self) -> Result<(), String> {
- log::debug!(
- "[flows][inference-probe] entering probe_readiness model={}",
- self.default_model
- );
-
- let model = match self.build_wire_model() {
- Ok(model) => model,
- Err(e) => {
- // The flows readiness gate's Layer 1 (sign-in / session
- // checks) is responsible for catching a genuinely
- // absent/expired session before this ever runs — a
- // construction failure reaching here is a race, not a
- // provider-configuration problem, so fail open rather than
- // duplicate or contradict that gate's message.
- log::debug!(
- "[flows][inference-probe] wire model construction failed, failing open: {e}"
- );
- return Ok(());
- }
- };
-
- let request = ModelRequest::new(vec![Message::user("ping")]).with_max_tokens(1);
-
- let outcome =
- match tokio::time::timeout(Duration::from_secs(5), model.invoke(&(), request)).await {
- Ok(result) => result,
- Err(_) => {
- log::debug!(
- "[flows][inference-probe] model={} timed out after 5s, failing open",
- self.default_model
- );
- return Ok(());
- }
- };
-
- match outcome {
- Ok(_) => {
- log::debug!(
- "[flows][inference-probe] model={} probe completion succeeded — provider ready",
- self.default_model
- );
- Ok(())
- }
- Err(TiError::Provider(err)) => {
- if is_provider_not_configured_error(&err) {
- log::warn!(
- "[flows][inference-probe] model={} backend reports no provider configured: {}",
- self.default_model,
- err.message
- );
- Err(err.message.clone())
- } else if err.status.is_some_and(|status| status >= 500) {
- log::debug!(
- "[flows][inference-probe] model={} backend {:?}, failing open: {}",
- self.default_model,
- err.status,
- err.message
- );
- Ok(())
- } else {
- // Any other structured provider failure (401, 429, a
- // malformed request, …) is not the definitive "provider
- // not configured" signal this probe exists to catch —
- // fail open rather than risk a false-positive
- // author-time block.
- log::debug!(
- "[flows][inference-probe] model={} non-definitive provider error {:?}, \
- failing open: {}",
- self.default_model,
- err.status,
- err.message
- );
- Ok(())
- }
- }
- Err(e) => {
- log::debug!(
- "[flows][inference-probe] model={} transport/model error, failing open: {e}",
- self.default_model
- );
- Ok(())
- }
- }
- }
}
-/// Whether `err` is the definitive "no inference provider configured for this
-/// account" signal the managed backend returns as an HTTP 400 with body
-/// `{"success":false,"error":"API key not configured for provider","errorCode":"BAD_REQUEST"}`.
-///
-/// Deliberately narrow: matches ONLY a 400 whose message contains the specific
-/// `"api key not configured for provider"` phrasing, or (as a `BAD_REQUEST`-
-/// coded tolerance for message wording drift) the narrower `"not configured
-/// for provider"` substring — never a bare `"not configured"`, which an
-/// unrelated 400 (a malformed request naming some other unconfigured field,
-/// a validation error, …) could also contain. Every other 4xx/5xx/transport
-/// failure fails open (see [`OpenHumanBackendModel::probe_readiness`]'s doc).
-fn is_provider_not_configured_error(err: &ProviderError) -> bool {
- if err.status != Some(400) {
- return false;
- }
- let message = err.message.to_ascii_lowercase();
- let code_is_bad_request = err
- .code
- .as_deref()
- .is_some_and(|c| c.eq_ignore_ascii_case("BAD_REQUEST"));
- message.contains("api key not configured for provider")
- || (code_is_bad_request && message.contains("not configured for provider"))
+/// Returns only a URL origin for diagnostics, never userinfo, path, query, or
+/// fragment data. Invalid and opaque URLs use a constant placeholder.
+pub(super) fn endpoint_origin_for_log(endpoint: &str) -> String {
+ url::Url::parse(endpoint)
+ .ok()
+ .map(|url| url.origin().ascii_serialization())
+ .filter(|origin| origin != "null")
+ .unwrap_or_else(|| "<invalid endpoint>".to_string())
}
-fn resolve_model(model: &str) -> String {
- let trimmed = model.trim();
- if trimmed.is_empty() {
- log::debug!(
- "[providers][openhuman-backend] empty model passed to OpenHuman backend; \
- substituting default `{}` (TAURI-RUST-RS)",
- openhuman_embed::__host::config::MODEL_MANAGED_DEFAULT
- );
- openhuman_embed::__host::config::MODEL_MANAGED_DEFAULT.to_string()
- } else {
- trimmed.to_string()
+/// Constructs the owning TinyInference model with OpenHuman's rotating
+/// credential source and host-specific connection policy.
+pub(super) fn build_chat_model(
+ api_url: Option<&str>,
+ options: &ManagedOptions,
+ model: &str,
+ native_tool_calling: bool,
+ thread_id: Option<&str>,
+ observe_auth_failures: bool,
+) -> anyhow::Result<TinyHumansModel> {
+ let endpoint = effective_api_url(&api_url.map(str::to_owned));
+ let resolver_options = options.clone();
+ let resolver_endpoint = endpoint.clone();
+ let mut managed = TinyHumansModel::new(
+ endpoint,
+ model,
+ super::tiers::MODEL_MANAGED_DEFAULT,
+ move || {
+ resolver_options
+ .resolve_bearer(&resolver_endpoint)
+ .map_err(|error| tinyinference_llm::Error::Model(error.to_string()))
+ },
+ )?
+ .with_cache_namespace("openhuman")
+ .with_native_tool_calling(native_tool_calling)
+ .with_thread_id(thread_id)
+ .with_error_observer(log_managed_error);
+
+ if observe_auth_failures {
+ managed = managed.with_managed_auth_failure_handler(|error, context| {
+ publish_managed_auth_failure(error, context);
+ });
}
+ Ok(managed)
}
-/// Connect timeout for the shared managed-inference client; matches the
-/// adapter's own default.
-const MANAGED_INFERENCE_CONNECT_TIMEOUT: Duration = Duration::from_secs(30);
-
-/// How long an idle pooled connection is kept. Below the AWS ALB's default 60s
-/// idle timeout in front of the backend, so the pool never hands out a
-/// connection the load balancer has already closed.
-const MANAGED_INFERENCE_POOL_IDLE_TIMEOUT: Duration = Duration::from_secs(50);
++/// Constructs the native managed model with a credential read once from the
++/// doctor's read-only snapshot. The closure passed to TinyInference can only
++/// return that frozen value; this path installs no mutable session-expiry hook.
++pub(super) fn build_chat_model_for_inspection(
++ api_url: Option<&str>,
++ model: &str,
++ bearer: String,
++ native_tool_calling: bool,
++ thread_id: Option<&str>,
++) -> anyhow::Result<TinyHumansModel> {
++ let endpoint = effective_api_url(&api_url.map(str::to_owned));
++ let managed = TinyHumansModel::new(
++ endpoint,
++ model,
++ super::tiers::MODEL_MANAGED_DEFAULT,
++ move || Ok(bearer.clone()),
++ )?
++ .with_cache_namespace("openhuman")
++ .with_native_tool_calling(native_tool_calling)
++ .with_thread_id(thread_id)
++ .with_error_observer(log_managed_error);
++ // Do not attach `with_managed_auth_failure_handler`: inspection must not
++ // publish expiry state or mutate the selected credential profile.
++ Ok(managed)
++}
+
-/// The one HTTP client every managed-inference call in the process shares.
-///
-/// `OpenAiModel` otherwise builds its own `reqwest::Client` per instance, and
-/// [`OpenHumanBackendModel::build_wire_model`] builds an instance per model
-/// call, so each call paid a fresh TCP + TLS handshake to the backend (about
-/// 150-300 ms measured to `api.tinyhumans.ai`) before its first token. A
-/// `reqwest::Client` is a cheap handle over a shared connection pool, so
-/// cloning it keeps connections warm across calls, turns and threads.
-fn managed_inference_http_client() -> reqwest::Client {
- static CLIENT: std::sync::OnceLock<reqwest::Client> = std::sync::OnceLock::new();
- CLIENT
- .get_or_init(|| {
- tracing::debug!(
- idle_timeout_secs = MANAGED_INFERENCE_POOL_IDLE_TIMEOUT.as_secs(),
- "[inference][managed] building shared pooled HTTP client"
+fn log_managed_error(error: &tinyinference_llm::Error, point: TinyHumansFailurePoint) {
+ let operation = match point {
+ TinyHumansFailurePoint::Invoke => "invoke",
+ TinyHumansFailurePoint::StreamOpen => "stream",
+ TinyHumansFailurePoint::StreamItem => "stream (in-band)",
+ TinyHumansFailurePoint::Readiness => return,
+ };
+ match error {
+ tinyinference_llm::Error::Provider(provider) => {
+ log::warn!(
+ "[providers][openhuman-backend] managed {operation} failed: status={:?} code={:?} provider={} retryable={} detail={}",
+ provider.status,
+ provider.code,
+ provider.provider,
+ provider.retryable,
+ tinyinference_core::sanitize::sanitize_api_error(&provider.message),
);
- reqwest::Client::builder()
- .connect_timeout(MANAGED_INFERENCE_CONNECT_TIMEOUT)
- .pool_idle_timeout(MANAGED_INFERENCE_POOL_IDLE_TIMEOUT)
- .tcp_keepalive(Duration::from_secs(30))
- .build()
- .unwrap_or_else(|error| {
- tracing::warn!(
- error = %error,
- "[inference][managed] pooled client build failed; using reqwest defaults"
- );
- reqwest::Client::new()
- })
- })
- .clone()
+ }
+ other => log::warn!(
+ "[providers][openhuman-backend] managed {operation} failed (non-provider error): {}",
+ tinyinference_core::sanitize::sanitize_api_error(&other.to_string()),
+ ),
+ }
}
#[cfg(test)]
diff --cc crates/openhuman-tinyhumans/src/inference/managed_session.rs
index 5e839e93f9,3ef8969937..5e9a26db88
--- a/crates/openhuman-tinyhumans/src/inference/managed_session.rs
+++ b/crates/openhuman-tinyhumans/src/inference/managed_session.rs
@@@ -3,35 -3,50 +3,74 @@@
//! rejected session.
use tinyinference_llm::model::ProviderError;
-use tinyinference_llm::Error as TiError;
+use tinyinference_llm::providers::tinyhumans::{
+ TinyHumansAuthFailure, TinyHumansAuthFailureKind, TinyHumansOperation,
+};
+
+/// Resolve the persisted app-session token for a managed inference caller.
+/// Both chat and embeddings use this path so signed-out state, expiry checks,
+/// and offline-local credential refusal stay consistent.
+pub(super) fn resolve_session_bearer(
+ state_dir: &std::path::Path,
+ secrets_encrypt: bool,
+ profile_override: Option<&str>,
+ operation: &str,
+) -> anyhow::Result<String> {
+ use openhuman_embed::__host::security::credentials::session_support::classify_session_token;
+ use openhuman_embed::__host::security::credentials::{AuthService, APP_SESSION_PROVIDER};
+
+ if openhuman_embed::__host::platform::llm_gate::is_signed_out() {
+ anyhow::bail!("SESSION_EXPIRED: backend session not active — sign in to resume LLM work");
+ }
+ let auth = AuthService::new(state_dir, secrets_encrypt);
+ let profile = auth.get_profile(APP_SESSION_PROVIDER, profile_override)?;
+ // Precheck recorded JWT expiry before constructing any inference request.
+ let check = classify_session_token(profile.as_ref(), chrono::Utc::now());
+ managed_bearer(check, operation)
+}
+ /// Resolve the managed backend bearer from a read-only selected-profile
+ /// snapshot. Inspection never refreshes credentials or publishes expiry.
+ pub(super) fn managed_bearer_for_inspection(
+ config: &openhuman_embed::__host::config::Config,
+ ) -> anyhow::Result<String> {
+ use openhuman_embed::__host::security::credentials::session_support::{
+ check_session_backend, classify_session_token, is_local_session_token,
+ load_app_session_profile_read_only, SessionTokenCheck,
+ };
+
+ if let Some(key) =
+ openhuman_embed::__host::security::credentials::api_key::get_api_key_read_only(config)
+ .map_err(|_| anyhow::anyhow!("managed API key profile is unavailable or invalid"))?
+ {
+ let endpoint = format!(
+ "{}/openai/v1",
+ crate::backend::url::effective_api_url(&config.api_url).trim_end_matches('/')
+ );
+ anyhow::ensure!(
+ crate::client::endpoint::is_managed_endpoint_for_api_key(&endpoint),
+ "managed API key endpoint is not an approved managed endpoint"
+ );
+ return Ok(key);
+ }
+
+ let profile = load_app_session_profile_read_only(config)
+ .map_err(|_| anyhow::anyhow!("managed session profile is unavailable or invalid"))?;
+ check_session_backend(config, profile.as_ref())
+ .map_err(|_| anyhow::anyhow!("managed session belongs to a different backend"))?;
+ match classify_session_token(profile.as_ref(), chrono::Utc::now()) {
+ SessionTokenCheck::Live(token) if !is_local_session_token(&token) => Ok(token),
+ SessionTokenCheck::Expired => anyhow::bail!("managed session is expired"),
+ SessionTokenCheck::Live(_) => {
+ anyhow::bail!("offline local session cannot call managed inference")
+ }
+ SessionTokenCheck::Absent => anyhow::bail!("managed session credential is unavailable"),
+ }
+ }
+
/// The bearer a classified app-session token yields for managed inference.
///
-/// Separate from `OpenHumanBackendModel::resolve_bearer` so the decision is
+/// Separate from the model factory's bearer resolver so the decision is
/// testable without an on-disk auth profile.
///
/// `exp`-less tokens carry no recorded expiry, so `classify_session_token`
diff --cc crates/openhuman-tinyhumans/src/inference/managed_session_tests.rs
index 48f8604ada,e4dcd46bed..eea6022878
--- a/crates/openhuman-tinyhumans/src/inference/managed_session_tests.rs
+++ b/crates/openhuman-tinyhumans/src/inference/managed_session_tests.rs
@@@ -18,6 -17,17 +20,20 @@@ fn the_offline_local_session_cannot_aut
error.to_string(),
LOCAL_SESSION_MANAGED_INFERENCE_UNAVAILABLE
);
+ }
+
+ #[test]
+ fn the_refusal_does_not_read_as_an_expired_session() {
+ use openhuman_embed::__host::security::credentials::session_support::SessionTokenCheck;
+
- let error = managed_bearer(SessionTokenCheck::Live("header.payload.local".to_string()))
- .expect_err("a local session has no managed bearer");
++ let error = managed_bearer(
++ SessionTokenCheck::Live("header.payload.local".to_string()),
++ "openhuman_backend_model.resolve_bearer",
++ )
++ .expect_err("a local session has no managed bearer");
+
+ // The whole point of the fix: this must not reach the sign-out path that
+ // the backend's 401 envelope used to trigger.
assert!(
!openhuman_embed::__host::core::observability::is_session_expired_message(
&error.to_string()
@@@ -38,3 -46,264 +53,222 @@@ fn a_signed_in_session_still_authentica
assert_eq!(bearer, "header.payload.signature");
}
+
-use tinyinference_llm::model::{ModelStreamItem, ProviderError};
-
+ static SESSION_EXPIRY_EVENT_TEST_LOCK: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(());
+
-/// #6724 (review): a 401 reported *inside* a stream must start re-auth just
-/// like a failed `stream()` call does.
-#[tokio::test]
-async fn an_in_band_401_publishes_session_expired() {
- use openhuman_embed::__host::core::events::DomainEvent;
-
- let _lock = SESSION_EXPIRY_EVENT_TEST_LOCK.lock().await;
-
- openhuman_embed::__host::core::bus::init()
- .await
- .expect("bus init");
- let mut rx = openhuman_embed::__host::core::bus::BUS
- .get()
- .expect("event bus initialized")
- .receiver();
-
- super::super::managed_calls::observe_in_band_failure(&ModelStreamItem::ProviderFailed(
- ProviderError {
- provider: super::super::managed_model::PROVIDER_LABEL.to_string(),
- status: Some(401),
- message: "TEST_MARKER_IN_BAND token expired".to_string(),
- ..ProviderError::default()
- },
- ));
-
- let mut source_seen = None;
- loop {
- match rx.try_recv() {
- Ok(DomainEvent::SessionExpired { source, reason })
- if reason.contains("TEST_MARKER_IN_BAND") =>
- {
- source_seen = Some(source);
- break;
- }
- Ok(_) | Err(tinybus::TryRecvError::Lagged(_)) => continue,
- Err(_) => break,
- }
- }
- assert_eq!(
- source_seen.as_deref(),
- Some("openhuman_backend_model.stream(401)"),
- "an in-band 401 must publish SessionExpired"
- );
-}
-
+ #[tokio::test]
+ async fn inspection_invoke_and_in_band_401_do_not_mutate_credentials_or_publish_expiry() {
+ const CHILD_MARKER: &str = "OPENHUMAN_INSPECTION_401_ISOLATED_CHILD";
+ if std::env::var_os(CHILD_MARKER).is_none() {
+ let exact = "inference::managed_session::tests::inspection_invoke_and_in_band_401_do_not_mutate_credentials_or_publish_expiry";
+ let output = std::process::Command::new(
+ std::env::current_exe().expect("resolve current test executable"),
+ )
+ .args(["--exact", exact, "--nocapture", "--test-threads=1"])
+ .env(CHILD_MARKER, "1")
+ .stdin(std::process::Stdio::null())
+ .output()
+ .expect("run inspection 401 test in an isolated process");
+ let stdout = String::from_utf8_lossy(&output.stdout);
+ assert!(
+ output.status.success()
+ && stdout.contains("test result: ok. 1 passed; 0 failed; 0 ignored"),
+ "isolated inspection 401 test must run exactly once and pass (status {})",
+ output.status
+ );
+ return;
+ }
+
+ use axum::response::IntoResponse;
+ use openhuman_embed::__host::config::Config;
+ use openhuman_embed::__host::core::events::DomainEvent;
+ use openhuman_embed::__host::egress::EgressLedger;
- use openhuman_embed::__host::inference_registry::ChatModelRequest;
++ use openhuman_embed::__host::inference_registry::{ChatModelRequest, ProviderContext};
+ use tinyinference_llm::message::Message;
- use tinyinference_llm::model::ModelRequest;
++ use tinyinference_llm::model::{ModelRequest, ModelStreamItem, ProviderError};
+
+ let _lock = SESSION_EXPIRY_EVENT_TEST_LOCK.lock().await;
+ let temp = tempfile::tempdir().expect("temporary selected credential workspace");
+ let invoke_addr = spawn_inspection_401_server(false).await;
+ let stream_addr = spawn_inspection_401_server(true).await;
+ let config = Config {
+ workspace_dir: temp.path().to_owned(),
+ action_dir: temp.path().to_owned(),
+ config_path: temp.path().join("config.toml"),
+ api_url: Some(format!("http://{invoke_addr}")),
+ secrets: {
+ let mut secrets = Config::default().secrets;
+ secrets.encrypt = false;
+ secrets
+ },
+ ..Config::default()
+ };
+ let auth_profile_path = temp.path().join("auth-profiles.json");
+ // Keep the fixture in the selected profile's portable JSON store. The
+ // ordinary AuthService may choose a machine-global secret backend, while
+ // the inspection adapter intentionally reads only this workspace.
+ std::fs::write(
+ &auth_profile_path,
+ r#"{"schema_version":1,"active_profiles":{"app-session":"app-session:default"},"profiles":{"app-session:default":{"provider":"app-session","profile_name":"default","kind":"token","token":"inspection-session-token"}}}"#,
+ )
+ .expect("seed selected app-session profile in the temporary workspace");
+ let profile_before = std::fs::read(&auth_profile_path).expect("read seeded auth profile");
+ let store_before = credential_store_snapshot(temp.path());
+
+ openhuman_embed::__host::core::bus::init()
+ .await
+ .expect("event bus init");
+ let mut events = openhuman_embed::__host::core::bus::BUS
+ .get()
+ .expect("event bus initialized")
+ .receiver();
+ drain_session_events(&mut events);
+
+ let egress = EgressLedger::none();
+ let build_inspection_model = |api_url: &str| {
+ let mut model_config = config.clone();
+ model_config.api_url = Some(format!("http://{api_url}"));
++ let context = ProviderContext {
++ config: model_config.clone(),
++ egress: egress.clone(),
++ embedding: None,
++ catalog: None,
++ };
+ let request = ChatModelRequest {
+ role: "chat",
- config: &model_config,
+ model_override: Some("reasoning-v1"),
+ default_model: None,
+ native_tool_calling: true,
+ thread_id: None,
- egress: &egress,
++ context: &context,
+ };
+ let model = super::super::build_chat_model_for_inspection(&request)
+ .expect("real TinyHumans inspection adapter should read the selected profile");
+ (model_config, model.model)
+ };
+
+ let (_invoke_config, invoke_model) = build_inspection_model(&invoke_addr);
+ let invoke_error = invoke_model
+ .invoke(&(), ModelRequest::new(vec![Message::user("probe")]))
+ .await
+ .expect_err("mock 401 should surface as a provider failure");
+ assert!(matches!(
+ invoke_error,
+ tinyinference_llm::Error::Provider(_)
+ ));
+ assert_eq!(
+ std::fs::read(&auth_profile_path).expect("read auth profile after invoke"),
+ profile_before,
+ "inspection invoke must not clear, rewrite, or quarantine the selected profile"
+ );
+ assert_eq!(credential_store_snapshot(temp.path()), store_before);
+ assert_no_session_expired(&mut events);
+
+ let (_stream_config, stream_model) = build_inspection_model(&stream_addr);
+ let stream = stream_model
+ .stream(&(), ModelRequest::new(vec![Message::user("probe")]))
+ .await
+ .expect("HTTP 200 stream can report an in-band provider error");
+ use futures::StreamExt;
+ let items = stream.collect::<Vec<_>>().await;
+ assert!(
+ items.iter().any(|item| matches!(
+ item,
+ ModelStreamItem::ProviderFailed(ProviderError {
+ status: Some(401),
+ ..
+ })
+ )),
+ "mock SSE should produce an in-band 401: {items:#?}"
+ );
+ assert_eq!(
+ std::fs::read(&auth_profile_path).expect("read auth profile after stream"),
+ profile_before,
+ "inspection stream must not clear, rewrite, or quarantine the selected profile"
+ );
+ assert_eq!(credential_store_snapshot(temp.path()), store_before);
+ assert!(!temp.path().join("auth-profiles.lock").exists());
+ assert_no_session_expired(&mut events);
+
+ async fn spawn_inspection_401_server(in_band: bool) -> String {
+ let listener = tokio::net::TcpListener::bind("127.0.0.1:0")
+ .await
+ .expect("bind loopback mock");
+ let addr = listener.local_addr().expect("mock address");
+ let app = axum::Router::new().route(
+ "/openai/v1/chat/completions",
+ axum::routing::post(move || async move {
+ if in_band {
+ (
+ axum::http::StatusCode::OK,
+ [(axum::http::header::CONTENT_TYPE, "text/event-stream")],
+ "data: {\"error\":{\"code\":401,\"message\":\"Invalid token\"}}\n\ndata: [DONE]\n\n",
+ )
+ .into_response()
+ } else {
+ (
+ axum::http::StatusCode::UNAUTHORIZED,
+ axum::Json(serde_json::json!({
+ "error": { "message": "Invalid token", "type": "auth_error" }
+ })),
+ )
+ .into_response()
+ }
+ }),
+ );
+ tokio::spawn(async move {
+ axum::serve(listener, app)
+ .await
+ .expect("serve loopback mock");
+ });
+ addr.to_string()
+ }
+
+ fn drain_session_events(receiver: &mut tinybus::events::EventReceiver<DomainEvent>) {
+ loop {
+ match receiver.try_recv() {
+ Ok(_) | Err(tinybus::TryRecvError::Lagged(_)) => continue,
+ Err(_) => return,
+ }
+ }
+ }
+
+ fn assert_no_session_expired(receiver: &mut tinybus::events::EventReceiver<DomainEvent>) {
+ loop {
+ match receiver.try_recv() {
+ Ok(DomainEvent::SessionExpired { source, reason }) => {
+ panic!("inspection call published SessionExpired ({source}): {reason}")
+ }
+ Ok(_) | Err(tinybus::TryRecvError::Lagged(_)) => continue,
+ Err(_) => return,
+ }
+ }
+ }
+
+ fn credential_store_snapshot(root: &std::path::Path) -> Vec<(std::path::PathBuf, Vec<u8>)> {
+ fn visit(
+ root: &std::path::Path,
+ dir: &std::path::Path,
+ out: &mut Vec<(std::path::PathBuf, Vec<u8>)>,
+ ) {
+ for entry in std::fs::read_dir(dir).expect("read credential fixture directory") {
+ let path = entry.expect("read credential fixture entry").path();
+ if path.is_dir() {
+ visit(root, &path, out);
+ } else {
+ out.push((
+ path.strip_prefix(root)
+ .expect("fixture file under root")
+ .to_path_buf(),
+ std::fs::read(&path).expect("read credential fixture bytes"),
+ ));
+ }
+ }
+ }
+
+ let mut files = Vec::new();
+ visit(root, root, &mut files);
+ files.sort_by(|left, right| left.0.cmp(&right.0));
+ files
+ }
+ }
diff --cc crates/openhuman-tinyhumans/src/inference/mod.rs
index 0523bd636d,a0098765dc..3c0150f707
--- a/crates/openhuman-tinyhumans/src/inference/mod.rs
+++ b/crates/openhuman-tinyhumans/src/inference/mod.rs
@@@ -24,12 -23,11 +24,13 @@@ pub(crate) use tiers::MODEL_MANAGED_DEF
use std::sync::Arc;
-use openhuman_embed::__host::config::{Config, MODEL_MANAGED_DEFAULT};
+use openhuman_embed::__host::config::Config;
use openhuman_embed::__host::inference_registry::{
- register_catalog, register_chat_model, register_embedding, register_inspection_chat_model,
- register_inspection_embedding, BoxFuture, ChatModelEntry, ChatModelFactory, ChatModelRequest,
- InspectionChatModelBuild, ReadinessProbe, PROVIDER_OPENHUMAN,
+ register_backend_error_classifier, register_catalog, register_chat_model,
- register_config_normalizer, register_embedding, ChatModelEntry, ChatModelFactory,
- ChatModelRequest, EmbeddingRequest, ProviderContext, ProviderModelMetadata, ReadinessProbe,
- PROVIDER_OPENHUMAN,
++ register_config_normalizer, register_embedding, register_inspection_catalog,
++ register_inspection_chat_model, register_inspection_embedding, ChatModelEntry,
++ ChatModelFactory, ChatModelRequest, EmbeddingRequest, InspectionChatModelBuild,
++ ProviderContext, ProviderModelMetadata, ReadinessProbe, PROVIDER_OPENHUMAN,
};
use tinyinference_llm::model::ChatModel;
@@@ -84,30 -78,54 +85,67 @@@ pub(crate) fn build_chat_model
Ok((Arc::new(model), pinned))
}
-/// Builds a managed model around a frozen read-only credential snapshot for
-/// inspection calls; invoke and stream never consult mutable auth state.
+ fn build_chat_model_for_inspection(
- request: &ChatModelRequest<'_>,
++ request: &ChatModelRequest<'_, ProviderContext>,
+ ) -> anyhow::Result<InspectionChatModelBuild> {
++ let config = &request.context.config;
+ let pinned = request
+ .model_override
+ .map(str::trim)
+ .filter(|model| !model.is_empty())
- .unwrap_or(MODEL_MANAGED_DEFAULT)
- .to_string();
++ .map(str::to_string)
++ .or_else(tiers::default_model)
++ .ok_or_else(|| anyhow::anyhow!("TinyHumans managed inference has no configured model"))?;
+ let default_model = request
+ .default_model
+ .map(str::trim)
+ .filter(|model| !model.is_empty())
+ .map(str::to_string)
+ .unwrap_or_else(|| pinned.clone());
- let options = managed_options(request.config);
- let bearer = managed_session::managed_bearer_for_inspection(request.config)?;
++ let bearer = managed_session::managed_bearer_for_inspection(config)?;
++ let model = managed_model::build_chat_model_for_inspection(
++ config.api_url.as_deref(),
++ &default_model,
++ bearer.clone(),
++ request.native_tool_calling,
++ request.thread_id,
++ )?;
+ let endpoint = format!(
+ "{}/openai/v1",
- crate::backend::url::effective_api_url(&request.config.api_url).trim_end_matches('/')
++ crate::backend::url::effective_api_url(&config.api_url).trim_end_matches('/')
+ );
- let model = OpenHumanBackendModel::new(
- request.config.api_url.as_deref(),
- &options,
- default_model.clone(),
- )
- .with_native_tool_calling(request.native_tool_calling)
- .with_thread_id(request.thread_id)
- .with_inspection_bearer(bearer.clone());
+ Ok(InspectionChatModelBuild {
+ model: Arc::new(model),
+ model_id: default_model,
+ endpoint,
+ credential: bearer,
+ })
+ }
+
fn readiness_probe() -> ReadinessProbe {
Arc::new(
- |role: String, model: String, config: Config| -> BoxFuture<Result<(), String>> {
+ |request: tinyinference_llm::providers::overrides::ReadinessRequest<ProviderContext>| -> tinyinference_llm::providers::overrides::BoxFuture<Result<(), String>> {
Box::pin(async move {
+ let role = request.role;
+ let model = request.model;
+ let config = request.context.config;
log::debug!("[tinyhumans][inference] readiness probe role={role} model={model}");
let options = managed_options(&config);
- OpenHumanBackendModel::new(config.api_url.as_deref(), &options, model)
- .probe_readiness()
- .await
+ let managed = match managed_model::build_chat_model(
+ config.api_url.as_deref(),
+ &options,
+ &model,
+ true,
+ None,
+ false,
+ ) {
+ Ok(managed) => managed,
+ Err(error) => {
+ log::debug!("[tinyhumans][inference] readiness model construction failed, failing open: {error}");
+ return Ok(());
+ }
+ };
+ managed.probe_readiness().await
})
},
)
@@@ -121,30 -139,24 +159,42 @@@ pub(crate) fn register(_options: &Insta
ChatModelEntry {
build,
probe: Some(readiness_probe()),
+ models: Some(ProviderModelMetadata {
+ default_model: Arc::new(tiers::default_model),
+ role_for_model: Arc::new(tiers::role_for_model),
+ is_alias: Arc::new(tiers::is_alias),
+ is_raw_model: Arc::new(tiers::is_raw_model),
+ supports_vision: Arc::new(tiers::supports_vision),
+ resolve_model: Arc::new(|role, context, model| {
+ tiers::resolve_model(role, &context.config, model)
+ }),
+ context_window: Arc::new(tiers::context_window),
+ default_pricing: Arc::new(tiers::default_pricing),
+ without_reasoning: Arc::new(tinyinference_llm::model::without_reasoning),
+ }),
},
);
+ register_embedding(
+ PROVIDER_OPENHUMAN,
+ Arc::new(|request: &EmbeddingRequest<'_, ProviderContext>| {
+ Ok(Box::new(managed_embedding::from_request(request)))
+ }),
+ );
+ register_inspection_chat_model(
+ PROVIDER_OPENHUMAN,
+ Arc::new(build_chat_model_for_inspection),
+ );
- register_embedding(PROVIDER_OPENHUMAN, |request| {
- Ok(Box::new(ManagedEmbeddingModel::from_request(request)))
- });
+ register_inspection_embedding(PROVIDER_OPENHUMAN, |request| {
- ManagedEmbeddingModel::from_request_for_inspection(request)
++ managed_embedding::from_request_for_inspection(request)
+ .map(|model| Box::new(model) as Box<dyn tinyinference_embeddings::EmbeddingModel>)
+ });
register_catalog(PROVIDER_OPENHUMAN, managed_catalog::entry());
- openhuman_embed::__host::inference_registry::register_inspection_catalog(
++ register_inspection_catalog(
+ PROVIDER_OPENHUMAN,
+ managed_catalog::inspection_entry(),
+ );
+ register_config_normalizer(PROVIDER_OPENHUMAN, Arc::new(tiers::normalize_config));
+ register_backend_error_classifier(Arc::new(backend_error_code::classify));
log::debug!(
"[tinyhumans] inference: registered the managed chat model, embeddings and catalog"
);
diff --cc crates/openhuman-tinyhumans/src/lib.rs
index 8cba9634a0,ca22f7c9e6..ac53a895f7
--- a/crates/openhuman-tinyhumans/src/lib.rs
+++ b/crates/openhuman-tinyhumans/src/lib.rs
@@@ -77,8 -77,8 +77,9 @@@ pub use openhuman_embed::__host
pub mod backend;
pub(crate) mod channels;
pub mod client;
+ pub(crate) mod doctor;
pub mod hosted;
+mod hosted_config;
pub(crate) mod inference;
mod install;
pub mod integrations;
diff --cc crates/openhuman-tinyhumans/src/register.rs
index f98fa5f7c1,2b3274b108..fa1a0a99e5
--- a/crates/openhuman-tinyhumans/src/register.rs
+++ b/crates/openhuman-tinyhumans/src/register.rs
@@@ -14,9 -23,8 +23,9 @@@ use crate::voice
use crate::{channels, client, inference, integrations, memory};
/// Registers every area's hooks with the core.
- pub(crate) fn register_all(options: &InstallOptions) {
+ pub(crate) fn register_all(options: &InstallOptions, doctor_registration: DoctorRegistration<'_>) {
log::debug!("[tinyhumans] register_all: registering core hooks");
+ crate::hosted_config::register();
client::register(options);
integrations::register(options);
#[cfg(feature = "voice")]
diff --cc crates/openhuman-tinyhumans/src/register_tests.rs
index 5fc0a475cb,b4c59b4211..03909cba56
--- a/crates/openhuman-tinyhumans/src/register_tests.rs
+++ b/crates/openhuman-tinyhumans/src/register_tests.rs
@@@ -5,34 -5,6 +5,34 @@@ fn register_all_is_idempotent()
let _registry = crate::registry_test_lock();
let options = InstallOptions::default();
- register_all(&options);
- register_all(&options);
+ register_all(&options, DoctorRegistration::Process);
+ register_all(&options, DoctorRegistration::Process);
}
+
+#[tokio::test]
+async fn boot_registration_supplies_hosted_model_default_and_normalizer_before_context_exists() {
+ let _registry = crate::registry_test_lock_async().await;
+ register_all(&InstallOptions::default());
+
+ let config = openhuman_embed::__host::config::Config::default();
+ assert_eq!(
+ config.default_model.as_deref(),
+ Some(crate::inference::MODEL_MANAGED_DEFAULT)
+ );
+
+ let mut legacy = openhuman_embed::__host::config::Config {
+ default_model: Some("reasoning-v1".to_string()),
+ ..Default::default()
+ };
+ let tmp = tempfile::tempdir().unwrap();
+ legacy.workspace_dir = tmp.path().join("workspace");
+ legacy.config_path = tmp.path().join("config.toml");
+ tokio::fs::create_dir_all(&legacy.workspace_dir)
+ .await
+ .unwrap();
+ openhuman_embed::__host::config::migrations::run_pending(&mut legacy).await;
+ assert_eq!(
+ legacy.default_model.as_deref(),
+ Some(crate::inference::MODEL_MANAGED_DEFAULT)
+ );
+}
diff --cc scripts/__tests__/debug-web-ui.test.mjs
index 5471a83fc4,1c26ce26d2..221c088b7f
--- a/scripts/__tests__/debug-web-ui.test.mjs
+++ b/scripts/__tests__/debug-web-ui.test.mjs
@@@ -118,9 -118,10 +118,9 @@@ test("core RPC client bounds a stalled
hangingFetch,
5,
);
- // AbortSignal.timeout uses an unref'd timer. Keep the test process alive so
- // the simulated stalled fetch can observe that timer without real network I/O.
- const keepAlive = setInterval(() => {}, 1_000);
-
+ // AbortSignal.timeout uses an unreferenced timer; keep the test process alive
+ // until that timeout fires even when no other handles are open.
+ const keepAlive = setTimeout(() => {}, 50);
try {
await assert.rejects(rpc("openhuman.auth_get_state"), {
name: "TimeoutError",
diff --cc scripts/__tests__/embed-contract-boundary.test.mjs
index 0291816ae8,24221a84f7..d9292e3598
--- a/scripts/__tests__/embed-contract-boundary.test.mjs
+++ b/scripts/__tests__/embed-contract-boundary.test.mjs
@@@ -1,45 -1,23 +1,47 @@@
-import test from 'node:test';
-import assert from 'node:assert/strict';
-import { copyFileSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
-import { tmpdir } from 'node:os';
-import { dirname, resolve } from 'node:path';
-import { spawnSync } from 'node:child_process';
+import test from "node:test";
+import assert from "node:assert/strict";
+import {
+ copyFileSync,
+ mkdirSync,
+ mkdtempSync,
+ rmSync,
+ writeFileSync,
+} from "node:fs";
+import { tmpdir } from "node:os";
+import { dirname, resolve } from "node:path";
+import { spawnSync } from "node:child_process";
function check(files) {
- const root = mkdtempSync(resolve(tmpdir(), 'embed-contract-boundary-'));
+ const root = mkdtempSync(resolve(tmpdir(), "embed-contract-boundary-"));
try {
- mkdirSync(resolve(root, 'scripts/ci'), { recursive: true });
- mkdirSync(resolve(root, 'scripts/lib'), { recursive: true });
- const bridge = 'vendor/tinyagents/crates/tinyagents-harness/src/providers/claude_code/bridge.rs';
++ mkdirSync(resolve(root, "crates"), { recursive: true });
++ mkdirSync(resolve(root, "vendor/tinyagents/crates"), { recursive: true });
+ mkdirSync(resolve(root, "scripts/ci"), { recursive: true });
+ mkdirSync(resolve(root, "scripts/lib"), { recursive: true });
+ const bridge =
+ "vendor/tinyagents/crates/tinyagents-harness/src/providers/claude_code/bridge.rs";
mkdirSync(dirname(resolve(root, bridge)), { recursive: true });
- writeFileSync(resolve(root, bridge), 'struct ChatMessage { pub(crate) role: String, pub(crate) content: String, }\n');
- copyFileSync(new URL('../ci/check-agent-runtime-boundary.mjs', import.meta.url), resolve(root, 'scripts/ci/check-agent-runtime-boundary.mjs'));
- for (const helper of ['runtime-boundary-types.mjs', 'agent-sdk-contracts.mjs']) {
- copyFileSync(new URL(`../lib/${helper}`, import.meta.url), resolve(root, `scripts/lib/${helper}`));
+ writeFileSync(
+ resolve(root, bridge),
+ "struct ChatMessage { pub(crate) role: String, pub(crate) content: String, }\n",
+ );
+ copyFileSync(
+ new URL("../ci/check-agent-runtime-boundary.mjs", import.meta.url),
+ resolve(root, "scripts/ci/check-agent-runtime-boundary.mjs"),
+ );
+ for (const helper of [
+ "runtime-boundary-types.mjs",
+ "agent-sdk-contracts.mjs",
+ ]) {
+ copyFileSync(
+ new URL(`../lib/${helper}`, import.meta.url),
+ resolve(root, `scripts/lib/${helper}`),
+ );
}
- writeFileSync(resolve(root, 'scripts/ci/agent-runtime-boundary-baseline.json'), '[]\n');
+ writeFileSync(
+ resolve(root, "scripts/ci/agent-runtime-boundary-baseline.json"),
+ "[]\n",
+ );
for (const [path, source] of Object.entries(files)) {
mkdirSync(dirname(resolve(root, path)), { recursive: true });
writeFileSync(resolve(root, path), source);
@@@ -154,61 -96,3 +156,190 @@@ test("Embed preserves native persisted
assert.match(rejected.output, /openhuman-upstream-reexport/);
}
});
+
+test("a builder method named with_thread_id is not a task-local accessor", () => {
+ const result = check({
+ "crates/openhuman-tinyhumans/src/inference/managed_model.rs":
+ "let model = builder.with_thread_id(thread_id);\n",
+ });
+ assert.equal(result.status, 0, result.output);
+});
+
+test("task-local with_thread_id calls, imports, and declarations remain forbidden", () => {
+ for (const source of [
+ "let request = with_thread_id(request, thread_id);\n",
+ "use crate::turn_context::with_thread_id;\n",
+ "fn with_thread_id(request: Request) -> Request { request }\n",
+ ]) {
+ const result = check({ "crates/openhuman-core/src/example.rs": source });
+ assert.equal(result.status, 1, result.output);
+ assert.match(result.output, /openhuman-task-local/);
+ }
+});
+
+test("Embed preserves the exact native dispatch-budget and observer contracts", () => {
+ const budget =
+ "pub use tinyagents_harness::cost::{\n" +
+ " ControlledDispatchError, DispatchModelOptions, DispatchRefusal, DispatchRefusalReason,\n" +
+ " PhysicalDispatchAdmission, PhysicalDispatchPermit,\n" +
+ "};\n";
+ const observer =
+ "pub use tinyagents_harness::observability::{\n" +
+ " PhysicalDispatchMetadata, PhysicalDispatchObserver, PhysicalDispatchOutcome,\n" +
+ " PhysicalDispatchStatus, PhysicalDispatchTerminal, PhysicalDispatchUsage,\n" +
+ "};\n";
+ const allowed = check({
+ "crates/openhuman-embed/src/budget.rs": budget,
+ "crates/openhuman-embed/src/complete.rs": observer,
+ });
+ assert.equal(allowed.status, 0, allowed.output);
+
+ for (const files of [
+ {
+ "crates/openhuman-embed/src/budget.rs": budget.replace(
+ "PhysicalDispatchAdmission, PhysicalDispatchPermit,",
+ "PhysicalDispatchAdmission, PhysicalDispatchPermit, UnreviewedType,",
+ ),
+ },
+ {
+ "crates/openhuman-embed/src/complete.rs": observer.replace(
+ "PhysicalDispatchStatus, PhysicalDispatchTerminal, PhysicalDispatchUsage,",
+ "PhysicalDispatchStatus, PhysicalDispatchTerminal, PhysicalDispatchUsage, UnreviewedType,",
+ ),
+ },
+ { "crates/openhuman-core/src/agent/tinyagents/budget.rs": budget },
+ ]) {
+ const rejected = check(files);
+ assert.equal(rejected.status, 1, rejected.output);
+ assert.match(rejected.output, /openhuman-upstream-reexport/);
+ }
+});
++
++test("Embed exposes exact native provider override contracts in inference_registry", () => {
++ const overrides =
++ "pub mod inference_registry {\n" +
++ " pub use tinyinference_llm::providers::overrides::{\n" +
++ " BoxFuture, CatalogEntry, CatalogLimits, CatalogListing, CatalogRequest,\n" +
++ " ChatModelEntry, ChatModelFactory, ChatModelRequest, EmbeddingFactory,\n" +
++ " EmbeddingRequest, ProviderModelMetadata, ProviderOverrides, ReadinessProbe,\n" +
++ " };\n" +
++ "}\n";
++ const allowed = check({
++ "crates/openhuman-embed/src/host_internals.rs": overrides,
++ });
++ assert.equal(allowed.status, 0, allowed.output);
++
++ for (const files of [
++ {
++ "crates/openhuman-embed/src/host_internals.rs": overrides.replace(
++ "ProviderOverrides, ReadinessProbe,",
++ "ProviderOverrides, ReadinessProbe, UnreviewedType,",
++ ),
++ },
++ {
++ "crates/openhuman-embed/src/host_internals.rs": overrides.replace(
++ "inference_registry",
++ "provider_registry",
++ ),
++ },
++ {
++ "crates/openhuman-core/src/inference/registry.rs": overrides,
++ },
++ ]) {
++ const rejected = check(files);
++ assert.equal(rejected.status, 1, rejected.output);
++ assert.match(rejected.output, /openhuman-upstream-reexport/);
++ }
++});
++
++test("the TinyAgents-owned AgentProgress type is allowed only at its native paths", () => {
++ const progressOwner =
++ "vendor/tinyagents/crates/tinyagents-harness/src/progress.rs";
++ const harness = "vendor/tinyagents/crates/tinyagents-harness/src/";
++ const native = {
++ [`${harness}lib.rs`]: "pub use progress::AgentProgress;\n",
++ [progressOwner]: "pub enum AgentProgress { Started }\n",
++ [`${harness}turn_runner/types.rs`]:
++ "use crate::progress::AgentProgress;\nstruct Event(AgentProgress);\n",
++ [`${harness}turn_runner/mod_tests.rs`]:
++ "fn progress(event: crate::progress::AgentProgress) { let _ = event; }\n",
++ };
++ const allowed = check(native);
++ assert.equal(allowed.status, 0, allowed.output);
++
++ for (const files of [
++ {
++ "vendor/tinyagents/crates/tinyagents-session/src/progress.rs":
++ "pub enum AgentProgress { Started }\n",
++ },
++ {
++ "vendor/tinyagents/crates/tinyagents-harness/src/agent_progress.rs":
++ "pub enum AgentProgress { Started }\n",
++ },
++ {
++ [progressOwner]:
++ "pub enum AgentProgress { Started }\nuse openhuman_core::AgentProgress;\n",
++ },
++ {
++ [`${harness}turn_runner/types.rs`]:
++ "use crate::progress::AgentProgress;\nuse openhuman_core::AgentProgress;\n",
++ },
++ {
++ [`${harness}turn_runner/types.rs`]:
++ "/* use crate::progress::AgentProgress; */\nstruct Event(AgentProgress);\n",
++ },
++ {
++ "vendor/tinyagents/crates/tinyagents-session/src/lib.rs":
++ "pub enum AgentProgress { Started }\n",
++ },
++ ]) {
++ const rejected = check(files);
++ assert.equal(rejected.status, 1, rejected.output);
++ assert.match(rejected.output, /tinyagents-openhuman-domain-name/);
++ }
++});
++
++test("provider override contract does not escape its closed facade module", () => {
++ const overrides =
++ "pub mod inference_registry {\n" +
++ "}\n" +
++ "pub mod other_registry {\n" +
++ " pub use tinyinference_llm::providers::overrides::{\n" +
++ " BoxFuture, CatalogEntry, CatalogLimits, CatalogListing, CatalogRequest,\n" +
++ " ChatModelEntry, ChatModelFactory, ChatModelRequest, EmbeddingFactory,\n" +
++ " EmbeddingRequest, ProviderModelMetadata, ProviderOverrides, ReadinessProbe,\n" +
++ " };\n" +
++ "}\n";
++ const misplaced = check({
++ "crates/openhuman-embed/src/host_internals.rs": overrides,
++ });
++ assert.equal(misplaced.status, 1, misplaced.output);
++ assert.match(misplaced.output, /openhuman-upstream-reexport/);
++
++ const freeExport = check({
++ "crates/openhuman-embed/src/host_internals.rs":
++ "pub mod inference_registry {\n}\n" +
++ "pub use tinyinference_llm::providers::overrides::{\n" +
++ " BoxFuture, CatalogEntry, CatalogLimits, CatalogListing, CatalogRequest,\n" +
++ " ChatModelEntry, ChatModelFactory, ChatModelRequest, EmbeddingFactory,\n" +
++ " EmbeddingRequest, ProviderModelMetadata, ProviderOverrides, ReadinessProbe,\n" +
++ "};\n",
++ });
++ assert.equal(freeExport.status, 1, freeExport.output);
++ assert.match(freeExport.output, /openhuman-upstream-reexport/);
++
++ const nestedExport = check({
++ "crates/openhuman-embed/src/host_internals.rs":
++ "pub mod inference_registry {\n" +
++ " pub mod nested {\n" +
++ " pub use tinyinference_llm::providers::overrides::{\n" +
++ " BoxFuture, CatalogEntry, CatalogLimits, CatalogListing, CatalogRequest,\n" +
++ " ChatModelEntry, ChatModelFactory, ChatModelRequest, EmbeddingFactory,\n" +
++ " EmbeddingRequest, ProviderModelMetadata, ProviderOverrides, ReadinessProbe,\n" +
++ " };\n" +
++ " }\n" +
++ "}\n",
++ });
++ assert.equal(nestedExport.status, 1, nestedExport.output);
++ assert.match(nestedExport.output, /openhuman-upstream-reexport/);
++});
diff --cc scripts/ci/agent-runtime-boundary-baseline.json
index 626e04d507,502105a167..bfcdc19299
--- a/scripts/ci/agent-runtime-boundary-baseline.json
+++ b/scripts/ci/agent-runtime-boundary-baseline.json
@@@ -523,5 -600,5 +523,47 @@@
"line": 69,
"text": "pub use tinyagents_harness::store::{AppendStore, Store};",
"occurrence": 1
++ },
++ {
++ "rule": "openhuman-task-local",
++ "path": "crates/openhuman-tinyhumans/src/inference/managed_calls.rs",
++ "line": 12,
++ "text": "use super::managed_reasoning::{apply_reasoning_hint, with_thread_id};",
++ "occurrence": 1
++ },
++ {
++ "rule": "openhuman-task-local",
++ "path": "crates/openhuman-tinyhumans/src/inference/managed_calls.rs",
++ "line": 123,
++ "text": "with_thread_id(apply_reasoning_hint(request), self.thread_id.as_deref()),",
++ "occurrence": 1
++ },
++ {
++ "rule": "openhuman-task-local",
++ "path": "crates/openhuman-tinyhumans/src/inference/managed_calls.rs",
++ "line": 153,
++ "text": "with_thread_id(apply_reasoning_hint(request), self.thread_id.as_deref()),",
++ "occurrence": 2
++ },
++ {
++ "rule": "openhuman-task-local",
++ "path": "crates/openhuman-tinyhumans/src/inference/managed_model.rs",
++ "line": 99,
++ "text": "pub fn with_thread_id(mut self, thread_id: Option<impl AsRef<str>>) -> Self {",
++ "occurrence": 1
++ },
++ {
++ "rule": "openhuman-upstream-reexport",
++ "path": "crates/openhuman-core/src/agent/tinyagents/budget.rs",
++ "line": 10,
++ "text": "pub use tinyagents_harness::cost::{",
++ "occurrence": 1
++ },
++ {
++ "rule": "openhuman-upstream-reexport",
++ "path": "crates/openhuman-embed/src/lib.rs",
++ "line": 251,
++ "text": "pub use tinyagents_harness_tools::todos::TodoList;",
++ "occurrence": 1
}
]
diff --cc scripts/ci/check-agent-runtime-boundary.mjs
index 40cfa2c5d9,c4ccb50fd9..31ef4d8258
--- a/scripts/ci/check-agent-runtime-boundary.mjs
+++ b/scripts/ci/check-agent-runtime-boundary.mjs
@@@ -85,17 -76,17 +85,64 @@@ function normalizeExport(statement)
function isEmbedContractExport(path, lines, index) {
const allowed = embedContractExports.get(path);
-- if (!allowed) return false;
++ const moduleExports = embedModuleContractExports.get(path);
++ if (!allowed && !moduleExports) return false;
const remaining = lines
.slice(index)
.map(({ text }) => text)
.join("\n");
const end = remaining.indexOf(";");
-- return end >= 0 && allowed.has(normalizeExport(remaining.slice(0, end + 1)));
++ if (end < 0) return false;
++
++ const statement = normalizeExport(remaining.slice(0, end + 1));
++ if (allowed?.has(statement)) return true;
++
++ if (!moduleExports) return false;
++ return [...moduleExports].some(
++ ([module, statements]) =>
++ statements.has(statement) && isInsidePublicModule(lines, index, module),
++ );
}
// Product types need not start with `OpenHuman`, so this is an explicit,
// reviewed inventory rather than a naming convention.
++const embedModuleContractExports = new Map([
++ [
++ "crates/openhuman-embed/src/host_internals.rs",
++ new Map([
++ [
++ "inference_registry",
++ new Set(
++ [
++ "pub use tinyinference_llm::providers::overrides::{BoxFuture, CatalogEntry, CatalogLimits, CatalogListing, CatalogRequest, ChatModelEntry, ChatModelFactory, ChatModelRequest, EmbeddingFactory, EmbeddingRequest, ProviderModelMetadata, ProviderOverrides, ReadinessProbe};",
++ ].map(normalizeExport),
++ ),
++ ],
++ ]),
++ ],
++]);
++
++function isInsidePublicModule(lines, index, module) {
++ const declaration = new RegExp(
++ `^\\s*pub\\s+mod\\s+${escapeRegex(module)}\\s*\\{`,
++ );
++ let start = -1;
++ for (let cursor = 0; cursor < index; cursor += 1) {
++ if (declaration.test(lines[cursor].text)) start = cursor;
++ }
++ if (start < 0) return false;
++
++ let depth = 0;
++ for (let cursor = start; cursor < index; cursor += 1) {
++ for (const char of lines[cursor].text) {
++ if (char === "{") depth += 1;
++ else if (char === "}") depth -= 1;
++ }
++ if (depth === 0) return false;
++ }
++ return depth === 1;
++}
++
const openhumanDomainTypes = new Set([
"AgentDefinitionDisplay",
"AgentDefinitionModel",
@@@ -116,6 -107,6 +163,35 @@@
"WorkspacePolicy",
]);
++function isNativeAgentProgressReference(path, text, source = text) {
++ const harness = "vendor/tinyagents/crates/tinyagents-harness/src/";
++ if (
++ /\b(?:openhuman(?:_[A-Za-z0-9_]+)?|tinyagents(?:_[A-Za-z0-9_]+)?)\s*::\s*AgentProgress\b/.test(
++ text,
++ )
++ )
++ return false;
++ if (
++ path === `${harness}progress.rs` &&
++ /\bpub\s+enum\s+AgentProgress\b/.test(rustCode(source))
++ )
++ return true;
++ if (
++ path === `${harness}lib.rs` &&
++ /^\s*pub\s+use\s+progress::AgentProgress\s*;\s*$/.test(text)
++ )
++ return true;
++ if (path === `${harness}turn_runner/types.rs`) {
++ const ownsImport = /^\s*use\s+crate::progress::AgentProgress\s*;\s*$/m.test(
++ rustCode(source),
++ );
++ return ownsImport;
++ }
++ if (path === `${harness}turn_runner/mod_tests.rs`)
++ return /\bcrate\s*::\s*progress\s*::\s*AgentProgress\b/.test(text);
++ return false;
++}
++
// Names moved out of compatibility layers. Values identify their sole owner;
// declarations in any other TinyAgents crate are facades even if private.
const movedSymbolOwners = new Map([
@@@ -476,6 -467,6 +552,51 @@@ function isBehaviorFreeForwarder(source
}
function assertSelfTests() {
++ const progressPath =
++ "vendor/tinyagents/crates/tinyagents-harness/src/progress.rs";
++ const nativeTypesPath =
++ "vendor/tinyagents/crates/tinyagents-harness/src/turn_runner/types.rs";
++ const testPath =
++ "vendor/tinyagents/crates/tinyagents-harness/src/turn_runner/mod_tests.rs";
++ const nativeTypes =
++ "use crate::progress::AgentProgress;\nProgress(Box<AgentProgress>)";
++ if (
++ !isNativeAgentProgressReference(progressPath, "pub enum AgentProgress {") ||
++ !isNativeAgentProgressReference(
++ "vendor/tinyagents/crates/tinyagents-harness/src/lib.rs",
++ "pub use progress::AgentProgress;",
++ ) ||
++ !isNativeAgentProgressReference(
++ nativeTypesPath,
++ "Progress(Box<AgentProgress>)",
++ nativeTypes,
++ ) ||
++ !isNativeAgentProgressReference(
++ testPath,
++ "_event: crate::progress::AgentProgress",
++ ) ||
++ isNativeAgentProgressReference(
++ "vendor/tinyagents/crates/tinyagents-session/src/lib.rs",
++ "pub enum AgentProgress {",
++ ) ||
++ isNativeAgentProgressReference(
++ progressPath,
++ "use openhuman_core::AgentProgress;",
++ "pub enum AgentProgress {\nuse openhuman_core::AgentProgress;",
++ ) ||
++ isNativeAgentProgressReference(
++ nativeTypesPath,
++ "use openhuman_core::AgentProgress;",
++ "use openhuman_core::AgentProgress;",
++ ) ||
++ isNativeAgentProgressReference(
++ testPath,
++ "_event: openhuman_core::AgentProgress",
++ )
++ )
++ throw new Error(
++ "agent-runtime boundary self-test: native AgentProgress allowance escaped its owner and paths",
++ );
const embedPath = "crates/openhuman-embed/src/lib.rs";
const policyExport = [{ text: "pub use tinytools::ToolPolicy;" }];
if (
@@@ -783,6 -764,6 +904,11 @@@ for (const path of await filesUnder
)
)
continue;
++ if (
++ name === "AgentProgress" &&
++ isNativeAgentProgressReference(relative(repoRoot, path), text, source)
++ )
++ continue;
if (new RegExp(`\\b${escapeRegex(name)}\\b`).test(text)) {
add("tinyagents-openhuman-domain-name", path, line, raw);
break;
diff --cc scripts/ci/check-openhuman-rust-layout.mjs
index 1fcf0c9c4f,b7e749db56..c9bf3c6bb3
--- a/scripts/ci/check-openhuman-rust-layout.mjs
+++ b/scripts/ci/check-openhuman-rust-layout.mjs
@@@ -43,7 -41,7 +41,7 @@@ const LEGACY_LIMIT_ENTRIES =
["crates/openhuman-core/src/core/all_tests.rs", 1465],
["crates/openhuman-core/src/core/events.rs", 1697],
["crates/openhuman-core/src/core/events_tests.rs", 988],
- ["crates/openhuman-core/src/core/observability.rs", 3425],
- ["crates/openhuman-core/src/core/observability.rs", 3361],
++ ["crates/openhuman-core/src/core/observability.rs", 3357],
];
const LEGACY_LIMITS = new Map(LEGACY_LIMIT_ENTRIES);
diff --cc scripts/ci/saas-ambient-baseline.json
index 937dadad69,34575c3208..bd8d04daa2
--- a/scripts/ci/saas-ambient-baseline.json
+++ b/scripts/ci/saas-ambient-baseline.json
@@@ -251,20 -251,20 +251,6 @@@
"text": "std::env::set_var(\"RUST_LOG\", default);",
"occurrence": 1
},
-- {
-- "rule": "home-dir",
- "path": "crates/openhuman-core/src/core/runtime/context.rs",
- "line": 226,
- "path": "crates/openhuman-core/src/core/runtime/context_boot.rs",
- "line": 125,
-- "text": "dirs::home_dir()",
-- "occurrence": 1
-- },
-- {
-- "rule": "ambient-config",
- "path": "crates/openhuman-core/src/core/runtime/context.rs",
- "line": 256,
- "path": "crates/openhuman-core/src/core/runtime/context_boot.rs",
- "line": 155,
-- "text": "None => crate::config::Config::load_or_init().await,",
-- "occurrence": 1
-- },
{
"rule": "home-dir",
"path": "crates/openhuman-core/src/core/runtime/saas.rs",
@@@ -342,13 -342,13 +328,6 @@@
"text": "tokio::spawn(async move {",
"occurrence": 1
},
-- {
-- "rule": "bare-spawn",
-- "path": "crates/openhuman-core/src/cron/scheduler/dispatcher.rs",
- "line": 56,
- "text": "tokio::spawn(async move {",
- "line": 615,
- "text": "Ok(tokio::spawn(work))",
-- "occurrence": 1
-- },
{
"rule": "bare-spawn",
"path": "crates/openhuman-core/src/desktop/app_state/ops/runtime_snapshot.rs",
@@@ -1055,5 -1104,5 +1020,68 @@@
"line": 87,
"text": "tokio::spawn(crate::core::runtime::context::CoreContext::propagate(",
"occurrence": 1
++ },
++ {
++ "rule": "home-dir",
++ "path": "crates/openhuman-core/src/core/runtime/context_boot.rs",
++ "line": 125,
++ "text": "dirs::home_dir()",
++ "occurrence": 1
++ },
++ {
++ "rule": "ambient-config",
++ "path": "crates/openhuman-core/src/core/runtime/context_boot.rs",
++ "line": 155,
++ "text": "None => crate::config::Config::load_or_init().await,",
++ "occurrence": 1
++ },
++ {
++ "rule": "bare-spawn",
++ "path": "crates/openhuman-core/src/cron/scheduler/dispatcher.rs",
++ "line": 615,
++ "text": "Ok(tokio::spawn(work))",
++ "occurrence": 1
++ },
++ {
++ "rule": "bare-spawn",
++ "path": "crates/openhuman-core/src/doctor/checks/storage.rs",
++ "line": 62,
++ "text": "match tokio::task::spawn_blocking(move || sqlite_probe(&path)).await {",
++ "occurrence": 1
++ },
++ {
++ "rule": "bare-spawn",
++ "path": "crates/openhuman-core/src/doctor/checks/storage.rs",
++ "line": 79,
++ "text": "match tokio::task::spawn_blocking(move || file_probe(&dir)).await {",
++ "occurrence": 1
++ },
++ {
++ "rule": "ambient-context",
++ "path": "crates/openhuman-core/src/doctor/contract.rs",
++ "line": 275,
++ "text": "let core = CoreContext::current();",
++ "occurrence": 1
++ },
++ {
++ "rule": "ambient-context",
++ "path": "crates/openhuman-core/src/doctor/ops.rs",
++ "line": 210,
++ "text": "let Some(parent) = CoreContext::current() else {",
++ "occurrence": 1
++ },
++ {
++ "rule": "bare-spawn",
++ "path": "crates/openhuman-core/src/doctor/runner.rs",
++ "line": 177,
++ "text": "tokio::task::spawn_blocking(move || {",
++ "occurrence": 1
++ },
++ {
++ "rule": "ambient-context",
++ "path": "crates/openhuman-core/src/inference/auth_error_registry.rs",
++ "line": 115,
++ "text": "let context = crate::core::runtime::CoreContext::current()?;",
++ "occurrence": 1
}
]
diff --cc vendor/tiny-artifacts
index 704e9c3062,704e9c3062..0d305e3675
--- a/vendor/tiny-artifacts
+++ b/vendor/tiny-artifacts
@@@ -1,1 -1,1 +1,1 @@@
--Subproject commit 704e9c3062512fad1d309280fb8782c8ce3c9034
++Subproject commit 0d305e36754a2df62c7cba8348037cd55c65155e
diff --cc vendor/tinyagents
index a4f60f0929,9d9cf25d5a..b069344177
--- a/vendor/tinyagents
+++ b/vendor/tinyagents
@@@ -1,1 -1,1 +1,1 @@@
- Subproject commit a4f60f09299fa2920a2962a698b45baa7254121e
-Subproject commit 9d9cf25d5af5c81fd991173494f9866077d806a9
++Subproject commit b069344177498363f643026778022ee4fee4ff11
diff --cc vendor/tinymcp
index 6bc701ad74,418f9c079b..7e18d33415
--- a/vendor/tinymcp
+++ b/vendor/tinymcp
@@@ -1,1 -1,1 +1,1 @@@
- Subproject commit 6bc701ad74a42b4549e545b9a69d0946b87c7d54
-Subproject commit 418f9c079b90e4466eacc207aebcc9f486bbf47f
++Subproject commit 7e18d33415b5e4413c05eadfb66d42a314b074a4
diff --cc vendor/tinyvoice
index ad11b013ac,4778ca5999..5838caf7a1
--- a/vendor/tinyvoice
+++ b/vendor/tinyvoice
@@@ -1,1 -1,1 +1,1 @@@
- Subproject commit ad11b013ac67148cc1e25017eb9e2a68ef04e550
-Subproject commit 4778ca59998b17e0938c3f2900eca55ac38b95af
++Subproject commit 5838caf7a1af4cb56ffbee824b68495680f059f7