Skip to content

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

Go

fix(wakeup): keep private-project issues out of the workspace wakeup lists (#10282)

pseudoyue692d03e234f
diff --git a/server/internal/handler/issue_wakeup.go b/server/internal/handler/issue_wakeup.go
index 6f069c4da6..1c92475e6b 100644
--- a/server/internal/handler/issue_wakeup.go
+++ b/server/internal/handler/issue_wakeup.go
@@ -90,8 +90,12 @@ func (h *Handler) ListWorkspaceWakeups(w http.ResponseWriter, r *http.Request) {
isAdmin = roleAllowed(manager.Role, "owner", "admin")
}
}
+ hidden, ok := h.requestHiddenProjects(w, r, workspaceID)
+ if !ok {
+ return
+ }
result, err := h.Queries.ListWorkspaceWakeups(r.Context(), db.ListWorkspaceWakeupsParams{
- WorkspaceID: parseUUID(workspaceID), AgentIds: ids, MemberID: managerID, IsAdmin: isAdmin,
+ WorkspaceID: parseUUID(workspaceID), AgentIds: ids, MemberID: managerID, IsAdmin: isAdmin, HiddenProjectIds: hidden.Param(),
Scope: scope, Kind: kind, Source: source, AgentID: agentID, Search: search, PageLimit: int32(limit), PageOffset: int32(page),
})
if err != nil {
@@ -172,7 +176,11 @@ func (h *Handler) ListWorkspaceWakeupSummaries(w http.ResponseWriter, r *http.Re
for id := range allowed {
ids = append(ids, parseUUID(id))
}
- rows, err := h.Queries.ListWorkspaceWakeupSummaryRows(r.Context(), db.ListWorkspaceWakeupSummaryRowsParams{WorkspaceID: parseUUID(workspaceID), AgentIds: ids})
+ hidden, ok := h.requestHiddenProjects(w, r, workspaceID)
+ if !ok {
+ return
+ }
+ rows, err := h.Queries.ListWorkspaceWakeupSummaryRows(r.Context(), db.ListWorkspaceWakeupSummaryRowsParams{WorkspaceID: parseUUID(workspaceID), AgentIds: ids, HiddenProjectIds: hidden.Param()})
if err != nil {
wakeupError(w, err)
return
@@ -472,7 +480,11 @@ func (h *Handler) ListPausedWakeups(w http.ResponseWriter, r *http.Request) {
if _, ok := h.workspaceMember(w, r, workspaceID); !ok {
return
}
- rows, err := h.Queries.ListPausedWakeupIssues(r.Context(), parseUUID(workspaceID))
+ hidden, ok := h.requestHiddenProjects(w, r, workspaceID)
+ if !ok {
+ return
+ }
+ rows, err := h.Queries.ListPausedWakeupIssues(r.Context(), db.ListPausedWakeupIssuesParams{WorkspaceID: parseUUID(workspaceID), HiddenProjectIds: hidden.Param()})
if err != nil {
wakeupError(w, err)
return
diff --git a/server/internal/handler/private_project_test.go b/server/internal/handler/private_project_test.go
index b4cebfb5c0..753556c470 100644
--- a/server/internal/handler/private_project_test.go
+++ b/server/internal/handler/private_project_test.go
@@ -746,3 +746,81 @@ func TestPrivateProjectCommentSubIssuePreviewHidden(t *testing.T) {
}
preview(f.insider).Want(http.StatusOK)
}
+
+// The workspace-wide wakeup lists (the Wakeups page, the board's paused cue
+// and the per-issue summaries) are not read through an issue, so each one has
+// to leave out rules on issues in a project the caller cannot see.
+func TestPrivateProjectWakeupListsSkipOutsiders(t *testing.T) {
+ f := newPrivateProjectFixture(t)
+ agent := dbfx.Agent(t, f.marker+" wake target", testRuntimeID)
+ dbfx.Cleanup(t, "DELETE FROM activity_log WHERE issue_id=$1", f.secretIssue)
+ dbfx.Cleanup(t, "DELETE FROM issue_wakeup WHERE issue_id=$1", f.secretIssue)
+ dbfx.Cleanup(t, "DELETE FROM issue_wakeup_receipt WHERE wakeup_id IN (SELECT id FROM issue_wakeup WHERE issue_id=$1)", f.secretIssue)
+ svc := service.IssueWakeupService{Tasks: testHandler.TaskService}
+ create := func() string {
+ t.Helper()
+ w, err := svc.Create(context.Background(), parseUUID(f.secretIssue), parseUUID(testUserID), pgtype.UUID{}, service.WakeupInput{
+ AgentID: agent, Kind: "event", Mode: "continuous", EventTypes: []string{"comment.created"}, Instruction: "check",
+ })
+ if err != nil {
+ t.Fatal(err)
+ }
+ return uuidToString(w.ID)
+ }
+ create()
+ paused := create()
+ dbfx.Exec(t, "UPDATE issue_wakeup SET enabled=false,paused_reason='rate',disabled_at=now() WHERE id=$1", paused)
+ // An open sub-issue makes the secret issue's child-done system rule listable.
+ dbfx.Issue(t, f.marker+" secret child", testutil.Cols{"project_id": f.projectID, "parent_issue_id": f.secretIssue})
+ if w := putChildDoneRule(t, f.secretIssue, map[string]any{"instruction": "Advance."}); w.Code != http.StatusOK {
+ t.Fatalf("create system rule: %d %s", w.Code, w.Body.String())
+ }
+
+ onSecretIssue := func(userID string, list http.HandlerFunc, path string) int {
+ t.Helper()
+ var rows []struct {
+ IssueID string `json:"issue_id"`
+ }
+ testutil.Call(t, list, asUser(newRequest(http.MethodGet, path, nil), userID)).Want(http.StatusOK).JSON(&rows)
+ n := 0
+ for _, row := range rows {
+ if row.IssueID == f.secretIssue {
+ n++
+ }
+ }
+ return n
+ }
+ for _, tc := range []struct {
+ name string
+ userID string
+ visible bool
+ }{
+ {"project member", f.insider, true},
+ {"workspace owner outside the member list", testUserID, true},
+ {"workspace member outside the project", f.outsider, false},
+ } {
+ // The marker is in the secret issue's title and nowhere else, so the
+ // search narrows the page and its total to this fixture's rules.
+ var page struct {
+ Items []struct {
+ IssueID string `json:"issue_id"`
+ } `json:"items"`
+ Total int `json:"total"`
+ }
+ req := asUser(newRequest(http.MethodGet, "/api/issue-wakeups?scope=all&limit=100&search="+f.marker, nil), tc.userID)
+ testutil.Call(t, testHandler.ListWorkspaceWakeups, req).Want(http.StatusOK).JSON(&page)
+ want := 0
+ if tc.visible {
+ want = 3 // the active rule, the paused rule and the system rule
+ }
+ if len(page.Items) != want || page.Total != want {
+ t.Errorf("%s: wakeup list has %d rules (total %d) on the secret issue, want %d", tc.name, len(page.Items), page.Total, want)
+ }
+ if got := onSecretIssue(tc.userID, testHandler.ListWorkspaceWakeupSummaries, "/api/issue-wakeup-summaries") > 0; got != tc.visible {
+ t.Errorf("%s: wakeup summaries include the secret issue = %v, want %v", tc.name, got, tc.visible)
+ }
+ if got := onSecretIssue(tc.userID, testHandler.ListPausedWakeups, "/api/issue-wakeup-paused") > 0; got != tc.visible {
+ t.Errorf("%s: paused wakeups include the secret issue = %v, want %v", tc.name, got, tc.visible)
+ }
+ }
+}
diff --git a/server/pkg/db/generated/wakeup.sql.go b/server/pkg/db/generated/wakeup.sql.go
index 40282ae666..a46b322880 100644
--- a/server/pkg/db/generated/wakeup.sql.go
+++ b/server/pkg/db/generated/wakeup.sql.go
@@ -1063,11 +1063,18 @@ const listPausedWakeupIssues = `-- name: ListPausedWakeupIssues :many
SELECT w.issue_id,w.id,w.agent_id,w.paused_reason
FROM issue_wakeup w JOIN issue i ON i.id=w.issue_id AND i.workspace_id=w.workspace_id
WHERE w.workspace_id= $1 AND NOT w.enabled AND w.paused_reason IN ('loop','rate','max_fires')
+ -- MUL-8472: private projects the caller cannot see.
+ AND ($2::uuid[] IS NULL OR i.project_id IS NULL OR NOT (i.project_id = ANY($2::uuid[])))
AND i.status NOT IN ('done','cancelled')
AND NOT EXISTS(SELECT 1 FROM issue_status s WHERE s.workspace_id=i.workspace_id AND s.key=i.status AND s.category IN ('done','closed'))
ORDER BY w.updated_at DESC LIMIT 200
`
+type ListPausedWakeupIssuesParams struct {
+ WorkspaceID pgtype.UUID `json:"workspace_id"`
+ HiddenProjectIds []pgtype.UUID `json:"hidden_project_ids"`
+}
+
type ListPausedWakeupIssuesRow struct {
IssueID pgtype.UUID `json:"issue_id"`
ID pgtype.UUID `json:"id"`
@@ -1077,8 +1084,8 @@ type ListPausedWakeupIssuesRow struct {
// Rules the platform paused on open issues, for board cues and the
// workspace banner. Access follows shared issue visibility.
-func (q *Queries) ListPausedWakeupIssues(ctx context.Context, workspaceID pgtype.UUID) ([]ListPausedWakeupIssuesRow, error) {
- rows, err := q.db.Query(ctx, listPausedWakeupIssues, workspaceID)
+func (q *Queries) ListPausedWakeupIssues(ctx context.Context, arg ListPausedWakeupIssuesParams) ([]ListPausedWakeupIssuesRow, error) {
+ rows, err := q.db.Query(ctx, listPausedWakeupIssues, arg.WorkspaceID, arg.HiddenProjectIds)
if err != nil {
return nil, err
}
@@ -1376,6 +1383,8 @@ LEFT JOIN member actor_member ON w.filter_actor_type='member' AND actor_member.u
LEFT JOIN "user" actor_user ON actor_user.id=actor_member.user_id
LEFT JOIN agent source ON source.id=w.filter_agent_id AND source.workspace_id=w.workspace_id AND source.id=ANY($1::uuid[])
WHERE w.workspace_id= $2 AND w.enabled
+ -- MUL-8472: private projects the caller cannot see.
+ AND ($3::uuid[] IS NULL OR i.project_id IS NULL OR NOT (i.project_id = ANY($3::uuid[])))
AND i.status NOT IN ('done','cancelled')
AND NOT EXISTS(SELECT 1 FROM issue_status s WHERE s.workspace_id=i.workspace_id AND s.key=i.status AND s.category IN ('done','closed'))
)
@@ -1384,8 +1393,9 @@ FROM ranked WHERE rank<=3 ORDER BY issue_id,rank
`
type ListWorkspaceWakeupSummaryRowsParams struct {
- AgentIds []pgtype.UUID `json:"agent_ids"`
- WorkspaceID pgtype.UUID `json:"workspace_id"`
+ AgentIds []pgtype.UUID `json:"agent_ids"`
+ WorkspaceID pgtype.UUID `json:"workspace_id"`
+ HiddenProjectIds []pgtype.UUID `json:"hidden_project_ids"`
}
type ListWorkspaceWakeupSummaryRowsRow struct {
@@ -1412,7 +1422,7 @@ type ListWorkspaceWakeupSummaryRowsRow struct {
// No prompts/history; at most three previews per issue plus exact counts.
func (q *Queries) ListWorkspaceWakeupSummaryRows(ctx context.Context, arg ListWorkspaceWakeupSummaryRowsParams) ([]ListWorkspaceWakeupSummaryRowsRow, error) {
- rows, err := q.db.Query(ctx, listWorkspaceWakeupSummaryRows, arg.AgentIds, arg.WorkspaceID)
+ rows, err := q.db.Query(ctx, listWorkspaceWakeupSummaryRows, arg.AgentIds, arg.WorkspaceID, arg.HiddenProjectIds)
if err != nil {
return nil, err
}
diff --git a/server/pkg/db/generated/workspace_wakeup.sql.go b/server/pkg/db/generated/workspace_wakeup.sql.go
index 707931e135..9bb696e106 100644
--- a/server/pkg/db/generated/workspace_wakeup.sql.go
+++ b/server/pkg/db/generated/workspace_wakeup.sql.go
@@ -49,6 +49,8 @@ LEFT JOIN "user" actor_user ON actor_user.id=actor_member.user_id
AND t.status IN ('queued','deferred','dispatched','running','waiting_local_directory')
) r ON true
WHERE w.workspace_id= $4 AND w.system_rule IS NULL
+ -- MUL-8472: private projects the caller cannot see.
+ AND ($5::uuid[] IS NULL OR i.project_id IS NULL OR NOT (i.project_id = ANY($5::uuid[])))
UNION ALL
-- The child-done system rule of each open parent that still waits for a
-- sub-issue: every child when unstaged, else its lowest unfinished stage.
@@ -87,6 +89,8 @@ LEFT JOIN "user" actor_user ON actor_user.id=actor_member.user_id
AND t.status IN ('queued','deferred','dispatched','running','waiting_local_directory')
) sr ON true
WHERE w.workspace_id= $4 AND w.system_rule IS NOT NULL AND agg.open_count>0
+ -- MUL-8472: private projects the caller cannot see.
+ AND ($5::uuid[] IS NULL OR p.project_id IS NULL OR NOT (p.project_id = ANY($5::uuid[])))
AND p.status NOT IN ('done','cancelled')
AND NOT EXISTS(SELECT 1 FROM issue_status s WHERE s.workspace_id=p.workspace_id AND s.key=p.status AND s.category IN ('done','closed'))
), classified AS (
@@ -95,13 +99,13 @@ LEFT JOIN "user" actor_user ON actor_user.id=actor_member.user_id
WHEN NOT issue_closed AND (disabled_at IS NOT NULL OR source='system') THEN 'disabled' ELSE 'ended' END AS scope
FROM base
), filtered AS (
- SELECT id, issue_id, issue_title, issue_identifier, agent_id, agent_name, kind, mode, event_types, filter_actor_type, filter_actor_id, filter_actor_name, filter_agent_id, filter_agent_name, filter_task_id, interval_seconds, cron_expression, timezone, next_fire_at, enabled, revision, disabled_at, last_task_id, last_error, created_at, expires_at, expiry_seconds, on_timeout, timed_out_at, condition, max_fires, fire_count, paused_reason, created_by_agent, created_by_name, source_agent_id, source_agent_name, issue_closed, can_manage, active_runs, source, rule, system_stage, target_type, system_remaining, scope FROM classified WHERE ($5::text='all' OR scope= $5)
- AND ($6::text='all' OR ($6='event' AND kind='event') OR ($6='at' AND kind='at') OR ($6='recurring' AND kind IN ('every','cron')))
- AND ($7::text='' OR source= $7)
- AND ($8::text='' OR agent_id::text= $8)
- AND ($9::text='' OR strpos(lower(issue_title||' '||issue_identifier||' '||agent_name),lower($9))>0)
+ SELECT id, issue_id, issue_title, issue_identifier, agent_id, agent_name, kind, mode, event_types, filter_actor_type, filter_actor_id, filter_actor_name, filter_agent_id, filter_agent_name, filter_task_id, interval_seconds, cron_expression, timezone, next_fire_at, enabled, revision, disabled_at, last_task_id, last_error, created_at, expires_at, expiry_seconds, on_timeout, timed_out_at, condition, max_fires, fire_count, paused_reason, created_by_agent, created_by_name, source_agent_id, source_agent_name, issue_closed, can_manage, active_runs, source, rule, system_stage, target_type, system_remaining, scope FROM classified WHERE ($6::text='all' OR scope= $6)
+ AND ($7::text='all' OR ($7='event' AND kind='event') OR ($7='at' AND kind='at') OR ($7='recurring' AND kind IN ('every','cron')))
+ AND ($8::text='' OR source= $8)
+ AND ($9::text='' OR agent_id::text= $9)
+ AND ($10::text='' OR strpos(lower(issue_title||' '||issue_identifier||' '||agent_name),lower($10))>0)
), page AS (
- SELECT id, issue_id, issue_title, issue_identifier, agent_id, agent_name, kind, mode, event_types, filter_actor_type, filter_actor_id, filter_actor_name, filter_agent_id, filter_agent_name, filter_task_id, interval_seconds, cron_expression, timezone, next_fire_at, enabled, revision, disabled_at, last_task_id, last_error, created_at, expires_at, expiry_seconds, on_timeout, timed_out_at, condition, max_fires, fire_count, paused_reason, created_by_agent, created_by_name, source_agent_id, source_agent_name, issue_closed, can_manage, active_runs, source, rule, system_stage, target_type, system_remaining, scope FROM filtered ORDER BY created_at DESC,id DESC LIMIT $11::int OFFSET $10::int
+ SELECT id, issue_id, issue_title, issue_identifier, agent_id, agent_name, kind, mode, event_types, filter_actor_type, filter_actor_id, filter_actor_name, filter_agent_id, filter_agent_name, filter_task_id, interval_seconds, cron_expression, timezone, next_fire_at, enabled, revision, disabled_at, last_task_id, last_error, created_at, expires_at, expiry_seconds, on_timeout, timed_out_at, condition, max_fires, fire_count, paused_reason, created_by_agent, created_by_name, source_agent_id, source_agent_name, issue_closed, can_manage, active_runs, source, rule, system_stage, target_type, system_remaining, scope FROM filtered ORDER BY created_at DESC,id DESC LIMIT $12::int OFFSET $11::int
), details AS (
SELECT p.id, p.issue_id, p.issue_title, p.issue_identifier, p.agent_id, p.agent_name, p.kind, p.mode, p.event_types, p.filter_actor_type, p.filter_actor_id, p.filter_actor_name, p.filter_agent_id, p.filter_agent_name, p.filter_task_id, p.interval_seconds, p.cron_expression, p.timezone, p.next_fire_at, p.enabled, p.revision, p.disabled_at, p.last_task_id, p.last_error, p.created_at, p.expires_at, p.expiry_seconds, p.on_timeout, p.timed_out_at, p.condition, p.max_fires, p.fire_count, p.paused_reason, p.created_by_agent, p.created_by_name, p.source_agent_id, p.source_agent_name, p.issue_closed, p.can_manage, p.active_runs, p.source, p.rule, p.system_stage, p.target_type, p.system_remaining, p.scope,r.status AS last_task_status,
(SELECT count(*) FROM agent_task_queue t7 WHERE t7.context->>'wakeup_id'=p.id::text AND t7.issue_id=p.issue_id
@@ -137,17 +141,18 @@ SELECT jsonb_build_object(
`
type ListWorkspaceWakeupsParams struct {
- AgentIds []pgtype.UUID `json:"agent_ids"`
- MemberID pgtype.UUID `json:"member_id"`
- IsAdmin bool `json:"is_admin"`
- WorkspaceID pgtype.UUID `json:"workspace_id"`
- Scope string `json:"scope"`
- Kind string `json:"kind"`
- Source string `json:"source"`
- AgentID string `json:"agent_id"`
- Search string `json:"search"`
- PageOffset int32 `json:"page_offset"`
- PageLimit int32 `json:"page_limit"`
+ AgentIds []pgtype.UUID `json:"agent_ids"`
+ MemberID pgtype.UUID `json:"member_id"`
+ IsAdmin bool `json:"is_admin"`
+ WorkspaceID pgtype.UUID `json:"workspace_id"`
+ HiddenProjectIds []pgtype.UUID `json:"hidden_project_ids"`
+ Scope string `json:"scope"`
+ Kind string `json:"kind"`
+ Source string `json:"source"`
+ AgentID string `json:"agent_id"`
+ Search string `json:"search"`
+ PageOffset int32 `json:"page_offset"`
+ PageLimit int32 `json:"page_limit"`
}
// Counts, filter choices, and page share one snapshot and the same access scope.
@@ -157,6 +162,7 @@ func (q *Queries) ListWorkspaceWakeups(ctx context.Context, arg ListWorkspaceWak
arg.MemberID,
arg.IsAdmin,
arg.WorkspaceID,
+ arg.HiddenProjectIds,
arg.Scope,
arg.Kind,
arg.Source,
diff --git a/server/pkg/db/queries/wakeup.sql b/server/pkg/db/queries/wakeup.sql
index 42ad9f7492..135b082b63 100644
--- a/server/pkg/db/queries/wakeup.sql
+++ b/server/pkg/db/queries/wakeup.sql
@@ -46,6 +46,8 @@ LEFT JOIN member actor_member ON w.filter_actor_type='member' AND actor_member.u
LEFT JOIN "user" actor_user ON actor_user.id=actor_member.user_id
LEFT JOIN agent source ON source.id=w.filter_agent_id AND source.workspace_id=w.workspace_id AND source.id=ANY(@agent_ids::uuid[])
WHERE w.workspace_id= @workspace_id AND w.enabled
+ -- MUL-8472: private projects the caller cannot see.
+ AND (sqlc.narg('hidden_project_ids')::uuid[] IS NULL OR i.project_id IS NULL OR NOT (i.project_id = ANY(sqlc.narg('hidden_project_ids')::uuid[])))
AND i.status NOT IN ('done','cancelled')
AND NOT EXISTS(SELECT 1 FROM issue_status s WHERE s.workspace_id=i.workspace_id AND s.key=i.status AND s.category IN ('done','closed'))
)
@@ -277,6 +279,8 @@ DELETE FROM issue_wakeup WHERE id= @id AND issue_id= @issue_id;
SELECT w.issue_id,w.id,w.agent_id,w.paused_reason
FROM issue_wakeup w JOIN issue i ON i.id=w.issue_id AND i.workspace_id=w.workspace_id
WHERE w.workspace_id= @workspace_id AND NOT w.enabled AND w.paused_reason IN ('loop','rate','max_fires')
+ -- MUL-8472: private projects the caller cannot see.
+ AND (sqlc.narg('hidden_project_ids')::uuid[] IS NULL OR i.project_id IS NULL OR NOT (i.project_id = ANY(sqlc.narg('hidden_project_ids')::uuid[])))
AND i.status NOT IN ('done','cancelled')
AND NOT EXISTS(SELECT 1 FROM issue_status s WHERE s.workspace_id=i.workspace_id AND s.key=i.status AND s.category IN ('done','closed'))
ORDER BY w.updated_at DESC LIMIT 200;
diff --git a/server/pkg/db/queries/workspace_wakeup.sql b/server/pkg/db/queries/workspace_wakeup.sql
index 50e3e29862..241e4dbb6b 100644
--- a/server/pkg/db/queries/workspace_wakeup.sql
+++ b/server/pkg/db/queries/workspace_wakeup.sql
@@ -37,6 +37,8 @@ LEFT JOIN "user" actor_user ON actor_user.id=actor_member.user_id
AND t.status IN ('queued','deferred','dispatched','running','waiting_local_directory')
) r ON true
WHERE w.workspace_id= @workspace_id AND w.system_rule IS NULL
+ -- MUL-8472: private projects the caller cannot see.
+ AND (sqlc.narg('hidden_project_ids')::uuid[] IS NULL OR i.project_id IS NULL OR NOT (i.project_id = ANY(sqlc.narg('hidden_project_ids')::uuid[])))
UNION ALL
-- The child-done system rule of each open parent that still waits for a
-- sub-issue: every child when unstaged, else its lowest unfinished stage.
@@ -75,6 +77,8 @@ LEFT JOIN "user" actor_user ON actor_user.id=actor_member.user_id
AND t.status IN ('queued','deferred','dispatched','running','waiting_local_directory')
) sr ON true
WHERE w.workspace_id= @workspace_id AND w.system_rule IS NOT NULL AND agg.open_count>0
+ -- MUL-8472: private projects the caller cannot see.
+ AND (sqlc.narg('hidden_project_ids')::uuid[] IS NULL OR p.project_id IS NULL OR NOT (p.project_id = ANY(sqlc.narg('hidden_project_ids')::uuid[])))
AND p.status NOT IN ('done','cancelled')
AND NOT EXISTS(SELECT 1 FROM issue_status s WHERE s.workspace_id=p.workspace_id AND s.key=p.status AND s.category IN ('done','closed'))
), classified AS (