The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix: preserve explicit agent thread boundaries
Steven Enamakel308abeb1227b
diff --git a/crates/openhuman-core/src/agent/goals/README.md b/crates/openhuman-core/src/agent/goals/README.mdindex e0355b17e7..fe53fab8a4 100644--- a/crates/openhuman-core/src/agent/goals/README.md+++ b/crates/openhuman-core/src/agent/goals/README.md@@ -1,7 +1,7 @@# Agent goalsTinyAgents owns goal types, lifecycle, persistence, budgets, and prompt-rendering. This directory contains OpenHuman runtime adapters for ambient+rendering. This directory contains OpenHuman runtime adapters for explicitthread selection, tool registration, turn accounting, and idle continuation.Goals are controlled by the agent tools and runtime. There is no thread-goaldiff --git a/crates/openhuman-core/src/agent/goals/runtime.rs b/crates/openhuman-core/src/agent/goals/runtime.rsindex a1ccaa3c94..a72544db0c 100644--- a/crates/openhuman-core/src/agent/goals/runtime.rs+++ b/crates/openhuman-core/src/agent/goals/runtime.rs@@ -36,7 +36,7 @@ pub async fn load_for_thread(workspace_dir: &Path, thread_id: Option<&str>) -> Omatch store::get(workspace_dir, &thread_id).await {Ok(goal) => goal,Err(e) => {- tracing::debug!(thread_id = %thread_id, error = %e, "[thread_goals] load_for_current_thread failed");+ tracing::debug!(thread_id = %thread_id, error = %e, "[thread_goals] load_for_thread failed");None}}@@ -61,14 +61,14 @@ pub async fn resume_for_thread(Some(Some(goal))}Err(e) => {- tracing::debug!(thread_id = %thread_id, error = %e, "[thread_goals] resume_for_current_thread failed");+ tracing::debug!(thread_id = %thread_id, error = %e, "[thread_goals] resume_for_thread failed");None}}}-/// Pause the active goal for the ambient thread (interrupt/abort semantics).-/// Best-effort; safe to call when there is no goal or no thread scope.+/// Pause the active goal for an explicit thread (interrupt/abort semantics).+/// Best-effort; safe to call when there is no goal or thread id.pub async fn pause_for_thread(workspace_dir: &Path, thread_id: Option<&str>) {let Some(thread_id) = normalized_thread(thread_id) else {return;@@ -84,14 +84,14 @@ pub async fn pause_for_thread(workspace_dir: &Path, thread_id: Option<&str>) {}}Err(e) => {- tracing::debug!(thread_id = %thread_id, error = %e, "[thread_goals] pause_for_current_thread failed");+ tracing::debug!(thread_id = %thread_id, error = %e, "[thread_goals] pause_for_thread failed");}}}-/// Mark the active goal for the ambient thread `Complete` (the originating+/// Mark the active goal for an explicit thread `Complete` (the originating/// task settled successfully). Best-effort; safe to call when there is no goal-/// or no thread scope. Emits `ThreadGoalUpdated` so the UI chip refreshes.+/// or no thread id. Emits `ThreadGoalUpdated` so the UI chip refreshes.////// This is the lifecycle counterpart the pause/resume pair was missing: without/// a settle, a goal a finished task left behind stays `Active` and is@@ -113,14 +113,14 @@ pub async fn complete_for_thread(workspace_dir: &Path, thread_id: Option<&str>)}}Err(e) => {- tracing::debug!(thread_id = %thread_id, error = %e, "[thread_goals] complete_for_current_thread failed");+ tracing::debug!(thread_id = %thread_id, error = %e, "[thread_goals] complete_for_thread failed");}}}-/// Delete the goal row for the ambient thread entirely (the originating task was+/// Delete the goal row for an explicit thread entirely (the originating task was/// abandoned / superseded, and no completion contract should persist).-/// Best-effort; safe to call when there is no goal or no thread scope.+/// Best-effort; safe to call when there is no goal or thread id.////// Clearing removes the row rather than moving it to a terminal status, so a/// later turn loads `None` and injects no `[active_goal]` block at all — the@@ -132,7 +132,7 @@ pub async fn clear_for_thread(workspace_dir: &Path, thread_id: Option<&str>) {match store::clear(workspace_dir, &thread_id).await {Ok(_existed) => {}Err(e) => {- tracing::debug!(thread_id = %thread_id, error = %e, "[thread_goals] clear_for_current_thread failed");+ tracing::debug!(thread_id = %thread_id, error = %e, "[thread_goals] clear_for_thread failed");}}}@@ -157,7 +157,7 @@ fn is_goal_continuation_turn() -> bool {)}-/// Account a finished turn's usage against the ambient thread's goal.+/// Account a finished turn's usage against an explicit thread's goal.////// The accounting rules are the crate's/// ([`crate_budget::account_turn`](tinyagents_graph::goals::account_turn)):@@ -166,7 +166,7 @@ fn is_goal_continuation_turn() -> bool {/// the one-shot continuation suppression (a continuation turn must not clear/// its own, see [`super::continuation`]).///-/// What is OpenHuman's here: reading the ambient thread from the turn scope,+/// What is OpenHuman's here: receiving the owned thread from the turn,/// classifying the turn as user-initiated vs. continuation from its origin, and/// emitting `ThreadGoalUpdated` when the status changes (e.g. →/// `budget_limited`) so the UI chip refreshes. Best-effort throughout: adiff --git a/crates/openhuman-core/src/agent/harness/session/turn/session_io/wrapup.rs b/crates/openhuman-core/src/agent/harness/session/turn/session_io/wrapup.rsindex fe95de6fa2..d7e2da871d 100644--- a/crates/openhuman-core/src/agent/harness/session/turn/session_io/wrapup.rs+++ b/crates/openhuman-core/src/agent/harness/session/turn/session_io/wrapup.rs@@ -40,10 +40,11 @@ impl Agent {let mut messages = base_messages.to_vec();messages.push(ChatMessage::user(instruction));- let chat_model = match self- .turn_model_source- .build_summarizer(effective_model, self.temperature)- {+ let chat_model = match self.turn_model_source.build_summarizer(+ effective_model,+ self.temperature,+ self.thread_id(),+ ) {Ok(model) => model,Err(error) => {tracing::error!(@@ -336,10 +337,11 @@ impl Agent {effective_model: &str,purpose: &str,) -> (String, Option<UsageInfo>) {- let chat_model = match self- .turn_model_source- .build_summarizer(effective_model, self.temperature)- {+ let chat_model = match self.turn_model_source.build_summarizer(+ effective_model,+ self.temperature,+ self.thread_id(),+ ) {Ok(model) => model,Err(error) => {tracing::error!(diff --git a/crates/openhuman-core/src/agent/harness/subagent_runner/extract_tool.rs b/crates/openhuman-core/src/agent/harness/subagent_runner/extract_tool.rsindex a66632a9ee..6b9fad6e14 100644--- a/crates/openhuman-core/src/agent/harness/subagent_runner/extract_tool.rs+++ b/crates/openhuman-core/src/agent/harness/subagent_runner/extract_tool.rs@@ -309,9 +309,9 @@ impl ExtractFromResultTool {// future clones the Arc (issue #4249, Phase 3 / Motion A). Model +// temperature are baked into the model, so the per-call request only// carries the messages.- let chat = self- .source- .build_summarizer(&self.model, EXTRACT_TEMPERATURE)?;+ let chat =+ self.source+ .build_summarizer(&self.model, EXTRACT_TEMPERATURE, thread_id.as_deref())?;// Model id for the per-chunk transcript metadata (the chat call itself// bakes it into `chat`).let model = self.model.clone();@@ -456,7 +456,7 @@ impl ExtractFromResultTool {let call_seq = self.next_call_seq();let provider_result = self.source- .build_summarizer(&self.model, EXTRACT_TEMPERATURE)?+ .build_summarizer(&self.model, EXTRACT_TEMPERATURE, thread_id).invoke(&(),ModelRequest::new(vec![diff --git a/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph/dispatch.rs b/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph/dispatch.rsindex 09d5778108..d89b659a17 100644--- a/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph/dispatch.rs+++ b/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph/dispatch.rs@@ -175,6 +175,12 @@ pub(in super::super) async fn run_subagent_via_graph(),SubagentRunError,> {+ // One resolved thread identity drives every child-facing boundary. An+ // explicit worker/task thread deliberately replaces the inherited parent;+ // otherwise a child remains in its parent's conversation. Do this before+ // constructing *any* model so managed requests, transcript metadata, and+ // the child carrier cannot disagree.+ let thread_id = inherited_thread_id(run_context.thread_id.clone(), thread_id);tracing::info!(model,max_iterations,@@ -205,7 +211,7 @@ pub(in super::super) async fn run_subagent_via_graph(// turn's own model set is consumed by the run). Built off the same source, so// the checkpoint invokes a crate `ChatModel` without naming `Provider`// (issue #4249, Phase 3 / Motion A).- let summary_model = source.build_summarizer(model, temperature)?;+ let summary_model = source.build_summarizer(model, temperature, thread_id.as_deref())?;// Resolve the sub-agent model's effective context window so the harness runs// the context-window summarization step (issue #4249) on sub-agent turns too.@@ -217,12 +223,7 @@ pub(in super::super) async fn run_subagent_via_graph(// Build the child turn's crate `ChatModel` set from the source; capability// reads (vision/native-tools) + telemetry id now come off the built bundle,// so the sub-agent path names crate model types only.- let turn_models = source.build(- model,- temperature,- context_window,- run_context.thread_id.as_deref(),- )?;+ let turn_models = source.build(model, temperature, context_window, thread_id.as_deref())?;// Vision forwarding (parity with the legacy `run_inner_loop`): rehydrate// `[IMAGE:…]` placeholders in the sub-agent's history when either the model@@ -278,7 +279,7 @@ pub(in super::super) async fn run_subagent_via_graph(// A parallel task may omit `thread_id`; that means inherit the parent// conversation, not erase it. Only an explicit task thread may replace// the typed carrier's inherited affinity.- child_context.thread_id = inherited_thread_id(child_context.thread_id, thread_id.clone());+ child_context.thread_id = thread_id.clone();child_context.progress = on_progress.clone().or(child_context.progress);child_context.workspace = workspace_descriptor.clone().or(child_context.workspace);let run_result = Box::pin(run_turn_via_tinyagents_shared(diff --git a/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph_failed_run_tests.rs b/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph_failed_run_tests.rsindex a56fccf119..e411a595e1 100644--- a/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph_failed_run_tests.rs+++ b/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph_failed_run_tests.rs@@ -63,6 +63,8 @@ async fn failed_subagent_run_keeps_its_unanswered_round_out_of_history() {"task-failed",false,None,+ crate::agent::tinyagents::host::OpenHumanRunContext::new(),+ None,workspace.path().to_path_buf(),None,1024,diff --git a/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph_tests.rs b/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph_tests.rsindex 986ef7fed6..a49925c660 100644--- a/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph_tests.rs+++ b/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph_tests.rs@@ -96,6 +96,57 @@ fn parallel_worker_without_thread_keeps_parent_transcript_affinity() {);}+#[tokio::test]+async fn explicit_worker_thread_replaces_parent_for_model_run_and_transcript() {+ let workspace = tempfile::tempdir().expect("workspace");+ let mut parent = crate::agent::tinyagents::host::OpenHumanRunContext::new();+ parent.thread_id = Some("parent-thread".to_owned());+ let mut history = vec![ChatMessage::user("finish this")];++ run_subagent_via_graph(+ crate::agent::tinyagents::TurnModelSource::from_model(Arc::new(TwoStepProvider {+ calls: AtomicUsize::new(1),+ })),+ "mock-model",+ 0.0,+ &mut history,+ Arc::new(vec![]),+ vec![],+ vec![],+ HashSet::new(),+ 2,+ None,+ None,+ "researcher",+ "worker-task",+ false,+ Some("worker-thread".to_owned()),+ parent,+ None,+ workspace.path().to_path_buf(),+ None,+ 1024,+ false,+ "root__worker-thread",+ "test",+ None,+ AgentTokenjuiceCompression::Off,+ None,+ )+ .await+ .expect("worker run");++ let path = crate::agent::harness::session::transcript::resolve_keyed_transcript_path(+ workspace.path(),+ "root__worker-thread",+ )+ .expect("transcript path");+ let persisted = crate::agent::harness::session::transcript::read_transcript(&path)+ .expect("worker transcript");+ assert_eq!(persisted.meta.thread_id.as_deref(), Some("worker-thread"));+ assert_ne!(persisted.meta.thread_id.as_deref(), Some("parent-thread"));+}+#[tokio::test]async fn subagent_runs_through_the_graph_engine_with_real_tools() {let provider = Arc::new(TwoStepProvider {@@ -123,6 +174,7 @@ async fn subagent_runs_through_the_graph_engine_with_real_tools() {false,None,crate::agent::tinyagents::host::OpenHumanRunContext::new(),+ None,std::env::temp_dir(),None,1024,@@ -209,6 +261,7 @@ async fn child_text_and_thinking_deltas_are_scoped_to_the_subagent() {false,None,crate::agent::tinyagents::host::OpenHumanRunContext::new(),+ None,std::env::temp_dir(),None,1024,@@ -345,6 +398,7 @@ async fn ask_user_clarification_pauses_and_surfaces_the_question() {false,None,crate::agent::tinyagents::host::OpenHumanRunContext::new(),+ None,std::env::temp_dir(),None,1024,@@ -437,6 +491,7 @@ async fn cap_hit_summarizes_a_resumable_checkpoint() {false,None,crate::agent::tinyagents::host::OpenHumanRunContext::new(),+ None,std::env::temp_dir(),None,1024,@@ -603,6 +658,7 @@ async fn run_with_spawn_tool_in_parent_surface(allowed: HashSet<String>) -> (boofalse,None,crate::agent::tinyagents::host::OpenHumanRunContext::new(),+ None,std::env::temp_dir(),None,1024,diff --git a/crates/openhuman-core/src/agent/orchestration/tools/dispatch_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/dispatch_tests.rsindex b8fe76b9e0..8cfb42c88d 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/dispatch_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/dispatch_tests.rs@@ -16,6 +16,28 @@ struct DelegationRegistrationTool {parameters: serde_json::Value,}+struct BlockingDelegationTool {+ started: tokio::sync::mpsc::Sender<()>,+}++#[async_trait]+impl Tool for BlockingDelegationTool {+ fn name(&self) -> &str {+ "delegate"+ }+ fn description(&self) -> &str {+ "blocking configured delegate"+ }+ fn parameters_schema(&self) -> serde_json::Value {+ serde_json::json!({})+ }+ async fn execute(&self, _args: serde_json::Value) -> anyhow::Result<tinytools::ToolResult> {+ let _ = self.started.send(()).await;+ std::future::pending::<()>().await;+ unreachable!("the parent cancellation must win")+ }+}+#[async_trait]impl Tool for DelegationRegistrationTool {fn name(&self) -> &str {@@ -108,24 +130,27 @@ async fn delegate_graph_dispatch_uses_its_durable_graph_argument_path() {#[tokio::test]async fn config_delegate_dispatch_honours_the_parent_cancellation_token() {- let tool: Arc<dyn Tool> = Arc::new(DelegationRegistrationTool {- name: "delegate",- parameters: serde_json::json!({}),+ let (started_tx, mut started_rx) = tokio::sync::mpsc::channel(1);+ let tool: Arc<dyn Tool> = Arc::new(BlockingDelegationTool {+ started: started_tx,});let dispatch = DelegateToolDispatch::new(tool);let cancellation = tinyagents_harness::CancellationToken::new();let parent = crate::agent::tinyagents::host::OpenHumanRunContext::new().with_cancellation(cancellation.clone()).into_tinyagents(RunConfig::new("config-delegate-parent").with_thread("thread-parent"));- cancellation.cancel();-- let result = dispatch- .execute(- &(),- serde_json::json!({"agent": "configured", "prompt": "work"}),- tinytools::ToolCallOptions::default(),- &parent,- )+ let execution = dispatch.execute(+ &(),+ serde_json::json!({"agent": "configured", "prompt": "work"}),+ tinytools::ToolCallOptions::default(),+ &parent,+ );+ tokio::pin!(execution);+ tokio::select! {+ _ = started_rx.recv() => cancellation.cancel(),+ result = &mut execution => panic!("blocking delegate returned before cancellation: {result:?}"),+ }+ let result = execution.await.expect("cancellation is reported as a tool result");assert!(result.is_error);diff --git a/crates/openhuman-core/src/agent/tinyagents/README.md b/crates/openhuman-core/src/agent/tinyagents/README.mdindex 44f840f68c..0e3120a56d 100644--- a/crates/openhuman-core/src/agent/tinyagents/README.md+++ b/crates/openhuman-core/src/agent/tinyagents/README.md@@ -106,9 +106,9 @@ Responses project the crate's own `AgentObservation` and `HarnessRunStatus` serdattachments, artifacts, dispatch, cancellation, thread, workspace and stophooks) across the OpenHuman turn boundary. The shared runner builds`RunContext<OpenHumanRunContext>` with `into_tinyagents`, and the OpenHuman-assembly plus middleware stack are specialized to that context. Route and-thread task-local scopes remain only around the drive while legacy tool/model-consumers still require them. Cancellation reaches recursive tools solely+assembly plus middleware stack are specialized to that context. Model and+transcript consumers receive the owned thread through that carrier; no thread+task-local surrounds the drive. Cancellation reaches recursive tools solelythrough the typed parent run.## Notesdiff --git a/crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rs b/crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rsindex 0493153634..e2a529260a 100644--- a/crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rs+++ b/crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rs@@ -421,7 +421,11 @@ impl SubagentPayloadSummarizer {let mut harness: AgentHarness<(), OpenHumanRunContext> = AgentHarness::new();harness.with_policy(policy);let provider_model = super::model::MaxTokensModel::new(- source.build_summarizer(&model, self.definition.temperature)?,+ source.build_summarizer(+ &model,+ self.definition.temperature,+ parent_ctx.data.thread_id.as_deref(),+ )?,max_output_tokens,);harnessdiff --git a/crates/openhuman-core/src/agent/tinyagents/turn_models.rs b/crates/openhuman-core/src/agent/tinyagents/turn_models.rsindex 1f044752cc..b470622f92 100644--- a/crates/openhuman-core/src/agent/tinyagents/turn_models.rs+++ b/crates/openhuman-core/src/agent/tinyagents/turn_models.rs@@ -472,6 +472,7 @@ impl TurnModelSource {&self,model: &str,temperature: f64,+ thread_id: Option<&str>,) -> anyhow::Result<Arc<dyn tinyinference_llm::model::ChatModel<()>>> {if let Some(direct) = &self.direct_model {let profile = direct.profile().cloned().unwrap_or_default();@@ -482,6 +483,28 @@ impl TurnModelSource {));}if let Some(cn) = &self.crate_native {+ let managed = cn+ .primary_override+ .as_deref()+ .map(|provider| {+ let provider = provider.trim();+ provider.is_empty() || provider == "cloud" || provider == "openhuman"+ })+ .unwrap_or_else(|| {+ crate::inference::provider::factory::resolves_to_managed_backend(+ &cn.role, &cn.config,+ )+ });+ if managed {+ return crate::inference::provider::factory::make_openhuman_backend_model_for_thread(+ &cn.role,+ &cn.config,+ model,+ !cn.force_text_mode,+ thread_id,+ )+ .map(|(model, _)| model);+ }let built = match cn.primary_override.as_deref() {Some(ps) => {crate::inference::provider::factory::create_turn_chat_model_from_string(diff --git a/crates/openhuman-core/src/inference/provider/README.md b/crates/openhuman-core/src/inference/provider/README.mdindex 22eb754378..ee8d6c4c34 100644--- a/crates/openhuman-core/src/inference/provider/README.md+++ b/crates/openhuman-core/src/inference/provider/README.md@@ -46,7 +46,7 @@ domain.- `crate::security::credentials` — auth-profile store for BYOK keys and OAuthtokens.- `crate::agent::tinyagents::{routes, host}` — workload routing and explicit run- ambient thread-context plumbing consumed while building a model.+ explicit run-thread plumbing consumed while building a managed model.- `crate::security::live_policy` + `crate::security::egress` — Privacy-Mode`LocalOnly` refusal and `EgressDescriptor` emission at the factory chokepoint(`factory/access_gates.rs`).diff --git a/scripts/ci/agent-runtime-boundary-baseline.json b/scripts/ci/agent-runtime-boundary-baseline.jsonindex 6983e90780..1983a053b5 100644--- a/scripts/ci/agent-runtime-boundary-baseline.json+++ b/scripts/ci/agent-runtime-boundary-baseline.json@@ -9,7 +9,7 @@{"rule": "openhuman-runtime-bridge","path": "crates/openhuman-core/src/agent/harness/graph.rs",- "line": 123,+ "line": 122,"text": "let outcome = run_turn_via_tinyagents_shared(","occurrence": 1},@@ -23,7 +23,7 @@{"rule": "openhuman-runtime-bridge","path": "crates/openhuman-core/src/agent/harness/session/turn/graph.rs",- "line": 120,+ "line": 122,"text": "run_turn_via_tinyagents_shared(","occurrence": 1},@@ -37,7 +37,7 @@{"rule": "openhuman-runtime-bridge","path": "crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph/dispatch.rs",- "line": 279,+ "line": 285,"text": "let run_result = Box::pin(run_turn_via_tinyagents_shared(","occurrence": 1},@@ -72,7 +72,7 @@{"rule": "openhuman-runtime-bridge","path": "crates/openhuman-core/src/agent/tinyagents/mod.rs",- "line": 84,+ "line": 83,"text": "pub(crate) use turn_runner::run_turn_via_tinyagents_shared;","occurrence": 1},@@ -136,70 +136,14 @@"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/goals/continuation.rs","line": 32,- "text": "use crate::agent::tinyagents::thread_context::with_thread_id;",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/goals/continuation.rs",- "line": 33,"text": "use crate::agent::turn_origin::{with_origin, AgentTurnOrigin, TrustedAutomationSource};","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/goals/continuation.rs",- "line": 199,- "text": "let result = with_thread_id(",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/goals/continuation.rs",- "line": 201,- "text": "with_origin(origin, agent.run_single(&prompt)),",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/goals/runtime.rs",- "line": 30,- "text": "use crate::agent::tinyagents::thread_context::current_thread_id;",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/goals/runtime.rs",- "line": 37,- "text": "let thread_id = current_thread_id()?;",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/goals/runtime.rs",- "line": 51,- "text": "let thread_id = current_thread_id()?;",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/goals/runtime.rs",- "line": 73,- "text": "let Some(thread_id) = current_thread_id() else {",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/goals/runtime.rs",- "line": 102,- "text": "let Some(thread_id) = current_thread_id() else {",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/goals/runtime.rs",- "line": 129,- "text": "let Some(thread_id) = current_thread_id() else {",+ "line": 198,+ "text": "let result = with_origin(origin, agent.run_single(&prompt)).await;","occurrence": 1},{@@ -209,13 +153,6 @@"text": "crate::agent::turn_origin::current(),","occurrence": 1},- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/goals/runtime.rs",- "line": 175,- "text": "let Some(thread_id) = current_thread_id() else {",- "occurrence": 1- },{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/harness/fork_context.rs",@@ -279,13 +216,6 @@"text": "AGENT_CONTEXT_PREPARED_SOURCES","occurrence": 1},- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/harness/memory_context.rs",- "line": 122,- "text": "let current_thread_id = crate::agent::tinyagents::thread_context::current_thread_id();",- "occurrence": 1- },{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/harness/mod.rs",@@ -408,49 +338,42 @@{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/harness/session/turn/core_turn.rs",- "line": 288,- "text": "crate::agent::tinyagents::thread_context::current_thread_id();",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/harness/session/turn/core_turn.rs",- "line": 670,+ "line": 667,"text": "harness::with_parent_context(","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/harness/session/turn/core_turn.rs",- "line": 672,+ "line": 669,"text": "harness::with_agent_context_prepared_sources(","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/harness/session/turn/core_turn.rs",- "line": 674,+ "line": 671,"text": "harness::turn_attachments_context::with_current_turn_image_placeholders(","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/harness/session/turn/core_turn.rs",- "line": 682,+ "line": 679,"text": "harness::with_parent_context(","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/harness/session/turn/core_turn.rs",- "line": 684,+ "line": 681,"text": "harness::with_agent_context_prepared_sources(","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/harness/session/turn/core_turn.rs",- "line": 686,+ "line": 683,"text": "harness::turn_attachments_context::with_current_turn_image_placeholders(","occurrence": 1},@@ -471,14 +394,14 @@{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/harness/session/turn/core/harness_turn.rs",- "line": 176,+ "line": 179,"text": "crate::agent::harness::turn_subagent_usage::with_turn_collector(","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/harness/session/turn/core/harness_turn.rs",- "line": 213,+ "line": 217,"text": "crate::agent::harness::turn_dispatch_guard::with_dispatch_guard(","occurrence": 1},@@ -492,7 +415,7 @@{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/harness/session/turn/graph.rs",- "line": 114,+ "line": 116,"text": "with_current_sandbox_mode(graph.sandbox_mode, async {","occurrence": 1},@@ -503,13 +426,6 @@"text": "let result = harness::with_parent_context(parent_ctx, fut).await;","occurrence": 1},- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/harness/session/turn/session_io/transcript_persist.rs",- "line": 56,- "text": "thread_id: crate::agent::tinyagents::thread_context::current_thread_id(),",- "occurrence": 1- },{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/harness/session/turn/session_io/transcript_persist.rs",@@ -723,21 +639,21 @@{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/orchestration/delegation.rs",- "line": 58,+ "line": 57,"text": "run_context.parent = current_parent();","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/orchestration/delegation.rs",- "line": 182,+ "line": 181,"text": "with_parent_context(parent, run).await","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/orchestration/delegation.rs",- "line": 187,+ "line": 186,"text": "with_parent_context(parent, run).await","occurrence": 1},@@ -751,21 +667,21 @@{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/orchestration/ops.rs",- "line": 417,+ "line": 416,"text": "let handle = tokio::spawn(crate::agent::turn_origin::propagate(","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/orchestration/ops.rs",- "line": 418,+ "line": 417,"text": "crate::agent::turn_workspace::propagate(async move {","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/orchestration/ops.rs",- "line": 420,+ "line": 419,"text": "let result = with_parent_context(parent, async move {","occurrence": 1},@@ -1101,99 +1017,15 @@{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/task_dispatcher/executor.rs",- "line": 227,+ "line": 228,"text": "crate::agent::turn_origin::with_origin(","occurrence": 1},{"rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/task_dispatcher/executor.rs",- "line": 234,- "text": "crate::agent::tinyagents::thread_context::with_thread_id(thread_id.to_string(), run)",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/tinyagents/host/run_context.rs",- "line": 91,- "text": "context.origin = crate::agent::turn_origin::current();",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/tinyagents/host/run_context.rs",- "line": 92,- "text": "context.progress = crate::agent::progress_sink::current_progress_sink();",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/tinyagents/host/run_context.rs",- "line": 94,- "text": "context.dispatch = crate::agent::harness::turn_dispatch_guard::current();",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/tinyagents/host/run_context.rs",- "line": 95,- "text": "context.thread_id = crate::agent::tinyagents::thread_context::current_thread_id();",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/tinyagents/host/run_context.rs",- "line": 96,- "text": "context.workspace = crate::agent::turn_workspace::current()",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/tinyagents/mod.rs",- "line": 55,- "text": "pub mod thread_context;",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/tinyagents/thread_context.rs",- "line": 58,- "text": "tokio::task_local! {",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/tinyagents/thread_context.rs",- "line": 59,- "text": "static THREAD_ID: Option<String>;",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/tinyagents/thread_context.rs",- "line": 80,- "text": "THREAD_ID.scope(value, fut).await",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/tinyagents/thread_context.rs",- "line": 86,- "text": "pub fn current_thread_id() -> Option<String> {",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/tinyagents/thread_context.rs",- "line": 87,- "text": "THREAD_ID",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/agent/tinyagents/turn_runner.rs",- "line": 588,- "text": "crate::agent::tinyagents::thread_context::with_thread_id(run_thread_id, async move {",+ "path": "crates/openhuman-core/src/agent/tools/delegate.rs",+ "line": 253,+ "text": ".with_thread_id(tool_context.and_then(ToolRunContext::thread_id));","occurrence": 1},{@@ -1360,21 +1192,14 @@{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/flows/ops/builder.rs",- "line": 175,+ "line": 176,"text": "let run = with_origin(","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/flows/ops/builder.rs",- "line": 184,- "text": "let run = crate::agent::tinyagents::thread_context::with_thread_id(",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/flows/ops/builder.rs",- "line": 232,+ "line": 229,"text": "let run = with_origin(AgentTurnOrigin::Cli, agent.run_single(&prompt));","occurrence": 1},@@ -1388,17 +1213,10 @@{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/flows/ops/discovery.rs",- "line": 73,+ "line": 74,"text": "let run = with_origin(AgentTurnOrigin::Cli, agent.run_single(FLOW_DISCOVER_PROMPT));","occurrence": 1},- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/flows/ops/discovery.rs",- "line": 80,- "text": "crate::agent::tinyagents::thread_context::with_thread_id(target.thread_id.clone(), run)",- "occurrence": 1- },{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/flows/ops/execution.rs",@@ -1458,64 +1276,57 @@{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs",- "line": 217,+ "line": 218,"text": "if let Some(tx) = crate::agent::progress_sink::current_progress_sink() {","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs",- "line": 228,+ "line": 229,"text": "let run = crate::agent::turn_origin::with_origin(","occurrence": 1},{"rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs",- "line": 235,- "text": "crate::agent::tinyagents::thread_context::with_thread_id(id, run).await",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs",- "line": 293,- "text": "crate::agent::tinyagents::thread_context::with_thread_id(id, run).await",+ "path": "crates/openhuman-core/src/inference/host_runtime/ops/turn_guards.rs",+ "line": 134,+ "text": "crate::agent::turn_origin::current()","occurrence": 1},{"rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/inference/host_runtime/ops/turn_guards.rs",- "line": 134,- "text": "crate::agent::turn_origin::current()",+ "path": "crates/openhuman-core/src/inference/provider/factory/managed_backend.rs",+ "line": 126,+ "text": ".with_thread_id(thread_id),","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/inference/provider/openhuman_backend_model.rs",- "line": 448,- "text": "fn with_thread_id(request: ModelRequest) -> ModelRequest {",+ "line": 121,+ "text": "pub fn with_thread_id(mut self, thread_id: Option<impl AsRef<str>>) -> Self {","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/inference/provider/openhuman_backend_model.rs",- "line": 449,- "text": "let Some(thread_id) = thread_context::current_thread_id() else {",+ "line": 463,+ "text": "fn with_thread_id(request: ModelRequest, thread_id: Option<&str>) -> ModelRequest {","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/inference/provider/openhuman_backend_model.rs",- "line": 558,- "text": "let response = match model.invoke(state, with_thread_id(request)).await {",+ "line": 574,+ "text": ".invoke(state, with_thread_id(request, self.thread_id.as_deref()))","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/inference/provider/openhuman_backend_model.rs",- "line": 582,- "text": "match model.stream(state, with_thread_id(request)).await {",+ "line": 601,+ "text": ".stream(state, with_thread_id(request, self.thread_id.as_deref()))","occurrence": 1},{@@ -1724,14 +1535,7 @@{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/voice/realtime_harness/agent.rs",- "line": 159,- "text": "let scoped_run = crate::agent::tinyagents::thread_context::with_thread_id(",- "occurrence": 1- },- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/voice/realtime_harness/agent.rs",- "line": 163,+ "line": 161,"text": "let fut = with_origin(","occurrence": 1},@@ -1742,13 +1546,6 @@"text": "crate::agent::turn_origin::with_origin(","occurrence": 1},- {- "rule": "openhuman-task-local",- "path": "crates/openhuman-core/src/web_chat/run_task.rs",- "line": 265,- "text": "let result = match crate::agent::tinyagents::thread_context::with_thread_id(",- "occurrence": 1- },{"rule": "openhuman-task-local","path": "crates/openhuman-embed/src/lib.rs",