Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(channels): search every channel the user is in from the rail (#8360)

gbirman184a9aed891f
diff --git a/apps/web/src/features/agent-dms/queries/search-pool.ts b/apps/web/src/features/agent-dms/queries/search-pool.ts
deleted file mode 100644
index 52b85a6f45..0000000000
--- a/apps/web/src/features/agent-dms/queries/search-pool.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-import type { ChannelEntity } from '@entity/types/entity';
-import { useListChannelsQuery } from '@queries/channel/channels';
-import { createMemo } from 'solid-js';
-
-/** The existing complete channel list finds personas beyond the visible soup page. */
-export function useAgentDmSearchPool() {
- const channels = useListChannelsQuery();
- return createMemo<ChannelEntity[]>(() =>
- channels.isSuccess
- ? channels.data.flatMap((channel) =>
- channel.agent_dm
- ? [
- {
- id: channel.id,
- type: 'channel' as const,
- name: channel.agent_dm.name,
- channelType: 'direct_message' as const,
- ownerId: channel.owner_id,
- isParticipant: channel.is_participant,
- participantIds: channel.participants.map(
- (participant) => participant.user_id
- ),
- },
- ]
- : []
- )
- : []
- );
-}
diff --git a/apps/web/src/features/channels-view/channels-view.test.tsx b/apps/web/src/features/channels-view/channels-view.test.tsx
index 905f1a0046..c6c99380cf 100644
--- a/apps/web/src/features/channels-view/channels-view.test.tsx
+++ b/apps/web/src/features/channels-view/channels-view.test.tsx
@@ -31,8 +31,8 @@ const mocks = vi.hoisted(() => ({
refresh: vi.fn(async () => {}),
}));
-vi.mock('@app/features/agent-dms/queries/search-pool', () => ({
- useAgentDmSearchPool: () => () => [],
+vi.mock('./queries/channel-list-search-pool', () => ({
+ useChannelListSearchPool: () => () => [],
}));
vi.mock('@app/features/command/mobile/mobileSearchState', () => ({
SearchState: {
diff --git a/apps/web/src/features/channels-view/channels-view.tsx b/apps/web/src/features/channels-view/channels-view.tsx
index 0447fb9642..5f7df5dc27 100644
--- a/apps/web/src/features/channels-view/channels-view.tsx
+++ b/apps/web/src/features/channels-view/channels-view.tsx
@@ -1,5 +1,4 @@
import { ViewShell } from '@app/components/view-shell';
-import { useAgentDmSearchPool } from '@app/features/agent-dms/queries/search-pool';
import { SearchState } from '@app/features/command/mobile/mobileSearchState';
import { markChannelNotificationsSeenOnOpen } from '@app/features/next-soup/utils';
import { MaybeSoupEntityActionDrawerManager } from '@app/features/soup';
@@ -35,6 +34,7 @@ import {
useChannelsSources,
} from './queries';
import { createChannelDetailSource } from './queries/channel-detail-source';
+import { useChannelListSearchPool } from './queries/channel-list-search-pool';
import { createChannelSearchSource } from './queries/channel-search-source';
import { channelsTour } from './tour';
@@ -50,10 +50,10 @@ export type ChannelsViewProps = {
// Mounted inside the mobile list's Suspense boundary.
function MobileChannelsList(props: { sources: ChannelsSources }) {
- const agentDms = useAgentDmSearchPool();
+ const listChannels = useChannelListSearchPool();
const mobileSearchText = () => '';
const mobileSearchSource = createChannelSearchSource({
- additionalLocalChannels: agentDms,
+ additionalLocalChannels: listChannels,
text: mobileSearchText,
scope: () => 'recents',
source: () => props.sources.recents,
@@ -72,10 +72,10 @@ function DesktopChannelsRail(props: {
searchOpen: boolean;
onSearchOpenChange: (open: boolean) => void;
}) {
- const agentDms = useAgentDmSearchPool();
+ const listChannels = useChannelListSearchPool();
const [searchQuery, setSearchQuery] = createSignal('');
const searchSource = createChannelSearchSource({
- additionalLocalChannels: agentDms,
+ additionalLocalChannels: listChannels,
text: searchQuery,
enabled: () => props.searchOpen,
scope: () => 'search',
diff --git a/apps/web/src/features/channels-view/queries/channel-list-search-pool.ts b/apps/web/src/features/channels-view/queries/channel-list-search-pool.ts
new file mode 100644
index 0000000000..4eda810555
--- /dev/null
+++ b/apps/web/src/features/channels-view/queries/channel-list-search-pool.ts
@@ -0,0 +1,27 @@
+import { useChannelsContext } from '@core/context/channels';
+import type { ChannelEntity } from '@entity';
+import { createMemo } from 'solid-js';
+
+/**
+ * Every channel the viewer is in, as search entities. The Soup `search` list
+ * holds only its newest page, so the rail's local name search reads this
+ * complete list to find a conversation from the first keystroke. Names arrive
+ * viewer-resolved: a DM carries the other participant's display name and an
+ * agent DM its persona name.
+ */
+export function useChannelListSearchPool() {
+ const { channels } = useChannelsContext();
+ return createMemo<ChannelEntity[]>(() =>
+ channels().map((channel) => ({
+ id: channel.id,
+ type: 'channel',
+ name: channel.agent_dm?.name ?? (channel.name || 'Unknown Channel'),
+ channelType: channel.channel_type,
+ ownerId: channel.owner_id,
+ isParticipant: channel.is_participant,
+ participantIds: channel.participants.map(
+ (participant) => participant.user_id
+ ),
+ }))
+ );
+}
diff --git a/apps/web/src/features/channels-view/queries/channel-search-source.test.ts b/apps/web/src/features/channels-view/queries/channel-search-source.test.ts
index 0d8a0617b6..7b5650c777 100644
--- a/apps/web/src/features/channels-view/queries/channel-search-source.test.ts
+++ b/apps/web/src/features/channels-view/queries/channel-search-source.test.ts
@@ -1,12 +1,20 @@
import type { ChannelEntity } from '@entity/types/entity';
import type { useSearchSoupQuery } from '@queries/soup/search';
-import { createRoot, createSignal } from 'solid-js';
+import type { ApiChannelWithLatest } from '@service-storage/channel-list-types';
+import { type Accessor, createRoot, createSignal } from 'solid-js';
import { createStore } from 'solid-js/store';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import type { ChannelsDataSource, ChannelsSourceScope } from '../queries';
+import { useChannelListSearchPool } from './channel-list-search-pool';
import { createChannelSearchSource } from './channel-search-source';
const queryMock = vi.hoisted(() => vi.fn());
+const channelList = vi.hoisted(() => ({
+ channels: (): ApiChannelWithLatest[] => [],
+}));
+vi.mock('@core/context/channels', () => ({
+ useChannelsContext: () => ({ channels: () => channelList.channels() }),
+}));
vi.mock('@queries/soup/search', () => ({
useSearchSoupQuery: queryMock,
validateSearchServiceText: (text: string) => text.length >= 3,
@@ -30,9 +38,81 @@ const channel = (id: string, name: string, direct = false): ChannelEntity => ({
});
const localChannel = channel('channel', 'Alpha channel');
const localDm = channel('dm', 'Alpha person', true);
+const supportChannel: ApiChannelWithLatest = {
+ id: 'support-acme',
+ name: 'Macro Support x Acme',
+ channel_type: 'private',
+ owner_id: 'viewer',
+ created_at: '2026-01-01T00:00:00Z',
+ updated_at: '2026-01-01T00:00:00Z',
+ auto_join_team: false,
+ is_participant: true,
+ participants: [
+ {
+ channel_id: 'support-acme',
+ user_id: 'viewer',
+ role: 'owner',
+ joined_at: '2026-01-01T00:00:00Z',
+ },
+ {
+ channel_id: 'support-acme',
+ user_id: 'acme-admin',
+ role: 'member',
+ joined_at: '2026-01-01T00:00:00Z',
+ },
+ ],
+};
+// The list names a DM after the other participant and an agent DM after its persona.
+const personDm: ApiChannelWithLatest = {
+ id: 'dm-ada',
+ name: 'Ada Acme',
+ channel_type: 'direct_message',
+ owner_id: 'viewer',
+ created_at: '2026-01-01T00:00:00Z',
+ updated_at: '2026-01-01T00:00:00Z',
+ auto_join_team: false,
+ is_participant: true,
+ participants: [
+ {
+ channel_id: 'dm-ada',
+ user_id: 'viewer',
+ role: 'owner',
+ joined_at: '2026-01-01T00:00:00Z',
+ },
+ {
+ channel_id: 'dm-ada',
+ user_id: 'ada',
+ role: 'member',
+ joined_at: '2026-01-01T00:00:00Z',
+ },
+ ],
+};
+const personaDm: ApiChannelWithLatest = {
+ id: 'agent-dm',
+ name: 'Archivist',
+ channel_type: 'direct_message',
+ owner_id: 'viewer',
+ created_at: '2026-01-01T00:00:00Z',
+ updated_at: '2026-01-01T00:00:00Z',
+ auto_join_team: false,
+ is_participant: true,
+ agent_dm: { bot_id: 'archivist', name: 'Archivist' },
+ participants: [
+ {
+ channel_id: 'agent-dm',
+ user_id: 'viewer',
+ role: 'owner',
+ joined_at: '2026-01-01T00:00:00Z',
+ },
+ ],
+};
let dispose: (() => void) | undefined;
-function setup(initialText = '', initialScope: ChannelsSourceScope = 'search') {
+function setup(
+ initialText = '',
+ initialScope: ChannelsSourceScope = 'search',
+ pool?: () => Accessor<ChannelEntity[]>
+) {
return createRoot((cleanup) => {
dispose = cleanup;
const [text, setText] = createSignal(initialText);
@@ -115,7 +195,7 @@ function setup(initialText = '', initialScope: ChannelsSourceScope = 'search') {
scope,
enabled,
source: () => local,
- additionalLocalChannels: extra,
+ additionalLocalChannels: pool?.() ?? extra,
});
return {
source,
@@ -141,29 +221,66 @@ describe('shared channel search source', () => {
beforeEach(() => {
vi.useFakeTimers();
vi.clearAllMocks();
+ channelList.channels = () => [];
});
afterEach(() => {
dispose?.();
vi.useRealTimers();
});
- it('finds an agent persona outside the loaded page and keeps it out of channel-only results', async () => {
- const s = setup('archivist', 'direct_messages');
- s.setExtra([channel('agent-dm', 'Archivist', true)]);
+ it('finds conversations beyond the loaded page in the complete channel list as it loads', async () => {
+ const [list, setList] = createSignal<ApiChannelWithLatest[]>([]);
+ channelList.channels = list;
+ const s = setup('acme', 'search', useChannelListSearchPool);
+ await vi.advanceTimersByTimeAsync(300);
+ expect(ids(s.source)).toEqual([]);
+ setList([supportChannel, personDm, personaDm]);
+ expect(new Set(ids(s.source))).toEqual(new Set(['support-acme', 'dm-ada']));
+ expect(
+ s.source.items().find((row) => row.id === 'support-acme')
+ ).toMatchObject({
+ name: 'Macro Support x Acme',
+ channelType: 'private',
+ ownerId: 'viewer',
+ isParticipant: true,
+ participantIds: ['viewer', 'acme-admin'],
+ });
+ expect(s.source.items().find((row) => row.id === 'dm-ada')?.name).toBe(
+ 'Ada Acme'
+ );
+ s.setScope('channels');
+ expect(ids(s.source)).toEqual(['support-acme']);
+ s.setScope('direct_messages');
+ expect(ids(s.source)).toEqual(['dm-ada']);
+ s.setText('archivist');
await vi.advanceTimersByTimeAsync(300);
expect(ids(s.source)).toEqual(['agent-dm']);
s.setScope('channels');
expect(ids(s.source)).toEqual([]);
});
- it('deduplicates a persona already in the visible page before local and remote matching', async () => {
+ it('prefers the loaded row over the complete-list entity for the same channel', async () => {
+ const loadedDm = {
+ ...localDm,
+ unreadNotifications: [
+ { id: 'unread', state: 'unseen' as const, createdAt: '2026-01-01' },
+ ],
+ latestRootMessage: {
+ messageId: 'message',
+ senderId: 'dm',
+ content: 'Hello',
+ mentions: [],
+ createdAt: '2026-09-28T12:00:00Z',
+ },
+ };
const s = setup('alpha');
+ s.setRows([localChannel, loadedDm]);
s.setExtra([{ ...localDm, name: 'Alpha persona' }]);
s.setRemote('data', [localDm]);
await vi.advanceTimersByTimeAsync(300);
expect(ids(s.source).filter((id) => id === localDm.id)).toHaveLength(1);
- expect(s.source.items().find((row) => row.id === localDm.id)?.name).toBe(
- localDm.name
+ expect(s.source.items().find((row) => row.id === localDm.id)).toMatchObject(
+ loadedDm
);
});
diff --git a/apps/web/src/features/channels-view/queries/channel-search-source.ts b/apps/web/src/features/channels-view/queries/channel-search-source.ts
index 24ad5f7d87..1a7c091161 100644
--- a/apps/web/src/features/channels-view/queries/channel-search-source.ts
+++ b/apps/web/src/features/channels-view/queries/channel-search-source.ts
@@ -18,15 +18,18 @@ export function createChannelSearchSource(options: {
}): ChannelsDataSource {
const enabled = () => options.enabled?.() ?? true;
const searching = () => options.text().trim().length > 0;
- const localChannels = createMemo(
- () =>
- new Map(
- [
- ...(options.additionalLocalChannels?.() ?? []),
- ...options.source().items(),
- ].map((channel) => [channel.id, channel])
- )
- );
+ // Loaded rows carry the unread and preview metadata the rail renders, so a
+ // loaded row replaces the additional entity for the same channel.
+ const localChannels = createMemo(() => {
+ const byId = new Map<string, ChannelEntity>();
+ for (const channel of options.additionalLocalChannels?.() ?? []) {
+ byId.set(channel.id, channel);
+ }
+ for (const channel of options.source().items()) {
+ byId.set(channel.id, channel);
+ }
+ return byId;
+ });
const search = createSearchState({
enabled,
text: options.text,
diff --git a/docs/agent-guide/channels.md b/docs/agent-guide/channels.md
index 380f3af4ae..b49b4c47ee 100644
--- a/docs/agent-guide/channels.md
+++ b/docs/agent-guide/channels.md
@@ -894,12 +894,15 @@ query, then scrolls the results to the selected channel when present or to the
start. Closing search restores the active tab and applies the same scroll
behavior to its lists. An empty result uses the standard search empty state
artwork and wraps long queries. Desktop channel name search combines local fuzzy
-matches and service results,
-deduplicated by channel ID, across channels and DMs. An empty query shows the
-ordinary list. Scrolling search results loads the next search page; clearing the
-query restores ordinary list pagination. Check a matching query, a query with no
-matches, and a clear/reopen cycle. Mobile dock search uses the independent Search
-route described below.
+matches and service results, deduplicated by channel ID, across channels and
+DMs. The local matches cover every conversation the viewer is in (the complete
+channel list, not only the loaded page), so a channel outside the newest hundred
+appears from the first keystroke; a loaded row keeps its unread and preview
+metadata when it matches. An empty query shows the ordinary list. Scrolling
+search results loads the next search page; clearing the query restores ordinary
+list pagination. Check a matching query, a query for a conversation absent from
+the ordinary list, a query with no matches, and a clear/reopen cycle. Mobile dock
+search uses the independent Search route described below.
Recent search includes both channels and DMs, including service hits without
message previews. It does not require message metadata or an importance filter.
Loaded conversation metadata is preserved when a service hit has the same ID.