Skip to content

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

test(session-host): cover reused tool-call ids across turns

Steven Enamakelac4fafcacff9
diff --git a/crates/openhuman-core/src/agent/session_host/codec_adoption_tests.rs b/crates/openhuman-core/src/agent/session_host/codec_adoption_tests.rs
index 1a872a261d..d6f7b98b2b 100644
--- a/crates/openhuman-core/src/agent/session_host/codec_adoption_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/codec_adoption_tests.rs
@@ -89,3 +89,46 @@ fn codec_retains_authoritative_row_metadata_after_legacy_head_adoption() {
assert_eq!(rows[2].request_id.as_deref(), Some("new-turn"));
assert_eq!(transcript.messages[1].id.as_deref(), Some("legacy-head"));
}
+
+/// Providers reuse tool-call ids across turns (`call_0`, `call_1`, ...). A
+/// failure in this turn must not retroactively mark an earlier turn's
+/// successful result with the same id as failed: that rewrites a persisted row,
+/// so the commit no longer extends the transcript and opens a new generation.
+#[test]
+fn failed_tool_outcome_does_not_mark_an_earlier_turns_result_with_the_same_call_id() {
+ let options = |context| TranscriptTurnOptions {
+ request_id: Some("turn".into()),
+ thread_id: None,
+ stream: false,
+ resume: ResumeMode::Never,
+ context,
+ };
+ let first = vec![Message::user("one"), Message::tool("call_1", "scheduled")];
+ let prior = OpenHumanTranscriptCodec
+ .reconcile(&[], &[], &first, &options(OpenHumanRunContext::new()))
+ .unwrap();
+ assert!(prior[1].tool_failure.is_none());
+
+ let context = OpenHumanRunContext::new();
+ context.session_sidecar.lock().unwrap().tool_outcomes.push(
+ crate::agent::tinyagents::ToolCallOutcome {
+ call_id: "call_1".into(),
+ name: "cron".into(),
+ arguments: serde_json::json!({}),
+ success: false,
+ content: "refused".into(),
+ duration_ms: 0,
+ },
+ );
+ let mut next = first.clone();
+ next.push(Message::user("two"));
+ next.push(Message::tool("call_1", "refused"));
+ let rows = OpenHumanTranscriptCodec
+ .reconcile(&prior, &first, &next, &options(context))
+ .unwrap();
+ assert!(
+ rows[1].tool_failure.is_none(),
+ "an earlier turn's result keeps its recorded status"
+ );
+ assert!(rows[3].tool_failure.as_ref().is_some_and(|f| f.failed));
+}