E53A Fix trigger schedule updates causing immediate pipeline execution by Copilot · Pull Request #6001 · mage-ai/mage-ai · GitHub
[go: up one dir, main page]

Skip to content

Fix trigger schedule updates causing immediate pipeline execution#6001

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-trigger-schedule-execution
Draft

Fix trigger schedule updates causing immediate pipeline execution#6001
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-trigger-schedule-execution

Conversation

Copy link
Contributor
Copilot AI commented Jan 17, 2026

Description

When editing an existing active trigger's schedule (e.g., updating cron expression) and merging via Git-sync, the pipeline executes immediately despite create_initial_pipeline_run being disabled. This occurs because last_enabled_at is not tracked in triggers.yaml, causing the system to reset it to current time on load, which tricks the scheduler into treating it as newly enabled.

Root Cause: In PipelineSchedule.create_or_update_batch(), loading triggers from YAML with last_enabled_at=None always set it to current time, breaking the should_schedule() logic that prevents initial runs.

Fix: Preserve existing last_enabled_at from database when updating active triggers. Only set to current time for new triggers or INACTIVE→ACTIVE transitions.

# Before: Always reset timestamp for active triggers
if trigger_config.status == ACTIVE and trigger_config.last_enabled_at is None:
    last_enabled_at = datetime.now(tz=pytz.UTC)

# After: Preserve timestamp for existing active triggers
if trigger_config.status == ACTIVE and trigger_config.last_enabled_at is None:
    if existing_trigger and existing_trigger.status == ACTIVE:
        last_enabled_at = existing_trigger.last_enabled_at  # Preserve
    else:
        last_enabled_at = datetime.now(tz=pytz.UTC)  # New or reactivated

How Has This Been Tested?

  • Added test_create_or_update_batch_preserves_last_enabled_at_on_schedule_update - verifies schedule edits preserve last_enabled_at
  • Added test_create_or_update_batch_sets_last_enabled_at_on_status_change - verifies status changes still set timestamp correctly
  • All 20 existing PipelineScheduleTests pass without regression

Checklist

  • The PR is tagged with proper labels (bug, enhancement, feature, documentation)
  • I have performed a self-review of my own code
  • I have added unit tests that prove my fix is effective or that my feature works
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
Original prompt

This section details on the original issue you should resolve

<issue_title>[BUG] Editing an existing trigger’s schedule causes unexpected pipeline execution on merge with “initial pipeline run” disabled</issue_title>
<issue_description>### Mage version

0.9.77

Describe the bug

When modifying an existing trigger’s schedule (e.g., updating the cron expression) and committing that change through the normal Git-sync workflow, Mage is executing the associated pipeline immediately upon promotion to a higher environment. This occurs even when “Create initial pipeline run if start date is before current execution period” is explicitly disabled.

This appears to be unintended behavior, as the pipeline should not auto-run because the schedule changed when the safeguard option is off.

To reproduce

  1. Edit an existing trigger that is already stored in code (e.g., update its cron expression).
  2. Ensure “Create initial pipeline run if start date is before current execution period” is disabled.
  3. Commit and push the change to a feature branch.
  4. Merge the feature branch into develop.
  5. Promote the same change to test (or another higher environment).
  6. Observe that the pipeline executes immediately upon merge.

Expected behavior

Updating the trigger’s schedule should not cause the pipeline to execute immediately upon merge.

With “initial pipeline run” disabled, Mage should wait until the next natural occurrence of the new schedule before triggering any execution.

Screenshots

No response

Operating system

No response

Additional context

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…active triggers

Co-authored-by: wangxiaoyou1993 <80284865+wangxiaoyou1993@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix trigger schedule edit causing immediate pipeline execution Fix trigger schedule updates causing immediate pipeline execution Jan 17, 2026
Copilot AI requested a review from wangxiaoyou1993 January 17, 2026 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Editing an existing trigger’s schedule causes unexpected pipeline execution on merge with “initial pipeline run” disabled

2 participants

0