Skip to content

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

Go

fix(autopilots): stop showing a next run for a paused autopilot (#11542)

pseudoyu23c8c6eece0d
diff --git a/packages/views/autopilots/components/autopilot-detail-page.tsx b/packages/views/autopilots/components/autopilot-detail-page.tsx
index 17eba07590..c18c6a1e3c 100644
--- a/packages/views/autopilots/components/autopilot-detail-page.tsx
+++ b/packages/views/autopilots/components/autopilot-detail-page.tsx
@@ -360,7 +360,17 @@ function SkippedRunsGroup({
);
}
-export function TriggerRow({ trigger, autopilotId, canWrite }: { trigger: AutopilotTrigger; autopilotId: string; canWrite: boolean }) {
+export function TriggerRow({
+ trigger,
+ autopilotId,
+ canWrite,
+ autopilotActive,
+}: {
+ trigger: AutopilotTrigger;
+ autopilotId: string;
+ canWrite: boolean;
+ autopilotActive: boolean;
+}) {
const { t, i18n } = useT("autopilots");
const describeSchedule = useDescribeSchedule();
const deleteTrigger = useDeleteAutopilotTrigger();
@@ -492,8 +502,10 @@ export function TriggerRow({ trigger, autopilotId, canWrite }: { trigger: Autopi
{/* A disabled trigger keeps the next_run_at it had — the dispatcher
filters on `enabled` instead of clearing it — so the row would
otherwise carry the Disabled badge and a promise to run at 09:00
- in the same breath. The badge is the true one. */}
- {trigger.next_run_at && trigger.enabled && (
+ in the same breath. The badge is the true one. Pausing the
+ autopilot keeps its triggers enabled, but the scheduler skips
+ them all, so a paused autopilot shows no next run either. */}
+ {trigger.next_run_at && trigger.enabled && autopilotActive && (
<span className="mr-1 hidden text-caption tabular-nums text-muted-foreground sm:inline">
{t(($) => $.trigger_row.next_label, {
date: formatInTimeZone(
@@ -1295,7 +1307,13 @@ export function AutopilotDetailPage({ autopilotId }: { autopilotId: string }) {
) : (
<ObjectSectionCard>
{triggers.map((trig) => (
- <TriggerRow key={trig.id} trigger={trig} autopilotId={autopilotId} canWrite={canWrite} />
+ <TriggerRow
+ key={trig.id}
+ trigger={trig}
+ autopilotId={autopilotId}
+ canWrite={canWrite}
+ autopilotActive={autopilot.status === "active"}
+ />
))}
</ObjectSectionCard>
)}
diff --git a/packages/views/autopilots/components/trigger-row.test.tsx b/packages/views/autopilots/components/trigger-row.test.tsx
index 597e1165b5..ff3153b0d7 100644
--- a/packages/views/autopilots/components/trigger-row.test.tsx
+++ b/packages/views/autopilots/components/trigger-row.test.tsx
@@ -70,11 +70,16 @@ function trigger(overrides: Partial<AutopilotTrigger> = {}): AutopilotTrigger {
};
}
-function renderRow(trig: AutopilotTrigger, canWrite = true) {
+function renderRow(trig: AutopilotTrigger, canWrite = true, autopilotActive = true) {
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
return renderWithI18n(
<QueryClientProvider client={qc}>
- <TriggerRow trigger={trig} autopilotId={AUTOPILOT_ID} canWrite={canWrite} />
+ <TriggerRow
+ trigger={trig}
+ autopilotId={AUTOPILOT_ID}
+ canWrite={canWrite}
+ autopilotActive={autopilotActive}
+ />
</QueryClientProvider>,
);
}
@@ -102,6 +107,14 @@ describe("TriggerRow", () => {
expect(screen.queryByText(/Next:/)).not.toBeInTheDocument();
});
+ it("stops promising a next run while the autopilot is paused", () => {
+ // Pausing the autopilot leaves its triggers enabled and their next_run_at
+ // in place, but the scheduler skips every trigger of a paused autopilot.
+ renderRow(trigger(), true, false);
+
+ expect(screen.queryByText(/Next:/)).not.toBeInTheDocument();
+ });
+
it("opens the editor on the schedule this row runs", async () => {
const user = userEvent.setup();
renderRow(trigger());
diff --git a/server/internal/handler/autopilot_list_test.go b/server/internal/handler/autopilot_list_test.go
index 7d1ec3c4f7..430eba3ea8 100644
--- a/server/internal/handler/autopilot_list_test.go
+++ b/server/internal/handler/autopilot_list_test.go
@@ -116,6 +116,50 @@ func TestListAutopilots_DerivedFields(t *testing.T) {
}
}
+// TestListAutopilots_PausedOmitsNextRun: the scheduler only fires schedule
+// triggers of an active autopilot, so a paused one must not list the next run
+// its enabled trigger still stores.
+func TestListAutopilots_PausedOmitsNextRun(t *testing.T) {
+ if testHandler == nil || testPool == nil {
+ t.Skip("database not available")
+ }
+ ctx := context.Background()
+
+ agentID := createHandlerTestAgent(t, "autopilot-list-paused-agent", []byte(`[]`))
+ paused := insertListTestAutopilot(t, agentID, "list-paused-next-run")
+ if _, err := testPool.Exec(ctx, `UPDATE autopilot SET status = 'paused' WHERE id = $1`, paused); err != nil {
+ t.Fatalf("pause autopilot fixture: %v", err)
+ }
+ if _, err := testPool.Exec(ctx, `
+ INSERT INTO autopilot_trigger (autopilot_id, kind, enabled, cron_expression, timezone, next_run_at)
+ VALUES ($1, 'schedule', true, '0 9 * * *', 'UTC', now() + interval '1 hour')
+ `, paused); err != nil {
+ t.Fatalf("insert trigger: %v", err)
+ }
+
+ w := httptest.NewRecorder()
+ testHandler.ListAutopilots(w, newRequest("GET", "/api/autopilots", nil))
+ if w.Code != 200 {
+ t.Fatalf("ListAutopilots: expected 200, got %d: %s", w.Code, w.Body.String())
+ }
+ var body struct {
+ Autopilots []map[string]any `json:"autopilots"`
+ }
+ if err := json.Unmarshal(w.Body.Bytes(), &body); err != nil {
+ t.Fatalf("failed to decode body: %v", err)
+ }
+ for _, row := range body.Autopilots {
+ if row["id"] != paused {
+ continue
+ }
+ if next, present := row["next_run_at"]; present {
+ t.Errorf("next_run_at: expected omitted for a paused autopilot, got %v", next)
+ }
+ return
+ }
+ t.Fatalf("paused autopilot %s missing from list", paused)
+}
+
func TestListAutopilots_DefaultExcludesArchived(t *testing.T) {
if testHandler == nil || testPool == nil {
t.Skip("database not available")
diff --git a/server/pkg/db/generated/autopilot.sql.go b/server/pkg/db/generated/autopilot.sql.go
index 1dd5022e5e..b1014eac6e 100644
--- a/server/pkg/db/generated/autopilot.sql.go
+++ b/server/pkg/db/generated/autopilot.sql.go
@@ -1577,6 +1577,7 @@ SELECT
SELECT min(t.next_run_at)
FROM autopilot_trigger t
WHERE t.autopilot_id = a.id AND t.enabled AND t.kind = 'schedule'
+ AND a.status = 'active'
)::timestamptz AS next_run_at,
COALESCE((
SELECT r.status
@@ -1613,6 +1614,8 @@ type ListAutopilotsRow struct {
// next run, last-run outcome) so the page never has to N+1 into the detail
// endpoint. trigger_kinds/next_run_at only consider ENABLED triggers — the
// columns answer "how does this fire today", not "what is configured".
+// next_run_at is also left NULL for an autopilot that is not active: the
+// scheduler skips every trigger of a paused one.
// last_run_status is COALESCEd to ” (never ran) because sqlc cannot infer
// nullability through a scalar subquery; the handler maps ” back to omitted.
func (q *Queries) ListAutopilots(ctx context.Context, arg ListAutopilotsParams) ([]ListAutopilotsRow, error) {
diff --git a/server/pkg/db/queries/autopilot.sql b/server/pkg/db/queries/autopilot.sql
index 968b00f4ff..b4f6f81ed8 100644
--- a/server/pkg/db/queries/autopilot.sql
+++ b/server/pkg/db/queries/autopilot.sql
@@ -7,6 +7,8 @@
-- next run, last-run outcome) so the page never has to N+1 into the detail
-- endpoint. trigger_kinds/next_run_at only consider ENABLED triggers — the
-- columns answer "how does this fire today", not "what is configured".
+-- next_run_at is also left NULL for an autopilot that is not active: the
+-- scheduler skips every trigger of a paused one.
-- last_run_status is COALESCEd to '' (never ran) because sqlc cannot infer
-- nullability through a scalar subquery; the handler maps '' back to omitted.
SELECT
@@ -20,6 +22,7 @@ SELECT
SELECT min(t.next_run_at)
FROM autopilot_trigger t
WHERE t.autopilot_id = a.id AND t.enabled AND t.kind = 'schedule'
+ AND a.status = 'active'
)::timestamptz AS next_run_at,
COALESCE((
SELECT r.status