Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(notifications): share immediate read behavior across opened items (#9448)
gbirman25f6d1b65314
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.mdindex 8e1dc883ef..89ec868d70 100644--- a/apps/web/AGENTS.md+++ b/apps/web/AGENTS.md@@ -549,10 +549,15 @@ resolved session ID; keep the existing `AgentSessionProvider` subscription to- Add Google Meet account hints only to join actions using the displayed calendar'sconnected email; keep stored and copied conference links unchanged. See the[calendar walkthrough](../../docs/agent-guide/calendar.md).-- Mark loaded calendar, agent-session, and CRM company/contact row notifications- through the notification source (`markRowNotificationsSeenOnOpen`) so read dots update- immediately and failed writes roll back; calendar grid selections and links- to an event also mark the canonical event read, excluding team projections.+- Share row-open reads through `features/notifications/mark-row-seen.ts` for+ documents/tasks, legacy chats, email, calendar, agents, CRM, PRs, calls, and+ projects; use it for previews, keyboard following, action advance, and split+ opens. Keep email mailbox writes in `queries/email/read-state.ts` with the+ owning inbox, and keep channel/external-message visibility policies separate.+ Ready document/chat/PR/email details mark read on mount for direct links.+ Calendar grid selections and links mark the canonical event, excluding team projections.+- Target modern projects as `initiative` / `INITIATIVE` for entity-wide+ notification writes; reserve `project` / `PROJECT` for legacy Drive folders.- Route explicit meeting-page exits using the server's `callEnded` result: endedcalls open their record; ongoing channel and scheduled calls return to thechannel and Calendar. Leaving from a channel's Call tab stays in the channel. Preserve the session ID and send the server leave before mediadiff --git a/apps/web/src/features/agents-view/views/AgentsView.tsx b/apps/web/src/features/agents-view/views/AgentsView.tsxindex 2f0df41920..0e147c4fb8 100644--- a/apps/web/src/features/agents-view/views/AgentsView.tsx+++ b/apps/web/src/features/agents-view/views/AgentsView.tsx@@ -1,6 +1,5 @@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';@@ -22,6 +21,7 @@ import { useUserId } from '@core/context/user';import { isTouchDevice } from '@core/mobile/isTouchDevice';import { ListEntityMetadataQueryProvider } from '@entity';import SpinnerIcon from '@icon/system/regular/spinner.svg';+import { markRowNotificationsSeenOnOpen } from '@notifications/mark-row-seen';import { useWarmAgentSessionQuery } from '@queries/agent-session/warm';import { useSoupAstItemsQuery } from '@queries/soup/items';import {@@ -376,7 +376,7 @@ function AgentsWorkspace(props: { route?: AgentsRoute }) {showUnlistedRuns={showUnlistedRuns()}onShowUnlistedRunsChange={setShowUnlistedRuns}onOpenConversation={(conversation, event) => {- markAgentSessionNotificationsSeenOnOpen(conversation, notifications);+ markRowNotificationsSeenOnOpen(conversation, notifications);openConversation(conversation,event,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.tsdeleted file mode 100644index aa19ee18ee..0000000000--- a/apps/web/src/features/block-agent/mark-session-notifications-seen.ts+++ /dev/null@@ -1,39 +0,0 @@-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/block-chat/component/Block.tsx b/apps/web/src/features/block-chat/component/Block.tsxindex 521600c81a..10a8189e96 100644--- a/apps/web/src/features/block-chat/component/Block.tsx+++ b/apps/web/src/features/block-chat/component/Block.tsx@@ -5,7 +5,7 @@ import { SidePanel } from '@components/app/side-panel';import { useBlockId } from '@core/block';import { DocumentBlockContainer } from '@core/component/DocumentBlockContainer';import { useBlockDocumentName } from '@core/util/currentBlockDocumentName';-import { DebouncedNotificationReadMarker } from '@notifications';+import { NotificationReadMarker } from '@notifications';import { Show } from 'solid-js';import { chatBlockData } from '../signal/chatBlockData';import { Chat } from './Chat';@@ -20,7 +20,7 @@ export default function ChatBlock() {return (<DocumentBlockContainer title={name()}><div class="size-full" tabIndex={-1}>- <DebouncedNotificationReadMarker+ <NotificationReadMarkernotificationSource={notificationSource}entity={{ type: 'chat', id: blockId }}/>diff --git a/apps/web/src/features/block-email/component/Block.tsx b/apps/web/src/features/block-email/component/Block.tsxindex ca305b9278..d7bfd4c1f7 100644--- a/apps/web/src/features/block-email/component/Block.tsx+++ b/apps/web/src/features/block-email/component/Block.tsx@@ -83,7 +83,6 @@ export default function BlockEmail() {threadId={threadId()}isLocalDraft={source.isLocalDraft()}linkId={threadData()?.link_id}- debounceTime={100}onRetry={() => fireAndForget(threadQuery.refetch(), 'email-thread')}><Show when={threadId()}>diff --git a/apps/web/src/features/block-email/component/EmailThreadLoadGate.test.tsx b/apps/web/src/features/block-email/component/EmailThreadLoadGate.test.tsxindex 244983b601..126b560035 100644--- a/apps/web/src/features/block-email/component/EmailThreadLoadGate.test.tsx+++ b/apps/web/src/features/block-email/component/EmailThreadLoadGate.test.tsx@@ -21,7 +21,7 @@ vi.mock('@queries/email/local-draft-source', () => ({}));beforeEach(() => localDrafts.mockReset().mockReturnValue([]));vi.mock('@notifications', () => ({- EmailDebouncedReadMarker: (props: { threadId: string; linkId?: string }) => {+ EmailReadMarker: (props: { threadId: string; linkId?: string }) => {const id = props.threadId;onMount(() => markers.mounts.push(id));onCleanup(() => markers.releases.push(id));diff --git a/apps/web/src/features/block-email/component/EmailThreadLoadGate.tsx b/apps/web/src/features/block-email/component/EmailThreadLoadGate.tsxindex ed271278b2..319bca0124 100644--- a/apps/web/src/features/block-email/component/EmailThreadLoadGate.tsx+++ b/apps/web/src/features/block-email/component/EmailThreadLoadGate.tsx@@ -3,14 +3,14 @@ import {EntityLoadGate,type EntityLoadResult,} from '@core/component/EntityLoadGate';-import { EmailDebouncedReadMarker } from '@notifications';+import { EmailReadMarker } from '@notifications';import type { ComponentProps, ParentProps } from 'solid-js';import { Show, Suspense } from 'solid-js';export type EmailThreadLoadGateProps<Data> = ParentProps<{result: EntityLoadResult<Data>;notificationSource: ComponentProps<- typeof EmailDebouncedReadMarker+ typeof EmailReadMarker>['notificationSource'];threadId: string;/** An account-owned working copy whose thread has never been confirmed. */@@ -48,7 +48,7 @@ export function EmailThreadLoadGate<Data>(><Show when={!props.isLocalDraft && props.threadId} keyed>{(threadId) => (- <EmailDebouncedReadMarker+ <EmailReadMarkernotificationSource={props.notificationSource}threadId={threadId}linkId={props.linkId}diff --git a/apps/web/src/features/block-md/component/Block.tsx b/apps/web/src/features/block-md/component/Block.tsxindex eaaf16e723..774c4505be 100644--- a/apps/web/src/features/block-md/component/Block.tsx+++ b/apps/web/src/features/block-md/component/Block.tsx@@ -26,7 +26,7 @@ import {useIsDocumentOwner,} from '@core/signal/permissions';import { useBlockDocumentName } from '@core/util/currentBlockDocumentName';-import { DocumentDebouncedNotificationReadMarker } from '@notifications';+import { DocumentNotificationReadMarker } from '@notifications';import { Show, Suspense } from 'solid-js';import { createMarkdownDocumentState } from '../context/markdown-document-state';import type { MarkdownData } from '../definition';@@ -160,7 +160,7 @@ export default function MarkdownBlockAdapter(props: BlockMarkdownProps) {</div></Suspense></div>- <DocumentDebouncedNotificationReadMarker+ <DocumentNotificationReadMarkernotificationSource={notificationSource}documentId={documentId}/>diff --git a/apps/web/src/features/block-pr/views/PrDetail.test.ts b/apps/web/src/features/block-pr/views/PrDetail.test.tsindex 3b390c964f..1c1d49a68f 100644--- a/apps/web/src/features/block-pr/views/PrDetail.test.ts+++ b/apps/web/src/features/block-pr/views/PrDetail.test.ts@@ -25,7 +25,7 @@ vi.mock('@entity/components/GithubLabelPill', () => ({GithubLabelPills: () => null,}));vi.mock('@notifications', () => ({- DebouncedNotificationReadMarker: () => null,+ NotificationReadMarker: () => null,}));vi.mock('@queries/storage/github-pull-requests', () => ({useRefreshGithubPullRequest: (diff --git a/apps/web/src/features/block-pr/views/PrDetail.tsx b/apps/web/src/features/block-pr/views/PrDetail.tsxindex ebb5678211..25887685a9 100644--- a/apps/web/src/features/block-pr/views/PrDetail.tsx+++ b/apps/web/src/features/block-pr/views/PrDetail.tsx@@ -17,7 +17,7 @@ import { GithubLabelPills } from '@entity/components/GithubLabelPill';import { PrAgentSessionsChip } from '@entity/views/PrAgentSessionsChip';import IconShared from '@icon/share.svg';import IconLink from '@icon/system/regular/link.svg';-import { DebouncedNotificationReadMarker } from '@notifications';+import { NotificationReadMarker } from '@notifications';import {type GithubPullRequestWithDetails,useRefreshGithubPullRequest,@@ -130,7 +130,7 @@ export function PrDetailBody(props: PrDetailBodyProps) {const notificationSource = useGlobalNotificationSource();return (<>- <DebouncedNotificationReadMarker+ <NotificationReadMarkernotificationSource={notificationSource}entity={{ type: 'foreign_entity', id: props.foreignEntityId }}/>diff --git a/apps/web/src/features/calendar/mark-event-notifications-seen.ts b/apps/web/src/features/calendar/mark-event-notifications-seen.tsdeleted file mode 100644index 31dc3045da..0000000000--- a/apps/web/src/features/calendar/mark-event-notifications-seen.ts+++ /dev/null@@ -1,30 +0,0 @@-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 { markNotificationsForEntityAsRead } from '@notifications/notification-helpers';-import type { NotificationSource } from '@notifications/notification-source';--/** Clear the reminders shown by the row before its calendar view opens. */-export function markCalendarNotificationSeenOnOpen(- entity: EntityWithRawNotifications<EntityData>,- notificationSource: NotificationSource-) {- if (entity.type !== 'calendar_event') return;- const notifications = getEntityNotifications(- entity,- notificationSource- ).filter((notification) => !notificationIsRead(notification));- fireAndForget(- notifications.length > 0- ? notificationSource.bulkMarkAsRead(notifications)- : markNotificationsForEntityAsRead(notificationSource, {- type: entity.type,- id: entity.id,- }),- 'calendar-notification-read'- );-}diff --git a/apps/web/src/features/crm/README.md b/apps/web/src/features/crm/README.mdindex 1fb957d0f8..7e59d806d4 100644--- a/apps/web/src/features/crm/README.md+++ b/apps/web/src/features/crm/README.md@@ -32,7 +32,7 @@ The root adapters construct production dependencies. `context` defines thecapabilities; it does not import their implementations. Views consume thesecapabilities, primitives receive narrow inputs, and components render props.Core modules remain independent of Solid, service clients, and app state.-`mark-record-notifications-seen.ts` integrates with shared list activation so+`features/notifications/mark-row-seen.ts` integrates with shared list activation soopening a company or contact clears its row's unread notifications immediately.It uses the row's attached notifications before falling back to an entity read;the shared notification source owns optimistic state and failure rollback.diff --git a/apps/web/src/features/crm/mark-record-notifications-seen.ts b/apps/web/src/features/crm/mark-record-notifications-seen.tsdeleted file mode 100644index 5574b1d91e..0000000000--- a/apps/web/src/features/crm/mark-record-notifications-seen.ts+++ /dev/null@@ -1,55 +0,0 @@-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 {- ensureNotificationSourceLoaded,- markNotificationsForEntityAsRead,-} from '@notifications/notification-helpers';-import type { NotificationSource } from '@notifications/notification-source';--/** Clear a company or contact row's unread dot when its details open. */-export function markCrmNotificationsSeenOnOpen(- entity: EntityWithRawNotifications<EntityData>,- notificationSource: NotificationSource-) {- if (entity.type !== 'crm_company' && entity.type !== 'crm_contact') return;-- const hasLoadedNotifications =- entity.notifications !== undefined ||- notificationSource._notificationsQuery.isStarted;- const notifications = hasLoadedNotifications- ? getEntityNotifications(entity, notificationSource).filter(- (notification) => !notificationIsRead(notification)- )- : [];-- fireAndForget(- Telemetry.span('crm.notifications.mark_read', async (span) => {- span.setAttr('entity.id', entity.id);- span.setAttr('entity.type', entity.type);- span.setAttr('notification.count', notifications.length);- try {- if (notifications.length > 0) {- await notificationSource.bulkMarkAsRead(notifications);- } else {- if (notificationSource._notificationsQuery.transport === 'rest') {- await ensureNotificationSourceLoaded(notificationSource);- }- await markNotificationsForEntityAsRead(notificationSource, {- type: entity.type,- id: entity.id,- });- }- } catch (error) {- span.error(error);- throw error;- }- }),- 'crm-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.tsindex 9c6a2114cb..13bd0fe3ba 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,6 @@ import {} from '@app/components/entity-detail/entity-detail-target';import { makeShareAction } from '@app/features/next-soup/actions';import {- markRowNotificationsSeenOnOpen,openEntityInNewTab,openEntityInSplitFromUnifiedList,} from '@app/features/next-soup/utils';@@ -25,6 +24,7 @@ import {openFolderPicker,} from '@core/util/upload';import type { EntityData } from '@entity';+import { markRowNotificationsSeenOnOpen } from '@notifications/mark-row-seen';import type { Accessor } from 'solid-js';import type { DriveHostActions } from './context/drive-context';import { useDriveDetailNavigation } from './drive-detail-navigation';diff --git a/apps/web/src/features/drive-view/drive-view.tsx b/apps/web/src/features/drive-view/drive-view.tsxindex ad95201d0b..dfc83a7f00 100644--- a/apps/web/src/features/drive-view/drive-view.tsx+++ b/apps/web/src/features/drive-view/drive-view.tsx@@ -17,6 +17,7 @@ import { enableDatabases, enableForms } from '@core/constant/featureFlags';import { useUserId } from '@core/context/user';import { fireAndForget } from '@core/util/fireAndForget';import { ListEntityMetadataQueryProvider } from '@entity';+import { markRowNotificationsSeenOnOpen } from '@notifications/mark-row-seen';import { useTagSets, useTagSetsReady } from '@property/tags/tag-sets-context';import {createEffect,@@ -170,6 +171,7 @@ function DriveComposition(props: { route: DriveRouteState }) {controller: list.controller,handle: panel.handle,openEntityInSplit: (entity, options) => {+ markRowNotificationsSeenOnOpen(entity, notificationSource);fireAndForget(openEntityInSplitFromUnifiedList(entity, {splitHandle: panel.handle,diff --git a/apps/web/src/features/drive-view/views/MarkdownDetail.tsx b/apps/web/src/features/drive-view/views/MarkdownDetail.tsxindex 61f8b10cf7..c552b4663c 100644--- a/apps/web/src/features/drive-view/views/MarkdownDetail.tsx+++ b/apps/web/src/features/drive-view/views/MarkdownDetail.tsx@@ -23,7 +23,7 @@ import { blockNameToDefaultFile } from '@core/constant/allBlocks';import { ENABLE_MARKDOWN_SIDE_PANEL } from '@core/constant/featureFlags';import { createMethodRegistration } from '@core/orchestrator';import SpinnerIcon from '@icon/system/regular/spinner.svg';-import { DocumentDebouncedNotificationReadMarker } from '@notifications';+import { DocumentNotificationReadMarker } from '@notifications';import { useItemRawName } from '@queries/preview';import { Button } from '@ui';import { createComputed, type JSX, Match, Show, Switch } from 'solid-js';@@ -128,7 +128,7 @@ function MarkdownDetailContent(props: {<div class="absolute top-1.5 right-4 z-action-menu flex justify-end"><FindAndReplace hotkeyScope={panel.splitHotkeyScope} /></div>- <DocumentDebouncedNotificationReadMarker+ <DocumentNotificationReadMarkernotificationSource={notificationSource}documentId={props.documentId}/>diff --git a/apps/web/src/features/email-thread/thread-read-adapter.ts b/apps/web/src/features/email-thread/thread-read-adapter.tsindex 6d4305eb50..1fc9d589d0 100644--- a/apps/web/src/features/email-thread/thread-read-adapter.ts+++ b/apps/web/src/features/email-thread/thread-read-adapter.ts@@ -24,7 +24,7 @@ export function createThreadReadAdapter(const markSeenMutation = useMarkThreadAsSeenMutation();const markUnreadMutation = useMarkThreadAsUnreadMutation();- // Viewing a thread marks it read (EmailDebouncedReadMarker), so each thread+ // Viewing a thread marks it read (EmailReadMarker), so each thread// starts with the toggle offering Mark Unread.const [threadMarkedUnread, setThreadMarkedUnread] = createSignal(false);const [threadMarkedRead, setThreadMarkedRead] = createSignal(false);diff --git a/apps/web/src/features/email-view/components/EmailDetailView.tsx b/apps/web/src/features/email-view/components/EmailDetailView.tsxindex bfe768ec93..0822850ca5 100644--- a/apps/web/src/features/email-view/components/EmailDetailView.tsx+++ b/apps/web/src/features/email-view/components/EmailDetailView.tsx@@ -286,7 +286,6 @@ export function EmailDetailView(props: {notificationSource={notificationSource}threadId={props.thread.id}linkId={threadData()?.link_id}- debounceTime={100}onRetry={() => fireAndForget(threadQuery.refetch(), 'email-view')}><EmailThreadHostViewdiff --git a/apps/web/src/features/email-view/components/EmailList.tsx b/apps/web/src/features/email-view/components/EmailList.tsxindex 431db4887d..13fc1d8f84 100644--- a/apps/web/src/features/email-view/components/EmailList.tsx+++ b/apps/web/src/features/email-view/components/EmailList.tsx@@ -1,4 +1,6 @@import { usePending } from '@app/observability/flow';+import { useGlobalNotificationSource } from '@components/app/GlobalAppState';+import { markRowNotificationsSeenOnOpen } from '@notifications/mark-row-seen';import { QueuedSendStatus } from '../../email-compose/queued-send-status';import '@entity/composed/ListEntity.css';import {@@ -135,6 +137,7 @@ export function EmailList(props: EmailListProps) {} = useEmailView();usePending('email.list.items', () => source.isLoading());const panel = useSplitPanelOrThrow();+ const notificationSource = useGlobalNotificationSource();function openEntity(entity: EntityData,@@ -143,6 +146,7 @@ export function EmailList(props: EmailListProps) {openInNewSplit?: boolean;} = {}) {+ markRowNotificationsSeenOnOpen(entity, notificationSource);const finishTouchHighlight = options.event? persistSoupNavigationTouchHighlight(options.event): undefined;diff --git a/apps/web/src/features/email-view/email-view-context.test.tsx b/apps/web/src/features/email-view/email-view-context.test.tsxindex b0c31d75a0..b528a65de4 100644--- a/apps/web/src/features/email-view/email-view-context.test.tsx+++ b/apps/web/src/features/email-view/email-view-context.test.tsx@@ -1,3 +1,10 @@+vi.mock('@components/app/GlobalAppState', () => ({+ useGlobalNotificationSource: () => ({}),+}));+vi.mock('@notifications/mark-row-seen', () => ({+ markRowNotificationsSeenOnOpen: vi.fn(),+}));+import type { TagSetResponse } from '@service-properties/generated/schemas/tagSetResponse';import { cleanup, render } from '@solidjs/testing-library';import { createStore } from 'solid-js/store';diff --git a/apps/web/src/features/email-view/email-view-context.tsx b/apps/web/src/features/email-view/email-view-context.tsxindex 49ae6dd1b2..0c729c634d 100644--- a/apps/web/src/features/email-view/email-view-context.tsx+++ b/apps/web/src/features/email-view/email-view-context.tsx@@ -18,6 +18,7 @@ import { beginInteraction } from '@app/observability/flow';import { usePreference } from '@app/preferences/use-preference';import { emailSplitRoute, emailThreadRoute } from '@app/routes/routes';import { createPreviewSelectionGuard } from '@components/app/createPreviewSelectionGuard';+import { useGlobalNotificationSource } from '@components/app/GlobalAppState';import {useSplitPanelOrThrow,withSplitPanelOwner,@@ -26,6 +27,7 @@ import { createAssertedContextProvider } from '@core/context/createContext';import { useUserId } from '@core/context/user';import { isTouchDevice } from '@core/mobile/isTouchDevice';import { fireAndForget } from '@core/util/fireAndForget';+import { markRowNotificationsSeenOnOpen } from '@notifications/mark-row-seen';import { listTagOptions } from '@property/tags/list-tag-options';import { useTagSets, useTagSetsReady } from '@property/tags/tag-sets-context';import { useEmailLinksQuery } from '@queries/email/link';@@ -268,6 +270,7 @@ export const [EmailViewProvider, useEmailView] = createAssertedContextProvider<'email-view');};+ const notificationSource = useGlobalNotificationSource();const openThread = (thread: EmailThreadTarget,options?: EntityDetailNavigationOptions & { replace?: boolean }@@ -277,6 +280,11 @@ export const [EmailViewProvider, useEmailView] = createAssertedContextProvider<// The router may refuse a claimed destination. Check compatibility without// claiming it until the accepted route changes.if (!selectPreview.canSelect(selection)) return true;+ const row = source+ .items()+ .find((row) => row.kind === 'entity' && row.entity.id === thread.id);+ if (row?.kind === 'entity')+ markRowNotificationsSeenOnOpen(row.entity, notificationSource);fireAndForget(navigate({ route: emailThreadRoute, params: { threadId: thread.id } },diff --git a/apps/web/src/features/home/components/HomeList.tsx b/apps/web/src/features/home/components/HomeList.tsxindex 2504187c0f..f2b5dc695a 100644--- a/apps/web/src/features/home/components/HomeList.tsx+++ b/apps/web/src/features/home/components/HomeList.tsx@@ -1,4 +1,5 @@import { usePending } from '@app/observability/flow';+import { markRowNotificationsSeenOnOpen } from '@notifications/mark-row-seen';import '@entity/composed/ListEntity.css';import {createListController,@@ -62,7 +63,6 @@ import {import { InboxListEntity } from '../../next-soup/soup-view/views/inbox/InboxListEntity';import {markChannelNotificationsSeenOnOpen,- markRowNotificationsSeenOnOpen,openEntityInSplitFromUnifiedList,} from '../../next-soup/utils';import { useHomeView } from '../home-view-context';@@ -137,6 +137,7 @@ export function HomeList(props: HomeListProps) {controller: list,handle: panel.handle,openEntityInSplit: (entity, options) => {+ markRowNotificationsSeenOnOpen(entity, notificationSource);fireAndForget(openEntityInSplitFromUnifiedList(entity, {splitHandle: panel.handle,@@ -173,7 +174,12 @@ export function HomeList(props: HomeListProps) {metadata?.newSplit === true || metadata?.event?.shiftKey === true;if (!isTouchDevice() && !newSplit) {- markEntitySeen(sourceRow.entity);+ if (!isNonMemberChannelEntity(sourceRow.entity)) {+ markChannelNotificationsSeenOnOpen(+ sourceRow.entity,+ notificationSource+ );+ }showPreview(sourceRow.entity, { activate: true });props.onPreviewActivate?.();// Home keeps the keyboard only when the item opened in Home itself.@@ -198,9 +204,10 @@ export function HomeList(props: HomeListProps) {}function showPreview(- entity: WithNotification<EntityData>,+ entity: WithNotification<EntityData> | undefined,options?: { activate?: boolean }) {+ if (entity) markRowNotificationsSeenOnOpen(entity, notificationSource);props.onPreviewEntityChange(entity, options);}@@ -301,7 +308,7 @@ export function HomeList(props: HomeListProps) {return ({ entity }) => {previewAfterNavigation.clear();- props.onPreviewEntityChange(entity);+ showPreview(entity);};};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.tsxindex a8a83487f7..f0772e517f 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@@ -50,7 +50,6 @@ import { ResponsiveTaskListHeader } from '@app/features/next-soup/soup-view/viewimport { TaskGroupHeader } from '@app/features/next-soup/soup-view/views/tasks/task-group-header';import {markChannelNotificationsSeenOnOpen,- markRowNotificationsSeenOnOpen,openEntityInNewTab,openEntityInSplitFromUnifiedList,restoreSoupFocus,@@ -103,6 +102,7 @@ import CheckIcon from '@icon/system/regular/check.svg';import InfoIcon from '@icon/system/regular/info.svg';import Spinner from '@icon/system/regular/spinner.svg';import { Telemetry } from '@macro-inc/observability';+import { markRowNotificationsSeenOnOpen } from '@notifications/mark-row-seen';import { createElementSize } from '@solid-primitives/resize-observer';import { debounce } from '@solid-primitives/scheduled';import { Button, cn, Layer } from '@ui';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.tsindex 237d585f6b..d3463eb025 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@@ -1,3 +1,7 @@+vi.mock('@notifications/mark-row-seen', () => ({+ markRowNotificationsSeenOnOpen: vi.fn(),+}));+import { createRoot } from 'solid-js';import { afterEach, describe, expect, it, vi } from 'vitest';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.tsindex 80379c7b8f..ad74b2a98d 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@@ -4,7 +4,6 @@ import { CommandState } from '@app/features/command/state';import { VIEW_TAB_PRESETS } from '@app/features/next-soup/sidebar/soup-filter-presets';import {markChannelNotificationsSeenOnOpen,- markRowNotificationsSeenOnOpen,openEntityInSplitFromUnifiedList,} from '@app/features/next-soup/utils';import { useAnalytics } from '@app/lib/analytics/analytics-context';@@ -24,6 +23,7 @@ import {} from '@entity';import { Telemetry } from '@macro-inc/observability';import { openSingleStackNotification } from '@notifications';+import { markRowNotificationsSeenOnOpen } from '@notifications/mark-row-seen';import { type Accessor, onCleanup } from 'solid-js';import type { VirtualizerHandle } from 'virtua/solid';import type { SoupState } from '../create-soup-state';diff --git a/apps/web/src/features/next-soup/utils.ts b/apps/web/src/features/next-soup/utils.tsindex 151458dcfe..3ef7aadb56 100644--- a/apps/web/src/features/next-soup/utils.ts+++ b/apps/web/src/features/next-soup/utils.ts@@ -1,7 +1,5 @@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,@@ -16,7 +14,6 @@ import {type CalendarViewTarget,} from '@app/features/calendar-view/types';import { callsHostedContent } from '@app/features/calls-view/calls-hosted-content';-import { markCrmNotificationsSeenOnOpen } from '@app/features/crm/mark-record-notifications-seen';import { driveHostedContent } from '@app/features/drive-view/drive-hosted-content';import { projectHostedContent } from '@app/features/projects/open-project';import { reviewsHostedContent } from '@app/features/reviews-view/reviews-hosted-content';@@ -913,19 +910,6 @@ export function markChannelNotificationsSeenOnOpen(});}-/**- * Clear the dots of rows whose opened view has no block that marks the row's- * loaded notifications read: calendar events, agent sessions, and CRM records.- */-export function markRowNotificationsSeenOnOpen(- entity: EntityWithRawNotifications<EntityData>,- notificationSource: NotificationSource-) {- markCalendarNotificationSeenOnOpen(entity, notificationSource);- markAgentSessionNotificationsSeenOnOpen(entity, notificationSource);- markCrmNotificationsSeenOnOpen(entity, notificationSource);-}-/*** The event and instance a calendar row points at, resolved exactly as the* open path resolves it so a copied link lands where a click would.diff --git a/apps/web/src/features/notifications/components/DebouncedNotificationReadMarker.tsx b/apps/web/src/features/notifications/components/NotificationReadMarker.tsxsimilarity index 59%rename from apps/web/src/features/notifications/components/DebouncedNotificationReadMarker.tsxrename to apps/web/src/features/notifications/components/NotificationReadMarker.tsxindex 540fbbbb01..1105962b3a 100644--- a/apps/web/src/features/notifications/components/DebouncedNotificationReadMarker.tsx+++ b/apps/web/src/features/notifications/components/NotificationReadMarker.tsx@@ -3,8 +3,11 @@ import { fireAndForget } from '@core/util/fireAndForget';import { useNonPrimaryEmailLinkIdHeader } from '@queries/email/link';import { useMarkThreadAsSeenMutation } from '@queries/email/thread';import { debounce } from '@solid-primitives/scheduled';-import { onMount } from 'solid-js';-import { markNotificationsForEntityAsReadInBackground } from '../notification-helpers';+import { onCleanup, onMount } from 'solid-js';+import {+ ensureNotificationSourceLoaded,+ markNotificationsForEntityAsReadInBackground,+} from '../notification-helpers';import type { NotificationSource } from '../notification-source';const DEFAULT_DEBOUNCE_TIME = 2_000;@@ -23,7 +26,8 @@ const makeDebouncedMarker = (props: DebouncedMarkerProps): VoidFunction => {};function DebouncedMarker(props: DebouncedMarkerProps) {- const triggerDebounce = makeDebouncedMarker(props);+ const triggerDebounce =+ props.debounceTime === 0 ? props.debouncedFn : makeDebouncedMarker(props);onMount(() => {triggerDebounce();@@ -32,51 +36,59 @@ function DebouncedMarker(props: DebouncedMarkerProps) {return '';}-/**- * Debounced component that marks a notification as read- * @param props- * @returns- */-export function DebouncedNotificationReadMarker(props: {+/** Mark ready content read on mount; channel callers can retain their delay. */+export function NotificationReadMarker(props: {notificationSource: NotificationSource;debounceTime?: number;entity: Entity;}) {if (props.entity.type === 'email') {return (- <EmailDebouncedReadMarker+ <EmailReadMarkernotificationSource={props.notificationSource}- debounceTime={props.debounceTime}+ debounceTime={props.debounceTime ?? 0}threadId={props.entity.id}/>);}+ let disposed = false;+ onCleanup(() => {+ disposed = true;+ });+ const markRead = async () => {+ const entity = props.entity;+ if (props.notificationSource._notificationsQuery.transport === 'rest') {+ await ensureNotificationSourceLoaded(props.notificationSource);+ }+ if (+ disposed ||+ props.entity.id !== entity.id ||+ props.entity.type !== entity.type+ )+ return;+ await markNotificationsForEntityAsReadInBackground(+ props.notificationSource,+ entity+ );+ };return (<DebouncedMarker- debounceTime={props.debounceTime}- debouncedFn={() => {- fireAndForget(- markNotificationsForEntityAsReadInBackground(- props.notificationSource,- props.entity- ),- 'notification-read'- );- }}+ debounceTime={props.debounceTime ?? 0}+ debouncedFn={() => fireAndForget(markRead(), 'notification-read')}/>);}-export function DocumentDebouncedNotificationReadMarker(props: {+export function DocumentNotificationReadMarker(props: {notificationSource: NotificationSource;debounceTime?: number;documentId: string;}) {return (- <DebouncedNotificationReadMarker+ <NotificationReadMarkernotificationSource={props.notificationSource}- debounceTime={props.debounceTime}+ debounceTime={props.debounceTime ?? 0}entity={{type: 'document',id: props.documentId,@@ -112,9 +124,9 @@ export function ChannelDebouncedNotificationReadMarker(props: ChannelDebouncedNotificationReadMarkerProps) {return (- <DebouncedNotificationReadMarker+ <NotificationReadMarkernotificationSource={props.notificationSource}- debounceTime={props.debounceTime}+ debounceTime={props.debounceTime ?? DEFAULT_DEBOUNCE_TIME}entity={{type: 'channel',id: props.channelId,@@ -123,7 +135,7 @@ export function ChannelDebouncedNotificationReadMarker();}-export function EmailDebouncedReadMarker(props: {+export function EmailReadMarker(props: {notificationSource: NotificationSource;debounceTime?: number;threadId: string;@@ -134,24 +146,21 @@ export function EmailDebouncedReadMarker(props: {const toHeaderLinkId = useNonPrimaryEmailLinkIdHeader();return (- <DebouncedMarker- debounceTime={props.debounceTime}- debouncedFn={() => {- fireAndForget(- markNotificationsForEntityAsReadInBackground(- props.notificationSource,- {- type: 'email_thread',- id: props.threadId,- }- ),- 'notification-read'- );- markSeenMutation.mutate({- threadId: props.threadId,- linkId: toHeaderLinkId(props.linkId),- });- }}- />+ <>+ <NotificationReadMarker+ notificationSource={props.notificationSource}+ debounceTime={props.debounceTime}+ entity={{ type: 'email_thread', id: props.threadId }}+ />+ <DebouncedMarker+ debounceTime={props.debounceTime ?? 0}+ debouncedFn={() =>+ markSeenMutation.mutate({+ threadId: props.threadId,+ linkId: toHeaderLinkId(props.linkId),+ })+ }+ />+ </>);}diff --git a/apps/web/src/features/notifications/index.ts b/apps/web/src/features/notifications/index.tsindex 2b35064879..2b649d164c 100644--- a/apps/web/src/features/notifications/index.ts+++ b/apps/web/src/features/notifications/index.ts@@ -1,11 +1,11 @@export { BrowserNotificationModal } from './components/BrowserNotificationModal';export {ChannelDebouncedNotificationReadMarker,- DebouncedNotificationReadMarker,- DocumentDebouncedNotificationReadMarker,- EmailDebouncedReadMarker,+ DocumentNotificationReadMarker,+ EmailReadMarker,makeDebouncedChannelNotificationReadMarker,-} from './components/DebouncedNotificationReadMarker';+ NotificationReadMarker,+} from './components/NotificationReadMarker';export type {CreateAppNotificationInterface,NotificationUnsupported,diff --git a/apps/web/src/features/notifications/mark-row-seen.ts b/apps/web/src/features/notifications/mark-row-seen.tsnew file mode 100644index 0000000000..8614a07e7f--- /dev/null+++ b/apps/web/src/features/notifications/mark-row-seen.ts@@ -0,0 +1,93 @@+import {+ type EntityWithRawNotifications,+ getEntityNotifications,+} from '@app/features/soup/entity-notifications';+import { fireAndForget } from '@core/util/fireAndForget';+import { type EntityData, isGithubPrEntity } from '@entity/types/entity';+import {+ notificationIsRead,+ toNotificationEntity,+} from '@entity/utils/notification';+import { Telemetry } from '@macro-inc/observability';+import { markEmailThreadSeen } from '@queries/email/read-state';+import {+ ensureNotificationSourceLoaded,+ markNotificationsForEntityAsRead,+} from './notification-helpers';+import type { NotificationSource } from './notification-source';++const READ_ON_OPEN_TYPES = new Set<EntityData['type']>([+ 'document',+ 'chat',+ 'email',+ 'agent_session',+ 'calendar_event',+ 'crm_company',+ 'crm_contact',+ 'call',+ 'project',+ 'initiative',+ 'foreign',+]);++/**+ * Clear the unread state represented by an opened row before its detail loads.+ * Channels and external conversations retain their scoped message-read policy.+ * Detail markers still cover direct links and notifications absent from the row.+ */+export function markRowNotificationsSeenOnOpen(+ entity: EntityWithRawNotifications<EntityData>,+ notificationSource: NotificationSource+) {+ if (!READ_ON_OPEN_TYPES.has(entity.type)) return;+ if (entity.type === 'foreign' && !isGithubPrEntity(entity)) return;++ if (entity.type === 'email' && !entity.isRead) {+ fireAndForget(+ markEmailThreadSeen({ threadId: entity.id, linkId: entity.linkId }),+ 'email-read'+ );+ }++ const hasLoadedNotifications =+ entity.notifications !== undefined ||+ notificationSource._notificationsQuery.isStarted ||+ notificationSource._notificationsQuery.transport === 'rest';+ const notifications = hasLoadedNotifications+ ? getEntityNotifications(entity, notificationSource).filter(+ (notification) => !notificationIsRead(notification)+ )+ : [];+ // Calendar and CRM have always completed entity reads here, including cold+ // REST feeds. Other details own that fallback when their content is ready.+ const markWholeEntity =+ entity.type === 'calendar_event' ||+ entity.type === 'crm_company' ||+ entity.type === 'crm_contact';+ if (notifications.length === 0 && !markWholeEntity) return;++ fireAndForget(+ Telemetry.span('notifications.row.mark_read', async (span) => {+ span.setAttr('entity.id', entity.id);+ span.setAttr('entity.type', entity.type);+ span.setAttr('notification.count', notifications.length);+ try {+ if (notifications.length > 0) {+ await notificationSource.bulkMarkAsRead(notifications);+ } else {+ if (notificationSource._notificationsQuery.transport === 'rest') {+ await ensureNotificationSourceLoaded(notificationSource);+ }+ await markNotificationsForEntityAsRead(+ notificationSource,+ toNotificationEntity(entity)+ );+ }+ } catch (error) {+ span.error(error);+ throw error;+ }+ }),+ 'row-notification-read'+ );+}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.tsindex ad56b39e9e..332ecf028c 100644--- 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@@ -1,8 +1,10 @@-import { markAgentSessionNotificationsSeenOnOpen } from '@app/features/block-agent/mark-session-notifications-seen';+vi.mock('@queries/email/read-state', () => ({ markEmailThreadSeen: vi.fn() }));+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 { markRowNotificationsSeenOnOpen } from '@notifications/mark-row-seen';import type { ConnectionGatewayWebsocket } from '@service-connection/websocket';import { createRoot } from 'solid-js';import { afterEach, describe, expect, it, vi } from 'vitest';@@ -106,10 +108,7 @@ describe('opening agent session notifications', () => {it('leaves rows without loaded notifications to the opened session', () => {const { source, dispose } = createSource();try {- markAgentSessionNotificationsSeenOnOpen(- { ...session, notifications: [] },- source- );+ markRowNotificationsSeenOnOpen({ ...session, notifications: [] }, source);expect(mocks.seen).not.toHaveBeenCalled();expect(mocks.entitySeen).not.toHaveBeenCalled();} finally {@@ -136,7 +135,7 @@ describe('opening agent session notifications', () => {const rendered = withEntityNotifications(row, source);try {expect(unreadFilterFn(rendered)).toBe(true);- markAgentSessionNotificationsSeenOnOpen(row, source);+ markRowNotificationsSeenOnOpen(row, source);expect(unreadFilterFn(rendered)).toBe(false);expect(mocks.seen).toHaveBeenLastCalledWith({notificationIds: [`pending-${shape}`],@@ -167,17 +166,17 @@ describe('opening agent session notifications', () => {source);try {- markAgentSessionNotificationsSeenOnOpen(row, source);+ markRowNotificationsSeenOnOpen(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',+ surface: 'row-notification-read',});expect(unreadFilterFn(row)).toBe(true);mocks.seen.mockResolvedValueOnce(undefined);- markAgentSessionNotificationsSeenOnOpen(row, source);+ markRowNotificationsSeenOnOpen(row, source);expect(unreadFilterFn(row)).toBe(false);} finally {dispose();diff --git a/apps/web/src/features/notifications/tests/calendar-notification-read.test.ts b/apps/web/src/features/notifications/tests/calendar-notification-read.test.tsindex 350cde43cf..eb889b8c9a 100644--- a/apps/web/src/features/notifications/tests/calendar-notification-read.test.ts+++ b/apps/web/src/features/notifications/tests/calendar-notification-read.test.ts@@ -1,8 +1,10 @@-import { markCalendarNotificationSeenOnOpen } from '@app/features/calendar/mark-event-notifications-seen';+vi.mock('@queries/email/read-state', () => ({ markEmailThreadSeen: vi.fn() }));+import { withEntityNotifications } from '@app/features/soup/entity-notifications';import type { CalendarEventEntity } from '@entity/types/entity';import { unreadFilterFn } from '@entity/utils/filter';import { Telemetry } from '@macro-inc/observability';+import { markRowNotificationsSeenOnOpen } from '@notifications/mark-row-seen';import type { ConnectionGatewayWebsocket } from '@service-connection/websocket';import { createRoot } from 'solid-js';import { afterEach, describe, expect, it, vi } from 'vitest';@@ -105,13 +107,10 @@ describe('opening calendar notifications', () => {dispose,}));try {- markCalendarNotificationSeenOnOpen(- { ...event, notifications: [] },- source- );+ markRowNotificationsSeenOnOpen({ ...event, notifications: [] }, source);await reported.promise;expect(telemetry).toHaveBeenCalledWith(error, {- surface: 'calendar-notification-read',+ surface: 'row-notification-read',});} finally {dispose();@@ -140,7 +139,7 @@ describe('opening calendar notifications', () => {const rendered = withEntityNotifications(row, source);try {expect(unreadFilterFn(rendered)).toBe(true);- markCalendarNotificationSeenOnOpen(row, source);+ markRowNotificationsSeenOnOpen(row, source);expect(unreadFilterFn(rendered)).toBe(false);expect(mocks.seen).toHaveBeenLastCalledWith({notificationIds: [`pending-${shape}`],@@ -173,13 +172,13 @@ describe('opening calendar notifications', () => {source);try {- markCalendarNotificationSeenOnOpen(row, source);+ markRowNotificationsSeenOnOpen(row, source);expect(unreadFilterFn(row)).toBe(false);pending.reject(new Error('offline'));await reported.promise;expect(unreadFilterFn(row)).toBe(true);mocks.seen.mockResolvedValueOnce(undefined);- markCalendarNotificationSeenOnOpen(row, source);+ markRowNotificationsSeenOnOpen(row, source);expect(unreadFilterFn(row)).toBe(false);} finally {dispose();diff --git a/apps/web/src/features/notifications/tests/crm-notification-read.test.ts b/apps/web/src/features/notifications/tests/crm-notification-read.test.tsindex 125d43c2cd..473e7ce001 100644--- a/apps/web/src/features/notifications/tests/crm-notification-read.test.ts+++ b/apps/web/src/features/notifications/tests/crm-notification-read.test.ts@@ -1,8 +1,10 @@-import { markCrmNotificationsSeenOnOpen } from '@app/features/crm/mark-record-notifications-seen';+vi.mock('@queries/email/read-state', () => ({ markEmailThreadSeen: vi.fn() }));+import { withEntityNotifications } from '@app/features/soup/entity-notifications';import type { CrmCompanyEntity, CrmContactEntity } from '@entity/types/entity';import { unreadFilterFn } from '@entity/utils/filter';import { Telemetry } from '@macro-inc/observability';+import { markRowNotificationsSeenOnOpen } from '@notifications/mark-row-seen';import type { ConnectionGatewayWebsocket } from '@service-connection/websocket';import { createRoot, createSignal } from 'solid-js';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';@@ -138,7 +140,7 @@ describe.each([COMPANY, CONTACT])('opening $type notifications', (record) => {dispose,}));try {- markCrmNotificationsSeenOnOpen(record, source);+ markRowNotificationsSeenOnOpen(record, source);expect(mocks.refetch).toHaveBeenCalledOnce();expect(mocks.seen).not.toHaveBeenCalled();loaded.resolve();@@ -165,10 +167,10 @@ describe.each([COMPANY, CONTACT])('opening $type notifications', (record) => {dispose,}));try {- markCrmNotificationsSeenOnOpen({ ...record, notifications: [] }, source);+ markRowNotificationsSeenOnOpen({ ...record, notifications: [] }, source);await reported.promise;expect(telemetry).toHaveBeenCalledWith(error, {- surface: 'crm-notification-read',+ surface: 'row-notification-read',});} finally {dispose();@@ -205,7 +207,7 @@ describe.each([COMPANY, CONTACT])('opening $type notifications', (record) => {const rendered = withEntityNotifications(row, source);try {expect(unreadFilterFn(rendered)).toBe(true);- markCrmNotificationsSeenOnOpen(row, source);+ markRowNotificationsSeenOnOpen(row, source);expect(unreadFilterFn(rendered)).toBe(false);expect(mocks.seen).toHaveBeenLastCalledWith({notificationIds: [`${record.id}-pending-${shape}`],@@ -241,13 +243,13 @@ describe.each([COMPANY, CONTACT])('opening $type notifications', (record) => {source);try {- markCrmNotificationsSeenOnOpen(row, source);+ markRowNotificationsSeenOnOpen(row, source);expect(unreadFilterFn(row)).toBe(false);pending.reject(new Error('offline'));await reported.promise;expect(unreadFilterFn(row)).toBe(true);mocks.seen.mockResolvedValueOnce(undefined);- markCrmNotificationsSeenOnOpen(row, source);+ markRowNotificationsSeenOnOpen(row, source);expect(unreadFilterFn(row)).toBe(false);} finally {dispose();@@ -264,7 +266,7 @@ describe.each([COMPANY, CONTACT])('opening $type notifications', (record) => {dispose,}));try {- markCrmNotificationsSeenOnOpen(+ markRowNotificationsSeenOnOpen({ ...record, notifications: shape === 'empty' ? [] : undefined },source);diff --git a/apps/web/src/features/notifications/tests/debounced-notification-read-marker.test.tsx b/apps/web/src/features/notifications/tests/debounced-notification-read-marker.test.tsxindex a52ee58b29..2c9de188b1 100644--- a/apps/web/src/features/notifications/tests/debounced-notification-read-marker.test.tsx+++ b/apps/web/src/features/notifications/tests/debounced-notification-read-marker.test.tsx@@ -2,18 +2,20 @@ import { render } from '@solidjs/testing-library';import { createRoot } from 'solid-js';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import {- DebouncedNotificationReadMarker,- EmailDebouncedReadMarker,+ EmailReadMarker,makeDebouncedChannelNotificationReadMarker,-} from '../components/DebouncedNotificationReadMarker';+ NotificationReadMarker,+} from '../components/NotificationReadMarker';import type { NotificationSource } from '../notification-source';const mocks = vi.hoisted(() => ({markInBackground: vi.fn(async () => {}),markThread: vi.fn(),+ load: vi.fn(async () => {}),}));vi.mock('../notification-helpers', () => ({markNotificationsForEntityAsReadInBackground: mocks.markInBackground,+ ensureNotificationSourceLoaded: mocks.load,}));vi.mock('@queries/email/thread', () => ({useMarkThreadAsSeenMutation: () => ({ mutate: mocks.markThread }),@@ -22,7 +24,9 @@ vi.mock('@queries/email/link', () => ({useNonPrimaryEmailLinkIdHeader: () => (linkId: string | undefined) => linkId,}));-const source = {} as NotificationSource;+const source = {+ _notificationsQuery: { transport: 'graphql' },+} as NotificationSource;let dispose: (() => void) | undefined;beforeEach(() => {vi.useFakeTimers();@@ -34,9 +38,64 @@ afterEach(() => {});describe('background notification read markers', () => {+ it('marks ready content immediately without scheduling a timer', () => {+ const view = render(() => (+ <NotificationReadMarker+ notificationSource={source}+ entity={{ type: 'chat', id: 'chat' }}+ />+ ));+ dispose = view.unmount;+ expect(mocks.markInBackground).toHaveBeenCalledExactlyOnceWith(source, {+ type: 'chat',+ id: 'chat',+ });+ expect(vi.getTimerCount()).toBe(0);+ });++ it('marks email immediately and does not repeat the read while it stays mounted', async () => {+ const view = render(() => (+ <EmailReadMarker+ notificationSource={source}+ threadId="thread"+ linkId="secondary-inbox"+ />+ ));+ dispose = view.unmount;+ expect(mocks.markThread).toHaveBeenCalledExactlyOnceWith({+ threadId: 'thread',+ linkId: 'secondary-inbox',+ });+ await vi.advanceTimersByTimeAsync(2_000);+ expect(mocks.markThread).toHaveBeenCalledTimes(1);+ });++ it.each([false, true])(+ 'waits for a cold REST feed, respecting disposal=%s',+ async (leave) => {+ const loaded = Promise.withResolvers<void>();+ mocks.load.mockReturnValueOnce(loaded.promise);+ const restSource = {+ _notificationsQuery: { transport: 'rest' },+ } as NotificationSource;+ const view = render(() => (+ <NotificationReadMarker+ notificationSource={restSource}+ entity={{ type: 'document', id: 'doc' }}+ />+ ));+ dispose = view.unmount;+ expect(mocks.markInBackground).not.toHaveBeenCalled();+ if (leave) view.unmount();+ loaded.resolve();+ await loaded.promise;+ expect(mocks.markInBackground).toHaveBeenCalledTimes(leave ? 0 : 1);+ }+ );+it('routes automatic entity reads through the rejection-handling helper', async () => {const view = render(() => (- <DebouncedNotificationReadMarker+ <NotificationReadMarkernotificationSource={source}entity={{ type: 'document', id: 'doc' }}debounceTime={10}@@ -78,7 +137,7 @@ describe('background notification read markers', () => {}));const view = render(() => (- <EmailDebouncedReadMarker+ <EmailReadMarkernotificationSource={source}threadId="thread"linkId="secondary-inbox"diff --git a/apps/web/src/features/notifications/tests/row-notification-read.test.ts b/apps/web/src/features/notifications/tests/row-notification-read.test.tsnew file mode 100644index 0000000000..2b4af7add9--- /dev/null+++ b/apps/web/src/features/notifications/tests/row-notification-read.test.ts@@ -0,0 +1,291 @@+vi.mock('@queries/email/read-state', () => ({+ markEmailThreadSeen: mocks.emailSeen,+}));++import { withEntityNotifications } from '@app/features/soup/entity-notifications';+import type { EntityData, GithubPullRequestEntity } from '@entity/types/entity';+import { unreadFilterFn } from '@entity/utils/filter';+import { Telemetry } from '@macro-inc/observability';+import { markRowNotificationsSeenOnOpen } from '@notifications/mark-row-seen';+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(),+ emailSeen: vi.fn(async () => {}),+ entitySeen: vi.fn(),+ feed: vi.fn<() => UnifiedNotification[]>(() => []),+ transport: 'graphql' as 'graphql' | 'rest',+}));++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: () => ({+ get transport() {+ return mocks.transport;+ },+ 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: 'foreign_entity',+ id: 'pull-request',+ })),+ 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 pr: GithubPullRequestEntity = {+ type: 'foreign',+ id: 'pull-request',+ ownerId: 'owner',+ name: 'Fix flaky test',+ foreignId: 'example/repo/pull/42',+ storedForId: 'team',+ storedForAuthEntity: 'team',+ foreignSource: 'github_pull_request',+ metadata: {+ number: 42,+ name: 'Fix flaky test',+ owner: 'example',+ repo: 'repo',+ url: 'https://github.com/example/repo/pull/42',+ status: 'open',+ additions: 1,+ deletions: 1,+ comments: [],+ checks: [],+ labels: [],+ },+};+function createSource() {+ return createRoot((dispose) => ({+ source: createNotificationSource({} as ConnectionGatewayWebsocket),+ dispose,+ }));+}++afterEach(() => {+ vi.restoreAllMocks();+ mocks.seen.mockReset();+ mocks.emailSeen.mockReset();+ mocks.entitySeen.mockClear();+ mocks.transport = 'graphql';+ mocks.feed.mockReturnValue([]);+});++const rows = [+ pr,+ {+ type: 'document',+ id: 'markdown',+ name: 'Note',+ ownerId: 'owner',+ fileType: 'md',+ },+ {+ type: 'document',+ id: 'task',+ name: 'Task',+ ownerId: 'owner',+ fileType: 'md',+ subType: { type: 'task', is_completed: false },+ },+ { type: 'chat', id: 'chat', name: 'Legacy chat', ownerId: 'owner' },+ {+ type: 'email',+ id: 'thread',+ name: 'Email',+ ownerId: 'owner',+ isRead: true,+ isDraft: false,+ isImportant: false,+ done: false,+ },+] satisfies EntityData[];++describe.each(rows)('opening $type ($id) notifications', (entity) => {+ const notification: UnifiedNotification = {+ id: `${entity.id}-reminder`,+ entity_id: entity.id,+ entity_type:+ entity.type === 'email'+ ? 'email_thread'+ : entity.type === 'foreign'+ ? 'foreign_entity'+ : entity.type,+ state: 'unseen',+ notification_event_type: 'reminder',+ notification_metadata: {+ tag: 'reminder',+ content: { reminderId: 'reminder', description: 'Follow up' },+ },+ created_at: '2026-10-23T17:00:00Z',+ updated_at: '2026-10-23T17:00:00Z',+ viewed_at: null,+ sent: true,+ };+ it('leaves rows without loaded notifications to the opened detail', () => {+ const { source, dispose } = createSource();+ try {+ markRowNotificationsSeenOnOpen({ ...entity, notifications: [] }, source);+ expect(mocks.seen).not.toHaveBeenCalled();+ expect(mocks.entitySeen).not.toHaveBeenCalled();+ } finally {+ dispose();+ }+ });++ it.each(['array', 'accessor', 'rest-feed'] as const)(+ 'clears %s notifications before the write finishes',+ async (shape) => {+ mocks.feed.mockClear();+ const pending = Promise.withResolvers<void>();+ mocks.seen.mockReturnValueOnce(pending.promise);+ const attached = [+ { ...notification, id: `${entity.id}-pending-${shape}` },+ {+ ...notification,+ id: `${entity.id}-done-${shape}`,+ state: 'done' as const,+ },+ {+ ...notification,+ id: `${entity.id}-seen-${shape}`,+ state: 'seen' as const,+ },+ ];+ const fromRestFeed = shape === 'rest-feed';+ if (fromRestFeed) {+ mocks.transport = 'rest';+ mocks.feed.mockReturnValue(attached);+ }+ const { source, dispose } = createSource();+ // REST Soup rows have no raw notification edge; Home reads the source.+ const row = fromRestFeed+ ? entity+ : {+ ...entity,+ notifications: shape === 'array' ? attached : () => attached,+ };+ const rendered = withEntityNotifications(row, source);+ try {+ expect(unreadFilterFn(rendered)).toBe(true);+ markRowNotificationsSeenOnOpen(row, source);+ expect(unreadFilterFn(rendered)).toBe(false);+ expect(mocks.seen).toHaveBeenLastCalledWith({+ notificationIds: [`${entity.id}-pending-${shape}`],+ });+ if (!fromRestFeed) expect(mocks.feed).not.toHaveBeenCalled();+ pending.resolve();+ await pending.promise;+ expect(unreadFilterFn(withEntityNotifications(row, source))).toBe(+ false+ );+ } finally {+ pending.resolve();+ dispose();+ }+ }+ );++ it.each(['graphql', 'rest'] as const)(+ 'restores the %s dot after a failed write and clears it on a retry',+ async (transport) => {+ const pending = Promise.withResolvers<void>();+ const reported = Promise.withResolvers<void>();+ const telemetry = vi+ .spyOn(Telemetry, 'error')+ .mockImplementation(() => reported.resolve());+ mocks.seen.mockReturnValueOnce(pending.promise);+ mocks.transport = transport;+ const attached = [+ { ...notification, id: `${entity.id}-failed-read-${transport}` },+ ];+ mocks.feed.mockReturnValue(attached);+ const { source, dispose } = createSource();+ const row = withEntityNotifications(+ transport === 'graphql'+ ? { ...entity, notifications: attached }+ : entity,+ source+ );+ try {+ markRowNotificationsSeenOnOpen(row, source);+ expect(unreadFilterFn(row)).toBe(false);+ const error = new Error('offline');+ pending.reject(error);+ await reported.promise;+ expect(telemetry).toHaveBeenCalledWith(error, {+ surface: 'row-notification-read',+ });+ expect(unreadFilterFn(row)).toBe(true);+ mocks.seen.mockResolvedValueOnce(undefined);+ markRowNotificationsSeenOnOpen(row, source);+ expect(unreadFilterFn(row)).toBe(false);+ } finally {+ dispose();+ }+ }+ );+});++it('marks an unread email with a draft reply in its owning inbox without waiting for notifications', () => {+ const { source, dispose } = createSource();+ try {+ markRowNotificationsSeenOnOpen(+ {+ type: 'email',+ id: 'unread-thread',+ ownerId: 'owner',+ name: 'Email',+ isRead: false,+ isDraft: true,+ isImportant: false,+ done: false,+ linkId: 'secondary-inbox',+ notifications: [],+ },+ source+ );+ expect(mocks.emailSeen).toHaveBeenCalledExactlyOnceWith({+ threadId: 'unread-thread',+ linkId: 'secondary-inbox',+ });+ expect(mocks.seen).not.toHaveBeenCalled();+ } finally {+ dispose();+ }+});diff --git a/apps/web/src/features/soup/createSoupEntityActions.ts b/apps/web/src/features/soup/createSoupEntityActions.tsindex 441c450a53..052f388b09 100644--- a/apps/web/src/features/soup/createSoupEntityActions.ts+++ b/apps/web/src/features/soup/createSoupEntityActions.ts@@ -31,7 +31,6 @@ import {} from '@app/features/next-soup/actions';import type { MarkDoneDelegate } from '@app/features/next-soup/actions/mark-done-delegate';import {- markRowNotificationsSeenOnOpen,openEntityInSplitFromUnifiedList,restoreSoupFocus,} from '@app/features/next-soup/utils';@@ -51,6 +50,7 @@ import { isMobile } from '@core/mobile/isMobile';import { fireAndForget } from '@core/util/fireAndForget';import type { EntityData } from '@entity';import { isEmailEntity, isGithubPrEntity, isTaskEntity } from '@entity';+import { markRowNotificationsSeenOnOpen } from '@notifications/mark-row-seen';import { SYSTEM_PROPERTY_IDS } from '@property/constants';import type { Component, JSX } from 'solid-js';diff --git a/apps/web/src/features/tasks-view/AGENTS.md b/apps/web/src/features/tasks-view/AGENTS.mdindex 827e98266e..52d47efb58 100644--- a/apps/web/src/features/tasks-view/AGENTS.md+++ b/apps/web/src/features/tasks-view/AGENTS.md@@ -70,6 +70,8 @@ Main Tasks and reusable task-list hosts. Projects and CRM embed `TasksViewProvid- Preserve the raw saved layout during mobile or flag fallbacks; capture that layout instead of the displayed list fallback.- Block ordinary definition saves while unsupported settings remain; only explicit banner cleanup removes them, and metadata writes leave the definition unchanged.+- Mark task row notifications through `notifications/mark-row-seen.ts` when opening inline details or a split, including board and Gantt rows; keep the mounted Markdown marker for direct routes.+## ChecksRun from `apps/web`:diff --git a/apps/web/src/features/tasks-view/components/task-list/TaskList.tsx b/apps/web/src/features/tasks-view/components/task-list/TaskList.tsxindex 65c8b4d2a0..adcef0d162 100644--- a/apps/web/src/features/tasks-view/components/task-list/TaskList.tsx+++ b/apps/web/src/features/tasks-view/components/task-list/TaskList.tsx@@ -17,6 +17,7 @@ import {removeValue,toggleValue,} from '@app/lib/signals/store-array-updaters';+import { useGlobalNotificationSource } from '@components/app/GlobalAppState';import { SwipableRowProvider } from '@components/app/mobile/SwipableRow';import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';import { HotkeyTags } from '@core/hotkey/constants';@@ -34,6 +35,7 @@ import {import { soupPropertyToProperty } from '@entity/extractors-property';import CheckIcon from '@icon/system/regular/check.svg';import SpinnerIcon from '@icon/system/regular/spinner.svg';+import { markRowNotificationsSeenOnOpen } from '@notifications/mark-row-seen';import { PROPERTY_OPTION_IDS, SYSTEM_PROPERTY_IDS } from '@property';import { useBulkSaveEntityPropertiesMutation } from '@queries/properties/entity';import { EntityType } from '@service-properties/generated/schemas/entityType';@@ -93,6 +95,7 @@ export type TaskListProps = {export function TaskList(props: TaskListProps) {const panel = useSplitPanelOrThrow();+ const notificationSource = useGlobalNotificationSource();const {state,calendar,@@ -126,6 +129,7 @@ export function TaskList(props: TaskListProps) {mergeHistory?: boolean;} = {}) {+ markRowNotificationsSeenOnOpen(entity, notificationSource);fireAndForget(openEntityInSplitFromUnifiedList(entity, {splitHandle: panel.handle,diff --git a/apps/web/src/features/tasks-view/tasks-board.test.tsx b/apps/web/src/features/tasks-view/tasks-board.test.tsxindex f00c12ec13..f8ad3d151b 100644--- a/apps/web/src/features/tasks-view/tasks-board.test.tsx+++ b/apps/web/src/features/tasks-view/tasks-board.test.tsx@@ -1,3 +1,10 @@+vi.mock('@components/app/GlobalAppState', () => ({+ useGlobalNotificationSource: () => ({}),+}));+vi.mock('@notifications/mark-row-seen', () => ({+ markRowNotificationsSeenOnOpen: vi.fn(),+}));+import type {EntityActionListState,EntityActionViewContext,diff --git a/apps/web/src/features/tasks-view/tasks-board.tsx b/apps/web/src/features/tasks-view/tasks-board.tsxindex 1dbcd0444a..92e86ceafc 100644--- a/apps/web/src/features/tasks-view/tasks-board.tsx+++ b/apps/web/src/features/tasks-view/tasks-board.tsx@@ -5,10 +5,12 @@ import {} from '@app/features/next-soup/actions';import { openEntityInSplitFromUnifiedList } from '@app/features/next-soup/utils';import { SoupEntityContextMenu } from '@app/features/soup';+import { useGlobalNotificationSource } from '@components/app/GlobalAppState';import { useSplitLayout } from '@components/app/split-layout/layout';import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';import { useUserId } from '@core/context/user';import { fireAndForget } from '@core/util/fireAndForget';+import { markRowNotificationsSeenOnOpen } from '@notifications/mark-row-seen';import { usePropertyUserDisplay } from '@property/hooks/usePropertyUserDisplay';import { type Accessor, type JSX, Show } from 'solid-js';import { type TaskBoardTask, toTaskBoardGrouping } from './core/task-board';@@ -23,6 +25,7 @@ export function TasksBoard(props: { ref?: (element: HTMLDivElement) => void }) {const context = useTasksView();const { state, source, openTask, projectsEnabled, calendar } = context;const panel = useSplitPanelOrThrow();+ const notificationSource = useGlobalNotificationSource();const layout = useSplitLayout();const createContext = useCreateContext();const queries = createTaskBoardQueries({@@ -112,6 +115,7 @@ export function TasksBoard(props: { ref?: (element: HTMLDivElement) => void }) {return;}+ markRowNotificationsSeenOnOpen(entity, notificationSource);fireAndForget(openEntityInSplitFromUnifiedList(entity, {splitHandle: panel.handle,diff --git a/apps/web/src/features/tasks-view/tasks-gantt.tsx b/apps/web/src/features/tasks-view/tasks-gantt.tsxindex 8b4baaaf27..2f00d32cff 100644--- a/apps/web/src/features/tasks-view/tasks-gantt.tsx+++ b/apps/web/src/features/tasks-view/tasks-gantt.tsx@@ -6,11 +6,13 @@ import {} from '@app/features/next-soup/actions';import { openEntityInSplitFromUnifiedList } from '@app/features/next-soup/utils';import { SoupEntityContextMenu } from '@app/features/soup';+import { useGlobalNotificationSource } from '@components/app/GlobalAppState';import { useSplitLayout } from '@components/app/split-layout/layout';import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';import { toast } from '@core/component/Toast/Toast';import { fireAndForget } from '@core/util/fireAndForget';import { getTaskStatusOptionId, type TaskEntityWithProperties } from '@entity';+import { markRowNotificationsSeenOnOpen } from '@notifications/mark-row-seen';import { PropertyValueIcon } from '@property/component/propertyValue';import { usePropertyEntityDisplay } from '@property/hooks/usePropertyEntityDisplay';import { usePropertyUserDisplay } from '@property/hooks/usePropertyUserDisplay';@@ -28,6 +30,7 @@ export function TasksGantt(props: { ref?: (element: HTMLDivElement) => void }) {const context = useTasksView();const { source, state, setState, openTask } = context;const panel = useSplitPanelOrThrow();+ const notificationSource = useGlobalNotificationSource();const layout = useSplitLayout();const createTask = (options?: TaskCreateOptions) =>layout.popoverSplit({@@ -57,6 +60,7 @@ export function TasksGantt(props: { ref?: (element: HTMLDivElement) => void }) {);if (opened) return;+ markRowNotificationsSeenOnOpen(task, notificationSource);fireAndForget(openEntityInSplitFromUnifiedList(task, {diff --git a/apps/web/src/features/tasks-view/tasks-view-context.tsx b/apps/web/src/features/tasks-view/tasks-view-context.tsxindex 4a325c0889..c5a16060a8 100644--- a/apps/web/src/features/tasks-view/tasks-view-context.tsx+++ b/apps/web/src/features/tasks-view/tasks-view-context.tsx@@ -29,6 +29,7 @@ import {tasksSplitRoute,} from '@app/routes/routes';import { createPreviewSelectionGuard } from '@components/app/createPreviewSelectionGuard';+import { useGlobalNotificationSource } from '@components/app/GlobalAppState';import {useSplitPanelOrThrow,withSplitPanelOwner,@@ -37,6 +38,7 @@ import { createAssertedContextProvider } from '@core/context/createContext';import { useUserId } from '@core/context/user';import { isTouchDevice } from '@core/mobile/isTouchDevice';import { fireAndForget } from '@core/util/fireAndForget';+import { markRowNotificationsSeenOnOpen } from '@notifications/mark-row-seen';import { useTagSets, useTagSetsReady } from '@property/tags/tag-sets-context';import type { ContextProviderProps } from '@solid-primitives/context';import {@@ -546,13 +548,27 @@ export const [TasksViewProvider, useTasksView] = createAssertedContextProvider<'tasks-view');};+ const notificationSource = useGlobalNotificationSource();+ const markTaskSeen = (id: string) => {+ const rows = source.boardRows?.() ?? source.items();+ const row = rows.find(+ (row) => row.kind === 'entity' && row.entity.id === id+ );+ if (row?.kind === 'entity')+ markRowNotificationsSeenOnOpen(row.entity, notificationSource);+ };const openTask = (task: TaskDetailTarget,options?: EntityDetailNavigationOptions) => {- if (props.onOpenTask) return props.onOpenTask(task, options);+ if (props.onOpenTask) {+ const opened = props.onOpenTask(task, options);+ if (opened) markTaskSeen(task.id);+ return opened;+ }if (!opensInline(options)) return false;if (!selectPreview.canSelect(taskSelection(task.id))) return true;+ markTaskSeen(task.id);fireAndForget(navigate({ route: taskDetailRoute, params: { taskId: task.id } },diff --git a/apps/web/src/lib/queries/email/read-state-graphql.test.tsx b/apps/web/src/lib/queries/email/read-state-graphql.test.tsxindex 5c468647c7..dd769dc8dc 100644--- a/apps/web/src/lib/queries/email/read-state-graphql.test.tsx+++ b/apps/web/src/lib/queries/email/read-state-graphql.test.tsx@@ -1,5 +1,5 @@import { QueryClient } from '@tanstack/solid-query';-import { ok } from 'neverthrow';+import { err, ok } from 'neverthrow';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { mountEmailMutation } from './tests/mutation';@@ -12,6 +12,7 @@ const mocks = vi.hoisted(() => ({legacyPatch: vi.fn(),graphqlMutation: vi.fn(),refresh: vi.fn(),+ refetch: vi.fn(),}));vi.mock('@core/constant/featureFlags', async (importOriginal) => ({...(await importOriginal<typeof import('@core/constant/featureFlags')>()),@@ -33,7 +34,7 @@ vi.mock('../client', () => ({}));vi.mock('../soup/cache', () => ({optimisticUpdateSoupEntity: mocks.legacyPatch,- refetchSoupEntity: vi.fn(),+ refetchSoupEntity: mocks.refetch,}));vi.mock('../soup/graphql/active-queries', async (importOriginal) => ({...(await importOriginal<typeof import('../soup/graphql/active-queries')>()),@@ -69,6 +70,7 @@ import { soupOptimisticResolvers } from '../optimistic-resolvers';import { registerGraphqlSoupRevalidations } from '../soup/graphql/active-queries';import { soupKeys } from '../soup/keys';import { emailKeys } from './keys';+import { markEmailThreadSeen } from './read-state';import {trackExternalThreadArchive,useMarkThreadAsSeenMutation,@@ -358,3 +360,54 @@ describe('email read state with GraphQL Soup', () => {});});++describe('row-open email read operation', () => {+ it('patches the REST row synchronously, preserves inbox targeting and refreshes only the failed thread', async () => {+ mocks.graphqlEnabled = false;+ const folderKey = soupKeys.astItems({+ params: {},+ body: { emailView: 'spam' },+ transport: 'rest',+ }).queryKey;+ const allKey = soupKeys.astItems({+ params: {},+ body: { emailView: 'all' },+ }).queryKey;+ client.setQueryData(folderKey, { pages: [] });+ client.setQueryData(allKey, { pages: [] });+ const pending = Promise.withResolvers<ReturnType<typeof ok<void>>>();+ mocks.markSeen.mockReturnValueOnce(pending.promise);+ const request = markEmailThreadSeen({+ threadId: 'thread',+ linkId: 'secondary-inbox',+ });+ expect(mocks.legacyPatch).toHaveBeenCalledExactlyOnceWith({+ tag: 'emailThread',+ data: { id: 'thread', isRead: true },+ frecency_score: 0,+ });+ expect(mocks.markSeen).toHaveBeenCalledExactlyOnceWith(+ { thread_id: 'thread' },+ 'secondary-inbox'+ );+ pending.resolve(ok(undefined));+ await request;+ expect(mocks.refetch).not.toHaveBeenCalled();+ expect(client.getQueryState(folderKey)?.isInvalidated).toBe(true);+ expect(client.getQueryState(allKey)?.isInvalidated).toBe(false);++ client.setQueryData(folderKey, { pages: [] });+ mocks.markSeen.mockResolvedValueOnce(+ err([{ code: 'NETWORK', message: 'offline' }])+ );+ await expect(+ markEmailThreadSeen({ threadId: 'thread', linkId: 'secondary-inbox' })+ ).rejects.toThrow('offline');+ expect(mocks.refetch).toHaveBeenCalledExactlyOnceWith(+ 'thread',+ 'emailThread'+ );+ expect(client.getQueryState(folderKey)?.isInvalidated).toBe(true);+ expect(client.getQueryState(allKey)?.isInvalidated).toBe(false);+ });+});diff --git a/apps/web/src/lib/queries/email/read-state.ts b/apps/web/src/lib/queries/email/read-state.tsnew file mode 100644index 0000000000..4a19be55bb--- /dev/null+++ b/apps/web/src/lib/queries/email/read-state.ts@@ -0,0 +1,63 @@+import {+ enableGraphqlSoup,+ isFeatureEnabled,+} from '@core/constant/featureFlags';+import { throwOnErr } from '@core/util/result';+import { emailClient } from '@service-email/client';+import { markGraphqlEmailThreadSeen } from '@service-storage/graphql-email-read-state';+import {+ getGraphqlSoupClient,+ graphqlCacheEnabled,+} from '@service-storage/graphql-soup';+import { optimisticUpdateSoupEntity, refetchSoupEntity } from '../soup/cache';+import {+ getUnmaintainedGraphqlSoupRevalidations,+ refreshActiveGraphqlSoupQueries,+} from '../soup/graphql/active-queries';+import { invalidateEmailFolderQueries } from './folder-cache';++export type MarkThreadAsSeenParams = {+ threadId: string;+ /** Owning inbox; omitted only when the backend should use the primary inbox. */+ linkId?: string;+};++/** Shared by row opens and detail controls. Never invalidate the messages cache:+ * remounting its Suspense boundary would reset the open thread's scroll. */+export async function markEmailThreadSeen(+ params: MarkThreadAsSeenParams+): Promise<void> {+ try {+ if (isFeatureEnabled(enableGraphqlSoup)) {+ const disposition = await markGraphqlEmailThreadSeen(+ getGraphqlSoupClient(),+ params.threadId,+ getUnmaintainedGraphqlSoupRevalidations()+ );+ if (disposition === 'committed' && !graphqlCacheEnabled()) {+ await refreshActiveGraphqlSoupQueries();+ }+ return;+ }++ optimisticUpdateSoupEntity({+ tag: 'emailThread',+ data: { id: params.threadId, isRead: true },+ frecency_score: 0,+ });+ try {+ await throwOnErr(() =>+ emailClient.markThreadAsSeen(+ { thread_id: params.threadId },+ params.linkId+ )+ );+ } catch (error) {+ // Read back only this thread on failure, preserving unrelated list writes.+ await refetchSoupEntity(params.threadId, 'emailThread');+ throw error;+ }+ } finally {+ await invalidateEmailFolderQueries();+ }+}diff --git a/apps/web/src/lib/queries/email/thread.ts b/apps/web/src/lib/queries/email/thread.tsindex 8cae23e842..dc13e0a90e 100644--- a/apps/web/src/lib/queries/email/thread.ts+++ b/apps/web/src/lib/queries/email/thread.ts@@ -16,10 +16,7 @@ import type {ApiThread as Thread,UpsertScheduledResponse,} from '@service-email/generated/schemas';-import {- markGraphqlEmailThreadSeen,- markGraphqlEmailThreadUnread,-} from '@service-storage/graphql-email-read-state';+import { markGraphqlEmailThreadUnread } from '@service-storage/graphql-email-read-state';import {getGraphqlSoupClient,graphqlCacheEnabled,@@ -52,6 +49,7 @@ import {type EmailArchiveDisposition,} from './integration';import { emailKeys } from './keys';+import { type MarkThreadAsSeenParams, markEmailThreadSeen } from './read-state';const THREAD_STALE_TIME = 5 * 60 * 1000;@@ -333,65 +331,13 @@ export function useThreadQuery<TData = ThreadQueryData>(};}-type MarkThreadAsSeenParams = {- threadId: string;- /** Target inbox for a non-primary inbox; sent as the X-Email-Link-Id header. */- linkId?: string;-};--/**- * Optimistically update soup queries when marking as seen.- * Note: We intentionally don't update the thread messages cache here.- * Doing so triggers Suspense boundaries which unmount/remount the email view,- * causing scroll position to reset. The is_read property isn't used in the- * email view anyway - only the soup/list view needs it.- */-function threadSeenOnMutate(params: MarkThreadAsSeenParams): void {- if (isFeatureEnabled(enableGraphqlSoup)) return;- optimisticUpdateSoupEntity({- tag: 'emailThread',- data: { id: params.threadId, isRead: true },- frecency_score: 0,- });-}--/**- * Mutation to mark a thread as seen.- */+/** Mutation wrapper for the shared optimistic thread read operation. */export function useMarkThreadAsSeenMutation(callbacks?: MutationCallbacks<void, Error, MarkThreadAsSeenParams>) {return useMutation(() => ({- mutationFn: async (params: MarkThreadAsSeenParams) => {- if (isFeatureEnabled(enableGraphqlSoup)) {- // The optimistic and committed `isRead` reach every list the cache- // maintains; the rest are read again when the write commits.- const disposition = await markGraphqlEmailThreadSeen(- getGraphqlSoupClient(),- params.threadId,- getUnmaintainedGraphqlSoupRevalidations()- );- if (disposition === 'committed' && !graphqlCacheEnabled())- await refreshActiveGraphqlSoupQueries();- return;- }- await throwOnErr(() =>- emailClient.markThreadAsSeen(- { thread_id: params.threadId },- params.linkId- )- );- },- ...withCallbacks<void, Error, MarkThreadAsSeenParams>(- {- onMutate: threadSeenOnMutate,- onSettled: () => invalidateEmailFolderQueries(),- // Note: We intentionally don't invalidate thread messages in onSuccess.- // The optimistic update already sets isRead in soup, and invalidating- // thread messages triggers Suspense which resets scroll position.- },- callbacks- ),+ mutationFn: markEmailThreadSeen,+ ...withCallbacks<void, Error, MarkThreadAsSeenParams>({}, callbacks),}));}@@ -404,7 +350,7 @@ type MarkThreadAsUnreadParams = {/*** Optimistically flip the soup row to unread. The thread messages cache is* intentionally left alone for the same Suspense/scroll-reset reason as- * threadSeenOnMutate.+ * markEmailThreadSeen.*/function threadUnreadOnMutate(params: MarkThreadAsUnreadParams): void {if (isFeatureEnabled(enableGraphqlSoup)) return;diff --git a/apps/web/src/lib/queries/notification/entity-mutations.ts b/apps/web/src/lib/queries/notification/entity-mutations.tsindex 1f9b16e6f8..f0457b2cc8 100644--- a/apps/web/src/lib/queries/notification/entity-mutations.ts+++ b/apps/web/src/lib/queries/notification/entity-mutations.ts@@ -24,6 +24,7 @@ type SimpleNotificationEntityType =| 'email_thread'| 'foreign'| 'foreign_entity'+ | 'initiative'| 'project'| 'reminder';@@ -63,6 +64,7 @@ export function toNotificationEntityRef(case 'email_thread':case 'foreign':case 'foreign_entity':+ case 'initiative':case 'project':case 'reminder':return { type: entity.type, id: entity.id };@@ -95,6 +97,7 @@ const ENTITY_TYPE_TO_GRAPHQL = {email_thread: 'EMAIL_THREAD',foreign: 'FOREIGN_ENTITY',foreign_entity: 'FOREIGN_ENTITY',+ initiative: 'INITIATIVE',project: 'PROJECT',reminder: 'REMINDER',} as const satisfies Record<SimpleNotificationEntityType, GraphqlEntityType>;diff --git a/apps/web/src/lib/queries/notification/tests/entity-mutations.test.ts b/apps/web/src/lib/queries/notification/tests/entity-mutations.test.tsindex 04c6e636b7..52bd0d2df7 100644--- a/apps/web/src/lib/queries/notification/tests/entity-mutations.test.ts+++ b/apps/web/src/lib/queries/notification/tests/entity-mutations.test.ts@@ -52,6 +52,40 @@ describe('updateNotificationsForEntities', () => {vi.clearAllMocks();});+ it.each(['MARK_SEEN', 'MARK_DONE'] as const)(+ 'sends %s for modern projects without targeting legacy folders',+ async (operation) => {+ const initiative = toNotificationEntityRef({+ type: 'initiative',+ id: 'project-1',+ });+ const folder = toNotificationEntityRef({+ type: 'project',+ id: 'project-1',+ });+ if (!initiative || !folder) {+ throw new Error('Both project types must support notification writes');+ }++ await updateNotificationsForEntities({+ entities: [initiative, folder],+ operation,+ expectedNotificationIds: ['notification-1'],+ });++ expect(+ mocks.updateGraphqlNotificationsForEntities+ ).toHaveBeenCalledExactlyOnceWith({+ entities: [+ { entityType: 'INITIATIVE', entityId: 'project-1' },+ { entityType: 'PROJECT', entityId: 'project-1' },+ ],+ operation,+ expectedNotificationIds: ['notification-1'],+ });+ }+ );+it('relies on normalized cache updates when the cache is active', async () => {await updateNotificationsForEntities({entities: [{ type: 'channel', id: 'channel-1' }],diff --git a/docs/agent-guide/ai-chat.md b/docs/agent-guide/ai-chat.mdindex 99857c2d9e..5abfd6f716 100644--- a/docs/agent-guide/ai-chat.md+++ b/docs/agent-guide/ai-chat.md@@ -2505,3 +2505,7 @@ preferences are private and cannot be read by targeting another user.Activity is generated for completed UTC days in the background. Local environmentsrequire an intentional CLI refresh; ordinary memory reads do not invoke a model.++Opening a row clears its unread state immediately; direct details mark read when+ready. See [reading items](notifications.md#reading-items) for failure, keyboard,+mobile, and email inbox checks.diff --git a/docs/agent-guide/documents.md b/docs/agent-guide/documents.mdindex d99ba95102..bfa37652b7 100644--- a/docs/agent-guide/documents.md+++ b/docs/agent-guide/documents.md@@ -3116,3 +3116,7 @@ an empty circle, and subtype-only previews use their completion flag. SeeSharing labels describe their audience: Only people with access, Anyone with the link, and Team members with the link. Permission choices say Can view, Can comment, and Can edit. Copying a restricted link still does not grant access. The existing immediately opening dialog and its deferred loading remain unchanged.Drive's existing New controls open a wide menu with icons and short descriptions for creation and uploads, while preserving the current destination and feature gates.++Opening a row clears its unread state immediately; direct details mark read when+ready. See [reading items](notifications.md#reading-items) for failure, keyboard,+mobile, and email inbox checks.diff --git a/docs/agent-guide/email.md b/docs/agent-guide/email.mdindex 6003e63a13..994fdad10a 100644--- a/docs/agent-guide/email.md+++ b/docs/agent-guide/email.md@@ -1412,3 +1412,7 @@ On desktop, drag a tag from the sidebar onto an email row. Its existing tagsremain; dropping onto a selected row applies the tag to every taggable selectedrow. The dragged chip shows the tag color and name, and the target gets an outline.Clicking the tag still filters the list. Mobile uses the existing tag menu.++Opening a row clears its unread state immediately; direct details mark read when+ready. See [reading items](notifications.md#reading-items) for failure, keyboard,+mobile, and email inbox checks.diff --git a/docs/agent-guide/notifications.md b/docs/agent-guide/notifications.mdindex ad2823b651..4c7c881ec8 100644--- a/docs/agent-guide/notifications.md+++ b/docs/agent-guide/notifications.md@@ -1,5 +1,33 @@# Notifications+## Reading items++Opening or previewing an item clears the unread dot immediately, before its+read request completes. Home, Mail, Drive and Tasks share this behavior for+Markdown/tasks, legacy AI chats, email, calendar events, agent sessions, CRM+records and pull requests. Loaded call/project notifications use the same policy.+Email clears both the mailbox unread state and reminder notifications, using the+thread's owning inbox. A failed notification write restores its dot; failed REST+mailbox writes refresh the affected thread. Direct document/chat/PR/email links+mark read when their content mounts, without an extra timer.++Check click/tap, Enter, keyboard preview following, next-item navigation and+mark-done advance. With writes held pending, the dot should already be gone;+fail the write and verify that the dot returns and reopening retries. Include+email from a secondary inbox and a received thread with a draft reply. Mark an+open email unread explicitly and leave it open: the mount marker must not keep+marking it read. Local-only drafts must not issue a mailbox read.++Channel/thread rows retain their scoped reads, and message readers still require+actual visibility; opening another entity must not mark hidden replies seen.++With GraphQL Soup enabled, modern project **Mark read** and **Mark done** actions+target all of the project's notifications, including notifications absent from+the loaded feed. The target is `INITIATIVE`; legacy Drive folders retain the+separate `PROJECT` target.+Check both actions with a partially loaded notification feed. This mapping does+not add read-on-open behavior to project routes or folder navigation.+## NotificationsBrowser notifications must arrive while Macro is in a background tab, not justdiff --git a/docs/agent-guide/pull-requests.md b/docs/agent-guide/pull-requests.mdindex 93135ea4cc..2018d2c0f9 100644--- a/docs/agent-guide/pull-requests.md+++ b/docs/agent-guide/pull-requests.md@@ -103,3 +103,10 @@ account. In the network panel, confirm the update arrives on the Soup GraphQLsubscription without triggering a refetch of every Soup list. Replaying anunchanged webhook should not produce another Soup update. The PR detail'sseparate diff and discussion requests are outside this subscription behavior.++Opening a pull request from Home clears its loaded unread notifications immediately,+including desktop previews, keyboard activation, j/k navigation, and phone taps.+Keyboard browsing marks the row when its debounced preview actually opens;+marking a row done also marks the next PR read when it opens. A failed read+write restores the unread dot; opening the row again retries it. The detail+view also marks the whole pull request read on mount, without an extra delay.diff --git a/docs/agent-guide/tasks.md b/docs/agent-guide/tasks.mdindex 7bd8b007dd..1dd639a9cf 100644--- a/docs/agent-guide/tasks.md+++ b/docs/agent-guide/tasks.md@@ -1289,3 +1289,7 @@ mention, and mention menu row, including completing and reopening without a reloThe Task, Subtask, Project, and Tag entries use a wide menu with original icons and muted descriptions. Subtask opens a parent-task picker, then the normal task composer. Saving includes the selected Parent task property; if that link cannot be confirmed, keep the created task and show a warning instead of asking the user to create it again. Canceling either step creates nothing.++Opening a row clears its unread state immediately; direct details mark read when+ready. See [reading items](notifications.md#reading-items) for failure, keyboard,+mobile, and email inbox checks.