Skip to content

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

chore: files changed crates/openhuman-core/src/agent/session_host/codec.rs,crates/openhuman-core/src

Steven Enamakela718e9a1cc63
diff --git a/crates/openhuman-core/src/agent/session_host/codec.rs b/crates/openhuman-core/src/agent/session_host/codec.rs
index 909a6c1e1a..6e59132a28 100644
--- a/crates/openhuman-core/src/agent/session_host/codec.rs
+++ b/crates/openhuman-core/src/agent/session_host/codec.rs
@@ -20,8 +20,29 @@ pub struct OpenHumanTranscriptCodec;
impl TranscriptCodec<OpenHumanRunContext> for OpenHumanTranscriptCodec {
fn decode_history(&self, transcript: &SessionTranscript) -> Result<Vec<Message>, RuntimeError> {
- tinyagents_runtime::transcript::native_transcript_to_messages(&transcript.messages)?;
- Ok(message_convert::history_to_messages(&transcript.messages))
+ // Old unpaired trims could persist tool results immediately after the
+ // frozen system prefix (#6721). Apply the host's existing adoption
+ // policy before strict native replay validation; later orphan results
+ // still fail validation, and the durable source is never rewritten.
+ let prefix = transcript.messages.iter().take_while(|row| row.role == "system").count();
+ let orphan_count = transcript.messages[prefix..]
+ .iter()
+ .take_while(|row| row.role == "tool")
+ .count();
+ let rows: std::borrow::Cow<'_, [TranscriptMessage]> = if orphan_count == 0 {
+ std::borrow::Cow::Borrowed(&transcript.messages)
+ } else {
+ tracing::warn!(orphan_count, "[session_host::codec] repaired legacy orphaned tool head");
+ std::borrow::Cow::Owned(
+ transcript.messages[..prefix]
+ .iter()
+ .chain(&transcript.messages[prefix + orphan_count..])
+ .cloned()
+ .collect(),
+ )
+ };
+ tinyagents_runtime::transcript::native_transcript_to_messages(&rows)?;
+ Ok(message_convert::history_to_messages(&rows))
}
fn reconcile(
diff --git a/crates/openhuman-core/src/agent/session_host/orphaned_head_resume_tests.rs b/crates/openhuman-core/src/agent/session_host/orphaned_head_resume_tests.rs
index 4c860502f1..540d420d25 100644
--- a/crates/openhuman-core/src/agent/session_host/orphaned_head_resume_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/orphaned_head_resume_tests.rs
@@ -101,32 +101,20 @@ async fn resumed_orphaned_tool_head_is_repaired_before_the_request() {
let mut host = new_host();
host.set_thread_id(Some("thread-orphaned-head"));
- // Self-proving fixture: the real codec must decode the orphans as `Tool`
- // rows right after the system prefix, or the request assertions below
- // would pass without the repair ever having anything to drop.
- assert!(host.resume_bound_session().await.unwrap());
- let decoded: Vec<Message> = host
- .runtime_session
- .as_ref()
- .expect("resumed runtime session")
- .history()
- .to_vec();
- let prefix = decoded
- .iter()
- .take_while(|m| matches!(m, Message::System(_)))
- .count();
- let orphan_ids: Vec<&str> = decoded[prefix..]
- .iter()
- .map_while(|m| match m {
- Message::Tool(t) => Some(t.tool_call_id.as_str()),
- _ => None,
- })
- .collect();
+ // The raw durable source still contains both leading orphans; the codec
+ // must heal only its model-visible replay view before strict validation.
+ let raw = tinyagents_session::transcript::read_transcript(&transcripts[0]).unwrap();
+ let raw_prefix = raw.messages.iter().take_while(|row| row.role == "system").count();
assert_eq!(
- orphan_ids,
+ raw.messages[raw_prefix..].iter().take_while(|row| row.role == "tool")
+ .map(|row| row.id.as_deref().unwrap()).collect::<Vec<_>>(),
["call_orphan_a", "call_orphan_b"],
- "the resumed head must decode the two orphans as leading Tool rows"
);
+ assert!(host.resume_bound_session().await.unwrap());
+ let decoded = host.runtime_session.as_ref().expect("resumed runtime session").history();
+ assert!(!decoded.iter().any(
+ |message| matches!(message, Message::Tool(tool) if tool.tool_call_id.starts_with("call_orphan"))
+ ));
assert_eq!(host.turn("second message").await.unwrap(), "second reply");
let requests = model.requests();
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_adapter_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_adapter_tests.rs
index 3b48ac420a..bc1b147eb7 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_adapter_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_adapter_tests.rs
@@ -742,3 +742,21 @@ async fn reply_language_directive_rides_each_user_message_until_cleared_body() {
"a cleared directive is gone next turn: {second}"
);
}
+
+
+#[test]
+fn codec_still_rejects_an_orphan_result_after_a_user_message() {
+ let transcript = tinyagents_session::transcript::SessionTranscript {
+ meta: meta(),
+ messages: [
+ serde_json::json!({"role":"system","content":"frozen"}),
+ serde_json::json!({"role":"tool","id":"legacy-head","content":"trimmed"}),
+ serde_json::json!({"role":"user","content":"continue"}),
+ serde_json::json!({"role":"tool","id":"later-orphan","content":"invalid"}),
+ ].into_iter().map(|row| serde_json::from_value(row).unwrap()).collect(),
+ tools: None,
+ };
+ let error = OpenHumanTranscriptCodec.decode_history(&transcript).unwrap_err();
+ assert!(error.to_string().contains("later-orphan"), "{error}");
+ assert_eq!(transcript.messages[1].id.as_deref(), Some("legacy-head"));
+}