Skip to content

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

fix(transcript_view): handle tool calls recorded after their results

Steven Enamakelf5c8df633c76
diff --git a/crates/openhuman-core/src/agent/session_host/codec.rs b/crates/openhuman-core/src/agent/session_host/codec.rs
index b9ea1695fa..ea36bb310e 100644
--- a/crates/openhuman-core/src/agent/session_host/codec.rs
+++ b/crates/openhuman-core/src/agent/session_host/codec.rs
@@ -239,9 +239,10 @@ fn attach_text_dialect_rounds(
.map(|result| serde_json::Value::String(result.tool_call_id.clone()))
.collect();
if !failed.is_empty() {
- match rows[index].extra_metadata.get_or_insert_with(|| {
- serde_json::Value::Object(serde_json::Map::new())
- }) {
+ match rows[index]
+ .extra_metadata
+ .get_or_insert_with(|| serde_json::Value::Object(serde_json::Map::new()))
+ {
serde_json::Value::Object(map) => {
map.insert(
TOOL_RESULT_FAILURES_METADATA_KEY.to_string(),
@@ -258,8 +259,7 @@ fn attach_text_dialect_rounds(
let Some(issuer) = index.checked_sub(1) else {
continue;
};
- if !fresh[issuer] || rows[issuer].role != "assistant" || rows[issuer].turn_usage.is_some()
- {
+ if !fresh[issuer] || rows[issuer].role != "assistant" || rows[issuer].turn_usage.is_some() {
continue;
}
let calls: Vec<TranscriptToolCall> = results
@@ -288,7 +288,9 @@ fn attach_text_dialect_rounds(
continue;
}
rows[issuer].turn_usage = Some(TurnUsage {
- provider: route.map(|route| route.provider.clone()).unwrap_or_default(),
+ provider: route
+ .map(|route| route.provider.clone())
+ .unwrap_or_default(),
model: route.map(|route| route.model.clone()).unwrap_or_default(),
usage: MessageUsage {
input: 0,
diff --git a/crates/openhuman-core/src/threads/ops/usage_tests.rs b/crates/openhuman-core/src/threads/ops/usage_tests.rs
index 88adda355b..a281b96d9c 100644
--- a/crates/openhuman-core/src/threads/ops/usage_tests.rs
+++ b/crates/openhuman-core/src/threads/ops/usage_tests.rs
@@ -333,7 +333,10 @@ fn provenance_only_tool_round_records_are_not_counted_as_turns() {
let rows = vec![
TranscriptMessage::new("user", "q"),
issuing,
- TranscriptMessage::new("user", "[Tool results]\n<tool_result id=\"call-1\">\nok\n</tool_result>\n"),
+ TranscriptMessage::new(
+ "user",
+ "[Tool results]\n<tool_result id=\"call-1\">\nok\n</tool_result>\n",
+ ),
TranscriptMessage::assistant("a"),
];
append_transcript_turn(
diff --git a/crates/openhuman-core/src/threads/transcript_view/project.rs b/crates/openhuman-core/src/threads/transcript_view/project.rs
index a1c6be38e7..681236cbab 100644
--- a/crates/openhuman-core/src/threads/transcript_view/project.rs
+++ b/crates/openhuman-core/src/threads/transcript_view/project.rs
@@ -628,7 +628,10 @@ fn project_text_tool_results(
/// The already-settled orphan row for `call_id` in the current turn — a result
/// that projected before any call named it.
-fn settled_orphan_mut<'a>(items: &'a mut [DisplayItem], call_id: &str) -> Option<&'a mut DisplayItem> {
+fn settled_orphan_mut<'a>(
+ items: &'a mut [DisplayItem],
+ call_id: &str,
+) -> Option<&'a mut DisplayItem> {
let turn_start = items
.iter()
.rposition(|item| matches!(item, DisplayItem::TurnBoundary { .. }))
diff --git a/crates/openhuman-core/src/threads/transcript_view/transcript_view_tests.rs b/crates/openhuman-core/src/threads/transcript_view/transcript_view_tests.rs
index 369b24aec3..510f9b4a1a 100644
--- a/crates/openhuman-core/src/threads/transcript_view/transcript_view_tests.rs
+++ b/crates/openhuman-core/src/threads/transcript_view/transcript_view_tests.rs
@@ -898,7 +898,10 @@ fn text_dialect_tool_turn_projects_calls_on_their_issuing_row_as_settled() {
.unwrap_or_default();
assert_eq!(
issued,
- vec!["call_web_search_1".to_string(), "call_file_read_1".to_string()],
+ vec![
+ "call_web_search_1".to_string(),
+ "call_file_read_1".to_string()
+ ],
"the issuing assistant row carries its calls"
);
assert!(
@@ -925,7 +928,11 @@ fn text_dialect_tool_turn_projects_calls_on_their_issuing_row_as_settled() {
_ => None,
})
.collect();
- assert_eq!(calls.len(), 2, "one item per call, no duplicates: {items:?}");
+ assert_eq!(
+ calls.len(),
+ 2,
+ "one item per call, no duplicates: {items:?}"
+ );
assert_eq!(calls[0].0, "call_web_search_1");
assert_eq!(calls[0].1, "web_search_tool");
assert_eq!(
@@ -954,5 +961,63 @@ fn text_dialect_tool_turn_projects_calls_on_their_issuing_row_as_settled() {
matches!(i, DisplayItem::AssistantMessage { content, .. } if content == "Here is what I found.")
})
.unwrap();
- assert!(first_call < final_answer, "calls precede the answer they fed");
+ assert!(
+ first_call < final_answer,
+ "calls precede the answer they fed"
+ );
+}
+
+/// Transcripts already written while the codec filed a turn's calls on its
+/// final row (calls recorded *after* their own results) still project each call
+/// once, settled, with its real name.
+#[test]
+fn calls_recorded_after_their_results_project_as_settled() {
+ let dir = TempDir::new().unwrap();
+ let thread = "thr_late_calls";
+ write_raw(
+ dir.path(),
+ "late_orchestrator",
+ thread,
+ &[
+ r#"{"role":"user","content":"search and read","request_id":"R"}"#,
+ r#"{"role":"assistant","content":"","request_id":"R"}"#,
+ r#"{"role":"user","content":"[Tool results]\n<tool_result id=\"call_web_search_1\">\nhits\n</tool_result>\n<tool_result id=\"call_file_read_1\">\nunknown tool\n</tool_result>\n","request_id":"R"}"#,
+ r#"{"role":"assistant","content":"Here is what I found.","provider":"e2e","model":"m","usage":{"input":0,"output":0,"cached_input":0,"context_window":0,"cost_usd":0.0},"ts":"2026-09-24T00:49:35Z","iteration":2,"tool_calls":[{"id":"call_web_search_1","name":"web_search_tool","arguments":"{\"query\":\"q\"}"},{"id":"call_file_read_1","name":"file_read","arguments":"{\"path\":\"p\"}"}],"request_id":"R"}"#,
+ ],
+ );
+
+ let items = project_thread(dir.path(), thread)
+ .expect("transcript")
+ .items;
+ let calls: Vec<_> = items
+ .iter()
+ .filter_map(|item| match item {
+ DisplayItem::ToolCall {
+ call_id,
+ name,
+ args,
+ status,
+ ..
+ } => Some((call_id.clone(), name.clone(), args.is_some(), *status)),
+ _ => None,
+ })
+ .collect();
+ assert_eq!(
+ calls,
+ vec![
+ (
+ "call_web_search_1".to_string(),
+ "web_search_tool".to_string(),
+ true,
+ ToolCallStatus::Success
+ ),
+ (
+ "call_file_read_1".to_string(),
+ "file_read".to_string(),
+ true,
+ ToolCallStatus::Success
+ ),
+ ],
+ "{items:?}"
+ );
}