Skip to content

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

Go

fix(issues): allow verified autopilot child assignment (MUL-6161) (#7275)

iiwish3d47913c8526
diff --git a/server/internal/handler/agent_access.go b/server/internal/handler/agent_access.go
index 76358079e4..13bf98d520 100644
--- a/server/internal/handler/agent_access.go
+++ b/server/internal/handler/agent_access.go
@@ -224,6 +224,18 @@ func (h *Handler) invokeOriginatorFromRequest(r *http.Request, actorType, actorI
return ""
}
+// effectiveInvocationAuthorityFromRequest returns the human principal used by
+// canInvokeAgent without changing attribution. A real top-of-chain originator
+// always wins. Only an unattributed agent request may fall back to the creator
+// of a lineage-verified autopilot issue supplied by the caller.
+func (h *Handler) effectiveInvocationAuthorityFromRequest(r *http.Request, delegationIssue *db.Issue, actorType, actorID string) string {
+ originatorUserID := h.invokeOriginatorFromRequest(r, actorType, actorID)
+ if originatorUserID != "" || delegationIssue == nil {
+ return originatorUserID
+ }
+ return h.autopilotDelegationAuthorityFromRequest(r, *delegationIssue, actorType, actorID)
+}
+
// autopilotDelegationAuthority resolves the effective invoking human for the A2A
// invoke gate (canInvokeAgent) when a trigger comment is authored by an
// UNATTRIBUTED autopilot dispatch delegating mid-chain on the very issue that
diff --git a/server/internal/handler/issue.go b/server/internal/handler/issue.go
index f49b505357..c785b14d88 100644
--- a/server/internal/handler/issue.go
+++ b/server/internal/handler/issue.go
@@ -2645,6 +2645,7 @@ func (h *Handler) QuickCreateIssue(w http.ResponseWriter, r *http.Request) {
r.Context(), r, workspaceID,
pgtype.Text{String: "agent", Valid: true},
agentUUID,
+ nil,
); status != 0 {
writeError(w, status, msg)
return
@@ -2937,13 +2938,33 @@ func (h *Handler) CreateIssue(w http.ResponseWriter, r *http.Request) {
assigneeID = id
}
- if status, msg := h.validateAssigneePair(r.Context(), r, workspaceID, assigneeType, assigneeID); status != 0 {
+ var parentIssueID pgtype.UUID
+ var projectID pgtype.UUID
+ var parentIssue *db.Issue
+ if req.ParentIssueID != nil {
+ id, ok := parseUUIDOrBadRequest(w, *req.ParentIssueID, "parent_issue_id")
+ if !ok {
+ return
+ }
+ parentIssueID = id
+ if assigneeType.Valid && (assigneeType.String == "agent" || assigneeType.String == "squad") {
+ parent, err := h.Queries.GetIssueInWorkspace(r.Context(), db.GetIssueInWorkspaceParams{
+ ID: parentIssueID,
+ WorkspaceID: wsUUID,
+ })
+ if err != nil || !parent.ID.Valid {
+ writeError(w, http.StatusBadRequest, "parent issue not found in this workspace")
+ return
+ }
+ parentIssue = &parent
+ }
+ }
+
+ if status, msg := h.validateAssigneePair(r.Context(), r, workspaceID, assigneeType, assigneeID, parentIssue); status != 0 {
writeError(w, status, msg)
return
}
- var parentIssueID pgtype.UUID
- var projectID pgtype.UUID
if req.ProjectID != nil {
id, ok := parseUUIDOrBadRequest(w, *req.ProjectID, "project_id")
if !ok {
@@ -2951,17 +2972,10 @@ func (h *Handler) CreateIssue(w http.ResponseWriter, r *http.Request) {
}
projectID = id
}
- if req.ParentIssueID != nil {
- id, ok := parseUUIDOrBadRequest(w, *req.ParentIssueID, "parent_issue_id")
- if !ok {
- return
- }
- parentIssueID = id
- }
- // Cross-workspace parent / project existence is enforced inside
- // IssueService.Create (atomically with the create), so every entry
- // point — HTTP, Lark, future MCP — gets the same boundary check
- // without duplicating the lookup here.
+ // Project existence and the final parent boundary check are enforced inside
+ // IssueService.Create atomically with the create. The handler preloads a
+ // supplied parent only because the assignee gate must bind any autopilot
+ // authority fallback to that server-verified issue before admission.
attachmentIDs, ok := parseUUIDSliceOrBadRequest(w, req.AttachmentIDs, "attachment_ids")
if !ok {
@@ -3587,7 +3601,7 @@ func (h *Handler) UpdateIssue(w http.ResponseWriter, r *http.Request) {
_, touchedType := rawFields["assignee_type"]
_, touchedID := rawFields["assignee_id"]
if touchedType || touchedID {
- if status, msg := h.validateAssigneePair(r.Context(), r, workspaceID, params.AssigneeType, params.AssigneeID); status != 0 {
+ if status, msg := h.validateAssigneePair(r.Context(), r, workspaceID, params.AssigneeType, params.AssigneeID, nil); status != 0 {
writeError(w, status, msg)
return
}
@@ -3741,11 +3755,15 @@ func (h *Handler) UpdateIssue(w http.ResponseWriter, r *http.Request) {
// That means owner-only for a private agent, with NO workspace-admin bypass
// and NO unconditional agent-to-agent bypass — an agent caller (X-Agent-ID) is
// judged by the top-of-chain human originator like everywhere else.
+// delegationIssue is non-nil only for child creation. It lets an unattributed
+// autopilot task borrow the parent autopilot creator's invoke rights after the
+// request task has been verified against that exact parent; it never changes
+// the new issue or task attribution.
//
// Returns (statusCode, errorMessage). statusCode == 0 means the pair is valid;
// callers should treat any non-zero status as a rejection and surface it back
// to the client.
-func (h *Handler) validateAssigneePair(ctx context.Context, r *http.Request, workspaceID string, assigneeType pgtype.Text, assigneeID pgtype.UUID) (int, string) {
+func (h *Handler) validateAssigneePair(ctx context.Context, r *http.Request, workspaceID string, assigneeType pgtype.Text, assigneeID pgtype.UUID, delegationIssue *db.Issue) (int, string) {
// Both unset → unassigned issue, valid.
if !assigneeType.Valid && !assigneeID.Valid {
return 0, ""
@@ -3779,7 +3797,8 @@ func (h *Handler) validateAssigneePair(ctx context.Context, r *http.Request, wor
return http.StatusBadRequest, "cannot assign to archived agent"
}
actorType, actorID := h.resolveActor(r, requestUserID(r), workspaceID)
- if !h.canInvokeAgent(ctx, agent, actorType, actorID, h.invokeOriginatorFromRequest(r, actorType, actorID), workspaceID) {
+ effectiveInvoker := h.effectiveInvocationAuthorityFromRequest(r, delegationIssue, actorType, actorID)
+ if !h.canInvokeAgent(ctx, agent, actorType, actorID, effectiveInvoker, workspaceID) {
// Names the missing permission, not the target's configuration: the
// old "private agent" wording both disclosed the agent's permission
// mode and was simply wrong for a `public_to` agent scoped to
@@ -3807,7 +3826,8 @@ func (h *Handler) validateAssigneePair(ctx context.Context, r *http.Request, wor
return http.StatusBadRequest, "squad leader is archived; cannot assign to this squad"
}
actorType, actorID := h.resolveActor(r, requestUserID(r), workspaceID)
- if !h.canInvokeAgent(ctx, leader, actorType, actorID, h.invokeOriginatorFromRequest(r, actorType, actorID), workspaceID) {
+ effectiveInvoker := h.effectiveInvocationAuthorityFromRequest(r, delegationIssue, actorType, actorID)
+ if !h.canInvokeAgent(ctx, leader, actorType, actorID, effectiveInvoker, workspaceID) {
// Same wording rule as the agent branch above; "this squad"
// avoids disclosing the leader agent's permission mode.
return http.StatusForbidden, "you do not have permission to assign work to this squad"
@@ -4319,7 +4339,7 @@ func (h *Handler) BatchUpdateIssues(w http.ResponseWriter, r *http.Request) {
_, batchTouchedType := rawUpdates["assignee_type"]
_, batchTouchedID := rawUpdates["assignee_id"]
if batchTouchedType || batchTouchedID {
- if status, _ := h.validateAssigneePair(r.Context(), r, workspaceID, params.AssigneeType, params.AssigneeID); status != 0 {
+ if status, _ := h.validateAssigneePair(r.Context(), r, workspaceID, params.AssigneeType, params.AssigneeID, nil); status != 0 {
continue
}
}
diff --git a/server/internal/handler/issue_autopilot_assignment_authority_test.go b/server/internal/handler/issue_autopilot_assignment_authority_test.go
new file mode 100644
index 0000000000..c84acc6a1a
--- /dev/null
+++ b/server/internal/handler/issue_autopilot_assignment_authority_test.go
@@ -0,0 +1,217 @@
+package handler
+
+import (
+ "net/http"
+ "strings"
+ "testing"
+
+ "github.com/multica-ai/multica/server/internal/testutil"
+)
+
+func autopilotChildIssueRequest(t *testing.T, assigneeType, assigneeID, parentIssueID, status, actorAgentID, taskID string) *http.Request {
+ t.Helper()
+
+ r := newRequest(http.MethodPost, "/api/issues?workspace_id="+testWorkspaceID, map[string]any{
+ "title": "autopilot private-assignee child " + t.Name(),
+ "status": status,
+ "priority": "low",
+ "assignee_type": assigneeType,
+ "assignee_id": assigneeID,
+ "parent_issue_id": parentIssueID,
+ "allow_duplicate": true,
+ })
+ if actorAgentID != "" {
+ r.Header.Set("X-Agent-ID", actorAgentID)
+ }
+ if taskID != "" {
+ r.Header.Set("X-Task-ID", taskID)
+ }
+ return r
+}
+
+func cleanupAutopilotChildIssue(t *testing.T, issueID string) {
+ t.Helper()
+ dbfx.Cleanup(t, `DELETE FROM issue WHERE id = $1`, issueID)
+ dbfx.Cleanup(t, `DELETE FROM agent_task_queue WHERE issue_id = $1`, issueID)
+}
+
+func TestCreateIssue_AutopilotLeaderAssignsPrivateWorker(t *testing.T) {
+ if testHandler == nil || testPool == nil {
+ t.Skip("database not available")
+ }
+
+ t.Run("verified lineage parks backlog child without enqueue", func(t *testing.T) {
+ workerID, ownerID, _ := privateAgentTestFixture(t)
+ fx := newAutopilotDelegationFixture(t, workerID, ownerID, "autopilot")
+ parentIssueID := uuidToString(fx.Issue.ID)
+
+ var created IssueResponse
+ testutil.Call(t, testHandler.CreateIssue,
+ autopilotChildIssueRequest(t, "agent", workerID, parentIssueID, "backlog", fx.LeaderAgentID, fx.LeaderTaskID),
+ ).Want(http.StatusCreated).JSON(&created)
+ cleanupAutopilotChildIssue(t, created.ID)
+ if created.ParentIssueID == nil || *created.ParentIssueID != parentIssueID {
+ t.Fatalf("created child parent_issue_id = %v, want %q", created.ParentIssueID, parentIssueID)
+ }
+ if created.AssigneeType == nil || *created.AssigneeType != "agent" || created.AssigneeID == nil || *created.AssigneeID != workerID {
+ t.Fatalf("created child assignee = (%v, %v), want (agent, %s)", created.AssigneeType, created.AssigneeID, workerID)
+ }
+
+ var queued int
+ dbfx.QueryRow(t, `
+ SELECT count(*) FROM agent_task_queue
+ WHERE issue_id = $1 AND agent_id = $2
+ `, created.ID, workerID).Scan(&queued)
+ if queued != 0 {
+ t.Fatalf("backlog child must not enqueue the private worker, got %d tasks", queued)
+ }
+ })
+
+ t.Run("verified lineage creates active child and enqueues once", func(t *testing.T) {
+ workerID, ownerID, _ := privateAgentTestFixture(t)
+ fx := newAutopilotDelegationFixture(t, workerID, ownerID, "autopilot")
+
+ var created IssueResponse
+ testutil.Call(t, testHandler.CreateIssue,
+ autopilotChildIssueRequest(t, "agent", workerID, uuidToString(fx.Issue.ID), "todo", fx.LeaderAgentID, fx.LeaderTaskID),
+ ).Want(http.StatusCreated).JSON(&created)
+ cleanupAutopilotChildIssue(t, created.ID)
+
+ var taskCount int
+ var originatorCount int
+ dbfx.QueryRow(t, `
+ SELECT count(*), count(originator_user_id) FROM agent_task_queue
+ WHERE issue_id = $1 AND agent_id = $2
+ `, created.ID, workerID).Scan(&taskCount, &originatorCount)
+ if taskCount != 1 {
+ t.Fatalf("active child must enqueue the private worker exactly once, got %d tasks", taskCount)
+ }
+ if originatorCount != 0 {
+ t.Fatal("autopilot creator authority is authorization-only; worker task must remain unattributed")
+ }
+ })
+
+ t.Run("verified lineage creates squad child and enqueues its private leader once", func(t *testing.T) {
+ workerID, ownerID, _ := privateAgentTestFixture(t)
+ fx := newAutopilotDelegationFixture(t, workerID, ownerID, "autopilot")
+ squadID := dbfx.Squad(t, "Autopilot Private Leader Squad", workerID)
+
+ var created IssueResponse
+ testutil.Call(t, testHandler.CreateIssue,
+ autopilotChildIssueRequest(t, "squad", squadID, uuidToString(fx.Issue.ID), "todo", fx.LeaderAgentID, fx.LeaderTaskID),
+ ).Want(http.StatusCreated).JSON(&created)
+ cleanupAutopilotChildIssue(t, created.ID)
+ if created.AssigneeType == nil || *created.AssigneeType != "squad" || created.AssigneeID == nil || *created.AssigneeID != squadID {
+ t.Fatalf("created child assignee = (%v, %v), want (squad, %s)", created.AssigneeType, created.AssigneeID, squadID)
+ }
+
+ var taskCount int
+ var originatorCount int
+ var squadTaskCount int
+ dbfx.QueryRow(t, `
+ SELECT count(*), count(originator_user_id), count(*) FILTER (WHERE squad_id = $3)
+ FROM agent_task_queue
+ WHERE issue_id = $1 AND agent_id = $2
+ `, created.ID, workerID, squadID).Scan(&taskCount, &originatorCount, &squadTaskCount)
+ if taskCount != 1 || squadTaskCount != 1 {
+ t.Fatalf("active squad child must enqueue its private leader exactly once with squad lineage, got %d tasks (%d with squad_id)", taskCount, squadTaskCount)
+ }
+ if originatorCount != 0 {
+ t.Fatal("autopilot creator authority is authorization-only; squad leader task must remain unattributed")
+ }
+ })
+
+ t.Run("creator without invoke rights is denied", func(t *testing.T) {
+ workerID, _, plainMemberID := privateAgentTestFixture(t)
+ fx := newAutopilotDelegationFixture(t, workerID, plainMemberID, "autopilot")
+
+ testutil.Call(t, testHandler.CreateIssue,
+ autopilotChildIssueRequest(t, "agent", workerID, uuidToString(fx.Issue.ID), "backlog", fx.LeaderAgentID, fx.LeaderTaskID),
+ ).Want(http.StatusForbidden)
+ })
+
+ t.Run("real originator takes precedence over autopilot creator", func(t *testing.T) {
+ workerID, ownerID, plainMemberID := privateAgentTestFixture(t)
+ fx := newAutopilotDelegationFixture(t, workerID, ownerID, "autopilot")
+ dbfx.Exec(t, `
+ UPDATE agent_task_queue
+ SET originator_user_id = $1, accountable_user_id = $1, originator_source = 'direct_human'
+ WHERE id = $2
+ `, plainMemberID, fx.LeaderTaskID)
+
+ testutil.Call(t, testHandler.CreateIssue,
+ autopilotChildIssueRequest(t, "agent", workerID, uuidToString(fx.Issue.ID), "backlog", fx.LeaderAgentID, fx.LeaderTaskID),
+ ).Want(http.StatusForbidden)
+ })
+
+ t.Run("missing task lineage is denied", func(t *testing.T) {
+ workerID, ownerID, _ := privateAgentTestFixture(t)
+ fx := newAutopilotDelegationFixture(t, workerID, ownerID, "autopilot")
+
+ testutil.Call(t, testHandler.CreateIssue,
+ autopilotChildIssueRequest(t, "agent", workerID, uuidToString(fx.Issue.ID), "backlog", fx.LeaderAgentID, ""),
+ ).Want(http.StatusForbidden)
+ })
+
+ t.Run("task actor mismatch is denied", func(t *testing.T) {
+ workerID, ownerID, _ := privateAgentTestFixture(t)
+ fx := newAutopilotDelegationFixture(t, workerID, ownerID, "autopilot")
+ workerTaskID := seedTaskOnIssue(t, workerID, uuidToString(fx.Issue.ID), fx.RuntimeID)
+
+ testutil.Call(t, testHandler.CreateIssue,
+ autopilotChildIssueRequest(t, "agent", workerID, uuidToString(fx.Issue.ID), "backlog", fx.LeaderAgentID, workerTaskID),
+ ).Want(http.StatusForbidden)
+ })
+
+ t.Run("task bound to another issue is denied", func(t *testing.T) {
+ workerID, ownerID, _ := privateAgentTestFixture(t)
+ fx := newAutopilotDelegationFixture(t, workerID, ownerID, "autopilot")
+ otherIssueID := seedBareIssue(t, fx.LeaderAgentID)
+ otherTaskID := seedTaskOnIssue(t, fx.LeaderAgentID, otherIssueID, fx.RuntimeID)
+
+ testutil.Call(t, testHandler.CreateIssue,
+ autopilotChildIssueRequest(t, "agent", workerID, uuidToString(fx.Issue.ID), "backlog", fx.LeaderAgentID, otherTaskID),
+ ).Want(http.StatusForbidden)
+ })
+
+ t.Run("cross-workspace parent is rejected before assignee authorization", func(t *testing.T) {
+ workerID, ownerID, _ := privateAgentTestFixture(t)
+ fx := newAutopilotDelegationFixture(t, workerID, ownerID, "autopilot")
+ squadID := dbfx.Squad(t, "Autopilot Cross-Workspace Squad", workerID)
+ foreignWorkspaceID := dbfx.Workspace(t, "Autopilot Foreign Parent", "autopilot-foreign-parent-"+workerID[:8])
+ foreignParentID := dbfx.Issue(t, "Autopilot foreign parent", testutil.Cols{
+ "workspace_id": foreignWorkspaceID,
+ "number": 1,
+ })
+
+ for _, target := range []struct {
+ name, assigneeType, assigneeID string
+ }{
+ {name: "agent", assigneeType: "agent", assigneeID: workerID},
+ {name: "squad", assigneeType: "squad", assigneeID: squadID},
+ } {
+ t.Run(target.name, func(t *testing.T) {
+ resp := testutil.Call(t, testHandler.CreateIssue,
+ autopilotChildIssueRequest(t, target.assigneeType, target.assigneeID, foreignParentID, "backlog", fx.LeaderAgentID, fx.LeaderTaskID),
+ ).Want(http.StatusBadRequest)
+ if !strings.Contains(resp.Text(), "parent issue not found in this workspace") {
+ t.Fatalf("cross-workspace parent rejection = %q, want workspace boundary error", resp.Text())
+ }
+
+ title := "autopilot private-assignee child " + t.Name()
+ if count := dbfx.Count(t, `SELECT count(*) FROM issue WHERE workspace_id = $1 AND title = $2`, testWorkspaceID, title); count != 0 {
+ t.Fatalf("cross-workspace parent rejection created %d issue rows", count)
+ }
+ })
+ }
+ })
+
+ t.Run("non-autopilot parent is denied", func(t *testing.T) {
+ workerID, ownerID, _ := privateAgentTestFixture(t)
+ fx := newAutopilotDelegationFixture(t, workerID, ownerID, "")
+
+ testutil.Call(t, testHandler.CreateIssue,
+ autopilotChildIssueRequest(t, "agent", workerID, uuidToString(fx.Issue.ID), "backlog", fx.LeaderAgentID, fx.LeaderTaskID),
+ ).Want(http.StatusForbidden)
+ })
+}
diff --git a/server/internal/handler/source_context.go b/server/internal/handler/source_context.go
index 7dbf78d64c..4aaa415978 100644
--- a/server/internal/handler/source_context.go
+++ b/server/internal/handler/source_context.go
@@ -641,7 +641,7 @@ func (h *Handler) createManualCommentSubIssue(w http.ResponseWriter, r *http.Req
}
assigneeID = parsed
}
- if code, message := h.validateAssigneePair(r.Context(), r, util.UUIDToString(workspaceID), assigneeType, assigneeID); code != 0 {
+ if code, message := h.validateAssigneePair(r.Context(), r, util.UUIDToString(workspaceID), assigneeType, assigneeID, nil); code != 0 {
writeError(w, code, message)
return errSourceContextResponseWritten
}
@@ -754,7 +754,7 @@ func (h *Handler) prepareAgentCommentSubIssue(w http.ResponseWriter, r *http.Req
}
agentID = parsed
}
- if status, message := h.validateAssigneePair(r.Context(), r, util.UUIDToString(workspaceID), pgtype.Text{String: "agent", Valid: true}, agentID); status != 0 {
+ if status, message := h.validateAssigneePair(r.Context(), r, util.UUIDToString(workspaceID), pgtype.Text{String: "agent", Valid: true}, agentID, nil); status != 0 {
writeError(w, status, message)
return nil, errSourceContextResponseWritten
}