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
refactor(session-import): remove live dual-write and shadow-read code
Steven Enamakel416665a8b374
diff --git a/crates/openhuman-core/src/agent/session_import/live.rs b/crates/openhuman-core/src/agent/session_import/live.rsindex 727bc27837..c133417a5b 100644--- a/crates/openhuman-core/src/agent/session_import/live.rs+++ b/crates/openhuman-core/src/agent/session_import/live.rs@@ -21,8 +21,8 @@use std::path::Path;use std::sync::Arc;-use anyhow::{Context, Result};-use tinyagents_harness::store::{AppendStore, Store};+use tinyagents_harness::store::Store;+use tinyagents_session::transcript::import::ops::{open_session_stores, SessionStores};use tinyagents_session::transcript::SessionTranscript;@@ -126,87 +126,6 @@ pub async fn session_kv_store() -> Option<Arc<dyn Store>> {Some(Arc::new(kv))}-/// Mirror one completed turn's transcript into the TinyAgents store.-///-/// Best-effort: the caller must treat any returned error as non-fatal (log and-/// swallow) — it never fails or alters the legacy chat turn.-///-/// Mirrors the importer's **full-rewrite** semantics: the legacy JSONL-/// transcript is rewritten in full on every turn (not appended), and the-/// `JsonlAppendStore` has no truncate, so the journal stream file is dropped and-/// re-appended each turn. This keeps the store stream shape-identical to an-/// import of the final JSONL. The descriptor is upserted in `NS_SESSIONS`-/// exactly as the importer would, reusing [`build_descriptor`].-pub async fn write_live_turn(- workspace: &Path,- session_key: &str,- transcript: &SessionTranscript,-) -> Result<()> {- log::debug!(- "[session-store] dual-write enter stem={session_key} workspace={} messages={}",- workspace.display(),- transcript.messages.len()- );-- let SessionStores {- kv,- journal,- journal_root,- } = open_session_stores(workspace);-- let stream = stream_name(session_key);-- // Full-rewrite parity: drop the stream file, then re-append every message so- // the journal reflects the current transcript exactly (the importer resets- // the same way on re-import). Layout: `{journal_root}/{stream}.jsonl`.- let stream_file = journal_root.join(format!("{stream}.jsonl"));- if stream_file.exists() {- std::fs::remove_file(&stream_file)- .with_context(|| format!("reset journal stream {stream}"))?;- }-- let records = journal_messages(transcript);- let message_count = records.len();- for (idx, record) in records.iter().enumerate() {- let value = serde_json::to_value(record)- .with_context(|| format!("serialize live message {idx}"))?;- journal- .append(&stream, value)- .await- .with_context(|| format!("journal append failed at message {idx}"))?;- }-- // Descriptor: same projection the importer uses. No run-ledger join here- // (live turns have no `agent_runs` link yet) and zero warnings; the source- // pointer records the workspace-relative JSONL twin.- let (thread_id, synthesized) =- effective_thread_id(session_key, transcript.meta.thread_id.as_deref());- let descriptor = build_descriptor(- session_key,- transcript,- thread_id,- synthesized,- Vec::new(),- DescriptorSource {- jsonl: Some(format!("session_raw/{session_key}.jsonl")),- md: None,- },- chrono::Utc::now().to_rfc3339(),- 0,- );- let descriptor_key = sanitize_store_name(session_key);- let descriptor_value =- serde_json::to_value(&descriptor).context("serialize live session descriptor")?;- kv.put(NS_SESSIONS, &descriptor_key, descriptor_value)- .await- .context("descriptor write failed")?;-- log::debug!(- "[session-store] dual-write exit stem={session_key} stream={stream} messages={message_count}"- );- Ok(())-}-// ─────────────────────────────────────────────────────────────────────────────// Store-backed SHADOW READ (issue #4249, sessions 04.2 phase 2)//@@ -237,117 +156,3 @@ pub fn shadow_reads_enabled(config_enabled: bool) -> bool {);enabled}--/// Outcome of one shadow-read comparison. Returned for tests/observability;-/// the compact divergence summary is also logged (`[session_shadow_read]`).-#[derive(Debug, Clone, PartialEq, Eq)]-pub enum ShadowReadOutcome {- /// The store stream rendered exactly the legacy transcript's messages.- Match { messages: usize },- /// The store stream diverged from the legacy render. Carries only compact- /// counts + the first differing index — never message bodies (PII).- Divergence {- legacy: usize,- shadow: usize,- first_diff: Option<usize>,- },- /// No shadow available: the store read errored, or the stream is- /// empty/absent for a non-empty legacy transcript (e.g. dual-write was off- /// when this session was written). Treated as non-divergent — the legacy- /// read is authoritative regardless.- Unavailable,-}--/// Read a session's messages back from the crate journal store-/// (`{workspace}/tinyagents_store/journal`, stream `session.{stem}.messages`)-/// as normalized [`JournalMessage`]s — the same shape the importer and live-/// dual-write write. A missing stream yields an empty vec (not an error).-async fn read_shadow_messages(workspace: &Path, session_key: &str) -> Result<Vec<JournalMessage>> {- let SessionStores { journal, .. } = open_session_stores(workspace);- let stream = stream_name(session_key);- let records = journal- .read_from(&stream, 0)- .await- .with_context(|| format!("shadow read of stream {stream}"))?;- let mut out = Vec::with_capacity(records.len());- for (offset, value) in records {- let msg: JournalMessage = serde_json::from_value(value)- .with_context(|| format!("shadow record shape at offset {offset}"))?;- out.push(msg);- }- Ok(out)-}--/// Shadow-read the given session back from the store and compare it against the-/// legacy transcript, logging divergence. Legacy stays authoritative — the-/// caller ignores the returned outcome for control flow (it exists for tests /-/// observability). Best-effort: any store-read error is logged at debug and-/// reported as [`ShadowReadOutcome::Unavailable`]; it never breaks or slows the-/// authoritative read.-///-/// Both sides are normalized through the importer's `convert` machinery-/// ([`journal_messages`]) so live/legacy renders are directly comparable, then-/// compared by message count and normalized content. On mismatch a **compact**-/// summary (counts + first differing index) is warn-logged; message bodies are-/// never emitted (PII).-pub async fn shadow_read_compare(- workspace: &Path,- session_key: &str,- legacy: &SessionTranscript,-) -> ShadowReadOutcome {- let expected = journal_messages(legacy);- log::debug!(- "[session_shadow_read] enter stem={session_key} workspace={} legacy_messages={}",- workspace.display(),- expected.len()- );-- let shadow = match read_shadow_messages(workspace, session_key).await {- Ok(v) => v,- Err(err) => {- log::debug!(- "[session_shadow_read] store read error stem={session_key}: {err:#} — no shadow available"- );- return ShadowReadOutcome::Unavailable;- }- };-- // Empty/absent store stream against a non-empty legacy transcript: the- // session simply was not mirrored (dual-write off when it was written).- // Treat as "no shadow" rather than a spurious divergence.- if shadow.is_empty() && !expected.is_empty() {- log::debug!(- "[session_shadow_read] no store stream stem={session_key} legacy_messages={} — no shadow available",- expected.len()- );- return ShadowReadOutcome::Unavailable;- }-- if shadow == expected {- log::debug!(- "[session_shadow_read] parity OK stem={session_key} messages={}",- expected.len()- );- return ShadowReadOutcome::Match {- messages: expected.len(),- };- }-- // Divergence: first index where the two normalized renders differ, or the- // shorter length when one is a strict prefix of the other. Compact only.- let first_diff = expected- .iter()- .zip(shadow.iter())- .position(|(a, b)| a != b)- .or_else(|| (expected.len() != shadow.len()).then(|| expected.len().min(shadow.len())));- log::warn!(- "[session_shadow_read] DIVERGENCE stem={session_key} legacy_count={} shadow_count={} first_diff={first_diff:?}",- expected.len(),- shadow.len()- );- ShadowReadOutcome::Divergence {- legacy: expected.len(),- shadow: shadow.len(),- first_diff,- }-}diff --git a/vendor/tinyagents b/vendor/tinyagentsindex efd33ffadd..88fce06086 160000--- a/vendor/tinyagents+++ b/vendor/tinyagents@@ -1 +1 @@-Subproject commit efd33ffaddebeced9b444355ad19cc064e3bb02a+Subproject commit 88fce06086991260e5cb9f22d05b9157f854cad3