Skip to content

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

test: add reasoning timing tests for assistant UI messages and chat runtime

Steven Enamakel464146f83ad5
diff --git a/app/src/providers/__tests__/assistantUiMessages.reasoningTiming.test.ts b/app/src/providers/__tests__/assistantUiMessages.reasoningTiming.test.ts
new file mode 100644
index 0000000000..d973d59d29
--- /dev/null
+++ b/app/src/providers/__tests__/assistantUiMessages.reasoningTiming.test.ts
@@ -0,0 +1,75 @@
+import { describe, expect, it } from 'vitest';
+
+import type { ThreadMessage } from '../../types/thread';
+import { reasoningPart, streamingTailMessage, toThreadMessageLike } from '../assistantUiMessages';
+
+/**
+ * Reasoning parts carry their block's timing to the thread's reasoning panel
+ * under `providerMetadata.openhuman`. Without it the panel cannot show
+ * "Thought for Ns" (the regression this guards against).
+ */
+
+const agentMsg: ThreadMessage = {
+ id: 'm1',
+ content: 'answer',
+ type: 'text',
+ extraMetadata: {},
+ sender: 'agent',
+ createdAt: '2026-09-24T00:00:00Z',
+} as ThreadMessage;
+
+describe('reasoningPart', () => {
+ it('attaches timing when known', () => {
+ expect(reasoningPart('x', 1_000, 5_000)).toEqual({
+ type: 'reasoning',
+ text: 'x',
+ providerMetadata: { openhuman: { startedAt: 1_000, endedAt: 5_000 } },
+ });
+ });
+
+ it('stays a bare part when no timing is known (legacy rows)', () => {
+ expect(reasoningPart('x', undefined, undefined)).toEqual({ type: 'reasoning', text: 'x' });
+ });
+
+ it('keeps a start with no end yet', () => {
+ expect(reasoningPart('x', 1_000, undefined)).toEqual({
+ type: 'reasoning',
+ text: 'x',
+ providerMetadata: { openhuman: { startedAt: 1_000 } },
+ });
+ });
+});
+
+describe('timing on projected reasoning parts', () => {
+ it('settled messages carry each transcript block’s timing', () => {
+ const like = toThreadMessageLike(
+ agentMsg,
+ [],
+ [{ kind: 'thinking', round: 1, seq: 0, text: 'plan', startedAt: 10, endedAt: 20 }]
+ );
+ expect(like.content).toEqual([
+ reasoningPart('plan', 10, 20),
+ { type: 'text', text: 'answer' },
+ ]);
+ });
+
+ it('the live tail carries the streaming thinking span', () => {
+ const tail = streamingTailMessage({
+ requestId: 'r',
+ content: '',
+ thinking: 'still thinking',
+ thinkingStartedAt: 1_000,
+ thinkingEndedAt: 3_000,
+ });
+ expect(tail?.content).toEqual([reasoningPart('still thinking', 1_000, 3_000)]);
+ });
+
+ it('the live tail uses transcript timing once the block is recorded', () => {
+ const tail = streamingTailMessage(
+ { requestId: 'r', content: '', thinking: 'recorded', thinkingStartedAt: 1 },
+ [],
+ [{ kind: 'thinking', round: 1, seq: 0, text: 'recorded', startedAt: 5, endedAt: 9 }]
+ );
+ expect(tail?.content).toEqual([reasoningPart('recorded', 5, 9)]);
+ });
+});
diff --git a/app/src/store/chatRuntimeSlice.reasoningTiming.test.ts b/app/src/store/chatRuntimeSlice.reasoningTiming.test.ts
new file mode 100644
index 0000000000..72f0c6a16a
--- /dev/null
+++ b/app/src/store/chatRuntimeSlice.reasoningTiming.test.ts
@@ -0,0 +1,119 @@
+import { configureStore } from '@reduxjs/toolkit';
+import { describe, expect, it } from 'vitest';
+
+import type { PersistedTurnState } from '../types/turnState';
+import chatRuntimeReducer, {
+ hydrateRuntimeFromSnapshot,
+ streamDeltaReceived,
+} from './chatRuntimeSlice';
+
+/**
+ * Regression coverage for the reasoning timing the "Thinking… Ns" badge and
+ * the settled "Thought for Ns" label read. Before this, no timing existed
+ * for reasoning at all, so the panel could never show a duration.
+ */
+
+function makeStore() {
+ return configureStore({ reducer: { chatRuntime: chatRuntimeReducer } });
+}
+
+const think = (delta: string, at: number | undefined, round = 1, requestId = 'req-1') =>
+ streamDeltaReceived({ threadId: 't', requestId, round, delta, channel: 'thinking', at });
+
+describe('streamDeltaReceived — reasoning timing', () => {
+ it('stamps a thinking block with its first delta and advances its end', () => {
+ const store = makeStore();
+ store.dispatch(think('Let me ', 1_000));
+ store.dispatch(think('check.', 4_500));
+
+ const [item] = store.getState().chatRuntime.processingByThread.t;
+ expect(item).toMatchObject({
+ kind: 'thinking',
+ text: 'Let me check.',
+ startedAt: 1_000,
+ endedAt: 4_500,
+ });
+ const streaming = store.getState().chatRuntime.streamingAssistantByThread.t;
+ expect(streaming).toMatchObject({ thinkingStartedAt: 1_000, thinkingEndedAt: 4_500 });
+ });
+
+ it('opens a new timed block per round', () => {
+ const store = makeStore();
+ store.dispatch(think('one', 1_000, 1));
+ store.dispatch(think('two', 9_000, 2));
+ const items = store.getState().chatRuntime.processingByThread.t;
+ expect(items).toHaveLength(2);
+ expect(items[1]).toMatchObject({ startedAt: 9_000, endedAt: 9_000 });
+ // The turn-level span covers both rounds.
+ expect(store.getState().chatRuntime.streamingAssistantByThread.t).toMatchObject({
+ thinkingStartedAt: 1_000,
+ thinkingEndedAt: 9_000,
+ });
+ });
+
+ it('keeps thinking timing across content deltas in the same turn', () => {
+ const store = makeStore();
+ store.dispatch(think('hmm', 2_000));
+ store.dispatch(
+ streamDeltaReceived({
+ threadId: 't',
+ requestId: 'req-1',
+ round: 1,
+ delta: 'Answer',
+ channel: 'content',
+ at: 7_000,
+ })
+ );
+ expect(store.getState().chatRuntime.streamingAssistantByThread.t).toMatchObject({
+ content: 'Answer',
+ thinkingStartedAt: 2_000,
+ thinkingEndedAt: 2_000,
+ });
+ });
+
+ it('resets timing when a new request starts', () => {
+ const store = makeStore();
+ store.dispatch(think('old', 1_000, 1, 'req-1'));
+ store.dispatch(think('new', 50_000, 1, 'req-2'));
+ expect(store.getState().chatRuntime.streamingAssistantByThread.t).toMatchObject({
+ requestId: 'req-2',
+ thinkingStartedAt: 50_000,
+ });
+ });
+
+ it('records no timing for deltas dispatched without a timestamp', () => {
+ const store = makeStore();
+ store.dispatch(think('untimed', undefined));
+ const [item] = store.getState().chatRuntime.processingByThread.t;
+ expect(item).not.toHaveProperty('startedAt');
+ expect(store.getState().chatRuntime.streamingAssistantByThread.t).not.toHaveProperty(
+ 'thinkingStartedAt'
+ );
+ });
+});
+
+describe('hydrateRuntimeFromSnapshot — reasoning timing', () => {
+ it('keeps persisted startedAt / endedAt so a reload still says "Thought for Ns"', () => {
+ const store = makeStore();
+ const snapshot: PersistedTurnState = {
+ threadId: 't-h',
+ requestId: 'req-1',
+ lifecycle: 'completed',
+ iteration: 1,
+ maxIterations: 10,
+ streamingText: '',
+ thinking: '',
+ toolTimeline: [],
+ transcript: [
+ { kind: 'thinking', round: 1, seq: 0, text: 'plan', startedAt: 1_000, endedAt: 13_000 },
+ ],
+ startedAt: '2026-09-24T00:00:00Z',
+ updatedAt: '2026-09-24T00:00:00Z',
+ };
+ store.dispatch(hydrateRuntimeFromSnapshot({ snapshot }));
+ expect(store.getState().chatRuntime.processingByThread['t-h'][0]).toMatchObject({
+ startedAt: 1_000,
+ endedAt: 13_000,
+ });
+ });
+});