Skip to content

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

Go

fix(server): preserve workflow assignees on description updates (MUL-8229) (#9506)

Yan Lobau601786123b7e
diff --git a/server/internal/handler/issue.go b/server/internal/handler/issue.go
index cf9492e1c6..e63cd8aea3 100644
--- a/server/internal/handler/issue.go
+++ b/server/internal/handler/issue.go
@@ -3652,14 +3652,15 @@ func mergeIssueChannelMediaDescription(current, incoming string, base *string, a
return merged
}
-func refreshUntouchedNullableIssueParams(params *db.UpdateIssueParams, current db.Issue, rawFields map[string]json.RawMessage) {
+func refreshUntouchedNullableIssueParams(params *db.UpdateIssueParams, current db.Issue, rawFields map[string]json.RawMessage, workflowAssignee bool) {
_, assigneeTypeTouched := rawFields["assignee_type"]
_, assigneeIDTouched := rawFields["assignee_id"]
// Assignee type and id form one validated value. If either half was
// supplied, retain the pre-validation counterpart in params rather than
// combining the supplied half with a concurrently-written counterpart that
- // has never been validated with it.
- if !assigneeTypeTouched && !assigneeIDTouched {
+ // has never been validated with it. A workflow-resolved assignee is also
+ // an intended write, even though the caller sent no assignee fields.
+ if !assigneeTypeTouched && !assigneeIDTouched && !workflowAssignee {
params.AssigneeType = current.AssigneeType
params.AssigneeID = current.AssigneeID
}
@@ -3682,7 +3683,7 @@ func refreshUntouchedNullableIssueParams(params *db.UpdateIssueParams, current d
var errIssueFieldConflict = errors.New("issue text field conflict")
-func (h *Handler) updateIssueAtomically(ctx context.Context, workspaceID pgtype.UUID, params db.UpdateIssueParams, rawFields map[string]json.RawMessage, titleBase, descriptionBase *string, attachmentIDs []pgtype.UUID, statusKey string) (db.Issue, db.Issue, bool, error) {
+func (h *Handler) updateIssueAtomically(ctx context.Context, workspaceID pgtype.UUID, params db.UpdateIssueParams, rawFields map[string]json.RawMessage, titleBase, descriptionBase *string, attachmentIDs []pgtype.UUID, statusKey string, workflowAssignee bool) (db.Issue, db.Issue, bool, error) {
if h.TxStarter == nil {
return db.Issue{}, db.Issue{}, false, errors.New("atomic issue update requires transaction starter")
}
@@ -3752,7 +3753,7 @@ func (h *Handler) updateIssueAtomically(ctx context.Context, workspaceID pgtype.
Valid: true,
}
}
- refreshUntouchedNullableIssueParams(&params, current, rawFields)
+ refreshUntouchedNullableIssueParams(&params, current, rawFields, workflowAssignee)
issue, cancelledWakeups, err := updateIssueStoppingWakeups(ctx, qtx, params)
if err != nil {
@@ -4050,7 +4051,7 @@ func (h *Handler) UpdateIssue(w http.ResponseWriter, r *http.Request) {
if req.Description != nil || req.TitleBase != nil || req.DescriptionBase != nil || len(attachmentIDs) > 0 {
var lockedPrev db.Issue
issue, lockedPrev, attachmentsChanged, err = h.updateIssueAtomically(
- writeCtx, prevIssue.WorkspaceID, params, rawFields, req.TitleBase, req.DescriptionBase, attachmentIDs, statusKeyForGuard,
+ writeCtx, prevIssue.WorkspaceID, params, rawFields, req.TitleBase, req.DescriptionBase, attachmentIDs, statusKeyForGuard, handoff != nil,
)
if lockedPrev.ID.Valid {
prevIssue = lockedPrev
@@ -4877,7 +4878,7 @@ func (h *Handler) BatchUpdateIssues(w http.ResponseWriter, r *http.Request) {
// legacy single-update clients that omit description_base.
var lockedPrev db.Issue
issue, lockedPrev, _, err = h.updateIssueAtomically(
- writeCtx, prevIssue.WorkspaceID, params, rawUpdates, nil, nil, nil, issueStatusGuard,
+ writeCtx, prevIssue.WorkspaceID, params, rawUpdates, nil, nil, nil, issueStatusGuard, handoff != nil,
)
if err == nil {
prevIssue = lockedPrev
diff --git a/server/internal/handler/issue_channel_media_merge_test.go b/server/internal/handler/issue_channel_media_merge_test.go
index e421da8f33..ad4272f8a0 100644
--- a/server/internal/handler/issue_channel_media_merge_test.go
+++ b/server/internal/handler/issue_channel_media_merge_test.go
@@ -81,7 +81,7 @@ func TestRefreshUntouchedNullableIssueParamsKeepsValidatedAssigneePair(t *testin
refreshUntouchedNullableIssueParams(&params, current, map[string]json.RawMessage{
"assignee_id": json.RawMessage(`"77777777-7777-4777-8777-777777777777"`),
- })
+ }, false)
if params.AssigneeType.String != "member" || params.AssigneeID != oldID {
t.Fatalf("validated assignee pair was recombined: type=%#v id=%#v", params.AssigneeType, params.AssigneeID)
diff --git a/server/internal/handler/issue_workflow_test.go b/server/internal/handler/issue_workflow_test.go
index 5a5f71370a..5ad9a2cd65 100644
--- a/server/internal/handler/issue_workflow_test.go
+++ b/server/internal/handler/issue_workflow_test.go
@@ -1239,3 +1239,67 @@ func TestHandoffDoesNotAlsoWakeTheHandler(t *testing.T) {
t.Fatal("another agent's wakeup missed the assignment")
}
}
+
+func TestDescriptionUpdatePreservesWorkflowHandoff(t *testing.T) {
+ seedTestCatalog(t)
+ targetAgent := seededReadyAgentID(t)
+ sourceAgent := dbfx.Agent(t, "Description handoff Agent A", handlerTestRuntimeID(t))
+ projectID := deliveryProject(t, "Description handoff project", targetAgent)
+ setColumnHandoff(t, projectID, "in_review", handToAgent(targetAgent, "Process the saved description.")).Want(http.StatusOK)
+ issueID := dbfx.Issue(t, "Saved result handoff", testutil.Cols{
+ "project_id": projectID, "status": "in_progress", "assignee_type": "agent", "assignee_id": sourceAgent,
+ })
+
+ updateIssueForTest(t, issueID, map[string]any{"status": "in_review", "description": "Updated description."}).Want(http.StatusOK)
+ _, kind, id := issueStatusAndAssignee(t, issueID)
+ if kind != "agent" || id != targetAgent {
+ t.Fatalf("saved assignee = %s/%s, want workflow-selected agent %s", kind, id, targetAgent)
+ }
+ if n := taskCountFor(t, issueID, targetAgent); n != 1 {
+ t.Fatalf("target agent runs = %d, want one without any follow-up comment", n)
+ }
+ if n := taskCountFor(t, issueID, sourceAgent); n != 0 {
+ t.Fatalf("source agent runs = %d, want none", n)
+ }
+ issue, err := testHandler.Queries.GetIssue(context.Background(), util.MustParseUUID(issueID))
+ if err != nil || issue.Description.String != "Updated description." {
+ t.Fatalf("saved result = %q, err = %v", issue.Description.String, err)
+ }
+ updateIssueForTest(t, issueID, map[string]any{"status": "in_review", "description": "Updated description."}).Want(http.StatusOK)
+ if n := taskCountFor(t, issueID, targetAgent); n != 1 {
+ t.Fatalf("unchanged-status retry created %d target agent runs, want one", n)
+ }
+}
+
+func TestBatchDescriptionUpdatePreservesWorkflowHandoff(t *testing.T) {
+ seedTestCatalog(t)
+ targetAgent := seededReadyAgentID(t)
+ sourceAgent := dbfx.Agent(t, "Batch description handoff Agent A", handlerTestRuntimeID(t))
+ projectID := deliveryProject(t, "Batch description handoff project", targetAgent)
+ setColumnHandoff(t, projectID, "in_review", handToAgent(targetAgent, "Process the saved description.")).Want(http.StatusOK)
+ issueID := dbfx.Issue(t, "Batch saved result handoff", testutil.Cols{
+ "project_id": projectID, "status": "in_progress", "assignee_type": "agent", "assignee_id": sourceAgent,
+ })
+ testutil.Call(t, testHandler.BatchUpdateIssues, workflowRequest(http.MethodPost, "/api/issues/batch", map[string]any{
+ "issue_ids": []string{issueID}, "updates": map[string]any{"status": "in_review", "description": "Batch updated description."},
+ })).Want(http.StatusOK)
+ _, kind, id := issueStatusAndAssignee(t, issueID)
+ if kind != "agent" || id != targetAgent || taskCountFor(t, issueID, targetAgent) != 1 || taskCountFor(t, issueID, sourceAgent) != 0 {
+ t.Fatalf("batch saved assignee = %s/%s; want target agent %s and one target-agent-only run", kind, id, targetAgent)
+ }
+}
+
+func TestDescriptionHandoffExplicitMemberOverride(t *testing.T) {
+ seedTestCatalog(t)
+ targetAgent := seededReadyAgentID(t)
+ projectID := deliveryProject(t, "Description explicit member project", targetAgent)
+ setColumnHandoff(t, projectID, "in_review", handToAgent(targetAgent, "Process the saved description.")).Want(http.StatusOK)
+ issueID := dbfx.Issue(t, "Explicit member assignment", testutil.Cols{"project_id": projectID, "status": "in_progress"})
+ updateIssueForTest(t, issueID, map[string]any{
+ "status": "in_review", "description": "Updated description for the assigned member.", "assignee_type": "member", "assignee_id": testUserID,
+ }).Want(http.StatusOK)
+ _, kind, id := issueStatusAndAssignee(t, issueID)
+ if kind != "member" || id != testUserID || taskCountFor(t, issueID, targetAgent) != 0 {
+ t.Fatalf("explicit member overridden: assignee=%s/%s", kind, id)
+ }
+}