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.

Seanaye/fix/load channel first (#7706)

Sean Ayec33b3e143d39
diff --git a/apps/web/src/features/channels-view/components/ChannelsMobileView.test.tsx b/apps/web/src/features/channels-view/components/ChannelsMobileView.test.tsx
index a551374cba..0e936f4738 100644
--- a/apps/web/src/features/channels-view/components/ChannelsMobileView.test.tsx
+++ b/apps/web/src/features/channels-view/components/ChannelsMobileView.test.tsx
@@ -1,8 +1,5 @@
import type { ChannelEntity } from '@entity/types/entity';
-import type {
- Notification,
- WithNotification,
-} from '@entity/types/notification';
+import type { Notification } from '@entity/types/notification';
import {
cleanup,
fireEvent,
@@ -30,6 +27,7 @@ const mocks = vi.hoisted(() => ({
mutedEntities: () => [],
},
handle: {},
+ failure: vi.fn(),
}));
vi.mock('@app/components/list', () => ({ createListController: () => ({}) }));
vi.mock('@app/features/next-soup/actions', () => ({
@@ -56,7 +54,9 @@ vi.mock('@components/app/split-layout/components/SplitHeader', () => ({
vi.mock('@components/app/split-layout/layoutUtils', () => ({
useSplitPanelOrThrow: () => ({ handle: mocks.handle }),
}));
-vi.mock('@core/component/Toast/Toast', () => ({ toast: { failure: vi.fn() } }));
+vi.mock('@core/component/Toast/Toast', () => ({
+ toast: { failure: mocks.failure },
+}));
vi.mock('@core/context/user', () => ({ useUserId: () => () => 'viewer' }));
vi.mock('@entity/utils/notification', () => ({ isMutedItem: () => false }));
vi.mock('@queries/channel/notification-selection', () => ({
@@ -105,31 +105,6 @@ const channel: ChannelEntity = {
{ id: 'reply-notification', state: 'unseen', createdAt: '2026-01-01' },
],
};
-const hydrated: WithNotification<ChannelEntity> = {
- ...channel,
- unreadNotifications: undefined,
- notifications: () => [
- {
- id: 'reply-notification',
- entity_id: channel.id,
- entity_type: 'channel',
- notification_event_type: 'channel_message_reply',
- notification_metadata: {
- tag: 'channel_message_reply',
- content: {
- messageId: 'reply',
- messageContent: 'Unread reply',
- threadId: 'root',
- channelType: 'private',
- },
- },
- sent: true,
- state: 'unseen',
- created_at: '2026-01-01',
- updated_at: '2026-01-01',
- },
- ],
-};
const source: ChannelsDataSource = {
items: () => [channel],
isLoading: () => false,
@@ -149,14 +124,8 @@ afterEach(cleanup);
describe('mobile channel activation', () => {
it.each<ChannelsQueryScope>(['recents', 'channels', 'direct_messages'])(
- 'hydrates and opens at latest with top-level read marking from %s',
+ 'opens immediately at latest with top-level read marking from %s',
async (tab) => {
- let resolve!: (channel: WithNotification<ChannelEntity>) => void;
- mocks.hydrate.mockReturnValueOnce(
- new Promise((done) => {
- resolve = done;
- })
- );
render(() => (
<ChannelsMobileView
source={source}
@@ -168,15 +137,12 @@ describe('mobile channel activation', () => {
));
fireEvent.click(screen.getByRole('button', { name: 'One' }));
- expect(mocks.hydrate).toHaveBeenCalledExactlyOnceWith(
- channel,
- mocks.source.withLocalOverrides
- );
- expect(mocks.openSplit).not.toHaveBeenCalled();
- resolve(hydrated);
+ expect(mocks.hydrate).not.toHaveBeenCalled();
+ expect(mocks.openSplit).toHaveBeenCalledOnce();
+ expect(mocks.failure).not.toHaveBeenCalled();
await waitFor(() =>
- expect(mocks.openSplit).toHaveBeenCalledExactlyOnceWith(hydrated, {
+ expect(mocks.openSplit).toHaveBeenCalledExactlyOnceWith(channel, {
splitHandle: mocks.handle,
referredFrom: 'channels',
notificationSource: mocks.source,
@@ -186,4 +152,30 @@ describe('mobile channel activation', () => {
);
}
);
+
+ it('still reports a navigation failure while the list is mounted', async () => {
+ const error = new Error('Navigation failed');
+ mocks.openSplit.mockRejectedValueOnce(error);
+ const log = vi.spyOn(console, 'error').mockImplementation(() => {});
+ try {
+ render(() => (
+ <ChannelsMobileView
+ source={source}
+ searchQuery=""
+ onClearSearch={() => {}}
+ tab="channels"
+ onTabChange={() => {}}
+ />
+ ));
+ fireEvent.click(screen.getByRole('button', { name: 'One' }));
+ await waitFor(() =>
+ expect(mocks.failure).toHaveBeenCalledExactlyOnceWith(
+ 'Unable to open conversation. Please try again.'
+ )
+ );
+ expect(log).toHaveBeenCalledWith('Failed to open conversation', error);
+ } finally {
+ log.mockRestore();
+ }
+ });
});
diff --git a/apps/web/src/features/channels-view/components/ChannelsMobileView.tsx b/apps/web/src/features/channels-view/components/ChannelsMobileView.tsx
index f68cf6f8f8..77dba8d881 100644
--- a/apps/web/src/features/channels-view/components/ChannelsMobileView.tsx
+++ b/apps/web/src/features/channels-view/components/ChannelsMobileView.tsx
@@ -15,7 +15,6 @@ import type { ChannelEntity } from '@entity';
import { isMutedItem } from '@entity/utils/notification';
import SpinnerIcon from '@phosphor/spinner.svg';
import XIcon from '@phosphor/x.svg';
-import { hydrateChannelNotificationSelection } from '@queries/channel/notification-selection';
import { createElementSize } from '@solid-primitives/resize-observer';
import { Button, EmptyStatePanel } from '@ui';
import {
@@ -128,12 +127,7 @@ export function ChannelsMobileView(props: {
const openChannel = async (channel: ChannelEntity) => {
const request = ++opening;
try {
- const full = await hydrateChannelNotificationSelection(
- channel,
- notificationSource.withLocalOverrides
- );
- if (request !== opening) return;
- await openEntityInSplitFromUnifiedList(full, {
+ await openEntityInSplitFromUnifiedList(channel, {
splitHandle: panel.handle,
referredFrom: 'channels',
notificationSource,
diff --git a/apps/web/src/features/next-soup/utils.test.ts b/apps/web/src/features/next-soup/utils.test.ts
index e9f1ee866f..aef8ef5d9b 100644
--- a/apps/web/src/features/next-soup/utils.test.ts
+++ b/apps/web/src/features/next-soup/utils.test.ts
@@ -16,6 +16,7 @@ vi.mock('@core/mobile/isTouchDevice', () => ({
}));
const toastAlert = vi.hoisted(() => vi.fn());
+const toastFailure = vi.hoisted(() => vi.fn());
const fetchChannelNotifications = vi.hoisted(() => vi.fn());
vi.mock('@service-storage/graphql-notifications', async (importOriginal) => ({
...(await importOriginal<
@@ -24,7 +25,7 @@ vi.mock('@service-storage/graphql-notifications', async (importOriginal) => ({
fetchGraphqlEntityNotifications: fetchChannelNotifications,
}));
vi.mock('@core/component/Toast/Toast', () => ({
- toast: { alert: toastAlert },
+ toast: { alert: toastAlert, failure: toastFailure },
}));
const operationMocks = vi.hoisted(() => {
@@ -152,7 +153,12 @@ import type {
OpenWithSplitOptions,
SplitManager,
} from '@components/app/split-layout/layoutManager';
-import { type ChannelEntityTarget, type EntityData, queryKeys } from '@entity';
+import {
+ type ChannelEntity,
+ type ChannelEntityTarget,
+ type EntityData,
+ queryKeys,
+} from '@entity';
import type { NotificationSource, UnifiedNotification } from '@notifications';
import { hydrateChannelNotificationSelection } from '@queries/channel/notification-selection';
import {
@@ -370,6 +376,216 @@ const channelThreadRow = (opts?: {
...(opts?.notifications ? { notifications: () => opts.notifications } : {}),
}) as unknown as EntityData;
+describe('non-blocking latest channel opens', () => {
+ function setup(status = 'opened') {
+ const channel: ChannelEntity = {
+ type: 'channel',
+ id: 'channel-1',
+ name: 'Channel',
+ ownerId: 'owner',
+ channelType: 'private',
+ isParticipant: true,
+ unreadNotifications: [],
+ };
+ const bulkMarkAsRead = vi.fn(async () => {});
+ const notificationsByEntity = vi.fn(() => ({
+ 'channel@channel-1': [sendNotification('stale-global', 'message')],
+ }));
+ const source = {
+ ...notificationSourceWithBulkMarkAsRead(bulkMarkAsRead),
+ notificationsByEntity,
+ withLocalOverrides: (notification: UnifiedNotification) => notification,
+ };
+ const isActive = vi.fn(() => true);
+ const view = {
+ owner: 'channel-pane',
+ topLevelSplit: { isActive },
+ };
+ const findOpenView = vi.fn((): typeof view | undefined => view);
+ const openWithSplit = vi.fn(
+ (_content: unknown, _options?: OpenWithSplitOptions) => ({ status })
+ );
+ setGlobalSplitManager({
+ activeSplit: vi.fn(),
+ getOrchestrator: () => ({
+ getBlockHandle: vi.fn(async () => undefined),
+ }),
+ findOpenView,
+ openWithSplit,
+ } as unknown as SplitManager);
+ const open = () =>
+ openEntityInSplitFromUnifiedList(channel, {
+ referredFrom: 'channels',
+ channelNavigation: 'latest',
+ channelReadScope: 'top-level',
+ notificationSource: source,
+ });
+ return {
+ channel,
+ source,
+ open,
+ openWithSplit,
+ bulkMarkAsRead,
+ notificationsByEntity,
+ findOpenView,
+ isActive,
+ };
+ }
+
+ it('opens before hydration settles, then marks only full-edge top-level unreads', async () => {
+ const test = setup();
+ let resolve!: (notifications: UnifiedNotification[]) => void;
+ fetchChannelNotifications.mockReturnValueOnce(
+ new Promise((done) => {
+ resolve = done;
+ })
+ );
+ const opening = test.open();
+ expect(test.openWithSplit).toHaveBeenCalledOnce();
+ expect(test.bulkMarkAsRead).not.toHaveBeenCalled();
+ // Opening itself completes while the notification request is still pending.
+ await opening;
+ expect(test.bulkMarkAsRead).not.toHaveBeenCalled();
+ const root = sendNotification('root', 'message');
+ resolve([
+ root,
+ asRead(sendNotification('seen', 'seen-message')),
+ replyNotification('reply', 'reply-message', 'message'),
+ ]);
+ await vi.waitFor(() =>
+ expect(test.bulkMarkAsRead).toHaveBeenCalledExactlyOnceWith([root])
+ );
+ expect(test.notificationsByEntity).not.toHaveBeenCalled();
+ expect(test.openWithSplit).toHaveBeenCalledOnce();
+ expect(toastFailure).not.toHaveBeenCalled();
+ });
+
+ it('keeps the channel open and leaves unread state untouched when hydration fails', async () => {
+ const test = setup();
+ const error = new Error('Conversation notifications are unavailable');
+ fetchChannelNotifications.mockRejectedValueOnce(error);
+ const log = vi.spyOn(console, 'error').mockImplementation(() => {});
+ try {
+ await test.open();
+ await vi.waitFor(() =>
+ expect(log).toHaveBeenCalledWith(
+ 'Failed to load conversation notifications after opening',
+ { channelId: 'channel-1', error }
+ )
+ );
+ expect(test.openWithSplit).toHaveBeenCalledOnce();
+ expect(test.bulkMarkAsRead).not.toHaveBeenCalled();
+ expect(test.notificationsByEntity).not.toHaveBeenCalled();
+ expect(toastFailure).not.toHaveBeenCalled();
+ } finally {
+ log.mockRestore();
+ }
+ });
+
+ it.each(['unavailable', 'navigating'])(
+ 'does not hydrate or mark notifications before an accepted open (%s)',
+ async (status) => {
+ const test = setup(status);
+ await test.open();
+ expect(fetchChannelNotifications).not.toHaveBeenCalled();
+ expect(test.bulkMarkAsRead).not.toHaveBeenCalled();
+ }
+ );
+
+ it('hydrates once after deferred navigation applies and keeps the pre-navigation identity', async () => {
+ const test = setup('navigating');
+ const root = sendNotification('root', 'message');
+ fetchChannelNotifications.mockResolvedValueOnce([root]);
+ await test.open();
+ test.channel.id = 'replacement-row';
+ const onApplied = test.openWithSplit.mock.calls[0][1]?.onApplied;
+ expect(onApplied).toBeDefined();
+ onApplied!();
+ onApplied!();
+ await vi.waitFor(() =>
+ expect(test.bulkMarkAsRead).toHaveBeenCalledExactlyOnceWith([root])
+ );
+ expect(fetchChannelNotifications).toHaveBeenCalledOnce();
+ expect(fetchChannelNotifications.mock.calls[0][1]).toBe('channel-1');
+ });
+
+ it.each(['closed', 'hidden'])(
+ 'does not mark a mobile channel read after its pane is %s',
+ async (state) => {
+ vi.mocked(isTouchDevice).mockReturnValue(true);
+ const test = setup();
+ let resolve!: (notifications: UnifiedNotification[]) => void;
+ fetchChannelNotifications.mockReturnValueOnce(
+ new Promise((done) => {
+ resolve = done;
+ })
+ );
+ await test.open();
+ if (state === 'closed') test.findOpenView.mockReturnValue(undefined);
+ else test.isActive.mockReturnValue(false);
+ resolve([sendNotification('root', 'message')]);
+ await vi.waitFor(() => expect(test.findOpenView).toHaveBeenCalled());
+ expect(test.bulkMarkAsRead).not.toHaveBeenCalled();
+ expect(test.openWithSplit).toHaveBeenCalledOnce();
+ }
+ );
+
+ it('honors local seen overrides after successful background hydration', async () => {
+ const test = setup();
+ test.source.withLocalOverrides = asRead;
+ fetchChannelNotifications.mockResolvedValueOnce([
+ sendNotification('already-seen', 'message'),
+ ]);
+ await test.open();
+ await vi.waitFor(() => expect(test.findOpenView).toHaveBeenCalled());
+ expect(test.bulkMarkAsRead).not.toHaveBeenCalled();
+ expect(test.notificationsByEntity).not.toHaveBeenCalled();
+ });
+
+ it('applies explicit message targets without waiting for notification hydration', async () => {
+ const test = setup();
+ test.channel.target = { messageId: 'message', threadId: 'root' };
+ fetchChannelNotifications.mockResolvedValueOnce([]);
+ await test.open();
+ expect(targetSearch(test.openWithSplit, 'channels')).toMatchObject({
+ messageId: ['message'],
+ threadId: ['root'],
+ });
+ expect(test.openWithSplit.mock.invocationCallOrder[0]).toBeLessThan(
+ fetchChannelNotifications.mock.invocationCallOrder[0]
+ );
+ });
+
+ it('preserves membership gating before starting background hydration', async () => {
+ const test = setup();
+ test.channel.isParticipant = false;
+ await test.open();
+ expect(test.openWithSplit).not.toHaveBeenCalled();
+ expect(fetchChannelNotifications).not.toHaveBeenCalled();
+ expect(test.bulkMarkAsRead).not.toHaveBeenCalled();
+ });
+
+ it('keeps notification-targeted inbox opens waiting for their full edge', async () => {
+ const test = setup();
+ let resolve!: (notifications: UnifiedNotification[]) => void;
+ fetchChannelNotifications.mockReturnValueOnce(
+ new Promise((done) => {
+ resolve = done;
+ })
+ );
+ const opening = openEntityInSplitFromUnifiedList(test.channel, {
+ notificationSource: test.source,
+ });
+ expect(test.openWithSplit).not.toHaveBeenCalled();
+ resolve([sendNotification('root', 'message')]);
+ await opening;
+ expect(test.openWithSplit).toHaveBeenCalledOnce();
+ expect(targetSearch(test.openWithSplit, 'channels')).toMatchObject({
+ messageId: ['message'],
+ });
+ });
+});
+
describe('channel unread clicks', () => {
const newer = {
...replyNotification('reply', 'newer', 'thread'),
diff --git a/apps/web/src/features/next-soup/utils.ts b/apps/web/src/features/next-soup/utils.ts
index 503818b6d6..0ddc1f98ed 100644
--- a/apps/web/src/features/next-soup/utils.ts
+++ b/apps/web/src/features/next-soup/utils.ts
@@ -688,7 +688,20 @@ export const openEntityInSplitFromUnifiedList = async (
const blockOrchestrator = splitManager.getOrchestrator();
- if (entity.type === 'channel' && entity.unreadNotifications !== undefined) {
+ // Latest opens do not need notifications to choose their destination. Snapshot
+ // the list row before navigation can dispose its Solid store, and hydrate only
+ // after the open is accepted. Inbox notification-targeted opens still wait.
+ const deferredChannel =
+ entity.type === 'channel' &&
+ entity.unreadNotifications !== undefined &&
+ options.channelNavigation === 'latest'
+ ? { ...entity }
+ : undefined;
+ if (
+ entity.type === 'channel' &&
+ entity.unreadNotifications !== undefined &&
+ !deferredChannel
+ ) {
try {
entity = await hydrateChannelNotificationSelection(
entity,
@@ -748,15 +761,45 @@ export const openEntityInSplitFromUnifiedList = async (
splitContent = withListNavigationSource(splitContent, splitHandle);
}
+ const hydrateNotificationsAndMarkSeen = async (
+ channel: ChannelEntity,
+ notificationSource: NotificationSource
+ ) => {
+ try {
+ const hydrated = await hydrateChannelNotificationSelection(
+ channel,
+ notificationSource.withLocalOverrides
+ );
+ const view = splitManager.findOpenView(content);
+ // A late response must not mark a closed conversation or a mobile pane
+ // that the user has already left. Hydration never reopens or retargets it.
+ if (!view || (isTouchDevice() && !view.topLevelSplit?.isActive())) return;
+ markChannelNotificationsSeenOnOpen(hydrated, notificationSource, {
+ channelReadScope: options.channelReadScope,
+ });
+ } catch (error) {
+ console.error('Failed to load conversation notifications after opening', {
+ channelId: channel.id,
+ error,
+ });
+ }
+ };
+
let markedNotifications = false;
const markNotificationsSeen = () => {
if (markedNotifications) return;
markedNotifications = true;
- if (options.notificationSource) {
- markChannelNotificationsSeenOnOpen(entity, options.notificationSource, {
- channelReadScope: options.channelReadScope,
- });
+ if (!options.notificationSource) return;
+ if (deferredChannel) {
+ void hydrateNotificationsAndMarkSeen(
+ deferredChannel,
+ options.notificationSource
+ );
+ return;
}
+ markChannelNotificationsSeenOnOpen(entity, options.notificationSource, {
+ channelReadScope: options.channelReadScope,
+ });
};
const result = splitManager.openWithSplit(splitContent, {
search: target ? searchLocationUpdates(content.id, target) : undefined,
diff --git a/docs/AGENT_GUIDE/channels.md b/docs/AGENT_GUIDE/channels.md
index 8f46f9de5f..5ea6381b62 100644
--- a/docs/AGENT_GUIDE/channels.md
+++ b/docs/AGENT_GUIDE/channels.md
@@ -469,8 +469,14 @@ seen without moving the conversation. No notification read marking runs
from an abbreviated list result, even if that result is empty. Access failures
show **Conversation unavailable** and stay hidden during retry until access is
confirmed. A route without cached channel metadata shows **Loading conversation**
-until its channel arrives. Mobile and opening in a new split retain the block
-host's existing notification-before-navigation flow.
+until its channel arrives. On mobile, opening from Recent, Channels, or DMs
+also navigates immediately: a slow or failed notification lookup must not prevent
+messages and the composer from loading. Full-edge notification hydration runs
+only after navigation is accepted; failure leaves unread state unchanged and
+must not show an “Unable to open conversation” toast. A late response must not
+reopen the channel or mark it read after the user leaves its mobile pane. Message
+loading retains its own access/error states. Verify with the notification request
+held, then failed, and with rapid back-navigation while it is pending.
The title bar's **Hide navigation** control hides the whole rail. Reopen it with
**Show navigation** (the hamburger) immediately before the conversation title.