Skip to content

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

Go

fix(issues): let issues enter a workflow step whose handler was archived or left (#11545)

pseudoyu30ff29e4a334
diff --git a/apps/docs/content/docs/workflows.fr.mdx b/apps/docs/content/docs/workflows.fr.mdx
index 6f411e3617..4cc20d032b 100644
--- a/apps/docs/content/docs/workflows.fr.mdx
+++ b/apps/docs/content/docs/workflows.fr.mdx
@@ -72,6 +72,8 @@ Changez le statut d’une tâche ou faites glisser sa carte vers une autre colon
Si vous créez une tâche dans un projet sans choisir de responsable et que son statut prévoit un passage de relais, elle est confiée directement au responsable de cette étape ; un agent commence aussitôt. La fenêtre de création indique à qui elle sera confiée. Pour la créer sans rien lancer, placez-la dans Backlog.
+Si l’agent, le squad ou son chef a été archivé, ou si le membre a quitté l’espace de travail, la tâche peut quand même entrer dans l’étape. Une tâche déplacée garde son responsable. Une tâche créée sans responsable reste non assignée.
+
Si le responsable précédent est un agent dont l’exécution est encore en cours ou en attente, la confirmation propose en plus de l’arrêter ou de l’annuler, option cochée par défaut. Laissez-la cochée, sauf si vous voulez que les deux agents travaillent en même temps ; ses commentaires publiés et le travail déjà enregistré sont conservés.
**Une fois terminé, passer à** et **En cas de rejet, renvoyer à** indiquent à l’agent où déplacer la tâche ensuite. La fin d’une exécution ne fait pas avancer la tâche à elle seule : c’est le membre ou l’agent responsable de l’étape qui met à jour son statut. Quand un agent fait entrer la tâche dans l’étape suivante, le passage de relais de cette étape se déclenche de la même façon.
diff --git a/apps/docs/content/docs/workflows.ja.mdx b/apps/docs/content/docs/workflows.ja.mdx
index f4603fe98e..bc6db8cb40 100644
--- a/apps/docs/content/docs/workflows.ja.mdx
+++ b/apps/docs/content/docs/workflows.ja.mdx
@@ -72,6 +72,8 @@ import { WorkflowDemo } from "@/components/demos/workflow-demo";
プロジェクトで担当者を選ばずにタスクを作成し、そのステータスに引き継ぎがある場合、タスクはそのステップの担当者に直接渡ります。エージェントならすぐに作業を始めます。作成画面には「作成後に…に引き継ぎます」と引き継ぎ先が表示されます。まだ何も始めたくない場合は Backlog に作成します。
+引き継ぎ先のエージェント、スクワッド、またはスクワッドのリーダーがアーカイブされた場合や、メンバーがワークスペースを退出した場合も、タスクはそのステップに進めます。移動したタスクは現在の担当者を維持し、担当者を選ばずに作成したタスクは未割り当てのままです。
+
前の担当者がエージェントで、まだ実行中または開始待ちの場合は、確認画面にそれを停止またはキャンセルする選択肢が加わり、最初から選択されています。2 つのエージェントに同時に作業させたい場合以外はそのままで構いません。そのエージェントが投稿したコメントと保存済みの作業は残ります。
「完了したら移動」と「差し戻す先」は、次にタスクをどこへ移すかをエージェントに伝えます。実行が終わっただけではタスクは次に進まず、そのステップを担当するメンバーやエージェントがステータスを更新します。エージェントがタスクを次のステップに移した場合も、そのステップの引き継ぎが同じように行われます。
diff --git a/apps/docs/content/docs/workflows.ko.mdx b/apps/docs/content/docs/workflows.ko.mdx
index 5e8448c73f..0e7f43ee80 100644
--- a/apps/docs/content/docs/workflows.ko.mdx
+++ b/apps/docs/content/docs/workflows.ko.mdx
@@ -72,6 +72,8 @@ import { WorkflowDemo } from "@/components/demos/workflow-demo";
프로젝트에서 담당자를 고르지 않고 태스크를 만들었는데 그 상태에 인계가 설정되어 있으면, 태스크는 해당 단계의 담당자에게 바로 넘어갑니다. 에이전트라면 즉시 작업을 시작합니다. 생성 창에 "생성 후 ○○에게 인계됩니다"라고 표시됩니다. 아직 아무것도 시작하지 않으려면 Backlog에 만드세요.
+인계 대상 에이전트, 스쿼드 또는 스쿼드 리더가 보관되었거나 멤버가 워크스페이스를 떠난 경우에도 태스크는 해당 단계로 이동할 수 있습니다. 이동한 태스크의 기존 담당자는 유지되며, 담당자를 지정하지 않고 만든 태스크는 미할당 상태로 남습니다.
+
이전 담당자가 에이전트이고 아직 실행 중이거나 시작을 기다리고 있다면, 확인 창에 그 실행을 중지하거나 취소하는 옵션이 추가되며 기본으로 선택되어 있습니다. 두 에이전트가 함께 작업하기를 원하는 경우가 아니면 그대로 두세요. 그 에이전트가 이미 게시한 댓글과 저장한 작업은 사라지지 않습니다.
**완료 후 이동**과 **반려 시 되돌릴 단계**는 에이전트에게 태스크를 다음에 어디로 옮길지 알려 줍니다. 실행이 끝났다고 태스크가 저절로 다음 단계로 넘어가지는 않으며, 해당 단계의 멤버나 에이전트가 상태를 바꿉니다. 에이전트가 태스크를 다음 단계로 옮길 때도 그 단계의 인계가 똑같이 일어납니다.
diff --git a/apps/docs/content/docs/workflows.mdx b/apps/docs/content/docs/workflows.mdx
index 89ef42df7d..57b6aae805 100644
--- a/apps/docs/content/docs/workflows.mdx
+++ b/apps/docs/content/docs/workflows.mdx
@@ -72,6 +72,8 @@ Change an issue's status or drag its card to another column. If that step has a
When you create an issue in a project without picking an assignee, and its status has a handoff, the issue goes straight to that step's handler; an agent starts right away. The create dialog shows who it will be handed to. To create it without starting anything yet, put it in Backlog.
+If the step's agent, squad, or squad leader was archived, or its member left the workspace, the issue can still enter the step. A moved issue keeps its assignee. A new issue created without an assignee stays unassigned.
+
When the previous assignee is an agent with a run underway or waiting to start, the confirmation adds an option to stop or cancel it, selected by default. Leave it selected unless you want both agents working at once; the comments and work it already saved are kept.
**When done, move to** and **If rejected, send back to** tell the agent where to move the issue next. A run finishing does not move the issue by itself: the member or agent handling the step updates its status. When an agent moves the issue into the next step, that step's handoff runs just as it would for a member.
diff --git a/apps/docs/content/docs/workflows.zh-Hant.mdx b/apps/docs/content/docs/workflows.zh-Hant.mdx
index bc1ed4a1b9..ae2e247e44 100644
--- a/apps/docs/content/docs/workflows.zh-Hant.mdx
+++ b/apps/docs/content/docs/workflows.zh-Hant.mdx
@@ -72,6 +72,8 @@ import { WorkflowDemo } from "@/components/demos/workflow-demo";
在專案中新建任務時,如果沒有選擇負責人,而任務所在的狀態設有交接,任務會直接交給這一步的處理人;處理人是 AI 代理時會立即開始。新建視窗會提示"建立後交給"誰。想先建好再說,可以把任務放在 Backlog。
+如果這一步的 AI 代理、小隊或小隊隊長已封存,或處理人已離開工作區,任務仍可進入這一步。移入的任務保留原負責人,未指定負責人的新任務維持未指派。
+
上一位負責人是 AI 代理、而且它仍在執行或等待開始時,確認視窗會多出停止或取消它的選項,預設勾選。除非想讓兩位 AI 代理同時處理,保留勾選就行;它已發表的評論和已儲存的工作不會丟。
"完成後進入"和"打回時退回到"告訴 AI 代理接下來該把任務移到哪裡。一次執行結束不會自行推進任務,狀態由負責這一步的成員或 AI 代理更新;AI 代理把任務移進下一步時,同樣會觸發那一步的交接。
diff --git a/apps/docs/content/docs/workflows.zh.mdx b/apps/docs/content/docs/workflows.zh.mdx
index 15c375f70c..5a6768b8bd 100644
--- a/apps/docs/content/docs/workflows.zh.mdx
+++ b/apps/docs/content/docs/workflows.zh.mdx
@@ -72,6 +72,8 @@ import { WorkflowDemo } from "@/components/demos/workflow-demo";
在项目中新建任务时,如果没有选择负责人,而任务所在的状态设有交接,任务会直接交给这一步的处理人;处理人是智能体时会立即开始。新建窗口会提示"创建后交给"谁。想先建好再说,可以把任务放在 Backlog。
+如果这一步的智能体、小队或小队队长已归档,或处理人已离开工作区,任务仍可进入这一步。移入的任务保留原负责人,未指定负责人的新任务保持未分配。
+
上一位负责人是智能体、而且它仍在运行或等待开始时,确认窗口会多出停止或取消它的选项,默认勾选。除非想让两位智能体同时处理,保留勾选就行;它已发表的评论和已保存的工作不会丢。
"完成后进入"和"打回时退回到"告诉智能体接下来该把任务移到哪里。一次运行结束不会自行推进任务,状态由负责这一步的成员或智能体更新;智能体把任务移进下一步时,同样会触发那一步的交接。
diff --git a/server/internal/handler/issue.go b/server/internal/handler/issue.go
index e580fcfd44..ab619de26e 100644
--- a/server/internal/handler/issue.go
+++ b/server/internal/handler/issue.go
@@ -3525,7 +3525,7 @@ func (h *Handler) CreateIssue(w http.ResponseWriter, r *http.Request) {
if req.AssigneeType == nil && req.AssigneeID == nil {
if step, ok := createWorkflow.Step(status); ok && step.HandsOff() {
handoffCreatorType, handoffCreatorID := h.resolveActor(r, creatorID, workspaceID)
- if t, id, ok := issueworkflow.ResolveHandler(step, createWorkflowProject, handoffCreatorType, parseUUID(handoffCreatorID)); ok {
+ if t, id, ok := issueworkflow.ResolveHandler(step, createWorkflowProject, handoffCreatorType, parseUUID(handoffCreatorID)); ok && !h.handoffTargetRetired(r.Context(), wsUUID, t, id) {
assigneeType = pgtype.Text{String: t, Valid: true}
assigneeID = id
if status, msg := h.validateAssigneePair(r.Context(), r, workspaceID, assigneeType, assigneeID); status != 0 {
diff --git a/server/internal/handler/issue_workflow_entry.go b/server/internal/handler/issue_workflow_entry.go
index 1ed7b47333..3c2e1c198d 100644
--- a/server/internal/handler/issue_workflow_entry.go
+++ b/server/internal/handler/issue_workflow_entry.go
@@ -7,6 +7,7 @@ import (
"net/http"
"strconv"
+ "github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"github.com/multica-ai/multica/server/internal/issuestatus"
"github.com/multica-ai/multica/server/internal/issueworkflow"
@@ -28,7 +29,8 @@ import (
// enters the column it lands on only when the caller asks for it.
//
// Handoffs reuse assignment wholesale: the resolved handler goes through the
-// same permission gate as a hand-picked assignee, and the run starts through
+// same permission gate as a hand-picked assignee (a handler archived or gone
+// since the step was set hands off to nobody), and the run starts through
// the same WillEnqueueRun predicate, with the step's brief as its handoff note.
// workflowHandoff is a handoff an issue write triggers.
@@ -107,7 +109,7 @@ func (h *Handler) applyIssueWorkflow(ctx context.Context, prev db.Issue, params
return nil, nil
}
assigneeType, assigneeID, ok := issueworkflow.ResolveHandler(step, project, prev.CreatorType, prev.CreatorID)
- if !ok {
+ if !ok || h.handoffTargetRetired(ctx, prev.WorkspaceID, assigneeType, assigneeID) {
return nil, nil
}
params.AssigneeType = pgtype.Text{String: assigneeType, Valid: true}
@@ -115,6 +117,32 @@ func (h *Handler) applyIssueWorkflow(ctx context.Context, prev db.Issue, params
return &workflowHandoff{def: *def, step: step, project: project}, nil
}
+// handoffTargetRetired reports whether a resolved handler can no longer take
+// work: an archived agent or squad, a squad without an active leader, or a
+// user who left the workspace. The step then behaves like a relative handler
+// with nobody to resolve to.
+func (h *Handler) handoffTargetRetired(ctx context.Context, workspaceID pgtype.UUID, assigneeType string, assigneeID pgtype.UUID) bool {
+ switch assigneeType {
+ case "agent":
+ agent, err := h.Queries.GetAgentInWorkspace(ctx, db.GetAgentInWorkspaceParams{ID: assigneeID, WorkspaceID: workspaceID})
+ return errors.Is(err, pgx.ErrNoRows) || (err == nil && agent.ArchivedAt.Valid)
+ case "squad":
+ squad, err := h.Queries.GetSquadInWorkspace(ctx, db.GetSquadInWorkspaceParams{ID: assigneeID, WorkspaceID: workspaceID})
+ if err != nil {
+ return errors.Is(err, pgx.ErrNoRows)
+ }
+ if squad.ArchivedAt.Valid {
+ return true
+ }
+ leader, err := h.Queries.GetAgentInWorkspace(ctx, db.GetAgentInWorkspaceParams{ID: squad.LeaderID, WorkspaceID: workspaceID})
+ return errors.Is(err, pgx.ErrNoRows) || (err == nil && leader.ArchivedAt.Valid)
+ case "member":
+ _, err := h.Queries.GetMemberByUserAndWorkspace(ctx, db.GetMemberByUserAndWorkspaceParams{UserID: assigneeID, WorkspaceID: workspaceID})
+ return errors.Is(err, pgx.ErrNoRows)
+ }
+ return false
+}
+
// workflowStepMoved shares the step guard with the claim brief so a run is
// never told to advance a step its status changes cannot act on.
func workflowStepMoved(def *issueworkflow.Definition, status string, run *db.AgentTaskQueue) bool {
diff --git a/server/internal/handler/issue_workflow_stale_handler_test.go b/server/internal/handler/issue_workflow_stale_handler_test.go
new file mode 100644
index 0000000000..851ca64342
--- /dev/null
+++ b/server/internal/handler/issue_workflow_stale_handler_test.go
@@ -0,0 +1,73 @@
+package handler
+
+import (
+ "net/http"
+ "testing"
+
+ "github.com/multica-ai/multica/server/internal/testutil"
+)
+
+// A step's handler that can no longer take work (an archived agent, a member
+// who left) must not stop issues from entering the step: the issue moves and
+// keeps its assignee, as when a relative handler has nobody to resolve to.
+func TestWorkflowStepWithUnassignableHandlerSkipsHandoff(t *testing.T) {
+ seedTestCatalog(t)
+ var runtimeID string
+ dbfx.QueryRow(t, `SELECT runtime_id::text FROM agent WHERE id = $1`, seededReadyAgentID(t)).Scan(&runtimeID)
+
+ cases := []struct {
+ name string
+ setup func(t *testing.T, projectID string) (handler map[string]any, retire func())
+ }{
+ {"archived agent", func(t *testing.T, _ string) (map[string]any, func()) {
+ agentID := dbfx.Agent(t, "Retired handler "+workflowTestSuffix(), runtimeID)
+ return map[string]any{"type": "agent", "id": agentID}, func() {
+ dbfx.Exec(t, `UPDATE agent SET archived_at = now() WHERE id = $1`, agentID)
+ }
+ }},
+ {"active squad with an archived leader", func(t *testing.T, _ string) (map[string]any, func()) {
+ leaderID := dbfx.Agent(t, "Retired squad leader "+workflowTestSuffix(), runtimeID)
+ squadID := dbfx.Squad(t, "Squad with retired leader "+workflowTestSuffix(), leaderID)
+ return map[string]any{"type": "squad", "id": squadID}, func() {
+ dbfx.Exec(t, `UPDATE agent SET archived_at = now() WHERE id = $1`, leaderID)
+ }
+ }},
+ {"removed member", func(t *testing.T, _ string) (map[string]any, func()) {
+ userID, _ := addWorkflowTestMember(t, "leaver")
+ return map[string]any{"type": "member", "id": userID}, func() {
+ dbfx.Exec(t, `DELETE FROM member WHERE user_id = $1 AND workspace_id = $2`, userID, testWorkspaceID)
+ }
+ }},
+ {"project lead is an archived agent", func(t *testing.T, projectID string) (map[string]any, func()) {
+ agentID := dbfx.Agent(t, "Retired lead "+workflowTestSuffix(), runtimeID)
+ dbfx.Exec(t, `UPDATE project SET lead_type = 'agent', lead_id = $1 WHERE id = $2`, agentID, projectID)
+ return map[string]any{"type": "project_lead"}, func() {
+ dbfx.Exec(t, `UPDATE agent SET archived_at = now() WHERE id = $1`, agentID)
+ }
+ }},
+ }
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ wf := createTestWorkflow(t, "Stale handler "+workflowTestSuffix(), "in_progress")
+ projectID := createWorkflowTestProject(t, "Stale handler")
+ setProjectWorkflow(t, projectID, map[string]any{"workflow_id": wf.ID}).Want(http.StatusOK)
+ handler, retire := tc.setup(t, projectID)
+ setWorkflowHandoff(t, wf.ID, "in_progress", map[string]any{"handler": handler}).Want(http.StatusOK)
+ retire()
+
+ issueID := dbfx.Issue(t, "Enters a stale step", testutil.Cols{"project_id": projectID, "status": "todo"})
+ updateIssueForTest(t, issueID, map[string]any{"status": "in_progress"}).Want(http.StatusOK)
+ if status, assigneeType, assigneeID := issueStatusAndAssignee(t, issueID); status != "in_progress" || assigneeType != "" || assigneeID != "" {
+ t.Fatalf("moved issue = %s, %q %q; want in_progress and still unassigned", status, assigneeType, assigneeID)
+ }
+
+ var created IssueResponse
+ testutil.Call(t, testHandler.CreateIssue, newRequest("POST", "/api/issues?workspace_id="+testWorkspaceID, map[string]any{
+ "title": "Created in a stale step", "status": "in_progress", "project_id": projectID,
+ })).Want(http.StatusCreated).JSON(&created)
+ if created.AssigneeType != nil || created.AssigneeID != nil {
+ t.Fatalf("created issue assignee = %v %v; want unassigned", created.AssigneeType, created.AssigneeID)
+ }
+ })
+ }
+}