Skip to content

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

refactor(session_host): remove history trimming from the driver

Steven Enamakel84fb755c5d1e
diff --git a/crates/openhuman-core/src/agent/session_host/driver.rs b/crates/openhuman-core/src/agent/session_host/driver.rs
index 60bd857cd4..f434c35f6d 100644
--- a/crates/openhuman-core/src/agent/session_host/driver.rs
+++ b/crates/openhuman-core/src/agent/session_host/driver.rs
@@ -32,7 +32,6 @@ pub struct OpenHumanSessionDriver {
model_name: String,
temperature: f64,
max_iterations: usize,
- max_history_messages: usize,
model_vision: bool,
run_queue:
Option<Arc<tinyagents_harness::run_queue::RunQueue<crate::agent::queued_turn::QueuedTurn>>>,
@@ -50,7 +49,6 @@ impl OpenHumanSessionDriver {
model_name: String,
temperature: f64,
max_iterations: usize,
- max_history_messages: usize,
model_vision: bool,
run_queue: Option<
Arc<tinyagents_harness::run_queue::RunQueue<crate::agent::queued_turn::QueuedTurn>>,
@@ -66,7 +64,6 @@ impl OpenHumanSessionDriver {
model_name,
temperature,
max_iterations,
- max_history_messages,
model_vision,
run_queue,
workspace,
@@ -357,7 +354,6 @@ impl SessionDriver<OpenHumanRunContext> for OpenHumanSessionDriver {
}
history.push(Message::assistant(output.clone()));
}
- trim_history(&mut history, self.max_history_messages);
// This is deliberately an out-of-band observation rather than a
// second history or transcript. The runtime only reads it from
@@ -424,55 +420,6 @@ impl SessionDriver<OpenHumanRunContext> for OpenHumanSessionDriver {
}
}
-/// Share of `max_history_messages` a cut keeps, as `KEEP_NUMERATOR /
-/// KEEP_DENOMINATOR`.
-const HISTORY_TRIM_KEEP_NUMERATOR: usize = 3;
-const HISTORY_TRIM_KEEP_DENOMINATOR: usize = 5;
-
-/// How many non-system messages a cut keeps for a given bound: 60% of it (at
-/// least one message), or none when the bound itself is zero.
-fn history_trim_target(max_history_messages: usize) -> usize {
- if max_history_messages == 0 {
- return 0;
- }
- (max_history_messages * HISTORY_TRIM_KEEP_NUMERATOR / HISTORY_TRIM_KEEP_DENOMINATOR).max(1)
-}
-
-/// Preserve the stable system prefix while bounding durable conversational
-/// history. The runtime owns history replacement, so this must happen before
-/// its successful `DriverOutcome` is committed.
-///
-/// The cut is hysteretic: once history exceeds `max_history_messages` it drops
-/// to 60% of the bound in one step, rather than shedding the oldest messages
-/// every turn. The messages right after the system prompt are part of the
-/// provider's cached prompt prefix; a cut that moved them every turn made every
-/// turn of a long thread a full cache miss. With a step cut the prefix stays
-/// byte-identical until history grows back past the bound.
-///
-/// The cut never splits an assistant tool-call turn from its results (#6721):
-/// a history opening on an orphaned `tool` message is rejected by the provider
-/// on every later turn. `find_safe_cutoff_point` moves the cut back to keep the
-/// owning assistant turn (so the target may be exceeded by one tool group).
-fn trim_history(history: &mut Vec<Message>, max_history_messages: usize) {
- let prefix_len = system_prefix_len(history);
- let retained = history.len().saturating_sub(prefix_len);
- if retained > max_history_messages {
- let target = history_trim_target(max_history_messages);
- let cut = tinyagents_harness::summarization::find_safe_cutoff_point(
- &history[prefix_len..],
- retained - target,
- );
- tracing::debug!(
- retained,
- max_history_messages,
- target,
- dropped = cut,
- "[session_host::driver] history over bound; step-trimmed to target (cached prefix moves once)"
- );
- history.drain(prefix_len..prefix_len + cut);
- }
-}
-
fn system_prefix_len(history: &[Message]) -> usize {
history
.iter()
diff --git a/crates/openhuman-core/src/agent/session_host/driver_tests.rs b/crates/openhuman-core/src/agent/session_host/driver_tests.rs
index 6f289042a2..af235f8f6c 100644
--- a/crates/openhuman-core/src/agent/session_host/driver_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/driver_tests.rs
@@ -163,96 +163,3 @@ fn tool_snapshot_with_no_executable_source_fails_closed_before_graph() {
.expect_err("a declared tool must have a request-scoped executable source");
assert!(error.error.to_string().contains("revoked_tool"));
}
-
-/// #6721: the req-029 → req-031 shape — an assistant issued 3 tool calls and
-/// the cut lands on the second result. The trimmed history must not open on an
-/// orphaned `tool` message.
-#[test]
-fn trim_history_keeps_tool_call_group_whole() {
- let mut calling = Message::assistant("");
- if let Message::Assistant(assistant) = &mut calling {
- assistant.tool_calls = ["a", "b", "c"]
- .iter()
- .map(|id| tinyinference_llm::ToolCall::new(*id, "search", serde_json::json!({})))
- .collect();
- }
- let mut history = vec![Message::system("s0"), Message::system("s1")];
- history.extend((0..20).map(|i| Message::user(format!("early {i}"))));
- history.extend([
- Message::user("u0"),
- calling,
- Message::tool("a", "ra"),
- Message::tool("b", "rb"),
- Message::tool("c", "rc"),
- Message::assistant("done"),
- ]);
- history.extend((0..27).map(|i| Message::user(format!("filler {i}"))));
- // 53 non-system messages, bound 50 → the step cut keeps 30, so it drops 23:
- // the 20 early messages, u0, the calling turn and tool "a" — landing on "b".
-
- trim_history(&mut history, 50);
-
- assert!(
- matches!(&history[2], Message::Assistant(a) if a.tool_calls.len() == 3),
- "trimmed history must open on the tool-calling assistant, got {:?}",
- history[2]
- );
- assert!(tinyagents_harness::summarization::tool_pairing_is_intact(
- &history[2..]
- ));
-}
-
-#[test]
-fn trim_history_without_tool_group_step_trims_to_sixty_percent() {
- let mut history = vec![Message::system("s0")];
- history.extend((0..60).map(|i| Message::user(format!("m{i}"))));
- trim_history(&mut history, 50);
- assert_eq!(history.len(), 31);
- assert_eq!(history[1].text(), "m30");
-}
-
-#[test]
-fn trim_history_leaves_history_within_the_bound_untouched() {
- let mut history = vec![Message::system("s0")];
- history.extend((0..50).map(|i| Message::user(format!("m{i}"))));
- let before = history.clone();
- trim_history(&mut history, 50);
- assert_eq!(history, before);
-}
-
-#[test]
-fn history_trim_target_edges() {
- assert_eq!(history_trim_target(0), 0);
- assert_eq!(history_trim_target(1), 1);
- assert_eq!(history_trim_target(50), 30);
-}
-
-/// Prompt-cache regression: the message right after the system prompt is the
-/// head of the provider's cached prefix. Before the step cut, a thread past the
-/// bound shed its oldest messages every turn, so the head moved (and the whole
-/// prompt missed the cache) on every one of these 30 turns.
-#[test]
-fn trim_history_keeps_the_cached_prefix_stable_across_turns() {
- let mut history = vec![Message::system("s0")];
- history.extend((0..50).map(|i| Message::user(format!("m{i}"))));
- let mut next = 50;
- let mut head_changes = 0;
- let mut head = history[1].text();
- for _turn in 0..30 {
- // One turn: user message + assistant reply.
- history.push(Message::user(format!("m{next}")));
- history.push(Message::assistant(format!("r{next}")));
- next += 1;
- trim_history(&mut history, 50);
- assert!(history.len() - 1 <= 50, "history stays within the bound");
- if history[1].text() != head {
- head_changes += 1;
- head = history[1].text();
- }
- }
- // Each cut frees 20 slots = 10 turns, so 30 turns cut at most 3 times.
- assert!(
- head_changes <= 3,
- "cached prefix moved {head_changes} times in 30 turns"
- );
-}
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
index 0d96fe4f6b..e144ded29f 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -1430,7 +1430,6 @@ impl OpenHumanSessionHost {
self.model_name.clone(),
self.temperature,
self.config.max_tool_iterations,
- self.config.max_history_messages,
self.model_vision,
self.run_queue.clone(),
self.workspace_descriptor.clone(),