Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix: anchor comment triggers to thread roots (#3746)
Naiyuan Qingb9334dd59f4b
diff --git a/server/internal/daemon/daemon.go b/server/internal/daemon/daemon.goindex 6789dd40c1..b9f54ec6da 100644--- a/server/internal/daemon/daemon.go+++ b/server/internal/daemon/daemon.go@@ -2520,6 +2520,7 @@ func (d *Daemon) runTask(ctx context.Context, task Task, provider string, slot itaskCtx := execenv.TaskContextForEnv{IssueID: task.IssueID,TriggerCommentID: task.TriggerCommentID,+ TriggerThreadID: task.TriggerThreadID,NewCommentCount: task.NewCommentCount,NewCommentsSince: task.NewCommentsSince,PriorSessionResumed: task.PriorSessionID != "",diff --git a/server/internal/daemon/execenv/execenv.go b/server/internal/daemon/execenv/execenv.goindex 3524205134..d60f518443 100644--- a/server/internal/daemon/execenv/execenv.go+++ b/server/internal/daemon/execenv/execenv.go@@ -59,6 +59,7 @@ type PrepareParams struct {type TaskContextForEnv struct {IssueID stringTriggerCommentID string // comment that triggered this task (empty for on_assign)+ TriggerThreadID string // root comment ID for the triggering thread; falls back to TriggerCommentID when emptyNewCommentCount int // issue-wide comments since this agent's last run (excludes its own and the injected trigger)NewCommentsSince string // RFC3339 anchor (last run's started_at) the count is measured from; empty on cold startPriorSessionResumed bool // true when the daemon will resume an existing provider session for this taskdiff --git a/server/internal/daemon/execenv/execenv_test.go b/server/internal/daemon/execenv/execenv_test.goindex ec61f93643..6bf4137c3b 100644--- a/server/internal/daemon/execenv/execenv_test.go+++ b/server/internal/daemon/execenv/execenv_test.go@@ -3665,6 +3665,7 @@ func TestInjectRuntimeConfigCommentTriggerResumedNoDeltaRead(t *testing.T) {ctx := TaskContextForEnv{IssueID: issueID,TriggerCommentID: triggerID,+ TriggerThreadID: "thread-root-1",PriorSessionResumed: true,}if _, err := InjectRuntimeConfig(dir, "claude", ctx); err != nil {@@ -3679,10 +3680,10 @@ func TestInjectRuntimeConfigCommentTriggerResumedNoDeltaRead(t *testing.T) {for _, want := range []string{"triggering comment is already included above","No other new comments on this issue since your last run",- "triggering comment ID / thread anchor",+ "active thread anchor `thread-root-1` and triggering comment ID `" + triggerID + "`","If your reply depends on thread context","do not rely only on resumed session memory",- "multica issue comment list " + issueID + " --thread " + triggerID + " --tail 30 --output json",+ "multica issue comment list " + issueID + " --thread thread-root-1 --tail 30 --output json",} {if !strings.Contains(s, want) {t.Errorf("comment-triggered resumed Workflow missing %q\n---\n%s", want, s)diff --git a/server/internal/daemon/execenv/reply_instructions.go b/server/internal/daemon/execenv/reply_instructions.goindex 7ee2401bf7..9723a6802a 100644--- a/server/internal/daemon/execenv/reply_instructions.go+++ b/server/internal/daemon/execenv/reply_instructions.go@@ -22,14 +22,15 @@ import "fmt"// there are no new comments (newCommentCount <= 0) or issueID is empty. In those// cases the caller falls back to BuildResumedCommentsHint (when a prior session// is active) or BuildColdCommentsHint.-func BuildNewCommentsHint(issueID, triggerCommentID, newCommentsSince string, newCommentCount int) string {+func BuildNewCommentsHint(issueID, triggerCommentID, triggerThreadID, newCommentsSince string, newCommentCount int) string {if newCommentCount <= 0 || newCommentsSince == "" || issueID == "" {return ""}+ threadID := activeThreadID(triggerThreadID, triggerCommentID)// When we know the triggering thread, steer the agent to read THAT thread// first rather than blindly pulling every new comment issue-wide. The// issue-wide --since catch-up is demoted to an only-if-needed fallback.- if triggerCommentID != "" {+ if threadID != "" {return fmt.Sprintf("%d new comment(s) on this issue since your last run — don't read them all blindly. "+"Start with the thread your triggering comment is in: "+@@ -37,7 +38,7 @@ func BuildNewCommentsHint(issueID, triggerCommentID, newCommentsSince string, ne"(swap `--since` for `--tail 30` if you need the full thread, not just the delta). "+"Only if you need context from the other threads, catch up issue-wide: "+"`multica issue comment list %s --since %s --output json`.\n\n",- newCommentCount, issueID, triggerCommentID, newCommentsSince, issueID, newCommentsSince,+ newCommentCount, issueID, threadID, newCommentsSince, issueID, newCommentsSince,)}// Defensive: comment triggers always carry a trigger id, but if one is@@ -58,18 +59,19 @@ func BuildNewCommentsHint(issueID, triggerCommentID, newCommentsSince string, ne// read bounded and conditional, but make it explicit that context-dependent// replies should refresh the triggering conversation rather than trusting// resumed memory alone.-func BuildResumedCommentsHint(issueID, triggerCommentID string) string {- if issueID == "" || triggerCommentID == "" {+func BuildResumedCommentsHint(issueID, triggerCommentID, triggerThreadID string) string {+ threadID := activeThreadID(triggerThreadID, triggerCommentID)+ if issueID == "" || threadID == "" {return ""}return fmt.Sprintf("You're resuming the prior session, and the triggering comment is already included above. "+"No other new comments on this issue since your last run. "+- "Use the triggering comment ID / thread anchor: `%s`. "++ "Use the active thread anchor `%s` and triggering comment ID `%s`. "+"If your reply depends on thread context, do not rely only on resumed session memory — "+"first pull the triggering conversation with: "+"`multica issue comment list %s --thread %s --tail 30 --output json`.\n\n",- triggerCommentID, issueID, triggerCommentID,+ threadID, triggerCommentID, issueID, threadID,)}@@ -86,8 +88,9 @@ func BuildResumedCommentsHint(issueID, triggerCommentID string) string {// single-source rule as BuildNewCommentsHint, PR #2816). Returns "" when there// is no triggering comment to thread from, so the caller can keep a final plain// fallback.-func BuildColdCommentsHint(issueID, triggerCommentID string) string {- if issueID == "" || triggerCommentID == "" {+func BuildColdCommentsHint(issueID, triggerCommentID, triggerThreadID string) string {+ threadID := activeThreadID(triggerThreadID, triggerCommentID)+ if issueID == "" || threadID == "" {return ""}return fmt.Sprintf(@@ -95,10 +98,17 @@ func BuildColdCommentsHint(issueID, triggerCommentID string) string {"`multica issue comment list %s --thread %s --tail 30 --output json` "+"(that thread's root + its 30 newest replies). "+"Need cross-thread background? `multica issue comment list %s --recent 20 --output json`.\n\n",- issueID, triggerCommentID, issueID,+ issueID, threadID, issueID,)}+func activeThreadID(triggerThreadID, triggerCommentID string) string {+ if triggerThreadID != "" {+ return triggerThreadID+ }+ return triggerCommentID+}+// BuildCommentReplyInstructions returns the canonical block telling an agent// how to post its reply for a comment-triggered task. Both the per-turn// prompt (daemon.buildCommentPrompt) and the CLAUDE.md workflowdiff --git a/server/internal/daemon/execenv/runtime_config.go b/server/internal/daemon/execenv/runtime_config.goindex 8b8959d03d..416b836b26 100644--- a/server/internal/daemon/execenv/runtime_config.go+++ b/server/internal/daemon/execenv/runtime_config.go@@ -583,11 +583,11 @@ func buildMetaSkillContent(provider string, ctx TaskContextForEnv) string {b.WriteString("**This task was triggered by a NEW comment.** Your primary job is to respond to THIS specific comment, even if you have handled similar requests before in this session.\n\n")fmt.Fprintf(&b, "1. Run `multica issue get %s --output json` to understand the issue context\n", ctx.IssueID)fmt.Fprintf(&b, "2. Run `multica issue metadata list %s --output json` to see what prior agents pinned — best-effort, empty `{}` and CLI failures are normal. See the `## Issue Metadata` section above for what to look for.\n", ctx.IssueID)- if hint := BuildNewCommentsHint(ctx.IssueID, ctx.TriggerCommentID, ctx.NewCommentsSince, ctx.NewCommentCount); hint != "" {+ if hint := BuildNewCommentsHint(ctx.IssueID, ctx.TriggerCommentID, ctx.TriggerThreadID, ctx.NewCommentsSince, ctx.NewCommentCount); hint != "" {b.WriteString("3. " + hint)} else if ctx.PriorSessionResumed {- b.WriteString("3. " + BuildResumedCommentsHint(ctx.IssueID, ctx.TriggerCommentID))- } else if cold := BuildColdCommentsHint(ctx.IssueID, ctx.TriggerCommentID); cold != "" {+ b.WriteString("3. " + BuildResumedCommentsHint(ctx.IssueID, ctx.TriggerCommentID, ctx.TriggerThreadID))+ } else if cold := BuildColdCommentsHint(ctx.IssueID, ctx.TriggerCommentID, ctx.TriggerThreadID); cold != "" {b.WriteString("3. " + cold)} else {fmt.Fprintf(&b, "3. Catch up on comments — read with `multica issue comment list %s --output json` (long issue? `--recent 20`).\n", ctx.IssueID)diff --git a/server/internal/daemon/execenv/runtime_config_test.go b/server/internal/daemon/execenv/runtime_config_test.goindex 38cff217d2..38b1b092a9 100644--- a/server/internal/daemon/execenv/runtime_config_test.go+++ b/server/internal/daemon/execenv/runtime_config_test.go@@ -206,6 +206,7 @@ func TestCommentTriggeredBriefColdStartThreadRead(t *testing.T) {ctx := TaskContextForEnv{IssueID: issueID,TriggerCommentID: "trigger-1",+ TriggerThreadID: "thread-root-1",NewCommentCount: 0,NewCommentsSince: "",}@@ -213,7 +214,7 @@ func TestCommentTriggeredBriefColdStartThreadRead(t *testing.T) {if strings.Contains(out, "new comment(s) since your last run") {t.Errorf("no since-delta hint should render on cold start, got:\n%s", out)}- if !strings.Contains(out, "multica issue comment list "+issueID+" --thread trigger-1 --tail 30 --output json") {+ if !strings.Contains(out, "multica issue comment list "+issueID+" --thread thread-root-1 --tail 30 --output json") {t.Errorf("cold start must point at the triggering thread read, got:\n%s", out)}}@@ -228,6 +229,7 @@ func TestCommentTriggeredBriefResumedNoDeltaSkipsDefaultThreadRead(t *testing.T)ctx := TaskContextForEnv{IssueID: issueID,TriggerCommentID: "trigger-1",+ TriggerThreadID: "thread-root-1",PriorSessionResumed: true,NewCommentCount: 0,NewCommentsSince: "",@@ -237,10 +239,10 @@ func TestCommentTriggeredBriefResumedNoDeltaSkipsDefaultThreadRead(t *testing.T)for _, want := range []string{"triggering comment is already included above","No other new comments on this issue since your last run",- "triggering comment ID / thread anchor",+ "active thread anchor `thread-root-1` and triggering comment ID `trigger-1`","If your reply depends on thread context","do not rely only on resumed session memory",- "multica issue comment list " + issueID + " --thread trigger-1 --tail 30 --output json",+ "multica issue comment list " + issueID + " --thread thread-root-1 --tail 30 --output json",} {if !strings.Contains(out, want) {t.Errorf("resumed/no-delta brief missing %q\n--- output ---\n%s", want, out)diff --git a/server/internal/daemon/prompt.go b/server/internal/daemon/prompt.goindex 12d308f2bf..6b7e448087 100644--- a/server/internal/daemon/prompt.go+++ b/server/internal/daemon/prompt.go@@ -165,11 +165,11 @@ func buildCommentPrompt(task Task, provider string) string {// injected, so don't force a duplicate thread read. Cold path: read the// triggering thread, not the flat timeline. Final fallback (no trigger id,// shouldn't happen here): plain read.- if hint := execenv.BuildNewCommentsHint(task.IssueID, task.TriggerCommentID, task.NewCommentsSince, task.NewCommentCount); hint != "" {+ if hint := execenv.BuildNewCommentsHint(task.IssueID, task.TriggerCommentID, task.TriggerThreadID, task.NewCommentsSince, task.NewCommentCount); hint != "" {b.WriteString(hint)} else if task.PriorSessionID != "" {- b.WriteString(execenv.BuildResumedCommentsHint(task.IssueID, task.TriggerCommentID))- } else if cold := execenv.BuildColdCommentsHint(task.IssueID, task.TriggerCommentID); cold != "" {+ b.WriteString(execenv.BuildResumedCommentsHint(task.IssueID, task.TriggerCommentID, task.TriggerThreadID))+ } else if cold := execenv.BuildColdCommentsHint(task.IssueID, task.TriggerCommentID, task.TriggerThreadID); cold != "" {b.WriteString(cold)} else {fmt.Fprintf(&b, "Read the discussion: `multica issue comment list %s --output json` (long issue? use `--recent 20`).\n\n", task.IssueID)diff --git a/server/internal/daemon/prompt_test.go b/server/internal/daemon/prompt_test.goindex a000daba35..069a51ca65 100644--- a/server/internal/daemon/prompt_test.go+++ b/server/internal/daemon/prompt_test.go@@ -415,6 +415,7 @@ func TestBuildPromptNewCommentsHint(t *testing.T) {task := Task{IssueID: issueID,TriggerCommentID: "trigger-1",+ TriggerThreadID: "thread-root-1",TriggerCommentContent: "please look",TriggerAuthorType: "member",NewCommentCount: 3,@@ -431,7 +432,7 @@ func TestBuildPromptNewCommentsHint(t *testing.T) {t.Errorf("hint must discourage blindly reading every new comment, got:\n%s", out)}// Parent thread first: the --thread <trigger> read is the prioritized action.- if !strings.Contains(out, "multica issue comment list "+issueID+" --thread trigger-1 --since "+since+" --output json") {+ if !strings.Contains(out, "multica issue comment list "+issueID+" --thread thread-root-1 --since "+since+" --output json") {t.Errorf("hint must point at the triggering (parent) thread --since read first, got:\n%s", out)}if !strings.Contains(out, "--tail 30") {@@ -456,6 +457,7 @@ func TestBuildPromptColdStartThreadRead(t *testing.T) {task := Task{IssueID: issueID,TriggerCommentID: "trigger-1",+ TriggerThreadID: "thread-root-1",TriggerCommentContent: "hi",TriggerAuthorType: "member",NewCommentCount: 0,@@ -465,7 +467,7 @@ func TestBuildPromptColdStartThreadRead(t *testing.T) {if strings.Contains(out, "new comment(s) since your last run") {t.Errorf("no since-delta hint should render on cold start, got:\n%s", out)}- if !strings.Contains(out, "multica issue comment list "+issueID+" --thread trigger-1 --tail 30 --output json") {+ if !strings.Contains(out, "multica issue comment list "+issueID+" --thread thread-root-1 --tail 30 --output json") {t.Errorf("cold start must point at the triggering thread read, got:\n%s", out)}}@@ -479,6 +481,7 @@ func TestBuildPromptResumedNoDeltaDoesNotForceThreadRead(t *testing.T) {task := Task{IssueID: issueID,TriggerCommentID: "trigger-1",+ TriggerThreadID: "thread-root-1",TriggerCommentContent: "hi again",TriggerAuthorType: "member",PriorSessionID: "session-123",@@ -490,10 +493,10 @@ func TestBuildPromptResumedNoDeltaDoesNotForceThreadRead(t *testing.T) {for _, want := range []string{"triggering comment is already included above","No other new comments on this issue since your last run",- "triggering comment ID / thread anchor",+ "active thread anchor `thread-root-1` and triggering comment ID `trigger-1`","If your reply depends on thread context","do not rely only on resumed session memory",- "multica issue comment list " + issueID + " --thread trigger-1 --tail 30 --output json",+ "multica issue comment list " + issueID + " --thread thread-root-1 --tail 30 --output json",} {if !strings.Contains(out, want) {t.Errorf("resumed/no-delta prompt missing %q\n--- output ---\n%s", want, out)diff --git a/server/internal/daemon/types.go b/server/internal/daemon/types.goindex 2496ca1d18..e14d310f3a 100644--- a/server/internal/daemon/types.go+++ b/server/internal/daemon/types.go@@ -52,6 +52,7 @@ type Task struct {PriorSessionID string `json:"prior_session_id,omitempty"` // Claude session ID from a previous task on this issuePriorWorkDir string `json:"prior_work_dir,omitempty"` // work_dir from a previous task on this issueTriggerCommentID string `json:"trigger_comment_id,omitempty"` // comment that triggered this task+ TriggerThreadID string `json:"trigger_thread_id,omitempty"` // root comment ID for the triggering thread; falls back to trigger_comment_id on old serversTriggerCommentContent string `json:"trigger_comment_content,omitempty"` // content of the triggering commentTriggerAuthorType string `json:"trigger_author_type,omitempty"` // "agent" or "member" — author kind for the triggering commentTriggerAuthorName string `json:"trigger_author_name,omitempty"` // display name of the triggering comment authordiff --git a/server/internal/handler/agent.go b/server/internal/handler/agent.goindex fbf3f9c3b2..2601e9d60b 100644--- a/server/internal/handler/agent.go+++ b/server/internal/handler/agent.go@@ -200,6 +200,7 @@ type AgentTaskResponse struct {// WorkDir directly; newer UIs should prefer RelativeWorkDir.RelativeWorkDir string `json:"relative_work_dir,omitempty"`TriggerCommentID *string `json:"trigger_comment_id,omitempty"` // comment that triggered this task+ TriggerThreadID string `json:"trigger_thread_id,omitempty"` // root comment ID for the triggering threadTriggerCommentContent string `json:"trigger_comment_content,omitempty"` // content of the triggering commentTriggerSummary *string `json:"trigger_summary,omitempty"` // canonical short description snapshot — comment text / autopilot title — taken at task creation; survives source edits/deletesTriggerAuthorType string `json:"trigger_author_type,omitempty"` // "agent" or "member" — author kind of the triggering commentdiff --git a/server/internal/handler/daemon.go b/server/internal/handler/daemon.goindex a2d35a4eff..0651be1e39 100644--- a/server/internal/handler/daemon.go+++ b/server/internal/handler/daemon.go@@ -1257,6 +1257,10 @@ func (h *Handler) ClaimTaskByRuntime(w http.ResponseWriter, r *http.Request) {if task.TriggerCommentID.Valid {if comment, err := h.Queries.GetComment(r.Context(), task.TriggerCommentID); err == nil {resp.TriggerCommentContent = comment.Content+ resp.TriggerThreadID = uuidToString(comment.ID)+ if comment.ParentID.Valid {+ resp.TriggerThreadID = uuidToString(comment.ParentID)+ }resp.TriggerAuthorType = comment.AuthorTypeswitch comment.AuthorType {case "agent":