Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-8541: feat(inbox): route comments by who they @mention, not who wrote them (#9864)
Bohan Jiangcb5ed4f33e36
diff --git a/apps/mobile/locales/en/settings.json b/apps/mobile/locales/en/settings.jsonindex 80129ac15f..2c9600c3a8 100644--- a/apps/mobile/locales/en/settings.json+++ b/apps/mobile/locales/en/settings.json@@ -97,9 +97,9 @@"label": "Mentions","description": "When someone @mentions you, including @all and @squad"},- "member_comments": {- "label": "Member comments",- "description": "When a member comments on an issue you follow"+ "comments_without_mentions": {+ "label": "Comments without mentions",+ "description": "When someone comments on an issue you follow without @mentioning anyone"},"agent_failures": {"label": "Agent errors",@@ -117,9 +117,9 @@"label": "Priority and dates","description": "When priority, start date, or due date changes"},- "agent_comments": {- "label": "Agent comments",- "description": "When an agent replies on an issue you follow"+ "comments_mentioning_others": {+ "label": "Comments mentioning others",+ "description": "When a comment on an issue you follow @mentions other people or agents, but not you"}}}diff --git a/apps/mobile/locales/zh-Hans/settings.json b/apps/mobile/locales/zh-Hans/settings.jsonindex 9a7facd6c2..f2d6e4668c 100644--- a/apps/mobile/locales/zh-Hans/settings.json+++ b/apps/mobile/locales/zh-Hans/settings.json@@ -97,9 +97,9 @@"label": "提及","description": "有人 @ 你时,包括 @all 和 @squad"},- "member_comments": {- "label": "成员评论",- "description": "成员在你订阅的任务里发表评论时"+ "comments_without_mentions": {+ "label": "未 @ 任何人的评论",+ "description": "有人在你订阅的任务里评论,且没有 @ 任何人时"},"agent_failures": {"label": "智能体出错",@@ -117,9 +117,9 @@"label": "优先级与日期","description": "优先级、开始日期或截止日期变化时"},- "agent_comments": {- "label": "智能体评论",- "description": "智能体在你订阅的任务里回复时"+ "comments_mentioning_others": {+ "label": "@ 了其他人的评论",+ "description": "你订阅的任务里的评论 @ 了其他成员或智能体、但没有 @ 你时"}}}diff --git a/apps/mobile/locales/zh-Hant/settings.json b/apps/mobile/locales/zh-Hant/settings.jsonindex 3387b52adb..8282e6a227 100644--- a/apps/mobile/locales/zh-Hant/settings.json+++ b/apps/mobile/locales/zh-Hant/settings.json@@ -97,9 +97,9 @@"label": "提及","description": "有人 @ 你時,包括 @all 和 @squad"},- "member_comments": {- "label": "成員評論",- "description": "成員在你訂閱的任務裡發表評論時"+ "comments_without_mentions": {+ "label": "未 @ 任何人的評論",+ "description": "有人在你訂閱的任務裡評論,且沒有 @ 任何人時"},"agent_failures": {"label": "AI 代理出錯",@@ -117,9 +117,9 @@"label": "優先順序與日期","description": "優先順序、開始日期或截止日期變化時"},- "agent_comments": {- "label": "AI 代理評論",- "description": "AI 代理在你訂閱的任務裡回覆時"+ "comments_mentioning_others": {+ "label": "@ 了其他人的評論",+ "description": "你訂閱的任務裡的評論 @ 了其他成員或 AI 代理、但沒有 @ 你時"}}}diff --git a/packages/core/notification-preferences/patch.ts b/packages/core/notification-preferences/patch.tsindex ef92874fe4..545a58bca6 100644--- a/packages/core/notification-preferences/patch.ts+++ b/packages/core/notification-preferences/patch.ts@@ -7,12 +7,12 @@ import type {const NOTIFICATION_GROUP_KEYS: readonly NotificationGroupKey[] = ["assigned","mentions",- "member_comments",+ "comments_without_mentions","agent_failures","status_changes","assignee_changes","updates",- "agent_comments",+ "comments_mentioning_others","assignments","comments","agent_activity",diff --git a/packages/core/notification-preferences/routes.test.ts b/packages/core/notification-preferences/routes.test.tsindex 500906abf1..b1b7018a14 100644--- a/packages/core/notification-preferences/routes.test.ts+++ b/packages/core/notification-preferences/routes.test.ts@@ -24,12 +24,12 @@ describe("resolveNotificationRoute", () => {expect(resolved({})).toEqual({assigned: "action",mentions: "action",- member_comments: "action",+ comments_without_mentions: "action",agent_failures: "action",status_changes: "activity",assignee_changes: "activity",updates: "activity",- agent_comments: "activity",+ comments_mentioning_others: "activity",});expect(notificationRoutesAreDefault({ status_changes: "all" })).toBe(true);});@@ -47,9 +47,12 @@ describe("resolveNotificationRoute", () => {});it("keeps a muted legacy group muting both halves until the new key is set", () => {- const prefs: NotificationPreferences = { comments: "muted", agent_comments: "activity" };- expect(resolveNotificationRoute(prefs, kind("member_comments"))).toBe("muted");- expect(resolveNotificationRoute(prefs, kind("agent_comments"))).toBe("activity");+ const prefs: NotificationPreferences = {+ comments: "muted",+ comments_mentioning_others: "activity",+ };+ expect(resolveNotificationRoute(prefs, kind("comments_without_mentions"))).toBe("muted");+ expect(resolveNotificationRoute(prefs, kind("comments_mentioning_others"))).toBe("activity");expect(resolveNotificationRoute(prefs, kind("mentions"))).toBe("action");expect(resolveNotificationRoute({ assignments: "muted" }, kind("assignee_changes"))).toBe("muted");});@@ -65,12 +68,12 @@ describe("withNotificationRoute", () => {it("retires a muted legacy group without unmuting the other kind it covered", () => {const next = withNotificationRoute({ comments: "muted", system_notifications: "muted" },- kind("member_comments"),+ kind("comments_without_mentions"),"action",);- expect(next).toEqual({ agent_comments: "muted", system_notifications: "muted" });- expect(resolveNotificationRoute(next, kind("member_comments"))).toBe("action");- expect(resolveNotificationRoute(next, kind("agent_comments"))).toBe("muted");+ expect(next).toEqual({ comments_mentioning_others: "muted", system_notifications: "muted" });+ expect(resolveNotificationRoute(next, kind("comments_without_mentions"))).toBe("action");+ expect(resolveNotificationRoute(next, kind("comments_mentioning_others"))).toBe("muted");});it("keeps a sibling's explicit choice when retiring the legacy group", () => {diff --git a/packages/core/notification-preferences/routes.ts b/packages/core/notification-preferences/routes.tsindex ee9fbc3dbd..19994d5f50 100644--- a/packages/core/notification-preferences/routes.ts+++ b/packages/core/notification-preferences/routes.ts@@ -16,16 +16,20 @@ export interface NotificationRouteKind {* Routable kinds in settings order. Mirrors `RouteKinds` in* server/internal/inbox/routing.go, which applies them when notifications are* created; keep the two in step.+ *+ * Comments route by who they are written to, not who wrote them: one that+ * @mentions nobody, or one that @mentions others but not the recipient. A+ * comment that @mentions the recipient follows `mentions`.*/export const NOTIFICATION_ROUTE_KINDS: readonly NotificationRouteKind[] = [{ key: "assigned", default: "action", legacy: "assignments" },{ key: "mentions", default: "action" },- { key: "member_comments", default: "action", legacy: "comments" },+ { key: "comments_without_mentions", default: "action", legacy: "comments" },{ key: "agent_failures", default: "action", legacy: "agent_activity" },{ key: "status_changes", default: "activity" },{ key: "assignee_changes", default: "activity", legacy: "assignments" },{ key: "updates", default: "activity" },- { key: "agent_comments", default: "activity", legacy: "comments" },+ { key: "comments_mentioning_others", default: "activity", legacy: "comments" },];function isRoute(value: unknown): value is NotificationRoute {diff --git a/packages/core/types/notification-preference.ts b/packages/core/types/notification-preference.tsindex 4a692fab48..17f5918bf9 100644--- a/packages/core/types/notification-preference.ts+++ b/packages/core/types/notification-preference.ts@@ -2,12 +2,12 @@export type NotificationRouteKey =| "assigned"| "mentions"- | "member_comments"+ | "comments_without_mentions"| "agent_failures"| "status_changes"| "assignee_changes"| "updates"- | "agent_comments";+ | "comments_mentioning_others";/** Where a routable kind lands: an Inbox section, or nowhere. */export type NotificationRoute = "action" | "activity" | "muted";diff --git a/packages/views/locales/en/settings.json b/packages/views/locales/en/settings.jsonindex 58db72b1c1..ddcbe9d3f7 100644--- a/packages/views/locales/en/settings.json+++ b/packages/views/locales/en/settings.json@@ -679,9 +679,9 @@"label": "Mentions","description": "When someone @mentions you, including @all and @squad"},- "member_comments": {- "label": "Member comments",- "description": "When a member comments on an issue you follow"+ "comments_without_mentions": {+ "label": "Comments without mentions",+ "description": "When someone comments on an issue you follow without @mentioning anyone"},"agent_failures": {"label": "Agent errors",@@ -699,9 +699,9 @@"label": "Priority and dates","description": "When priority, start date, or due date changes"},- "agent_comments": {- "label": "Agent comments",- "description": "When an agent replies on an issue you follow"+ "comments_mentioning_others": {+ "label": "Comments mentioning others",+ "description": "When a comment on an issue you follow @mentions other people or agents, but not you"}},"system": {diff --git a/packages/views/locales/fr/settings.json b/packages/views/locales/fr/settings.jsonindex 32394dbc0d..a8aeb23809 100644--- a/packages/views/locales/fr/settings.json+++ b/packages/views/locales/fr/settings.json@@ -679,9 +679,9 @@"label": "Mentions","description": "Quand quelqu'un vous @mentionne, y compris @all et @squad"},- "member_comments": {- "label": "Commentaires des membres",- "description": "Quand un membre commente une tâche que vous suivez"+ "comments_without_mentions": {+ "label": "Commentaires sans mention",+ "description": "Quand quelqu'un commente une tâche que vous suivez sans @mentionner personne"},"agent_failures": {"label": "Erreurs d'agent",@@ -699,9 +699,9 @@"label": "Priorité et dates","description": "Quand la priorité, la date de début ou l'échéance change"},- "agent_comments": {- "label": "Commentaires d'agent",- "description": "Quand un agent répond sur une tâche que vous suivez"+ "comments_mentioning_others": {+ "label": "Commentaires mentionnant d'autres",+ "description": "Quand un commentaire sur une tâche que vous suivez @mentionne d'autres personnes ou agents, mais pas vous"}},"system": {diff --git a/packages/views/locales/ja/settings.json b/packages/views/locales/ja/settings.jsonindex 339a518a66..a85075e9be 100644--- a/packages/views/locales/ja/settings.json+++ b/packages/views/locales/ja/settings.json@@ -662,21 +662,21 @@},"muted": {"label": "オフ",- "description": "インボックスに入らない。課題では引き続き表示"+ "description": "インボックスに入らない。タスクでは引き続き表示"}},"kinds": {"assigned": {"label": "自分への割り当て",- "description": "課題が自分に割り当てられたとき"+ "description": "タスクが自分に割り当てられたとき"},"mentions": {"label": "メンション","description": "誰かがあなたを @ したとき(@all と @squad を含む)"},- "member_comments": {- "label": "メンバーのコメント",- "description": "フォロー中の課題にメンバーがコメントしたとき"+ "comments_without_mentions": {+ "label": "メンションなしのコメント",+ "description": "フォロー中のタスクに、誰も @ していないコメントが付いたとき"},"agent_failures": {"label": "エージェントのエラー",@@ -684,19 +684,19 @@},"status_changes": {"label": "ステータス変更",- "description": "フォロー中の課題のステータスが変わったとき"+ "description": "フォロー中のタスクのステータスが変わったとき"},"assignee_changes": {"label": "担当者の変更",- "description": "課題の担当者が変わったとき、または割り当てが外れたとき"+ "description": "タスクの担当者が変わったとき、または割り当てが外れたとき"},"updates": {"label": "優先度と日付","description": "優先度、開始日、期日が変わったとき"},- "agent_comments": {- "label": "エージェントのコメント",- "description": "フォロー中の課題でエージェントが返信したとき"+ "comments_mentioning_others": {+ "label": "他の人をメンションしたコメント",+ "description": "フォロー中のタスクのコメントが、あなたではなく他の人やエージェントを @ したとき"}},"system": {diff --git a/packages/views/locales/ko/settings.json b/packages/views/locales/ko/settings.jsonindex 02c1a58296..ddf1e74916 100644--- a/packages/views/locales/ko/settings.json+++ b/packages/views/locales/ko/settings.json@@ -662,21 +662,21 @@},"muted": {"label": "끄기",- "description": "인박스에 들어오지 않음. 이슈에서는 계속 표시"+ "description": "인박스에 들어오지 않음. 태스크에서는 계속 표시"}},"kinds": {"assigned": {"label": "나에게 할당",- "description": "이슈가 나에게 할당될 때"+ "description": "태스크가 나에게 할당될 때"},"mentions": {"label": "멘션","description": "누군가 나를 @ 멘션할 때(@all, @squad 포함)"},- "member_comments": {- "label": "멤버 댓글",- "description": "팔로우 중인 이슈에 멤버가 댓글을 달 때"+ "comments_without_mentions": {+ "label": "멘션 없는 댓글",+ "description": "팔로우 중인 태스크에 아무도 @ 멘션하지 않은 댓글이 달릴 때"},"agent_failures": {"label": "에이전트 오류",@@ -684,19 +684,19 @@},"status_changes": {"label": "상태 변경",- "description": "팔로우 중인 이슈의 상태가 바뀔 때"+ "description": "팔로우 중인 태스크의 상태가 바뀔 때"},"assignee_changes": {"label": "담당자 변경",- "description": "이슈 담당자가 바뀌거나 내 할당이 해제될 때"+ "description": "태스크 담당자가 바뀌거나 내 할당이 해제될 때"},"updates": {"label": "우선순위와 날짜","description": "우선순위, 시작일, 마감일이 바뀔 때"},- "agent_comments": {- "label": "에이전트 댓글",- "description": "팔로우 중인 이슈에 에이전트가 답할 때"+ "comments_mentioning_others": {+ "label": "다른 사람을 멘션한 댓글",+ "description": "팔로우 중인 태스크의 댓글이 내가 아닌 다른 사람이나 에이전트를 @ 멘션할 때"}},"system": {diff --git a/packages/views/locales/zh-Hans/settings.json b/packages/views/locales/zh-Hans/settings.jsonindex 315599b163..97beac4591 100644--- a/packages/views/locales/zh-Hans/settings.json+++ b/packages/views/locales/zh-Hans/settings.json@@ -674,9 +674,9 @@"label": "提及","description": "有人 @ 你时,包括 @all 和 @squad"},- "member_comments": {- "label": "成员评论",- "description": "成员在你订阅的任务里发表评论时"+ "comments_without_mentions": {+ "label": "未 @ 任何人的评论",+ "description": "有人在你订阅的任务里评论,且没有 @ 任何人时"},"agent_failures": {"label": "智能体出错",@@ -694,9 +694,9 @@"label": "优先级与日期","description": "优先级、开始日期或截止日期变化时"},- "agent_comments": {- "label": "智能体评论",- "description": "智能体在你订阅的任务里回复时"+ "comments_mentioning_others": {+ "label": "@ 了其他人的评论",+ "description": "你订阅的任务里的评论 @ 了其他成员或智能体、但没有 @ 你时"}},"system": {diff --git a/packages/views/locales/zh-Hant/settings.json b/packages/views/locales/zh-Hant/settings.jsonindex e360dfa65b..d99a190564 100644--- a/packages/views/locales/zh-Hant/settings.json+++ b/packages/views/locales/zh-Hant/settings.json@@ -674,9 +674,9 @@"label": "提及","description": "有人 @ 你時,包括 @all 和 @squad"},- "member_comments": {- "label": "成員評論",- "description": "成員在你訂閱的任務裡發表評論時"+ "comments_without_mentions": {+ "label": "未 @ 任何人的評論",+ "description": "有人在你訂閱的任務裡評論,且沒有 @ 任何人時"},"agent_failures": {"label": "AI 代理出錯",@@ -694,9 +694,9 @@"label": "優先順序與日期","description": "優先順序、開始日期或截止日期變化時"},- "agent_comments": {- "label": "AI 代理評論",- "description": "AI 代理在你訂閱的任務裡回覆時"+ "comments_mentioning_others": {+ "label": "@ 了其他人的評論",+ "description": "你訂閱的任務裡的評論 @ 了其他成員或 AI 代理、但沒有 @ 你時"}},"system": {diff --git a/packages/views/settings/components/notifications-tab.test.tsx b/packages/views/settings/components/notifications-tab.test.tsxindex 8c813af277..39897d369a 100644--- a/packages/views/settings/components/notifications-tab.test.tsx+++ b/packages/views/settings/components/notifications-tab.test.tsx@@ -52,7 +52,8 @@ describe("NotificationsTab", () => {expect(select(kinds.assigned.label)).toHaveTextContent(routes.action.label);expect(select(kinds.mentions.label)).toHaveTextContent(routes.action.label);expect(select(kinds.status_changes.label)).toHaveTextContent(routes.activity.label);- expect(select(kinds.agent_comments.label)).toHaveTextContent(routes.activity.label);+ expect(select(kinds.comments_without_mentions.label)).toHaveTextContent(routes.action.label);+ expect(select(kinds.comments_mentioning_others.label)).toHaveTextContent(routes.activity.label);expect(screen.getByRole("button", { name: enSettings.notifications.reset })).toBeDisabled();});@@ -60,8 +61,8 @@ describe("NotificationsTab", () => {prefs.current = { comments: "muted" };render(<NotificationsTab />, { wrapper: Wrapper });- expect(select(kinds.member_comments.label)).toHaveTextContent(routes.muted.label);- expect(select(kinds.agent_comments.label)).toHaveTextContent(routes.muted.label);+ expect(select(kinds.comments_without_mentions.label)).toHaveTextContent(routes.muted.label);+ expect(select(kinds.comments_mentioning_others.label)).toHaveTextContent(routes.muted.label);expect(select(kinds.mentions.label)).toHaveTextContent(routes.action.label);});@@ -82,11 +83,11 @@ describe("NotificationsTab", () => {prefs.current = { comments: "muted" };render(<NotificationsTab />, { wrapper: Wrapper });- await user.click(select(kinds.member_comments.label));+ await user.click(select(kinds.comments_without_mentions.label));await user.click(await screen.findByRole("option", { name: new RegExp(`^${routes.action.label}`) }));await waitFor(() =>- expect(mutate).toHaveBeenCalledWith({ agent_comments: "muted" }, expect.anything()),+ expect(mutate).toHaveBeenCalledWith({ comments_mentioning_others: "muted" }, expect.anything()),);});diff --git a/server/cmd/server/notification_comment_audience_test.go b/server/cmd/server/notification_comment_audience_test.gonew file mode 100644index 0000000000..465a14882c--- /dev/null+++ b/server/cmd/server/notification_comment_audience_test.go@@ -0,0 +1,210 @@+package main++import (+ "context"+ "fmt"+ "strings"+ "testing"++ "github.com/google/uuid"+ "github.com/multica-ai/multica/server/internal/events"+ "github.com/multica-ai/multica/server/internal/handler"+ "github.com/multica-ai/multica/server/internal/inbox"+ "github.com/multica-ai/multica/server/internal/util"+ db "github.com/multica-ai/multica/server/pkg/db/generated"+ "github.com/multica-ai/multica/server/pkg/protocol"+)++// TestNotification_CommentRoutedByAudience covers MUL-8541: a comment lands in+// Needs action for a subscriber it @mentions or when it @mentions nobody, and+// in Activity for a subscriber it does not @mention while it @mentions someone+// else. Who wrote the comment does not matter, so every case is posted by an+// agent, the author whose replies used to default to Activity.+func TestNotification_CommentRoutedByAudience(t *testing.T) {+ ctx := context.Background()+ queries := db.New(testPool)+ bus := newNotificationBus(t, queries)++ var agentID string+ if err := testPool.QueryRow(ctx,+ `SELECT id::text FROM agent WHERE workspace_id = $1 ORDER BY created_at ASC LIMIT 1`,+ testWorkspaceID).Scan(&agentID); err != nil {+ t.Fatalf("load agent: %v", err)+ }++ suffix := uuid.NewString()[:8]+ member := func(name string) string {+ email := fmt.Sprintf("notif-audience-%s-%[email protected]", name, suffix)+ id := createNotificationMember(t, email)+ t.Cleanup(func() { cleanupTestUser(t, email) })+ return id+ }+ target := member("target")+ bystander := member("bystander")+ optedIn := member("opted-in")+ if _, err := testPool.Exec(ctx, `+ INSERT INTO notification_preference (workspace_id, user_id, preferences)+ VALUES ($1, $2, '{"comments_mentioning_others":"action"}'::jsonb)+ `, testWorkspaceID, optedIn); err != nil {+ t.Fatalf("seed preference: %v", err)+ }++ // A squad with target as its only human member.+ var squadID string+ if err := testPool.QueryRow(ctx, `+ INSERT INTO squad (workspace_id, name, description, leader_id, creator_id)+ VALUES ($1, $2, '', $3, $4) RETURNING id+ `, testWorkspaceID, "Audience squad "+suffix, agentID, testUserID).Scan(&squadID); err != nil {+ t.Fatalf("create squad: %v", err)+ }+ t.Cleanup(func() { testPool.Exec(context.Background(), `DELETE FROM squad WHERE id = $1`, squadID) })+ if _, err := testPool.Exec(ctx, `+ INSERT INTO squad_member (squad_id, member_type, member_id) VALUES ($1, 'member', $2), ($1, 'agent', $3)+ `, squadID, target, agentID); err != nil {+ t.Fatalf("add squad members: %v", err)+ }++ mentionMember := func(id string) string { return fmt.Sprintf("[@M](mention://member/%s)", id) }+ cases := []struct {+ name string+ content string+ // want is the new_comment section per subscriber.+ want map[string]string+ // mentioned lists who also gets a "mentioned" row.+ mentioned []string+ }{+ {+ name: "nobody mentioned",+ content: "Done, the PR is up.",+ want: map[string]string{target: "action", bystander: "action", optedIn: "action"},+ },+ {+ name: "issue link is not a mention",+ content: "Related to [MUL-1](mention://issue/" + uuid.NewString() + ").",+ want: map[string]string{target: "action", bystander: "action", optedIn: "action"},+ },+ {+ name: "member mentioned",+ content: mentionMember(target) + " can you confirm?",+ want: map[string]string{target: "action", bystander: "activity", optedIn: "action"},+ mentioned: []string{target},+ },+ {+ // The mention parser accepts these forms; they must still reach+ // the member they name.+ name: "member mentioned in uppercase",+ content: fmt.Sprintf("[@M](mention://member/%s) can you confirm?", strings.ToUpper(target)),+ want: map[string]string{target: "action", bystander: "activity", optedIn: "action"},+ mentioned: []string{target},+ },+ {+ name: "member mentioned without hyphens",+ content: fmt.Sprintf("[@M](mention://member/%s) can you confirm?", strings.ReplaceAll(target, "-", "")),+ want: map[string]string{target: "action", bystander: "activity", optedIn: "action"},+ mentioned: []string{target},+ },+ {+ name: "only an agent mentioned",+ content: fmt.Sprintf("[@A](mention://agent/%s) please take this", agentID),+ want: map[string]string{target: "activity", bystander: "activity", optedIn: "action"},+ },+ {+ name: "recipient and others mentioned",+ content: mentionMember(target) + fmt.Sprintf(" and [@A](mention://agent/%s)", agentID),+ want: map[string]string{target: "action", bystander: "activity", optedIn: "action"},+ mentioned: []string{target},+ },+ {+ name: "squad reaches its human members",+ content: fmt.Sprintf("[@S](mention://squad/%s) over to you", squadID),+ want: map[string]string{target: "action", bystander: "activity", optedIn: "action"},+ mentioned: []string{target},+ },+ {+ name: "@all reaches everyone",+ content: "[@all](mention://all/all) heads up",+ want: map[string]string{target: "action", bystander: "action", optedIn: "action"},+ mentioned: []string{target, bystander, optedIn},+ },+ }++ for _, c := range cases {+ t.Run(c.name, func(t *testing.T) {+ issueID := createTestIssue(t, testWorkspaceID, testUserID)+ t.Cleanup(func() {+ cleanupInboxForIssue(t, issueID)+ cleanupTestIssue(t, issueID)+ })+ for _, id := range []string{target, bystander, optedIn} {+ addTestSubscriber(t, issueID, "member", id, "commenter")+ }++ bus.Publish(events.Event{+ Type: protocol.EventCommentCreated,+ WorkspaceID: testWorkspaceID,+ ActorType: "agent",+ ActorID: agentID,+ Payload: map[string]any{+ "comment": handler.CommentResponse{+ ID: uuid.NewString(),+ IssueID: issueID,+ AuthorType: "agent",+ AuthorID: agentID,+ Content: c.content,+ Type: "comment",+ },+ "issue_title": "audience test issue",+ "issue_status": "todo",+ },+ })++ mentioned := map[string]bool{}+ for _, id := range c.mentioned {+ mentioned[id] = true+ }+ for id, want := range c.want {+ var comment, mention int+ for _, item := range inboxItemsForRecipient(t, queries, id) {+ if util.UUIDToString(item.IssueID) != issueID {+ continue+ }+ switch item.Type {+ case "new_comment":+ comment+++ if !item.Section.Valid || item.Section.String != want {+ t.Errorf("%s: new_comment section = %+v, want %q", id, item.Section, want)+ }+ case "mentioned":+ mention+++ }+ }+ if comment != 1 {+ t.Errorf("%s: new_comment rows = %d, want 1", id, comment)+ }+ if wantMention := map[bool]int{true: 1}[mentioned[id]]; mention != wantMention {+ t.Errorf("%s: mentioned rows = %d, want %d", id, mention, wantMention)+ }+ }+ })+ }+}++// TestCommentAudienceCanonicalizesMemberIDs guards the comparison behind+// commentAudience: subscriber IDs are canonical (lowercase, hyphenated), and a+// member mention written in another accepted form must match them, so the+// comment follows the member's mentions choice instead of landing in+// Activity as if it were written to someone else.+func TestCommentAudienceCanonicalizesMemberIDs(t *testing.T) {+ const member = "0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d"+ for _, id := range []string{member, strings.ToUpper(member), strings.ReplaceAll(member, "-", "")} {+ mentioned := expandMentionedMembers(context.Background(), nil, "",+ parseMentions(fmt.Sprintf("[@M](mention://member/%s) please look", id)))+ if got := mentioned.commentAudience(member); got != inbox.CommentToRecipient {+ t.Errorf("mention of %q: audience = %v, want CommentToRecipient", id, got)+ }+ section, ok := inbox.RouteComment(map[string]string{"mentions": "muted"}, mentioned.commentAudience(member))+ if ok {+ t.Errorf("mention of %q with mentions muted: route = (%q, delivered), want muted", id, section)+ }+ }+}diff --git a/server/cmd/server/notification_listeners.go b/server/cmd/server/notification_listeners.goindex 052008d7b7..a51097c2b6 100644--- a/server/cmd/server/notification_listeners.go+++ b/server/cmd/server/notification_listeners.go@@ -263,6 +263,18 @@ func archiveStaleTaskFailedInbox("row_count", len(rows), "recipient_count", len(counts))}+// subscriberRoute decides which Inbox section a notification lands in for one+// member subscriber, given their preferences. ok is false when they muted it.+type subscriberRoute func(memberID string, prefs map[string]string) (section string, ok bool)++// routeByType routes on the notification type alone, which is enough for+// every kind except comments.+func routeByType(notifType string) subscriberRoute {+ return func(_ string, prefs map[string]string) (string, bool) {+ return inbox.Route(prefs, notifType)+ }+}+// notifySubscribers queries the subscriber table for an issue, excludes the// actor and any extra IDs, and creates inbox items for each remaining member// subscriber. Publishes an inbox:new event for each notification.@@ -283,10 +295,33 @@ func notifySubscribers(title string,body string,details []byte,+) {+ notifySubscribersRouted(ctx, queries, bus, issueID, issueStatus, workspaceID, e, exclude,+ notifType, severity, title, body, details, routeByType(notifType))+}++// notifySubscribersRouted is notifySubscribers with a caller-chosen route per+// subscriber. Comments use it: where a comment lands depends on whether it+// @mentions the subscriber, someone else, or nobody.+func notifySubscribersRouted(+ ctx context.Context,+ queries *db.Queries,+ bus *events.Bus,+ issueID string,+ issueStatus string,+ workspaceID string,+ e events.Event,+ exclude map[string]bool,+ notifType string,+ severity string,+ title string,+ body string,+ details []byte,+ route subscriberRoute,) {notified, tierSuppressed := notifyIssueSubscribers(ctx, queries, bus,issueID, issueID, issueStatus, workspaceID, e, exclude,- notifType, severity, title, body, details)+ notifType, severity, title, body, details, route)// Only a small allowlist of event types bubbles to parent subscribers.if !parentBubbleNotifTypes[notifType] {@@ -328,7 +363,7 @@ func notifySubscribers(parentID := util.UUIDToString(issue.ParentIssueID)notifyIssueSubscribers(ctx, queries, bus,parentID, issueID, issueStatus, workspaceID, e, parentExclude,- notifType, severity, title, body, details)+ notifType, severity, title, body, details, route)}// notifyIssueSubscribers sends inbox notifications to subscribers of@@ -355,6 +390,7 @@ func notifyIssueSubscribers(title string,body string,details []byte,+ route subscriberRoute,) (map[string]bool, map[string]bool) {notified := map[string]bool{}tierSuppressed := map[string]bool{}@@ -409,7 +445,7 @@ func notifyIssueSubscribers(}// The recipient decides which Inbox section this lands in, or mutes it.- section, routed := inbox.Route(userPrefs[subID], notifType, util.StrToText(e.ActorType))+ section, routed := route(subID, userPrefs[subID])if !routed {continue}@@ -484,11 +520,11 @@ func notifyDirect(}// Member recipients route the notification through their preferences.- section := inbox.DefaultSection(notifType, util.StrToText(e.ActorType))+ section := inbox.DefaultSection(notifType)if recipientType == "member" {prefs := loadUserPrefs(ctx, queries, workspaceID, []string{recipientID})var routed bool- section, routed = inbox.Route(prefs[recipientID], notifType, util.StrToText(e.ActorType))+ section, routed = inbox.Route(prefs[recipientID], notifType)if !routed {return}@@ -529,74 +565,134 @@ func notifyDirect(})}-// notifyMentionedMembers creates inbox items for each @mentioned member,-// excluding the actor and any IDs in the skip set. When an @all mention is-// present, all workspace members are notified (excluding agents).-func notifyMentionedMembers(- bus *events.Bus,- queries *db.Queries,- e events.Event,- mentions []mention,- issueID string,- issueTitle string,- issueStatus string,- title string,- skip map[string]bool,- details []byte,-) {- // Collect the set of member IDs to notify.- recipientIDs := map[string]bool{}+// mentionedMembers is the set of workspace members a piece of content+// @mentions: by name, through a squad they belong to, or through @all.+type mentionedMembers struct {+ ids map[string]bool+ // addressesPeople is true when the content @mentions anyone at all — a+ // member, an agent, a squad or @all. Issue links do not count.+ addressesPeople bool+ // complete is false when a squad or @all could not be expanded, so a+ // member missing from ids may still have been mentioned.+ complete bool+}++// expandMentionedMembers resolves mentions to the members they reach. Agent+// members of a squad are reached via comment-trigger / assignment paths, not+// the mention-inbox path, so only member-typed squad members are included.+func expandMentionedMembers(ctx context.Context, queries *db.Queries, workspaceID string, mentions []mention) mentionedMembers {+ out := mentionedMembers{ids: map[string]bool{}, complete: true}hasAll := false- var squadIDs []string+ var squadIDs []pgtype.UUIDfor _, m := range mentions {- if m.Type == "all" {+ switch m.Type {+ case "all":hasAll = true- continue- }- if m.Type == "member" {+ out.addressesPeople = true+ case "member":+ memberUUID, err := util.ParseUUID(m.ID)+ if err != nil {+ continue+ }+ // Keyed by the canonical form, which is how subscriber and actor+ // IDs read: the parser also accepts uppercase or unhyphenated+ // UUIDs, and those must still match the member they name.+ out.ids[util.UUIDToString(memberUUID)] = true+ out.addressesPeople = true+ case "agent":if _, err := util.ParseUUID(m.ID); err != nil {continue}- recipientIDs[m.ID] = true- }- if m.Type == "squad" {- squadIDs = append(squadIDs, m.ID)+ out.addressesPeople = true+ case "squad":+ squadUUID, err := util.ParseUUID(m.ID)+ if err != nil {+ continue+ }+ squadIDs = append(squadIDs, squadUUID)+ out.addressesPeople = true}}- // Expand each @squad mention to its human members. Agent members of a- // squad are reached via comment-trigger / assignment paths, not the- // mention-inbox path, so we only seed member-typed recipients here.- for _, sid := range squadIDs {- squadUUID, err := util.ParseUUID(sid)- if err != nil {- continue- }- members, err := queries.ListSquadMembers(context.Background(), squadUUID)+ for _, squadUUID := range squadIDs {+ members, err := queries.ListSquadMembers(ctx, squadUUID)if err != nil {- slog.Error("failed to list squad members for @squad mention", "squad_id", sid, "error", err)+ slog.Error("failed to list squad members for @squad mention",+ "squad_id", util.UUIDToString(squadUUID), "error", err)+ out.complete = falsecontinue}for _, sm := range members {if sm.MemberType == "member" {- recipientIDs[util.UUIDToString(sm.MemberID)] = true+ out.ids[util.UUIDToString(sm.MemberID)] = true}}}- // If @all is present, expand to all workspace members.if hasAll {- members, err := queries.ListMembers(context.Background(), parseUUID(e.WorkspaceID))+ members, err := queries.ListMembers(ctx, parseUUID(workspaceID))if err != nil {- slog.Error("failed to list members for @all mention", "workspace_id", e.WorkspaceID, "error", err)+ slog.Error("failed to list members for @all mention", "workspace_id", workspaceID, "error", err)+ out.complete = false} else {for _, m := range members {- recipientIDs[util.UUIDToString(m.UserID)] = true+ out.ids[util.UUIDToString(m.UserID)] = true}}}+ return out+}++// commentAudience is who a comment is written to, as one subscriber sees it+// (see inbox.CommentAudience). When a squad or @all could not be expanded, a+// subscriber the comment may have reached is treated as if nobody was+// mentioned: a comment meant for them then still waits in Needs action+// instead of slipping into Activity.+func (m mentionedMembers) commentAudience(memberID string) inbox.CommentAudience {+ switch {+ case m.ids[memberID]:+ return inbox.CommentToRecipient+ case !m.addressesPeople || !m.complete:+ return inbox.CommentToNobody+ default:+ return inbox.CommentToOthers+ }+}++// notifyMentionedMembers creates inbox items for each @mentioned member,+// excluding the actor and any IDs in the skip set. When an @all mention is+// present, all workspace members are notified (excluding agents).+func notifyMentionedMembers(+ bus *events.Bus,+ queries *db.Queries,+ e events.Event,+ mentions []mention,+ issueID string,+ issueTitle string,+ issueStatus string,+ title string,+ skip map[string]bool,+ details []byte,+) {+ mentioned := expandMentionedMembers(context.Background(), queries, e.WorkspaceID, mentions)+ notifyMentionedMemberIDs(bus, queries, e, mentioned.ids, issueID, issueStatus, title, skip, details)+}++// notifyMentionedMemberIDs creates a "mentioned" inbox item for each member in+// recipientIDs, excluding the actor and any IDs in the skip set.+func notifyMentionedMemberIDs(+ bus *events.Bus,+ queries *db.Queries,+ e events.Event,+ recipientIDs map[string]bool,+ issueID string,+ issueStatus string,+ title string,+ skip map[string]bool,+ details []byte,+) {// Batch-load notification preferences for all mention recipients.var mentionUserIDs []stringfor id := range recipientIDs {@@ -612,7 +708,7 @@ func notifyMentionedMembers(}// Mentions route on their own key, deliberately apart from comments:// muting comment volume must not silence someone asking for you by name.- section, routed := inbox.Route(mentionPrefs[id], "mentioned", util.StrToText(e.ActorType))+ section, routed := inbox.Route(mentionPrefs[id], "mentioned")if !routed {continue}@@ -932,16 +1028,22 @@ func registerNotificationListeners(bus *events.Bus, queries *db.Queries) {})}- notifySubscribers(ctx, queries, bus, issueID, issueStatus, e.WorkspaceID, e,+ // Where a comment lands depends on who it is written to, not who wrote+ // it: one that @mentions the subscriber or nobody waits on them, one+ // that @mentions only others is activity for them.+ mentioned := expandMentionedMembers(ctx, queries, e.WorkspaceID, parseMentions(commentContent))+ notifySubscribersRouted(ctx, queries, bus, issueID, issueStatus, e.WorkspaceID, e,nil, "new_comment", "info",issueTitle, commentContent,- commentDetails)+ commentDetails,+ func(memberID string, prefs map[string]string) (string, bool) {+ return inbox.RouteComment(prefs, mentioned.commentAudience(memberID))+ })// Notify @mentions in comment content.- mentions := parseMentions(commentContent)- if len(mentions) > 0 {+ if len(mentioned.ids) > 0 {skip := map[string]bool{e.ActorID: true}- notifyMentionedMembers(bus, queries, e, mentions, issueID, issueTitle, issueStatus,+ notifyMentionedMemberIDs(bus, queries, e, mentioned.ids, issueID, issueStatus,issueTitle, skip, commentDetails)}})@@ -1069,7 +1171,7 @@ func inboxItemToResponse(item db.InboxItem) map[string]any {"recipient_id": util.UUIDToString(item.RecipientID),"type": item.Type,"severity": item.Severity,- "section": inbox.ItemSection(item.Section, item.Type, item.ActorType),+ "section": inbox.ItemSection(item.Section, item.Type),"issue_id": util.UUIDToPtr(item.IssueID),"title": item.Title,"body": util.TextToPtr(item.Body),diff --git a/server/internal/handler/inbox.go b/server/internal/handler/inbox.goindex c201429b43..2ccb852532 100644--- a/server/internal/handler/inbox.go+++ b/server/internal/handler/inbox.go@@ -43,7 +43,7 @@ func inboxToResponse(i db.InboxItem) InboxItemResponse {RecipientID: uuidToString(i.RecipientID),Type: i.Type,Severity: i.Severity,- Section: inbox.ItemSection(i.Section, i.Type, i.ActorType),+ Section: inbox.ItemSection(i.Section, i.Type),IssueID: uuidToPtr(i.IssueID),Title: i.Title,Body: textToPtr(i.Body),@@ -120,7 +120,7 @@ func inboxRowToResponse(r db.ListInboxItemsRow) InboxItemResponse {RecipientID: uuidToString(r.RecipientID),Type: r.Type,Severity: r.Severity,- Section: inbox.ItemSection(r.Section, r.Type, r.ActorType),+ Section: inbox.ItemSection(r.Section, r.Type),IssueID: uuidToPtr(r.IssueID),Title: r.Title,Body: inboxListBody(r.Type, r.IssueID, r.Body),@@ -284,7 +284,7 @@ func (h *Handler) MarkInboxUnread(w http.ResponseWriter, r *http.Request) {// clients from before the Inbox sections offer one) files it under Needs// action: it counts again and archive-all-read leaves it in place.params := db.MarkInboxUnreadParams{ID: prev.ID}- if inbox.ItemSection(prev.Section, prev.Type, prev.ActorType) == inbox.SectionActivity {+ if inbox.ItemSection(prev.Section, prev.Type) == inbox.SectionActivity {params.Section = inbox.SectionText(inbox.SectionAction)}item, err := h.Queries.MarkInboxUnread(r.Context(), params)@@ -319,16 +319,15 @@ func (h *Handler) ArchiveInboxItem(w http.ResponseWriter, r *http.Request) {// Archive the sibling inbox items for the same issue. An action row takes// the whole issue with it; an activity row only clears the issue's other// activity, so an unread mention or failure on it stays in the inbox.- section := inbox.ItemSection(item.Section, item.Type, item.ActorType)+ section := inbox.ItemSection(item.Section, item.Type)if item.IssueID.Valid {if section == inbox.SectionActivity {h.Queries.ArchiveInboxActivityByIssue(r.Context(), db.ArchiveInboxActivityByIssueParams{- WorkspaceID: item.WorkspaceID,- RecipientType: item.RecipientType,- RecipientID: item.RecipientID,- IssueID: item.IssueID,- ActivityTypes: inbox.ActivityTypes,- AgentActivityTypes: inbox.AgentActivityTypes,+ WorkspaceID: item.WorkspaceID,+ RecipientType: item.RecipientType,+ RecipientID: item.RecipientID,+ IssueID: item.IssueID,+ ActivityTypes: inbox.ActivityTypes,})} else {h.Queries.ArchiveInboxByIssue(r.Context(), db.ArchiveInboxByIssueParams{@@ -407,11 +406,10 @@ func (h *Handler) CountUnreadInbox(w http.ResponseWriter, r *http.Request) {}count, err := h.Queries.CountUnreadInbox(r.Context(), db.CountUnreadInboxParams{- WorkspaceID: wsUUID,- RecipientType: "member",- RecipientID: parseUUID(userID),- ActivityTypes: inbox.ActivityTypes,- AgentActivityTypes: inbox.AgentActivityTypes,+ WorkspaceID: wsUUID,+ RecipientType: "member",+ RecipientID: parseUUID(userID),+ ActivityTypes: inbox.ActivityTypes,})if err != nil {writeError(w, http.StatusInternalServerError, "failed to count unread inbox")@@ -441,9 +439,8 @@ func (h *Handler) UnreadInboxSummary(w http.ResponseWriter, r *http.Request) {}rows, err := h.Queries.CountUnreadInboxByWorkspace(r.Context(), db.CountUnreadInboxByWorkspaceParams{- RecipientID: parseUUID(userID),- ActivityTypes: inbox.ActivityTypes,- AgentActivityTypes: inbox.AgentActivityTypes,+ RecipientID: parseUUID(userID),+ ActivityTypes: inbox.ActivityTypes,})if err != nil {writeError(w, http.StatusInternalServerError, "failed to summarize unread inbox")@@ -564,10 +561,9 @@ func (h *Handler) ArchiveAllReadInbox(w http.ResponseWriter, r *http.Request) {}count, err := h.Queries.ArchiveAllReadInbox(r.Context(), db.ArchiveAllReadInboxParams{- WorkspaceID: wsUUID,- RecipientID: parseUUID(userID),- ActivityTypes: inbox.ActivityTypes,- AgentActivityTypes: inbox.AgentActivityTypes,+ WorkspaceID: wsUUID,+ RecipientID: parseUUID(userID),+ ActivityTypes: inbox.ActivityTypes,})if err != nil {writeError(w, http.StatusInternalServerError, "failed to archive all read inbox")diff --git a/server/internal/handler/inbox_archive.go b/server/internal/handler/inbox_archive.goindex 913b4a20bd..43118f0409 100644--- a/server/internal/handler/inbox_archive.go+++ b/server/internal/handler/inbox_archive.go@@ -97,7 +97,7 @@ func (h *Handler) ListArchivedInboxPage(w http.ResponseWriter, r *http.Request)p := db.ListArchivedInboxPageParams{WorkspaceID: filters.WorkspaceID, RecipientID: filters.RecipientID,Statuses: filters.Statuses, Priorities: filters.Priorities, Actors: filters.Actors, UnreadOnly: filters.UnreadOnly,- ActivityTypes: inbox.ActivityTypes, AgentActivityTypes: inbox.AgentActivityTypes,+ ActivityTypes: inbox.ActivityTypes,}limit := 50if raw := r.URL.Query().Get("limit"); raw != "" {@@ -180,7 +180,7 @@ func (h *Handler) GetArchivedInboxFacets(w http.ResponseWriter, r *http.Request)}// Set after parsing, not inside it: the parsed filters also key the page// cursor scope, which must not change when the section rule does.- p.ActivityTypes, p.AgentActivityTypes = inbox.ActivityTypes, inbox.AgentActivityTypes+ p.ActivityTypes = inbox.ActivityTypesrows, err := h.Queries.ArchivedInboxFacets(r.Context(), p)if err != nil {writeError(w, http.StatusInternalServerError, "failed to load archived inbox filters")diff --git a/server/internal/handler/inbox_section_test.go b/server/internal/handler/inbox_section_test.goindex b3eb6b5bb7..ef6445500f 100644--- a/server/internal/handler/inbox_section_test.go+++ b/server/internal/handler/inbox_section_test.go@@ -90,8 +90,12 @@ func TestListInboxReturnsSection(t *testing.T) {issueID := f.issue("Section field")f.item(issueID, "mentioned", "member", "mention", false, "now() - interval '4 minutes'")f.item(issueID, "status_changed", "agent", "agent status", false, "now() - interval '3 minutes'")+ // Rows from before sections store none; a comment among them is action+ // whoever wrote it, since the row does not record whom it @mentioned.f.item(issueID, "new_comment", "agent", "agent comment", false, "now() - interval '2 minutes'")f.item(issueID, "new_comment", "member", "member comment", false, "now() - interval '1 minute'")+ // A comment routed to activity (it @mentioned someone else) keeps that.+ f.routed(issueID, "new_comment", "member", "comment to others", "activity", "now() - interval '30 seconds'")var items []InboxItemResponsetestutil.Call(t, inboxWorkspaceHandler(testHandler.ListInbox),@@ -100,10 +104,11 @@ func TestListInboxReturnsSection(t *testing.T) {JSON(&items)want := map[string]string{- "mention": "action",- "agent status": "activity",- "agent comment": "activity",- "member comment": "action",+ "mention": "action",+ "agent status": "activity",+ "agent comment": "action",+ "member comment": "action",+ "comment to others": "activity",}if len(items) != len(want) {t.Fatalf("items = %d, want %d: %+v", len(items), len(want), items)@@ -120,15 +125,15 @@ func TestUnreadCountsIgnoreActivity(t *testing.T) {// Only routine activity, all stored unread: nothing to count.quietIssue := f.issue("Agent finished")f.item(quietIssue, "status_changed", "agent", "quiet status", false, "now() - interval '3 minutes'")- f.item(quietIssue, "new_comment", "agent", "quiet comment", false, "now() - interval '2 minutes'")+ f.routed(quietIssue, "new_comment", "agent", "quiet comment", "activity", "now() - interval '2 minutes'")// An unread mention followed by newer activity: the activity must neither// count nor decide the group's state.mentionIssue := f.issue("Mentioned")f.item(mentionIssue, "mentioned", "member", "mention", false, "now() - interval '3 minutes'")f.item(mentionIssue, "status_changed", "agent", "later status", true, "now() - interval '1 minute'")- // A person commenting without a mention still wants the recipient.- commentIssue := f.issue("Member comment")- f.item(commentIssue, "new_comment", "member", "member comment", false, "now() - interval '1 minute'")+ // A comment without a stored section is action, whoever wrote it.+ commentIssue := f.issue("Agent comment")+ f.item(commentIssue, "new_comment", "agent", "agent comment", false, "now() - interval '1 minute'")// Read action rows never count.readIssue := f.issue("Already handled")f.item(readIssue, "issue_assigned", "member", "handled", true, "now() - interval '1 minute'")@@ -145,7 +150,7 @@ func TestUnreadCountsIgnoreActivity(t *testing.T) {}}if grouped != 2 {- t.Fatalf("unread summary = %d, want 2 (mention + member comment): %+v", grouped, summary)+ t.Fatalf("unread summary = %d, want 2 (mention + agent comment): %+v", grouped, summary)}var raw struct {@@ -188,7 +193,7 @@ func TestArchiveInboxItemScopesActivityToSection(t *testing.T) {issueID := f.issue("Archive scope")mentionID := f.item(issueID, "mentioned", "member", "mention", false, "now() - interval '3 minutes'")activityID := f.item(issueID, "status_changed", "agent", "status", false, "now() - interval '2 minutes'")- f.item(issueID, "new_comment", "agent", "agent comment", false, "now() - interval '1 minute'")+ f.routed(issueID, "new_comment", "agent", "agent comment", "activity", "now() - interval '1 minute'")testutil.Call(t, inboxWorkspaceHandler(testHandler.ArchiveInboxItem),withURLParam(inboxRequest(http.MethodPost, "/api/inbox/"+activityID+"/archive", f.workspaceID), "id", activityID)).diff --git a/server/internal/handler/notification_preference_test.go b/server/internal/handler/notification_preference_test.goindex a71adf1d65..f2f0587f85 100644--- a/server/internal/handler/notification_preference_test.go+++ b/server/internal/handler/notification_preference_test.go@@ -198,11 +198,12 @@ func TestPatchNotificationPreferencesRoutes(t *testing.T) {testHandler.PatchNotificationPreferences(recorder,notificationPreferenceRequest(t, http.MethodPatch, map[string]string{- "status_changes": "action",- "mentions": "activity",- "agent_comments": "muted",- "assigned": "all",- "comments": "muted",+ "status_changes": "action",+ "mentions": "activity",+ "comments_mentioning_others": "muted",+ "comments_without_mentions": "activity",+ "assigned": "all",+ "comments": "muted",}),)if recorder.Code != http.StatusOK {@@ -216,10 +217,11 @@ func TestPatchNotificationPreferencesRoutes(t *testing.T) {t.Fatalf("decode response: %v", err)}want := map[string]string{- "status_changes": "action",- "mentions": "activity",- "agent_comments": "muted",- "comments": "muted",+ "status_changes": "action",+ "mentions": "activity",+ "comments_mentioning_others": "muted",+ "comments_without_mentions": "activity",+ "comments": "muted",}for key, value := range want {if response.Preferences[key] != value {@@ -231,6 +233,9 @@ func TestPatchNotificationPreferencesRoutes(t *testing.T) {{"status_changes": "loud"},{"comments": "action"},{"system_notifications": "activity"},+ // The author-based comment keys were replaced by audience-based ones.+ {"member_comments": "action"},+ {"agent_comments": "muted"},} {recorder := httptest.NewRecorder()testHandler.PatchNotificationPreferences(recorder,diff --git a/server/internal/inbox/routing.go b/server/internal/inbox/routing.goindex 01fce1d011..b26ff425af 100644--- a/server/internal/inbox/routing.go+++ b/server/internal/inbox/routing.go@@ -1,7 +1,5 @@package inbox-import "github.com/jackc/pgx/v5/pgtype"-// Recipients choose, per kind of notification, whether it lands in "action",// in "activity", or nowhere ("muted"). The choice lives in the recipient's// notification preferences under the kind's key.@@ -19,6 +17,13 @@ const (RouteDefault = "all")+// Preference keys of the routable kinds a comment can fall under.+const (+ RouteKeyMentions = "mentions"+ RouteKeyCommentsWithoutMentions = "comments_without_mentions"+ RouteKeyCommentsMentioningOthers = "comments_mentioning_others"+)+type routeKind struct {Key stringDefault string@@ -30,13 +35,13 @@ type routeKind struct {// RouteKinds lists the routable kinds in the order settings render them.var RouteKinds = []routeKind{{Key: "assigned", Default: SectionAction, Legacy: "assignments"},- {Key: "mentions", Default: SectionAction},- {Key: "member_comments", Default: SectionAction, Legacy: "comments"},+ {Key: RouteKeyMentions, Default: SectionAction},+ {Key: RouteKeyCommentsWithoutMentions, Default: SectionAction, Legacy: "comments"},{Key: "agent_failures", Default: SectionAction, Legacy: "agent_activity"},{Key: "status_changes", Default: SectionActivity},{Key: "assignee_changes", Default: SectionActivity, Legacy: "assignments"},{Key: "updates", Default: SectionActivity},- {Key: "agent_comments", Default: SectionActivity, Legacy: "comments"},+ {Key: RouteKeyCommentsMentioningOthers, Default: SectionActivity, Legacy: "comments"},}var routeKindByKey = func() map[string]routeKind {@@ -47,21 +52,43 @@ var routeKindByKey = func() map[string]routeKind {return m}()+// commentToRecipientKind routes a comment that @mentions the recipient. It+// follows the recipient's mentions choice, since the same comment also sends+// them a "mentioned" notification and the two should land together. Unlike+// the "mentioned" kind it keeps the legacy comments mute: before routing, a+// recipient who muted comments got only the mention for such a comment.+var commentToRecipientKind = routeKind{Key: RouteKeyMentions, Default: SectionAction, Legacy: "comments"}++// CommentAudience is who a comment is written to, as one recipient sees it.+// Only people count as an audience: @member, @agent, @squad and @all. Issue+// and project links do not.+type CommentAudience int++const (+ // CommentToNobody: the comment @mentions nobody. It is usually a reply+ // to whoever is following the conversation, so it waits on them.+ CommentToNobody CommentAudience = iota+ // CommentToRecipient: the comment @mentions the recipient, directly,+ // through a squad they belong to, or through @all. This wins when the+ // comment also @mentions others.+ CommentToRecipient+ // CommentToOthers: the comment @mentions someone, and not the recipient.+ CommentToOthers+)+// RouteKindKey names the routable kind of a notification, or "" when the type// is not routable (review requests, quick-create and autopilot results,-// reactions...) and always lands in its default section.-func RouteKindKey(notifType string, actorType pgtype.Text) string {- agent := actorType.Valid && actorType.String == "agent"+// reactions...) and always lands in its default section. A new_comment routed+// without an audience is treated as written to nobody; RouteComment is the+// audience-aware entry point.+func RouteKindKey(notifType string) string {switch notifType {case "issue_assigned":return "assigned"case "mentioned":- return "mentions"+ return RouteKeyMentionscase "new_comment":- if agent {- return "agent_comments"- }- return "member_comments"+ return RouteKeyCommentsWithoutMentionscase "task_failed", "agent_blocked":return "agent_failures"case "status_changed":@@ -76,11 +103,30 @@ func RouteKindKey(notifType string, actorType pgtype.Text) string {// Route resolves where a notification goes for a recipient with these// preferences. ok is false when the recipient muted it.-func Route(prefs map[string]string, notifType string, actorType pgtype.Text) (section string, ok bool) {- kind, routable := routeKindByKey[RouteKindKey(notifType, actorType)]+func Route(prefs map[string]string, notifType string) (section string, ok bool) {+ kind, routable := routeKindByKey[RouteKindKey(notifType)]if !routable {- return DefaultSection(notifType, actorType), true+ return DefaultSection(notifType), true}+ return routeTo(prefs, kind)+}++// RouteComment resolves where a new_comment goes for a recipient, given who+// the comment is written to. Who wrote it does not matter: a person's comment+// and an agent's reply are routed the same way. ok is false when the+// recipient muted it.+func RouteComment(prefs map[string]string, audience CommentAudience) (section string, ok bool) {+ switch audience {+ case CommentToRecipient:+ return routeTo(prefs, commentToRecipientKind)+ case CommentToOthers:+ return routeTo(prefs, routeKindByKey[RouteKeyCommentsMentioningOthers])+ default:+ return routeTo(prefs, routeKindByKey[RouteKeyCommentsWithoutMentions])+ }+}++func routeTo(prefs map[string]string, kind routeKind) (section string, ok bool) {switch prefs[kind.Key] {case RouteAction:return SectionAction, truediff --git a/server/internal/inbox/routing_test.go b/server/internal/inbox/routing_test.goindex 6e2119ee7f..863e51615a 100644--- a/server/internal/inbox/routing_test.go+++ b/server/internal/inbox/routing_test.go@@ -7,79 +7,135 @@ import ()func TestRoute(t *testing.T) {- agent := pgtype.Text{String: "agent", Valid: true}- member := pgtype.Text{String: "member", Valid: true}muted := ""cases := []struct {name stringprefs map[string]stringnotifType string- actor pgtype.Textwant string // muted means not delivered}{// Defaults match DefaultSection, so an untouched account sees no change.- {"default assigned", nil, "issue_assigned", member, SectionAction},- {"default mention", nil, "mentioned", agent, SectionAction},- {"default member comment", nil, "new_comment", member, SectionAction},- {"default agent comment", nil, "new_comment", agent, SectionActivity},- {"default agent failure", nil, "task_failed", agent, SectionAction},- {"default status", nil, "status_changed", member, SectionActivity},- {"default assignee change", nil, "unassigned", member, SectionActivity},- {"default update", nil, "due_date_changed", member, SectionActivity},- {"explicit all is the default", map[string]string{"status_changes": "all"}, "status_changed", agent, SectionActivity},+ {"default assigned", nil, "issue_assigned", SectionAction},+ {"default mention", nil, "mentioned", SectionAction},+ {"default comment without audience", nil, "new_comment", SectionAction},+ {"default agent failure", nil, "task_failed", SectionAction},+ {"default status", nil, "status_changed", SectionActivity},+ {"default assignee change", nil, "unassigned", SectionActivity},+ {"default update", nil, "due_date_changed", SectionActivity},+ {"explicit all is the default", map[string]string{"status_changes": "all"}, "status_changed", SectionActivity},// The recipient's choice wins.- {"status routed to action", map[string]string{"status_changes": "action"}, "status_changed", agent, SectionAction},- {"agent comments routed to action", map[string]string{"agent_comments": "action"}, "new_comment", agent, SectionAction},- {"mentions routed to activity", map[string]string{"mentions": "activity"}, "mentioned", member, SectionActivity},- {"updates muted", map[string]string{"updates": "muted"}, "priority_changed", member, muted},- {"agent comment choice leaves member comments alone", map[string]string{"agent_comments": "muted"}, "new_comment", member, SectionAction},+ {"status routed to action", map[string]string{"status_changes": "action"}, "status_changed", SectionAction},+ {"mentions routed to activity", map[string]string{"mentions": "activity"}, "mentioned", SectionActivity},+ {"updates muted", map[string]string{"updates": "muted"}, "priority_changed", muted},// Muting comment volume never silences someone asking for you by name.- {"muted comments still delivers mentions", map[string]string{"comments": "muted"}, "mentioned", member, SectionAction},- {"muted mentions drops mentioned", map[string]string{"mentions": "muted"}, "mentioned", member, muted},- {"muted mentions still delivers new_comment", map[string]string{"mentions": "muted"}, "new_comment", member, SectionAction},+ {"muted comments still delivers mentions", map[string]string{"comments": "muted"}, "mentioned", SectionAction},+ {"muted mentions drops mentioned", map[string]string{"mentions": "muted"}, "mentioned", muted},+ {"muted mentions still delivers new_comment", map[string]string{"mentions": "muted"}, "new_comment", SectionAction},// A muted pre-routing group mutes both halves until the new key is set.- {"legacy comments muted drops member comment", map[string]string{"comments": "muted"}, "new_comment", member, muted},- {"legacy comments muted drops agent comment", map[string]string{"comments": "muted"}, "new_comment", agent, muted},- {"legacy assignments muted drops assigned", map[string]string{"assignments": "muted"}, "issue_assigned", member, muted},- {"legacy assignments muted drops unassigned", map[string]string{"assignments": "muted"}, "unassigned", member, muted},- {"legacy agent_activity muted drops failure", map[string]string{"agent_activity": "muted"}, "task_failed", agent, muted},- {"new key overrides muted legacy group", map[string]string{"comments": "muted", "agent_comments": "activity"}, "new_comment", agent, SectionActivity},- {"muting comments leaves assignments alone", map[string]string{"comments": "muted"}, "issue_assigned", member, SectionAction},+ {"legacy comments muted drops comment", map[string]string{"comments": "muted"}, "new_comment", muted},+ {"legacy assignments muted drops assigned", map[string]string{"assignments": "muted"}, "issue_assigned", muted},+ {"legacy assignments muted drops unassigned", map[string]string{"assignments": "muted"}, "unassigned", muted},+ {"legacy agent_activity muted drops failure", map[string]string{"agent_activity": "muted"}, "task_failed", muted},+ {"muting comments leaves assignments alone", map[string]string{"comments": "muted"}, "issue_assigned", SectionAction},// Types outside the routable kinds always land in their default section.- {"unroutable reaction", map[string]string{"comments": "muted"}, "reaction_added", member, SectionActivity},- {"unroutable review request", map[string]string{"assigned": "muted"}, "review_requested", member, SectionAction},- {"unknown value falls back to default", map[string]string{"status_changes": "loud"}, "status_changed", member, SectionActivity},+ {"unroutable reaction", map[string]string{"comments": "muted"}, "reaction_added", SectionActivity},+ {"unroutable review request", map[string]string{"assigned": "muted"}, "review_requested", SectionAction},+ {"unknown value falls back to default", map[string]string{"status_changes": "loud"}, "status_changed", SectionActivity},}for _, c := range cases {t.Run(c.name, func(t *testing.T) {- got, ok := Route(c.prefs, c.notifType, c.actor)- if c.want == muted {- if ok {- t.Fatalf("Route = (%q, delivered), want muted", got)- }- return- }- if !ok || got != c.want {- t.Fatalf("Route = (%q, %v), want (%q, delivered)", got, ok, c.want)- }+ assertRoute(t, c.want, muted)(Route(c.prefs, c.notifType))})}}+func TestRouteComment(t *testing.T) {+ muted := ""++ cases := []struct {+ name string+ prefs map[string]string+ audience CommentAudience+ want string // muted means not delivered+ }{+ // Defaults: only a comment written to someone else is activity.+ {"default to nobody", nil, CommentToNobody, SectionAction},+ {"default to recipient", nil, CommentToRecipient, SectionAction},+ {"default to others", nil, CommentToOthers, SectionActivity},++ // Each audience follows its own key.+ {"to nobody routed to activity", map[string]string{"comments_without_mentions": "activity"}, CommentToNobody, SectionActivity},+ {"to others routed to action", map[string]string{"comments_mentioning_others": "action"}, CommentToOthers, SectionAction},+ {"to others muted", map[string]string{"comments_mentioning_others": "muted"}, CommentToOthers, muted},+ {"to others choice leaves to nobody alone", map[string]string{"comments_mentioning_others": "muted"}, CommentToNobody, SectionAction},+ {"to nobody choice leaves to others alone", map[string]string{"comments_without_mentions": "muted"}, CommentToOthers, SectionActivity},++ // A comment that @mentions the recipient follows the mentions choice,+ // so it lands with the "mentioned" notification it also sends.+ {"to recipient follows mentions", map[string]string{"mentions": "activity"}, CommentToRecipient, SectionActivity},+ {"to recipient muted with mentions", map[string]string{"mentions": "muted"}, CommentToRecipient, muted},+ {"to recipient ignores comment keys", map[string]string{"comments_without_mentions": "muted", "comments_mentioning_others": "muted"}, CommentToRecipient, SectionAction},++ // A muted pre-routing comments group still mutes every comment until+ // the recipient sets the new key.+ {"legacy comments muted drops to nobody", map[string]string{"comments": "muted"}, CommentToNobody, muted},+ {"legacy comments muted drops to others", map[string]string{"comments": "muted"}, CommentToOthers, muted},+ {"legacy comments muted drops to recipient", map[string]string{"comments": "muted"}, CommentToRecipient, muted},+ {"new key overrides muted legacy group", map[string]string{"comments": "muted", "comments_mentioning_others": "activity"}, CommentToOthers, SectionActivity},+ {"mentions key overrides muted legacy group", map[string]string{"comments": "muted", "mentions": "action"}, CommentToRecipient, SectionAction},+ }+ for _, c := range cases {+ t.Run(c.name, func(t *testing.T) {+ assertRoute(t, c.want, muted)(RouteComment(c.prefs, c.audience))+ })+ }+}++func assertRoute(t *testing.T, want, muted string) func(string, bool) {+ t.Helper()+ return func(got string, ok bool) {+ t.Helper()+ if want == muted {+ if ok {+ t.Fatalf("route = (%q, delivered), want muted", got)+ }+ return+ }+ if !ok || got != want {+ t.Fatalf("route = (%q, %v), want (%q, delivered)", got, ok, want)+ }+ }+}++func TestRouteKeysAreRouteKinds(t *testing.T) {+ for _, key := range []string{RouteKeyMentions, RouteKeyCommentsWithoutMentions, RouteKeyCommentsMentioningOthers} {+ if !IsRouteKey(key) {+ t.Errorf("%q is not a route kind", key)+ }+ }+ for _, retired := range []string{"member_comments", "agent_comments"} {+ if IsRouteKey(retired) {+ t.Errorf("%q should no longer be a route kind", retired)+ }+ }+}+func TestItemSection(t *testing.T) {- agent := pgtype.Text{String: "agent", Valid: true}- if got := ItemSection(SectionText(SectionAction), "status_changed", agent); got != SectionAction {+ if got := ItemSection(SectionText(SectionAction), "status_changed"); got != SectionAction {t.Errorf("stored action = %q", got)}- if got := ItemSection(pgtype.Text{}, "status_changed", agent); got != SectionActivity {+ if got := ItemSection(SectionText(SectionActivity), "new_comment"); got != SectionActivity {+ t.Errorf("stored activity = %q", got)+ }+ if got := ItemSection(pgtype.Text{}, "status_changed"); got != SectionActivity {t.Errorf("unset falls back to default, got %q", got)}- if got := ItemSection(SectionText("bogus"), "mentioned", agent); got != SectionAction {+ if got := ItemSection(SectionText("bogus"), "mentioned"); got != SectionAction {t.Errorf("unknown stored value falls back to default, got %q", got)}}diff --git a/server/internal/inbox/section.go b/server/internal/inbox/section.goindex 21bbe55e98..8fa85e9fa6 100644--- a/server/internal/inbox/section.go+++ b/server/internal/inbox/section.go@@ -3,11 +3,11 @@ package inboximport "github.com/jackc/pgx/v5/pgtype"// Every notification belongs to one of two Inbox sections. "action" is what-// waits on the recipient — an assignment, a mention, a failed run, a person-// talking on their issue — and is the only section that counts as unread.-// "activity" is routine progress the Work sidebar already tracks live (status-// moves, agent replies, property edits); it stays listable but never raises-// the unread badge.+// waits on the recipient — an assignment, a mention, a failed run, a comment+// written to them or to nobody in particular — and is the only section that+// counts as unread. "activity" is routine progress the Work sidebar already+// tracks live (status moves, property edits) and comments written to someone+// else; it stays listable but never raises the unread badge.//// A row written since recipients could route notifications (see Route)// stores its section. Older rows store none and classify by DefaultSection,@@ -20,6 +20,10 @@ const (// ActivityTypes are activity by default, whoever caused them. task_completed,// agent_completed and issue_subscribed are no longer written but may exist in// older rows.+//+// new_comment is not here: whether a comment is activity depends on who it+// @mentions (see RouteComment), which a row without a stored section does not+// record, so such rows stay action.var ActivityTypes = []string{"status_changed","priority_changed",@@ -34,47 +38,32 @@ var ActivityTypes = []string{"issue_subscribed",}-// AgentActivityTypes are activity by default when an agent caused them and-// action when a person did: an agent's reply is the run's result, which the-// sidebar already shows; a person commenting on your issue usually wants you.-var AgentActivityTypes = []string{- "new_comment",-}--var (- activityTypeSet = toSet(ActivityTypes)- agentActivityTypeSet = toSet(AgentActivityTypes)-)--func toSet(values []string) map[string]bool {- set := make(map[string]bool, len(values))- for _, v := range values {+var activityTypeSet = func() map[string]bool {+ set := make(map[string]bool, len(ActivityTypes))+ for _, v := range ActivityTypes {set[v] = true}return set-}+}()// DefaultSection classifies a notification nobody routed. Unknown types are// action, so a new kind is never hidden from the unread count by default. The// SQL predicates apply the same rule to rows without a stored section through-// ActivityTypes and AgentActivityTypes; keep the two in step.-func DefaultSection(notifType string, actorType pgtype.Text) string {+// ActivityTypes; keep the two in step.+func DefaultSection(notifType string) string {if activityTypeSet[notifType] {return SectionActivity}- if agentActivityTypeSet[notifType] && actorType.Valid && actorType.String == "agent" {- return SectionActivity- }return SectionAction}// ItemSection is the section of a stored row: the one it was routed to, or the// default for rows written before routing existed.-func ItemSection(stored pgtype.Text, notifType string, actorType pgtype.Text) string {+func ItemSection(stored pgtype.Text, notifType string) string {if stored.Valid && (stored.String == SectionAction || stored.String == SectionActivity) {return stored.String}- return DefaultSection(notifType, actorType)+ return DefaultSection(notifType)}// SectionText is the value written to inbox_item.section.diff --git a/server/internal/inbox/section_test.go b/server/internal/inbox/section_test.goindex f6924c3943..c562693e92 100644--- a/server/internal/inbox/section_test.go+++ b/server/internal/inbox/section_test.go@@ -1,42 +1,32 @@package inbox-import (- "testing"-- "github.com/jackc/pgx/v5/pgtype"-)+import "testing"func TestDefaultSection(t *testing.T) {- agent := pgtype.Text{String: "agent", Valid: true}- member := pgtype.Text{String: "member", Valid: true}- none := pgtype.Text{}-cases := []struct {notifType string- actor pgtype.Textwant string}{- {"issue_assigned", member, SectionAction},- {"mentioned", agent, SectionAction},- {"task_failed", none, SectionAction},- {"children_done", none, SectionAction},- {"quick_create_failed", agent, SectionAction},- {"autopilot_paused", none, SectionAction},- {"new_comment", member, SectionAction},- {"new_comment", none, SectionAction},- {"new_comment", agent, SectionActivity},- {"status_changed", agent, SectionActivity},- {"status_changed", member, SectionActivity},- {"priority_changed", member, SectionActivity},- {"assignee_changed", agent, SectionActivity},- {"reaction_added", member, SectionActivity},- {"quick_create_done", agent, SectionActivity},- {"task_completed", agent, SectionActivity},- {"some_future_type", agent, SectionAction},+ {"issue_assigned", SectionAction},+ {"mentioned", SectionAction},+ {"task_failed", SectionAction},+ {"children_done", SectionAction},+ {"quick_create_failed", SectionAction},+ {"autopilot_paused", SectionAction},+ // A row without a stored section does not record who the comment+ // @mentioned, so it stays action whoever wrote it.+ {"new_comment", SectionAction},+ {"status_changed", SectionActivity},+ {"priority_changed", SectionActivity},+ {"assignee_changed", SectionActivity},+ {"reaction_added", SectionActivity},+ {"quick_create_done", SectionActivity},+ {"task_completed", SectionActivity},+ {"some_future_type", SectionAction},}for _, c := range cases {- if got := DefaultSection(c.notifType, c.actor); got != c.want {- t.Errorf("DefaultSection(%q, %q) = %q, want %q", c.notifType, c.actor.String, got, c.want)+ if got := DefaultSection(c.notifType); got != c.want {+ t.Errorf("DefaultSection(%q) = %q, want %q", c.notifType, got, c.want)}}}diff --git a/server/internal/service/autopilot.go b/server/internal/service/autopilot.goindex 3a648929fd..412f40dab3 100644--- a/server/internal/service/autopilot.go+++ b/server/internal/service/autopilot.go@@ -944,7 +944,7 @@ func (s *AutopilotService) notifyAutopilotSubscribersOnCreate("recipient_id": util.UUIDToString(item.RecipientID),"type": item.Type,"severity": item.Severity,- "section": inbox.ItemSection(item.Section, item.Type, item.ActorType),+ "section": inbox.ItemSection(item.Section, item.Type),"issue_id": util.UUIDToPtr(item.IssueID),"issue_status": issue.Status,"title": item.Title,diff --git a/server/internal/service/autopilot_quota_notifications.go b/server/internal/service/autopilot_quota_notifications.goindex 6c30a69e08..6eea1c25ba 100644--- a/server/internal/service/autopilot_quota_notifications.go+++ b/server/internal/service/autopilot_quota_notifications.go@@ -189,7 +189,7 @@ func (s *AutopilotService) publishAutopilotQuotaInboxItems(items []db.InboxItem)Payload: map[string]any{"item": map[string]any{"id": util.UUIDToString(item.ID), "workspace_id": util.UUIDToString(item.WorkspaceID),"recipient_type": item.RecipientType, "recipient_id": util.UUIDToString(item.RecipientID),- "type": item.Type, "severity": item.Severity, "section": inbox.ItemSection(item.Section, item.Type, item.ActorType), "issue_id": nil,+ "type": item.Type, "severity": item.Severity, "section": inbox.ItemSection(item.Section, item.Type), "issue_id": nil,"issue_status": nil, "issue_priority": nil,"title": item.Title, "body": util.TextToPtr(item.Body), "read": item.Read,"archived": item.Archived, "created_at": util.TimestampToString(item.CreatedAt),diff --git a/server/internal/service/delegated_failure_recovery_routing_test.go b/server/internal/service/delegated_failure_recovery_routing_test.goindex a5c423b786..eaec60505e 100644--- a/server/internal/service/delegated_failure_recovery_routing_test.go+++ b/server/internal/service/delegated_failure_recovery_routing_test.go@@ -68,8 +68,8 @@ func TestRecoveryExhaustionHonorsAgentFailureRoute(t *testing.T) {if route == "muted" {t.Errorf("agent_failures=muted still creates task_failed notification")}- if route == "activity" && inbox.ItemSection(item.Section, item.Type, item.ActorType) != "activity" {- t.Errorf("agent_failures=activity produced section %q", inbox.ItemSection(item.Section, item.Type, item.ActorType))+ if route == "activity" && inbox.ItemSection(item.Section, item.Type) != "activity" {+ t.Errorf("agent_failures=activity produced section %q", inbox.ItemSection(item.Section, item.Type))}}if route == "activity" && failures != 1 {diff --git a/server/internal/service/issue_wakeup_system.go b/server/internal/service/issue_wakeup_system.goindex 1a6f3927a8..99b1d2cb2d 100644--- a/server/internal/service/issue_wakeup_system.go+++ b/server/internal/service/issue_wakeup_system.go@@ -700,7 +700,7 @@ func (s *IssueWakeupService) publishSystemInbox(item db.InboxItem, issueStatus sPayload: map[string]any{"item": map[string]any{"id": util.UUIDToString(item.ID), "workspace_id": util.UUIDToString(item.WorkspaceID),"recipient_type": item.RecipientType, "recipient_id": util.UUIDToString(item.RecipientID),- "type": item.Type, "severity": item.Severity, "section": inboxwriter.ItemSection(item.Section, item.Type, item.ActorType), "issue_id": util.UUIDToPtr(item.IssueID),+ "type": item.Type, "severity": item.Severity, "section": inboxwriter.ItemSection(item.Section, item.Type), "issue_id": util.UUIDToPtr(item.IssueID),"title": item.Title, "body": util.TextToPtr(item.Body), "read": item.Read, "archived": item.Archived,"created_at": util.TimestampToString(item.CreatedAt), "actor_type": util.TextToPtr(item.ActorType),"actor_id": util.UUIDToPtr(item.ActorID), "details": json.RawMessage(item.Details), "issue_status": issueStatus,diff --git a/server/internal/service/task.go b/server/internal/service/task.goindex 602019d2e7..8606db9536 100644--- a/server/internal/service/task.go+++ b/server/internal/service/task.go@@ -6767,7 +6767,7 @@ func (s *TaskService) exhaustDelegatedFailureRecovery(ctx context.Context, targereturn fmt.Errorf("load delegated failure exhaustion recipient preferences: %w", err)}actorType := pgtype.Text{String: "system", Valid: true}- section, routed := inbox.Route(prefs, "task_failed", actorType)+ section, routed := inbox.Route(prefs, "task_failed")if !routed {return nil}@@ -6831,7 +6831,7 @@ func (s *TaskService) exhaustDelegatedFailureRecovery(ctx context.Context, targe"recipient_id": util.UUIDToString(exhaustedInbox.RecipientID),"type": exhaustedInbox.Type,"severity": exhaustedInbox.Severity,- "section": inbox.ItemSection(exhaustedInbox.Section, exhaustedInbox.Type, exhaustedInbox.ActorType),+ "section": inbox.ItemSection(exhaustedInbox.Section, exhaustedInbox.Type),"issue_id": util.UUIDToPtr(exhaustedInbox.IssueID),"title": exhaustedInbox.Title,"body": util.TextToPtr(exhaustedInbox.Body),@@ -8378,7 +8378,7 @@ func (s *TaskService) publishQuickCreateInbox(item db.InboxItem, workspaceID, ag"recipient_id": util.UUIDToString(item.RecipientID),"type": item.Type,"severity": item.Severity,- "section": inbox.ItemSection(item.Section, item.Type, item.ActorType),+ "section": inbox.ItemSection(item.Section, item.Type),"issue_id": util.UUIDToPtr(item.IssueID),"title": item.Title,"body": util.TextToPtr(item.Body),diff --git a/server/pkg/db/generated/inbox.sql.go b/server/pkg/db/generated/inbox.sql.goindex 2c601bf0ab..f4794efc50 100644--- a/server/pkg/db/generated/inbox.sql.go+++ b/server/pkg/db/generated/inbox.sql.go@@ -35,12 +35,11 @@ WITH active AS (COALESCE(i.issue_id, i.id) AS group_id,i.created_at,i.read,- COALESCE(i.section = 'activity', i.type = ANY($1::text[])- OR (COALESCE(i.actor_type, '') = 'agent' AND i.type = ANY($2::text[]))) AS is_activity+ COALESCE(i.section = 'activity', i.type = ANY($1::text[])) AS is_activityFROM inbox_item i- WHERE i.workspace_id = $3+ WHERE i.workspace_id = $2AND i.recipient_type = 'member'- AND i.recipient_id = $4+ AND i.recipient_id = $3AND i.archived = false), newest_groups AS (SELECT DISTINCT ON (group_id, is_activity)@@ -61,10 +60,9 @@ WHERE i.id = a.id`type ArchiveAllReadInboxParams struct {- ActivityTypes []string `json:"activity_types"`- AgentActivityTypes []string `json:"agent_activity_types"`- WorkspaceID pgtype.UUID `json:"workspace_id"`- RecipientID pgtype.UUID `json:"recipient_id"`+ ActivityTypes []string `json:"activity_types"`+ WorkspaceID pgtype.UUID `json:"workspace_id"`+ RecipientID pgtype.UUID `json:"recipient_id"`}// "Read" is the state of the one row the inbox renders per issue and section:@@ -75,12 +73,7 @@ type ArchiveAllReadInboxParams struct {// reappear after the newest row is archived (and can archive an older read// sibling under an unread row).func (q *Queries) ArchiveAllReadInbox(ctx context.Context, arg ArchiveAllReadInboxParams) (int64, error) {- result, err := q.db.Exec(ctx, archiveAllReadInbox,- arg.ActivityTypes,- arg.AgentActivityTypes,- arg.WorkspaceID,- arg.RecipientID,- )+ result, err := q.db.Exec(ctx, archiveAllReadInbox, arg.ActivityTypes, arg.WorkspaceID, arg.RecipientID)if err != nil {return 0, err}@@ -118,24 +111,22 @@ WHERE i.workspace_id = $1AND i.recipient_id = $3AND i.issue_id = $4AND i.archived = false- AND COALESCE(i.section = 'activity', i.type = ANY($5::text[])- OR (COALESCE(i.actor_type, '') = 'agent' AND i.type = ANY($6::text[])))+ AND COALESCE(i.section = 'activity', i.type = ANY($5::text[]))`type ArchiveInboxActivityByIssueParams struct {- WorkspaceID pgtype.UUID `json:"workspace_id"`- RecipientType string `json:"recipient_type"`- RecipientID pgtype.UUID `json:"recipient_id"`- IssueID pgtype.UUID `json:"issue_id"`- ActivityTypes []string `json:"activity_types"`- AgentActivityTypes []string `json:"agent_activity_types"`+ WorkspaceID pgtype.UUID `json:"workspace_id"`+ RecipientType string `json:"recipient_type"`+ RecipientID pgtype.UUID `json:"recipient_id"`+ IssueID pgtype.UUID `json:"issue_id"`+ ActivityTypes []string `json:"activity_types"`}// Section-scoped counterpart of ArchiveInboxByIssue, used when the archived row// is activity: clearing routine progress must not take an unread action item// on the same issue (a mention, a failed run) with it. The activity predicate// mirrors inbox.ItemSection: a stored section wins, otherwise the type rule-// the caller passes as inbox.ActivityTypes and inbox.AgentActivityTypes.+// the caller passes as inbox.ActivityTypes.func (q *Queries) ArchiveInboxActivityByIssue(ctx context.Context, arg ArchiveInboxActivityByIssueParams) (int64, error) {result, err := q.db.Exec(ctx, archiveInboxActivityByIssue,arg.WorkspaceID,@@ -143,7 +134,6 @@ func (q *Queries) ArchiveInboxActivityByIssue(ctx context.Context, arg ArchiveInarg.RecipientID,arg.IssueID,arg.ActivityTypes,- arg.AgentActivityTypes,)if err != nil {return 0, err@@ -250,16 +240,14 @@ WHERE i.workspace_id = $1AND i.recipient_id = $3AND i.read = falseAND i.archived = false- AND NOT COALESCE(i.section = 'activity', i.type = ANY($4::text[])- OR (COALESCE(i.actor_type, '') = 'agent' AND i.type = ANY($5::text[])))+ AND NOT COALESCE(i.section = 'activity', i.type = ANY($4::text[]))`type CountUnreadInboxParams struct {- WorkspaceID pgtype.UUID `json:"workspace_id"`- RecipientType string `json:"recipient_type"`- RecipientID pgtype.UUID `json:"recipient_id"`- ActivityTypes []string `json:"activity_types"`- AgentActivityTypes []string `json:"agent_activity_types"`+ WorkspaceID pgtype.UUID `json:"workspace_id"`+ RecipientType string `json:"recipient_type"`+ RecipientID pgtype.UUID `json:"recipient_id"`+ ActivityTypes []string `json:"activity_types"`}// Activity rows never count as unread, whatever their stored `read` flag; see@@ -270,7 +258,6 @@ func (q *Queries) CountUnreadInbox(ctx context.Context, arg CountUnreadInboxParaarg.RecipientType,arg.RecipientID,arg.ActivityTypes,- arg.AgentActivityTypes,)var count int64err := row.Scan(&count)@@ -287,8 +274,7 @@ FROM (WHERE i.recipient_type = 'member'AND i.recipient_id = $1AND i.archived = false- AND NOT COALESCE(i.section = 'activity', i.type = ANY($2::text[])- OR (COALESCE(i.actor_type, '') = 'agent' AND i.type = ANY($3::text[])))+ AND NOT COALESCE(i.section = 'activity', i.type = ANY($2::text[]))ORDER BY i.workspace_id, COALESCE(i.issue_id, i.id), i.created_at DESC) newestWHERE newest.read = false@@ -296,9 +282,8 @@ GROUP BY newest.workspace_id`type CountUnreadInboxByWorkspaceParams struct {- RecipientID pgtype.UUID `json:"recipient_id"`- ActivityTypes []string `json:"activity_types"`- AgentActivityTypes []string `json:"agent_activity_types"`+ RecipientID pgtype.UUID `json:"recipient_id"`+ ActivityTypes []string `json:"activity_types"`}type CountUnreadInboxByWorkspaceRow struct {@@ -321,7 +306,7 @@ type CountUnreadInboxByWorkspaceRow struct {// not decide a group's state either, so a routine status change landing after// an unread mention leaves the mention counted.func (q *Queries) CountUnreadInboxByWorkspace(ctx context.Context, arg CountUnreadInboxByWorkspaceParams) ([]CountUnreadInboxByWorkspaceRow, error) {- rows, err := q.db.Query(ctx, countUnreadInboxByWorkspace, arg.RecipientID, arg.ActivityTypes, arg.AgentActivityTypes)+ rows, err := q.db.Query(ctx, countUnreadInboxByWorkspace, arg.RecipientID, arg.ActivityTypes)if err != nil {return nil, err}diff --git a/server/pkg/db/generated/inbox_archive.sql.go b/server/pkg/db/generated/inbox_archive.sql.goindex 4850a8b784..e964a49ff6 100644--- a/server/pkg/db/generated/inbox_archive.sql.go+++ b/server/pkg/db/generated/inbox_archive.sql.go@@ -16,15 +16,14 @@ WITH newest AS MATERIALIZED (SELECT DISTINCT ON (COALESCE(i.issue_id, i.id))i.id, i.issue_id, i.created_at,-- Activity is never unread (inbox.Section); the caller passes- -- inbox.ActivityTypes and inbox.AgentActivityTypes.- (i.read OR COALESCE(i.section = 'activity', i.type = ANY($1::text[])- OR (COALESCE(i.actor_type, '') = 'agent' AND i.type = ANY($2::text[])))) AS read,+ -- inbox.ActivityTypes.+ (i.read OR COALESCE(i.section = 'activity', i.type = ANY($1::text[]))) AS read,CASE WHEN i.actor_type = 'system' THEN 'system'ELSE i.actor_type || ':' || i.actor_id::text END AS actorFROM inbox_item i- WHERE i.workspace_id = $3::uuid+ WHERE i.workspace_id = $2::uuidAND i.recipient_type = 'member'- AND i.recipient_id = $4::uuid+ AND i.recipient_id = $3::uuidAND i.archived = trueAND (i.issue_id IS NULL OR NOT EXISTS (SELECT 1 FROM inbox_item active@@ -38,13 +37,13 @@ WITH newest AS MATERIALIZED (SELECT newest.id, newest.issue_id, newest.created_at, newest.read, newest.actor, iss.status AS issue_status, iss.priority AS issue_priorityFROM newestLEFT JOIN issue iss ON iss.id = newest.issue_id- AND iss.workspace_id = $3::uuid+ AND iss.workspace_id = $2::uuid), matched AS (SELECT projected.id, projected.issue_id, projected.created_at, projected.read, projected.actor, projected.issue_status, projected.issue_priority,- (cardinality($5::text[]) = 0 OR issue_status = ANY($5::text[])) AS status_match,- (cardinality($6::text[]) = 0 OR issue_priority = ANY($6::text[])) AS priority_match,- (cardinality($7::text[]) = 0 OR actor = ANY($7::text[])) AS actor_match,- (NOT $8::boolean OR NOT read) AS read_match+ (cardinality($4::text[]) = 0 OR issue_status = ANY($4::text[])) AS status_match,+ (cardinality($5::text[]) = 0 OR issue_priority = ANY($5::text[])) AS priority_match,+ (cardinality($6::text[]) = 0 OR actor = ANY($6::text[])) AS actor_match,+ (NOT $7::boolean OR NOT read) AS read_matchFROM projected)SELECT 'statuses'::text AS dimension, issue_status::text AS key,@@ -65,14 +64,13 @@ FROM matched`type ArchivedInboxFacetsParams struct {- ActivityTypes []string `json:"activity_types"`- AgentActivityTypes []string `json:"agent_activity_types"`- WorkspaceID pgtype.UUID `json:"workspace_id"`- RecipientID pgtype.UUID `json:"recipient_id"`- Statuses []string `json:"statuses"`- Priorities []string `json:"priorities"`- Actors []string `json:"actors"`- UnreadOnly bool `json:"unread_only"`+ ActivityTypes []string `json:"activity_types"`+ WorkspaceID pgtype.UUID `json:"workspace_id"`+ RecipientID pgtype.UUID `json:"recipient_id"`+ Statuses []string `json:"statuses"`+ Priorities []string `json:"priorities"`+ Actors []string `json:"actors"`+ UnreadOnly bool `json:"unread_only"`}type ArchivedInboxFacetsRow struct {@@ -85,7 +83,6 @@ type ArchivedInboxFacetsRow struct {func (q *Queries) ArchivedInboxFacets(ctx context.Context, arg ArchivedInboxFacetsParams) ([]ArchivedInboxFacetsRow, error) {rows, err := q.db.Query(ctx, archivedInboxFacets,arg.ActivityTypes,- arg.AgentActivityTypes,arg.WorkspaceID,arg.RecipientID,arg.Statuses,@@ -116,18 +113,17 @@ WITH newest AS MATERIALIZED (SELECT DISTINCT ON (COALESCE(i.issue_id, i.id))i.id, i.issue_id, i.created_at,-- Activity is never unread (inbox.Section); the caller passes- -- inbox.ActivityTypes and inbox.AgentActivityTypes.- (i.read OR COALESCE(i.section = 'activity', i.type = ANY($1::text[])- OR (COALESCE(i.actor_type, '') = 'agent' AND i.type = ANY($2::text[])))) AS read,+ -- inbox.ActivityTypes.+ (i.read OR COALESCE(i.section = 'activity', i.type = ANY($1::text[]))) AS read,CASE WHEN i.actor_type = 'system' THEN 'system'ELSE i.actor_type || ':' || i.actor_id::text END AS actorFROM inbox_item i- WHERE i.workspace_id = $3::uuid+ WHERE i.workspace_id = $2::uuidAND i.recipient_type = 'member'- AND i.recipient_id = $4::uuid+ AND i.recipient_id = $3::uuidAND i.archived = true- AND ($5::uuid IS NULL OR i.issue_id = $5::uuid- OR (i.issue_id IS NULL AND i.id = $5::uuid))+ AND ($4::uuid IS NULL OR i.issue_id = $4::uuid+ OR (i.issue_id IS NULL AND i.id = $4::uuid))AND (i.issue_id IS NULL OR NOT EXISTS (SELECT 1 FROM inbox_item activeWHERE active.workspace_id = i.workspace_id@@ -140,22 +136,22 @@ WITH newest AS MATERIALIZED (SELECT newest.id, newest.issue_id, newest.created_at, newest.read, newest.actor, iss.status AS issue_status, iss.priority AS issue_priorityFROM newestLEFT JOIN issue iss ON iss.id = newest.issue_id- AND iss.workspace_id = $3::uuid+ AND iss.workspace_id = $2::uuid), matched AS (SELECT projected.id, projected.issue_id, projected.created_at, projected.read, projected.actor, projected.issue_status, projected.issue_priority,- (cardinality($6::text[]) = 0 OR issue_status = ANY($6::text[])) AS status_match,- (cardinality($7::text[]) = 0 OR issue_priority = ANY($7::text[])) AS priority_match,- (cardinality($8::text[]) = 0 OR actor = ANY($8::text[])) AS actor_match,- (NOT $9::boolean OR NOT read) AS read_match+ (cardinality($5::text[]) = 0 OR issue_status = ANY($5::text[])) AS status_match,+ (cardinality($6::text[]) = 0 OR issue_priority = ANY($6::text[])) AS priority_match,+ (cardinality($7::text[]) = 0 OR actor = ANY($7::text[])) AS actor_match,+ (NOT $8::boolean OR NOT read) AS read_matchFROM projected), selected AS (SELECT id, issue_id, created_at, read, actor, issue_status, issue_priority, status_match, priority_match, actor_match, read_match FROM matchedWHERE status_match AND priority_match AND actor_match AND read_match- AND ($10::timestamptz IS NULL OR- (created_at, id) < ($10::timestamptz, $11::uuid))+ AND ($9::timestamptz IS NULL OR+ (created_at, id) < ($9::timestamptz, $10::uuid))ORDER BY created_at DESC, id DESC- LIMIT $12::int+ LIMIT $11::int)SELECT i.id, i.workspace_id, i.recipient_type, i.recipient_id, i.type, i.severity, i.issue_id, i.title, i.body, i.read, i.archived, i.created_at, i.actor_type, i.actor_id, i.details, i.section, selected.issue_status, selected.issue_priority,COALESCE(anchor.comment_id, '')::text AS comment_id@@ -174,18 +170,17 @@ ORDER BY i.created_at DESC, i.id DESC`type ListArchivedInboxPageParams struct {- ActivityTypes []string `json:"activity_types"`- AgentActivityTypes []string `json:"agent_activity_types"`- WorkspaceID pgtype.UUID `json:"workspace_id"`- RecipientID pgtype.UUID `json:"recipient_id"`- GroupID pgtype.UUID `json:"group_id"`- Statuses []string `json:"statuses"`- Priorities []string `json:"priorities"`- Actors []string `json:"actors"`- UnreadOnly bool `json:"unread_only"`- BeforeTime pgtype.Timestamptz `json:"before_time"`- BeforeID pgtype.UUID `json:"before_id"`- PageLimit int32 `json:"page_limit"`+ ActivityTypes []string `json:"activity_types"`+ WorkspaceID pgtype.UUID `json:"workspace_id"`+ RecipientID pgtype.UUID `json:"recipient_id"`+ GroupID pgtype.UUID `json:"group_id"`+ Statuses []string `json:"statuses"`+ Priorities []string `json:"priorities"`+ Actors []string `json:"actors"`+ UnreadOnly bool `json:"unread_only"`+ BeforeTime pgtype.Timestamptz `json:"before_time"`+ BeforeID pgtype.UUID `json:"before_id"`+ PageLimit int32 `json:"page_limit"`}type ListArchivedInboxPageRow struct {@@ -199,7 +194,6 @@ type ListArchivedInboxPageRow struct {func (q *Queries) ListArchivedInboxPage(ctx context.Context, arg ListArchivedInboxPageParams) ([]ListArchivedInboxPageRow, error) {rows, err := q.db.Query(ctx, listArchivedInboxPage,arg.ActivityTypes,- arg.AgentActivityTypes,arg.WorkspaceID,arg.RecipientID,arg.GroupID,diff --git a/server/pkg/db/queries/inbox.sql b/server/pkg/db/queries/inbox.sqlindex 8276a377ff..b0a8b14013 100644--- a/server/pkg/db/queries/inbox.sql+++ b/server/pkg/db/queries/inbox.sql@@ -136,15 +136,14 @@ WHERE workspace_id = $1 AND recipient_type = $2 AND recipient_id = $3 AND issue_-- is activity: clearing routine progress must not take an unread action item-- on the same issue (a mention, a failed run) with it. The activity predicate-- mirrors inbox.ItemSection: a stored section wins, otherwise the type rule--- the caller passes as inbox.ActivityTypes and inbox.AgentActivityTypes.+-- the caller passes as inbox.ActivityTypes.UPDATE inbox_item i SET archived = trueWHERE i.workspace_id = sqlc.arg('workspace_id')AND i.recipient_type = sqlc.arg('recipient_type')AND i.recipient_id = sqlc.arg('recipient_id')AND i.issue_id = sqlc.arg('issue_id')AND i.archived = false- AND COALESCE(i.section = 'activity', i.type = ANY(sqlc.arg('activity_types')::text[])- OR (COALESCE(i.actor_type, '') = 'agent' AND i.type = ANY(sqlc.arg('agent_activity_types')::text[])));+ AND COALESCE(i.section = 'activity', i.type = ANY(sqlc.arg('activity_types')::text[]));-- name: MarkInboxReadByIssue :execrows-- Opening an issue anywhere (Work sidebar, search, a link) settles its inbox@@ -183,8 +182,7 @@ WHERE i.workspace_id = sqlc.arg('workspace_id')AND i.recipient_id = sqlc.arg('recipient_id')AND i.read = falseAND i.archived = false- AND NOT COALESCE(i.section = 'activity', i.type = ANY(sqlc.arg('activity_types')::text[])- OR (COALESCE(i.actor_type, '') = 'agent' AND i.type = ANY(sqlc.arg('agent_activity_types')::text[])));+ AND NOT COALESCE(i.section = 'activity', i.type = ANY(sqlc.arg('activity_types')::text[]));-- name: CountUnreadInboxByWorkspace :many-- Per-workspace unread inbox counts for a recipient member, matching the@@ -210,8 +208,7 @@ FROM (WHERE i.recipient_type = 'member'AND i.recipient_id = sqlc.arg('recipient_id')AND i.archived = false- AND NOT COALESCE(i.section = 'activity', i.type = ANY(sqlc.arg('activity_types')::text[])- OR (COALESCE(i.actor_type, '') = 'agent' AND i.type = ANY(sqlc.arg('agent_activity_types')::text[])))+ AND NOT COALESCE(i.section = 'activity', i.type = ANY(sqlc.arg('activity_types')::text[]))ORDER BY i.workspace_id, COALESCE(i.issue_id, i.id), i.created_at DESC) newestWHERE newest.read = false@@ -238,8 +235,7 @@ WITH active AS (COALESCE(i.issue_id, i.id) AS group_id,i.created_at,i.read,- COALESCE(i.section = 'activity', i.type = ANY(sqlc.arg('activity_types')::text[])- OR (COALESCE(i.actor_type, '') = 'agent' AND i.type = ANY(sqlc.arg('agent_activity_types')::text[]))) AS is_activity+ COALESCE(i.section = 'activity', i.type = ANY(sqlc.arg('activity_types')::text[])) AS is_activityFROM inbox_item iWHERE i.workspace_id = sqlc.arg('workspace_id')AND i.recipient_type = 'member'diff --git a/server/pkg/db/queries/inbox_archive.sql b/server/pkg/db/queries/inbox_archive.sqlindex c879b51c12..8a40ae4f8f 100644--- a/server/pkg/db/queries/inbox_archive.sql+++ b/server/pkg/db/queries/inbox_archive.sql@@ -4,9 +4,8 @@ WITH newest AS MATERIALIZED (SELECT DISTINCT ON (COALESCE(i.issue_id, i.id))i.id, i.issue_id, i.created_at,-- Activity is never unread (inbox.Section); the caller passes- -- inbox.ActivityTypes and inbox.AgentActivityTypes.- (i.read OR COALESCE(i.section = 'activity', i.type = ANY(sqlc.arg(activity_types)::text[])- OR (COALESCE(i.actor_type, '') = 'agent' AND i.type = ANY(sqlc.arg(agent_activity_types)::text[])))) AS read,+ -- inbox.ActivityTypes.+ (i.read OR COALESCE(i.section = 'activity', i.type = ANY(sqlc.arg(activity_types)::text[]))) AS read,CASE WHEN i.actor_type = 'system' THEN 'system'ELSE i.actor_type || ':' || i.actor_id::text END AS actorFROM inbox_item i@@ -66,9 +65,8 @@ WITH newest AS MATERIALIZED (SELECT DISTINCT ON (COALESCE(i.issue_id, i.id))i.id, i.issue_id, i.created_at,-- Activity is never unread (inbox.Section); the caller passes- -- inbox.ActivityTypes and inbox.AgentActivityTypes.- (i.read OR COALESCE(i.section = 'activity', i.type = ANY(sqlc.arg(activity_types)::text[])- OR (COALESCE(i.actor_type, '') = 'agent' AND i.type = ANY(sqlc.arg(agent_activity_types)::text[])))) AS read,+ -- inbox.ActivityTypes.+ (i.read OR COALESCE(i.section = 'activity', i.type = ANY(sqlc.arg(activity_types)::text[]))) AS read,CASE WHEN i.actor_type = 'system' THEN 'system'ELSE i.actor_type || ':' || i.actor_id::text END AS actorFROM inbox_item i