Skip to content

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

Go

fix(workflow): keep terminal issues at their current status (MUL-9746) (#11094)

Multica Eve0c40c971be76
diff --git a/server/internal/handler/issue_workflow.go b/server/internal/handler/issue_workflow.go
index a23421d444..3b519accee 100644
--- a/server/internal/handler/issue_workflow.go
+++ b/server/internal/handler/issue_workflow.go
@@ -1347,6 +1347,9 @@ func (h *Handler) PreviewIssueWorkflowBrief(w http.ResponseWriter, r *http.Reque
StatusName: func(key string) string {
return resolver.Name(ctx, h.Queries, key)
},
+ EffectiveStatus: func(key string) string {
+ return resolver.Effective(ctx, h.Queries, key)
+ },
HandlerName: func(s issueworkflow.Step) string {
switch s.Handler.Type {
case issueworkflow.HandlerAgent, issueworkflow.HandlerSquad, issueworkflow.HandlerMember:
diff --git a/server/internal/handler/issue_workflow_entry.go b/server/internal/handler/issue_workflow_entry.go
index 87c599e78a..4d40fe09f6 100644
--- a/server/internal/handler/issue_workflow_entry.go
+++ b/server/internal/handler/issue_workflow_entry.go
@@ -268,6 +268,9 @@ func (h *Handler) workflowBriefInput(ctx context.Context, issue db.Issue, def is
StatusName: func(key string) string {
return resolver.Name(ctx, h.Queries, key)
},
+ EffectiveStatus: func(key string) string {
+ return resolver.Effective(ctx, h.Queries, key)
+ },
HandlerName: func(step issueworkflow.Step) string {
if !step.HandsOff() {
return ""
diff --git a/server/internal/handler/issue_workflow_test.go b/server/internal/handler/issue_workflow_test.go
index 53f05e695b..6d0cb168ae 100644
--- a/server/internal/handler/issue_workflow_test.go
+++ b/server/internal/handler/issue_workflow_test.go
@@ -1034,6 +1034,49 @@ func TestClaimCarriesProjectWorkflow(t *testing.T) {
}
}
+func TestWorkflowBriefOmitsMovesAtCustomTerminalStatuses(t *testing.T) {
+ agentID := seededReadyAgentID(t)
+ for _, tc := range []struct{ key, category, instructions string }{
+ {"brief_verified", "done", "Record the release in the project notes."},
+ {"brief_wont_fix", "closed", ""},
+ } {
+ t.Run(tc.category, func(t *testing.T) {
+ status := createTestCustomStatus(t, tc.key, tc.category)
+ workflow := createTestWorkflow(t, "Terminal status "+workflowTestSuffix(), status.Key)
+ draft := map[string]any{}
+ if tc.instructions != "" {
+ draft = handToAgent(agentID, tc.instructions)
+ setWorkflowHandoff(t, workflow.ID, status.Key, draft).Want(http.StatusOK)
+ }
+ draft["status_key"] = status.Key
+ projectID := createWorkflowTestProject(t, "Custom terminal status project")
+ setProjectWorkflow(t, projectID, map[string]any{"workflow_id": workflow.ID}).Want(http.StatusOK)
+ issueID := dbfx.Issue(t, "At a custom terminal status", testutil.Cols{
+ "project_id": projectID, "status": status.Key, "assignee_type": "agent", "assignee_id": agentID,
+ })
+ checkBrief := func(source, brief string) {
+ _, column, _ := strings.Cut(brief, "\n- `"+status.Key+"`")
+ column, _, _ = strings.Cut(column, "\n")
+ if !strings.HasSuffix(column, " ← current") ||
+ strings.Contains(brief, "Your moves:") || strings.Contains(brief, "multica issue status") {
+ t.Errorf("%s brief should show %q as current without offering moves:\n%s", source, status.Key, brief)
+ }
+ if tc.instructions != "" && !strings.Contains(brief, tc.instructions) {
+ t.Errorf("%s brief dropped the configured instructions:\n%s", source, brief)
+ }
+ }
+ checkBrief("claim", claimBriefForTest(t, issueID, db.AgentTaskQueue{AgentID: parseUUID(agentID)}))
+
+ var preview struct {
+ Brief string `json:"brief"`
+ }
+ req := withURLParam(workflowRequest("POST", "/api/issue-workflows/"+workflow.ID+"/brief", draft), "id", workflow.ID)
+ testutil.Call(t, testHandler.PreviewIssueWorkflowBrief, req).Want(http.StatusOK).JSON(&preview)
+ checkBrief("preview", preview.Brief)
+ })
+ }
+}
+
func TestClaimExplainsMovedWorkflowStep(t *testing.T) {
seedTestCatalog(t)
agentID := seededReadyAgentID(t)
diff --git a/server/internal/issueworkflow/issueworkflow.go b/server/internal/issueworkflow/issueworkflow.go
index f5c1a9b014..68bc759952 100644
--- a/server/internal/issueworkflow/issueworkflow.go
+++ b/server/internal/issueworkflow/issueworkflow.go
@@ -727,6 +727,9 @@ type BriefInput struct {
MovedBy string
// StatusName resolves a catalog key to its display name.
StatusName func(key string) string
+ // EffectiveStatus resolves a catalog key to its canonical behavior. With
+ // no resolver, the key itself determines the behavior.
+ EffectiveStatus func(key string) string
// HandlerName describes who a step hands off to, e.g. "Sentinel" or
// "Lin (project lead)". Empty means the step does not hand off.
HandlerName func(step Step) string
@@ -762,6 +765,14 @@ type BriefInput struct {
func Brief(in BriefInput) string {
step, _ := in.Workflow.Step(in.StatusKey)
stepMoved := in.BoundStep != "" && in.BoundStep != in.StatusKey
+ effectiveStatus := in.StatusKey
+ if in.EffectiveStatus != nil {
+ effectiveStatus = in.EffectiveStatus(in.StatusKey)
+ }
+ terminal := effectiveStatus == issuestatus.Done || effectiveStatus == issuestatus.Cancelled
+ // Nothing on the board follows a terminal status, so its only moves are
+ // the ones its author configured (MUL-9746).
+ terminalMoves := terminal && (step.NextStatusKey != "" || step.BackStatusKey != "")
name := func(key string) string {
if in.StatusName == nil {
return key
@@ -792,7 +803,7 @@ func Brief(in BriefInput) string {
// An older daemon still states the built-in rules itself, so its brief
// keeps the per-step wording rather than add a second in_progress rule.
var span handlerlessSpan
- if !stepMoved && !in.Observer && !in.LegacyRuntimeRules {
+ if !stepMoved && !in.Observer && !in.LegacyRuntimeRules && !terminal {
span = in.Workflow.handlerlessSpan(in.StatusKey)
}
if in.LegacyRuntimeRules && !stepMoved {
@@ -828,7 +839,12 @@ func Brief(in BriefInput) string {
b.WriteString("to finish.\n")
}
} else {
- fmt.Fprintf(&b, "You are handling the %q step of %s.\n", name(in.StatusKey), in.IssueIdentifier)
+ if terminal && !terminalMoves {
+ fmt.Fprintf(&b, "%s has reached the terminal status %s. Leave the issue at this status unless a member explicitly asks you to reopen it.\n",
+ in.IssueIdentifier, statusLabel(name(in.StatusKey), in.StatusKey))
+ } else {
+ fmt.Fprintf(&b, "You are handling the %q step of %s.\n", name(in.StatusKey), in.IssueIdentifier)
+ }
if instructions := briefText(step.Instructions); instructions != "" {
b.WriteString("\nStep instructions:\n")
for _, line := range strings.Split(instructions, "\n") {
@@ -862,6 +878,9 @@ func Brief(in BriefInput) string {
b.WriteString("\nMoving the issue into a step that hands off reassigns it to that step's handler and starts their run.\n")
return b.String()
}
+ if terminal && !terminalMoves {
+ return b.String()
+ }
b.WriteString("\nYour moves:\n")
switch {
case span.ok:
@@ -874,7 +893,11 @@ func Brief(in BriefInput) string {
fmt.Fprintf(&b, "Step done → leave the issue at `%s`; `done` is set by a human\n", in.StatusKey)
}
default:
- if next := in.Workflow.NextStatus(in.StatusKey); next != "" {
+ next := step.NextStatusKey
+ if !terminal {
+ next = in.Workflow.NextStatus(in.StatusKey)
+ }
+ if next != "" {
fmt.Fprintf(&b, "Step done → multica issue status %s %s%s\n", in.IssueIdentifier, next, handsOffTo(next))
}
}
@@ -882,7 +905,7 @@ func Brief(in BriefInput) string {
fmt.Fprintf(&b, "Needs changes → multica issue status %s %s%s\n", in.IssueIdentifier, step.BackStatusKey, handsOffTo(step.BackStatusKey))
}
switch {
- case in.Workflow.Has(issuestatus.Blocked):
+ case in.Workflow.Has(issuestatus.Blocked) && !terminal:
fmt.Fprintf(&b, "Can't proceed → multica issue status %s blocked, then comment why\n", in.IssueIdentifier)
case step.BackStatusKey != "":
b.WriteString("Can't proceed → comment why, then run Needs changes\n")
diff --git a/server/internal/issueworkflow/issueworkflow_test.go b/server/internal/issueworkflow/issueworkflow_test.go
index 3013ac1968..2d20e27257 100644
--- a/server/internal/issueworkflow/issueworkflow_test.go
+++ b/server/internal/issueworkflow/issueworkflow_test.go
@@ -292,6 +292,88 @@ func TestBriefNamesStepCommandsAndHandlers(t *testing.T) {
}
}
+func TestBriefOmitsMovesAtTerminalStatuses(t *testing.T) {
+ for _, status := range []string{"done", "cancelled"} {
+ for _, legacy := range []bool{false, true} {
+ t.Run(fmt.Sprintf("%s/legacy=%v", status, legacy), func(t *testing.T) {
+ brief := Brief(BriefInput{
+ Workflow: blockedOnlyDefault(),
+ StatusKey: status,
+ IssueIdentifier: "MUL-7",
+ LegacyRuntimeRules: legacy,
+ })
+ for _, unwanted := range []string{"Your moves:", "multica issue status", "Before your run ends, either run one of them"} {
+ if strings.Contains(brief, unwanted) {
+ t.Fatalf("terminal brief carries %q:\n%s", unwanted, brief)
+ }
+ }
+ for _, want := range []string{
+ "- `" + status + "` ← current",
+ "Leave the issue at this status unless a member explicitly asks you to reopen it.",
+ } {
+ if !strings.Contains(brief, want) {
+ t.Errorf("terminal brief is missing %q:\n%s", want, brief)
+ }
+ }
+ })
+ }
+ }
+}
+
+func TestBriefKeepsConfiguredMovesAtCustomTerminalStatus(t *testing.T) {
+ verifying := func(next, back string) Definition {
+ def := Definition{Name: "Release", Steps: stepsFor(ArrangeKeys([]string{"in_progress", "verifying", "blocked"}))}
+ return withHandoffs(def, []Step{{
+ StatusKey: "verifying", Handler: Handler{Type: HandlerAgent, ID: testAgentID},
+ Instructions: "Check the deploy.", NextStatusKey: next, BackStatusKey: back,
+ }})
+ }
+ for _, tc := range []struct {
+ name, next, back string
+ want, unwanted []string
+ }{
+ {
+ name: "next and back", next: "done", back: "in_progress",
+ want: []string{
+ "Step done → multica issue status DEP-42 done\n",
+ "Needs changes → multica issue status DEP-42 in_progress\n",
+ "Can't proceed → comment why, then run Needs changes\n",
+ },
+ },
+ {
+ // Without a configured Next, the status after verifying on the
+ // board (done) is not offered.
+ name: "back only", back: "in_progress",
+ want: []string{"Needs changes → multica issue status DEP-42 in_progress\n"},
+ unwanted: []string{"Step done"},
+ },
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ brief := Brief(BriefInput{
+ Workflow: verifying(tc.next, tc.back),
+ StatusKey: "verifying",
+ IssueIdentifier: "DEP-42",
+ EffectiveStatus: func(key string) string {
+ if key == "verifying" {
+ return "done"
+ }
+ return key
+ },
+ })
+ for _, want := range append([]string{`You are handling the "verifying" step of DEP-42.`, "> Check the deploy.\n"}, tc.want...) {
+ if !strings.Contains(brief, want) {
+ t.Errorf("brief is missing %q:\n%s", want, brief)
+ }
+ }
+ for _, unwanted := range append([]string{"blocked, then comment why", "has reached the terminal status"}, tc.unwanted...) {
+ if strings.Contains(brief, unwanted) {
+ t.Errorf("brief carries %q:\n%s", unwanted, brief)
+ }
+ }
+ })
+ }
+}
+
func TestBriefForMovedStep(t *testing.T) {
for _, current := range []string{"implement", "todo"} {
for _, observer := range []bool{false, true} {