fix(timeline): surface reasoning streams as thinking rows #10945
ClosedDerrickkoko1234(GitHub profile, opens in a new tab)wants to merge 2 commits into
main fromrefs/pull/10945/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -1136,0 +1181,21 @@1181+ const takeBufferedThinkingText = (1182+ threadId: ThreadId,1183+ turnId: TurnId | undefined,1184+ ): Effect.Effect<BufferedThinking> =>1185+ Cache.getOption(bufferedThinkingTextByTurnKey, thinkingBufferKey(threadId, turnId)).pipe(1186+ Effect.flatMap((existing) =>1187+ Cache.invalidate(bufferedThinkingTextByTurnKey, thinkingBufferKey(threadId, turnId)).pipe(1188+ Effect.as(1189+ Option.getOrElse(existing, (): BufferedThinking => ({ text: "", firstCreatedAt: "" })),1190+ ),1191+ ),1192+ ),1193+ );1194+1195+ const splitThinkingText = (text: string): Array<string> => {1196+ const chunks: Array<string> = [];1197+ for (let index = 0; index < text.length; index += MAX_THINKING_CHARS_PER_ACTIVITY) {1198+ chunks.push(text.slice(index, index + MAX_THINKING_CHARS_PER_ACTIVITY));1199+ }1200+ return chunks;1201+ };@@ -1136,0 +1167,21 @@1167+ delta: string,1168+ createdAt: string,1169+ ) =>1170+ Cache.getOption(bufferedThinkingTextByTurnKey, thinkingBufferKey(threadId, turnId)).pipe(1171+ Effect.flatMap((existing) => {1172+ const previous = Option.getOrElse(existing, () => ({ text: "", firstCreatedAt: "" }));1173+ return Cache.set(bufferedThinkingTextByTurnKey, thinkingBufferKey(threadId, turnId), {1174+ text: `${previous.text}${delta}`,1175+ firstCreatedAt:1176+ previous.firstCreatedAt.length > 0 ? previous.firstCreatedAt : createdAt,1177+ });1178+ }),1179+ );1180+1181+ const takeBufferedThinkingText = (1182+ threadId: ThreadId,1183+ turnId: TurnId | undefined,1184+ ): Effect.Effect<BufferedThinking> =>1185+ Cache.getOption(bufferedThinkingTextByTurnKey, thinkingBufferKey(threadId, turnId)).pipe(1186+ Effect.flatMap((existing) =>1187+ Cache.invalidate(bufferedThinkingTextByTurnKey, thinkingBufferKey(threadId, turnId)).pipe(@@ -1134,3 +1161,14 @@11341161 const clearBufferedAssistantText = (messageId: MessageId) =>11351162 Cache.invalidate(bufferedAssistantTextByMessageId, messageId);113611631164+ const appendBufferedThinkingText = (1165+ threadId: ThreadId,1166+ turnId: TurnId | undefined,1167+ delta: string,1168+ createdAt: string,1169+ ) =>1170+ Cache.getOption(bufferedThinkingTextByTurnKey, thinkingBufferKey(threadId, turnId)).pipe(1171+ Effect.flatMap((existing) => {1172+ const previous = Option.getOrElse(existing, () => ({ text: "", firstCreatedAt: "" }));1173+ return Cache.set(bufferedThinkingTextByTurnKey, thinkingBufferKey(threadId, turnId), {1174+ text: `${previous.text}${delta}`,@@ -1911,3 +2058,5 @@19112058 }1912205919132060 if (event.type === "session.exited") {2061+ const exitedActiveTurnId = thread.session?.activeTurnId ?? undefined;2062+ yield* flushBufferedThinkingForTurn({@@ -1054,12 +1055,18 @@10541055 continue;10551056 }10561057 const groupedEntries = [timelineEntry.entry];1058+ // Thinking rows stay visible outside collapsed tool groups: they break1059+ // the run on both sides so a reasoning-narrated turn keeps its narrative1060+ // without expanding dozens of tool calls.1061+ const anchorIsThinking = isThinkingWorkEntry(timelineEntry.entry);10571062 let cursor = index + 1;10581063 while (cursor < input.timelineEntries.length) {10591064 const nextEntry = input.timelineEntries[cursor];10601065 if (10611066 !nextEntry ||1067+ anchorIsThinking ||10621068 nextEntry.kind !== "work" ||10631069 nextEntry.entry.agentSpawn !== undefined ||10641070 nextEntry.entry.sourceActivityKind === "context-compaction" ||10651071 nextEntry.entry.tone === "error" ||1072+ isThinkingWorkEntry(nextEntry.entry) ||
- apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts lines 1173 to 1176OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1134,3 +1161,16 @@11341161 const clearBufferedAssistantText = (messageId: MessageId) =>11351162 Cache.invalidate(bufferedAssistantTextByMessageId, messageId);113611631164+ const appendBufferedThinkingText = (1165+ threadId: ThreadId,1166+ turnId: TurnId | undefined,1167+ delta: string,1168+ createdAt: string,1169+ ) =>1170+ Cache.getOption(bufferedThinkingTextByTurnKey, thinkingBufferKey(threadId, turnId)).pipe(1171+ Effect.flatMap((existing) => {1172+ const previous = Option.getOrElse(existing, () => ({ text: "", firstCreatedAt: "" }));1173+ return Cache.set(bufferedThinkingTextByTurnKey, thinkingBufferKey(threadId, turnId), {1174+ text: `${previous.text}${delta}`,1175+ firstCreatedAt:1176+ previous.firstCreatedAt.length > 0 ? previous.firstCreatedAt : createdAt,apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts lines 1594 to 1597OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1477,3 +1581,17 @@14771581 const processRuntimeEvent = (event: ProviderRuntimeEvent) =>14781582 Effect.gen(function* () {14791583 if (event.type === "content.delta" && event.payload.streamKind !== "assistant_text") {1584+ // Reasoning streams buffer into `thinking` activities (flushed at the1585+ // points below). Every other non-assistant stream stays ignored: it1586+ // carries tool output the timeline already shows through tool rows.1587+ if (1588+ (event.payload.streamKind === "reasoning_text" ||1589+ event.payload.streamKind === "reasoning_summary_text") &&1590+ event.payload.delta.length > 01591+ ) {1592+ const thread = yield* resolveThreadRuntimeContext(event.threadId);1593+ if (thread) {1594+ yield* appendBufferedThinkingText(1595+ thread.id,1596+ toTurnId(event.turnId),1597+ event.payload.delta,
- @@ -1136,0 +1264,21 @@1264+ /** Activity timestamp: the chunked reasoning's first delta. */1265+ activityCreatedAt: string;1266+ /** Command timestamp: the event that triggered this flush or spill. */1267+ createdAt: string;1268+ commandTag: string;1269+ chunkIdTag: string;1270+ chunkIndex: number;1271+ chunk: string;1272+ }) =>1273+ Effect.gen(function* () {1274+ yield* orchestrationEngine.dispatch({1275+ type: "thread.activity.append",1276+ commandId: yield* providerCommandId(1277+ input.event,1278+ `${input.commandTag}:${input.chunkIndex}`,1279+ ),1280+ threadId: input.threadId,1281+ activity: {1282+ id: EventId.make(1283+ `${input.event.eventId}:thinking:${input.chunkIdTag}:${input.turnId ?? NO_TURN_BUFFER_SUFFIX}:${input.chunkIndex}`,1284+ ),
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed