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 ? ( +