Skip to content

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

fix: correct context ladder to handle empty agent list

Steven Enamakel621a555d1b43
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_context_ladder.rs b/crates/openhuman-core/src/agent/tinyagents/harness_context_ladder.rs
index 2c4680346c..e56df30109 100644
--- a/crates/openhuman-core/src/agent/tinyagents/harness_context_ladder.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/harness_context_ladder.rs
@@ -66,9 +66,10 @@ pub(super) fn install_context_ladder(
//
// 1. `ContextCompressionMiddleware` — the **summarization** step. Once the
// running token estimate crosses `window * SUMMARIZE_THRESHOLD_FRACTION`
- // (90% of *this model's* context window), it folds the older slice of the
- // transcript into a single LLM-generated system summary (keeping system
- // messages + the recent window verbatim). This is keyed to whatever model
+ // (90% of *this model's* context window, or the absolute
+ // `compaction_trigger_tokens` override), it folds the older slice of the
+ // transcript into a single LLM-generated, user-role checkpoint (keeping
+ // system messages + the recent window verbatim). This is keyed to whatever model
// the turn is running on, preserving the legacy context threshold.
// 2. `ImageAwareMessageTrimMiddleware` — a deterministic, no-extra-LLM-call
// hard cap (issue #4462; replaces the crate `MessageTrimMiddleware`).
@@ -119,19 +120,16 @@ pub(super) fn install_context_ladder(
compression_mw = Some(mw);
}
}
- if let Some(window) = context_window.filter(|w| *w > 0) {
-
- // Deterministic hard-cap trim (issue #4462). The crate
- // `MessageTrimMiddleware` regressed three legacy `token_budget.rs`
- // guards: it priced a base64 image at ~2M tokens (chars/4) and could
- // evict system messages, it reordered system messages to the front, and
- // its budget was the fixed `window − AGENT_TURN_MAX_OUTPUT_TOKENS`
- // (floored 1024) that collapses an 8k local model's input budget from
- // ~7373 to 1024. Our seam-owned `ImageAwareMessageTrimMiddleware`
- // restores all three: image markers priced at a flat cost, the
- // proportional reply reserve, system messages always kept in place, and a
- // grep-able warn with drop/token counts on any eviction.
- }
+ // Deterministic hard-cap trim (issue #4462). The crate
+ // `MessageTrimMiddleware` regressed three legacy `token_budget.rs`
+ // guards: it priced a base64 image at ~2M tokens (chars/4) and could
+ // evict system messages, it reordered system messages to the front, and
+ // its budget was the fixed `window − AGENT_TURN_MAX_OUTPUT_TOKENS`
+ // (floored 1024) that collapses an 8k local model's input budget from
+ // ~7373 to 1024. Our seam-owned `ImageAwareMessageTrimMiddleware`
+ // restores all three: image markers priced at a flat cost, the
+ // proportional reply reserve, system messages always kept in place, and a
+ // grep-able warn with drop/token counts on any eviction.
// ── The context ladder, cheapest sufficient step first (issue #6014) ──────
//
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_context_ladder_tests.rs b/crates/openhuman-core/src/agent/tinyagents/harness_context_ladder_tests.rs
new file mode 100644
index 0000000000..90397cc515
--- /dev/null
+++ b/crates/openhuman-core/src/agent/tinyagents/harness_context_ladder_tests.rs
@@ -0,0 +1,32 @@
+use super::*;
+use tinyagents_harness::summarization::DEFAULT_SUMMARIZE_KEEP_LAST;
+
+#[test]
+fn no_window_and_no_override_installs_no_compression() {
+ assert!(compression_policy(None, None).is_none());
+ assert!(compression_policy(Some(0), None).is_none());
+ assert!(compression_policy(None, Some(0)).is_none());
+}
+
+#[test]
+fn a_known_window_triggers_at_ninety_percent() {
+ let policy = compression_policy(Some(200_000), None).expect("policy");
+ assert_eq!(policy.trigger_budget(), 180_000);
+ assert_eq!(policy.keep_last, DEFAULT_SUMMARIZE_KEEP_LAST);
+}
+
+#[test]
+fn the_override_replaces_the_window_fraction() {
+ let policy = compression_policy(Some(1_000_000), Some(64_000)).expect("policy");
+ assert_eq!(policy.trigger_budget(), 64_000);
+ assert!(policy.exceeds_trigger(64_001));
+ assert!(!policy.exceeds_trigger(63_000));
+ assert_eq!(policy.keep_last, DEFAULT_SUMMARIZE_KEEP_LAST);
+}
+
+#[test]
+fn the_override_works_without_a_known_window() {
+ let policy = compression_policy(None, Some(64_000)).expect("policy");
+ assert_eq!(policy.trigger_budget(), 64_000);
+ assert_eq!(policy.keep_last, DEFAULT_SUMMARIZE_KEEP_LAST);
+}