Skip to content

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

Go

feat(inbox): notify the human behind agent-created issues and their agent replies (MUL-9314) (#10656)

Jiayuan Zhangff4b7a0ffc1a
diff --git a/server/cmd/server/delegated_subscriber_test.go b/server/cmd/server/delegated_subscriber_test.go
index d582cfa740..2981417e4c 100644
--- a/server/cmd/server/delegated_subscriber_test.go
+++ b/server/cmd/server/delegated_subscriber_test.go
@@ -470,7 +470,6 @@ func TestDeliverToSubscriber_DelegatedTier(t *testing.T) {
{"direct subscriber keeps comments", "assignee", "new_comment", false, true},
{"delegated skips routine progress", "delegated", "status_changed", false, false},
- {"delegated skips comment churn", "delegated", "new_comment", false, false},
{"delegated skips assignee churn", "delegated", "assignee_changed", false, false},
{"delegated skips date churn", "delegated", "due_date_changed", false, false},
{"delegated skips non-status events even on a handoff", "delegated", "due_date_changed", true, false},
@@ -478,6 +477,7 @@ func TestDeliverToSubscriber_DelegatedTier(t *testing.T) {
{"delegated gets the handoff", "delegated", "status_changed", true, true},
{"delegated always gets direct mentions", "delegated", "mentioned", false, true},
+ {"delegated always gets comments", "delegated", "new_comment", false, true},
{"delegated always gets failures", "delegated", "task_failed", false, true},
{"delegated always gets agent_blocked", "delegated", "agent_blocked", false, true},
}
@@ -652,3 +652,131 @@ func TestDeliverToSubscriber_UnknownReasonIsDirect(t *testing.T) {
t.Fatal("an unrecognized subscription reason must default to full delivery")
}
}
+
+// TestDelegatedIssueCreated_NotifiesTheHumanOwner: an issue an agent files on a
+// human's behalf reaches that human's inbox when it is created, unless a parent
+// they already watch leads there (MUL-9314).
+func TestDelegatedIssueCreated_NotifiesTheHumanOwner(t *testing.T) {
+ ctx := context.Background()
+ queries := db.New(testPool)
+ agentID, runtimeID := firstFixtureAgent(t)
+
+ issueCreatedRows := func(issueID string) int {
+ t.Helper()
+ var n int
+ if err := testPool.QueryRow(ctx,
+ `SELECT COUNT(*) FROM inbox_item
+ WHERE recipient_type = 'member' AND recipient_id = $1 AND issue_id = $2 AND type = 'issue_created'`,
+ testUserID, issueID,
+ ).Scan(&n); err != nil {
+ t.Fatalf("count inbox: %v", err)
+ }
+ return n
+ }
+ // fileIn runs the agent create through both listener sets in main.go's
+ // order and returns the issue with the inbox:new events it published for
+ // the human.
+ fileIn := func(t *testing.T, originType string, parent pgtype.UUID, projectID string) (string, int) {
+ t.Helper()
+ bus := events.New()
+ registerSubscriberListeners(bus, testPool)
+ registerNotificationListeners(bus, queries)
+ inboxNew := 0
+ bus.Subscribe(protocol.EventInboxNew, func(e events.Event) {
+ item, _ := e.Payload.(map[string]any)["item"].(map[string]any)
+ if item["recipient_id"] == testUserID {
+ inboxNew++
+ }
+ })
+
+ task := createAgentTaskWithOriginator(t, agentID, runtimeID, util.MustParseUUID(testUserID))
+ issueID := createAgentOriginIssue(t, agentID, originType, task, parent)
+ t.Cleanup(func() {
+ testPool.Exec(context.Background(), `DELETE FROM inbox_item WHERE issue_id = $1`, issueID)
+ })
+ resp := handler.IssueResponse{
+ ID: issueID,
+ WorkspaceID: testWorkspaceID,
+ Title: "delegated subscriber test issue",
+ Status: "todo",
+ Priority: "medium",
+ CreatorType: "agent",
+ CreatorID: agentID,
+ }
+ if parent.Valid {
+ parentID := util.UUIDToString(parent)
+ resp.ParentIssueID = &parentID
+ }
+ if projectID != "" {
+ if _, err := testPool.Exec(ctx, `UPDATE issue SET project_id = $1 WHERE id = $2`, projectID, issueID); err != nil {
+ t.Fatalf("set project: %v", err)
+ }
+ resp.ProjectID = &projectID
+ }
+ bus.Publish(events.Event{
+ Type: protocol.EventIssueCreated,
+ WorkspaceID: testWorkspaceID,
+ ActorType: "agent",
+ ActorID: agentID,
+ Payload: map[string]any{"issue": resp},
+ })
+ return issueID, inboxNew
+ }
+ file := func(t *testing.T, originType string, parent pgtype.UUID) string {
+ t.Helper()
+ issueID, _ := fileIn(t, originType, parent, "")
+ return issueID
+ }
+
+ t.Run("also watching the project notifies once", func(t *testing.T) {
+ projectID := createTestProject(t)
+ addProjectSubscribers(t, projectID, testUserID)
+ issueID, inboxNew := fileIn(t, "agent_create", pgtype.UUID{}, projectID)
+ if n := issueCreatedRows(issueID); n != 1 {
+ t.Fatalf("issue_created rows = %d, want 1", n)
+ }
+ if inboxNew != 1 {
+ t.Fatalf("inbox:new events = %d, want 1", inboxNew)
+ }
+ })
+
+ t.Run("top-level issue", func(t *testing.T) {
+ issueID := file(t, "agent_create", pgtype.UUID{})
+ if n := issueCreatedRows(issueID); n != 1 {
+ t.Fatalf("issue_created rows = %d, want 1", n)
+ }
+ })
+
+ t.Run("sub-issue under a parent the human does not watch", func(t *testing.T) {
+ parentID := createTestIssue(t, testWorkspaceID, testUserID)
+ t.Cleanup(func() { cleanupTestIssue(t, parentID) })
+ issueID := file(t, "agent_create", util.MustParseUUID(parentID))
+ if n := issueCreatedRows(issueID); n != 1 {
+ t.Fatalf("issue_created rows = %d, want 1", n)
+ }
+ })
+
+ t.Run("sub-issue under a watched parent stays quiet", func(t *testing.T) {
+ parentID := createTestIssue(t, testWorkspaceID, testUserID)
+ t.Cleanup(func() { cleanupTestIssue(t, parentID) })
+ if _, err := queries.AddIssueSubscriber(ctx, db.AddIssueSubscriberParams{
+ IssueID: util.MustParseUUID(parentID),
+ UserType: "member",
+ UserID: util.MustParseUUID(testUserID),
+ Reason: "creator",
+ }); err != nil {
+ t.Fatalf("subscribe parent: %v", err)
+ }
+ issueID := file(t, "agent_create", util.MustParseUUID(parentID))
+ if n := issueCreatedRows(issueID); n != 0 {
+ t.Fatalf("issue_created rows = %d, want 0", n)
+ }
+ })
+
+ t.Run("quick create is not a delegated notification", func(t *testing.T) {
+ issueID := file(t, "quick_create", pgtype.UUID{})
+ if n := issueCreatedRows(issueID); n != 0 {
+ t.Fatalf("issue_created rows = %d, want 0", n)
+ }
+ })
+}
diff --git a/server/cmd/server/notification_listeners.go b/server/cmd/server/notification_listeners.go
index 0f3cb35be6..1de8eae8ff 100644
--- a/server/cmd/server/notification_listeners.go
+++ b/server/cmd/server/notification_listeners.go
@@ -45,10 +45,16 @@ var parentBubbleNotifTypes = map[string]bool{
// delegatedAlwaysNotifTypes are the events a DELEGATED subscriber (reason=
// 'delegated' — an agent created this issue on their behalf, MUL-5483) receives
-// unconditionally: they are either addressed at the human directly, or they are
-// exceptions that stall the work until a human looks.
+// unconditionally: they are addressed at the human directly, carry the agent's
+// result, or are exceptions that stall the work until a human looks.
+//
+// new_comment is here because an agent posts its result as a comment: muting
+// status changes must not leave the human with no signal that the work they
+// started was answered (MUL-9314). The inbox keeps one row per issue, so a
+// comment lands on the row a handoff would light anyway.
var delegatedAlwaysNotifTypes = map[string]bool{
"mentioned": true,
+ "new_comment": true,
"task_failed": true,
"agent_blocked": true,
}
@@ -677,6 +683,58 @@ func notifyDirect(
})
}
+// notifyDelegatedIssueCreated tells the human behind an agent-created issue
+// that it exists. The delegated tier otherwise stays silent until a handoff
+// status, which left a new top-level issue findable only from the comment of
+// the run that filed it (MUL-9314). It reads the delegated subscription the
+// subscriber listener wrote for this same event, and adds each recipient to
+// skip so the project fanout that follows does not notify them twice.
+//
+// A sub-issue under a parent the human already watches stays quiet: the parent
+// leads there, and an agent splitting work into many children is the noise
+// the delegated tier exists to suppress (MUL-5483).
+func notifyDelegatedIssueCreated(
+ ctx context.Context,
+ queries *db.Queries,
+ bus *events.Bus,
+ issue handler.IssueResponse,
+ e events.Event,
+ skip map[string]bool,
+) {
+ if issue.CreatorType != "agent" {
+ return
+ }
+ subs, err := queries.ListIssueSubscribers(ctx, parseUUID(issue.ID))
+ if err != nil {
+ slog.Error("delegated issue_created: list subscribers failed", "issue_id", issue.ID, "error", err)
+ return
+ }
+ for _, sub := range subs {
+ subID := util.UUIDToString(sub.UserID)
+ if sub.UserType != "member" || sub.Reason != "delegated" || skip[subID] {
+ continue
+ }
+ if issue.ParentIssueID != nil {
+ watchingParent, err := queries.IsIssueSubscriber(ctx, db.IsIssueSubscriberParams{
+ IssueID: parseUUID(*issue.ParentIssueID),
+ UserType: "member",
+ UserID: sub.UserID,
+ })
+ if err != nil {
+ slog.Error("delegated issue_created: parent subscription check failed",
+ "issue_id", issue.ID, "error", err)
+ continue
+ }
+ if watchingParent {
+ continue
+ }
+ }
+ skip[subID] = true
+ notifyDirect(ctx, queries, bus, "member", subID, issue.WorkspaceID, e, issue.ID, issue.Status,
+ "issue_created", "info", issue.Title, "", emptyDetails)
+ }
+}
+
// 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).
@@ -840,6 +898,8 @@ func registerNotificationListeners(bus *events.Bus, queries *db.Queries) {
issue.Title, skip, emptyDetails)
}
+ notifyDelegatedIssueCreated(ctx, queries, bus, issue, e, skip)
+
// Members watching the project hear about every new issue in it.
if issue.ProjectID != nil {
notifyProjectSubscribers(ctx, queries, bus, issue.ID, issue.Status, issue.WorkspaceID, e,