Skip to content

Skip task setup for non-runnable Runs - #1536

Open
salasebas wants to merge 1 commit into
Shopify:mainfrom
salasebas:agent/skip-task-setup-for-non-runnable-runs
Open

Skip task setup for non-runnable Runs#1536
salasebas wants to merge 1 commit into
Shopify:mainfrom
salasebas:agent/skip-task-setup-for-non-runnable-runs

Conversation

@salasebas

Copy link
Copy Markdown
Contributor

A job can remain queued after its Run is cancelled. When eventually worked, it currently downloads CSV data, builds the collection, sets started_at, and runs after_start before stopping.

Claim the Run before task setup and abort when it is no longer runnable. Preserve pausing and cancelling transitions, and prevent the no-locking fallback from moving paused or completed Runs back to running.

Adds regression coverage for cancelled jobs, lifecycle callbacks, races, and both locking paths.

Tests: bundle exec rake test and bundle exec rubocop --no-parallel.

@salasebas
salasebas marked this pull request as ready for review August 15, 2026 23:05
with_stale_object_retry do
running! unless stopping?
reload_status if running?
running! if RUNNABLE_STATUSES.include?(status.to_sym)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
running! if RUNNABLE_STATUSES.include?(status.to_sym)
running! if runnable?

Let's define a predicate for this. It is easier to read.

@salasebas salasebas Aug 21, 2026

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.

Added Run#runnable?

def before_perform
@run = arguments.first
@run.running
abort_unless_run_is_running

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to call this multiple times? Perhaps we just need the second one.

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.

fixed

A job can remain queued after its Run is cancelled. When eventually
worked, it currently downloads CSV data, builds the collection, sets
started_at, and runs after_start before stopping.

Claim the Run before task setup and abort when it is no longer
runnable. Preserve pausing and cancelling transitions, and prevent
the no-locking fallback from moving paused or completed Runs back to
running.

Adds Run#runnable? and regression coverage for cancelled jobs,
lifecycle callbacks, races, and both locking paths.
@salasebas
salasebas force-pushed the agent/skip-task-setup-for-non-runnable-runs branch from a0904df to cdfe46e Compare August 25, 2026 16:26
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