Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-8596 feat(inbox): opening an issue reads its informational Inbox notifications (#9928)
Jiayuan Zhange0ce246499c1
diff --git a/server/internal/handler/inbox.go b/server/internal/handler/inbox.goindex ce0945df1c..683307dd76 100644--- a/server/internal/handler/inbox.go+++ b/server/internal/handler/inbox.go@@ -437,8 +437,9 @@ func (h *Handler) MarkAllInboxRead(w http.ResponseWriter, r *http.Request) {writeJSON(w, http.StatusOK, map[string]any{"count": count})}-// MarkIssueInboxRead marks the caller's unread notifications on one issue-// read. The client calls it while the issue is on screen outside the inbox, so+// MarkIssueInboxRead marks the caller's unread informational notifications on+// one issue read; items that need handling stay unread (see+// MarkInboxReadByIssue). The client calls it while the issue is on screen outside the inbox, so// reading an issue anywhere also reads it in the inbox (MUL-8588). The update// is scoped to the caller's own rows, so an issue id from another workspace// matches nothing.diff --git a/server/internal/handler/inbox_issue_read_test.go b/server/internal/handler/inbox_issue_read_test.goindex 104972cfd6..ae30392f90 100644--- a/server/internal/handler/inbox_issue_read_test.go+++ b/server/internal/handler/inbox_issue_read_test.go@@ -1,6 +1,7 @@package handlerimport (+ "fmt""net/http""testing"@@ -116,3 +117,154 @@ func TestMarkIssueInboxReadRejectsInvalidIssueID(t *testing.T) {withURLParam(inboxRequest(http.MethodPost, "/api/inbox/issues/nope/read", workspaceID), "issueId", "nope")).Want(http.StatusBadRequest)}++type issueInboxFixture struct {+ t *testing.T+ workspaceID string+ issueID string+}++func newIssueInboxFixture(t *testing.T, name string) issueInboxFixture {+ t.Helper()+ workspaceID := dbfx.Workspace(t, name, "issue-inbox-mixed-"+uuid.NewString())+ dbfx.Member(t, workspaceID, testUserID, "owner")+ issueID := dbfx.Issue(t, name, testutil.Cols{"workspace_id": workspaceID})+ dbfx.Cleanup(t, `DELETE FROM inbox_item WHERE workspace_id = $1`, workspaceID)+ return issueInboxFixture{t: t, workspaceID: workspaceID, issueID: issueID}+}++func (f issueInboxFixture) notify(notifType, severity string, minutesAgo int) string {+ f.t.Helper()+ return dbfx.Insert(f.t, "inbox_item", testutil.Cols{+ "workspace_id": f.workspaceID,+ "recipient_type": "member",+ "recipient_id": testUserID,+ "type": notifType,+ "severity": severity,+ "issue_id": f.issueID,+ "title": notifType,+ "created_at": testutil.Raw(fmt.Sprintf("now() - interval '%d minutes'", minutesAgo)),+ })+}++// openIssue is opening the issue outside the inbox.+func (f issueInboxFixture) openIssue() int64 {+ f.t.Helper()+ var resp struct {+ Count int64 `json:"count"`+ }+ testutil.Call(f.t, inboxWorkspaceHandler(testHandler.MarkIssueInboxRead),+ withURLParam(inboxRequest(http.MethodPost, "/api/inbox/issues/"+f.issueID+"/read", f.workspaceID), "issueId", f.issueID)).+ Want(http.StatusOK).+ JSON(&resp)+ return resp.Count+}++// openInInbox is selecting the issue's row in the inbox: it renders the+// group's newest row and marks that one read.+func (f issueInboxFixture) openInInbox() {+ f.t.Helper()+ var items []InboxItemResponse+ testutil.Call(f.t, inboxWorkspaceHandler(testHandler.ListInbox),+ inboxRequest(http.MethodGet, "/api/inbox", f.workspaceID)).+ Want(http.StatusOK).+ JSON(&items)+ if len(items) == 0 {+ f.t.Fatal("the inbox lists nothing for the issue")+ }+ newest := items[0].ID+ testutil.Call(f.t, inboxWorkspaceHandler(testHandler.MarkInboxRead),+ withURLParam(inboxRequest(http.MethodPost, "/api/inbox/"+newest+"/read", f.workspaceID), "id", newest)).+ Want(http.StatusOK)+}++// unreadRows is the issue's row in the unread badge: 1 while its newest+// active row is unread.+func (f issueInboxFixture) unreadRows() int64 {+ f.t.Helper()+ var summary []InboxWorkspaceUnreadResponse+ testutil.Call(f.t, inboxWorkspaceHandler(testHandler.UnreadInboxSummary),+ inboxRequest(http.MethodGet, "/api/inbox/unread-summary", f.workspaceID)).+ Want(http.StatusOK).+ JSON(&summary)+ for _, s := range summary {+ if s.WorkspaceID == f.workspaceID {+ return s.Count+ }+ }+ return 0+}++func (f issueInboxFixture) read(id string) bool {+ f.t.Helper()+ var read bool+ dbfx.QueryRow(f.t, `SELECT read FROM inbox_item WHERE id = $1`, id).Scan(&read)+ return read+}++func TestMarkIssueInboxReadKeepsPendingItemsThatNeedHandling(t *testing.T) {+ for _, kept := range []struct{ notifType, severity string }{+ {"issue_assigned", "action_required"},+ {"task_failed", "action_required"},+ {"autopilot_paused", "attention"},+ {"mentioned", "info"},+ } {+ t.Run(kept.notifType, func(t *testing.T) {+ f := newIssueInboxFixture(t, "keeps "+kept.notifType)+ keptID := f.notify(kept.notifType, kept.severity, 2)+ comment := f.notify("new_comment", "info", 1)++ // The comment is the row the inbox shows: reading it would turn the+ // row read with the kept item still waiting behind it.+ if got := f.openIssue(); got != 0 {+ t.Fatalf("count = %d, want nothing read while %s is pending", got, kept.notifType)+ }+ if f.read(keptID) || f.read(comment) || f.unreadRows() != 1 {+ t.Fatalf("opening the issue read past a pending %s", kept.notifType)+ }+ })+ }++ t.Run("kept row is the newest", func(t *testing.T) {+ f := newIssueInboxFixture(t, "keeps the newest row")+ comment := f.notify("new_comment", "info", 2)+ assigned := f.notify("issue_assigned", "action_required", 1)+ if got := f.openIssue(); got != 0 || f.read(comment) || f.read(assigned) {+ t.Fatalf("count = %d, want the assignment row left unread as it is", got)+ }+ })+}++func TestMarkIssueInboxReadIsNotBlockedByAnAssignmentTheInboxReadPast(t *testing.T) {+ f := newIssueInboxFixture(t, "assignment the inbox read past")+ assigned := f.notify("issue_assigned", "action_required", 3)+ f.notify("new_comment", "info", 2)++ // The inbox shows and reads only the newest comment; the assignment under+ // it stays unread for good.+ f.openInInbox()+ if f.read(assigned) || f.unreadRows() != 0 {+ t.Fatal("setup: want the inbox row read with the assignment still unread under it")+ }++ next := f.notify("new_comment", "info", 1)+ if f.unreadRows() != 1 {+ t.Fatal("setup: a new comment should make the issue's row unread again")+ }+ if got := f.openIssue(); got != 1 || !f.read(next) {+ t.Fatalf("count = %d, want the new comment read", got)+ }+ if f.unreadRows() != 0 {+ t.Fatal("the issue's inbox row is still unread after opening the issue")+ }+ if f.read(assigned) {+ t.Fatal("opening the issue read the assignment")+ }++ // An assignment that arrives after that is pending again.+ reassigned := f.notify("issue_assigned", "action_required", 0)+ f.notify("new_comment", "info", 0)+ if got := f.openIssue(); got != 0 || f.read(reassigned) || f.unreadRows() != 1 {+ t.Fatalf("count = %d, want a new assignment to keep the row unread", got)+ }+}diff --git a/server/pkg/db/generated/inbox.sql.go b/server/pkg/db/generated/inbox.sql.goindex 68a4cbacdb..76348020b4 100644--- a/server/pkg/db/generated/inbox.sql.go+++ b/server/pkg/db/generated/inbox.sql.go@@ -655,9 +655,22 @@ func (q *Queries) MarkInboxRead(ctx context.Context, id pgtype.UUID) (InboxItem,}const markInboxReadByIssue = `-- name: MarkInboxReadByIssue :execrows-UPDATE inbox_item SET read = true-WHERE workspace_id = $1 AND recipient_type = 'member' AND recipient_id = $2- AND issue_id = $3 AND archived = false AND read = false+UPDATE inbox_item i SET read = true+WHERE i.workspace_id = $1 AND i.recipient_type = 'member' AND i.recipient_id = $2+ AND i.issue_id = $3 AND i.archived = false AND i.read = false+ AND i.severity = 'info' AND i.type <> 'mentioned'+ AND NOT EXISTS (+ SELECT 1 FROM inbox_item kept+ WHERE kept.workspace_id = $1 AND kept.recipient_type = 'member' AND kept.recipient_id = $2+ AND kept.issue_id = $3 AND kept.archived = false AND kept.read = false+ AND (kept.severity <> 'info' OR kept.type = 'mentioned')+ AND NOT EXISTS (+ SELECT 1 FROM inbox_item seen+ WHERE seen.workspace_id = $1 AND seen.recipient_type = 'member' AND seen.recipient_id = $2+ AND seen.issue_id = $3 AND seen.archived = false AND seen.read = true+ AND (seen.created_at, seen.id) > (kept.created_at, kept.id)+ )+ )`type MarkInboxReadByIssueParams struct {@@ -673,6 +686,14 @@ type MarkInboxReadByIssueParams struct {// siblings would otherwise stay in CountUnreadInbox. Archived rows are left as// they are, as in MarkAllInboxRead, which also keeps the lookup on the partial// index idx_inbox_active_by_issue.+//+// Only informational rows are read (MUL-8596). action_required and attention+// rows, and mentions, which are addressed to the reader, stay until handled.+// The inbox renders the group's newest row, so reading info rows around a+// pending kept row could turn the group read and hide it; while one is pending+// nothing is read. A kept row stops being pending once a newer row in the group+// has been read: the inbox already showed the group past it, and it would+// otherwise block every later notification on the issue.func (q *Queries) MarkInboxReadByIssue(ctx context.Context, arg MarkInboxReadByIssueParams) (int64, error) {result, err := q.db.Exec(ctx, markInboxReadByIssue, arg.WorkspaceID, arg.RecipientID, arg.IssueID)if err != nil {diff --git a/server/pkg/db/queries/inbox.sql b/server/pkg/db/queries/inbox.sqlindex 479c17f38f..38d27bdb38 100644--- a/server/pkg/db/queries/inbox.sql+++ b/server/pkg/db/queries/inbox.sql@@ -191,9 +191,30 @@ WHERE workspace_id = $1 AND recipient_type = 'member' AND recipient_id = $2 AND-- siblings would otherwise stay in CountUnreadInbox. Archived rows are left as-- they are, as in MarkAllInboxRead, which also keeps the lookup on the partial-- index idx_inbox_active_by_issue.-UPDATE inbox_item SET read = true-WHERE workspace_id = $1 AND recipient_type = 'member' AND recipient_id = $2- AND issue_id = $3 AND archived = false AND read = false;+--+-- Only informational rows are read (MUL-8596). action_required and attention+-- rows, and mentions, which are addressed to the reader, stay until handled.+-- The inbox renders the group's newest row, so reading info rows around a+-- pending kept row could turn the group read and hide it; while one is pending+-- nothing is read. A kept row stops being pending once a newer row in the group+-- has been read: the inbox already showed the group past it, and it would+-- otherwise block every later notification on the issue.+UPDATE inbox_item i SET read = true+WHERE i.workspace_id = $1 AND i.recipient_type = 'member' AND i.recipient_id = $2+ AND i.issue_id = $3 AND i.archived = false AND i.read = false+ AND i.severity = 'info' AND i.type <> 'mentioned'+ AND NOT EXISTS (+ SELECT 1 FROM inbox_item kept+ WHERE kept.workspace_id = $1 AND kept.recipient_type = 'member' AND kept.recipient_id = $2+ AND kept.issue_id = $3 AND kept.archived = false AND kept.read = false+ AND (kept.severity <> 'info' OR kept.type = 'mentioned')+ AND NOT EXISTS (+ SELECT 1 FROM inbox_item seen+ WHERE seen.workspace_id = $1 AND seen.recipient_type = 'member' AND seen.recipient_id = $2+ AND seen.issue_id = $3 AND seen.archived = false AND seen.read = true+ AND (seen.created_at, seen.id) > (kept.created_at, kept.id)+ )+ );-- name: ArchiveAllInbox :execrowsUPDATE inbox_item SET archived = true