Skip to content

Commit f4456ff

Browse files
npub1223z34hd7vtwc6qj4s7flsxkj644nlre2nthu7lrrmkumhu3xddsrx9r6wtellaho
andcommitted
fix(desktop): scope channel working mirror to channel-level bot typing
The reportChannelBotTyping mirror effect built its pubkey key from all bot typing entries, so an agent typing only inside a thread lit the main composer activity bar and fed false channel-level working state into sidebar/profile surfaces. Extract channelScopedBotTypingPubkeyKey, which keeps only threadHeadId === null entries (thread surfaces apply their own threadHeadId filter), and use it in the mirror effect. Regression tests cover the helper and the end-to-end signal path: thread-only typing no longer marks channel-level working; channel-scoped typing still does. Addresses review feedback on #1494. Co-authored-by: Taylor Ho <[email protected]> Signed-off-by: Taylor Ho <[email protected]>
1 parent 8110f35 commit f4456ff

2 files changed

Lines changed: 94 additions & 5 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import assert from "node:assert/strict";
2+
import { beforeEach, describe, it } from "node:test";
3+
4+
import {
5+
getAgentWorkingState,
6+
getWorkingAgentPubkeysForChannel,
7+
reportChannelBotTyping,
8+
resetAgentWorkingSignal,
9+
} from "../../agents/agentWorkingSignal.ts";
10+
import { resetActiveAgentTurnsStore } from "../../agents/activeAgentTurnsStore.ts";
11+
import { channelScopedBotTypingPubkeyKey } from "./useChannelActivityTyping.ts";
12+
13+
const AGENT =
14+
"abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234";
15+
const AGENT_2 =
16+
"dcba4321dcba4321dcba4321dcba4321dcba4321dcba4321dcba4321dcba4321";
17+
18+
describe("channelScopedBotTypingPubkeyKey", () => {
19+
it("excludes thread-scoped typing entries", () => {
20+
const key = channelScopedBotTypingPubkeyKey([
21+
{ pubkey: AGENT, threadHeadId: "thread-1" },
22+
]);
23+
assert.equal(key, "");
24+
});
25+
26+
it("keeps channel-scoped entries and drops thread-scoped ones", () => {
27+
const key = channelScopedBotTypingPubkeyKey([
28+
{ pubkey: AGENT, threadHeadId: "thread-1" },
29+
{ pubkey: AGENT_2, threadHeadId: null },
30+
]);
31+
assert.equal(key, AGENT_2);
32+
});
33+
34+
it("sorts and lowercases channel-scoped pubkeys", () => {
35+
const key = channelScopedBotTypingPubkeyKey([
36+
{ pubkey: AGENT_2.toUpperCase(), threadHeadId: null },
37+
{ pubkey: AGENT, threadHeadId: null },
38+
]);
39+
assert.equal(key, `${AGENT},${AGENT_2}`);
40+
});
41+
});
42+
43+
describe("thread-only bot typing regression", () => {
44+
beforeEach(() => {
45+
resetActiveAgentTurnsStore();
46+
resetAgentWorkingSignal();
47+
});
48+
49+
it("does not mark channel-level working", () => {
50+
// The mirror effect reports only the channel-scoped key; thread-only
51+
// typing produces an empty key, so nothing reaches the working signal.
52+
const key = channelScopedBotTypingPubkeyKey([
53+
{ pubkey: AGENT, threadHeadId: "thread-1" },
54+
]);
55+
reportChannelBotTyping("chan-1", key ? key.split(",") : []);
56+
57+
assert.deepEqual(getWorkingAgentPubkeysForChannel("chan-1"), []);
58+
const state = getAgentWorkingState(AGENT, "chan-1");
59+
assert.equal(state.working, false);
60+
assert.equal(state.source, "none");
61+
});
62+
63+
it("still marks channel-level working for channel-scoped typing", () => {
64+
const key = channelScopedBotTypingPubkeyKey([
65+
{ pubkey: AGENT, threadHeadId: null },
66+
{ pubkey: AGENT_2, threadHeadId: "thread-1" },
67+
]);
68+
reportChannelBotTyping("chan-1", key ? key.split(",") : []);
69+
70+
assert.deepEqual(getWorkingAgentPubkeysForChannel("chan-1"), [AGENT]);
71+
const state = getAgentWorkingState(AGENT, "chan-1");
72+
assert.equal(state.working, true);
73+
assert.equal(state.source, "typing");
74+
});
75+
});

‎desktop/src/features/channels/ui/useChannelActivityTyping.ts‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ import {
1515
getChannelAgentSessionAgents,
1616
} from "./useChannelAgentSessions";
1717

18+
/**
19+
* Key of bot typing pubkeys that may mark the *channel* as working. Only
20+
* channel-scoped entries (`threadHeadId === null`) count — thread-only typing
21+
* must not light channel-level surfaces (composer bar, sidebar, profile);
22+
* thread surfaces apply their own `threadHeadId` filter.
23+
*/
24+
export function channelScopedBotTypingPubkeyKey(
25+
entries: readonly Pick<TypingIndicatorEntry, "pubkey" | "threadHeadId">[],
26+
): string {
27+
return entries
28+
.filter((entry) => entry.threadHeadId === null)
29+
.map((entry) => entry.pubkey.toLowerCase())
30+
.sort()
31+
.join(",");
32+
}
33+
1834
export function useChannelActivityTyping({
1935
activeChannel,
2036
activeChannelId,
@@ -88,11 +104,9 @@ export function useChannelActivityTyping({
88104
// Mirror bot typing into the unified working signal so surfaces that read
89105
// agentWorkingSignal (sidebar badges, activity panel, composer bar) get the
90106
// typing fallback. Entries follow the typing TTL because this effect
91-
// re-reports whenever botTypingEntries changes.
92-
const botTypingPubkeyKey = botTypingEntries
93-
.map((entry) => entry.pubkey.toLowerCase())
94-
.sort()
95-
.join(",");
107+
// re-reports whenever botTypingEntries changes. Thread-only typing is
108+
// excluded — see channelScopedBotTypingPubkeyKey.
109+
const botTypingPubkeyKey = channelScopedBotTypingPubkeyKey(botTypingEntries);
96110
React.useEffect(() => {
97111
if (!activeChannelId) {
98112
return;

0 commit comments

Comments
 (0)