Skip to content

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

feat(web_chat): add session lease tracking to web chat turns

Steven Enamakel7be33088cb63
diff --git a/crates/openhuman-core/src/web_chat/runner.rs b/crates/openhuman-core/src/web_chat/runner.rs
index 56186676fc..df716a49c3 100644
--- a/crates/openhuman-core/src/web_chat/runner.rs
+++ b/crates/openhuman-core/src/web_chat/runner.rs
@@ -28,6 +28,7 @@ use super::turn_events::{WebEvents, WebFailures, WebReplies, WebSummarizer};
use super::turn_host::WebHost;
use super::types::WebChatTaskResult;
use crate::agent::queued_turn::QueuedPayload;
+use crate::agent::session_lease::{SessionLease, SessionLeaseKey};
use crate::core::runtime::DispatchCtx;
pub(super) type WebRunner = TurnRunner<
@@ -79,6 +80,9 @@ pub(super) struct CancelNote {
pub(super) struct TurnSlot {
pub(super) activity: TurnActivity,
pub(super) session: Option<CheckedOutSession>,
+ /// Cross-surface lease survives TinyAgents' early `checkin` until the
+ /// terminal projection has finished delivering this turn.
+ pub(super) session_lease: Option<SessionLease>,
pub(super) fork: bool,
pub(super) config: Option<Arc<crate::config::Config>>,
pub(super) thread_dir: Option<std::path::PathBuf>,
diff --git a/crates/openhuman-core/src/web_chat/turn_host.rs b/crates/openhuman-core/src/web_chat/turn_host.rs
index b8ad859930..cbf1322d04 100644
--- a/crates/openhuman-core/src/web_chat/turn_host.rs
+++ b/crates/openhuman-core/src/web_chat/turn_host.rs
@@ -89,6 +89,23 @@ impl WebHost {
let ctx = Self::ctx_of(request)?;
let id = request.request_id.as_str();
let payload = &request.payload;
+ // The harness lock is local to this WebRuntime. Native channel and
+ // relay runners use the same agent-domain lease before checking out
+ // this durable identity, so separate surface runners cannot resume
+ // and commit the same transcript concurrently.
+ let tenant = ctx.tenant().map_err(|error| error.to_string())?;
+ let tenant_scope = crate::core::runtime::tenant::tenant_key(&tenant, "");
+ let lease = crate::agent::session_lease::SessionLease::acquire(
+ crate::agent::session_lease::SessionLeaseKey::new(
+ tenant_scope,
+ request.scope.agent_id.clone(),
+ request.thread_id.clone(),
+ ),
+ None,
+ )
+ .await
+ .map_err(|()| "agent session lease was cancelled".to_owned())?;
+ self.shared.with(id, |slot| slot.session_lease = Some(lease));
// A follow-up the runner dispatches after its predecessor finished was
// admitted when it was queued; one started directly still has its
// admission to answer.