Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-7485: fix(issues): make the cancelled-work warning specific and match its own headline (#8540)
adai8c4f4328f6e3
diff --git a/server/internal/handler/issue_child_done.go b/server/internal/handler/issue_child_done.goindex 7a2a0c4923..e7345aa015 100644--- a/server/internal/handler/issue_child_done.go+++ b/server/internal/handler/issue_child_done.go@@ -341,7 +341,8 @@ func (h *Handler) postChildDoneComment(ctx context.Context, parent, completed dbvar content stringif staged {- stageCancelled := stageHasCancelled(children, closedStage, statuses.status)+ stageCancelledCount := countStageCancelled(children, closedStage, statuses.status)+ stageCancelled := stageCancelledCount > 0advanceHasCancelled := stageCancelledif batch {// A single batch can close several stages. Always preserve cancellation@@ -351,7 +352,7 @@ func (h *Handler) postChildDoneComment(ctx context.Context, parent, completed dbadvanceHasCancelled = stageCancelled || batchClosedScopeHasCancelled(children, batchCompleted, closedStage, statuses.status)}summary, nextStage := stageProgressSummary(children, closedStage, statuses.status)- advance := stageAdvanceInstruction(nextStage, parentID, advanceHasCancelled)+ advance := stageAdvanceInstruction(nextStage, parentID, stageCancelledCount, advanceHasCancelled)if !stageCancelled {// Keep the historical no-cancellation wording byte-identical for the// named stage. A lower stage cancelled in the same batch can still add@@ -640,13 +641,27 @@ func stageProgressSummary(children []db.Issue, closedStage int32, statusOf func(return strings.Join(parts, "; "), nextStage}-func stageHasCancelled(children []db.Issue, stage int32, statusOf func(db.Issue) string) bool {+// countStageCancelled counts the cancelled children of one stage. The advance+// instruction reports the number rather than the fact, because the agent it is+// written for has to decide whether the next stage can start without that work:+// "2 sub-issues cancelled" is checkable against the layout, "includes cancelled+// items" is not.+func countStageCancelled(children []db.Issue, stage int32, statusOf func(db.Issue) string) int {+ n := 0for _, child := range children {if child.Stage.Valid && child.Stage.Int32 == stage && statusOf(child) == "cancelled" {- return true+ n++}}- return false+ return n+}++// subIssueCount renders a sub-issue count with the right plural.+func subIssueCount(n int) string {+ if n == 1 {+ return "1 sub-issue"+ }+ return fmt.Sprintf("%d sub-issues", n)}// batchClosedScopeHasCancelled reports whether this batch newly cancelled work@@ -695,10 +710,16 @@ func anyCancelledChildren(children []db.Issue, statusOf func(db.Issue) string) b// asserted a finality the server cannot know and pushed leaders to wrap up// mid-workflow (MUL-4062 / #4927). The message now names both possibilities// and hands the create-next-vs-wrap-up decision back to the leader.-// - hasCancelled: one of the stages just closed contains cancelled work, so-// the instruction asks the assignee to confirm it is not a dependency-// before advancing. The server still does not decide that question itself.-func stageAdvanceInstruction(nextStage int32, parentID string, hasCancelled bool) string {+// - stageCancelled: how many sub-issues of the stage this comment names were+// cancelled. Non-zero also means the headline above calls the stage+// `closed` rather than complete, so the instruction says "Closing" to+// match rather than contradicting its own comment with "Completing".+// - scopeCancelled: whether anything the update closed was cancelled, which+// for a batch includes lower stages that carry no count of their own. It+// decides whether the warning renders at all; stageCancelled decides+// whether the warning can be specific. The server still does not decide+// the dependency question itself either way.+func stageAdvanceInstruction(nextStage int32, parentID string, stageCancelled int, scopeCancelled bool) string {var instruction stringif nextStage > 0 {instruction = fmt.Sprintf(@@ -706,12 +727,25 @@ func stageAdvanceInstruction(nextStage int32, parentID string, hasCancelled boolnextStage, parentID, nextStage,)} else {- instruction = fmt.Sprintf(" Completing this stage does not mean the whole issue is done. Decide whether the issue is actually complete — if so, synthesize the results and run `multica issue status %s in_review` to mark the parent ready for review — or whether the next stage still needs to be created, in which case create that stage and its sub-issues now.", parentID)+ verb := "Completing"+ if stageCancelled > 0 {+ verb = "Closing"+ }+ instruction = fmt.Sprintf(" %s this stage does not mean the whole issue is done. Decide whether the issue is actually complete — if so, synthesize the results and run `multica issue status %s in_review` to mark the parent ready for review — or whether the next stage still needs to be created, in which case create that stage and its sub-issues now.", verb, parentID)}- if !hasCancelled {+ if !scopeCancelled {return instruction}- return instruction + " The just-closed work includes cancelled items: confirm that the cancelled work is not a dependency of whatever comes next before advancing. If unsure, do not promote or create the next stage yet; post a comment to confirm first."+ // Only the named stage has a count attached to it. A batch that also closed+ // lower stages has no single stage to name, so it keeps the general warning+ // rather than reporting a number that would not match any one stage.+ if stageCancelled == 0 {+ return instruction + " The just-closed work includes cancelled items: confirm that the cancelled work is not a dependency of whatever comes next before advancing. If unsure, do not promote or create the next stage yet; post a comment to confirm first."+ }+ if nextStage > 0 {+ return instruction + fmt.Sprintf(" The stage that just closed has %s cancelled: confirm that the cancelled work is not something Stage %d depends on before advancing. If unsure, do not promote yet; post a comment to confirm first.", subIssueCount(stageCancelled), nextStage)+ }+ return instruction + fmt.Sprintf(" The stage that just closed has %s cancelled: confirm that the cancelled work is not a dependency of whatever comes next before advancing. If unsure, do not create the next stage yet; post a comment to confirm first.", subIssueCount(stageCancelled))}func unstagedCancellationInstruction() string {diff --git a/server/internal/handler/issue_child_done_batch_stage_test.go b/server/internal/handler/issue_child_done_batch_stage_test.goindex df42c4ddc4..080edd3d74 100644--- a/server/internal/handler/issue_child_done_batch_stage_test.go+++ b/server/internal/handler/issue_child_done_batch_stage_test.go@@ -254,7 +254,8 @@ func TestBatchChildDonePreservesRepresentativeAndParentOrder(t *testing.T) {if !strings.Contains(content, "Stage 7 of this issue is closed") ||!strings.Contains(content, "Stage 2: 0/1 done, 1 cancelled; Stage 7: 0/2 done, 2 cancelled; Stage 20: 0/1 done (next)") ||!strings.Contains(content, "Stage 20 is next") ||- !strings.Contains(content, "confirm that the cancelled work is not a dependency") {+ !strings.Contains(content, "has 2 sub-issues cancelled") ||+ !strings.Contains(content, "not something Stage 20 depends on") {t.Fatalf("inaccurate cancelled-stage summary: %s", content)}} else if !strings.Contains(content, "Stage 7 of this issue is complete") || !strings.Contains(content, "Stage 2: 1/1 done; Stage 7: 2/2 done; Stage 20: 0/1 done (next)") || !strings.Contains(content, "Stage 20 is next") {diff --git a/server/internal/handler/issue_child_done_cancelled_test.go b/server/internal/handler/issue_child_done_cancelled_test.goindex 5a089faac4..1d5e11ae24 100644--- a/server/internal/handler/issue_child_done_cancelled_test.go+++ b/server/internal/handler/issue_child_done_cancelled_test.go@@ -88,8 +88,11 @@ func TestBatchClosedScopeHasCancelled(t *testing.T) {})}+// A batch can close lower stages alongside the one the comment names. Those+// carry no count of their own, so the warning stays general rather than+// reporting a number that belongs to no single stage.func TestStageAdvanceInstructionWarnsOnCancelledWork(t *testing.T) {- got := stageAdvanceInstruction(3, "parent-id", true)+ got := stageAdvanceInstruction(3, "parent-id", 0, true)for _, want := range []string{"Stage 3 is next","confirm that the cancelled work is not a dependency",@@ -101,3 +104,55 @@ func TestStageAdvanceInstructionWarnsOnCancelledWork(t *testing.T) {}}}++// When the cancellations are in the stage this comment is about, the agent+// deciding whether to promote gets the two facts it can act on: how many+// sub-issues were cancelled, and which stage has to not depend on them.+func TestStageAdvanceInstructionNamesCountAndDependentStage(t *testing.T) {+ got := stageAdvanceInstruction(3, "parent-id", 2, true)+ for _, want := range []string{+ "Stage 3 is next",+ "has 2 sub-issues cancelled",+ "not something Stage 3 depends on",+ "post a comment to confirm first",+ } {+ if !strings.Contains(got, want) {+ t.Fatalf("instruction missing %q: %s", want, got)+ }+ }+ if strings.Contains(got, "includes cancelled items") {+ t.Fatalf("named stage must not fall back to the general warning: %s", got)+ }+}++func TestStageAdvanceInstructionSingularCancellation(t *testing.T) {+ got := stageAdvanceInstruction(3, "parent-id", 1, true)+ if !strings.Contains(got, "has 1 sub-issue cancelled") {+ t.Fatalf("want singular sub-issue, got %q", got)+ }+ if strings.Contains(got, "1 sub-issues") {+ t.Fatalf("plural leaked into the singular case: %s", got)+ }+}++// The headline above this instruction calls a stage with cancelled work+// `closed`, not complete. With no next stage the instruction opens the very+// next sentence, so it has to use the same word.+func TestStageAdvanceInstructionSaysClosingWhenStageWasCancelled(t *testing.T) {+ got := stageAdvanceInstruction(0, "parent-id", 2, true)+ if !strings.Contains(got, "Closing this stage does not mean") {+ t.Fatalf("want Closing to match the headline, got %q", got)+ }+ if strings.Contains(got, "Completing this stage") {+ t.Fatalf("stage closed with cancelled work must not read as completed: %s", got)+ }+}++// A lower stage cancelled by the same batch must not change the verb: the+// stage this comment names did complete.+func TestStageAdvanceInstructionKeepsCompletingForBatchScopeOnly(t *testing.T) {+ got := stageAdvanceInstruction(0, "parent-id", 0, true)+ if !strings.Contains(got, "Completing this stage does not mean") {+ t.Fatalf("named stage completed, want Completing, got %q", got)+ }+}diff --git a/server/internal/handler/issue_child_done_stage_test.go b/server/internal/handler/issue_child_done_stage_test.goindex 9126536005..3d9b7f43e3 100644--- a/server/internal/handler/issue_child_done_stage_test.go+++ b/server/internal/handler/issue_child_done_stage_test.go@@ -155,14 +155,14 @@ func TestStageAdvanceInstruction(t *testing.T) {const parentID = "parent-uuid"t.Run("a known next stage points the leader at it", func(t *testing.T) {- got := stageAdvanceInstruction(3, parentID, false)+ got := stageAdvanceInstruction(3, parentID, 0, false)if !strings.Contains(got, "Stage 3 is next") {t.Fatalf("expected next-stage instruction, got %q", got)}})t.Run("no created next stage does not assert finality", func(t *testing.T) {- got := stageAdvanceInstruction(0, parentID, false)+ got := stageAdvanceInstruction(0, parentID, 0, false)// Regression guard for MUL-4062: an intermediate stage in a lazily// created workflow also reaches nextStage==0, so the message must not// claim this was definitively the final stage.