Skip to content

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

fix(chat): restore turn state persistence in runtime provider

Steven Enamakel88779603c463
diff --git a/app/src/providers/ChatRuntimeProvider.tsx b/app/src/providers/ChatRuntimeProvider.tsx
index f4a989bd04..354f4bb97f 100644
--- a/app/src/providers/ChatRuntimeProvider.tsx
+++ b/app/src/providers/ChatRuntimeProvider.tsx
@@ -1103,6 +1103,7 @@ const ChatRuntimeProvider = ({ children }: { children: React.ReactNode }) => {
round: event.round,
delta: event.delta,
channel: 'thinking',
+ at: Date.now(),
})
);
},
diff --git a/app/src/store/chatRuntimeSlice.ts b/app/src/store/chatRuntimeSlice.ts
index 141f882f11..aaa174940b 100644
--- a/app/src/store/chatRuntimeSlice.ts
+++ b/app/src/store/chatRuntimeSlice.ts
@@ -374,6 +374,10 @@ export interface StreamingAssistantState {
requestId: string;
content: string;
thinking: string;
+ /** Epoch ms of the turn's first thinking delta (drives "Thinking… Ns"). */
+ thinkingStartedAt?: number;
+ /** Epoch ms of the turn's latest thinking delta (drives "Thought for Ns"). */
+ thinkingEndedAt?: number;
}
/**
@@ -1414,9 +1418,15 @@ const chatRuntimeSlice = createSlice({
round: number;
delta: string;
channel: 'content' | 'thinking';
+ /**
+ * Epoch ms the delta arrived, stamped by the dispatcher so the
+ * reducer stays pure. Timestamps the thinking block for the
+ * reasoning panel's "Thought for Ns"; omitted deltas carry no timing.
+ */
+ at?: number;
}>
) => {
- const { threadId, requestId, round, delta, channel } = action.payload;
+ const { threadId, requestId, round, delta, channel, at } = action.payload;
// A parallel (forked) turn streams into its own lane so it doesn't clobber
// the primary turn's stream on the same thread.
if (state.parallelRequestThreads[requestId] !== undefined) {
@@ -1434,11 +1444,19 @@ const chatRuntimeSlice = createSlice({
const sameTurn = existing != null && existing.requestId === requestId;
const carryContent = sameTurn ? existing.content : '';
const carryThinking = sameTurn ? existing.thinking : '';
- state.streamingAssistantByThread[threadId] = {
+ const next: StreamingAssistantState = {
requestId,
content: channel === 'content' ? `${carryContent}${delta}` : carryContent,
thinking: channel === 'thinking' ? `${carryThinking}${delta}` : carryThinking,
};
+ const carryStartedAt = sameTurn ? existing.thinkingStartedAt : undefined;
+ const carryEndedAt = sameTurn ? existing.thinkingEndedAt : undefined;
+ const stampThinking = channel === 'thinking' && delta.length > 0 && at !== undefined;
+ const startedAt = carryStartedAt ?? (stampThinking ? at : undefined);
+ const endedAt = stampThinking ? at : carryEndedAt;
+ if (startedAt !== undefined) next.thinkingStartedAt = startedAt;
+ if (endedAt !== undefined) next.thinkingEndedAt = endedAt;
+ state.streamingAssistantByThread[threadId] = next;
// Live interleaved processing transcript so a mid-turn "View processing"
// isn't empty — coalesce into the trailing same-kind, same-round block.
if (!delta) return;
@@ -1447,6 +1465,12 @@ const chatRuntimeSlice = createSlice({
const last = list[list.length - 1];
if (last && last.kind === kind && last.round === round) {
last.text += delta;
+ if (last.kind === 'thinking' && at !== undefined) {
+ last.startedAt ??= at;
+ last.endedAt = at;
+ }
+ } else if (kind === 'thinking' && at !== undefined) {
+ list.push({ kind, round, seq: list.length, text: delta, startedAt: at, endedAt: at });
} else {
list.push({ kind, round, seq: list.length, text: delta });
}
diff --git a/app/src/types/turnState.ts b/app/src/types/turnState.ts
index 9cb5ece931..02c0353a60 100644
--- a/app/src/types/turnState.ts
+++ b/app/src/types/turnState.ts
@@ -49,7 +49,16 @@ export interface PersistedSubagentToolCall {
*/
export type PersistedTranscriptItem =
| { kind: 'narration'; round: number; seq: number; text: string }
- | { kind: 'thinking'; round: number; seq: number; text: string }
+ | {
+ kind: 'thinking';
+ round: number;
+ seq: number;
+ text: string;
+ /** Epoch ms of the block's first delta (absent on pre-timing rows). */
+ startedAt?: number;
+ /** Epoch ms of the block's latest delta (absent on pre-timing rows). */
+ endedAt?: number;
+ }
| { kind: 'toolCall'; round: number; seq: number; callId: string };
/**