Skip to content

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

Go

fix(server): clarify silent-exit prompt and pin handoff contract (#1775)

Bohan Jiang541aaa974d37
diff --git a/server/internal/daemon/execenv/runtime_config.go b/server/internal/daemon/execenv/runtime_config.go
index 97a2524431..57c2422e4b 100644
--- a/server/internal/daemon/execenv/runtime_config.go
+++ b/server/internal/daemon/execenv/runtime_config.go
@@ -168,7 +168,7 @@ func buildMetaSkillContent(provider string, ctx TaskContextForEnv) string {
fmt.Fprintf(&b, "2. Run `multica issue comment list %s --output json` to read the conversation\n", ctx.IssueID)
b.WriteString(" - If the output is very large or truncated, use pagination: `--limit 30` to get the latest 30 comments, or `--since <timestamp>` to fetch only recent ones\n")
fmt.Fprintf(&b, "3. Find the triggering comment (ID: `%s`) and understand what is being asked — do NOT confuse it with previous comments\n", ctx.TriggerCommentID)
- b.WriteString("4. **Decide whether a reply is warranted.** If the triggering comment is an acknowledgment / thanks / sign-off from another agent and no concrete question or task is being asked of you, do NOT post a reply — and do NOT post a comment saying 'No reply needed' or similar. Simply exit with no output. Silence is a valid and preferred way to end agent-to-agent conversations.\n")
+ b.WriteString("4. **Decide whether a reply is warranted.** If you produced actual work this turn (investigated, fixed, answered a real question), post the result via step 6 — that is a normal reply, not a noise comment. If the triggering comment was a pure acknowledgment / thanks / sign-off from another agent AND you produced no work this turn, do NOT post a reply — and do NOT post a comment saying 'No reply needed' or similar. Simply exit with no output. Silence is a valid and preferred way to end agent-to-agent conversations.\n")
b.WriteString("5. If a reply IS warranted: do any requested work first, then **decide whether to include any `@mention` link.** The default is NO mention. Only mention when you are escalating to a human owner who is not yet involved, delegating a concrete new sub-task to another agent for the first time, or the user explicitly asked you to loop someone in. Never @mention the agent you are replying to as a thank-you or sign-off.\n")
b.WriteString("6. **If you reply, post it as a comment — this step is mandatory when you reply.** Text in your terminal or run logs is NOT delivered to the user. ")
b.WriteString(BuildCommentReplyInstructions(ctx.IssueID, ctx.TriggerCommentID))
diff --git a/server/internal/daemon/prompt.go b/server/internal/daemon/prompt.go
index 23447b2b45..24dc266fdf 100644
--- a/server/internal/daemon/prompt.go
+++ b/server/internal/daemon/prompt.go
@@ -49,7 +49,7 @@ func buildCommentPrompt(task Task) string {
fmt.Fprintf(&b, "[NEW COMMENT] %s just left a new comment. Focus on THIS comment — do not confuse it with previous ones:\n\n", authorLabel)
fmt.Fprintf(&b, "> %s\n\n", task.TriggerCommentContent)
if task.TriggerAuthorType == "agent" {
- b.WriteString("⚠️ The triggering comment was posted by another agent. Before replying, decide whether a reply is warranted at all. If that comment was an acknowledgment, thanks, or sign-off and no concrete question or task is being asked of you, do NOT reply — and do NOT post a comment saying 'No reply needed' or similar. Simply exit with no output. Silence is the preferred way to end agent-to-agent threads. If you do reply, do not @mention the other agent as a sign-off (that re-triggers them and starts a loop).\n\n")
+ b.WriteString("⚠️ The triggering comment was posted by another agent. Decide whether a reply is warranted. If you produced actual work this turn (investigated, fixed something, answered a real question), post the result as a normal reply — that is NOT a noise comment, and the standard rule that final results must be delivered via comment still applies. If the triggering comment was a pure acknowledgment, thanks, or sign-off AND you produced no work this turn, do NOT reply — and do NOT post a comment saying 'No reply needed' or similar. Simply exit with no output. Silence is the preferred way to end agent-to-agent threads. If you do reply, do not @mention the other agent as a sign-off (that re-triggers them and starts a loop).\n\n")
}
}
fmt.Fprintf(&b, "Start by running `multica issue get %s --output json` to understand your task, then decide how to proceed.\n\n", task.IssueID)
diff --git a/server/internal/handler/handler_test.go b/server/internal/handler/handler_test.go
index 60f114418e..967f7229fc 100644
--- a/server/internal/handler/handler_test.go
+++ b/server/internal/handler/handler_test.go
@@ -2115,3 +2115,70 @@ func TestAgentReplyDoesNotInheritParentMentions(t *testing.T) {
t.Fatalf("expected 1 task for Agent B after member reply (parent inheritance allowed), got %d", countTasks(agentB))
}
}
+
+// TestAgentExplicitMentionStillTriggers documents the boundary the structural
+// fix preserves: suppressing implicit parent-mention inheritance for agent
+// authors does NOT block deliberate handoffs. An agent that explicitly
+// @mentions another agent in its own comment content still enqueues a task
+// for that mentioned agent.
+func TestAgentExplicitMentionStillTriggers(t *testing.T) {
+ if testHandler == nil {
+ t.Skip("database not available")
+ }
+ ctx := context.Background()
+
+ agentA := createHandlerTestAgent(t, "Handoff Agent A", nil)
+ agentB := createHandlerTestAgent(t, "Handoff Agent B", nil)
+
+ w := httptest.NewRecorder()
+ req := newRequest("POST", "/api/issues?workspace_id="+testWorkspaceID, map[string]any{
+ "title": "Agent explicit handoff test",
+ "status": "todo",
+ })
+ testHandler.CreateIssue(w, req)
+ if w.Code != http.StatusCreated {
+ t.Fatalf("CreateIssue: expected 201, got %d: %s", w.Code, w.Body.String())
+ }
+ var issue IssueResponse
+ json.NewDecoder(w.Body).Decode(&issue)
+ issueID := issue.ID
+
+ t.Cleanup(func() {
+ testPool.Exec(ctx, `DELETE FROM agent_task_queue WHERE issue_id = $1`, issueID)
+ testPool.Exec(ctx, `DELETE FROM comment WHERE issue_id = $1`, issueID)
+ testPool.Exec(ctx, `DELETE FROM issue WHERE id = $1`, issueID)
+ })
+
+ countTasks := func(agentID string) int {
+ var n int
+ err := testPool.QueryRow(ctx,
+ `SELECT count(*) FROM agent_task_queue WHERE issue_id = $1 AND agent_id = $2 AND status = 'queued'`,
+ issueID, agentID,
+ ).Scan(&n)
+ if err != nil {
+ t.Fatalf("failed to count tasks: %v", err)
+ }
+ return n
+ }
+
+ // Agent A posts a top-level comment that explicitly @mentions Agent B —
+ // a deliberate handoff. This must enqueue a task for Agent B, and must
+ // not enqueue a self-trigger for Agent A.
+ explicitMention := fmt.Sprintf("[@Agent B](mention://agent/%s) please take it from here", agentB)
+ w = httptest.NewRecorder()
+ r := newRequest("POST", "/api/issues/"+issueID+"/comments", map[string]any{
+ "content": explicitMention,
+ })
+ r = withURLParam(r, "id", issueID)
+ r.Header.Set("X-Agent-ID", agentA)
+ testHandler.CreateComment(w, r)
+ if w.Code != http.StatusCreated {
+ t.Fatalf("agent A handoff: expected 201, got %d: %s", w.Code, w.Body.String())
+ }
+ if got := countTasks(agentB); got != 1 {
+ t.Fatalf("expected 1 task for Agent B after explicit mention by Agent A, got %d", got)
+ }
+ if got := countTasks(agentA); got != 0 {
+ t.Fatalf("expected 0 tasks for Agent A (no self-trigger on own mention), got %d", got)
+ }
+}