Skip to content

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

fix(archivist): only recover segments when the summariser just answered

Shanu094dd829018c
diff --git a/src/openhuman/agent/harness/archivist/hook_impl.rs b/src/openhuman/agent/harness/archivist/hook_impl.rs
index 4c7e1bf23c..10b628c0a0 100644
--- a/src/openhuman/agent/harness/archivist/hook_impl.rs
+++ b/src/openhuman/agent/harness/archivist/hook_impl.rs
@@ -158,19 +158,28 @@ impl PostTurnHook for ArchivistHook {
// moves the tree write to segment granularity inside on_segment_closed.
if let Some(ref segment) = closed_segment {
let now = Self::now_timestamp();
- self.on_segment_closed(segment, session_id, now).await;
+ let recap_succeeded = self.on_segment_closed(segment, session_id, now).await;
// Recover segments an earlier failed recap left unsummarised
// (#6186). Driven from here rather than from a timer because a
- // close that just happened is first-hand evidence that the
- // summariser is answering *now* — a scheduler would have to guess,
- // and would spend its budget against a provider that is still down.
+ // recap that just succeeded is first-hand evidence that the
+ // summariser is answering *now* — a scheduler would have to guess.
+ //
+ // The gate is load-bearing, not a nicety. `resummarise_pending`
+ // spends a per-segment attempt budget, and running it while the
+ // provider is still down would burn that budget on calls that
+ // cannot succeed: two segment closes during one outage would
+ // exhaust every pending segment's retries and skip them for the
+ // rest of the process — including after the provider came back.
+ // The outage would consume the recovery it is supposed to trigger.
//
// Deliberately not called from `flush_open_segment`, the other
// caller of `on_segment_closed`: that one is awaited unbounded at
// session wind-down, and opportunistic recovery must never be
// charged to how long the app takes to close. This path is a
// detached post-turn hook, so the time is invisible.
- self.resummarise_pending(now).await;
+ if recap_succeeded {
+ self.resummarise_pending(now).await;
+ }
}
tracing::debug!("[archivist] turn indexed successfully: session={session_id}");
diff --git a/src/openhuman/agent/harness/archivist/lifecycle.rs b/src/openhuman/agent/harness/archivist/lifecycle.rs
index aceb0dafda..600b293ee8 100644
--- a/src/openhuman/agent/harness/archivist/lifecycle.rs
+++ b/src/openhuman/agent/harness/archivist/lifecycle.rs
@@ -331,12 +331,20 @@ impl ArchivistHook {
///
/// Soft-fallback contract (mirrors `LlmSummariser`): this function
/// never returns `Err`; all failures are logged and ignored.
+ /// Returns whether a usable LLM recap was produced for this segment.
+ ///
+ /// The caller uses it as a liveness signal, not as a success code: a `true`
+ /// means the summariser answered *just now*, which is the only first-hand
+ /// evidence the app gets that it is reachable. `false` covers every reason
+ /// a recap did not happen — no driver, no entries, no summariser, or a
+ /// summariser that failed — because none of them are a moment to spend
+ /// budget re-trying older segments against the same provider (#6186).
pub(super) async fn on_segment_closed(
&self,
segment: &ConversationSegment,
session_id: &str,
now: f64,
- ) {
+ ) -> bool {
// Gather the conversation text for this segment. Prefer the
// md-backed memory_archivist read when config is available; fall
// back to the driver's episodic family otherwise.
@@ -356,7 +364,7 @@ impl ArchivistHook {
"[archivist] segment={} has no entries — skipping recap",
segment.segment_id
);
- return;
+ return false;
}
// Build segment text from user messages (for event extraction).
@@ -376,7 +384,7 @@ impl ArchivistHook {
// driver, not the summary: with no episodic family there is nothing to
// write on either arm, and this is the exit that path has always taken.
let Some(episodic) = self.episodic() else {
- return;
+ return false;
};
if recap_is_usable(from_llm, &summary) {
@@ -557,6 +565,8 @@ impl ArchivistHook {
);
}
}
+
+ recap_is_usable(from_llm, &summary)
}
/// Embed `summary` for `segment_id` and write the per-model embedding row.
diff --git a/src/openhuman/agent/harness/archivist/lifecycle_tests.rs b/src/openhuman/agent/harness/archivist/lifecycle_tests.rs
index e9fc0e3477..858aa2194c 100644
--- a/src/openhuman/agent/harness/archivist/lifecycle_tests.rs
+++ b/src/openhuman/agent/harness/archivist/lifecycle_tests.rs
@@ -77,7 +77,16 @@ async fn heuristic_recap_is_not_persisted_or_embedded() {
let provider: Arc<dyn MemoryProvider> = recording.clone();
let hook = ArchivistHook::new(provider, true);
- hook.on_segment_closed(&segment(), SESSION, 200.0).await;
+ let recap_succeeded = hook.on_segment_closed(&segment(), SESSION, 200.0).await;
+
+ // #6186: the caller gates the re-summarisation pass on this. Reporting
+ // `true` here would make an outage spend every pending segment's retry
+ // budget against the provider that is still down, and skip them for the
+ // rest of the process — including after it recovers.
+ assert!(
+ !recap_succeeded,
+ "a heuristic recap must not report the summariser as answering"
+ );
let methods = methods(&recording);
assert!(