Skip to content

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

test(chat-runtime): add tests for cancelled-turn timeline and synthetic tool-call id reuse

Steven Enamakeleca13edb32d4
diff --git a/app/src/store/__tests__/chatRuntimeSlice.test.ts b/app/src/store/__tests__/chatRuntimeSlice.test.ts
index d8d3d01427..70a4ed6d83 100644
--- a/app/src/store/__tests__/chatRuntimeSlice.test.ts
+++ b/app/src/store/__tests__/chatRuntimeSlice.test.ts
@@ -4,6 +4,7 @@ import type { PersistedTurnState } from '../../types/turnState';
import reducer, {
beginInferenceTurn,
bumpInferenceHeartbeatForThread,
+ cancelUnresolvedTurnTimeline,
clearAllChatRuntime,
clearArtifactsForThread,
clearInferenceStatusForThread,
@@ -1115,6 +1116,37 @@ describe('toolCallReceived (Phase 3 reducer-side merge)', () => {
expect(rows[0]).toMatchObject({ id: 'c1', status: 'success', result: 'ok' });
});
+ it('does not reopen a cancelled row when a late tool_call for it arrives', () => {
+ let state = reducer(
+ undefined,
+ toolCallReceived({ threadId: 't1', round: 1, toolName: 'shell', toolCallId: 'c1' })
+ );
+ state = reducer(state, cancelUnresolvedTurnTimeline({ threadId: 't1', rowIds: ['c1'] }));
+ state = reducer(
+ state,
+ toolCallReceived({ threadId: 't1', round: 1, toolName: 'shell', toolCallId: 'c1' })
+ );
+
+ expect(state.toolTimelineByThread['t1'][0]).toMatchObject({ id: 'c1', status: 'cancelled' });
+ });
+
+ it('only cancels the completed turn rows captured before snapshot recovery', () => {
+ let state = reducer(
+ undefined,
+ toolCallReceived({ threadId: 't1', round: 1, toolName: 'completed', toolCallId: 'old' })
+ );
+ state = reducer(
+ state,
+ toolCallReceived({ threadId: 't1', round: 1, toolName: 'new-turn', toolCallId: 'new' })
+ );
+ state = reducer(state, cancelUnresolvedTurnTimeline({ threadId: 't1', rowIds: ['old'] }));
+
+ expect(state.toolTimelineByThread['t1']).toMatchObject([
+ { id: 'old', status: 'cancelled' },
+ { id: 'new', status: 'running' },
+ ]);
+ });
+
it('appends a new running row with a generated id and records the processing pointer', () => {
const state = reducer(
undefined,
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 c752527301..2c5de789f2 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
@@ -133,6 +133,41 @@ fn projects_turn_with_tools_reasoning_and_sanitization() {
}
}
+#[test]
+fn reuses_synthetic_tool_call_ids_in_a_later_turn() {
+ let dir = TempDir::new().unwrap();
+ let path = write_raw(
+ dir.path(),
+ "synthetic_ids",
+ "thr_synthetic",
+ &[
+ r#"{"role":"user","content":"one","request_id":"req-1"}"#,
+ r#"{"role":"assistant","content":"","tool_calls":[{"id":"call_0","name":"first","arguments":"{}"}],"request_id":"req-1"}"#,
+ r#"{"role":"tool","content":"first result","id":"call_0","request_id":"req-1"}"#,
+ r#"{"role":"user","content":"two","request_id":"req-2"}"#,
+ r#"{"role":"assistant","content":"","tool_calls":[{"id":"call_0","name":"second","arguments":"{}"}],"request_id":"req-2"}"#,
+ r#"{"role":"tool","content":"second result","id":"call_0","request_id":"req-2"}"#,
+ ],
+ );
+ let display = read_transcript_display(&path).unwrap();
+ let items = project_records(&display.records);
+
+ let calls: Vec<_> = items
+ .iter()
+ .filter_map(|item| match item {
+ DisplayItem::ToolCall { name, result, .. } => Some((name.as_str(), result.as_deref())),
+ _ => None,
+ })
+ .collect();
+ assert_eq!(
+ calls,
+ vec![
+ ("first", Some("first result")),
+ ("second", Some("second result"))
+ ]
+ );
+}
+
#[test]
fn recovers_tool_name_from_native_envelope_without_turn_usage() {
let dir = TempDir::new().unwrap();