Skip to content

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

Go

fix(server): preserve legacy handoff notes (#7989)

Bohan Jiang0eff894b59b6
diff --git a/server/internal/daemon/handoff_prompt_test.go b/server/internal/daemon/handoff_prompt_test.go
new file mode 100644
index 0000000000..e8586e4a40
--- /dev/null
+++ b/server/internal/daemon/handoff_prompt_test.go
@@ -0,0 +1,27 @@
+package daemon
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestBuildPromptAssignmentHandoffIsPerTurnContext(t *testing.T) {
+ note := "Only touch the login flow; do not change payments."
+ out := BuildPrompt(Task{IssueID: "issue-123", HandoffNote: note}, "claude")
+
+ for _, want := range []string{note, "handoff note", "multica issue get issue-123"} {
+ if !strings.Contains(out, want) {
+ t.Fatalf("assignment prompt missing %q:\n%s", want, out)
+ }
+ }
+ if strings.Contains(out, "quick-create assistant") {
+ t.Fatalf("handoff task must stay on the assignment prompt branch:\n%s", out)
+ }
+}
+
+func TestBuildPromptAssignmentWithoutHandoffStaysClean(t *testing.T) {
+ out := BuildPrompt(Task{IssueID: "issue-123"}, "claude")
+ if strings.Contains(out, "handoff note") {
+ t.Fatalf("assignment without a note gained handoff framing:\n%s", out)
+ }
+}
diff --git a/server/internal/daemon/prompt.go b/server/internal/daemon/prompt.go
index 8ef9d5a0c5..da6681abe7 100644
--- a/server/internal/daemon/prompt.go
+++ b/server/internal/daemon/prompt.go
@@ -214,6 +214,12 @@ func buildPromptBody(task Task, provider string) string {
var b strings.Builder
b.WriteString("You are running as a local coding agent for a Multica workspace.\n\n")
fmt.Fprintf(&b, "Your assigned issue ID is: %s\n\n", task.IssueID)
+ // Assignment handoff is run-scoped data from legacy clients. Keep it in the
+ // per-turn prompt rather than the cached runtime brief (MUL-5377).
+ if task.HandoffNote != "" {
+ b.WriteString("You were handed this issue with a handoff note. Treat it as the assigner's scoping instruction for this run; follow it before doing anything broader, and do not reply to it as if it were a comment:\n\n")
+ fmt.Fprintf(&b, "> %s\n\n", task.HandoffNote)
+ }
fmt.Fprintf(&b, "Start by running `multica issue get %s --output json` to understand your task, then complete it.\n", task.IssueID)
fmt.Fprintf(&b, "For comment history, follow the rule in your runtime workflow file (assignment-triggered tasks treat the read as mandatory). Scan the threads first with `multica issue comment list %s --roots-only --summary --compact --output json`, then expand only what matters with `--thread <thread-id> --tail 30`. For `--since` incremental polling, pagination, and folding, see `multica issue comment list --help`.\n", task.IssueID)
return b.String()
diff --git a/server/internal/daemon/types.go b/server/internal/daemon/types.go
index 856458476b..25f95e672c 100644
--- a/server/internal/daemon/types.go
+++ b/server/internal/daemon/types.go
@@ -137,6 +137,7 @@ type Task struct {
QuickCreateDueDate string `json:"quick_create_due_date,omitempty"` // explicit calendar due date selected in quick-create
QuickCreateAttachmentIDs []string `json:"quick_create_attachment_ids,omitempty"` // attachments uploaded in the quick-create prompt and bound by issue create
QuickCreateSourceContext json.RawMessage `json:"quick_create_source_context,omitempty"` // immutable historical context, separate from the new instruction
+ HandoffNote string `json:"handoff_note,omitempty"` // legacy assignment handoff instruction; rendered only in the per-turn prompt
SquadID string `json:"squad_id,omitempty"` // when the picker was a squad, the squad's UUID; Agent is still the resolved leader
SquadName string `json:"squad_name,omitempty"` // display name for the picker squad, used in prompt text
diff --git a/server/internal/handler/agent.go b/server/internal/handler/agent.go
index a74500fd90..16fdc61d42 100644
--- a/server/internal/handler/agent.go
+++ b/server/internal/handler/agent.go
@@ -461,6 +461,7 @@ type AgentTaskResponse struct {
QuickCreateDueDate string `json:"quick_create_due_date,omitempty"` // explicit calendar due date selected in quick-create
QuickCreateAttachmentIDs []string `json:"quick_create_attachment_ids,omitempty"` // attachment ids uploaded in the quick-create prompt and bound on issue create
QuickCreateSourceContext json.RawMessage `json:"quick_create_source_context,omitempty"` // immutable historical context for source-context quick-create
+ HandoffNote string `json:"handoff_note,omitempty"` // legacy assignment handoff instruction retained for installed clients; rendered by the daemon only in the per-turn prompt
SquadID string `json:"squad_id,omitempty"` // for quick-create tasks where the picker was a squad; Agent is still the resolved leader
SquadName string `json:"squad_name,omitempty"` // display name for the picker squad
ParentIssueID string `json:"parent_issue_id,omitempty"` // for quick-create tasks opened from "Add sub issue" — UUID of the parent issue the new issue should be filed under
@@ -756,6 +757,10 @@ func taskToResponse(t db.AgentTaskQueue, workspaceID string) AgentTaskResponse {
if t.BranchName.Valid {
branchName = t.BranchName.String
}
+ handoffNote := ""
+ if t.HandoffNote.Valid {
+ handoffNote = t.HandoffNote.String
+ }
return AgentTaskResponse{
ID: uuidToString(t.ID),
AgentID: uuidToString(t.AgentID),
@@ -780,6 +785,7 @@ func taskToResponse(t db.AgentTaskQueue, workspaceID string) AgentTaskResponse {
CoalescedCommentIDs: uuidsToStrings(t.CoalescedCommentIds),
DeliveredCommentIDs: uuidStringsOrEmpty(t.DeliveredCommentIds),
TriggerSummary: textToPtr(t.TriggerSummary),
+ HandoffNote: handoffNote,
WorkDir: workDir,
RelativeWorkDir: relativeWorkDir(workDir, workspaceID, uuidToString(t.ID)),
DurableWorkDir: durableWorkDir,
diff --git a/server/internal/handler/issue.go b/server/internal/handler/issue.go
index 3903527871..a3d24d9e69 100644
--- a/server/internal/handler/issue.go
+++ b/server/internal/handler/issue.go
@@ -3138,6 +3138,10 @@ type UpdateIssueRequest struct {
// the issue can be run later via manual run/rerun. Optional; omitted or
// false keeps today's behavior. Mirrors comment suppress_agent_ids.
SuppressRun bool `json:"suppress_run,omitempty"`
+ // HandoffNote is retained at the API boundary for installed clients that
+ // predate the handoff UI removal. It is consumed only when this write starts
+ // a run and is never stored on the issue itself.
+ HandoffNote string `json:"handoff_note,omitempty"`
}
func mergeIssueChannelMediaDescription(current, incoming string, base *string, attachments []db.Attachment) string {
@@ -3662,7 +3666,7 @@ func (h *Handler) UpdateIssue(w http.ResponseWriter, r *http.Request) {
},
h.issueTriggerWriteProbe(r, actorType, actorID, issue),
); ok && !req.SuppressRun {
- h.dispatchIssueRun(r.Context(), issue, trigger, actorType, actorID)
+ h.dispatchIssueRun(r.Context(), issue, trigger, actorType, actorID, req.HandoffNote)
}
// Platform-driven parent notification: when this issue transitions into
@@ -4344,7 +4348,7 @@ func (h *Handler) BatchUpdateIssues(w http.ResponseWriter, r *http.Request) {
},
h.issueTriggerWriteProbe(r, actorType, actorID, issue),
); ok && !req.Updates.SuppressRun {
- h.dispatchIssueRun(r.Context(), issue, trigger, actorType, actorID)
+ h.dispatchIssueRun(r.Context(), issue, trigger, actorType, actorID, req.Updates.HandoffNote)
}
// No status change — not even → cancelled — cancels active tasks here,
diff --git a/server/internal/handler/issue_trigger.go b/server/internal/handler/issue_trigger.go
index d5791b2642..b48d8c13be 100644
--- a/server/internal/handler/issue_trigger.go
+++ b/server/internal/handler/issue_trigger.go
@@ -77,17 +77,19 @@ func (h *Handler) shouldSuppressActiveSelfAssignment(ctx context.Context, actorT
}
// dispatchIssueRun executes the enqueue side effect for a decision produced by
-// WillEnqueueRun. The squad path still flows through enqueueSquadLeaderTask so
-// the leader access gate and pending dedup stay in one place.
-func (h *Handler) dispatchIssueRun(ctx context.Context, issue db.Issue, trigger service.IssueRunTrigger, actorType, actorID string) {
+// WillEnqueueRun. handoffNote is a legacy API input retained for installed
+// clients and travels only with a run that actually starts. The squad path
+// still flows through enqueueSquadLeaderTask so the leader access gate and
+// pending dedup stay in one place.
+func (h *Handler) dispatchIssueRun(ctx context.Context, issue db.Issue, trigger service.IssueRunTrigger, actorType, actorID, handoffNote string) {
switch trigger.AssigneeType {
case "agent":
// The member who performed this assign/promote is the accountable human
// for the run (MUL-4302 §4). An agent actor is not a human, so only a
// member actor is threaded; otherwise attribution falls back to the chain.
- _, _ = h.TaskService.EnqueueTaskForIssueByActor(ctx, issue, memberActorUserID(actorType, actorID))
+ _, _ = h.TaskService.EnqueueTaskForIssueWithHandoff(ctx, issue, handoffNote, memberActorUserID(actorType, actorID))
case "squad":
- h.enqueueSquadLeaderTask(ctx, issue, pgtype.UUID{}, actorType, actorID)
+ h.enqueueSquadLeaderTask(ctx, issue, pgtype.UUID{}, actorType, actorID, handoffNote)
}
}
diff --git a/server/internal/handler/issue_trigger_preview_test.go b/server/internal/handler/issue_trigger_preview_test.go
index 564ed5d4da..fe2534a6fc 100644
--- a/server/internal/handler/issue_trigger_preview_test.go
+++ b/server/internal/handler/issue_trigger_preview_test.go
@@ -7,6 +7,9 @@ import (
"net/http/httptest"
"strings"
"testing"
+
+ "github.com/multica-ai/multica/server/internal/daemon"
+ "github.com/multica-ai/multica/server/internal/util"
)
// seededReadyAgentID returns a workspace agent that has a runtime bound (the
@@ -220,6 +223,52 @@ func TestUpdateIssueSuppressRunSkipsEnqueue(t *testing.T) {
}
}
+// TestLegacyV0438HandoffPayloadReachesTaskPrompt is the cross-version guard
+// for installed clients: the v0.4.38 update payload must survive the current
+// API, task queue, claim wire shape, and daemon prompt rendering.
+func TestLegacyV0438HandoffPayloadReachesTaskPrompt(t *testing.T) {
+ agentID := seededReadyAgentID(t)
+ note := "Only touch the login flow."
+ issue := createIssueForTest(t, map[string]any{
+ "title": "legacy handoff compatibility",
+ "status": "todo",
+ })
+
+ w := httptest.NewRecorder()
+ req := withURLParam(newRequest("PUT", "/api/issues/"+issue.ID, map[string]any{
+ "assignee_type": "agent",
+ "assignee_id": agentID,
+ "handoff_note": note,
+ }), "id", issue.ID)
+ testHandler.UpdateIssue(w, req)
+ if w.Code != http.StatusOK {
+ t.Fatalf("UpdateIssue with v0.4.38 handoff payload: %d %s", w.Code, w.Body.String())
+ }
+
+ tasks, err := testHandler.Queries.ListTasksByIssue(context.Background(), util.MustParseUUID(issue.ID))
+ if err != nil {
+ t.Fatalf("ListTasksByIssue: %v", err)
+ }
+ if len(tasks) != 1 {
+ t.Fatalf("legacy handoff update queued %d tasks, want 1", len(tasks))
+ }
+
+ claimJSON, err := json.Marshal(taskToResponse(tasks[0], testWorkspaceID))
+ if err != nil {
+ t.Fatalf("marshal claim response: %v", err)
+ }
+ var claimed daemon.Task
+ if err := json.Unmarshal(claimJSON, &claimed); err != nil {
+ t.Fatalf("decode daemon task: %v", err)
+ }
+ if claimed.HandoffNote != note {
+ t.Fatalf("claimed handoff note = %q, want %q", claimed.HandoffNote, note)
+ }
+ if prompt := daemon.BuildPrompt(claimed, "codex"); !strings.Contains(prompt, note) {
+ t.Fatalf("daemon prompt dropped legacy handoff note:\n%s", prompt)
+ }
+}
+
// TestPreviewIssueTrigger_MalformedBody verifies the endpoint rejects a
// malformed body with 400 rather than a 500 or a silent empty result.
func TestPreviewIssueTrigger_MalformedBody(t *testing.T) {
diff --git a/server/internal/handler/squad.go b/server/internal/handler/squad.go
index 178c377cc1..4ca3c46720 100644
--- a/server/internal/handler/squad.go
+++ b/server/internal/handler/squad.go
@@ -1171,7 +1171,7 @@ func commentMentionsAnyone(content string) bool {
// paths go through computeCommentAgentTriggers so preview and create share the
// same trigger set.
// It returns true only when a leader task was actually enqueued.
-func (h *Handler) enqueueSquadLeaderTask(ctx context.Context, issue db.Issue, triggerCommentID pgtype.UUID, authorType, authorID string) bool {
+func (h *Handler) enqueueSquadLeaderTask(ctx context.Context, issue db.Issue, triggerCommentID pgtype.UUID, authorType, authorID, handoffNote string) bool {
squad, err := h.Queries.GetSquadInWorkspace(ctx, db.GetSquadInWorkspaceParams{
ID: issue.AssigneeID,
WorkspaceID: issue.WorkspaceID,
@@ -1210,12 +1210,13 @@ func (h *Handler) enqueueSquadLeaderTask(ctx context.Context, issue db.Issue, tr
return false
}
- // triggerCommentID is always empty on the assign/promote path.
+ // triggerCommentID is always empty on the assign/promote path; legacy
+ // handoff text rides its dedicated task column instead.
_ = triggerCommentID
// The member who performed the assign/promote is the accountable human for the
// leader run (MUL-4302 §4) — the same principal the gate above judged. An agent
// author is not a human, so only a member actor is threaded.
- if _, err := h.TaskService.EnqueueTaskForSquadLeaderByActor(ctx, issue, squad.LeaderID, squad.ID, memberActorUserID(authorType, authorID)); err != nil {
+ if _, err := h.TaskService.EnqueueTaskForSquadLeaderWithHandoff(ctx, issue, squad.LeaderID, squad.ID, handoffNote, memberActorUserID(authorType, authorID)); err != nil {
slog.Warn("enqueue squad leader task failed",
"issue_id", uuidToString(issue.ID),
"squad_id", uuidToString(squad.ID),
diff --git a/server/internal/service/task.go b/server/internal/service/task.go
index 3c2102c705..9342aae732 100644
--- a/server/internal/service/task.go
+++ b/server/internal/service/task.go
@@ -1095,7 +1095,7 @@ func (s *TaskService) EnqueueTaskForIssue(ctx context.Context, issue db.Issue, t
if len(triggerCommentID) > 0 {
commentID = triggerCommentID[0]
}
- return s.enqueueIssueTask(ctx, issue, commentID, false, pgtype.UUID{}, pgtype.UUID{}, pgtype.Timestamptz{})
+ return s.enqueueIssueTask(ctx, issue, commentID, false, "", pgtype.UUID{}, pgtype.UUID{}, pgtype.Timestamptz{})
}
// EnqueueDeferredChannelIssueTask persists the assigned task for a media-backed
@@ -1103,7 +1103,7 @@ func (s *TaskService) EnqueueTaskForIssue(ctx context.Context, issue db.Issue, t
// crash-safe fallback; the channel router promotes the task as soon as the
// detached attachment transaction settles.
func (s *TaskService) EnqueueDeferredChannelIssueTask(ctx context.Context, issue db.Issue, fireAt time.Time) (db.AgentTaskQueue, error) {
- return s.enqueueIssueTask(ctx, issue, pgtype.UUID{}, false, pgtype.UUID{}, pgtype.UUID{}, pgtype.Timestamptz{Time: fireAt, Valid: true})
+ return s.enqueueIssueTask(ctx, issue, pgtype.UUID{}, false, "", pgtype.UUID{}, pgtype.UUID{}, pgtype.Timestamptz{Time: fireAt, Valid: true})
}
// createDeferredChannelIssueTaskWithQueries inserts the inert media-gated task
@@ -1114,7 +1114,7 @@ func (s *TaskService) EnqueueDeferredChannelIssueTask(ctx context.Context, issue
// commit without holding database locks across a network call.
func (s *TaskService) createDeferredChannelIssueTaskWithQueries(ctx context.Context, q *db.Queries, issue db.Issue, fireAt time.Time) (db.AgentTaskQueue, error) {
txService := &TaskService{Queries: q}
- return txService.enqueueIssueTask(ctx, issue, pgtype.UUID{}, false, pgtype.UUID{}, pgtype.UUID{}, pgtype.Timestamptz{Time: fireAt, Valid: true})
+ return txService.enqueueIssueTask(ctx, issue, pgtype.UUID{}, false, "", pgtype.UUID{}, pgtype.UUID{}, pgtype.Timestamptz{Time: fireAt, Valid: true})
}
// hydrateDeferredChannelIssueTaskOverlay fills the optional Composio overlay
@@ -1154,7 +1154,15 @@ func (s *TaskService) hydrateDeferredChannelIssueTaskOverlay(ctx context.Context
// assign/promote and becomes the accountable human for the run (MUL-4302 §4);
// invalid when the caller has no member actor.
func (s *TaskService) EnqueueTaskForIssueByActor(ctx context.Context, issue db.Issue, actorUserID pgtype.UUID) (db.AgentTaskQueue, error) {
- return s.enqueueIssueTask(ctx, issue, pgtype.UUID{}, false, actorUserID, pgtype.UUID{}, pgtype.Timestamptz{})
+ return s.enqueueIssueTask(ctx, issue, pgtype.UUID{}, false, "", actorUserID, pgtype.UUID{}, pgtype.Timestamptz{})
+}
+
+// EnqueueTaskForIssueWithHandoff is the backward-compatible assign/promote
+// variant used when an installed client still sends handoff_note. The note is
+// persisted on the task so both old and current daemons can render it in the
+// run's opening prompt. Empty text behaves like EnqueueTaskForIssueByActor.
+func (s *TaskService) EnqueueTaskForIssueWithHandoff(ctx context.Context, issue db.Issue, handoffNote string, actorUserID pgtype.UUID) (db.AgentTaskQueue, error) {
+ return s.enqueueIssueTask(ctx, issue, pgtype.UUID{}, false, handoffNote, actorUserID, pgtype.UUID{}, pgtype.Timestamptz{})
}
// enqueueIssueTask is the shared implementation behind EnqueueTaskForIssue
@@ -1202,11 +1210,11 @@ func (s *TaskService) ResolveIssueReviewSHAParam(ctx context.Context, issueID pg
return headShaText(s.ResolveIssueReviewSHA(ctx, issueID))
}
-func (s *TaskService) enqueueIssueTask(ctx context.Context, issue db.Issue, triggerCommentID pgtype.UUID, forceFreshSession bool, actorUserID pgtype.UUID, rerunOfTaskID pgtype.UUID, fireAt pgtype.Timestamptz) (db.AgentTaskQueue, error) {
- return s.enqueueIssueTaskWithCommentPlan(ctx, issue, triggerCommentID, nil, forceFreshSession, actorUserID, rerunOfTaskID, fireAt)
+func (s *TaskService) enqueueIssueTask(ctx context.Context, issue db.Issue, triggerCommentID pgtype.UUID, forceFreshSession bool, handoffNote string, actorUserID pgtype.UUID, rerunOfTaskID pgtype.UUID, fireAt pgtype.Timestamptz) (db.AgentTaskQueue, error) {
+ return s.enqueueIssueTaskWithCommentPlan(ctx, issue, triggerCommentID, nil, forceFreshSession, handoffNote, actorUserID, rerunOfTaskID, fireAt)
}
-func (s *TaskService) enqueueIssueTaskWithCommentPlan(ctx context.Context, issue db.Issue, triggerCommentID pgtype.UUID, coalescedCommentIDs []pgtype.UUID, forceFreshSession bool, actorUserID pgtype.UUID, rerunOfTaskID pgtype.UUID, fireAt pgtype.Timestamptz) (db.AgentTaskQueue, error) {
+func (s *TaskService) enqueueIssueTaskWithCommentPlan(ctx context.Context, issue db.Issue, triggerCommentID pgtype.UUID, coalescedCommentIDs []pgtype.UUID, forceFreshSession bool, handoffNote string, actorUserID pgtype.UUID, rerunOfTaskID pgtype.UUID, fireAt pgtype.Timestamptz) (db.AgentTaskQueue, error) {
if !issue.AssigneeID.Valid {
slog.Error("task enqueue failed", "issue_id", util.UUIDToString(issue.ID), "error", "issue has no assignee")
return db.AgentTaskQueue{}, fmt.Errorf("issue has no assignee")
@@ -1252,6 +1260,7 @@ func (s *TaskService) enqueueIssueTaskWithCommentPlan(ctx context.Context, issue
CoalescedCommentIds: coalescedCommentIDs,
TriggerSummary: s.buildCommentTriggerSummary(ctx, issue.WorkspaceID, triggerCommentID),
ForceFreshSession: pgtype.Bool{Bool: forceFreshSession, Valid: forceFreshSession},
+ HandoffNote: pgtype.Text{String: handoffNote, Valid: handoffNote != ""},
OriginatorUserID: originatorUserID,
AccountableUserID: attr.AccountableUserID,
RuleVersionID: attr.RuleVersionID,
@@ -1279,6 +1288,7 @@ func (s *TaskService) enqueueIssueTaskWithCommentPlan(ctx context.Context, issue
TriggerSummary: createParams.TriggerSummary,
ForceFreshSession: createParams.ForceFreshSession,
IsLeaderTask: createParams.IsLeaderTask,
+ HandoffNote: createParams.HandoffNote,
SquadID: createParams.SquadID,
HeadSha: createParams.HeadSha,
OriginatorUserID: createParams.OriginatorUserID,
@@ -1325,13 +1335,13 @@ func (s *TaskService) enqueueIssueTaskWithCommentPlan(ctx context.Context, issue
// Unlike EnqueueTaskForIssue, this takes an explicit agent ID rather than
// deriving it from the issue assignee.
func (s *TaskService) EnqueueTaskForMention(ctx context.Context, issue db.Issue, agentID pgtype.UUID, triggerCommentID pgtype.UUID) (db.AgentTaskQueue, error) {
- return s.enqueueMentionTask(ctx, issue, agentID, triggerCommentID, false, pgtype.UUID{}, false, pgtype.UUID{}, pgtype.UUID{})
+ return s.enqueueMentionTask(ctx, issue, agentID, triggerCommentID, false, pgtype.UUID{}, false, "", pgtype.UUID{}, pgtype.UUID{})
}
// EnqueueTaskForThreadParent creates a queued task for the agent who authored
// the direct parent comment a member replied to.
func (s *TaskService) EnqueueTaskForThreadParent(ctx context.Context, issue db.Issue, agentID pgtype.UUID, triggerCommentID pgtype.UUID) (db.AgentTaskQueue, error) {
- return s.enqueueMentionTask(ctx, issue, agentID, triggerCommentID, false, pgtype.UUID{}, false, pgtype.UUID{}, pgtype.UUID{})
+ return s.enqueueMentionTask(ctx, issue, agentID, triggerCommentID, false, pgtype.UUID{}, false, "", pgtype.UUID{}, pgtype.UUID{})
}
// EnqueueTaskForSquadLeader is the leader-role variant of EnqueueTaskForMention.
@@ -1346,7 +1356,7 @@ func (s *TaskService) EnqueueTaskForThreadParent(ctx context.Context, issue db.I
// leader task was triggered (comment @squad, issue assign, autopilot,
// sub-issue done callback). See migration 127.
func (s *TaskService) EnqueueTaskForSquadLeader(ctx context.Context, issue db.Issue, leaderID pgtype.UUID, squadID pgtype.UUID, triggerCommentID pgtype.UUID) (db.AgentTaskQueue, error) {
- return s.enqueueMentionTask(ctx, issue, leaderID, triggerCommentID, true, squadID, false, pgtype.UUID{}, pgtype.UUID{})
+ return s.enqueueMentionTask(ctx, issue, leaderID, triggerCommentID, true, squadID, false, "", pgtype.UUID{}, pgtype.UUID{})
}
// EnqueueTaskForSquadLeaderByActor is the assign/promote variant of
@@ -1354,14 +1364,20 @@ func (s *TaskService) EnqueueTaskForSquadLeader(ctx context.Context, issue db.Is
// assign/promote and becomes the accountable human (MUL-4302 §4); invalid when
// the caller has no member actor.
func (s *TaskService) EnqueueTaskForSquadLeaderByActor(ctx context.Context, issue db.Issue, leaderID pgtype.UUID, squadID pgtype.UUID, actorUserID pgtype.UUID) (db.AgentTaskQueue, error) {
- return s.enqueueMentionTask(ctx, issue, leaderID, pgtype.UUID{}, true, squadID, false, actorUserID, pgtype.UUID{})
+ return s.enqueueMentionTask(ctx, issue, leaderID, pgtype.UUID{}, true, squadID, false, "", actorUserID, pgtype.UUID{})
+}
+
+// EnqueueTaskForSquadLeaderWithHandoff is the squad equivalent of
+// EnqueueTaskForIssueWithHandoff.
+func (s *TaskService) EnqueueTaskForSquadLeaderWithHandoff(ctx context.Context, issue db.Issue, leaderID pgtype.UUID, squadID pgtype.UUID, handoffNote string, actorUserID pgtype.UUID) (db.AgentTaskQueue, error) {
+ return s.enqueueMentionTask(ctx, issue, leaderID, pgtype.UUID{}, true, squadID, false, handoffNote, actorUserID, pgtype.UUID{})
}
-func (s *TaskService) enqueueMentionTask(ctx context.Context, issue db.Issue, agentID pgtype.UUID, triggerCommentID pgtype.UUID, isLeader bool, squadID pgtype.UUID, forceFreshSession bool, actorUserID pgtype.UUID, rerunOfTaskID pgtype.UUID) (db.AgentTaskQueue, error) {
- return s.enqueueMentionTaskWithCommentPlan(ctx, issue, agentID, triggerCommentID, nil, isLeader, squadID, forceFreshSession, actorUserID, rerunOfTaskID)
+func (s *TaskService) enqueueMentionTask(ctx context.Context, issue db.Issue, agentID pgtype.UUID, triggerCommentID pgtype.UUID, isLeader bool, squadID pgtype.UUID, forceFreshSession bool, handoffNote string, actorUserID pgtype.UUID, rerunOfTaskID pgtype.UUID) (db.AgentTaskQueue, error) {
+ return s.enqueueMentionTaskWithCommentPlan(ctx, issue, agentID, triggerCommentID, nil, isLeader, squadID, forceFreshSession, handoffNote, actorUserID, rerunOfTaskID)
}
-func (s *TaskService) enqueueMentionTaskWithCommentPlan(ctx context.Context, issue db.Issue, agentID pgtype.UUID, triggerCommentID pgtype.UUID, coalescedCommentIDs []pgtype.UUID, isLeader bool, squadID pgtype.UUID, forceFreshSession bool, actorUserID pgtype.UUID, rerunOfTaskID pgtype.UUID) (db.AgentTaskQueue, error) {
+func (s *TaskService) enqueueMentionTaskWithCommentPlan(ctx context.Context, issue db.Issue, agentID pgtype.UUID, triggerCommentID pgtype.UUID, coalescedCommentIDs []pgtype.UUID, isLeader bool, squadID pgtype.UUID, forceFreshSession bool, handoffNote string, actorUserID pgtype.UUID, rerunOfTaskID pgtype.UUID) (db.AgentTaskQueue, error) {
agent, err := s.Queries.GetAgent(ctx, agentID)
if err != nil {
slog.Error("mention task enqueue failed: agent not found", "issue_id", util.UUIDToString(issue.ID), "agent_id", util.UUIDToString(agentID), "error", err)
@@ -1402,6 +1418,7 @@ func (s *TaskService) enqueueMentionTaskWithCommentPlan(ctx context.Context, iss
TriggerSummary: s.buildCommentTriggerSummary(ctx, issue.WorkspaceID, triggerCommentID),
IsLeaderTask: pgtype.Bool{Bool: isLeader, Valid: isLeader},
ForceFreshSession: pgtype.Bool{Bool: forceFreshSession, Valid: forceFreshSession},
+ HandoffNote: pgtype.Text{String: handoffNote, Valid: handoffNote != ""},
SquadID: squadID,
OriginatorUserID: originatorUserID,
AccountableUserID: attr.AccountableUserID,
@@ -5713,9 +5730,9 @@ func (s *TaskService) promoteNewestSurvivingComment(ctx context.Context, ids []p
func (s *TaskService) enqueueRerunTask(ctx context.Context, issue db.Issue, agentID pgtype.UUID, triggerCommentID pgtype.UUID, coalescedCommentIDs []pgtype.UUID, isLeader bool, squadID pgtype.UUID, actorUserID pgtype.UUID, rerunOfTaskID pgtype.UUID) (db.AgentTaskQueue, error) {
if issue.AssigneeType.String == "agent" && issue.AssigneeID.Valid &&
util.UUIDToString(issue.AssigneeID) == util.UUIDToString(agentID) {
- return s.enqueueIssueTaskWithCommentPlan(ctx, issue, triggerCommentID, coalescedCommentIDs, true, actorUserID, rerunOfTaskID, pgtype.Timestamptz{})
+ return s.enqueueIssueTaskWithCommentPlan(ctx, issue, triggerCommentID, coalescedCommentIDs, true, "", actorUserID, rerunOfTaskID, pgtype.Timestamptz{})
}
- return s.enqueueMentionTaskWithCommentPlan(ctx, issue, agentID, triggerCommentID, coalescedCommentIDs, isLeader, squadID, true, actorUserID, rerunOfTaskID)
+ return s.enqueueMentionTaskWithCommentPlan(ctx, issue, agentID, triggerCommentID, coalescedCommentIDs, isLeader, squadID, true, "", actorUserID, rerunOfTaskID)
}
// The bulk terminal writes below are the sweeper, archive and daemon-recovery
diff --git a/server/pkg/db/generated/agent.sql.go b/server/pkg/db/generated/agent.sql.go
index d0bf172bab..b2f585fa19 100644
--- a/server/pkg/db/generated/agent.sql.go
+++ b/server/pkg/db/generated/agent.sql.go
@@ -2281,7 +2281,7 @@ func (q *Queries) CreateAgentBuilder(ctx context.Context, arg CreateAgentBuilder
const createAgentTask = `-- name: CreateAgentTask :one
INSERT INTO agent_task_queue (
agent_id, runtime_id, issue_id, status, priority, trigger_comment_id,
- coalesced_comment_ids, trigger_summary, force_fresh_session, is_leader_task,
+ coalesced_comment_ids, trigger_summary, force_fresh_session, is_leader_task, handoff_note,
squad_id, context, originator_user_id, accountable_user_id, runtime_mcp_overlay, runtime_connected_apps,
originator_source, delegated_from_task_id, rule_version_id, rerun_of_task_id, trigger_evidence_kind, trigger_evidence_ref_id,
id
@@ -2293,12 +2293,12 @@ SELECT
COALESCE($8::boolean, FALSE),
COALESCE($9::boolean, FALSE),
$10,
+ $11,
CASE
- WHEN COALESCE($11::text, '') <> ''
- THEN jsonb_build_object('head_sha', $11::text)
+ WHEN COALESCE($12::text, '') <> ''
+ THEN jsonb_build_object('head_sha', $12::text)
ELSE NULL
END,
- $12,
$13,
$14,
$15,
@@ -2308,7 +2308,8 @@ SELECT
$19,
$20,
$21,
- COALESCE($22::uuid, gen_random_uuid())
+ $22,
+ COALESCE($23::uuid, gen_random_uuid())
WHERE lock_task_owner_rows($1, $3, $2)
RETURNING id, agent_id, issue_id, status, priority, dispatched_at, started_at, completed_at, result, error, created_at, context, runtime_id, session_id, work_dir, trigger_comment_id, chat_session_id, autopilot_run_id, attempt, max_attempts, parent_task_id, failure_reason, trigger_summary, force_fresh_session, is_leader_task, wait_reason, initiator_user_id, handoff_note, prepare_lease_expires_at, squad_id, runtime_mcp_overlay, escalation_for_task_id, fire_at, originator_user_id, runtime_connected_apps, coalesced_comment_ids, delivered_comment_ids, chat_input_task_id, chat_finalize_deferred_at, originator_source, delegated_from_task_id, retry_of_task_id, rerun_of_task_id, rule_version_id, trigger_evidence_kind, trigger_evidence_ref_id, accountable_user_id, session_rollout_missing, retired_session_id, quick_actions_disabled, regenerate_quick_actions_for, branch_name, durable_work_dir, channel_context_revision
`
@@ -2323,6 +2324,7 @@ type CreateAgentTaskParams struct {
TriggerSummary pgtype.Text `json:"trigger_summary"`
ForceFreshSession pgtype.Bool `json:"force_fresh_session"`
IsLeaderTask pgtype.Bool `json:"is_leader_task"`
+ HandoffNote pgtype.Text `json:"handoff_note"`
SquadID pgtype.UUID `json:"squad_id"`
HeadSha pgtype.Text `json:"head_sha"`
OriginatorUserID pgtype.UUID `json:"originator_user_id"`
@@ -2367,6 +2369,7 @@ func (q *Queries) CreateAgentTask(ctx context.Context, arg CreateAgentTaskParams
arg.TriggerSummary,
arg.ForceFreshSession,
arg.IsLeaderTask,
+ arg.HandoffNote,
arg.SquadID,
arg.HeadSha,
arg.OriginatorUserID,
@@ -2588,7 +2591,7 @@ func (q *Queries) CreateDeferredAgentTask(ctx context.Context, arg CreateDeferre
const createDeferredChannelIssueTask = `-- name: CreateDeferredChannelIssueTask :one
INSERT INTO agent_task_queue (
agent_id, runtime_id, issue_id, status, priority, trigger_comment_id,
- coalesced_comment_ids, trigger_summary, force_fresh_session, is_leader_task,
+ coalesced_comment_ids, trigger_summary, force_fresh_session, is_leader_task, handoff_note,
squad_id, context, originator_user_id, accountable_user_id, runtime_mcp_overlay, runtime_connected_apps,
originator_source, delegated_from_task_id, rule_version_id, rerun_of_task_id,
trigger_evidence_kind, trigger_evidence_ref_id, fire_at,
@@ -2601,11 +2604,11 @@ SELECT
COALESCE($8::boolean, FALSE),
COALESCE($9::boolean, FALSE),
$10,
+ $11,
jsonb_strip_nulls(jsonb_build_object(
- 'head_sha', NULLIF(COALESCE($11::text, ''), ''),
+ 'head_sha', NULLIF(COALESCE($12::text, ''), ''),
'channel_issue_media_pending', TRUE
)),
- $12,
$13,
$14,
$15,
@@ -2616,7 +2619,8 @@ SELECT
$20,
$21,
$22,
- COALESCE($23::uuid, gen_random_uuid())
+ $23,
+ COALESCE($24::uuid, gen_random_uuid())
WHERE lock_task_owner_rows($1, $3, $2)
RETURNING id, agent_id, issue_id, status, priority, dispatched_at, started_at, completed_at, result, error, created_at, context, runtime_id, session_id, work_dir, trigger_comment_id, chat_session_id, autopilot_run_id, attempt, max_attempts, parent_task_id, failure_reason, trigger_summary, force_fresh_session, is_leader_task, wait_reason, initiator_user_id, handoff_note, prepare_lease_expires_at, squad_id, runtime_mcp_overlay, escalation_for_task_id, fire_at, originator_user_id, runtime_connected_apps, coalesced_comment_ids, delivered_comment_ids, chat_input_task_id, chat_finalize_deferred_at, originator_source, delegated_from_task_id, retry_of_task_id, rerun_of_task_id, rule_version_id, trigger_evidence_kind, trigger_evidence_ref_id, accountable_user_id, session_rollout_missing, retired_session_id, quick_actions_disabled, regenerate_quick_actions_for, branch_name, durable_work_dir, channel_context_revision
`
@@ -2631,6 +2635,7 @@ type CreateDeferredChannelIssueTaskParams struct {
TriggerSummary pgtype.Text `json:"trigger_summary"`
ForceFreshSession pgtype.Bool `json:"force_fresh_session"`
IsLeaderTask pgtype.Bool `json:"is_leader_task"`
+ HandoffNote pgtype.Text `json:"handoff_note"`
SquadID pgtype.UUID `json:"squad_id"`
HeadSha pgtype.Text `json:"head_sha"`
OriginatorUserID pgtype.UUID `json:"originator_user_id"`
@@ -2665,6 +2670,7 @@ func (q *Queries) CreateDeferredChannelIssueTask(ctx context.Context, arg Create
arg.TriggerSummary,
arg.ForceFreshSession,
arg.IsLeaderTask,
+ arg.HandoffNote,
arg.SquadID,
arg.HeadSha,
arg.OriginatorUserID,
diff --git a/server/pkg/db/queries/agent.sql b/server/pkg/db/queries/agent.sql
index 9bb3fa569d..05c135412f 100644
--- a/server/pkg/db/queries/agent.sql
+++ b/server/pkg/db/queries/agent.sql
@@ -299,7 +299,7 @@ ORDER BY created_at DESC;
-- The same pattern is used by every INSERT listed in pkg/dbid's write table.
INSERT INTO agent_task_queue (
agent_id, runtime_id, issue_id, status, priority, trigger_comment_id,
- coalesced_comment_ids, trigger_summary, force_fresh_session, is_leader_task,
+ coalesced_comment_ids, trigger_summary, force_fresh_session, is_leader_task, handoff_note,
squad_id, context, originator_user_id, accountable_user_id, runtime_mcp_overlay, runtime_connected_apps,
originator_source, delegated_from_task_id, rule_version_id, rerun_of_task_id, trigger_evidence_kind, trigger_evidence_ref_id,
id
@@ -310,6 +310,7 @@ SELECT
sqlc.narg(trigger_summary),
COALESCE(sqlc.narg('force_fresh_session')::boolean, FALSE),
COALESCE(sqlc.narg('is_leader_task')::boolean, FALSE),
+ sqlc.narg(handoff_note),
sqlc.narg(squad_id),
CASE
WHEN COALESCE(sqlc.narg('head_sha')::text, '') <> ''
@@ -340,7 +341,7 @@ RETURNING *;
-- binding settles or the fire_at fallback is promoted by the normal sweeper.
INSERT INTO agent_task_queue (
agent_id, runtime_id, issue_id, status, priority, trigger_comment_id,
- coalesced_comment_ids, trigger_summary, force_fresh_session, is_leader_task,
+ coalesced_comment_ids, trigger_summary, force_fresh_session, is_leader_task, handoff_note,
squad_id, context, originator_user_id, accountable_user_id, runtime_mcp_overlay, runtime_connected_apps,
originator_source, delegated_from_task_id, rule_version_id, rerun_of_task_id,
trigger_evidence_kind, trigger_evidence_ref_id, fire_at,
@@ -352,6 +353,7 @@ SELECT
sqlc.narg(trigger_summary),
COALESCE(sqlc.narg('force_fresh_session')::boolean, FALSE),
COALESCE(sqlc.narg('is_leader_task')::boolean, FALSE),
+ sqlc.narg(handoff_note),
sqlc.narg(squad_id),
jsonb_strip_nulls(jsonb_build_object(
'head_sha', NULLIF(COALESCE(sqlc.narg('head_sha')::text, ''), ''),