Skip to content

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

fix(subagent_sessions): surface document update errors instead of swallowing them

Steven Enamakela6b80fda645e
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops_tests.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops_tests.rs
index cbcd0b4e3c..211f8ebcfa 100644
--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops_tests.rs
@@ -107,18 +107,33 @@ fn an_equal_millisecond_live_close_persists_and_a_stale_snapshot_cannot_reopen_i
let storage = MemoryStorage::new();
let docs = Docs::over(&storage.for_scope(&Scope::new("local").unwrap()).unwrap());
- let original = session("equal-ms-close");
- docs.save(std::slice::from_ref(&original)).unwrap();
- let stale_snapshot = docs.load().unwrap();
let store = SubagentSessionStore::new(std::env::temp_dir());
+ let original = with_override(docs.clone(), || {
+ upsert_running(
+ &store,
+ SubagentSessionUpsert {
+ selector: selector("equal-ms-close"),
+ display_name: None,
+ task_title: "Task".into(),
+ worker_thread_id: None,
+ task_id: "task-id".into(),
+ },
+ None,
+ )
+ .unwrap()
+ });
+ let stale_snapshot = docs.load().unwrap();
with_override(docs.clone(), || {
- let mut equal_ms_closed = original.clone();
- equal_ms_closed.status = DurableSubagentStatus::Closed;
- equal_ms_closed.reusable = false;
- // Deliberately preserve the same `_ms` value. A close can occur
- // inside the same millisecond as the last update.
- store.save(&[equal_ms_closed]).unwrap();
+ store
+ .update_session(&original.subagent_session_id, |current, _now| {
+ current.status = DurableSubagentStatus::Closed;
+ current.reusable = false;
+ // Deliberately leave updated_at unchanged to force an equal
+ // `_ms` live transition without a clock shim or sleep.
+ })
+ .unwrap()
+ .expect("the session is updated");
// A whole-list snapshot at the same timestamp must not reopen it.
store.save(&stale_snapshot).unwrap();
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents.rs
index dc732c92e5..775b0505d7 100644
--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents.rs
+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents.rs
@@ -211,26 +211,28 @@ impl Docs {
F: FnMut(&mut DurableSubagentSession, String) + Send,
{
let id = key_of(subagent_session_id)?;
- self.0.run(|docs| async move {
+ let updated = self.0.run(|docs| async move {
let repo = tinystoragedrivers::Repo::<Value>::new(&docs, SESSIONS)?;
- let updated = repo
- .update(&id, move |current| {
- let Some(current) = current else {
- return Ok(None);
- };
- let stored: StoredSession = serde_json::from_value(current)?;
- let mut session = DurableSubagentSession::from(stored);
- update(&mut session, chrono::Utc::now().to_rfc3339());
- Ok(Some(serde_json::to_value(StoredSession::from(&session))?))
- })
- .await?;
- updated
- .map(|(stored, _)| {
- serde_json::from_value::<StoredSession>(stored)
- .map(DurableSubagentSession::from)
- })
- .transpose()
- })
+ repo.update(&id, move |current| {
+ let Some(current) = current else {
+ return Ok(None);
+ };
+ let stored: StoredSession = serde_json::from_value(current)
+ .map_err(|error| crate::storage::StorageError::backend(error.to_string()))?;
+ let mut session = DurableSubagentSession::from(stored);
+ update(&mut session, chrono::Utc::now().to_rfc3339());
+ let next = serde_json::to_value(StoredSession::from(&session))
+ .map_err(|error| crate::storage::StorageError::backend(error.to_string()))?;
+ Ok(Some(next))
+ })
+ .await
+ .map(|updated| updated.map(|(value, _)| value))
+ })?;
+ updated
+ .map(|value| {
+ serde_json::from_value::<StoredSession>(value).map(DurableSubagentSession::from)
+ })
+ .transpose()
}
/// Whether the one-time legacy file import finished in this scope.