Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(issues): narrow my_agents and My work squad scope to owned leaders (MUL-9814) (#11159)
Jiayuan Zhang0cc830613777
diff --git a/packages/core/types/api.ts b/packages/core/types/api.tsindex e3a8ec9798..a92f9b6960 100644--- a/packages/core/types/api.ts+++ b/packages/core/types/api.ts@@ -235,9 +235,8 @@ export interface ListIssuesParams {ids?: string[];/*** Widen the assignee filter to issues where the user is the *indirect*- * assignee — assignee is one of the user's owned agents, or a squad that- * involves the user (human member / leader-via-owned-agent / agent member- * owned by the user). Direct member assignment is intentionally excluded:+ * assignee — assignee is one of the user's owned agents, or a squad led by+ * an agent the user owns. Direct member assignment is intentionally excluded:* `involves_user_id` and `assignee_id=<user>` (tab "Assigned to me") produce* disjoint result sets by construction.*/diff --git a/packages/views/issues/utils/filter.ts b/packages/views/issues/utils/filter.tsindex 85e1c68060..b3aad70847 100644--- a/packages/views/issues/utils/filter.ts+++ b/packages/views/issues/utils/filter.ts@@ -121,7 +121,7 @@ export interface IssueRelationContext {/** Agents the viewer owns. Loaded only while a filter tests "my_agents";* without it that relation is left to the server for agent rows. */myAgentIds?: ReadonlySet<string>;- /** Squads the viewer or one of their agents is in, the other half of+ /** Squads led by an agent the viewer owns, the other half of* "my_agents"; without it that relation is left to the server for squad* rows. */mySquadIds?: ReadonlySet<string>;diff --git a/server/internal/handler/agent_test.go b/server/internal/handler/agent_test.goindex 89432f81bf..2de3e2238a 100644--- a/server/internal/handler/agent_test.go+++ b/server/internal/handler/agent_test.go@@ -279,7 +279,7 @@ func TestListWorkspaceWorkingAgents(t *testing.T) {// Insert source issues directly: this test is about the working-agent// projection, so it must not inherit unrelated CreateIssue validation or// side effects. The fixtures cover every direct My Issues relation plus- // all three squad-involvement branches.+ // owned-leader squads (included) and non-leader squad memberships (excluded).insertedIssueIDs := make([]string, 0, 6)insertIssue := func(title, creatorType, creatorID string,@@ -457,25 +457,21 @@ func TestListWorkspaceWorkingAgents(t *testing.T) {{name: "mine defaults to any",query: "?type=issue&scope=mine",- wantCount: 5,+ wantCount: 3,wantIssueIDs: []string{assignedIssueID,ownedAgentIssueID,- directMemberSquadIssueID,ownedLeaderSquadIssueID,- ownedMemberSquadIssueID,},},{name: "mine any",query: "?type=issue&scope=mine&relation=any",- wantCount: 5,+ wantCount: 3,wantIssueIDs: []string{assignedIssueID,ownedAgentIssueID,- directMemberSquadIssueID,ownedLeaderSquadIssueID,- ownedMemberSquadIssueID,},},{@@ -493,12 +489,10 @@ func TestListWorkspaceWorkingAgents(t *testing.T) {{name: "mine involved",query: "?type=issue&scope=mine&relation=involved",- wantCount: 4,+ wantCount: 2,wantIssueIDs: []string{ownedAgentIssueID,- directMemberSquadIssueID,ownedLeaderSquadIssueID,- ownedMemberSquadIssueID,},},} {diff --git a/server/internal/handler/issue.go b/server/internal/handler/issue.goindex 52b14b523d..f6a9fcfc6f 100644--- a/server/internal/handler/issue.go+++ b/server/internal/handler/issue.go@@ -1408,10 +1408,10 @@ func (h *Handler) ListIssues(w http.ResponseWriter, r *http.Request) {projectFilter = id}// involves_user_id widens the assignee filter to surface issues where the- // user is the indirect assignee (their owned agent, or a squad they belong- // to / lead / have an agent inside). Direct member-assignment is excluded- // by design — that is the meaning of `assignee_id` (tab 1), and tab 3 must- // be disjoint from tab 1.+ // user is the indirect assignee (their owned agent, or a squad led by an+ // agent they own). Direct member-assignment is excluded by design — that is+ // the meaning of `assignee_id` (tab 1), and tab 3 must be disjoint from+ // tab 1.var involvesUserFilter pgtype.UUIDif u := r.URL.Query().Get("involves_user_id"); u != "" {id, ok := parseUUIDOrBadRequest(w, u, "involves_user_id")@@ -1766,38 +1766,7 @@ func (h *Handler) ListIssues(w http.ResponseWriter, r *http.Request) {}where = appendIssueDateFilter(where, addArg, dateFilter)if involvesUserFilter.Valid {- ref := addArg(involvesUserFilter)- where = append(where, fmt.Sprintf(`(- (i.assignee_type = 'agent' AND i.assignee_id IN (- SELECT a.id FROM agent a- WHERE a.workspace_id = $1- AND a.owner_id = %[1]s::uuid- ))- OR (i.assignee_type = 'squad' AND i.assignee_id IN (- SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- WHERE s.workspace_id = $1- AND sm.member_type = 'member'- AND sm.member_id = %[1]s::uuid- UNION- SELECT s.id- FROM squad s- JOIN agent a ON a.id = s.leader_id- WHERE s.workspace_id = $1- AND a.workspace_id = $1- AND a.owner_id = %[1]s::uuid- UNION- SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- JOIN agent a ON a.id = sm.member_id- WHERE s.workspace_id = $1- AND sm.member_type = 'agent'- AND a.workspace_id = $1- AND a.owner_id = %[1]s::uuid- ))-)`, ref))+ where = append(where, issueTableInvolvedPredicate(addArg(involvesUserFilter)))}whereSql := strings.Join(where, " AND ")@@ -2229,10 +2198,8 @@ func (h *Handler) ListGroupedIssues(w http.ResponseWriter, r *http.Request) {} else if filter != nil {where = append(where, propertiesFilterPredicate(filter, addArg))}- // Mirror the involves_user_id 4-branch UNION from sqlc's ListIssues /- // ListOpenIssues / CountIssues. ListGroupedIssues is a hand-written dynamic- // SQL builder that does not share parameters with sqlc, so the fragment is- // re-implemented here in lock-step. Member-direct assignment is excluded by+ // Mirror the involves_user_id 2-branch predicate from sqlc's ListIssues /+ // ListOpenIssues / CountIssues. Member-direct assignment is excluded by// design: that semantics belongs to tab 1 (`assignee_id`), and tab 3 must// stay disjoint from tab 1.if raw := r.URL.Query().Get("involves_user_id"); raw != "" {@@ -2240,38 +2207,7 @@ func (h *Handler) ListGroupedIssues(w http.ResponseWriter, r *http.Request) {if !ok {return}- ref := addArg(id)- where = append(where, fmt.Sprintf(`(- (i.assignee_type = 'agent' AND i.assignee_id IN (- SELECT a.id FROM agent a- WHERE a.workspace_id = $1- AND a.owner_id = %[1]s::uuid- ))- OR (i.assignee_type = 'squad' AND i.assignee_id IN (- SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- WHERE s.workspace_id = $1- AND sm.member_type = 'member'- AND sm.member_id = %[1]s::uuid- UNION- SELECT s.id- FROM squad s- JOIN agent a ON a.id = s.leader_id- WHERE s.workspace_id = $1- AND a.workspace_id = $1- AND a.owner_id = %[1]s::uuid- UNION- SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- JOIN agent a ON a.id = sm.member_id- WHERE s.workspace_id = $1- AND sm.member_type = 'agent'- AND a.workspace_id = $1- AND a.owner_id = %[1]s::uuid- ))-)`, ref))+ where = append(where, issueTableInvolvedPredicate(addArg(id)))}assigneeFilters, ok := parseActorFilterList(w, r.URL.Query().Get("assignee_filters"), "assignee_filters")diff --git a/server/internal/handler/issue_involves_test.go b/server/internal/handler/issue_involves_test.goindex 9ee56cdcdc..62ebd49738 100644--- a/server/internal/handler/issue_involves_test.go+++ b/server/internal/handler/issue_involves_test.go@@ -10,21 +10,22 @@ import ("time")-// involvesFixture seeds, for a single test, the data needed to exercise every-// branch of the `involves_user_id` 4-branch filter — owned agent, squad human-// member, squad canonical leader (via squad.leader_id, NOT a squad_member copy-// row), and squad agent member — plus a parallel set in a second workspace so-// the cross-workspace negative tests can prove subquery-level isolation.+// involvesFixture seeds, for a single test, the data needed to exercise the+// `involves_user_id` filter — owned agent and squad canonical leader (via+// squad.leader_id, NOT a squad_member copy row) — plus negative shapes for+// shared squads where the user or one of their agents is only a member, and a+// parallel set in a second workspace so cross-workspace negative tests can+// prove subquery-level isolation.type involvesFixture struct {// All IDs are in the primary handler-test workspace unless noted otherwise.userID string // the "me" user the filter is keyed on (== testUserID)otherID string // a different user in the same workspace- ownedAgentID string // agent.owner_id = userID — branch (1) seed+ ownedAgentID string // agent.owner_id = userID — matchesotherAgentID string // agent.owner_id = otherID — must NOT match- squadMemberID string // squad with userID as human member — branch (2)- squadLeaderID string // squad whose leader_id is an agent owned by userID — branch (3)- squadAgentMemID string // squad with an owned-agent as squad_member row — branch (4)+ squadMemberID string // squad with userID as human member (other leader) — must NOT match+ squadLeaderID string // squad whose leader_id is an agent owned by userID — matches+ squadAgentMemID string // squad with an owned-agent as squad_member row (other leader) — must NOT match// Other workspace, mirror objects — used by ExcludesOtherWorkspace* testsotherWsID string@@ -293,13 +294,13 @@ func TestListIssues_InvolvesUserID_MatchesOwnedAgentAssignee(t *testing.T) {}}-func TestListIssues_InvolvesUserID_MatchesSquadMember(t *testing.T) {+func TestListIssues_InvolvesUserID_ExcludesSquadHumanMember(t *testing.T) {ctx := context.Background()fx := setupInvolvesFixture(t)- wantID := insertIssueTo(t, ctx, testWorkspaceID,- "issue assigned to a squad I'm a member of", "squad", fx.squadMemberID)- if got := listIssuesInvolves(t, fx.userID); !containsIssueID(got, wantID) {- t.Fatalf("branch (2) miss: human-member squad assignee not surfaced (want %s, got %v)", wantID, got)+ issueID := insertIssueTo(t, ctx, testWorkspaceID,+ "issue assigned to a shared squad I'm a human member of", "squad", fx.squadMemberID)+ if got := listIssuesInvolves(t, fx.userID); containsIssueID(got, issueID) {+ t.Fatalf("shared squad human-member assignee should not surface in involves_user_id (id=%s, got=%v)", issueID, got)}}@@ -307,21 +308,21 @@ func TestListIssues_InvolvesUserID_MatchesLeaderViaCanonicalRelation(t *testing.ctx := context.Background()fx := setupInvolvesFixture(t)// Fixture deliberately omits the squad_member leader-copy row, so this- // can only match if the SQL reads squad.leader_id directly (branch 3).+ // can only match if the SQL reads squad.leader_id directly.wantID := insertIssueTo(t, ctx, testWorkspaceID,"issue assigned to a squad my agent leads", "squad", fx.squadLeaderID)if got := listIssuesInvolves(t, fx.userID); !containsIssueID(got, wantID) {- t.Fatalf("branch (3) miss: squad-leader-via-canonical assignee not surfaced (want %s, got %v)", wantID, got)+ t.Fatalf("squad-leader-via-canonical assignee not surfaced (want %s, got %v)", wantID, got)}}-func TestListIssues_InvolvesUserID_MatchesSquadAgentMember(t *testing.T) {+func TestListIssues_InvolvesUserID_ExcludesSquadAgentMember(t *testing.T) {ctx := context.Background()fx := setupInvolvesFixture(t)- wantID := insertIssueTo(t, ctx, testWorkspaceID,- "issue assigned to a squad my agent is a member of", "squad", fx.squadAgentMemID)- if got := listIssuesInvolves(t, fx.userID); !containsIssueID(got, wantID) {- t.Fatalf("branch (4) miss: squad agent-member assignee not surfaced (want %s, got %v)", wantID, got)+ issueID := insertIssueTo(t, ctx, testWorkspaceID,+ "issue assigned to another squad where my agent is only a member", "squad", fx.squadAgentMemID)+ if got := listIssuesInvolves(t, fx.userID); containsIssueID(got, issueID) {+ t.Fatalf("non-leader squad agent-member assignee should not surface in involves_user_id (id=%s, got=%v)", issueID, got)}}@@ -454,14 +455,25 @@ func TestListIssues_InvolvesUserID_InvalidUUIDReturns400(t *testing.T) {}}-// Grouped path also exercises canonical-leader resolution, so a single positive-// guards the dynamic SQL builder against accidentally dropping branch (3).+// Grouped path also exercises canonical-leader resolution and excludes+// non-leader squad memberships, guarding the dynamic SQL builder.func TestListGroupedIssues_InvolvesUserID_MatchesLeaderViaCanonicalRelation(t *testing.T) {ctx := context.Background()fx := setupInvolvesFixture(t)wantID := insertIssueTo(t, ctx, testWorkspaceID,"grouped: squad my agent leads", "squad", fx.squadLeaderID)- if got := listGroupedIssuesInvolves(t, fx.userID); !containsIssueID(got, wantID) {- t.Fatalf("grouped branch (3) miss: squad-leader-via-canonical not surfaced (want %s, got %v)", wantID, got)+ humanMemberID := insertIssueTo(t, ctx, testWorkspaceID,+ "grouped: shared squad where I am a human member", "squad", fx.squadMemberID)+ agentMemberID := insertIssueTo(t, ctx, testWorkspaceID,+ "grouped: squad where my agent is only a member", "squad", fx.squadAgentMemID)+ got := listGroupedIssuesInvolves(t, fx.userID)+ if !containsIssueID(got, wantID) {+ t.Fatalf("grouped squad-leader-via-canonical not surfaced (want %s, got %v)", wantID, got)+ }+ if containsIssueID(got, humanMemberID) {+ t.Fatalf("grouped shared squad human-member should not surface (id=%s, got=%v)", humanMemberID, got)+ }+ if containsIssueID(got, agentMemberID) {+ t.Fatalf("grouped non-leader squad agent-member should not surface (id=%s, got=%v)", agentMemberID, got)}}diff --git a/server/internal/handler/issue_table_negation_test.go b/server/internal/handler/issue_table_negation_test.goindex 585b01b9cc..438f5b52cc 100644--- a/server/internal/handler/issue_table_negation_test.go+++ b/server/internal/handler/issue_table_negation_test.go@@ -127,15 +127,15 @@ func TestIssueTableRowsNegationAndRelations(t *testing.T) {assertRows("relation assigned",issueTableFiltersRequest{Relations: []string{"assigned"}},assignedToMe)- assertRows("relation my agents matches the involved scope: my agents and my squads",+ assertRows("relation my agents matches owned agents and squads led by owned agents",issueTableFiltersRequest{Relations: []string{"my_agents"}},- mineByAgent, mySquad, squadWithMe, squadWithMyAgent)+ mineByAgent, mySquad)assertRows("relations OR within the dimension",issueTableFiltersRequest{Relations: []string{"assigned", "my_agents"}},- assignedToMe, mineByAgent, mySquad, squadWithMe, squadWithMyAgent)+ assignedToMe, mineByAgent, mySquad)assertRows("relation is not my agents",issueTableFiltersRequest{Relations: []string{"my_agents"}, Negate: []string{"relations"}},- assignedToMe, theirAgent, unassignedByOther, theirSquad)+ assignedToMe, theirAgent, unassignedByOther, squadWithMe, squadWithMyAgent, theirSquad)assertRows("relation subscribed matches only my member subscriptions",issueTableFiltersRequest{Relations: []string{"subscribed"}},assignedToMe, theirAgent)@@ -165,7 +165,7 @@ func TestIssueTableRowsNegationAndRelations(t *testing.T) {for _, id := range involvedSquadIDs(t) {involved[id] = true}- for squad, want := range map[string]bool{ledByMyAgent: true, withMe: true, withMyAgent: true, notMine: false} {+ for squad, want := range map[string]bool{ledByMyAgent: true, withMe: false, withMyAgent: false, notMine: false} {if involved[squad] != want {t.Fatalf("involved squads include %s = %v, want %v", squad, involved[squad], want)}diff --git a/server/internal/handler/issue_table_query.go b/server/internal/handler/issue_table_query.goindex 989bb3ca30..f12a78fa8f 100644--- a/server/internal/handler/issue_table_query.go+++ b/server/internal/handler/issue_table_query.go@@ -474,8 +474,7 @@ func appendIssueTableInvolvedPredicate(where []string, addArg func(any) string,}// issueTableInvolvedPredicate matches issues assigned to an agent the user-// owns, or to a squad the user belongs to or one of their agents leads or-// belongs to.+// owns, or to a squad led by an agent the user owns.func issueTableInvolvedPredicate(userRef string) string {return fmt.Sprintf(`((i.assignee_type = 'agent' AND i.assignee_id IN (@@ -484,28 +483,12 @@ func issueTableInvolvedPredicate(userRef string) string {AND a.owner_id = %[1]s::uuid))OR (i.assignee_type = 'squad' AND i.assignee_id IN (- SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- WHERE s.workspace_id = $1- AND sm.member_type = 'member'- AND sm.member_id = %[1]s::uuid- UNIONSELECT s.idFROM squad sJOIN agent a ON a.id = s.leader_idWHERE s.workspace_id = $1AND a.workspace_id = $1AND a.owner_id = %[1]s::uuid- UNION- SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- JOIN agent a ON a.id = sm.member_id- WHERE s.workspace_id = $1- AND sm.member_type = 'agent'- AND a.workspace_id = $1- AND a.owner_id = %[1]s::uuid)))`, userRef)}diff --git a/server/pkg/db/generated/agent.sql.go b/server/pkg/db/generated/agent.sql.goindex 771d211037..30004e0502 100644--- a/server/pkg/db/generated/agent.sql.go+++ b/server/pkg/db/generated/agent.sql.go@@ -6821,33 +6821,11 @@ WHERE a.workspace_id = $1AND EXISTS (SELECT 1FROM squad s+ JOIN agent leader ON leader.id = s.leader_idWHERE s.id = i.assignee_idAND s.workspace_id = a.workspace_id- AND (- EXISTS (- SELECT 1- FROM squad_member sm- WHERE sm.squad_id = s.id- AND sm.member_type = 'member'- AND sm.member_id = $4::uuid- )- OR EXISTS (- SELECT 1- FROM agent leader- WHERE leader.id = s.leader_id- AND leader.workspace_id = a.workspace_id- AND leader.owner_id = $4::uuid- )- OR EXISTS (- SELECT 1- FROM squad_member sm- JOIN agent owned_member ON owned_member.id = sm.member_id- WHERE sm.squad_id = s.id- AND sm.member_type = 'agent'- AND owned_member.workspace_id = a.workspace_id- AND owned_member.owner_id = $4::uuid- )- )+ AND leader.workspace_id = a.workspace_id+ AND leader.owner_id = $4::uuid)))diff --git a/server/pkg/db/generated/issue.sql.go b/server/pkg/db/generated/issue.sql.goindex eade2901db..563bd0896c 100644--- a/server/pkg/db/generated/issue.sql.go+++ b/server/pkg/db/generated/issue.sql.go@@ -196,28 +196,12 @@ WHERE i.workspace_id = $1AND a.owner_id = $12::uuid))OR (i.assignee_type = 'squad' AND i.assignee_id IN (- SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- WHERE s.workspace_id = $1- AND sm.member_type = 'member'- AND sm.member_id = $12::uuid- UNIONSELECT s.idFROM squad sJOIN agent a ON a.id = s.leader_idWHERE s.workspace_id = $1AND a.workspace_id = $1AND a.owner_id = $12::uuid- UNION- SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- JOIN agent a ON a.id = sm.member_id- WHERE s.workspace_id = $1- AND sm.member_type = 'agent'- AND a.workspace_id = $1- AND a.owner_id = $12::uuid)))`@@ -1423,36 +1407,17 @@ WHERE i.workspace_id = $1WHERE a.workspace_id = $1AND a.owner_id = $14::uuid))- -- (2)(3)(4) assignee is a squad related to the user — three relations+ -- (2) assignee is a squad whose canonical leader is an agent owned by the+ -- user. We read squad.leader_id directly rather than relying on a+ -- squad_member row, because the leader copy in squad_member is best-effort+ -- (see squad.go AddSquadMember error handling).OR (i.assignee_type = 'squad' AND i.assignee_id IN (- -- (2) the user is a human member of the squad- SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- WHERE s.workspace_id = $1- AND sm.member_type = 'member'- AND sm.member_id = $14::uuid- UNION- -- (3) the squad's canonical leader is an agent owned by the user.- -- We read squad.leader_id directly rather than relying on a- -- squad_member row, because the leader copy in squad_member is- -- best-effort (see squad.go AddSquadMember error handling).SELECT s.idFROM squad sJOIN agent a ON a.id = s.leader_idWHERE s.workspace_id = $1AND a.workspace_id = $1AND a.owner_id = $14::uuid- UNION- -- (4) the squad has an agent member owned by the user- SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- JOIN agent a ON a.id = sm.member_id- WHERE s.workspace_id = $1- AND sm.member_type = 'agent'- AND a.workspace_id = $1- AND a.owner_id = $14::uuid)))ORDER BY i.position ASC, i.created_at DESC@@ -1505,11 +1470,11 @@ type ListIssuesRow struct {}// involves_user_id widens the assignee filter to surface issues where the user-// is *indirectly* the assignee — via an owned agent or a squad they belong to /-// lead / have an agent inside. The semantics intentionally exclude direct-// member assignment (`assignee_type='member' AND assignee_id=involves_user_id`)-// because that is already the meaning of the `assignee_id` filter (tab 1-// "Assigned to me"), and the two filters must produce disjoint result sets.+// is *indirectly* the assignee — via an owned agent or a squad led by an owned+// agent. The semantics intentionally exclude direct member assignment+// (`assignee_type='member' AND assignee_id=involves_user_id`) because that is+// already the meaning of the `assignee_id` filter (tab 1 "Assigned to me"),+// and the two filters must produce disjoint result sets.func (q *Queries) ListIssues(ctx context.Context, arg ListIssuesParams) ([]ListIssuesRow, error) {rows, err := q.db.Query(ctx, listIssues,arg.WorkspaceID,@@ -1654,28 +1619,12 @@ WHERE i.workspace_id = $1AND a.owner_id = $12::uuid))OR (i.assignee_type = 'squad' AND i.assignee_id IN (- SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- WHERE s.workspace_id = $1- AND sm.member_type = 'member'- AND sm.member_id = $12::uuid- UNIONSELECT s.idFROM squad sJOIN agent a ON a.id = s.leader_idWHERE s.workspace_id = $1AND a.workspace_id = $1AND a.owner_id = $12::uuid- UNION- SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- JOIN agent a ON a.id = sm.member_id- WHERE s.workspace_id = $1- AND sm.member_type = 'agent'- AND a.workspace_id = $1- AND a.owner_id = $12::uuid)))ORDER BY i.position ASC, i.created_at DESC@@ -1724,7 +1673,7 @@ type ListOpenIssuesRow struct {DuplicateOfIssueID pgtype.UUID `json:"duplicate_of_issue_id"`}-// See ListIssues for the semantics of involves_user_id (mirrors the 4-branch+// See ListIssues for the semantics of involves_user_id (mirrors the 2-branch// filter; member-direct assignment is intentionally excluded).func (q *Queries) ListOpenIssues(ctx context.Context, arg ListOpenIssuesParams) ([]ListOpenIssuesRow, error) {rows, err := q.db.Query(ctx, listOpenIssues,diff --git a/server/pkg/db/generated/squad.sql.go b/server/pkg/db/generated/squad.sql.goindex 71c4831faa..293f3f7d09 100644--- a/server/pkg/db/generated/squad.sql.go+++ b/server/pkg/db/generated/squad.sql.go@@ -268,28 +268,12 @@ func (q *Queries) ListAllSquads(ctx context.Context, workspaceID pgtype.UUID) ([}const listInvolvedSquadIDs = `-- name: ListInvolvedSquadIDs :many-SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- WHERE s.workspace_id = $1- AND sm.member_type = 'member'- AND sm.member_id = $2-UNIONSELECT s.idFROM squad sJOIN agent a ON a.id = s.leader_idWHERE s.workspace_id = $1AND a.workspace_id = $1AND a.owner_id = $2-UNION-SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- JOIN agent a ON a.id = sm.member_id- WHERE s.workspace_id = $1- AND sm.member_type = 'agent'- AND a.workspace_id = $1- AND a.owner_id = $2`type ListInvolvedSquadIDsParams struct {@@ -297,9 +281,8 @@ type ListInvolvedSquadIDsParams struct {UserID pgtype.UUID `json:"user_id"`}-// Squads whose issues count as the user's agents' work: the user is a member,-// or an agent they own leads or is a member. Must match the squad branch of-// issueTableInvolvedPredicate.+// Squads whose issues count as the user's agents' work: squads led by an agent+// the user owns. Must match the squad branch of issueTableInvolvedPredicate.func (q *Queries) ListInvolvedSquadIDs(ctx context.Context, arg ListInvolvedSquadIDsParams) ([]pgtype.UUID, error) {rows, err := q.db.Query(ctx, listInvolvedSquadIDs, arg.WorkspaceID, arg.UserID)if err != nil {@@ -308,11 +291,11 @@ func (q *Queries) ListInvolvedSquadIDs(ctx context.Context, arg ListInvolvedSquadefer rows.Close()items := []pgtype.UUID{}for rows.Next() {- var squad_id pgtype.UUID- if err := rows.Scan(&squad_id); err != nil {+ var id pgtype.UUID+ if err := rows.Scan(&id); err != nil {return nil, err}- items = append(items, squad_id)+ items = append(items, id)}if err := rows.Err(); err != nil {return nil, errdiff --git a/server/pkg/db/queries/agent.sql b/server/pkg/db/queries/agent.sqlindex e9482e8ffd..8543864fdd 100644--- a/server/pkg/db/queries/agent.sql+++ b/server/pkg/db/queries/agent.sql@@ -2710,33 +2710,11 @@ WHERE a.workspace_id = $1AND EXISTS (SELECT 1FROM squad s+ JOIN agent leader ON leader.id = s.leader_idWHERE s.id = i.assignee_idAND s.workspace_id = a.workspace_id- AND (- EXISTS (- SELECT 1- FROM squad_member sm- WHERE sm.squad_id = s.id- AND sm.member_type = 'member'- AND sm.member_id = @member_id::uuid- )- OR EXISTS (- SELECT 1- FROM agent leader- WHERE leader.id = s.leader_id- AND leader.workspace_id = a.workspace_id- AND leader.owner_id = @member_id::uuid- )- OR EXISTS (- SELECT 1- FROM squad_member sm- JOIN agent owned_member ON owned_member.id = sm.member_id- WHERE sm.squad_id = s.id- AND sm.member_type = 'agent'- AND owned_member.workspace_id = a.workspace_id- AND owned_member.owner_id = @member_id::uuid- )- )+ AND leader.workspace_id = a.workspace_id+ AND leader.owner_id = @member_id::uuid)))diff --git a/server/pkg/db/queries/issue.sql b/server/pkg/db/queries/issue.sqlindex 5597533d80..db58ab2a4e 100644--- a/server/pkg/db/queries/issue.sql+++ b/server/pkg/db/queries/issue.sql@@ -1,10 +1,10 @@-- name: ListIssues :many-- involves_user_id widens the assignee filter to surface issues where the user--- is *indirectly* the assignee — via an owned agent or a squad they belong to /--- lead / have an agent inside. The semantics intentionally exclude direct--- member assignment (`assignee_type='member' AND assignee_id=involves_user_id`)--- because that is already the meaning of the `assignee_id` filter (tab 1--- "Assigned to me"), and the two filters must produce disjoint result sets.+-- is *indirectly* the assignee — via an owned agent or a squad led by an owned+-- agent. The semantics intentionally exclude direct member assignment+-- (`assignee_type='member' AND assignee_id=involves_user_id`) because that is+-- already the meaning of the `assignee_id` filter (tab 1 "Assigned to me"),+-- and the two filters must produce disjoint result sets.SELECT i.id, i.workspace_id, i.title, i.description, i.status, i.priority,i.assignee_type, i.assignee_id, i.creator_type, i.creator_id, i.requester_user_id,i.parent_issue_id, i.position, i.start_date, i.due_date, i.created_at, i.updated_at, i.last_activity_at, i.number, i.project_id, i.metadata, i.stage, i.properties,@@ -30,36 +30,17 @@ WHERE i.workspace_id = $1WHERE a.workspace_id = $1AND a.owner_id = sqlc.narg('involves_user_id')::uuid))- -- (2)(3)(4) assignee is a squad related to the user — three relations+ -- (2) assignee is a squad whose canonical leader is an agent owned by the+ -- user. We read squad.leader_id directly rather than relying on a+ -- squad_member row, because the leader copy in squad_member is best-effort+ -- (see squad.go AddSquadMember error handling).OR (i.assignee_type = 'squad' AND i.assignee_id IN (- -- (2) the user is a human member of the squad- SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- WHERE s.workspace_id = $1- AND sm.member_type = 'member'- AND sm.member_id = sqlc.narg('involves_user_id')::uuid- UNION- -- (3) the squad's canonical leader is an agent owned by the user.- -- We read squad.leader_id directly rather than relying on a- -- squad_member row, because the leader copy in squad_member is- -- best-effort (see squad.go AddSquadMember error handling).SELECT s.idFROM squad sJOIN agent a ON a.id = s.leader_idWHERE s.workspace_id = $1AND a.workspace_id = $1AND a.owner_id = sqlc.narg('involves_user_id')::uuid- UNION- -- (4) the squad has an agent member owned by the user- SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- JOIN agent a ON a.id = sm.member_id- WHERE s.workspace_id = $1- AND sm.member_type = 'agent'- AND a.workspace_id = $1- AND a.owner_id = sqlc.narg('involves_user_id')::uuid)))ORDER BY i.position ASC, i.created_at DESC@@ -525,7 +506,7 @@ cleared_task_context_receipts AS (DELETE FROM issue WHERE issue.id IN (SELECT target.id FROM target);-- name: ListOpenIssues :many--- See ListIssues for the semantics of involves_user_id (mirrors the 4-branch+-- See ListIssues for the semantics of involves_user_id (mirrors the 2-branch-- filter; member-direct assignment is intentionally excluded).SELECT i.id, i.workspace_id, i.title, i.description, i.status, i.priority,i.assignee_type, i.assignee_id, i.creator_type, i.creator_id, i.requester_user_id,@@ -609,28 +590,12 @@ WHERE i.workspace_id = $1AND a.owner_id = sqlc.narg('involves_user_id')::uuid))OR (i.assignee_type = 'squad' AND i.assignee_id IN (- SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- WHERE s.workspace_id = $1- AND sm.member_type = 'member'- AND sm.member_id = sqlc.narg('involves_user_id')::uuid- UNIONSELECT s.idFROM squad sJOIN agent a ON a.id = s.leader_idWHERE s.workspace_id = $1AND a.workspace_id = $1AND a.owner_id = sqlc.narg('involves_user_id')::uuid- UNION- SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- JOIN agent a ON a.id = sm.member_id- WHERE s.workspace_id = $1- AND sm.member_type = 'agent'- AND a.workspace_id = $1- AND a.owner_id = sqlc.narg('involves_user_id')::uuid)))ORDER BY i.position ASC, i.created_at DESC;@@ -658,28 +623,12 @@ WHERE i.workspace_id = $1AND a.owner_id = sqlc.narg('involves_user_id')::uuid))OR (i.assignee_type = 'squad' AND i.assignee_id IN (- SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- WHERE s.workspace_id = $1- AND sm.member_type = 'member'- AND sm.member_id = sqlc.narg('involves_user_id')::uuid- UNIONSELECT s.idFROM squad sJOIN agent a ON a.id = s.leader_idWHERE s.workspace_id = $1AND a.workspace_id = $1AND a.owner_id = sqlc.narg('involves_user_id')::uuid- UNION- SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- JOIN agent a ON a.id = sm.member_id- WHERE s.workspace_id = $1- AND sm.member_type = 'agent'- AND a.workspace_id = $1- AND a.owner_id = sqlc.narg('involves_user_id')::uuid)));diff --git a/server/pkg/db/queries/squad.sql b/server/pkg/db/queries/squad.sqlindex 56e6bdf8df..fa41bd443c 100644--- a/server/pkg/db/queries/squad.sql+++ b/server/pkg/db/queries/squad.sql@@ -60,29 +60,12 @@ ORDER BYsm.created_at ASC;-- name: ListInvolvedSquadIDs :many--- Squads whose issues count as the user's agents' work: the user is a member,--- or an agent they own leads or is a member. Must match the squad branch of--- issueTableInvolvedPredicate.-SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- WHERE s.workspace_id = sqlc.arg(workspace_id)- AND sm.member_type = 'member'- AND sm.member_id = sqlc.arg(user_id)-UNION+-- Squads whose issues count as the user's agents' work: squads led by an agent+-- the user owns. Must match the squad branch of issueTableInvolvedPredicate.SELECT s.idFROM squad sJOIN agent a ON a.id = s.leader_idWHERE s.workspace_id = sqlc.arg(workspace_id)- AND a.workspace_id = sqlc.arg(workspace_id)- AND a.owner_id = sqlc.arg(user_id)-UNION-SELECT sm.squad_id- FROM squad_member sm- JOIN squad s ON s.id = sm.squad_id- JOIN agent a ON a.id = sm.member_id- WHERE s.workspace_id = sqlc.arg(workspace_id)- AND sm.member_type = 'agent'AND a.workspace_id = sqlc.arg(workspace_id)AND a.owner_id = sqlc.arg(user_id);