Skip to content

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

test(session_host): cover deferred tail context isolation

Steven Enamakeld181bb448494
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/post_commit_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/post_commit_tests.rs
index f9e8aae93e..2b02a2b221 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session/post_commit_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/post_commit_tests.rs
@@ -89,3 +89,25 @@ async fn completion_is_published_before_slow_post_commit_work_finishes() {
async fn await_pending_is_a_no_op_without_deferred_work() {
await_pending(None).await;
}
+
+/// The deferred tail acts for the context it was handed, not for whichever
+/// context is active on the task that published the completion.
+#[tokio::test]
+async fn deferred_tail_runs_under_the_handed_context_not_the_active_one() {
+ use crate::core::runtime::{CoreContext, DispatchCtx, DomainSet};
+
+ let handed = CoreContext::for_test(DomainSet::full(), None);
+ let active = CoreContext::for_test(DomainSet::full(), None);
+ let (seen_tx, seen_rx) = tokio::sync::oneshot::channel();
+ let tail = async move {
+ let _ = seen_tx.send(CoreContext::scoped());
+ };
+ let dispatch = DispatchCtx::new(std::sync::Arc::clone(&handed));
+ let (_, pending) = CoreContext::scope(active, async {
+ complete_then_defer(&dispatch, async { true }, tail).await
+ })
+ .await;
+ pending.await.expect("tail finishes");
+ let seen = seen_rx.await.expect("tail ran").expect("tail has a context");
+ assert!(std::sync::Arc::ptr_eq(&seen, &handed));
+}