Skip to content

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

feat(message_convert): filter out Custom messages from provider-bound conversions

Steven Enamakele7732f8896b7
diff --git a/crates/openhuman-core/src/agent/message_convert.rs b/crates/openhuman-core/src/agent/message_convert.rs
index 35e43f4a53..9aa584c27d 100644
--- a/crates/openhuman-core/src/agent/message_convert.rs
+++ b/crates/openhuman-core/src/agent/message_convert.rs
@@ -386,8 +386,13 @@ pub(crate) fn history_to_messages(history: &[ChatMessage]) -> Vec<Message> {
/// Assistant tool calls are flattened to their text (the loop already executed
/// them and appended `Tool` result messages), and a tool message preserves its
/// correlation id on [`ChatMessage::id`] so downstream persistence keeps it.
-pub(crate) fn message_to_chat_message(msg: &Message) -> ChatMessage {
- match msg {
+///
+/// Returns `None` for [`Message::Custom`]: that variant is a host-side
+/// out-of-band record (compaction marker, label, audit note) that the harness
+/// never sends to a provider, and a [`ChatMessage`] history *is* provider
+/// input, so carrying it across would leak it into the next request.
+pub(crate) fn message_to_chat_message(msg: &Message) -> Option<ChatMessage> {
+ Some(match msg {
Message::System(_) => ChatMessage::system(msg.text()),
Message::User(_) => ChatMessage::user(msg.text()),
Message::Assistant(a) => {
@@ -400,12 +405,18 @@ pub(crate) fn message_to_chat_message(msg: &Message) -> ChatMessage {
cm.id = Some(t.tool_call_id.clone());
cm
}
- }
+ Message::Custom(c) => {
+ log::trace!("[message_convert] dropping custom message kind={}", c.kind);
+ return None;
+ }
+ })
}
/// Convert a harness transcript back into openhuman history.
+///
+/// [`Message::Custom`] records are dropped; see [`message_to_chat_message`].
pub(crate) fn messages_to_history(messages: &[Message]) -> Vec<ChatMessage> {
- messages.iter().map(message_to_chat_message).collect()
+ messages.iter().filter_map(message_to_chat_message).collect()
}
/// Serialize a user [`Message`]'s content blocks back into a single string for a
@@ -460,8 +471,11 @@ fn native_user_content(msg: &Message) -> String {
/// followed by an orphan tool message and drops the round — breaking multi-turn
/// native tool calling (e.g. the orchestrator's `spawn_parallel_agents` →
/// synthesis hop).
-pub(crate) fn message_to_native_chat_message(msg: &Message) -> ChatMessage {
- match msg {
+///
+/// Returns `None` for [`Message::Custom`], which is never provider input; see
+/// [`message_to_chat_message`].
+pub(crate) fn message_to_native_chat_message(msg: &Message) -> Option<ChatMessage> {
+ Some(match msg {
Message::System(_) => ChatMessage::system(msg.text()),
Message::User(_) => ChatMessage::user(native_user_content(msg)),
Message::Assistant(a) if !a.tool_calls.is_empty() => {
@@ -488,7 +502,11 @@ pub(crate) fn message_to_native_chat_message(msg: &Message) -> ChatMessage {
cm.id = Some(t.tool_call_id.clone());
cm
}
- }
+ Message::Custom(c) => {
+ log::trace!("[message_convert] dropping custom message kind={}", c.kind);
+ return None;
+ }
+ })
}
/// Convert a harness transcript into the **typed** [`ConversationMessage`] shape
@@ -541,6 +559,11 @@ pub(crate) fn messages_to_conversation(messages: &[Message]) -> Vec<Conversation
});
}
}
+ // Host-side out-of-band record; not part of the persisted
+ // conversation and never provider input.
+ Message::Custom(c) => {
+ log::trace!("[message_convert] dropping custom message kind={}", c.kind);
+ }
}
}
flush(&mut out, &mut pending);
diff --git a/crates/openhuman-core/src/agent/message_convert_tests.rs b/crates/openhuman-core/src/agent/message_convert_tests.rs
index 0cdc50b90b..b1c2189fd6 100644
--- a/crates/openhuman-core/src/agent/message_convert_tests.rs
+++ b/crates/openhuman-core/src/agent/message_convert_tests.rs
@@ -174,13 +174,13 @@ fn seeded_native_tool_round_recovers_structure_and_round_trips() {
// Outbound: re-serialized to a well-formed native tool round (assistant
// carries structured tool_calls, the tool row carries the matching id).
- let a_native = message_to_native_chat_message(&a);
+ let a_native = message_to_native_chat_message(&a).expect("assistant converts");
assert_eq!(a_native.role, "assistant");
let av: serde_json::Value = serde_json::from_str(&a_native.content).unwrap();
assert_eq!(av["tool_calls"][0]["id"], "call-1");
assert_eq!(av["content"], "calling echo");
- let t_native = message_to_native_chat_message(&t);
+ let t_native = message_to_native_chat_message(&t).expect("tool converts");
assert_eq!(t_native.role, "tool");
let tv: serde_json::Value = serde_json::from_str(&t_native.content).unwrap();
assert_eq!(tv["tool_call_id"], "call-1");
@@ -218,7 +218,7 @@ fn reasoning_content_uses_typed_thinking_block_and_round_trips_metadata() {
.iter()
.any(|block| matches!(block, ContentBlock::ProviderExtension(_))));
- let back = message_to_chat_message(&msg);
+ let back = message_to_chat_message(&msg).expect("assistant converts");
assert_eq!(back.content, "visible answer");
assert_eq!(
back.extra_metadata
@@ -244,7 +244,7 @@ fn legacy_provider_extension_reasoning_still_round_trips() {
origin: None,
});
- let back = message_to_chat_message(&msg);
+ let back = message_to_chat_message(&msg).expect("assistant converts");
assert_eq!(back.content, "visible answer");
assert_eq!(
back.extra_metadata
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
index ff07b3b26a..b85f15a056 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
@@ -465,7 +465,7 @@ impl SubagentPlanner<crate::agent::tinyagents::host::OpenHumanRunContext, HostRe
options.initial_history = Some(
history
.iter()
- .map(crate::agent::message_convert::message_to_native_chat_message)
+ .filter_map(crate::agent::message_convert::message_to_native_chat_message)
.collect(),
);
history
@@ -1009,7 +1009,7 @@ impl tinyagents_orchestration::subagent::SubagentPersistence for OpenHumanPersis
.outcome
.history
.iter()
- .map(crate::agent::message_convert::message_to_native_chat_message)
+ .filter_map(crate::agent::message_convert::message_to_native_chat_message)
.collect(),
question: paused.reason.clone(),
options: None,
@@ -1251,7 +1251,7 @@ fn outcome_to_host(
final_history: outcome
.history
.iter()
- .map(crate::agent::message_convert::message_to_native_chat_message)
+ .filter_map(crate::agent::message_convert::message_to_native_chat_message)
.collect(),
usage: SubagentUsage {
input_tokens: outcome.usage.usage.input_tokens,