The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(session_host): align encode_history with adopted replay view
Steven Enamakel728f40c3b038
diff --git a/crates/openhuman-core/src/agent/session_host/codec.rs b/crates/openhuman-core/src/agent/session_host/codec.rsindex 6e59132a28..9c1ffb8c9f 100644--- a/crates/openhuman-core/src/agent/session_host/codec.rs+++ b/crates/openhuman-core/src/agent/session_host/codec.rs@@ -20,27 +20,7 @@ pub struct OpenHumanTranscriptCodec;impl TranscriptCodec<OpenHumanRunContext> for OpenHumanTranscriptCodec {fn decode_history(&self, transcript: &SessionTranscript) -> Result<Vec<Message>, RuntimeError> {- // 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(),- )- };+ let rows = replayable_host_rows(&transcript.messages);tinyagents_runtime::transcript::native_transcript_to_messages(&rows)?;Ok(message_convert::history_to_messages(&rows))}@@ -52,6 +32,9 @@ impl TranscriptCodec<OpenHumanRunContext> for OpenHumanTranscriptCodec {next: &[Message],options: &TranscriptTurnOptions<OpenHumanRunContext>,) -> Result<Vec<TranscriptMessage>, RuntimeError> {+ // Match against the same adopted view used by decode_history; dropped+ // legacy head results must not shift retained rows' metadata.+ let prior = replayable_host_rows(prior);let mut rows = next.iter().filter_map(tinyagents_runtime::transcript::message_to_native_transcript)@@ -330,3 +313,21 @@ fn attach_text_dialect_rounds(});}}+++/// Apply OpenHuman's historical orphan-head adoption to the replay view only.+fn replayable_host_rows(rows: &[TranscriptMessage]) -> std::borrow::Cow<'_, [TranscriptMessage]> {+ // Old unpaired trims could persist tool results immediately after the+ // frozen system prefix (#6721). Later orphan results still fail native+ // validation. Merely resuming never rewrites the durable source.+ let prefix = rows.iter().take_while(|row| row.role == "system").count();+ let orphan_count = rows[prefix..].iter().take_while(|row| row.role == "tool").count();+ if orphan_count == 0 {+ std::borrow::Cow::Borrowed(rows)+ } else {+ tracing::warn!(orphan_count, "[session_host::codec] repaired legacy orphaned tool head");+ std::borrow::Cow::Owned(+ rows[..prefix].iter().chain(&rows[prefix + orphan_count..]).cloned().collect(),+ )+ }+}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.rsindex 540d420d25..137f7f5083 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@@ -115,7 +115,21 @@ async fn resumed_orphaned_tool_head_is_repaired_before_the_request() {assert!(!decoded.iter().any(|message| matches!(message, Message::Tool(tool) if tool.tool_call_id.starts_with("call_orphan"))));+ assert_eq!(+ std::fs::read_to_string(&transcripts[0]).unwrap(),+ spliced.join("\n") + "\n",+ "adoption must not rewrite the durable source merely on resume",+ );assert_eq!(host.turn("second message").await.unwrap(), "second reply");+ let committed_history = host.runtime_session.as_ref().unwrap().history().to_vec();+ let mut resumed_again = new_host();+ resumed_again.set_thread_id(Some("thread-orphaned-head"));+ assert!(resumed_again.resume_bound_session().await.unwrap());+ assert_eq!(+ resumed_again.runtime_session.as_ref().unwrap().history(),+ committed_history.as_slice(),+ "the healed committed head must retain aligned native rows across a fresh resume",+ );let requests = model.requests();let sent = &requests