Skip to content

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

Go

fix(cli): stop showing a next run for triggers that will not fire (#11632)

pseudoyu0d0d28e47a5e
diff --git a/server/cmd/multica/cmd_autopilot.go b/server/cmd/multica/cmd_autopilot.go
index 199277f29c..2c937d20d0 100644
--- a/server/cmd/multica/cmd_autopilot.go
+++ b/server/cmd/multica/cmd_autopilot.go
@@ -836,14 +836,24 @@ func runAutopilotTriggerList(cmd *cobra.Command, args []string) error {
return cli.PrintJSON(os.Stdout, map[string]any{"triggers": triggers, "total": len(triggers)})
}
+ // The scheduler only fires enabled triggers of an active autopilot; the
+ // others keep a stale next_run_at, so leave NEXT_RUN blank for them.
+ autopilot, _ := resp["autopilot"].(map[string]any)
+ autopilotActive := strVal(autopilot, "status") == "active"
+
fullID, _ := cmd.Flags().GetBool("full-id")
headers := []string{"ID", "KIND", "ENABLED", "SCHEDULE", "NEXT_RUN", "LABEL"}
rows := make([][]string, 0, len(triggers))
for _, t := range triggers {
enabled := "no"
- if b, ok := t["enabled"].(bool); ok && b {
+ triggerEnabled, _ := t["enabled"].(bool)
+ if triggerEnabled {
enabled = "yes"
}
+ nextRun := ""
+ if triggerEnabled && autopilotActive {
+ nextRun = strVal(t, "next_run_at")
+ }
schedule := strVal(t, "cron_expression")
if tz := strVal(t, "timezone"); schedule != "" && tz != "" {
schedule += " (" + tz + ")"
@@ -853,7 +863,7 @@ func runAutopilotTriggerList(cmd *cobra.Command, args []string) error {
strVal(t, "kind"),
enabled,
schedule,
- relativeTimestamp(strVal(t, "next_run_at")),
+ relativeTimestamp(nextRun),
strVal(t, "label"),
})
}
diff --git a/server/cmd/multica/cmd_autopilot_test.go b/server/cmd/multica/cmd_autopilot_test.go
index 6a851a8606..69522388a1 100644
--- a/server/cmd/multica/cmd_autopilot_test.go
+++ b/server/cmd/multica/cmd_autopilot_test.go
@@ -1158,6 +1158,63 @@ func TestRunAutopilotTriggerListSurfacesIDs(t *testing.T) {
}
}
+// The scheduler only fires enabled triggers of an active autopilot, so a
+// trigger that will not fire must not show a next run, matching the web UI.
+func TestRunAutopilotTriggerListHidesNextRunThatWillNotFire(t *testing.T) {
+ const autopilotID = "11111111-1111-1111-1111-111111111111"
+ nextRun := time.Now().Add(3*24*time.Hour + time.Hour).UTC().Format(time.RFC3339)
+
+ cases := []struct {
+ name string
+ autopilotStatus string
+ enabled bool
+ wantNextRun bool
+ }{
+ {"active autopilot, enabled trigger", "active", true, true},
+ {"paused autopilot", "paused", true, false},
+ {"archived autopilot", "archived", true, false},
+ {"disabled trigger", "active", false, false},
+ }
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.URL.Path != "/api/autopilots/"+autopilotID {
+ http.NotFound(w, r)
+ return
+ }
+ _ = json.NewEncoder(w).Encode(map[string]any{
+ "autopilot": map[string]any{"id": autopilotID, "status": tc.autopilotStatus},
+ "triggers": []map[string]any{
+ {
+ "id": "22222222-2222-2222-2222-222222222222",
+ "kind": "schedule",
+ "enabled": tc.enabled,
+ "cron_expression": "0 9 * * *",
+ "timezone": "UTC",
+ "next_run_at": nextRun,
+ },
+ },
+ })
+ }))
+ defer srv.Close()
+
+ t.Setenv("MULTICA_SERVER_URL", srv.URL)
+ t.Setenv("MULTICA_WORKSPACE_ID", "ws-1")
+ t.Setenv("MULTICA_TOKEN", "mat_test-token")
+
+ out, err := captureStdout(t, func() error {
+ return runAutopilotTriggerList(newAutopilotTriggerListTestCmd("table"), []string{autopilotID})
+ })
+ if err != nil {
+ t.Fatalf("runAutopilotTriggerList: %v", err)
+ }
+ if got := strings.Contains(out, "in 3d"); got != tc.wantNextRun {
+ t.Errorf("next run shown = %v, want %v:\n%s", got, tc.wantNextRun, out)
+ }
+ })
+ }
+}
+
// Webhook triggers carry a URL that grants the ability to fire the autopilot,
// so trigger-list must redact it the same way `get` does.
func TestRunAutopilotTriggerListRedactsWebhookCredentials(t *testing.T) {