Skip to content

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

fix(test): stop trimming history by message count in agent turn loop

Steven Enamakel4c3776239207
diff --git a/crates/openhuman-core/src/agent/agent_turn_loop_tests.rs b/crates/openhuman-core/src/agent/agent_turn_loop_tests.rs
index aaf5e56aed..529a5ad8ca 100644
--- a/crates/openhuman-core/src/agent/agent_turn_loop_tests.rs
+++ b/crates/openhuman-core/src/agent/agent_turn_loop_tests.rs
@@ -258,41 +258,53 @@ async fn turn_propagates_provider_error() {
}
// ═══════════════════════════════════════════════════════════════════════════
-// 8. History trimming during long conversations
+// 8. Long conversations keep their history (no message-count trim)
// ═══════════════════════════════════════════════════════════════════════════
+/// Prompt-cache regression: the legacy `max_history_messages` bound used to
+/// drop the oldest messages on every turn past it, which moved the head of the
+/// provider's cached prompt prefix every turn (a full cache miss each time).
+/// History is now bounded only by the token-aware context ladder, so a small
+/// legacy bound is ignored and the message after the system prompt never moves.
#[tokio::test]
-async fn history_trims_after_max_messages() {
- let max_history = 6;
- let mut responses = vec![];
- for _ in 0..max_history + 5 {
- responses.push(text_response("ok"));
- }
+async fn history_is_not_trimmed_by_message_count() {
+ let legacy_bound = 6;
+ let turns = legacy_bound + 5;
+ let responses = (0..turns).map(|_| text_response("ok")).collect();
let provider = Arc::new(ScriptedProvider::new(responses));
let config = AgentConfig {
- max_history_messages: max_history,
+ max_history_messages: legacy_bound,
..AgentConfig::default()
};
let (mut agent, _tmp) = build_agent_with_config(provider, vec![], config);
- for i in 0..max_history + 5 {
+ for i in 0..turns {
let _ = agent.turn(&format!("msg {i}")).await.unwrap();
}
- // System prompt (1) + trimmed messages
- // Should not exceed max_history + 1 (system prompt)
+ let history = agent.history();
+ // System prompt should always be preserved.
+ assert!(matches!(&history[0], ConversationMessage::Chat(c) if c.role == "system"));
+ // Every turn's user message is still there, and the first one still opens
+ // the conversation right after the system prompt.
assert!(
- agent.history().len() <= max_history + 1,
- "History length {} exceeds max {} + 1 (system)",
- agent.history().len(),
- max_history,
+ history.len() > legacy_bound + 1,
+ "history length {} was trimmed to the legacy bound {legacy_bound}",
+ history.len()
+ );
+ let first_user = history
+ .iter()
+ .find_map(|m| match m {
+ ConversationMessage::Chat(c) if c.role == "user" => Some(c.content.clone()),
+ _ => None,
+ })
+ .expect("a user message");
+ assert!(
+ first_user.contains("msg 0"),
+ "the oldest turn was dropped; first user message is {first_user:?}"
);
-
- // System prompt should always be preserved
- let first = &agent.history()[0];
- assert!(matches!(first, ConversationMessage::Chat(c) if c.role == "system"));
}
// ═══════════════════════════════════════════════════════════════════════════
diff --git a/crates/openhuman-core/src/config/schema/agent.rs b/crates/openhuman-core/src/config/schema/agent.rs
index 0fef7db9b9..d6e90805df 100644
--- a/crates/openhuman-core/src/config/schema/agent.rs
+++ b/crates/openhuman-core/src/config/schema/agent.rs
@@ -247,6 +247,13 @@ pub struct AgentConfig {
/// seam.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub chat_agent_id: Option<String>,
+ /// Deprecated and ignored: the session driver no longer trims history by
+ /// message count. Context size is bounded by the token-aware context
+ /// ladder (microcompaction, message trimming and summarisation, sized to
+ /// the model's window), which cuts rarely. A count cut dropped the oldest
+ /// messages on every turn past the bound, which moved the head of the
+ /// provider's cached prompt prefix and made each such turn a full cache
+ /// miss. Still parsed so existing `config.toml` files keep loading.
#[serde(default = "default_agent_max_history_messages")]
pub max_history_messages: usize,
#[serde(default)]