Skip to content

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

refactor(flows): extract host model resolution and pass runtime context to boot reconcile

Steven Enamakeldc0de463c12c
diff --git a/crates/openhuman-core/src/core/runtime/services.rs b/crates/openhuman-core/src/core/runtime/services.rs
index 2732a60579..732eae378e 100644
--- a/crates/openhuman-core/src/core/runtime/services.rs
+++ b/crates/openhuman-core/src/core/runtime/services.rs
@@ -146,7 +146,7 @@ pub(crate) async fn start_selected_services(
// a background service — runs can be started without cron in the
// ServiceSet, so their orphans must be reconcilable without it too.
if ctx.domains().flows {
- spawn_flows_boot_reconcile();
+ spawn_flows_boot_reconcile(std::sync::Arc::clone(ctx));
}
if services.channels {
if let Some(handle) = spawn_channels_service(&crate::core::runtime::DispatchCtx::new(
@@ -230,16 +230,22 @@ pub fn spawn_update_scheduler() -> tokio::task::JoinHandle<()> {
/// safe at any point in boot — the sweep's own `PROCESS_RUN_FLOOR` guard means
/// it can never touch a run this process started, so it carries no ordering
/// requirement against the cron scheduler or any agent turn.
-pub fn spawn_flows_boot_reconcile() {
+pub fn spawn_flows_boot_reconcile(
+ ctx: std::sync::Arc<crate::core::runtime::CoreContext>,
+) {
#[cfg(feature = "flows")]
{
log::debug!("[flows] boot reconcile: scheduling orphaned-run sweep");
- tokio::spawn(async {
+ tokio::spawn(async move {
log::debug!("[flows] boot reconcile: loading config");
match crate::config::Config::load_or_init().await {
Ok(config) => {
- let swept =
- crate::flows::ops::sweep_orphaned_running_runs_on_boot(&config).await;
+ let dispatch = crate::core::runtime::DispatchCtx::new(ctx);
+ let swept = crate::flows::recovery::sweep_orphaned_runs_on_boot(
+ &dispatch,
+ &config,
+ )
+ .await;
// Logged unconditionally: a silent success and a task that
// never ran are otherwise indistinguishable in a boot log.
log::debug!("[flows] boot reconcile: completed; reconciled_runs={swept}");
diff --git a/crates/openhuman-core/src/flows/caps_host/llm.rs b/crates/openhuman-core/src/flows/caps_host/llm.rs
index 93be0672bf..17aa60661d 100644
--- a/crates/openhuman-core/src/flows/caps_host/llm.rs
+++ b/crates/openhuman-core/src/flows/caps_host/llm.rs
@@ -17,6 +17,13 @@ use crate::inference::provider::{
use crate::modules::tinyflows as module;
use tinyinference_llm::model::ModelRequest;
+pub(crate) fn resolve_host_model(node_model: Option<&str>, provider_model: String) -> String {
+ match node_model.filter(|model| is_raw_passthrough_model(model)) {
+ Some(model) => model.to_owned(),
+ None => provider_model,
+ }
+}
+
/// [`LlmProvider`] adapter over OpenHuman's inference stack
/// (`crates/openhuman-core/src/inference/provider/`).
///
@@ -116,10 +123,7 @@ impl OpenHumanLlm {
.map_err(|e| EngineError::Capability(e.to_string()))?;
// `create_chat_provider` handed back the role's default model. If the node
// pinned a raw/BYOK id, forward it verbatim instead (issue #4598).
- let model = match node_model.filter(|model| is_raw_passthrough_model(model)) {
- Some(model) => model.to_owned(),
- None => model,
- };
+ let model = resolve_host_model(node_model, model);
let mut model_request = ModelRequest::new(
messages
diff --git a/crates/openhuman-core/src/flows/caps_host/ops_schema_and_structured_output_tests.rs b/crates/openhuman-core/src/flows/caps_host/ops_schema_and_structured_output_tests.rs
index 0f9bcdb07c..6ee1a55ee6 100644
--- a/crates/openhuman-core/src/flows/caps_host/ops_schema_and_structured_output_tests.rs
+++ b/crates/openhuman-core/src/flows/caps_host/ops_schema_and_structured_output_tests.rs
@@ -1,79 +1,37 @@
use super::*;
use crate::inference::provider::is_raw_passthrough_model;
-use tinyflows::nodes::integration::agent_prompt;
-// ── resolve_completion_model raw/BYOK passthrough (issue #4598) ───────────
#[test]
-fn resolve_completion_model_forwards_raw_byok_node_model_verbatim() {
- // A raw/BYOK id maps to the `chat` role, so the role resolves to the
- // default model — but the pinned id is what the user selected and must
- // be the model the completion runs on.
- assert_eq!(
- agent_prompt::resolve_completion_model(
- Some("claude-opus-4"),
- "chat-v1".to_string(),
- is_raw_passthrough_model
- ),
- "claude-opus-4"
- );
- assert_eq!(
- agent_prompt::resolve_completion_model(
- Some("deepseek-v4-pro"),
- "chat-v1".to_string(),
- is_raw_passthrough_model
- ),
- "deepseek-v4-pro"
- );
+fn raw_provider_models_override_the_role_default() {
+ for raw in ["claude-opus-4", "deepseek-v4-pro"] {
+ assert!(is_raw_passthrough_model(raw));
+ assert_eq!(
+ resolve_host_model(Some(raw), "chat-v1".to_owned()),
+ raw
+ );
+ }
}
#[test]
-fn resolve_completion_model_leaves_managed_tier_and_hint_node_models_untouched() {
- // Managed tiers and every `hint:*` alias keep the role-resolved model.
- assert_eq!(
- agent_prompt::resolve_completion_model(
- Some("chat-v1"),
- "chat-v1".to_string(),
- is_raw_passthrough_model
- ),
- "chat-v1"
- );
- assert_eq!(
- agent_prompt::resolve_completion_model(
- Some("hint:reasoning"),
- "reasoning-v1".to_string(),
- is_raw_passthrough_model
- ),
- "reasoning-v1"
- );
+fn managed_model_tiers_keep_the_provider_resolved_model() {
+ for tier in ["chat-v1", "hint:reasoning", "hint:garbage"] {
+ assert_eq!(
+ resolve_host_model(Some(tier), "reasoning-v1".to_owned()),
+ "reasoning-v1"
+ );
+ }
assert_eq!(
- agent_prompt::resolve_completion_model(
- Some("hint:garbage"),
- "reasoning-v1".to_string(),
- is_raw_passthrough_model
- ),
- "reasoning-v1"
- );
- // No pinned model, or a whitespace-only pin, keeps the resolved default.
- assert_eq!(
- agent_prompt::resolve_completion_model(
- None,
- "chat-v1".to_string(),
- is_raw_passthrough_model
- ),
+ resolve_host_model(None, "chat-v1".to_owned()),
"chat-v1"
);
assert_eq!(
- agent_prompt::resolve_completion_model(
- Some(" "),
- "chat-v1".to_string(),
- is_raw_passthrough_model
- ),
+ resolve_host_model(Some(" "), "chat-v1".to_owned()),
"chat-v1"
);
}
#[test]
-fn crate_model_response_preserves_flow_completion_contract() {
+fn provider_response_preserves_the_flow_completion_contract() {
use tinyinference_llm::message::{AssistantMessage, ContentBlock};
use tinyinference_llm::model::ModelResponse;
use tinyinference_llm::tool::ToolCall;
@@ -120,5 +78,3 @@ fn crate_model_response_preserves_flow_completion_contract() {
assert_eq!(value["usage"]["charged_amount_usd"], 0.125);
assert_eq!(value["reasoning_content"], "private chain");
}
-
-// ── build_agent_result improvements (issue #5151) ────────────────────