Repository navigation
fix: retry failed jobs with solid queue's own transactional retry - #53
Merged
Merged
Conversation
vishaltps
approved these changes
Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Retrying a failed job could leave it with no execution at all: no ready, claimed, failed or scheduled execution, and no
finished_at. Solid Queue never runs it again. The dashboard lists it under the "Pending" status filter forever, and no Overview card counts it.FailedJobService#retry_jobreimplemented the retry by hand:ActiveRecord::Base.transactionopens a transaction on the app's primary database. When Solid Queue has its own database (config.solid_queue.connects_to, the Rails 8 default), that transaction doesn't cover the queue tables, so the two writes commit separately.How it happened
I found an orphaned job in a Rails 8 app (MySQL, separate queue database, solid_queue 1.7.0). Its development log shows the full sequence for one click on Retry:
ActiveJob::DeserializationError).Job#failed_withtries to create a new failed execution and hits the unique index onjob_id, because the old one still exists. It handles this case on purpose (rescue ActiveRecord::RecordNotUnique) by updating the existing failed execution with the new error.The job is left with no execution of any kind. Solid Queue handled its own race correctly; it just can't account for an outside tool deleting a row in the middle of it.
Fix
retry_jobnow calls Solid Queue's ownFailedExecution#retry, the same method Solid Queue and Mission Control use:That runs as one locked transaction on Solid Queue's own connection.
FailedExecution#retryexists and is transactional in every published solid_queue version I checked (0.1.1 through 1.7.2), so the gemspec'ssolid_queue >= 0.1.0stays valid.Side effects, all matching a retry done by Solid Queue itself:
retry_on ... attempts:starts over after a manual retry.limits_concurrencyis respected. The old code created a ready execution directly, skipping the concurrency check. Now a retried job whose slot is taken goes to blocked executions, so the service's success message changed from "Job moved to ready queue for retry" to "Job queued for retry".with_lockraiseRecordNotFound. That is now returned as{ success: false, message: 'Failed job not found' }instead of raising.retry_all) catches errors per job, the same wayDiscardReadyJobService#discard_manydoes. A lock timeout or deadlock on one job counts as failed and the rest are still retried, instead of stopping halfway with an error page.Tests
spec/services/solid_queue_monitor/failed_job_service_spec.rbcovers: a normal retry; delegation toFailedExecution#retry; a missing failed execution; one removed after it was loaded; a missing job; and bulk retry, including partial failure and a job whose retry raises.FailedExecution#retryinspec/support/solid_queue_stubs.rbnow behaves like the real one: onewith_locktransaction that creates the ready execution and deletes the failed one, raisingRecordNotFoundif the row is gone.bundle exec rspec: 384 examples, 0 failures.bundle exec rubocop: no offenses.Not in this PR
ActiveRecord::Base.transactionaround queue-database writes. I'd like to fix them in a follow-up PR. Discard needs a decision first: Solid Queue's ownFailedExecution#discarddeletes the job, while the monitor marks it finished (finished_at), and that also ignoresSolidQueue.preserve_finished_jobs = false. Which behavior would you prefer?if service.retry_job(id), and the service returns a Hash, which is always truthy. I have a separate small fix ready for that.