Skip to content

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

Go

fix(comments): suppress same-issue agent self-mentions (#10765)

Multica Eve2dfa62c12075
diff --git a/apps/docs/content/docs/mentioning-agents.fr.mdx b/apps/docs/content/docs/mentioning-agents.fr.mdx
index 54b1ae9435..f50dc85345 100644
--- a/apps/docs/content/docs/mentioning-agents.fr.mdx
+++ b/apps/docs/content/docs/mentioning-agents.fr.mdx
@@ -94,6 +94,8 @@ Une @mention ne peut pas contourner le réglage Accès d'un agent. Si vous n'ave
## Agents qui se mentionnent entre eux
+Lorsqu'un agent se mentionne sur la tâche à laquelle appartient son exécution en cours, le commentaire est enregistré sans lancer une nouvelle exécution, même dans un autre fil. Une auto-mention sur une autre tâche peut toujours lancer une exécution, sous réserve des règles d'Accès.
+
Les agents peuvent @mentionner d'autres agents dans leurs réponses. Lorsque A @mentionne B et que B @mentionne A en retour, le système fusionne les exécutions en double au même moment, mais il ne décide pas si la collaboration doit prendre fin. Indiquez dans les instructions de l'agent quand s'arrêter.
## Étapes suivantes
diff --git a/apps/docs/content/docs/mentioning-agents.ja.mdx b/apps/docs/content/docs/mentioning-agents.ja.mdx
index 756b230a00..f56d46a42a 100644
--- a/apps/docs/content/docs/mentioning-agents.ja.mdx
+++ b/apps/docs/content/docs/mentioning-agents.ja.mdx
@@ -94,6 +94,8 @@ import { SteerDemo } from "@/components/demos/steer-demo";
## エージェント同士のメンション
+エージェントが現在の実行に属するタスクで自分自身を @メンションしても、コメントは保存されますが、新しい実行は開始されません。別のスレッドでも同様です。別のタスクでの自己メンションは、Access の確認を通過すれば引き続き実行を開始できます。
+
エージェントは自分の返信の中で他のエージェントを @メンションできます。A が B を、B が A をメンションし返す場合、同じタイミングの重複実行は統合されますが、この協働を終えるべきかどうかはシステムは判断しません。いつ止めるかはエージェントの指示に書いてください。
## 次のステップ
diff --git a/apps/docs/content/docs/mentioning-agents.ko.mdx b/apps/docs/content/docs/mentioning-agents.ko.mdx
index fa3d3f6ede..80daa4ffba 100644
--- a/apps/docs/content/docs/mentioning-agents.ko.mdx
+++ b/apps/docs/content/docs/mentioning-agents.ko.mdx
@@ -94,6 +94,8 @@ import { SteerDemo } from "@/components/demos/steer-demo";
## 에이전트 간 @멘션
+에이전트가 현재 실행이 속한 태스크에서 자신을 @멘션하면 댓글은 저장되지만 새 실행은 시작되지 않습니다. 다른 스레드에서도 마찬가지입니다. 다른 태스크에서 자신을 @멘션하면 Access 확인을 통과한 경우 계속 새 실행을 시작할 수 있습니다.
+
에이전트도 자신의 답변에서 다른 에이전트를 @멘션할 수 있습니다. A가 B를 @멘션하고 B가 다시 A를 @멘션하면 시스템은 같은 시점의 중복 실행을 합치지만 이 협업을 끝내야 하는지는 판단하지 않습니다. 언제 멈출지는 에이전트 지시문에 작성하세요.
## 다음 단계
diff --git a/apps/docs/content/docs/mentioning-agents.mdx b/apps/docs/content/docs/mentioning-agents.mdx
index 45cb6fa39f..914b236a3d 100644
--- a/apps/docs/content/docs/mentioning-agents.mdx
+++ b/apps/docs/content/docs/mentioning-agents.mdx
@@ -94,6 +94,8 @@ An @-mention cannot bypass an agent's Access. When you lack permission to run th
## Agents mentioning each other
+When an agent mentions itself on the issue its current run belongs to, the comment is saved without starting another run, even in a different thread. Self-mentions on another issue can still start a run, subject to Access.
+
Agents can @-mention other agents in their replies. When A @-mentions B and B @-mentions A back, the system merges duplicate runs at the same moment, but it does not decide whether the collaboration should end. Write when to stop into the agent instructions.
## Next steps
diff --git a/apps/docs/content/docs/mentioning-agents.zh-Hant.mdx b/apps/docs/content/docs/mentioning-agents.zh-Hant.mdx
index 9c239ed0d9..c90404fb8c 100644
--- a/apps/docs/content/docs/mentioning-agents.zh-Hant.mdx
+++ b/apps/docs/content/docs/mentioning-agents.zh-Hant.mdx
@@ -94,6 +94,8 @@ AI 代理做到一半、方向不對時,不必停下來重來。在評論框
## AI 代理之間的互相提及
+AI 代理在目前執行所屬的任務中 @自己,評論會正常儲存,但不會因此啟動新一輪執行,即使評論位於另一個討論串也是如此。在其他任務中 @自己仍可啟動執行,但需通過 Access 檢查。
+
AI 代理可以在自己的回覆中 @其他 AI 代理。A @ B、B 又 @ A 時,系統會合並同一時刻的重複執行,但不會判斷這段協作該不該結束。什麼時候停,要寫進 AI 代理指令。
## 接下來
diff --git a/apps/docs/content/docs/mentioning-agents.zh.mdx b/apps/docs/content/docs/mentioning-agents.zh.mdx
index 9ecff40b4c..89d9e53f9a 100644
--- a/apps/docs/content/docs/mentioning-agents.zh.mdx
+++ b/apps/docs/content/docs/mentioning-agents.zh.mdx
@@ -94,6 +94,8 @@ import { SteerDemo } from "@/components/demos/steer-demo";
## 智能体之间的互相提及
+智能体在当前运行所属的任务中 @自己,评论会正常保存,但不会因此启动新一轮运行,即使评论在另一个讨论串中也是如此。在其他任务中 @自己仍可启动运行,但需通过 Access 校验。
+
智能体可以在自己的回复中 @其他智能体。A @ B、B 又 @ A 时,系统会合并同一时刻的重复执行,但不会判断这段协作该不该结束。什么时候停,要写进智能体指令。
## 接下来
diff --git a/server/internal/handler/comment.go b/server/internal/handler/comment.go
index cb283de526..b379a4c998 100644
--- a/server/internal/handler/comment.go
+++ b/server/internal/handler/comment.go
@@ -3102,11 +3102,10 @@ func (h *Handler) hasPendingTaskForIssueAndAgent(ctx context.Context, issueID, a
// mentions from the current comment and returns the runnable agent recipients.
// Skips agents with on_mention trigger disabled, and private agents mentioned
// by non-owner members (only the agent owner or workspace admin/owner can
-// mention a private agent). Self-mentions are intentionally allowed so an
-// agent running in one issue can explicitly enqueue itself on another (e.g.
-// a child-issue run notifying the parent issue whose assignee is the same
-// agent); runaway loops are prevented by HasPendingTaskForIssueAndAgent
-// dedupe and the natural queued/dispatched coalescing of the task queue.
+// mention a private agent). A self-mention from a trusted authoring task on
+// this issue is suppressed, including during completion replay. Cross-issue
+// self-mentions remain explicit handoffs (e.g. a child-issue run notifying the
+// parent issue whose assignee is the same agent).
// Note: no issue status gate here — @mention is an explicit action and should
// work even on done/cancelled issues (the agent can reopen the issue if needed).
// commentMentionTarget is one EXPLICIT @agent / @squad mention and how it
@@ -3318,6 +3317,22 @@ func (h *Handler) resolveMentionedAgentCommentTriggers(ctx context.Context, issu
blockUnusableTarget("agent", m.ID, agent, verdict)
continue
}
+ if authorType == "agent" && authorID == uuidToString(agent.ID) && opts.AuthoringTaskID.Valid {
+ sourceTask, err := h.Queries.GetAgentTask(ctx, opts.AuthoringTaskID)
+ if err != nil {
+ blockTarget("agent", m.ID, ReasonInternalError)
+ continue
+ }
+ // Compare the exact authoring task, never the assignee or latest
+ // run: the same agent may be notifying this issue from another.
+ // Terminal source tasks still match when completion replays a comment.
+ if sourceTask.AgentID == agent.ID && sourceTask.IssueID == issue.ID {
+ active, activeErr := h.hasActiveTaskForIssueAndAgent(ctx, issue.ID, agent.ID, opts.ThreadCommentID)
+ status, reason := decideSuppressedLeaderOutcome(active, activeErr)
+ addTarget(commentMentionTarget{TargetType: "agent", TargetID: m.ID, Status: status, ReasonCode: reason})
+ continue
+ }
+ }
hasPending, err := h.hasPendingTaskForIssueAndAgent(ctx, issue.ID, agentUUID, opts)
if err != nil {
blockTarget("agent", m.ID, ReasonInternalError)
diff --git a/server/internal/handler/comment_self_mention_test.go b/server/internal/handler/comment_self_mention_test.go
new file mode 100644
index 0000000000..caff28a55d
--- /dev/null
+++ b/server/internal/handler/comment_self_mention_test.go
@@ -0,0 +1,229 @@
+package handler
+
+import (
+ "context"
+ "errors"
+ "net/http"
+ "testing"
+ "time"
+
+ "github.com/jackc/pgx/v5/pgtype"
+ "github.com/multica-ai/multica/server/internal/auth"
+ "github.com/multica-ai/multica/server/internal/middleware"
+ "github.com/multica-ai/multica/server/internal/testutil"
+ db "github.com/multica-ai/multica/server/pkg/db/generated"
+)
+
+func TestCommentSelfMention_SourceIssueAndThread(t *testing.T) {
+ for _, mode := range []string{"same thread", "different thread", "different issue"} {
+ t.Run(mode, func(t *testing.T) {
+ runtimeID := dbfx.Runtime(t, "Self mention runtime")
+ agentID := dbfx.Agent(t, "Self mention author", runtimeID)
+ otherAgentID := dbfx.Agent(t, "Other mentioned agent", runtimeID)
+ issueID := dbfx.Issue(t, "Authoring issue")
+ rootID := dbfx.Comment(t, issueID, "Please investigate")
+ var triggerID any = rootID
+ if mode == "different thread" {
+ // Assignment runs may comment in any thread; comment-triggered
+ // runs must reply only to their covered parents.
+ triggerID = nil
+ }
+ taskID := dbfx.Task(t, agentID, testutil.Cols{
+ "runtime_id": runtimeID, "issue_id": issueID, "status": "running",
+ "trigger_comment_id": triggerID, "delivered_comment_ids": []string{rootID},
+ "created_at": testutil.Raw("now() - interval '1 minute'"), "started_at": testutil.Raw("now()"),
+ "originator_user_id": testUserID, "accountable_user_id": testUserID,
+ })
+ targetIssue, parentID := issueID, rootID
+ if mode == "different issue" {
+ targetIssue = dbfx.Issue(t, "Cross issue notification")
+ }
+ if mode != "same thread" {
+ parentID = dbfx.Comment(t, targetIssue, "Another thread")
+ }
+ if mode == "different issue" {
+ // A newer local run of the same agent is not evidence that
+ // this comment was authored on the target issue.
+ dbfx.Task(t, agentID, testutil.Cols{
+ "runtime_id": runtimeID, "issue_id": targetIssue, "status": "running",
+ "trigger_comment_id": parentID,
+ })
+ }
+ dbfx.Cleanup(t, `DELETE FROM agent_task_queue WHERE issue_id = $1 AND id <> $2`, targetIssue, taskID)
+ dbfx.Cleanup(t, `DELETE FROM comment WHERE issue_id = $1 AND source_task_id = $2`, targetIssue, taskID)
+ token := "mat_self_mention_" + taskID
+ dbfx.Insert(t, "task_token", testutil.Cols{
+ "token_hash": auth.HashToken(token), "task_id": taskID, "agent_id": agentID,
+ "workspace_id": testWorkspaceID, "user_id": testUserID, "expires_at": time.Now().Add(time.Hour),
+ })
+ call := func(handle http.HandlerFunc, method, path, param, id string, body map[string]any) *testutil.Response {
+ t.Helper()
+ req := withURLParam(newRequest(method, path, body), param, id)
+ req.Header.Set("Authorization", "Bearer "+token)
+ // The authenticated token, not these client-supplied identities,
+ // must determine whose run authored the comment.
+ req.Header.Set("X-Agent-ID", "forged-agent")
+ req.Header.Set("X-Task-ID", "forged-task")
+ protected := middleware.Auth(testHandler.Queries, nil, nil, nil)(
+ middleware.RequireWorkspaceMember(testHandler.Queries)(handle),
+ )
+ return testutil.Call(t, protected.ServeHTTP, req)
+ }
+ content := mention(agentID) + " " + mention(otherAgentID)
+ body := map[string]any{"content": content, "parent_id": parentID}
+ var preview CommentTriggerPreviewResponse
+ call(testHandler.PreviewCommentTriggers, http.MethodPost, "/api/issues/"+targetIssue+"/comments/trigger-preview", "id", targetIssue, body).
+ Want(http.StatusOK).JSON(&preview)
+ wantQueued := 0
+ if mode == "different issue" {
+ wantQueued = 1
+ }
+ if mode == "different issue" {
+ requirePreviewAgents(t, preview, agentID, otherAgentID)
+ } else {
+ requirePreviewAgents(t, preview, otherAgentID)
+ }
+ var comment CommentResponse
+ call(testHandler.CreateComment, http.MethodPost, "/api/issues/"+targetIssue+"/comments", "id", targetIssue, body).
+ Want(http.StatusCreated).JSON(&comment)
+ if comment.AuthorType != "agent" || comment.AuthorID != agentID || comment.SourceTaskID == nil || *comment.SourceTaskID != taskID {
+ t.Fatalf("comment lost its token-bound author/source task: %+v", comment)
+ }
+ outcome := findCommentOutcome(t, comment.TriggerOutcomes, agentID)
+ wantStatus, wantReason := DispatchBlocked, ReasonSelfTriggerSuppressed
+ if mode == "same thread" {
+ wantStatus, wantReason = DispatchDeferred, ReasonAlreadyActive
+ } else if mode == "different issue" {
+ wantStatus, wantReason = DispatchQueued, ReasonQueued
+ }
+ if outcome.Status != wantStatus || outcome.ReasonCode != wantReason {
+ t.Errorf("outcome = %+v, want %s/%s", outcome, wantStatus, wantReason)
+ }
+ if got := countQueuedOrDispatched(t, agentID, targetIssue); got != wantQueued {
+ t.Errorf("queued tasks = %d, want %d", got, wantQueued)
+ }
+ if other := findCommentOutcome(t, comment.TriggerOutcomes, otherAgentID); other.Status != DispatchQueued {
+ t.Errorf("mention of the other agent = %+v, want queued", other)
+ }
+ body["content"] = content + " Updated evidence."
+ body["editing_comment_id"] = comment.ID
+ call(testHandler.PreviewCommentTriggers, http.MethodPost, "/api/issues/"+targetIssue+"/comments/trigger-preview", "id", targetIssue, body).
+ Want(http.StatusOK).JSON(&preview)
+ if mode == "different issue" {
+ requirePreviewAgents(t, preview, agentID, otherAgentID)
+ } else {
+ requirePreviewAgents(t, preview, otherAgentID)
+ }
+ call(testHandler.UpdateComment, http.MethodPatch, "/api/comments/"+comment.ID, "commentId", comment.ID, body).
+ Want(http.StatusOK).JSON(&comment)
+ if comment.SourceTaskID == nil || *comment.SourceTaskID != taskID {
+ t.Fatal("edit lost its token-bound source task")
+ }
+ if edited := findCommentOutcome(t, comment.TriggerOutcomes, agentID); edited.Status != wantStatus || edited.ReasonCode != wantReason {
+ t.Errorf("edit outcome = %+v, want %s/%s", edited, wantStatus, wantReason)
+ }
+ if got := countQueuedOrDispatched(t, agentID, targetIssue); got != wantQueued {
+ t.Errorf("queued tasks after edit = %d, want %d", got, wantQueued)
+ }
+ if mode == "same thread" {
+ completeWorkerReplyRun(t, taskID)
+ if got := countQueuedOrDispatched(t, agentID, issueID); got != 0 {
+ t.Errorf("completion replay queued %d self-triggered tasks, want 0", got)
+ }
+ }
+ })
+ }
+}
+
+func TestCommentSelfMention_RequiresMatchingSourceTask(t *testing.T) {
+ runtimeID := dbfx.Runtime(t, "Source identity runtime")
+ agentID := dbfx.Agent(t, "Source identity author", runtimeID)
+ otherAgentID := dbfx.Agent(t, "Other source identity", runtimeID)
+ issueID := dbfx.Issue(t, "Source identity issue")
+ otherIssueID := dbfx.Issue(t, "Other source issue")
+ for _, tc := range []struct {
+ name, sourceAgent, sourceIssue, authorType string
+ missing bool
+ }{
+ {name: "legacy unstamped comment", missing: true, authorType: "agent"},
+ {name: "different source agent", sourceAgent: otherAgentID, sourceIssue: issueID, authorType: "agent"},
+ {name: "different source issue", sourceAgent: agentID, sourceIssue: otherIssueID, authorType: "agent"},
+ {name: "source without issue", sourceAgent: agentID, authorType: "agent"},
+ {name: "member mention", sourceAgent: agentID, sourceIssue: issueID, authorType: "member"},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ var sourceID pgtype.UUID
+ if !tc.missing {
+ var sourceIssue any
+ if tc.sourceIssue != "" {
+ sourceIssue = tc.sourceIssue
+ }
+ sourceID = parseUUID(dbfx.Task(t, tc.sourceAgent, testutil.Cols{
+ "runtime_id": runtimeID, "issue_id": sourceIssue, "status": "completed",
+ }))
+ }
+ authorID := agentID
+ if tc.authorType == "member" {
+ authorID = testUserID
+ }
+ triggers, _ := testHandler.computeCommentAgentTriggers(context.Background(), db.Issue{
+ ID: parseUUID(issueID), WorkspaceID: parseUUID(testWorkspaceID),
+ }, mention(agentID), nil, tc.authorType, authorID, commentTriggerComputeOptions{
+ AuthoringTaskID: sourceID, OriginatorUserID: testUserID,
+ })
+ if len(triggers) != 1 || triggers[0].Agent.ID != parseUUID(agentID) {
+ t.Fatalf("non-self/cross-issue mention was suppressed: %+v", triggers)
+ }
+ })
+ }
+}
+
+func TestCommentSelfMention_QueryErrors(t *testing.T) {
+ runtimeID := dbfx.Runtime(t, "Self mention query errors")
+ agentID := dbfx.Agent(t, "Self mention query author", runtimeID)
+ issueID := dbfx.Issue(t, "Self mention query issue")
+ sourceID := dbfx.Task(t, agentID, testutil.Cols{
+ "runtime_id": runtimeID, "issue_id": issueID, "status": "running",
+ })
+ for _, query := range []string{"GetAgentTask", "HasActiveTaskForIssueAndAgentInThread"} {
+ t.Run(query, func(t *testing.T) {
+ h := *testHandler
+ h.Queries = db.New(failQueryDBTX{DBTX: testPool, failOn: "-- name: " + query + " :one", err: errors.New("database unavailable")})
+ triggers, targets := h.computeCommentAgentTriggers(context.Background(), db.Issue{
+ ID: parseUUID(issueID), WorkspaceID: parseUUID(testWorkspaceID),
+ }, mention(agentID), nil, "agent", agentID, commentTriggerComputeOptions{
+ AuthoringTaskID: parseUUID(sourceID), OriginatorUserID: testUserID,
+ })
+ if len(triggers) != 0 {
+ t.Fatal("query failure must not enqueue a self-trigger")
+ }
+ outcome := findCommentOutcome(t, commentTriggerOutcomes(targets, nil), agentID)
+ if outcome.Status != DispatchBlocked || outcome.ReasonCode != ReasonInternalError {
+ t.Fatalf("query failure outcome = %+v, want blocked/internal_error", outcome)
+ }
+ })
+ }
+}
+
+func TestCommentSelfMention_PermissionGatePrecedesSuppression(t *testing.T) {
+ runtimeID := dbfx.Runtime(t, "Self mention permissions")
+ agentID := dbfx.Agent(t, "Private self mention author", runtimeID)
+ issueID := dbfx.Issue(t, "Self mention permission issue")
+ sourceID := dbfx.Task(t, agentID, testutil.Cols{
+ "runtime_id": runtimeID, "issue_id": issueID, "status": "running",
+ })
+ otherUserID := dbfx.User(t, "Other originator", "[email protected]")
+ dbfx.Member(t, testWorkspaceID, otherUserID, "member")
+ triggers, targets := testHandler.computeCommentAgentTriggers(context.Background(), db.Issue{
+ ID: parseUUID(issueID), WorkspaceID: parseUUID(testWorkspaceID),
+ }, mention(agentID), nil, "agent", agentID, commentTriggerComputeOptions{
+ AuthoringTaskID: parseUUID(sourceID), OriginatorUserID: otherUserID,
+ })
+ if len(triggers) != 0 {
+ t.Fatal("an originator who cannot invoke the agent must not enqueue it")
+ }
+ outcome := findCommentOutcome(t, commentTriggerOutcomes(targets, nil), agentID)
+ if outcome.Status != DispatchBlocked || outcome.ReasonCode != ReasonInvocationNotAllowed {
+ t.Fatalf("permission denial = %+v, want blocked/invocation_not_allowed", outcome)
+ }
+}
diff --git a/server/internal/handler/mention_self_trigger_test.go b/server/internal/handler/mention_self_trigger_test.go
index 47bb8ccd93..7ef5a7f6be 100644
--- a/server/internal/handler/mention_self_trigger_test.go
+++ b/server/internal/handler/mention_self_trigger_test.go
@@ -4,6 +4,7 @@ import (
"context"
"testing"
+ "github.com/multica-ai/multica/server/internal/testutil"
"github.com/multica-ai/multica/server/internal/util"
db "github.com/multica-ai/multica/server/pkg/db/generated"
)
@@ -13,21 +14,21 @@ import (
// test helper so these integration tests keep asserting enqueue side effects.
func enqueueMentionedAgentTasksForTest(t *testing.T, ctx context.Context, issue db.Issue, comment db.Comment, parentComment *db.Comment, authorType, authorID string) {
t.Helper()
- triggers, _ := testHandler.computeCommentAgentTriggers(ctx, issue, comment.Content, parentComment, authorType, authorID, commentTriggerComputeOptions{})
+ triggers, _ := testHandler.computeCommentAgentTriggers(ctx, issue, comment.Content, parentComment, authorType, authorID, commentTriggerComputeOptions{
+ AuthoringTaskID: comment.SourceTaskID,
+ })
testHandler.enqueueCommentAgentTriggers(ctx, issue, comment.ID, triggers)
}
// selfMentionFixture wires the seeded "Handler Test Agent" as J plus two
// fresh issues so we can exercise the agent-self-mention path on the @mention
// branch of computeCommentAgentTriggers. The three tests below cover
-// the behavior we want post-MUL-2338:
+// the self-mention routing boundaries:
//
// - cross-issue self-mention enqueues (child→parent handoff between issues
// assigned to the same agent must not be swallowed)
-// - same-issue self-mention with an in-flight running task enqueues a
-// follow-up (queue coalescing already allows this — the comment handler
-// must not pre-empt it with an extra in-thread guard)
-// - same-issue self-mention with a queued/dispatched task is deduped
+// - same-issue self-mention from the authoring task does not enqueue a follow-up
+// - legacy unstamped self-mention with a queued/dispatched task is deduped
// (HasPendingTaskForIssueAndAgent still does its job)
type selfMentionFixture struct {
JID string
@@ -162,6 +163,11 @@ func TestEnqueueMentionedAgentTasks_SelfMentionCrossIssueEnqueues(t *testing.T)
}
ctx := context.Background()
fx := newSelfMentionFixture(t)
+ sourceID := dbfx.Task(t, fx.JID, testutil.Cols{
+ "runtime_id": fx.RuntimeID, "issue_id": fx.IssueAID, "status": "running",
+ })
+ fx.CommentB.SourceTaskID = parseUUID(sourceID)
+ dbfx.Exec(t, `UPDATE comment SET source_task_id = $2 WHERE id = $1`, fx.CommentBID, sourceID)
if got := countQueuedOrDispatched(t, fx.JID, fx.IssueBID); got != 0 {
t.Fatalf("before: expected 0 pending tasks on parent issue, got %d", got)
@@ -174,25 +180,19 @@ func TestEnqueueMentionedAgentTasks_SelfMentionCrossIssueEnqueues(t *testing.T)
}
}
-// TestEnqueueMentionedAgentTasks_SelfMentionWhileRunningQueuesFollowup proves
-// that a self-mention posted in the same issue an agent is currently running
-// in does NOT pre-empt the natural queue-coalescing behavior: a `running`
-// task is not "pending" for dedup purposes, so a new queued follow-up is
-// added and the agent picks it up on its next cycle.
-func TestEnqueueMentionedAgentTasks_SelfMentionWhileRunningQueuesFollowup(t *testing.T) {
+// A trusted authoring task must not wake itself by mentioning its own agent on
+// the same issue, even though running tasks are not pending for queue dedup.
+func TestEnqueueMentionedAgentTasks_SelfMentionWhileRunningDoesNotQueueFollowup(t *testing.T) {
if testHandler == nil || testPool == nil {
t.Skip("database not available")
}
ctx := context.Background()
fx := newSelfMentionFixture(t)
- // Seed a running task for J on issue A — this is the agent's current run.
- if _, err := testPool.Exec(ctx, `
- INSERT INTO agent_task_queue (agent_id, runtime_id, issue_id, status)
- VALUES ($1, $2, $3, 'running')
- `, fx.JID, fx.RuntimeID, fx.IssueAID); err != nil {
- t.Fatalf("seed running task: %v", err)
- }
+ sourceID := dbfx.Task(t, fx.JID, testutil.Cols{
+ "runtime_id": fx.RuntimeID, "issue_id": fx.IssueAID, "status": "running",
+ })
+ fx.CommentA.SourceTaskID = parseUUID(sourceID)
if got := countQueuedOrDispatched(t, fx.JID, fx.IssueAID); got != 0 {
t.Fatalf("before: expected 0 queued/dispatched tasks (only the running task), got %d", got)
@@ -200,8 +200,8 @@ func TestEnqueueMentionedAgentTasks_SelfMentionWhileRunningQueuesFollowup(t *tes
enqueueMentionedAgentTasksForTest(t, ctx, fx.IssueA, fx.CommentA, nil, "agent", fx.JID)
- if got := countQueuedOrDispatched(t, fx.JID, fx.IssueAID); got != 1 {
- t.Fatalf("after self-mention while running: expected 1 new queued follow-up, got %d", got)
+ if got := countQueuedOrDispatched(t, fx.JID, fx.IssueAID); got != 0 {
+ t.Fatalf("after same-issue self-mention: expected no queued follow-up, got %d", got)
}
}