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(subagent_sessions): stop deleting sessions on save
Steven Enamakel3774591d887d
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.rsindex e38ad69e63..f0efee62d5 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@@ -13,13 +13,13 @@//!//! The file store loads and saves the whole list, last writer wins. `save`//! keeps that contract for the callers in `ops.rs`, but writes each session as-//! its own document (and deletes the ones the list no longer holds), so a-//! session's history stays well under any document-size limit and two-//! processes only collide on a session they both changed.+//! its own document, so a session's history stays well under any document-size+//! limit and two processes only collide on a session they both changed. `save`+//! never deletes: `ops.rs` only replaces a session (remove then re-add the same+//! id) and never drops one, and a delete sweep over a stale snapshot would+//! remove sessions another process added meanwhile.use anyhow::Result;-use std::collections::HashSet;-use serde_json::Value;use tinystoragedrivers::{CollectionSpec, Precondition, Query, Sort};@@ -93,16 +93,9 @@ impl Docs {}log::debug!("[subagent_sessions] document save count={}", writes.len());self.0.run(|docs| async move {- let keep: HashSet<String> = writes.iter().map(|(id, _)| id.clone()).collect();for (id, doc) in writes {docs.put(SESSIONS, &id, doc, Precondition::None).await?;}- for stored in docs.query_all(SESSIONS, &Query::all()).await? {- if !keep.contains(&stored.id) {- docs.delete(SESSIONS, &stored.id, Precondition::None)- .await?;- }- }Ok(())})}diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents_tests.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents_tests.rsindex ffe97a82c5..0dc5167628 100644--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents_tests.rs@@ -42,17 +42,22 @@ fn a_missing_list_loads_empty() {}#[test]-fn save_replaces_the_whole_list() {+fn save_upserts_sessions_and_keeps_the_others() {let docs = docs_in(&MemoryStorage::new(), "local");docs.save(&[session("a"), session("b")]).unwrap();let loaded = docs.load().unwrap();assert_eq!(loaded.len(), 2);assert_eq!(loaded[0].subagent_session_id, "a");assert_eq!(loaded[1].status, DurableSubagentStatus::Idle);- docs.save(&[session("c")]).unwrap(); // a, b are deleted- let loaded = docs.load().unwrap();- assert_eq!(loaded.len(), 1);- assert_eq!(loaded[0].subagent_session_id, "c");+ // A save from a stale snapshot never removes a session it does not know.+ docs.save(&[session("c")]).unwrap();+ let ids: Vec<_> = docs+ .load()+ .unwrap()+ .into_iter()+ .map(|s| s.subagent_session_id)+ .collect();+ assert_eq!(ids, ["a", "b", "c"]);}#[test]diff --git a/scripts/ci/check-storage-bypass.mjs b/scripts/ci/check-storage-bypass.mjsindex 66543db64b..4e6487837c 100755--- a/scripts/ci/check-storage-bypass.mjs+++ b/scripts/ci/check-storage-bypass.mjs@@ -181,11 +181,16 @@ export function codeOf(line) {export function scan(rel, source) {const found = [];const occurrences = new Map();- for (const [index, raw] of source.split(/\r?\n/).entries()) {+ const lines = source.split(/\r?\n/);+ for (const [index, raw] of lines.entries()) {const code = codeOf(raw);if (!code.trim()) continue;+ // A call may break between the path and its `(`: look one line ahead, and+ // count a match only when it starts on this line.+ const searchable = `${code}\n${codeOf(lines[index + 1] ?? "")}`;for (const { rule, pattern } of RULES) {- if (!pattern.test(code)) continue;+ const hit = pattern.exec(searchable);+ if (!hit || hit.index >= code.length) continue;const text = raw.trim();const key = `${rule}\0${text}`;const occurrence = (occurrences.get(key) ?? 0) + 1;