Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(wakeup): preserve squad leader attribution for issue wakeups (#9427)
areslp51975f95fc0a
diff --git a/server/internal/service/issue_wakeup.go b/server/internal/service/issue_wakeup.goindex 3dda35fea5..c552007ae2 100644--- a/server/internal/service/issue_wakeup.go+++ b/server/internal/service/issue_wakeup.go@@ -1323,8 +1323,22 @@ func (s *IssueWakeupService) dispatch(ctx context.Context, prev db.IssueWakeup)if err = guardIssueNotInTriage(ctx, q, issue.ID, OriginNamed); err != nil {return err}+ var squadID pgtype.UUID+ if issue.AssigneeType.String == "squad" && issue.AssigneeID.Valid {+ squad, squadErr := q.GetSquadInWorkspace(ctx, db.GetSquadInWorkspaceParams{+ ID: issue.AssigneeID, WorkspaceID: issue.WorkspaceID,+ })+ if squadErr != nil && !errors.Is(squadErr, pgx.ErrNoRows) {+ return squadErr+ }+ // Only the issue's current, active squad leader gets leader authority.+ // Other wakeup targets remain ordinary agent turns.+ if squadErr == nil && !squad.ArchivedAt.Valid && squad.LeaderID == agent.ID {+ squadID = squad.ID+ }+ }contextJSON, _ := json.Marshal(map[string]any{"wakeup_id": util.UUIDToString(w.ID), "wakeup_revision": w.Revision, "wakeup_evidence": evidence, "wakeup_chain": chain})- task, err = q.CreateWakeupTask(ctx, db.CreateWakeupTaskParams{ID: dbid.NewV7(), AgentID: w.AgentID, RuntimeID: agent.RuntimeID, IssueID: w.IssueID, Priority: priorityToInt(issue.Priority), TriggerCommentID: w.ParentCommentID, TriggerSummary: pgtype.Text{String: "Wakeup: " + truncateForSummary(w.Instruction, 160), Valid: true}, HandoffNote: pgtype.Text{String: noteText, Valid: true}, OriginatorUserID: w.CreatedBy, AccountableUserID: w.CreatedBy, OriginatorSource: pgtype.Text{String: "trigger_owner", Valid: true}, TriggerEvidenceKind: pgtype.Text{String: "issue_wakeup", Valid: true}, TriggerEvidenceRefID: w.ID, DelegatedFromTaskID: w.SourceTaskID, WakeupContext: contextJSON, RuntimeMcpOverlay: overlay.Overlay, RuntimeConnectedApps: overlay.ConnectedApps})+ task, err = q.CreateWakeupTask(ctx, db.CreateWakeupTaskParams{ID: dbid.NewV7(), AgentID: w.AgentID, RuntimeID: agent.RuntimeID, IssueID: w.IssueID, Priority: priorityToInt(issue.Priority), TriggerCommentID: w.ParentCommentID, TriggerSummary: pgtype.Text{String: "Wakeup: " + truncateForSummary(w.Instruction, 160), Valid: true}, HandoffNote: pgtype.Text{String: noteText, Valid: true}, IsLeaderTask: pgtype.Bool{Bool: squadID.Valid, Valid: true}, SquadID: squadID, OriginatorUserID: w.CreatedBy, AccountableUserID: w.CreatedBy, OriginatorSource: pgtype.Text{String: "trigger_owner", Valid: true}, TriggerEvidenceKind: pgtype.Text{String: "issue_wakeup", Valid: true}, TriggerEvidenceRefID: w.ID, DelegatedFromTaskID: w.SourceTaskID, WakeupContext: contextJSON, RuntimeMcpOverlay: overlay.Overlay, RuntimeConnectedApps: overlay.ConnectedApps})}if err != nil {return errdiff --git a/server/internal/service/issue_wakeup_squad_test.go b/server/internal/service/issue_wakeup_squad_test.gonew file mode 100644index 0000000000..85ceb43f61--- /dev/null+++ b/server/internal/service/issue_wakeup_squad_test.go@@ -0,0 +1,80 @@+package service++import (+ "context"+ "testing"++ "github.com/jackc/pgx/v5/pgtype"+ "github.com/multica-ai/multica/server/internal/util"+ db "github.com/multica-ai/multica/server/pkg/db/generated"+)++func TestIssueWakeupSquadLeaderAttribution(t *testing.T) {+ for _, tc := range []struct {+ name string+ assignee string+ otherLead bool+ archived bool+ rotated bool+ foreign bool+ wantLeader bool+ }{+ {name: "current squad leader", assignee: "squad", wantLeader: true},+ {name: "ordinary squad worker", assignee: "squad", otherLead: true},+ {name: "individually assigned leader", assignee: "agent"},+ {name: "archived squad", assignee: "squad", archived: true},+ {name: "leader rotated before dispatch", assignee: "squad", rotated: true},+ {name: "cross workspace squad", assignee: "squad", foreign: true},+ } {+ t.Run(tc.name, func(t *testing.T) {+ f, s, issue, agent := wakeFixture(t)+ leader := agent+ if tc.otherLead {+ leader = f.privateAgentOwnedBy(t, f.UserID, "other leader")+ }+ squad := f.Squad(t, "Wakeup squad", leader)+ f.SquadMember(t, squad, "agent", agent)+ if tc.foreign {+ other, _ := newPrincipalFixture(t)+ squad = other.Squad(t, "Foreign squad", agent)+ }+ assignee := squad+ if tc.assignee == "agent" {+ assignee = agent+ }+ f.Exec(t, "UPDATE issue SET assignee_type=$2,assignee_id=$3 WHERE id=$1", issue, tc.assignee, assignee)+ if tc.archived {+ f.Exec(t, "UPDATE squad SET archived_at=now() WHERE id=$1", squad)+ }+ w := wakeCreate(t, f, s, issue, WakeupInput{+ AgentID: agent, Kind: "at", AfterSeconds: 1, Instruction: "Record the evaluation",+ })+ if tc.rotated {+ next := f.privateAgentOwnedBy(t, f.UserID, "replacement leader")+ f.Exec(t, "UPDATE squad SET leader_id=$2 WHERE id=$1", squad, next)+ }+ f.Exec(t, "UPDATE issue_wakeup SET next_fire_at=now()-interval '1 second' WHERE id=$1", w.ID)+ wakeDispatch(t, s, w)+ current, err := f.q.GetIssueWakeup(context.Background(), db.GetIssueWakeupParams{+ ID: w.ID, WorkspaceID: w.WorkspaceID,+ })+ if err != nil {+ t.Fatal(err)+ }+ task, err := f.q.GetAgentTask(context.Background(), current.LastTaskID)+ if err != nil {+ t.Fatal(err)+ }+ if task.IsLeaderTask != tc.wantLeader {+ t.Fatalf("is_leader_task=%v, want %v", task.IsLeaderTask, tc.wantLeader)+ }+ wantSquad := pgtype.UUID{}+ if tc.wantLeader {+ wantSquad = parseTestUUID(t, squad)+ }+ if task.SquadID != wantSquad {+ t.Fatalf("squad_id=%s, want %s", util.UUIDToString(task.SquadID), util.UUIDToString(wantSquad))+ }+ })+ }+}