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(inbox): bucket live-notified rows by notification time when the server sort is off (#6576)

gbirmanb383f9d19b57
diff --git a/apps/web/src/features/inbox-view/queries/inbox-query.ts b/apps/web/src/features/inbox-view/queries/inbox-query.ts
index edb6620406..282b3d1e6c 100644
--- a/apps/web/src/features/inbox-view/queries/inbox-query.ts
+++ b/apps/web/src/features/inbox-view/queries/inbox-query.ts
@@ -137,14 +137,22 @@ export type InboxViewContext = {
/**
* Signal and Noise are notification feeds: a row belongs where its latest
* notification puts it, not where its content's last edit does — a comment
- * on a week-old task is today's news. The server sort is also a filter (rows
- * without a notification are absent), which is what those tabs mean anyway.
+ * on a week-old task is today's news.
+ */
+export const inboxTabIsNotificationFeed = (tab: InboxTab): boolean =>
+ tab === 'signal' || tab === 'noise';
+
+/**
+ * Whether to ask the server to sort (and, being a sort-as-filter, restrict)
+ * these tabs by the viewer's latest notification. Gated behind a flag: the
+ * candidate query is costly. Client-side date bucketing is not gated on it —
+ * see `inboxGroupTimestamp` — so a live notification still re-buckets its row
+ * even while the server keeps sorting by content recency.
*/
export const inboxTabOrdersByNotification = (
context: Pick<InboxViewContext, 'tab' | 'capabilities'>
): boolean =>
- context.capabilities.notifiedSort &&
- (context.tab === 'signal' || context.tab === 'noise');
+ context.capabilities.notifiedSort && inboxTabIsNotificationFeed(context.tab);
/** Builds the heterogeneous Soup AST for the composable Inbox view. */
export function buildInboxQuery(
diff --git a/apps/web/src/features/inbox-view/queries/inbox-results.test.ts b/apps/web/src/features/inbox-view/queries/inbox-results.test.ts
index 9474d5bf81..bcddfaa06c 100644
--- a/apps/web/src/features/inbox-view/queries/inbox-results.test.ts
+++ b/apps/web/src/features/inbox-view/queries/inbox-results.test.ts
@@ -123,23 +123,29 @@ describe('inbox date buckets', () => {
]);
});
- it('buckets by content recency while the notified sort is off', () => {
+ it('still buckets a stamped row by its notification while the server sort is off', () => {
+ // The server notified_at sort is gated for cost, but a websocket
+ // notification stamps `notifiedAt` locally and the row must re-bucket
+ // there regardless — otherwise a fresh comment on a stale task sinks into
+ // an old date section until a refetch catches up.
const signal = {
tab: 'signal' as const,
capabilities: withoutNotifiedSort.capabilities,
};
expect(inboxGroupTimestamp(staleTaskFreshComment, signal)).toBe(
- '2026-08-31T19:00:00Z'
+ '2026-09-02T17:00:00Z'
+ );
+ // A row without a stamp still falls back to content recency.
+ expect(inboxGroupTimestamp(freshEmail, signal)).toBe(
+ '2026-09-02T16:00:00Z'
);
const groups = groupInboxEntitiesByDate(
[freshEmail, staleTaskFreshComment],
signal,
now
);
- expect(groups.map((group) => group.label)).toEqual([
- 'Today',
- 'Last 7 days',
- ]);
+ expect(groups).toHaveLength(1);
+ expect(groups[0].label).toBe('Today');
});
});
diff --git a/apps/web/src/features/inbox-view/queries/inbox-results.ts b/apps/web/src/features/inbox-view/queries/inbox-results.ts
index 90c0886b5b..c4c8ac9feb 100644
--- a/apps/web/src/features/inbox-view/queries/inbox-results.ts
+++ b/apps/web/src/features/inbox-view/queries/inbox-results.ts
@@ -14,7 +14,7 @@ import {
} from './home-date-buckets';
import {
type InboxViewContext,
- inboxTabOrdersByNotification,
+ inboxTabIsNotificationFeed,
} from './inbox-query';
type InboxOrderContext = Pick<InboxViewContext, 'tab' | 'capabilities'>;
@@ -23,16 +23,19 @@ export const inboxSortTimestamp = (entity: EntityData) =>
entity.sortTs ?? entity.updatedAt ?? entity.createdAt;
/**
- * The timestamp a row is bucketed on. Tabs served by the `notified_at` sort
- * bucket on the viewer's latest notification, matching the order the rows
- * arrive in; rows without a stamp (websocket inserts) and the other tabs fall
- * back to content recency.
+ * The timestamp a row is bucketed on. The notification feeds (Signal, Noise)
+ * bucket on the viewer's latest notification so a fresh comment on a stale
+ * entity reads as today's news. A live websocket notification stamps
+ * `notifiedAt` right away (`bumpSoupEntityNotifiedAt`), so this holds even
+ * while the server keeps sorting by content recency — the `notified_at` server
+ * sort is gated for cost, but client bucketing is free. Rows without a stamp,
+ * and the other tabs, fall back to content recency.
*/
export const inboxGroupTimestamp = (
entity: EntityData,
context: InboxOrderContext
) =>
- (inboxTabOrdersByNotification(context) ? entity.notifiedAt : undefined) ??
+ (inboxTabIsNotificationFeed(context.tab) ? entity.notifiedAt : undefined) ??
inboxSortTimestamp(entity);
export function groupInboxEntitiesByDate<T extends EntityData>(