Skip to content

Commit 7f3b7ed

Browse files
address issues
1 parent f069c0a commit 7f3b7ed

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

apps/sim/app/workspace/[workspaceId]/home/components/message-content/components/thinking-block/thinking-block.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ export function ThinkingBlock({
2828
const [expanded, setExpanded] = useState(false)
2929
const panelRef = useRef<HTMLDivElement>(null)
3030
const wasActiveRef = useRef<boolean | null>(null)
31-
// Suppress active thinking until it exceeds 5s. Completed-<=5s is
32-
// filtered upstream in message-content, so if we're mounted with
33-
// isActive=false we've already passed that gate.
31+
// Suppress active thinking until it exceeds MIN_VISIBLE_THINKING_MS.
32+
// Completed-<=threshold is filtered upstream in message-content, so if
33+
// we're mounted with isActive=false we've already passed that gate.
3434
const [thresholdReached, setThresholdReached] = useState(() => {
3535
if (!isActive || startedAt === undefined) return true
3636
return Date.now() - startedAt > MIN_VISIBLE_THINKING_MS

apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3566,6 +3566,14 @@ export function useChat(
35663566
queryClient.getQueryData<TaskChatHistory>(taskKeys.detail(chatIdRef.current))
35673567
?.activeStreamId ||
35683568
undefined
3569+
// Snapshot the active assistant message id BEFORE clearActiveTurn()
3570+
// nulls the ref. Used below to restrict markMessageStopped to the
3571+
// in-flight turn only — historical messages from the chat history
3572+
// also lack `endedAt` on their legacy blocks (pre-timing-fields),
3573+
// and without this gate we'd corrupt them with cancelled markers.
3574+
const activeAssistantMessageId =
3575+
activeTurnRef.current?.assistantMessageId ??
3576+
(sid ? getLiveAssistantMessageId(sid) : undefined)
35693577
const stopContentSnapshot = streamingContentRef.current
35703578
const stopNow = Date.now()
35713579
const stopBlocksSnapshot = streamingBlocksRef.current.map((block) => ({
@@ -3594,7 +3602,11 @@ export function useChat(
35943602
await queryClient.cancelQueries({ queryKey: taskKeys.detail(activeChatId) })
35953603
upsertTaskChatHistory(activeChatId, (current) => ({
35963604
...current,
3597-
messages: current.messages.map(markMessageStopped),
3605+
messages: current.messages.map((message) =>
3606+
activeAssistantMessageId && message.id === activeAssistantMessageId
3607+
? markMessageStopped(message)
3608+
: message
3609+
),
35983610
}))
35993611
} else {
36003612
setPendingMessages((prev) =>

0 commit comments

Comments
 (0)