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(archivist): bound the recap fold at 90s instead of 600s
Shanu089bb23d72de
diff --git a/src/openhuman/agent/harness/archivist/recap.rs b/src/openhuman/agent/harness/archivist/recap.rsindex 31932d778b..590b998e58 100644--- a/src/openhuman/agent/harness/archivist/recap.rs+++ b/src/openhuman/agent/harness/archivist/recap.rs@@ -5,6 +5,7 @@ use super::types::ArchivistHook;use crate::openhuman::memory::api::provider::{ConversationSegment, EpisodicTurn, SummaryContext, SummaryInput,};+use std::time::Duration;// The fold itself is `MemoryTree::summarise` now, so the DTOs are the// contract's owned ones and `tree_kind` is the wire string the driver// validates rather than the engine's `TreeKind` enum (#5560).@@ -28,6 +29,34 @@ const INPUT_TOKEN_BUDGET: u32 = 50_000;/// See [`INPUT_TOKEN_BUDGET`] for why this is a copy.const SUMMARY_OVERHEAD_RESERVE_TOKENS: u32 = 2_048;+/// How long a segment recap may take before the turn stops waiting for it.+///+/// This bound is **reasoned, not measured** — say so plainly, because the+/// number should be re-tuned the moment someone has real folds to look at.+/// The attempt to measure it (#6200) produced nothing usable: the workspace it+/// ran in had no summariser configured, so every fold short-circuited to the+/// heuristic without a network call.+///+/// Three things set it:+///+/// - **600 s is what it replaces.** `tinyinference`'s request default is the+/// only bound under this call today, and `ChatPrompt` carries no per-call+/// override, so a summariser that accepts a connection and then goes silent+/// holds the turn for ten minutes.+/// - **It must clear two attempts.** `tinymemory`'s retry gives up on a further+/// attempt once ~20 s have elapsed, so its realistic worst case is two folds+/// back to back. A deadline under that would cut the chain before the second+/// attempt and quietly turn the retry into dead code.+/// - **Overshooting is cheap now, undershooting is not.** Since #6156 a fold+/// that misses this writes nothing and leaves the segment `'closed'` for the+/// recovery pass, so a healthy-but-slow fold is deferred rather than lost.+/// Cutting a good fold short only churns.+///+/// Compare `AUTO_RECALL_BUDGET` (5 s), which bounds a *retrieval* on the same+/// turn path and was set from a field measurement. A fold is an LLM generation+/// over up to `INPUT_TOKEN_BUDGET` tokens, so it is not the same kind of wait.+const RECAP_DEADLINE: Duration = Duration::from_secs(90);+/// Fold one segment's corpus through the **guarded** driver's tree family.////// The guard rather than the archivist's own provider handle, because@@ -268,14 +297,42 @@ impl ArchivistHook {"[archivist] summarize_entries: LLM recap segment={segment_id} entries={}",entries.len());- // #6200: timed because this await is on the turn path — the- // caller's `flush_open_segment` is awaited before a turn- // returns — and the only bound under it today is- // tinyinference's 600s request default. The measurement is- // what a deadline should be chosen from; logging it first- // means the number comes from real folds rather than a guess.+ // #6200: bounded because this await is on the turn path — the+ // caller's `flush_open_segment` runs before a turn returns — and+ // the only bound under it otherwise is tinyinference's 600 s+ // request default. Wrapping here rather than passing a timeout+ // down keeps it host-side: `ChatPrompt` has no timeout field, so+ // the alternative is a `tinymemory` contract change, a release+ // and a re-pin. It also bounds the whole retry chain rather than+ // a single attempt, which is the thing the turn actually waits+ // on. `elapsed_ms` rides every arm so the number above can be+ // re-tuned from real folds.let started = std::time::Instant::now();- let summary_result = fold_through_driver(&corpus_inputs, &summary_ctx).await;+ let summary_result = match tokio::time::timeout(+ RECAP_DEADLINE,+ fold_through_driver(&corpus_inputs, &summary_ctx),+ )+ .await+ {+ Ok(result) => result,+ Err(_) => {+ // WARN, not debug: a fold that outlasts the deadline+ // held the turn for the whole of it, and that is the+ // symptom worth finding in a log. Falls through to+ // the same `(bookend, false)` the error arm returns,+ // so nothing is persisted and the segment keeps the+ // marker a later pass selects on.+ tracing::warn!(+ "[archivist] summarize_entries: recap exceeded {:?} — \+ segment={segment_id} left unsummarised for a later pass",+ RECAP_DEADLINE+ );+ return (+ super::boundary::fallback_summary(first, last, turn_count),+ false,+ );+ }+ };let elapsed_ms = started.elapsed().as_millis();match summary_result {diff --git a/src/openhuman/agent/harness/archivist/recap_tests.rs b/src/openhuman/agent/harness/archivist/recap_tests.rsindex 6f842dfba8..7a16c68bd7 100644--- a/src/openhuman/agent/harness/archivist/recap_tests.rs+++ b/src/openhuman/agent/harness/archivist/recap_tests.rs@@ -59,3 +59,28 @@ fn segment_membership_falls_back_to_episodic_id() {assert!(entry(None, Some(25), 101.0).is_in_segment(&segment));assert!(!entry(None, Some(26), 100.001).is_in_segment(&segment));}++/// The recap deadline clears two of `tinymemory`'s retry attempts.+///+/// Not a behavioural test — an arithmetic one, and it exists because the two+/// numbers live in different repositories and nothing else would catch them+/// drifting apart. `tinymemory`'s retry stops starting further attempts once+/// ~20 s have elapsed, so its realistic worst case is two folds back to back.+/// A `RECAP_DEADLINE` under that would cut the chain before the second attempt+/// and silently turn the retry into dead code — the failure this pins.+#[test]+fn the_recap_deadline_leaves_room_for_the_drivers_retry() {+ const TINYMEMORY_RETRY_CEILING: Duration = Duration::from_secs(20);++ assert!(+ RECAP_DEADLINE > TINYMEMORY_RETRY_CEILING * 2,+ "RECAP_DEADLINE ({RECAP_DEADLINE:?}) must clear two attempts of the \+ driver's {TINYMEMORY_RETRY_CEILING:?} retry window, or the retry can \+ never fire a second attempt"+ );+ assert!(+ RECAP_DEADLINE < Duration::from_secs(600),+ "RECAP_DEADLINE must stay well under tinyinference's 600s request \+ default, which is the bound it exists to replace"+ );+}diff --git a/src/openhuman/agent/harness/session/turn/core_turn.rs b/src/openhuman/agent/harness/session/turn/core_turn.rsindex 3cf56aa274..dea2f2473e 100644--- a/src/openhuman/agent/harness/session/turn/core_turn.rs+++ b/src/openhuman/agent/harness/session/turn/core_turn.rs@@ -673,13 +673,26 @@ impl Agent {// archivist sub-agent that will distil durable facts into the// workspace MEMORY.md file via the `update_memory_md` tool.//- // The spawn is fire-and-forget: the main turn returns the- // user-visible response immediately, and the archivist runs- // asynchronously on the `agentic` tier. We optimistically mark- // the extraction complete right away — if it actually fails,- // we'll just retry on the next threshold window (a few turns- // later), which is the right amount of retry behaviour for a- // librarian task that's idempotent across reruns.+ // The archivist sub-agent itself is spawned and runs asynchronously+ // on the `agentic` tier. We optimistically mark the extraction+ // complete right away — if it actually fails, we'll just retry on the+ // next threshold window (a few turns later), which is the right amount+ // of retry behaviour for a librarian task that's idempotent across+ // reruns.+ //+ // This call is NOT fire-and-forget, despite spawning one (#6200). It+ // is awaited, and before it spawns anything it awaits+ // `flush_open_segment`, so the trailing segment's recap runs on this+ // path — `result` below is returned only afterwards. The comment here+ // used to claim the turn returned immediately; it did not, and with+ // `tinyinference`'s 600 s request default underneath that was up to ten+ // minutes of a held-open turn. `RECAP_DEADLINE` in `archivist::recap`+ // is what bounds it now.+ //+ // Detaching the flush instead would match the old comment, but it would+ // drop the `GUARANTEE:` documented at the flush site — that the+ // trailing segment always receives its recap before wind-down. Bounding+ // the wait keeps that promise and removes the hazard.if result.is_ok() && self.context.should_extract_session_memory() {self.spawn_session_memory_extraction(session_memory_parent_context).await;