Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(agents): hide working agents under a parent issue in a private project (#11576)
pseudoyu7071ce61c771
diff --git a/server/internal/handler/agent.go b/server/internal/handler/agent.goindex 83b78725e8..529603e216 100644--- a/server/internal/handler/agent.go+++ b/server/internal/handler/agent.go@@ -3321,13 +3321,27 @@ func (h *Handler) ListWorkspaceWorkingAgents(w http.ResponseWriter, r *http.Requif !ok {return}- // A private project the caller cannot see (MUL-8472) is answered like- // one with nobody working, so its agents and run count stay hidden.- hidden, ok := h.requestHiddenProjects(w, r, workspaceID)- if !ok {+ }++ // A project, or a parent issue's project, that is private and that the+ // caller cannot see (MUL-8472) is answered like one with nobody working,+ // so its agents and run count stay hidden.+ hidden, ok := h.requestHiddenProjects(w, r, workspaceID)+ if !ok {+ return+ }+ if projectID.Valid && !hidden.CanSeeProject(projectID) {+ writeJSON(w, http.StatusOK, []WorkspaceWorkingAgent{})+ return+ }+ if parentIssueID.Valid && !hidden.Empty() {+ parentProjectID, err := h.Queries.GetIssueProjectID(r.Context(), parentIssueID)+ if err != nil && !errors.Is(err, pgx.ErrNoRows) {+ writeProjectAccessError(w, r, workspaceID, err)return}- if !hidden.CanSeeProject(projectID) {+ // A missing parent is not hidden; the query below finds nothing.+ if err == nil && !hidden.CanSeeProject(parentProjectID) {writeJSON(w, http.StatusOK, []WorkspaceWorkingAgent{})return}@@ -3359,10 +3373,6 @@ func (h *Handler) ListWorkspaceWorkingAgents(w http.ResponseWriter, r *http.Requ// Issues in private projects the caller cannot see (MUL-8472) are left// out of issue_ids; the agent and its running count stay, as on the// redacted run list.- hidden, ok := h.requestHiddenProjects(w, r, workspaceID)- if !ok {- return- }var issueIDs []pgtype.UUIDfor _, row := range rows {issueIDs = append(issueIDs, row.IssueIds...)diff --git a/server/internal/handler/private_project_test.go b/server/internal/handler/private_project_test.goindex 50a719b9e2..a091fa7c33 100644--- a/server/internal/handler/private_project_test.go+++ b/server/internal/handler/private_project_test.go@@ -1134,3 +1134,27 @@ func TestPrivateProjectWorkingAgentsHiddenFromOutsiders(t *testing.T) {}}}++func TestPrivateProjectWorkingAgentsUnderHiddenParent(t *testing.T) {+ f := newPrivateProjectFixture(t)+ agentID := createHandlerTestAgent(t, f.marker+" sub-issue agent", []byte(`{}`))+ child := dbfx.Issue(t, f.marker+" secret sub-issue", testutil.Cols{"project_id": f.projectID, "parent_issue_id": f.secretIssue})+ dbfx.Task(t, agentID, testutil.Cols{"issue_id": child, "runtime_id": testRuntimeID, "status": "running", "started_at": time.Now()})+ for _, userID := range []string{f.outsider, f.outsideAdmin, f.insider} {+ req := asUser(newRequest(http.MethodGet, "/api/working-agents?type=issue&parent="+f.secretIssue, nil), userID)+ var agents []WorkspaceWorkingAgent+ testutil.Call(t, testHandler.ListWorkspaceWorkingAgents, req).Want(http.StatusOK).JSON(&agents)+ found := false+ for _, a := range agents {+ if a.ID == agentID {+ found = a.RunningTaskCount == 1+ }+ }+ if userID == f.insider && !found {+ t.Fatalf("project member lost the agent working under the issue: %+v", agents)+ }+ if userID != f.insider && len(agents) != 0 {+ t.Fatalf("working agents under a private issue exposed to %s: %+v", userID, agents)+ }+ }+}diff --git a/server/internal/handler/project_access.go b/server/internal/handler/project_access.goindex eafe2da942..cad6ca7241 100644--- a/server/internal/handler/project_access.go+++ b/server/internal/handler/project_access.go@@ -71,16 +71,22 @@ func (h *Handler) hiddenProjectsForAgentRun(ctx context.Context, workspaceID pgtfunc (h *Handler) requestHiddenProjects(w http.ResponseWriter, r *http.Request, workspaceID string) (projectaccess.Hidden, bool) {hidden, err := h.hiddenProjects(r, workspaceID)if err != nil {- if writeQueryCancellation(w, r, err) {- return projectaccess.Hidden{}, false- }- slog.Warn("resolve project access failed", append(logger.RequestAttrs(r), "workspace_id", workspaceID, "error", err)...)- writeError(w, http.StatusInternalServerError, "failed to resolve project access")+ writeProjectAccessError(w, r, workspaceID, err)return projectaccess.Hidden{}, false}return hidden, true}+// writeProjectAccessError answers a failed project access lookup: nothing for+// a request the client already cancelled, otherwise a logged 500.+func writeProjectAccessError(w http.ResponseWriter, r *http.Request, workspaceID string, err error) {+ if writeQueryCancellation(w, r, err) {+ return+ }+ slog.Warn("resolve project access failed", append(logger.RequestAttrs(r), "workspace_id", workspaceID, "error", err)...)+ writeError(w, http.StatusInternalServerError, "failed to resolve project access")+}+// requireProjectVisible writes status with notFoundMsg when projectID is a// private project the request may not see. Callers pass the status and// message they already use for a missing object: a hidden object must be