From bc410a62bdd1e08e4d21f886fd36f0a28bc2ad5b Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Mon, 30 Nov 2026 21:11:31 +0100 Subject: [PATCH] fix: show a next run moved by an automation's code on its page and in the Calendar (#35388) When an automation's code moved its next run, the run happened at the new time, but the automation page kept showing the regular scheduled time and the Calendar did not list the moved run. Both now show the next run as it will really happen, including for automations that only run manually, and the Calendar leaves out the scheduled times the moved run replaces. Once the moved run is done, both go back to the regular schedule. Fixes #35377 --- backend/open_webui/routers/calendar.py | 59 +++++++++++-------- .../automations/AutomationEditor.svelte | 11 ++-- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/backend/open_webui/routers/calendar.py b/backend/open_webui/routers/calendar.py index 944a588daa..056e366aa2 100644 --- a/backend/open_webui/routers/calendar.py +++ b/backend/open_webui/routers/calendar.py @@ -210,7 +210,31 @@ async def get_events( # Future runs: expand RRULEs for active automations only active_automations = await Automations.get_active_by_user(user.id) + now_ns = int(time.time_ns()) for auto in active_automations: + next_run_at = auto.next_run_at + action = auto.data['action'] + next_run_event = { + 'id': f'auto_{auto.id}_next', + 'calendar_id': SCHEDULED_TASKS_CALENDAR_ID, + 'user_id': user.id, + 'title': auto.name, + 'description': action.get('prompt') or action.get('code') or '', + 'start_at': next_run_at, + 'end_at': None, + 'all_day': False, + 'rrule': None, + 'color': None, + 'location': None, + 'data': None, + 'meta': {'automation_id': auto.id}, + 'is_cancelled': False, + 'attendees': [], + 'created_at': auto.created_at, + 'updated_at': auto.updated_at, + 'user': None, + } + scheduled_starts = set() schedules = [t['rrule'] for t in auto.data['triggers'] if t['type'] == 'schedule'] for i, rrule_str in enumerate(schedules): start_at = await next_run_ns(rrule_str, tz=user.timezone) or 0 @@ -222,36 +246,25 @@ async def get_events( except ValueError: pass - action = auto.data['action'] - virtual = { - 'id': f'auto_{auto.id}_{i}', - 'calendar_id': SCHEDULED_TASKS_CALENDAR_ID, - 'user_id': user.id, - 'title': auto.name, - 'description': action.get('prompt') or action.get('code') or '', - 'start_at': start_at, - 'end_at': None, - 'all_day': False, - 'rrule': rrule_str, - 'color': None, - 'location': None, - 'data': None, - 'meta': {'automation_id': auto.id}, - 'is_cancelled': False, - 'attendees': [], - 'created_at': auto.created_at, - 'updated_at': auto.updated_at, - 'user': None, - } + virtual = {**next_run_event, 'id': f'auto_{auto.id}_{i}', 'start_at': start_at, 'rrule': rrule_str} # Only expand into the future — past runs are handled below - now_ns = int(time.time_ns()) rrule_start = max(start_ns, now_ns) instances = await evaluate_recurrence( expand_recurring_event, virtual, rrule_start, end_ns, user.timezone ) for inst in instances: - expanded.append(CalendarEventUserResponse(**inst)) + # A next run moved by code replaces the scheduled times before it + if inst['start_at'] >= (next_run_at or 0): + scheduled_starts.add(inst['start_at']) + expanded.append(CalendarEventUserResponse(**inst)) + + if ( + next_run_at + and max(start_ns, now_ns) <= next_run_at < end_ns + and next_run_at not in scheduled_starts + ): + expanded.append(CalendarEventUserResponse(**next_run_event)) # Past runs: single range query joined with automation runs_with_auto = await AutomationRuns.get_runs_by_user_range(user.id, start_ns, end_ns) diff --git a/src/lib/components/automations/AutomationEditor.svelte b/src/lib/components/automations/AutomationEditor.svelte index 88158198c4..1722c3d180 100644 --- a/src/lib/components/automations/AutomationEditor.svelte +++ b/src/lib/components/automations/AutomationEditor.svelte @@ -1040,7 +1040,7 @@ - {#if action_type === 'code' || automation.data.triggers.some((trigger) => trigger.type === 'schedule') || automation.last_run_at} + {#if action_type === 'code' || automation.next_run_at || automation.data.triggers.some((trigger) => trigger.type === 'schedule') || automation.last_run_at}