Synthetic Industry

Troubleshooting guide · updated 2026-10-10

Laravel job cannot find a record just created: check dispatch versus database commit

Diagnose a worker racing an open transaction and distinguish commit-aware dispatch from guaranteed delivery after a commit.

Look for a timing race

A feature owner reports an intermittent record-not-found error in a worker immediately after a form creates the record. Trace when the transaction starts, the job dispatches, the transaction commits and the worker queries the record. A successful synchronous test can hide the race because it does not reproduce an independent worker. Check the database and queue connection involved without logging private payloads.

  • Distinguish a transaction race from the worker using the wrong database or identifier.
  • Use synthetic records and a separately running worker on an authorised test copy.

Choose the intended commit boundary

In Laravel 12.x, after_commit on a queue connection defers dispatch until open parent transactions commit. afterCommit can request this for an individual job; beforeCommit can deliberately override the connection policy. Review the whole dispatch path, including listeners and notifications, before changing a global setting. If the transaction rolls back because of an exception, deferred jobs from that transaction are discarded.

  • Test an outer transaction as well as any nested transaction used by the feature.
  • Do not replace the race with an arbitrary sleep in the worker.

A later dispatch can still fail

Waiting for commit addresses when the worker can read the record. It does not itself establish that the database commit and a separate queue service form one atomic transaction. Specify how an enqueue failure after commit is surfaced and recovered, and how retries avoid duplicate business effects. Those are application reliability requirements, not a documented guarantee of afterCommit.

  • Keep a committed record with an unresolved dispatch visibly distinguishable from completed processing.
  • Do not report success to the owner solely because the database write succeeded.

Acceptance covers commit, rollback and dispatch failure

Require a committed synthetic record to be processed, a rolled-back record not to produce the deferred effect, and an agreed visible recovery path when dispatch fails. Preserve the original failing case as a regression test. This is one feature's transaction boundary, not a whole-app queue audit. Send version and redacted timing symptoms initially; private access, acceptance details and price are agreed before work.

Sources and limits

  • Laravel 12.x: jobs and database transactions Checked 2026-10-10.
    • A dispatched job can run before its parent database transaction commits.
    • after_commit waits for open parent transactions; jobs dispatched within a transaction rolled back because of an exception are discarded.
    • afterCommit permits per-job deferred dispatch; beforeCommit can override a connection's after_commit policy.