Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(inbox): treat squads called in with @squad as squad handoffs (MUL-10054) (#11398)
Jiayuan Zhangf63e89b4191d
diff --git a/apps/docs/content/docs/inbox.fr.mdx b/apps/docs/content/docs/inbox.fr.mdxindex 89af2e4979..276b357ba1 100644--- a/apps/docs/content/docs/inbox.fr.mdx+++ b/apps/docs/content/docs/inbox.fr.mdx@@ -171,7 +171,7 @@ En dessous, **Me notifier pour** active ou désactive chaque type de notificatio**Changements de statut** est désactivé par défaut ; tous les autres types sont activés. Un type désactivé ne crée aucune notification, et le réactiver ne fait pas revenir ce que vous avez manqué ; les changements restent enregistrés sur la tâche. Quelques types, comme les résultats de création rapide et les mises en pause d'automatisation, ne relèvent pas de ces groupes et sont toujours envoyés. Les notifications système et du navigateur contrôlent les bannières sur le bureau et ne modifient pas la boîte de réception elle-même.-Sous **Commentaires**, **Inclure les passations de squad** couvre les commentaires d'une tâche de squad par lesquels son chef et ses agents se transmettent le travail : le chef qui @-mentionne un agent ou une squad, et les agents qui lui rendent compte. Activé par défaut ; désactivez-le pour ne garder que les commentaires destinés à des personnes. Les commentaires qui vous @-mentionnent, vous ou quelqu'un d'autre, les réponses d'agent au commentaire d'une personne, les exécutions d'agent en échec et les statuts qui demandent votre attention arrivent toujours.+Sous **Commentaires**, **Inclure les passations de squad** couvre les commentaires par lesquels le chef d'une squad et ses agents se transmettent le travail, sur une tâche assignée à la squad ou sur laquelle la squad a été @-mentionnée : le chef qui @-mentionne un agent ou une squad, et les agents qui lui rendent compte. Activé par défaut ; désactivez-le pour ne garder que les commentaires destinés à des personnes. Les commentaires qui vous @-mentionnent, vous ou quelqu'un d'autre, les réponses d'agent au commentaire d'une personne, les exécutions d'agent en échec et les statuts qui demandent votre attention arrivent toujours.## Étapes suivantesdiff --git a/apps/docs/content/docs/inbox.ja.mdx b/apps/docs/content/docs/inbox.ja.mdxindex 080bef1a94..190f5105d7 100644--- a/apps/docs/content/docs/inbox.ja.mdx+++ b/apps/docs/content/docs/inbox.ja.mdx@@ -171,7 +171,7 @@ multica inbox snooze <id>... --until tomorrow # RFC 3339、30m、3h、1d、1w**ステータス変更** は既定でオフ、ほかの種類は既定でオンです。オフにした種類の通知は作られず、オンに戻しても見逃した分は戻りません。変更そのものはタスクに記録され続けます。エージェント経由の作成結果、オートパイロットの一時停止など一部のタイプはこれらのグループの対象外で、常に届きます。システム通知とブラウザ通知はデスクトップのバナーを制御するもので、インボックス自体は変わりません。-**コメント** の下の **スクワッド内の引き継ぎを含める** は、スクワッドのタスクでリーダーとエージェントが作業を受け渡すコメントが対象です。リーダーがエージェントやスクワッドを @ メンションして依頼するコメントと、エージェントからの報告がこれに当たります。既定でオンで、オフにすると人に向けたコメントだけが届きます。あなたや他のメンバーを @ メンションしたコメント、人のコメントへのエージェントの返信、エージェント実行の失敗、対応が必要なステータスは引き続き届きます。+**コメント** の下の **スクワッド内の引き継ぎを含める** は、リーダーとエージェントが作業を受け渡すコメントが対象です。スクワッドに割り当てたタスクでも、コメントでスクワッドを @ メンションしたタスクでも同じです。リーダーがエージェントやスクワッドを @ メンションして依頼するコメントと、エージェントからの報告がこれに当たります。既定でオンで、オフにすると人に向けたコメントだけが届きます。あなたや他のメンバーを @ メンションしたコメント、人のコメントへのエージェントの返信、エージェント実行の失敗、対応が必要なステータスは引き続き届きます。## 次のステップdiff --git a/apps/docs/content/docs/inbox.ko.mdx b/apps/docs/content/docs/inbox.ko.mdxindex 4700899b13..64e26b141c 100644--- a/apps/docs/content/docs/inbox.ko.mdx+++ b/apps/docs/content/docs/inbox.ko.mdx@@ -171,7 +171,7 @@ multica inbox snooze <id>... --until tomorrow # RFC 3339, 30m, 3h, 1d, 1w; uns**상태 변경**은 기본적으로 꺼져 있고 나머지 종류는 켜져 있습니다. 끈 종류의 알림은 만들어지지 않으며, 다시 켜도 놓친 알림은 돌아오지 않습니다. 변경 사항 자체는 태스크에 계속 기록됩니다. 빠른 생성 결과, 자동화 일시 중지 같은 일부 유형은 이 그룹들과 관계없이 항상 전달됩니다. 시스템 알림과 브라우저 알림 설정은 데스크톱 배너를 제어할 뿐 인박스 자체를 바꾸지 않습니다.-**댓글** 아래의 **스쿼드 내부 인계 포함**은 스쿼드 태스크에서 리더와 에이전트가 작업을 주고받는 댓글을 다룹니다. 리더가 에이전트나 스쿼드를 @멘션해 일을 맡기는 댓글과 에이전트의 보고가 여기에 해당합니다. 기본적으로 켜져 있으며, 끄면 사람에게 향한 댓글만 받습니다. 나나 다른 멤버를 @멘션한 댓글, 사람의 댓글에 대한 에이전트 답글, 실패한 에이전트 실행, 확인이 필요한 상태는 계속 전달됩니다.+**댓글** 아래의 **스쿼드 내부 인계 포함**은 리더와 에이전트가 작업을 주고받는 댓글을 다룹니다. 스쿼드에 지정된 태스크든, 댓글에서 스쿼드를 @멘션한 태스크든 같습니다. 리더가 에이전트나 스쿼드를 @멘션해 일을 맡기는 댓글과 에이전트의 보고가 여기에 해당합니다. 기본적으로 켜져 있으며, 끄면 사람에게 향한 댓글만 받습니다. 나나 다른 멤버를 @멘션한 댓글, 사람의 댓글에 대한 에이전트 답글, 실패한 에이전트 실행, 확인이 필요한 상태는 계속 전달됩니다.## 다음 단계diff --git a/apps/docs/content/docs/inbox.mdx b/apps/docs/content/docs/inbox.mdxindex 4f39c15608..0b49065a01 100644--- a/apps/docs/content/docs/inbox.mdx+++ b/apps/docs/content/docs/inbox.mdx@@ -171,7 +171,7 @@ Below them, **Notify me about** turns each kind of notification on or off. These**Status changes** starts off; every other kind starts on. A kind that's turned off creates no notification, and turning it back on doesn't bring back what you missed; the changes are still recorded on the issue. A few types, such as quick-create results and autopilot pauses, sit outside these groups and are always delivered. System and browser notifications control desktop banners and don't change the inbox itself.-Under **Comments**, **Include squad handoffs** covers the comments on a squad's issue that its leader and agents pass work to each other with: the leader @-mentioning an agent or squad, and the agents reporting back. It starts on; turn it off to keep only the comments meant for people. Comments that @-mention you or anyone else, agent replies to a person's comment, failed agent runs, and statuses that need attention still arrive.+Under **Comments**, **Include squad handoffs** covers the comments a squad's leader and agents pass work to each other with, on an issue assigned to the squad or one the squad was @-mentioned on: the leader @-mentioning an agent or squad, and the agents reporting back. It starts on; turn it off to keep only the comments meant for people. Comments that @-mention you or anyone else, agent replies to a person's comment, failed agent runs, and statuses that need attention still arrive.## Next stepsdiff --git a/apps/docs/content/docs/inbox.zh-Hant.mdx b/apps/docs/content/docs/inbox.zh-Hant.mdxindex 776848aeb3..56b23a10ba 100644--- a/apps/docs/content/docs/inbox.zh-Hant.mdx+++ b/apps/docs/content/docs/inbox.zh-Hant.mdx@@ -171,7 +171,7 @@ multica inbox snooze <id>... --until tomorrow # RFC 3339、30m、3h、1d、1w**狀態變更**預設關閉,其餘類型預設開啟。關閉某一類後,不再建立這類通知,重新開啟也不會補回錯過的通知;相關變化仍然儲存在任務中。快速建立結果和自動化暫停等少數類型不受這些分組控制,始終投遞。系統通知和瀏覽器通知控制的是桌面橫幅,不會改變收件箱本身。-**評論**下的**包含小隊內部交接**針對小隊任務裡隊長和 AI 代理之間傳遞工作的評論:隊長 @ AI 代理或小隊指派工作,以及 AI 代理向隊長回報。預設開啟;關閉後只保留寫給人的評論。@ 你或其他成員的評論、AI 代理對某人評論的回覆、AI 代理執行失敗和需要關注的狀態照常通知。+**評論**下的**包含小隊內部交接**針對隊長和 AI 代理之間傳遞工作的評論,無論任務是指派給小隊,還是在評論裡 @ 了小隊:隊長 @ AI 代理或小隊指派工作,以及 AI 代理向隊長回報。預設開啟;關閉後只保留寫給人的評論。@ 你或其他成員的評論、AI 代理對某人評論的回覆、AI 代理執行失敗和需要關注的狀態照常通知。## 接下來diff --git a/apps/docs/content/docs/inbox.zh.mdx b/apps/docs/content/docs/inbox.zh.mdxindex 91489e69d9..1d732aa18a 100644--- a/apps/docs/content/docs/inbox.zh.mdx+++ b/apps/docs/content/docs/inbox.zh.mdx@@ -171,7 +171,7 @@ multica inbox snooze <id>... --until tomorrow # RFC 3339、30m、3h、1d、1w**状态变更**默认关闭,其余类型默认打开。关闭某一类后,不再创建这类通知,重新打开也不会补回错过的通知;相关变化仍然保存在任务中。快速创建结果和自动化暂停等少数类型不受这些分组控制,始终投递。系统通知和浏览器通知控制的是桌面横幅,不会改变收件箱本身。-**评论**下的**包含小队内部交接**针对小队任务里队长和智能体之间传递工作的评论:队长 @ 智能体或小队派活,以及智能体向队长回报。默认打开;关闭后只保留写给人的评论。@ 你或其他成员的评论、智能体对某人评论的回复、智能体运行失败和需要关注的状态照常通知。+**评论**下的**包含小队内部交接**针对队长和智能体之间传递工作的评论,无论任务是指派给小队,还是在评论里 @ 了小队:队长 @ 智能体或小队派活,以及智能体向队长回报。默认打开;关闭后只保留写给人的评论。@ 你或其他成员的评论、智能体对某人评论的回复、智能体运行失败和需要关注的状态照常通知。## 接下来diff --git a/server/cmd/server/notification_squad_handoff.go b/server/cmd/server/notification_squad_handoff.goindex 5670d6deb4..a57354416f 100644--- a/server/cmd/server/notification_squad_handoff.go+++ b/server/cmd/server/notification_squad_handoff.go@@ -3,13 +3,23 @@ package mainimport ("context"+ "github.com/jackc/pgx/v5/pgtype"db "github.com/multica-ai/multica/server/pkg/db/generated")-// isSquadHandoff reports whether a comment is one agent of the squad its issue-// is assigned to handing work to another (MUL-10008): the leader dispatching-// with an @agent or @squad mention, or a worker reporting back. A member's-// inbox drops these rows when they mute inbox.SquadHandoffsPref.+// maxSquadLineageHops bounds the delegated_from_task_id walk from a comment's+// run back to the squad leader run that started the chain.+const maxSquadLineageHops = 8++// isSquadHandoff reports whether a comment is one agent of a squad handing+// work to another (MUL-10008): the leader dispatching with an @agent or @squad+// mention, or a worker reporting back. A member's inbox drops these rows when+// they mute inbox.SquadHandoffsPref.+//+// The squad is the one whose leader run the comment's run descends from, so a+// squad called in with an @squad mention on an issue it is not assigned to+// counts too (MUL-10054). Without such a run it is the squad the issue is+// assigned to.//// A worker is a roster agent of the squad, or any agent whose run the squad's// leader dispatched (delegated_from_task_id points at a leader task of this@@ -44,12 +54,24 @@ func isSquadHandoff(ctx context.Context, queries *db.Queries, workspaceID, commeif err != nil || comment.AuthorType != "agent" || !comment.AuthorID.Valid {return false}- issue, err := queries.GetIssue(ctx, comment.IssueID)- if err != nil || !issue.AssigneeID.Valid || issue.AssigneeType.String != "squad" {+ // The run that posted the comment, when it is the author's own.+ var task *db.AgentTaskQueue+ if comment.SourceTaskID.Valid {+ t, err := queries.GetAgentTask(ctx, comment.SourceTaskID)+ if err != nil {+ return false+ }+ if t.AgentID == comment.AuthorID {+ task = &t+ }+ }++ squadID, ok := handoffSquadID(ctx, queries, comment.IssueID, task)+ if !ok {return false}squad, err := queries.GetSquadInWorkspace(ctx, db.GetSquadInWorkspaceParams{- ID: issue.AssigneeID,+ ID: squadID,WorkspaceID: wsID,})if err != nil || squad.ArchivedAt.Valid {@@ -60,26 +82,20 @@ func isSquadHandoff(ctx context.Context, queries *db.Queries, workspaceID, commereturn addressesAgent}- if comment.SourceTaskID.Valid {- task, err := queries.GetAgentTask(ctx, comment.SourceTaskID)- if err != nil {- return false- }- if task.AgentID == comment.AuthorID {- if task.DelegatedFromTaskID.Valid {- source, err := queries.GetAgentTask(ctx, task.DelegatedFromTaskID)- if err == nil && source.IsLeaderTask && source.SquadID == squad.ID {- return true- }+ if task != nil {+ if task.DelegatedFromTaskID.Valid {+ source, err := queries.GetAgentTask(ctx, task.DelegatedFromTaskID)+ if err == nil && source.IsLeaderTask && source.SquadID == squad.ID {+ return true}- if task.TriggerCommentID.Valid {- trigger, err := queries.GetCommentInWorkspace(ctx, db.GetCommentInWorkspaceParams{- ID: task.TriggerCommentID,- WorkspaceID: wsID,- })- if err != nil || trigger.AuthorType == "member" {- return false- }+ }+ if task.TriggerCommentID.Valid {+ trigger, err := queries.GetCommentInWorkspace(ctx, db.GetCommentInWorkspaceParams{+ ID: task.TriggerCommentID,+ WorkspaceID: wsID,+ })+ if err != nil || trigger.AuthorType == "member" {+ return false}}}@@ -91,3 +107,35 @@ func isSquadHandoff(ctx context.Context, queries *db.Queries, workspaceID, comme})return err == nil && onRoster}++// handoffSquadID is the squad a comment's run works for: the squad of the+// leader run on the comment's issue that the run descends from, else the squad+// the issue is assigned to. Runs on other issues are not followed, so an agent+// working its own issue is never counted for a squad that dispatched it+// elsewhere.+func handoffSquadID(ctx context.Context, queries *db.Queries, issueID pgtype.UUID, task *db.AgentTaskQueue) (pgtype.UUID, bool) {+ if task != nil {+ run := *task+ for range maxSquadLineageHops {+ if run.IssueID != issueID {+ break+ }+ if run.IsLeaderTask && run.SquadID.Valid {+ return run.SquadID, true+ }+ if !run.DelegatedFromTaskID.Valid {+ break+ }+ next, err := queries.GetAgentTask(ctx, run.DelegatedFromTaskID)+ if err != nil {+ break+ }+ run = next+ }+ }+ issue, err := queries.GetIssue(ctx, issueID)+ if err != nil || !issue.AssigneeID.Valid || issue.AssigneeType.String != "squad" {+ return pgtype.UUID{}, false+ }+ return issue.AssigneeID, true+}diff --git a/server/cmd/server/notification_squad_handoff_test.go b/server/cmd/server/notification_squad_handoff_test.goindex da50472136..4676ab189d 100644--- a/server/cmd/server/notification_squad_handoff_test.go+++ b/server/cmd/server/notification_squad_handoff_test.go@@ -61,6 +61,12 @@ func TestNotification_SquadHandoffs(t *testing.T) {leaderTask := fx.f.Task(t, fx.leaderID, testutil.Cols{"runtime_id": fx.runtimeID, "is_leader_task": true, "squad_id": fx.squadID,})+ // leaderTaskOn is the leader run an @squad mention starts on issueID.+ leaderTaskOn := func(t *testing.T, issueID string) string {+ return fx.f.Task(t, fx.leaderID, testutil.Cols{+ "runtime_id": fx.runtimeID, "issue_id": issueID, "is_leader_task": true, "squad_id": fx.squadID,+ })+ }cases := []struct {name string@@ -98,6 +104,36 @@ func TestNotification_SquadHandoffs(t *testing.T) {}},{name: "roster worker on an issue not assigned to the squad", assignee: "agent", author: fx.workerID,content: "Done.", handoff: false},+ {name: "leader called in with @squad dispatching", assignee: "agent", author: fx.leaderID,+ content: agentMention(fx.workerID) + " review the PR", handoff: true,+ task: func(t *testing.T, issueID string) string { return leaderTaskOn(t, issueID) }},+ {name: "leader called in with @squad without a mention", assignee: "agent", author: fx.leaderID,+ content: "Review is done, ready to merge.", handoff: false,+ task: func(t *testing.T, issueID string) string { return leaderTaskOn(t, issueID) }},+ {name: "outside agent the called-in leader dispatched", assignee: "agent", author: fx.outsideID,+ content: "Review: request changes.", handoff: true,+ task: func(t *testing.T, issueID string) string {+ return fx.f.Task(t, fx.outsideID, testutil.Cols{+ "runtime_id": fx.runtimeID, "issue_id": issueID, "delegated_from_task_id": leaderTaskOn(t, issueID),+ })+ }},+ {name: "roster worker a dispatched worker handed to", assignee: "agent", author: fx.workerID,+ content: "Fixed.", handoff: true,+ task: func(t *testing.T, issueID string) string {+ first := fx.f.Task(t, fx.outsideID, testutil.Cols{+ "runtime_id": fx.runtimeID, "issue_id": issueID, "delegated_from_task_id": leaderTaskOn(t, issueID),+ })+ return fx.f.Task(t, fx.workerID, testutil.Cols{+ "runtime_id": fx.runtimeID, "issue_id": issueID, "delegated_from_task_id": first,+ })+ }},+ {name: "agent the leader dispatched from another issue", assignee: "agent", author: fx.outsideID,+ content: "Done.", handoff: false,+ task: func(t *testing.T, issueID string) string {+ return fx.f.Task(t, fx.outsideID, testutil.Cols{+ "runtime_id": fx.runtimeID, "issue_id": issueID, "delegated_from_task_id": leaderTask,+ })+ }},}for _, tc := range cases {