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(agent-sessions): clear unread dots when opening session rows (#8658)

gbirmanef4db20fb7c7
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index db1eb1c5bb..b6450411bb 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -298,8 +298,9 @@ the user's newest account for that app from the last fifteen minutes.
- Add Google Meet account hints only to join actions using the displayed calendar's
connected email; keep stored and copied conference links unchanged. See the
[calendar walkthrough](../../docs/agent-guide/calendar.md).
-- Mark loaded calendar row notifications through the notification source so read
- dots update immediately and failed writes roll back; grid selections also mark
+- Mark loaded calendar and agent-session row notifications through the
+ notification source (`markRowNotificationsSeenOnOpen`) so read dots update
+ immediately and failed writes roll back; calendar grid selections also mark
the canonical event read, excluding team projections.
- Route explicit call exits using the server's `callEnded` result: ended calls
open their record; ongoing channel and scheduled calls return to the channel
diff --git a/apps/web/src/features/agents-view/views/AgentsView.tsx b/apps/web/src/features/agents-view/views/AgentsView.tsx
index c4e3d2e587..54c3237d6c 100644
--- a/apps/web/src/features/agents-view/views/AgentsView.tsx
+++ b/apps/web/src/features/agents-view/views/AgentsView.tsx
@@ -1,5 +1,6 @@
import { ViewShell } from '@app/components/view-shell';
import { startPendingSession } from '@app/features/block-agent/context/pending-session';
+import { markAgentSessionNotificationsSeenOnOpen } from '@app/features/block-agent/mark-session-notifications-seen';
import { AgentSettings } from '@app/features/settings/AgentSettings';
import { IntegrationsPage } from '@app/features/settings/IntegrationsPage';
import { withEntityNotifications } from '@app/features/soup/entity-notifications';
@@ -366,9 +367,14 @@ function AgentsWorkspace(props: { route?: AgentsRoute }) {
onSearchChange={setSearch}
showUnlistedRuns={showUnlistedRuns()}
onShowUnlistedRunsChange={setShowUnlistedRuns}
- onOpenConversation={(conversation, event) =>
- openConversation(conversation, event, modeForConversation(conversation))
- }
+ onOpenConversation={(conversation, event) => {
+ markAgentSessionNotificationsSeenOnOpen(conversation, notifications);
+ openConversation(
+ conversation,
+ event,
+ modeForConversation(conversation)
+ );
+ }}
onRetry={() => fireAndForget(query.refetch(), 'agents-view')}
onLoadMore={() => fireAndForget(query.fetchNextPage(), 'agents-view')}
/>
diff --git a/apps/web/src/features/block-agent/mark-session-notifications-seen.ts b/apps/web/src/features/block-agent/mark-session-notifications-seen.ts
new file mode 100644
index 0000000000..aa19ee18ee
--- /dev/null
+++ b/apps/web/src/features/block-agent/mark-session-notifications-seen.ts
@@ -0,0 +1,39 @@
+import {
+ type EntityWithRawNotifications,
+ getEntityNotifications,
+} from '@app/features/soup/entity-notifications';
+import { fireAndForget } from '@core/util/fireAndForget';
+import type { EntityData } from '@entity/types/entity';
+import { notificationIsRead } from '@entity/utils/notification';
+import { Telemetry } from '@macro-inc/observability';
+import type { NotificationSource } from '@notifications/notification-source';
+
+/**
+ * Clear the row's loaded dots before the session opens. The opened session's
+ * read marker still marks the whole entity, so rows without loaded
+ * notifications send nothing here.
+ */
+export function markAgentSessionNotificationsSeenOnOpen(
+ entity: EntityWithRawNotifications<EntityData>,
+ notificationSource: NotificationSource
+) {
+ if (entity.type !== 'agent_session') return;
+ const notifications = getEntityNotifications(
+ entity,
+ notificationSource
+ ).filter((notification) => !notificationIsRead(notification));
+ if (notifications.length === 0) return;
+ fireAndForget(
+ Telemetry.span('agent_session.notifications.mark_read', async (span) => {
+ span.setAttr('agent_session.id', entity.id);
+ span.setAttr('notification.count', notifications.length);
+ try {
+ await notificationSource.bulkMarkAsRead(notifications);
+ } catch (error) {
+ span.error(error);
+ throw error;
+ }
+ }),
+ 'agent-session-notification-read'
+ );
+}
diff --git a/apps/web/src/features/drive-view/drive-host-actions.ts b/apps/web/src/features/drive-view/drive-host-actions.ts
index 2a717e45ca..9c6a2114cb 100644
--- a/apps/web/src/features/drive-view/drive-host-actions.ts
+++ b/apps/web/src/features/drive-view/drive-host-actions.ts
@@ -4,7 +4,7 @@ import {
} from '@app/components/entity-detail/entity-detail-target';
import { makeShareAction } from '@app/features/next-soup/actions';
import {
- markCalendarNotificationSeenOnOpen,
+ markRowNotificationsSeenOnOpen,
openEntityInNewTab,
openEntityInSplitFromUnifiedList,
} from '@app/features/next-soup/utils';
@@ -83,7 +83,7 @@ export function createDriveHostActions(options: {
// Nested project/content targets reach this adapter. The main row
// consumes Cmd/Ctrl itself for selection.
if (event?.metaKey || event?.ctrlKey) {
- markCalendarNotificationSeenOnOpen(entity, notificationSource);
+ markRowNotificationsSeenOnOpen(entity, notificationSource);
openEntityInNewTab({ entity, location });
return;
@@ -95,7 +95,7 @@ export function createDriveHostActions(options: {
return;
}
- markCalendarNotificationSeenOnOpen(entity, notificationSource);
+ markRowNotificationsSeenOnOpen(entity, notificationSource);
const target =
openInNewSplit || location ? undefined : inlineDetailTarget(entity);
diff --git a/apps/web/src/features/home/components/HomeList.tsx b/apps/web/src/features/home/components/HomeList.tsx
index b7baab39c9..878a03f447 100644
--- a/apps/web/src/features/home/components/HomeList.tsx
+++ b/apps/web/src/features/home/components/HomeList.tsx
@@ -60,8 +60,8 @@ import {
} from '../../next-soup/soup-view/soup-navigation-touch-highlight';
import { InboxListEntity } from '../../next-soup/soup-view/views/inbox/InboxListEntity';
import {
- markCalendarNotificationSeenOnOpen,
markChannelNotificationsSeenOnOpen,
+ markRowNotificationsSeenOnOpen,
openEntityInSplitFromUnifiedList,
} from '../../next-soup/utils';
import { useHomeView } from '../home-view-context';
@@ -188,7 +188,7 @@ export function HomeList(props: HomeListProps) {
}
function markEntitySeen(entity: WithNotification<EntityData>) {
- markCalendarNotificationSeenOnOpen(entity, notificationSource);
+ markRowNotificationsSeenOnOpen(entity, notificationSource);
if (!isNonMemberChannelEntity(entity)) {
markChannelNotificationsSeenOnOpen(entity, notificationSource);
}
diff --git a/apps/web/src/features/next-soup/soup-view/soup-view.tsx b/apps/web/src/features/next-soup/soup-view/soup-view.tsx
index 5138783494..14f4da3467 100644
--- a/apps/web/src/features/next-soup/soup-view/soup-view.tsx
+++ b/apps/web/src/features/next-soup/soup-view/soup-view.tsx
@@ -48,8 +48,8 @@ import { TaskListEntity } from '@app/features/next-soup/soup-view/views/tasks/Ta
import { ResponsiveTaskListHeader } from '@app/features/next-soup/soup-view/views/tasks/TaskListHeader';
import { TaskGroupHeader } from '@app/features/next-soup/soup-view/views/tasks/task-group-header';
import {
- markCalendarNotificationSeenOnOpen,
markChannelNotificationsSeenOnOpen,
+ markRowNotificationsSeenOnOpen,
openEntityInNewTab,
openEntityInSplitFromUnifiedList,
restoreSoupFocus,
@@ -823,7 +823,7 @@ const SoupViewListContent = (props: SoupViewListProps) => {
return;
}
- markCalendarNotificationSeenOnOpen(entity, notificationSource);
+ markRowNotificationsSeenOnOpen(entity, notificationSource);
// FIXME: this never gets called because we have overrides
if (event.metaKey || event.ctrlKey) {
diff --git a/apps/web/src/features/next-soup/soup-view/use-soup-view-hotkeys.test.ts b/apps/web/src/features/next-soup/soup-view/use-soup-view-hotkeys.test.ts
index 2006b5e560..237d585f6b 100644
--- a/apps/web/src/features/next-soup/soup-view/use-soup-view-hotkeys.test.ts
+++ b/apps/web/src/features/next-soup/soup-view/use-soup-view-hotkeys.test.ts
@@ -18,7 +18,7 @@ vi.mock('@app/features/next-soup/sidebar/soup-filter-presets', () => ({
}));
vi.mock('@app/features/next-soup/utils', () => ({
markChannelNotificationsSeenOnOpen: vi.fn(),
- markCalendarNotificationSeenOnOpen: vi.fn(),
+ markRowNotificationsSeenOnOpen: vi.fn(),
openEntityInSplitFromUnifiedList: mocks.open,
}));
vi.mock('@app/lib/analytics/analytics-context', () => ({
diff --git a/apps/web/src/features/next-soup/soup-view/use-soup-view-hotkeys.ts b/apps/web/src/features/next-soup/soup-view/use-soup-view-hotkeys.ts
index 5f7a5aac2b..80379c7b8f 100644
--- a/apps/web/src/features/next-soup/soup-view/use-soup-view-hotkeys.ts
+++ b/apps/web/src/features/next-soup/soup-view/use-soup-view-hotkeys.ts
@@ -3,8 +3,8 @@ import { isListViewID, type ListView } from '@app/constants/list-views';
import { CommandState } from '@app/features/command/state';
import { VIEW_TAB_PRESETS } from '@app/features/next-soup/sidebar/soup-filter-presets';
import {
- markCalendarNotificationSeenOnOpen,
markChannelNotificationsSeenOnOpen,
+ markRowNotificationsSeenOnOpen,
openEntityInSplitFromUnifiedList,
} from '@app/features/next-soup/utils';
import { useAnalytics } from '@app/lib/analytics/analytics-context';
@@ -195,7 +195,7 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {
entity: EntityData,
openOptions: { location?: SearchLocation; openInNewSplit?: boolean }
) => {
- markCalendarNotificationSeenOnOpen(entity, notificationSource);
+ markRowNotificationsSeenOnOpen(entity, notificationSource);
await openEntityInSplitFromUnifiedList(entity, {
...openOptions,
splitHandle,
diff --git a/apps/web/src/features/next-soup/utils.ts b/apps/web/src/features/next-soup/utils.ts
index 37300f884d..7b31be48d8 100644
--- a/apps/web/src/features/next-soup/utils.ts
+++ b/apps/web/src/features/next-soup/utils.ts
@@ -1,5 +1,7 @@
import { isListViewID } from '@app/constants/list-views';
+import { markAgentSessionNotificationsSeenOnOpen } from '@app/features/block-agent/mark-session-notifications-seen';
import { getPreferredCalendarPeriodView } from '@app/features/calendar/calendar-preferences';
+import { markCalendarNotificationSeenOnOpen } from '@app/features/calendar/mark-event-notifications-seen';
import { openCalendarView } from '@app/features/calendar-view/calendar-navigation';
import {
type CalendarEventTime,
@@ -888,7 +890,17 @@ export function markChannelNotificationsSeenOnOpen(
});
}
-export { markCalendarNotificationSeenOnOpen } from '../calendar/mark-event-notifications-seen';
+/**
+ * Clear the dots of rows whose opened view has no block that marks the row's
+ * loaded notifications read: calendar events and agent sessions.
+ */
+export function markRowNotificationsSeenOnOpen(
+ entity: EntityWithRawNotifications<EntityData>,
+ notificationSource: NotificationSource
+) {
+ markCalendarNotificationSeenOnOpen(entity, notificationSource);
+ markAgentSessionNotificationsSeenOnOpen(entity, notificationSource);
+}
/**
* The event and instance a calendar row points at, resolved exactly as the
diff --git a/apps/web/src/features/notifications/tests/agent-session-notification-read.test.ts b/apps/web/src/features/notifications/tests/agent-session-notification-read.test.ts
new file mode 100644
index 0000000000..ad56b39e9e
--- /dev/null
+++ b/apps/web/src/features/notifications/tests/agent-session-notification-read.test.ts
@@ -0,0 +1,186 @@
+import { markAgentSessionNotificationsSeenOnOpen } from '@app/features/block-agent/mark-session-notifications-seen';
+import { withEntityNotifications } from '@app/features/soup/entity-notifications';
+import type { AgentSessionEntity } from '@entity/types/entity';
+import { unreadFilterFn } from '@entity/utils/filter';
+import { Telemetry } from '@macro-inc/observability';
+import type { ConnectionGatewayWebsocket } from '@service-connection/websocket';
+import { createRoot } from 'solid-js';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { createNotificationSource } from '../notification-source';
+import type { UnifiedNotification } from '../types';
+
+const mocks = vi.hoisted(() => ({
+ seen: vi.fn(),
+ entitySeen: vi.fn(),
+ feed: vi.fn(() => []),
+}));
+
+vi.mock('@core/constant/featureFlags', () => ({
+ ENABLE_DOCUMENT_MENTION_NOTIFICATIONS: true,
+ enableGraphqlSoup: { key: 'enable-graphql-soup' },
+ isFeatureEnabled: () => true,
+}));
+vi.mock('@macro-inc/collaboration/websocket', () => ({
+ createSocketEffect: vi.fn(),
+}));
+vi.mock('@queries/notification/user-notifications', () => ({
+ optimisticInsertNotification: vi.fn(),
+ useMarkNotificationsAsSeenMutation: () => ({ mutateAsync: mocks.seen }),
+ useMarkNotificationsAsDoneMutation: () => ({ mutateAsync: vi.fn() }),
+ useUserNotificationsQuery: () => ({
+ transport: 'graphql',
+ isLoading: false,
+ get data() {
+ return mocks.feed();
+ },
+ }),
+}));
+vi.mock('@queries/notification/notification-soup', () => ({
+ updateSoupForNotification: vi.fn(),
+}));
+vi.mock('@queries/notification/unsubscribes', () => ({
+ useMuteItemMutation: () => ({ mutateAsync: vi.fn() }),
+ useUnmuteItemMutation: () => ({ mutateAsync: vi.fn() }),
+}));
+vi.mock('@queries/notification/entity-mutations', () => ({
+ toNotificationEntityRef: vi.fn(() => ({
+ type: 'agent_session',
+ id: 'session',
+ })),
+ updateNotificationsForEntities: mocks.entitySeen,
+}));
+vi.mock('@service-storage/graphql-soup', () => ({
+ mapGraphqlNotification: (value: unknown) => value,
+}));
+vi.mock('@service-storage/graphql-soup-websocket', () => ({
+ subscribeToGraphqlNotificationPatches: () => () => {},
+}));
+vi.mock('../queries/muted-entities-query', () => ({
+ createMutedEntitiesQuery: () => ({ isPending: true }),
+}));
+
+const session: AgentSessionEntity = {
+ type: 'agent_session',
+ id: 'session',
+ name: 'Fix the flaky test',
+ ownerId: 'owner',
+ botId: 'bot',
+ status: 'idle',
+};
+const settled: UnifiedNotification = {
+ id: 'settled',
+ entity_id: session.id,
+ entity_type: 'agent_session',
+ state: 'unseen',
+ notification_event_type: 'agent_session_settled',
+ notification_metadata: {
+ tag: 'agent_session_settled',
+ content: {
+ sessionId: session.id,
+ sessionName: session.name,
+ botId: session.botId,
+ botName: 'Macro Coder',
+ channelId: 'channel',
+ threadId: 'thread',
+ turn: 3,
+ stopReason: 'end_turn',
+ excerpt: 'Done.',
+ },
+ },
+ created_at: '2026-10-23T17:00:00Z',
+ updated_at: '2026-10-23T17:00:00Z',
+ viewed_at: null,
+ sent: true,
+};
+
+function createSource() {
+ return createRoot((dispose) => ({
+ source: createNotificationSource({} as ConnectionGatewayWebsocket),
+ dispose,
+ }));
+}
+
+afterEach(() => vi.restoreAllMocks());
+
+describe('opening agent session notifications', () => {
+ it('leaves rows without loaded notifications to the opened session', () => {
+ const { source, dispose } = createSource();
+ try {
+ markAgentSessionNotificationsSeenOnOpen(
+ { ...session, notifications: [] },
+ source
+ );
+ expect(mocks.seen).not.toHaveBeenCalled();
+ expect(mocks.entitySeen).not.toHaveBeenCalled();
+ } finally {
+ dispose();
+ }
+ });
+
+ it.each(['array', 'accessor'] as const)(
+ 'clears an attached %s before the write finishes without loading the global feed',
+ async (shape) => {
+ mocks.feed.mockClear();
+ const pending = Promise.withResolvers<void>();
+ mocks.seen.mockReturnValueOnce(pending.promise);
+ const { source, dispose } = createSource();
+ const attached = [
+ { ...settled, id: `pending-${shape}` },
+ { ...settled, id: `done-${shape}`, state: 'done' as const },
+ { ...settled, id: `seen-${shape}`, state: 'seen' as const },
+ ];
+ const row = {
+ ...session,
+ notifications: shape === 'array' ? attached : () => attached,
+ };
+ const rendered = withEntityNotifications(row, source);
+ try {
+ expect(unreadFilterFn(rendered)).toBe(true);
+ markAgentSessionNotificationsSeenOnOpen(row, source);
+ expect(unreadFilterFn(rendered)).toBe(false);
+ expect(mocks.seen).toHaveBeenLastCalledWith({
+ notificationIds: [`pending-${shape}`],
+ });
+ expect(mocks.feed).not.toHaveBeenCalled();
+ pending.resolve();
+ await pending.promise;
+ expect(unreadFilterFn(withEntityNotifications(row, source))).toBe(
+ false
+ );
+ } finally {
+ pending.resolve();
+ dispose();
+ }
+ }
+ );
+
+ it('restores the dot after a failed write and clears it on a retry', async () => {
+ const pending = Promise.withResolvers<void>();
+ const reported = Promise.withResolvers<void>();
+ const telemetry = vi
+ .spyOn(Telemetry, 'error')
+ .mockImplementation(() => reported.resolve());
+ mocks.seen.mockReturnValueOnce(pending.promise);
+ const { source, dispose } = createSource();
+ const row = withEntityNotifications(
+ { ...session, notifications: [{ ...settled, id: 'failed-read' }] },
+ source
+ );
+ try {
+ markAgentSessionNotificationsSeenOnOpen(row, source);
+ expect(unreadFilterFn(row)).toBe(false);
+ const error = new Error('offline');
+ pending.reject(error);
+ await reported.promise;
+ expect(telemetry).toHaveBeenCalledWith(error, {
+ surface: 'agent-session-notification-read',
+ });
+ expect(unreadFilterFn(row)).toBe(true);
+ mocks.seen.mockResolvedValueOnce(undefined);
+ markAgentSessionNotificationsSeenOnOpen(row, source);
+ expect(unreadFilterFn(row)).toBe(false);
+ } finally {
+ dispose();
+ }
+ });
+});
diff --git a/apps/web/src/features/soup/createSoupEntityActions.ts b/apps/web/src/features/soup/createSoupEntityActions.ts
index 19f60a1c8a..ce6a7d1d48 100644
--- a/apps/web/src/features/soup/createSoupEntityActions.ts
+++ b/apps/web/src/features/soup/createSoupEntityActions.ts
@@ -31,7 +31,7 @@ import {
} from '@app/features/next-soup/actions';
import type { MarkDoneDelegate } from '@app/features/next-soup/actions/mark-done-delegate';
import {
- markCalendarNotificationSeenOnOpen,
+ markRowNotificationsSeenOnOpen,
openEntityInSplitFromUnifiedList,
restoreSoupFocus,
} from '@app/features/next-soup/utils';
@@ -292,7 +292,7 @@ export function createSoupEntityActions(
});
}
- markCalendarNotificationSeenOnOpen(entity, notificationSource);
+ markRowNotificationsSeenOnOpen(entity, notificationSource);
// Match row navigation, including a thread row's driving message.
await openEntityInSplitFromUnifiedList(entity, {
diff --git a/docs/agent-guide/home.md b/docs/agent-guide/home.md
index 1e24146b84..5c691b4640 100644
--- a/docs/agent-guide/home.md
+++ b/docs/agent-guide/home.md
@@ -122,9 +122,10 @@ explicitly saved favorites still open their context. Verify this alongside an
ordinary standalone session, which remains listed.
The Agents workspace uses a single left dot for activity and unread state in
-place of the sparkle. Opening a loaded session from Home or Agents marks its
-notifications read after the viewing delay, including notifications arriving
-while that session remains active.
+place of the sparkle. Clicking a session row in Home or the Agents sidebar
+clears the row's loaded unread dot immediately; a failed read write restores
+it. The opened session also marks its notifications read after the viewing
+delay, including notifications arriving while that session remains active.
Other Home items have no title tooltips, and their timestamps are
visible only while hovering the row. An unread
dot remains visible. Click a row to preview it; `j`/`k` navigate and update the