Skip to content

Started canceling runs when automation becomes inactive#27623

Merged
troyciesco merged 1 commit into
mainfrom
evanhahn-ny-1261-bail-out-of-automation-run-if-automation-becomes-inactive
Apr 29, 2026
Merged

Started canceling runs when automation becomes inactive#27623
troyciesco merged 1 commit into
mainfrom
evanhahn-ny-1261-bail-out-of-automation-run-if-automation-becomes-inactive

Conversation

@EvanHahn
Copy link
Copy Markdown
Contributor

@EvanHahn EvanHahn commented Apr 29, 2026

closes https://linear.app/ghost/issue/NY-1261

This was built by Kimi K2.6 with the following prompt:

@ghost/core/core/server/services/welcome-email-automations/poll.js runs pending automation runs. This is good! But it has a missing feature: if the welcome email automation is inactive (see welcome_email_automations's status column), we still run the automation. Let's implement this behavior!

Using red/green TDD (edit poll.test.js, probably), make it so that we cancel an automation run if the automation is disabled. This will also mean adding a new exit_reason to the welcome_email_automation_runs table (see @ghost/core/core/server/data/schema/schema.js), and a new type for the exitReason argument of markExited in poll.js.

(There's a chance this feature already exists, in which case this request is a no-op. But I'm pretty sure we need to implement it.)

I made a few small tweaks and put it up for review.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 10f6ce52-15b2-4b40-87d9-f04e25859b61

📥 Commits

Reviewing files that changed from the base of the PR and between 4a656a9 and 5575d37.

📒 Files selected for processing (3)
  • ghost/core/core/server/data/schema/schema.js
  • ghost/core/core/server/services/welcome-email-automations/poll.js
  • ghost/core/test/integration/services/welcome-email-automations/poll.test.js
🚧 Files skipped from review as they are similar to previous changes (3)
  • ghost/core/core/server/data/schema/schema.js
  • ghost/core/core/server/services/welcome-email-automations/poll.js
  • ghost/core/test/integration/services/welcome-email-automations/poll.test.js

Walkthrough

The change adds an automation disabled value to the welcome_email_automation_runs.exit_reason validation enum. The poller now selects each run's parent automation status and, if the automation is not active, stops processing the run and updates it with exit_reason = 'automation disabled' (clearing pending email and readiness/step timestamps and resetting attempts). An integration test verifies the inactive-automation path (no emails sent, no tracked recipients created, run updated, no further polling scheduled).

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: implementing logic to cancel automation runs when the parent automation becomes inactive.
Description check ✅ Passed The description is directly related to the changeset, explaining the feature implementation, referencing the Linear issue, and noting that the work was AI-assisted with minor tweaks.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch evanhahn-ny-1261-bail-out-of-automation-run-if-automation-becomes-inactive

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 6/8 reviews remaining, refill in 10 minutes and 52 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the migration [pull request] Includes migration for review label Apr 29, 2026
@github-actions

This comment was marked as outdated.

@EvanHahn EvanHahn removed the migration [pull request] Includes migration for review label Apr 29, 2026
closes https://linear.app/ghost/issue/NY-1261

This was built by Kimi K2.6 with the following prompt:

> @ghost/core/core/server/services/welcome-email-automations/poll.js runs pending automation runs. This is good! But it has a missing feature: if the welcome email automation is inactive (see `welcome_email_automations`'s `status` column), we still run the automation. Let's implement this behavior!
>
> Using red/green TDD (edit `poll.test.js`, probably), make it so that we cancel an automation run if the automation is disabled. This will also mean adding a new `exit_reason` to the `welcome_email_automation_runs` table (see @ghost/core/core/server/data/schema/schema.js), and a new type for the `exitReason` argument of `markExited` in poll.js.
>
> (There's a chance this feature already exists, in which case this request is a no-op. But I'm pretty sure we need to implement it.)

I made a few small tweaks and put it up for review.
@EvanHahn EvanHahn force-pushed the evanhahn-ny-1261-bail-out-of-automation-run-if-automation-becomes-inactive branch from 4a656a9 to 5575d37 Compare April 29, 2026 16:17
coderabbitai[bot]

This comment was marked as resolved.

step_started_at: {type: 'dateTime', nullable: true},
step_attempts: {type: 'integer', unsigned: true, nullable: false, defaultTo: 0},
exit_reason: {type: 'string', maxlength: 50, nullable: true, validations: {isIn: [['email send failed', 'member unsubscribed', 'member changed status', 'finished']]}},
exit_reason: {type: 'string', maxlength: 50, nullable: true, validations: {isIn: [['email send failed', 'member unsubscribed', 'member changed status', 'finished', 'automation disabled']]}},
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These validations don't get encoded into the schema, so we don't need to do a migration here.

@EvanHahn EvanHahn requested a review from troyciesco April 29, 2026 16:43
@troyciesco troyciesco merged commit fc5b9a8 into main Apr 29, 2026
43 checks passed
@troyciesco troyciesco deleted the evanhahn-ny-1261-bail-out-of-automation-run-if-automation-becomes-inactive branch April 29, 2026 18:34
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.

2 participants