Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

perf(inbox): open notifications at the issue's canonical URL (MUL-9538) (#10868)

Jiayuan Zhang5bb66f20ffe7
diff --git a/packages/core/api/schemas.test.ts b/packages/core/api/schemas.test.ts
index 9d40749e41..0f38e98172 100644
--- a/packages/core/api/schemas.test.ts
+++ b/packages/core/api/schemas.test.ts
@@ -1586,6 +1586,16 @@ describe("InboxItemListSchema", () => {
).toHaveLength(1);
});
+ it("keeps the row when the issue identifier is unusable", () => {
+ const parsed = parseWithFallback(
+ [row({ issue_identifier: 7 }), row({ id: "inbox-2", issue_identifier: "MUL-7" })],
+ InboxItemListSchema,
+ EMPTY_INBOX_ITEMS,
+ ENDPOINT,
+ );
+ expect(parsed.map((item) => item.issue_identifier)).toEqual([null, "MUL-7"]);
+ });
+
it("returns the empty fallback when an issue projection is wrong-typed", () => {
expect(
parseWithFallback(
diff --git a/packages/core/api/schemas.ts b/packages/core/api/schemas.ts
index bc68f84d12..d55589a550 100644
--- a/packages/core/api/schemas.ts
+++ b/packages/core/api/schemas.ts
@@ -3323,6 +3323,9 @@ export const InboxItemListSchema = z.array(
type: z.string(),
severity: z.string(),
issue_id: z.string().nullish(),
+ // Only picks the link; a bad value falls back to the issue_id link
+ // instead of failing the whole list.
+ issue_identifier: z.string().min(1).nullish().catch(null),
title: z.string(),
body: z.string().nullish(),
issue_status: z.string().nullish(),
diff --git a/packages/core/types/inbox.ts b/packages/core/types/inbox.ts
index 4e08535863..998215b022 100644
--- a/packages/core/types/inbox.ts
+++ b/packages/core/types/inbox.ts
@@ -68,6 +68,12 @@ export interface InboxItem {
type: InboxItemType;
severity: InboxSeverity;
issue_id: string | null;
+ /**
+ * The linked issue's identifier (MUL-123). Links use it so they open the
+ * canonical issue URL directly; a UUID URL is rewritten after load, which
+ * mounts the issue page twice on web. Absent on older servers.
+ */
+ issue_identifier?: string | null;
title: string;
body: string | null;
issue_status: IssueStatus | null;
diff --git a/packages/views/inbox/components/inbox-display.test.ts b/packages/views/inbox/components/inbox-display.test.ts
index 35d639e6bc..bf4b9e7935 100644
--- a/packages/views/inbox/components/inbox-display.test.ts
+++ b/packages/views/inbox/components/inbox-display.test.ts
@@ -1,9 +1,11 @@
// @vitest-environment node
import { describe, expect, it } from "vitest";
+import { paths } from "@multica/core/paths";
import type { InboxItem } from "@multica/core/types";
import {
getInboxDisplayTitle,
getQuickCreateOutcomeDetail,
+ inboxRowHref,
isAutopilotQuotaNotice,
isQuickCreateOutcome,
resolveDetailItem,
@@ -152,3 +154,16 @@ describe("resolveDetailItem", () => {
expect(resolveDetailItem(list, "issue-gone", "issue-also-gone")).toBeNull();
});
});
+
+describe("inboxRowHref", () => {
+ const p = paths.workspace("acme");
+
+ it("links to the issue identifier, keeping the comment anchor", () => {
+ expect(inboxRowHref(p, item({ issue_identifier: "MUL-7", details: { comment_id: "c-1" } })))
+ .toBe("/acme/issues/MUL-7#comment-c-1");
+ });
+
+ it("falls back to the issue id when the server sent no identifier", () => {
+ expect(inboxRowHref(p, item({ details: { comment_id: "c-1" } }))).toBe("/acme/issues/issue-1#comment-c-1");
+ });
+});
diff --git a/packages/views/inbox/components/inbox-display.ts b/packages/views/inbox/components/inbox-display.ts
index 36910048bb..bc9ad4e9ab 100644
--- a/packages/views/inbox/components/inbox-display.ts
+++ b/packages/views/inbox/components/inbox-display.ts
@@ -92,6 +92,15 @@ export function resolveDetailItem(
return selectedKey ? byKey(selectedKey) : null;
}
+/**
+ * How a notification addresses its issue in a link: the identifier when the
+ * server sent one, so the issue route opens without rewriting its URL (a
+ * rewrite mounts the whole issue page again on web), else the UUID.
+ */
+export function inboxIssueRef(item: Pick<InboxItem, "issue_identifier">, issueId: string): string {
+ return item.issue_identifier || issueId;
+}
+
/**
* Where a notification row leads: its issue, at the comment or app request it
* is about when it names one. An issue-less notification opens on the Inbox
@@ -99,7 +108,7 @@ export function resolveDetailItem(
*/
export function inboxRowHref(p: WorkspacePaths, item: InboxItem): string {
if (!item.issue_id) return `${p.inbox()}?${new URLSearchParams({ issue: item.id }).toString()}`;
- const issueHref = p.issueDetail(item.issue_id);
+ const issueHref = p.issueDetail(inboxIssueRef(item, item.issue_id));
const requestId = item.type.startsWith("app_") ? item.details?.request_id : undefined;
if (requestId) return `${issueHref}#app-request-${requestId}`;
const commentId = item.details?.comment_id;
diff --git a/packages/views/inbox/components/inbox-item-actions.tsx b/packages/views/inbox/components/inbox-item-actions.tsx
index 52077f903a..ed988b7289 100644
--- a/packages/views/inbox/components/inbox-item-actions.tsx
+++ b/packages/views/inbox/components/inbox-item-actions.tsx
@@ -7,6 +7,7 @@ import type { RowActionItem } from "../../common/row-actions-menu";
import { useIntentNavigate } from "../../navigation";
import { useT } from "../../i18n";
import type { InboxView } from "./inbox-view";
+import { inboxIssueRef } from "./inbox-display";
/** Row-level actions the menus invoke, all keyed by inbox item id. */
export interface InboxRowActions {
@@ -50,7 +51,7 @@ export function useInboxItemActions(
const issueHref =
slug && item.issue_id
- ? paths.workspace(slug).issueDetail(item.issue_id)
+ ? paths.workspace(slug).issueDetail(inboxIssueRef(item, item.issue_id))
: null;
const isArchivedView = view === "archived";
diff --git a/packages/views/inbox/components/inbox-list-item.tsx b/packages/views/inbox/components/inbox-list-item.tsx
index 3f0252c879..5fb6f92c04 100644
--- a/packages/views/inbox/components/inbox-list-item.tsx
+++ b/packages/views/inbox/components/inbox-list-item.tsx
@@ -13,6 +13,7 @@ import type { InboxView } from "./inbox-view";
import { InboxDetailLabel, useTypeLabels } from "./inbox-detail-label";
import {
getInboxDisplayTitle,
+ inboxIssueRef,
isAutopilotQuotaNotice,
} from "./inbox-display";
import { useInboxContextMenu } from "./inbox-context-menu";
@@ -70,7 +71,7 @@ export function InboxListItem({
const slug = useWorkspaceSlug();
const issueHref =
slug && item.issue_id
- ? paths.workspace(slug).issueDetail(item.issue_id)
+ ? paths.workspace(slug).issueDetail(inboxIssueRef(item, item.issue_id))
: null;
const intentNavigate = useIntentNavigate();
const displayTitle = isAutopilotQuotaNotice(item.type)
diff --git a/server/internal/handler/inbox.go b/server/internal/handler/inbox.go
index 634fbcdc5b..658669156a 100644
--- a/server/internal/handler/inbox.go
+++ b/server/internal/handler/inbox.go
@@ -6,6 +6,7 @@ import (
"errors"
"log/slog"
"net/http"
+ "strconv"
"github.com/go-chi/chi/v5"
"github.com/jackc/pgx/v5"
@@ -24,13 +25,18 @@ type InboxItemResponse struct {
Type string `json:"type"`
Severity string `json:"severity"`
IssueID *string `json:"issue_id"`
- Title string `json:"title"`
- Body *string `json:"body"`
- Read bool `json:"read"`
- Archived bool `json:"archived"`
- CreatedAt string `json:"created_at"`
- IssueStatus *string `json:"issue_status"`
- IssuePriority *string `json:"issue_priority"`
+ // The issue's identifier (MUL-123), so a client links to the canonical
+ // issue URL. Opening `/issues/<uuid>` instead rewrites the address once
+ // the issue loads, and on web that mounts the whole page a second time.
+ // Null when the item has no issue or the prefix could not be resolved.
+ IssueIdentifier *string `json:"issue_identifier"`
+ Title string `json:"title"`
+ Body *string `json:"body"`
+ Read bool `json:"read"`
+ Archived bool `json:"archived"`
+ CreatedAt string `json:"created_at"`
+ IssueStatus *string `json:"issue_status"`
+ IssuePriority *string `json:"issue_priority"`
// Issue fields the inbox filters match on. List rows always carry them
// (an empty label list included), which is how a client tells a server
// that supports those filters from an older one.
@@ -125,10 +131,21 @@ func inboxListBody(notifType string, issueID pgtype.UUID, body pgtype.Text) *str
return full
}
+// inboxIssueIdentifier formats an inbox row's issue identifier the way issue
+// responses do. `prefix` is the workspace's effective issue prefix; empty when
+// it could not be loaded, which leaves the client on the UUID link.
+func inboxIssueIdentifier(prefix string, number pgtype.Int4) *string {
+ if prefix == "" || !number.Valid {
+ return nil
+ }
+ identifier := prefix + "-" + strconv.Itoa(int(number.Int32))
+ return &identifier
+}
+
// inboxRowToResponse maps a LIST row — the main inbox and, through
// archivedInboxRowToResponse, the archived view. Single-item responses go
// through inboxToResponse and keep the full body.
-func inboxRowToResponse(r db.ListInboxItemsRow) InboxItemResponse {
+func inboxRowToResponse(r db.ListInboxItemsRow, issuePrefix string) InboxItemResponse {
return InboxItemResponse{
ID: uuidToString(r.ID),
WorkspaceID: uuidToString(r.WorkspaceID),
@@ -137,6 +154,7 @@ func inboxRowToResponse(r db.ListInboxItemsRow) InboxItemResponse {
Type: r.Type,
Severity: r.Severity,
IssueID: uuidToPtr(r.IssueID),
+ IssueIdentifier: inboxIssueIdentifier(issuePrefix, r.IssueNumber),
Title: r.Title,
Body: inboxListBody(r.Type, r.IssueID, r.Body),
Read: r.Read,
@@ -168,8 +186,8 @@ func inboxLabelIDs(ids []string) []string {
// queries select `inbox_item.*` plus the joined issue projections), so the archived
// row converts to the active one and reuses its mapper. If either query's
// column list drifts, this conversion stops compiling — which is the point.
-func archivedInboxRowToResponse(r db.ListArchivedInboxItemsRow) InboxItemResponse {
- return inboxRowToResponse(db.ListInboxItemsRow(r))
+func archivedInboxRowToResponse(r db.ListArchivedInboxItemsRow, issuePrefix string) InboxItemResponse {
+ return inboxRowToResponse(db.ListInboxItemsRow(r), issuePrefix)
}
func (h *Handler) enrichInboxResponse(ctx context.Context, resp InboxItemResponse, issueID pgtype.UUID) InboxItemResponse {
@@ -178,6 +196,7 @@ func (h *Handler) enrichInboxResponse(ctx context.Context, resp InboxItemRespons
}
issue, err := h.Queries.GetIssue(ctx, issueID)
if err == nil {
+ resp.IssueIdentifier = inboxIssueIdentifier(h.getIssuePrefix(ctx, issue.WorkspaceID), pgtype.Int4{Int32: issue.Number, Valid: true})
s := issue.Status
resp.IssueStatus = &s
p := issue.Priority
@@ -234,9 +253,10 @@ func (h *Handler) ListInbox(w http.ResponseWriter, r *http.Request) {
return
}
+ issuePrefix := h.getIssuePrefix(r.Context(), wsUUID)
resp := make([]InboxItemResponse, len(items))
for i, item := range items {
- resp[i] = inboxRowToResponse(item)
+ resp[i] = inboxRowToResponse(item, issuePrefix)
}
writeJSON(w, http.StatusOK, resp)
@@ -335,9 +355,10 @@ func (h *Handler) ListArchivedInbox(w http.ResponseWriter, r *http.Request) {
return
}
+ issuePrefix := h.getIssuePrefix(r.Context(), wsUUID)
resp := make([]InboxItemResponse, len(items))
for i, item := range items {
- resp[i] = archivedInboxRowToResponse(item)
+ resp[i] = archivedInboxRowToResponse(item, issuePrefix)
}
writeJSON(w, http.StatusOK, resp)
diff --git a/server/internal/handler/inbox_archive.go b/server/internal/handler/inbox_archive.go
index da7052c72e..392180f919 100644
--- a/server/internal/handler/inbox_archive.go
+++ b/server/internal/handler/inbox_archive.go
@@ -212,8 +212,10 @@ func (h *Handler) ListArchivedInboxPage(w http.ResponseWriter, r *http.Request)
if resp.HasMore {
rows = rows[:limit]
}
+ issuePrefix := h.getIssuePrefix(r.Context(), filters.WorkspaceID)
for _, row := range rows {
item := inboxToResponse(row.InboxItem)
+ item.IssueIdentifier = inboxIssueIdentifier(issuePrefix, row.IssueNumber)
item.Body = inboxListBody(row.InboxItem.Type, row.InboxItem.IssueID, row.InboxItem.Body)
item.IssueStatus, item.IssuePriority = textToPtr(row.IssueStatus), textToPtr(row.IssuePriority)
item.IssueProjectID, item.IssueDueDate = uuidToPtr(row.IssueProjectID), dateToPtr(row.IssueDueDate)
diff --git a/server/internal/handler/inbox_test.go b/server/internal/handler/inbox_test.go
index 5cca80f186..5b293308b4 100644
--- a/server/internal/handler/inbox_test.go
+++ b/server/internal/handler/inbox_test.go
@@ -382,3 +382,85 @@ func truncateForLog(s string) string {
}
return s
}
+
+// Inbox rows carry the issue identifier so clients link to the canonical issue
+// URL; opening `/issues/<uuid>` rewrites the address and remounts the page
+// (MUL-9538). Every read that hands a client a row carries it.
+func TestInboxItemsCarryIssueIdentifier(t *testing.T) {
+ workspaceID := dbfx.Workspace(t, "Inbox identifiers", "inbox-identifier-"+uuid.NewString(),
+ testutil.Cols{"issue_prefix": "IDN"})
+ dbfx.Member(t, workspaceID, testUserID, "owner")
+ issueID := dbfx.Issue(t, "Identified issue", testutil.Cols{"workspace_id": workspaceID, "number": 42})
+ insertItem := func(title string, archived bool) string {
+ return dbfx.Insert(t, "inbox_item", testutil.Cols{
+ "workspace_id": workspaceID,
+ "recipient_type": "member",
+ "recipient_id": testUserID,
+ "type": "new_comment",
+ "severity": "info",
+ "issue_id": issueID,
+ "title": title,
+ "archived": archived,
+ })
+ }
+ activeID := insertItem("Active", false)
+ dbfx.Insert(t, "inbox_item", testutil.Cols{
+ "workspace_id": workspaceID,
+ "recipient_type": "member",
+ "recipient_id": testUserID,
+ "type": "system",
+ "severity": "info",
+ "title": "Issue-less",
+ })
+ const want = "IDN-42"
+ identifier := func(item InboxItemResponse) string {
+ if item.IssueIdentifier == nil {
+ return "<nil>"
+ }
+ return *item.IssueIdentifier
+ }
+
+ var active []InboxItemResponse
+ testutil.Call(t, inboxWorkspaceHandler(testHandler.ListInbox),
+ inboxRequest(http.MethodGet, "/api/inbox", workspaceID)).Want(http.StatusOK).JSON(&active)
+ for _, item := range active {
+ got, expected := identifier(item), want
+ if item.IssueID == nil {
+ expected = "<nil>"
+ }
+ if got != expected {
+ t.Errorf("list %q issue_identifier = %s, want %s", item.Title, got, expected)
+ }
+ }
+
+ var read InboxItemResponse
+ testutil.Call(t, inboxWorkspaceHandler(testHandler.MarkInboxRead),
+ withURLParam(inboxRequest(http.MethodPost, "/api/inbox/"+activeID+"/read", workspaceID), "id", activeID)).
+ Want(http.StatusOK).JSON(&read)
+ if got := identifier(read); got != want {
+ t.Errorf("mark read issue_identifier = %s, want %s", got, want)
+ }
+
+ // The archived views list an issue only while it has no active row.
+ dbfx.Exec(t, `UPDATE inbox_item SET archived = true WHERE workspace_id = $1`, workspaceID)
+ var archived []InboxItemResponse
+ testutil.Call(t, inboxWorkspaceHandler(testHandler.ListArchivedInbox),
+ inboxRequest(http.MethodGet, "/api/inbox/archived", workspaceID)).Want(http.StatusOK).JSON(&archived)
+ var page archivedInboxPageResponse
+ testutil.Call(t, inboxWorkspaceHandler(testHandler.ListArchivedInboxPage),
+ inboxRequest(http.MethodGet, "/api/inbox/archived/page", workspaceID)).Want(http.StatusOK).JSON(&page)
+ for name, items := range map[string][]InboxItemResponse{"archived": archived, "archived page": page.Items} {
+ found := false
+ for _, item := range items {
+ if item.IssueID != nil && *item.IssueID == issueID {
+ found = true
+ if got := identifier(item); got != want {
+ t.Errorf("%s issue_identifier = %s, want %s", name, got, want)
+ }
+ }
+ }
+ if !found {
+ t.Errorf("%s did not list the issue's row: %+v", name, items)
+ }
+ }
+}
diff --git a/server/pkg/db/generated/inbox.sql.go b/server/pkg/db/generated/inbox.sql.go
index a8b2f9df8b..9500f90c49 100644
--- a/server/pkg/db/generated/inbox.sql.go
+++ b/server/pkg/db/generated/inbox.sql.go
@@ -514,6 +514,7 @@ WITH eligible_archived AS MATERIALIZED (
SELECT id FROM comment_anchors
)
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, i.snoozed_until, i.snoozed_at,
+ iss.number AS issue_number,
iss.status AS issue_status,
iss.priority AS issue_priority,
iss.project_id AS issue_project_id,
@@ -555,6 +556,7 @@ type ListArchivedInboxItemsRow struct {
Section pgtype.Text `json:"section"`
SnoozedUntil pgtype.Timestamptz `json:"snoozed_until"`
SnoozedAt pgtype.Timestamptz `json:"snoozed_at"`
+ IssueNumber pgtype.Int4 `json:"issue_number"`
IssueStatus pgtype.Text `json:"issue_status"`
IssuePriority pgtype.Text `json:"issue_priority"`
IssueProjectID pgtype.UUID `json:"issue_project_id"`
@@ -618,6 +620,7 @@ func (q *Queries) ListArchivedInboxItems(ctx context.Context, arg ListArchivedIn
&i.Section,
&i.SnoozedUntil,
&i.SnoozedAt,
+ &i.IssueNumber,
&i.IssueStatus,
&i.IssuePriority,
&i.IssueProjectID,
@@ -638,6 +641,7 @@ func (q *Queries) ListArchivedInboxItems(ctx context.Context, arg ListArchivedIn
const listInboxItems = `-- name: ListInboxItems :many
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, i.snoozed_until, i.snoozed_at,
+ iss.number AS issue_number,
iss.status AS issue_status,
iss.priority AS issue_priority,
iss.project_id AS issue_project_id,
@@ -684,6 +688,7 @@ type ListInboxItemsRow struct {
Section pgtype.Text `json:"section"`
SnoozedUntil pgtype.Timestamptz `json:"snoozed_until"`
SnoozedAt pgtype.Timestamptz `json:"snoozed_at"`
+ IssueNumber pgtype.Int4 `json:"issue_number"`
IssueStatus pgtype.Text `json:"issue_status"`
IssuePriority pgtype.Text `json:"issue_priority"`
IssueProjectID pgtype.UUID `json:"issue_project_id"`
@@ -729,6 +734,7 @@ func (q *Queries) ListInboxItems(ctx context.Context, arg ListInboxItemsParams)
&i.Section,
&i.SnoozedUntil,
&i.SnoozedAt,
+ &i.IssueNumber,
&i.IssueStatus,
&i.IssuePriority,
&i.IssueProjectID,
diff --git a/server/pkg/db/generated/inbox_archive.sql.go b/server/pkg/db/generated/inbox_archive.sql.go
index 6cf227bde1..c81fa2596f 100644
--- a/server/pkg/db/generated/inbox_archive.sql.go
+++ b/server/pkg/db/generated/inbox_archive.sql.go
@@ -291,6 +291,7 @@ WITH base AS MATERIALIZED (
LIMIT $19::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, i.snoozed_until, i.snoozed_at, selected.issue_status, selected.issue_priority,
+ iss.number AS issue_number,
iss.project_id AS issue_project_id,
iss.assignee_type AS issue_assignee_type,
iss.assignee_id AS issue_assignee_id,
@@ -343,6 +344,7 @@ type ListArchivedInboxPageRow struct {
InboxItem InboxItem `json:"inbox_item"`
IssueStatus pgtype.Text `json:"issue_status"`
IssuePriority pgtype.Text `json:"issue_priority"`
+ IssueNumber pgtype.Int4 `json:"issue_number"`
IssueProjectID pgtype.UUID `json:"issue_project_id"`
IssueAssigneeType pgtype.Text `json:"issue_assignee_type"`
IssueAssigneeID pgtype.UUID `json:"issue_assignee_id"`
@@ -409,6 +411,7 @@ func (q *Queries) ListArchivedInboxPage(ctx context.Context, arg ListArchivedInb
&i.InboxItem.SnoozedAt,
&i.IssueStatus,
&i.IssuePriority,
+ &i.IssueNumber,
&i.IssueProjectID,
&i.IssueAssigneeType,
&i.IssueAssigneeID,
diff --git a/server/pkg/db/queries/inbox.sql b/server/pkg/db/queries/inbox.sql
index e1219f7cb7..0c57ee3f71 100644
--- a/server/pkg/db/queries/inbox.sql
+++ b/server/pkg/db/queries/inbox.sql
@@ -3,6 +3,7 @@
-- identical to ListArchivedInboxItems: the handler converts one row type into
-- the other.
SELECT i.*,
+ iss.number AS issue_number,
iss.status AS issue_status,
iss.priority AS issue_priority,
iss.project_id AS issue_project_id,
@@ -95,6 +96,7 @@ WITH eligible_archived AS MATERIALIZED (
SELECT id FROM comment_anchors
)
SELECT i.*,
+ iss.number AS issue_number,
iss.status AS issue_status,
iss.priority AS issue_priority,
iss.project_id AS issue_project_id,
diff --git a/server/pkg/db/queries/inbox_archive.sql b/server/pkg/db/queries/inbox_archive.sql
index c15882471e..6d91c05625 100644
--- a/server/pkg/db/queries/inbox_archive.sql
+++ b/server/pkg/db/queries/inbox_archive.sql
@@ -92,6 +92,7 @@ WITH base AS MATERIALIZED (
LIMIT sqlc.arg(page_limit)::int
)
SELECT sqlc.embed(i), selected.issue_status, selected.issue_priority,
+ iss.number AS issue_number,
iss.project_id AS issue_project_id,
iss.assignee_type AS issue_assignee_type,
iss.assignee_id AS issue_assignee_id,