Skip to content

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

refactor(tinyagents): adjust child context initialization and error handling

Steven Enamakelfa400b15d8ba
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
index 6e2c92c204..747ce74cc3 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -639,8 +639,6 @@ impl OpenHumanRunContext {
// child's parks route through the origin and are marked detached, so
// their cards survive the parent turn's end (#5499).
child.approval = Default::default();
- child.model_budget = None;
- child.dispatch_admission = None;
child.dispatch = None;
child.subagent_usage = Arc::new(Mutex::new(Vec::new()));
child.parent_subagent_usage = None;
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs
index 67980f4d43..c71cac6b5b 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs
@@ -451,7 +451,7 @@ fn child_inherits_the_same_physical_dispatch_admission() {
}
#[test]
-fn detached_child_does_not_inherit_parent_dispatch_admission() {
+fn detached_child_retains_the_parent_dispatch_admission() {
let admission: Arc<dyn crate::agent::tinyagents::budget::PhysicalDispatchAdmission> =
Arc::new(TestAdmission);
let parent = OpenHumanRunContext {
@@ -459,7 +459,10 @@ fn detached_child_does_not_inherit_parent_dispatch_admission() {
..OpenHumanRunContext::new()
};
- assert!(parent.detached_child().dispatch_admission.is_none());
+ assert!(Arc::ptr_eq(
+ parent.dispatch_admission.as_ref().unwrap(),
+ parent.detached_child().dispatch_admission.as_ref().unwrap()
+ ));
}
struct TestAdmission;
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_run_error.rs b/crates/openhuman-core/src/agent/tinyagents/turn_run_error.rs
index 04435a05d6..ebf779597e 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_run_error.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_run_error.rs
@@ -31,6 +31,16 @@ pub(super) async fn map_turn_run_error(
if let Some(journal) = turn_journal {
journal.finish_failed(&e.to_string()).await;
}
+ // A host admission refusal is a terminal policy result, not a provider
+ // failure. Preserve its typed source before consulting the provider error
+ // slot, which may still contain an earlier successful route's stale error.
+ if let tinyagents_harness::TinyAgentsError::PhysicalDispatchAdmission(refusal) = &e {
+ error_slot
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .take();
+ return anyhow::Error::new(*refusal);
+ }
// The harness owns the ordering-sensitive classification; the host only
// maps each kind onto its typed error.
match classify_run_failure(&e) {