From 9ebae61c1c099d87631b94fe7f310f4466d4c877 Mon Sep 17 00:00:00 2001 From: npub1223z34hd7vtwc6qj4s7flsxkj644nlre2nthu7lrrmkumhu3xddsrx9r6w <52a228d6edf316ec6812ac3c9fc0d696ab59fc7954d77e7be31eedcddf91335b@sprout-oss.stage.blox.sqprod.co> Date: Mon, 6 Jul 2026 21:32:24 -0700 Subject: [PATCH] feat(desktop): pulse thread ingress rows while an agent works in the thread MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Derive a stable, sorted set of working thread head ids from thread-scoped bot typing entries in ChannelPane and pass it down the timeline as a ReadonlySet, so each thread summary row gets a plain boolean instead of scanning raw typing entries. The set identity only changes when the set of working threads changes — not on each 1s typing prune tick — preserving the existing timeline memo boundaries. Channel-level working surfaces are untouched; thread-only typing still stays out of agentWorkingSignal. The badge is a small motion-safe pulsing dot on the matching MessageThreadSummaryRow, with an aria-label suffix for screen readers. Co-authored-by: Taylor Ho Signed-off-by: Taylor Ho --- .../src/features/channels/ui/ChannelPane.tsx | 19 ++++++++ .../ui/useChannelActivityTyping.test.mjs | 43 ++++++++++++++++++- .../channels/ui/useChannelActivityTyping.ts | 19 ++++++++ .../messages/ui/MessageThreadSummaryRow.tsx | 15 ++++++- .../features/messages/ui/MessageTimeline.tsx | 4 ++ .../messages/ui/TimelineMessageList.tsx | 8 ++++ 6 files changed, 105 insertions(+), 3 deletions(-) diff --git a/desktop/src/features/channels/ui/ChannelPane.tsx b/desktop/src/features/channels/ui/ChannelPane.tsx index 22ae3a507b..90ee0c54ec 100644 --- a/desktop/src/features/channels/ui/ChannelPane.tsx +++ b/desktop/src/features/channels/ui/ChannelPane.tsx @@ -45,6 +45,7 @@ import { mentionsKnownAgent, } from "@/features/channels/ui/ChannelPane.helpers"; import type { ChannelPaneProps } from "@/features/channels/ui/ChannelPane.types"; +import { threadScopedBotTypingHeadIdKey } from "@/features/channels/ui/useChannelActivityTyping"; import * as agentSessionSelection from "@/features/channels/ui/agentSessionSelection"; import { Button } from "@/shared/ui/button"; import { buildMainTimelineEntries } from "@/features/messages/lib/threadPanel"; @@ -55,6 +56,10 @@ import { KIND_SYSTEM_MESSAGE } from "@/shared/constants/kinds"; import { useIsThreadPanelOverlay } from "@/shared/hooks/use-mobile"; import { channelChrome } from "@/shared/layout/chromeLayout"; import { cn } from "@/shared/lib/cn"; + +/** Stable empty set so no-typing renders keep a constant identity. */ +const EMPTY_WORKING_THREAD_HEAD_IDS: ReadonlySet = new Set(); + export const ChannelPane = React.memo(function ChannelPane({ activeChannel, agentPubkeys, @@ -356,6 +361,19 @@ export const ChannelPane = React.memo(function ChannelPane({ }, [botTypingEntries, openThreadHeadId]); const hasThreadComposerBotActivity = threadComposerBotTypingPubkeys.length > 0; + // Thread ingress working badges: derive once per typing update, keyed on a + // stable sorted string so the Set identity (and every memoized row below it) + // only changes when the set of working threads changes — not on each 1s + // typing prune tick or entry-array recreation. + const workingThreadHeadIdKey = + threadScopedBotTypingHeadIdKey(botTypingEntries); + const workingThreadHeadIds = React.useMemo>( + () => + workingThreadHeadIdKey + ? new Set(workingThreadHeadIdKey.split(",")) + : EMPTY_WORKING_THREAD_HEAD_IDS, + [workingThreadHeadIdKey], + ); const directMessageIntro = React.useMemo( () => buildDirectMessageIntro({ @@ -624,6 +642,7 @@ export const ChannelPane = React.memo(function ChannelPane({ searchQuery={channelFind.query} targetMessageId={targetMessageId} threadUnreadCounts={threadUnreadCounts} + workingThreadHeadIds={workingThreadHeadIds} /> {isNonMemberView ? (
{ }); }); +describe("threadScopedBotTypingHeadIdKey", () => { + it("excludes channel-scoped typing entries", () => { + const key = threadScopedBotTypingHeadIdKey([ + { pubkey: AGENT, threadHeadId: null }, + ]); + assert.equal(key, ""); + }); + + it("keeps thread-scoped entries and drops channel-scoped ones", () => { + const key = threadScopedBotTypingHeadIdKey([ + { pubkey: AGENT, threadHeadId: null }, + { pubkey: AGENT_2, threadHeadId: "thread-1" }, + ]); + assert.equal(key, "thread-1"); + }); + + it("dedupes multiple agents in the same thread and sorts head ids", () => { + const key = threadScopedBotTypingHeadIdKey([ + { pubkey: AGENT, threadHeadId: "thread-2" }, + { pubkey: AGENT_2, threadHeadId: "thread-1" }, + { pubkey: AGENT, threadHeadId: "thread-1" }, + ]); + assert.equal(key, "thread-1,thread-2"); + }); + + it("is stable across entry order so memoized row state keeps identity", () => { + const first = threadScopedBotTypingHeadIdKey([ + { pubkey: AGENT, threadHeadId: "thread-1" }, + { pubkey: AGENT_2, threadHeadId: "thread-2" }, + ]); + const second = threadScopedBotTypingHeadIdKey([ + { pubkey: AGENT_2, threadHeadId: "thread-2" }, + { pubkey: AGENT, threadHeadId: "thread-1" }, + ]); + assert.equal(first, second); + }); +}); + describe("thread-only bot typing regression", () => { beforeEach(() => { resetActiveAgentTurnsStore(); diff --git a/desktop/src/features/channels/ui/useChannelActivityTyping.ts b/desktop/src/features/channels/ui/useChannelActivityTyping.ts index 9bb07acd8c..4f1a543e6f 100644 --- a/desktop/src/features/channels/ui/useChannelActivityTyping.ts +++ b/desktop/src/features/channels/ui/useChannelActivityTyping.ts @@ -31,6 +31,25 @@ export function channelScopedBotTypingPubkeyKey( .join(","); } +/** + * Stable key of thread head ids with active bot typing. Deduped and sorted so + * the key (and anything memoized on it) only changes identity when the set of + * working threads actually changes — not on every typing prune tick. Channel + * -scoped entries (`threadHeadId === null`) are excluded; they belong to + * channel-level surfaces. + */ +export function threadScopedBotTypingHeadIdKey( + entries: readonly Pick[], +): string { + const headIds = new Set(); + for (const entry of entries) { + if (entry.threadHeadId !== null) { + headIds.add(entry.threadHeadId); + } + } + return [...headIds].sort().join(","); +} + export function useChannelActivityTyping({ activeChannel, activeChannelId, diff --git a/desktop/src/features/messages/ui/MessageThreadSummaryRow.tsx b/desktop/src/features/messages/ui/MessageThreadSummaryRow.tsx index 083faf04db..d6cb587084 100644 --- a/desktop/src/features/messages/ui/MessageThreadSummaryRow.tsx +++ b/desktop/src/features/messages/ui/MessageThreadSummaryRow.tsx @@ -59,6 +59,7 @@ export function MessageThreadSummaryRow({ depth = 0, depthGuideDepths, highlightThreadLineDepths, + isAgentWorking = false, message, onCollapseDepthGuide, onCollapseDepthGuideHoverChange, @@ -72,6 +73,8 @@ export function MessageThreadSummaryRow({ depth?: number; depthGuideDepths?: ReadonlyArray; highlightThreadLineDepths?: ReadonlyArray; + /** True when an agent is actively working (bot typing) in this thread. */ + isAgentWorking?: boolean; message: TimelineMessage; onCollapseDepthGuide?: (message: TimelineMessage) => void; onCollapseDepthGuideHoverChange?: ( @@ -95,9 +98,10 @@ export function MessageThreadSummaryRow({ THREAD_SUMMARY_SURFACE_AVATAR_INSET_REM, )})`; const replyLabel = summary.replyCount === 1 ? "reply" : "replies"; + const workingSuffix = isAgentWorking ? ", agent working" : ""; const summaryAriaLabel = summary.lastReplyAt - ? `View thread with ${summary.replyCount} ${replyLabel}, last reply ${formatThreadSummaryLastReplyTime(summary.lastReplyAt)}` - : `View thread with ${summary.replyCount} ${replyLabel}`; + ? `View thread with ${summary.replyCount} ${replyLabel}, last reply ${formatThreadSummaryLastReplyTime(summary.lastReplyAt)}${workingSuffix}` + : `View thread with ${summary.replyCount} ${replyLabel}${workingSuffix}`; const guideDepths = depthGuideDepths ? [...depthGuideDepths] : Array.from({ length: Math.max(0, depth - 1) }, (_, index) => index + 1); @@ -240,6 +244,13 @@ export function MessageThreadSummaryRow({ /> ))}
+ {isAgentWorking ? ( +