Skip to content

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

fix(agent): mark every resumed row as replayed, not only rows with a request id

M3gA-Mind2283e0342ecb
diff --git a/crates/openhuman-core/src/agent/harness/session/runtime/resume.rs b/crates/openhuman-core/src/agent/harness/session/runtime/resume.rs
index 42f9644711..a93023f153 100644
--- a/crates/openhuman-core/src/agent/harness/session/runtime/resume.rs
+++ b/crates/openhuman-core/src/agent/harness/session/runtime/resume.rs
@@ -54,7 +54,7 @@ impl Agent {
Vec::with_capacity(prior.len() + 1);
cached.push(crate::agent::messages::ChatMessage::system(system_prompt));
for (role, content) in prior {
- let mut chat = match role.as_str() {
+ let chat = match role.as_str() {
"user" => crate::agent::messages::ChatMessage::user(content),
"agent" | "assistant" => crate::agent::messages::ChatMessage::assistant(content),
// Fall back to user role for unknown senders rather than
@@ -62,10 +62,6 @@ impl Agent {
// mislabelling a system/tool message.
_ => crate::agent::messages::ChatMessage::user(content),
};
- // The conversation log records no request id for these rows, and
- // they belong to earlier turns: mark them so persisting them with the
- // next turn does not attribute them to that turn's request (#6282).
- crate::agent::harness::session::transcript::attach_replayed_metadata(&mut chat, None);
cached.push(chat);
}
diff --git a/crates/openhuman-core/src/agent/harness/session/session_dispatch_and_resume_tests.rs b/crates/openhuman-core/src/agent/harness/session/session_dispatch_and_resume_tests.rs
index 62a0956019..a520f1918a 100644
--- a/crates/openhuman-core/src/agent/harness/session/session_dispatch_and_resume_tests.rs
+++ b/crates/openhuman-core/src/agent/harness/session/session_dispatch_and_resume_tests.rs
@@ -365,7 +365,7 @@ fn prose_seeded_rows_are_not_restamped_with_the_resuming_request() {
use crate::agent::harness::session::transcript::{
append_transcript_turn, read_transcript_display, DisplayRecord,
};
- use crate::agent::messages::ChatMessage;
+ use crate::agent::messages::{ChatMessage, ConversationMessage};
let mut agent = build_minimal_agent_with_definition_name(Some("orchestrator"));
agent
@@ -377,11 +377,13 @@ fn prose_seeded_rows_are_not_restamped_with_the_resuming_request() {
"what happened?",
)
.expect("seed");
- let mut messages = agent
- .cached_transcript_messages
- .clone()
- .expect("cache populated");
- messages.push(ChatMessage::user("what happened?"));
+ // The resuming turn: its own message, then the seeded prefix absorbed ahead
+ // of it and rendered for persistence, exactly as the turn driver does.
+ agent.history = vec![ConversationMessage::Chat(ChatMessage::user(
+ "what happened?",
+ ))];
+ agent.absorb_resumed_transcript_prefix();
+ let messages = agent.tool_dispatcher.to_provider_messages(&agent.history);
let dir = tempfile::TempDir::new().expect("temp dir");
let path = dir.path().join("seeded.jsonl");
@@ -407,9 +409,9 @@ fn prose_seeded_rows_are_not_restamped_with_the_resuming_request() {
let ids: Vec<Option<&str>> = rows.iter().map(|(_, id)| id.as_deref()).collect();
assert_eq!(
ids,
- vec![Some("req-now"), None, None, Some("req-now")],
- "only this turn's rows (the freshly built system prompt and the new user \
- message) take its request id: {rows:?}"
+ vec![None, None, None, Some("req-now")],
+ "the seeded prefix (its system prompt included) keeps no request id; only \
+ this turn's new message takes it: {rows:?}"
);
}
diff --git a/crates/openhuman-core/src/agent/harness/session/session_thread_resume_tests.rs b/crates/openhuman-core/src/agent/harness/session/session_thread_resume_tests.rs
index fa2a799cac..aa178be84f 100644
--- a/crates/openhuman-core/src/agent/harness/session/session_thread_resume_tests.rs
+++ b/crates/openhuman-core/src/agent/harness/session/session_thread_resume_tests.rs
@@ -704,3 +704,77 @@ async fn a_resumed_transcript_prefix_is_absorbed_into_history() {
],
);
}
+
+/// #6282: a thread transcript written without request ids (a CLI or full-rewrite
+/// transcript) resumed into a request-scoped turn must not have its replayed
+/// rows restamped with the resuming request, which would group every earlier
+/// message into the current turn.
+#[test]
+fn a_resumed_request_less_transcript_is_not_restamped_with_the_resuming_request() {
+ use super::super::transcript::{self, read_transcript_display, DisplayRecord};
+ use crate::agent::messages::{ChatMessage, ConversationMessage};
+
+ let ws = tempfile::TempDir::new().expect("temp workspace");
+ let wsp = ws.path().to_path_buf();
+ let thread_id = "thr_request_less";
+ let path = transcript::resolve_keyed_transcript_path(&wsp, "1700000000_orchestrator")
+ .expect("resolve transcript path");
+ transcript::write_transcript(
+ &path,
+ &[
+ ChatMessage::system("stored prompt"),
+ ChatMessage::user("first question"),
+ ChatMessage::assistant("first answer"),
+ ],
+ &fake_transcript_meta(thread_id),
+ None,
+ )
+ .expect("write transcript");
+
+ let mem: Arc<dyn Memory> = crate::memory::test_support::noop_memory();
+ let mut agent = Agent::builder()
+ .chat_model(Arc::new(MockProvider {
+ responses: Mutex::new(vec![]),
+ }))
+ .tools(vec![Box::new(MockTool)])
+ .memory(mem)
+ .tool_dispatcher(Box::new(NativeToolDispatcher))
+ .workspace_dir(wsp.clone())
+ .build()
+ .expect("agent build should succeed");
+ assert!(agent.seed_resume_from_thread_transcript(thread_id));
+
+ // The resuming turn: its own message, then the replayed prefix absorbed
+ // ahead of it, exactly as the turn driver does.
+ agent.history = vec![ConversationMessage::Chat(ChatMessage::user(
+ "second question",
+ ))];
+ agent.absorb_resumed_transcript_prefix();
+ let messages = agent.tool_dispatcher.to_provider_messages(&agent.history);
+
+ let out = wsp.join("resumed.jsonl");
+ transcript::append_transcript_turn(
+ &out,
+ &[],
+ &messages,
+ &fake_transcript_meta(thread_id),
+ None,
+ Some("req-2"),
+ )
+ .expect("persist resumed turn");
+ let rows: Vec<(String, Option<String>)> = read_transcript_display(&out)
+ .expect("display read")
+ .records
+ .into_iter()
+ .filter_map(|record| match record {
+ DisplayRecord::Message(m) => Some((m.message.content, m.request_id)),
+ _ => None,
+ })
+ .collect();
+ let ids: Vec<Option<&str>> = rows.iter().map(|(_, id)| id.as_deref()).collect();
+ assert_eq!(
+ ids,
+ vec![None, None, None, Some("req-2")],
+ "replayed request-less rows keep no request id; only the resuming turn's row takes it: {rows:?}"
+ );
+}
diff --git a/crates/openhuman-core/src/agent/harness/session/transcript.rs b/crates/openhuman-core/src/agent/harness/session/transcript.rs
index cd217e606e..1e2a41aec3 100644
--- a/crates/openhuman-core/src/agent/harness/session/transcript.rs
+++ b/crates/openhuman-core/src/agent/harness/session/transcript.rs
@@ -117,10 +117,10 @@ mod types;
mod writer;
pub use legacy_md::read_transcript_legacy_md;
-pub(crate) use metadata::attach_replayed_metadata;
pub(crate) use metadata::attach_tool_failure_metadata;
#[cfg(test)]
pub(crate) use metadata::attach_turn_usage_metadata;
+pub(crate) use metadata::mark_replayed_if_unmarked;
pub use paths::{
find_latest_transcript_in_subdir, resolve_keyed_transcript_path,
resolve_keyed_transcript_path_in_dir,
diff --git a/crates/openhuman-core/src/agent/harness/session/transcript/metadata.rs b/crates/openhuman-core/src/agent/harness/session/transcript/metadata.rs
index c3c65fc21b..21bb8809ec 100644
--- a/crates/openhuman-core/src/agent/harness/session/transcript/metadata.rs
+++ b/crates/openhuman-core/src/agent/harness/session/transcript/metadata.rs
@@ -109,6 +109,21 @@ pub(crate) fn attach_replayed_metadata(message: &mut ChatMessage, request_id: Op
);
}
+/// Mark `message` as replayed with no recorded request id, unless it already
+/// carries a replayed marker. A transcript row read back with its own
+/// `request_id` keeps that id; every other resumed row (a request-less line, a
+/// conversation-log seed) must not take the resuming turn's id either (#6282).
+pub(crate) fn mark_replayed_if_unmarked(message: &mut ChatMessage) {
+ let marked = message
+ .extra_metadata
+ .as_ref()
+ .and_then(|meta| meta.get(REPLAYED_METADATA_KEY))
+ .is_some();
+ if !marked {
+ attach_replayed_metadata(message, None);
+ }
+}
+
/// Pop the replayed marker out of a cloned `extra_metadata` map, returning
/// `Some(original_request_id)` when the message was replayed and `None` when it
/// belongs to the turn being written.
diff --git a/crates/openhuman-core/src/agent/harness/session/turn/core/resumed_prefix.rs b/crates/openhuman-core/src/agent/harness/session/turn/core/resumed_prefix.rs
index 3956d5cd43..35999d03fc 100644
--- a/crates/openhuman-core/src/agent/harness/session/turn/core/resumed_prefix.rs
+++ b/crates/openhuman-core/src/agent/harness/session/turn/core/resumed_prefix.rs
@@ -72,9 +72,17 @@ impl Agent {
&& matches!(entry, ConversationMessage::Chat(chat) if chat.role == "system")
})
.collect();
+ // Every absorbed row belongs to an earlier turn. Mark it as replayed so
+ // persisting it with this turn keeps the request it was written under
+ // (or none) instead of taking this turn's request id (#6282). This is
+ // the one place every resume path (thread transcript, agent
+ // transcript, conversation-log seed) enters `history`.
self.history = cached
.into_iter()
- .map(ConversationMessage::Chat)
+ .map(|mut message| {
+ crate::agent::harness::session::transcript::mark_replayed_if_unmarked(&mut message);
+ ConversationMessage::Chat(message)
+ })
.chain(tail)
.collect();
}