A failure queue: what an operator needs before retrying

Retain the reason for stopping, bound a new epoch, and return only the repaired task to work. An example with a MySQL/InnoDB journal and a safe export.

An operator opens the track for one repaired task; the other remains behind the barrier.
An operator opens the track for one repaired task; the other remains behind the barrier.

A task has failed again. The queue has already spent its automatic attempts, the operator can see a retry button, and the cause seems clear: someone corrected one field in the input. What remains is deciding exactly what to return to work. One task? Every record with the same error code? The same intent with revised data, or an entirely new operation?

A failure queue becomes useful when it retains enough information for that decision. The word “failed” offers little help on its own. We need the spent budget, the reason for stopping, the input and handler revisions, and the boundary of any possible side effect. Otherwise, retrying can easily become a way to hide an error without removing its cause.

The independent example runs in one Symfony Demo: two synthetic tasks, a MySQL 8.4/InnoDB journal accessed through native PDO, and a registered command. Tables use foreign keys and CHECK constraints; textual identities use VARCHAR with utf8mb4_0900_bin, while long text uses LONGTEXT. This is a persisted teaching model without a broker, Messenger worker, or external handler action. Connecting to MySQL is not a call to an external business service.

An attempt starts before the handler works

First, define the unit of the budget. In this example, an attempt is a persisted handler start, not a terminal message, an exception, or a new delivery. Before invoking the code, a short transaction increments the counter, appends an immutable start row, and moves the task from pending to running. The runner calls the handler only after the commit.

The first epoch permits three starts in total. That does not mean “the first attempt plus three retries.” If the handler reports another transient failure after the third start, the task moves to closed. A fourth runner invocation is no longer allowed to start work. The counter shown to the operator and the number of journal rows must explain the same number.

The process can stop between the commit and the handler invocation. The start has then been spent even though useful work may never have begun. Returning that task to the queue without investigation would erase this uncertainty. The example allows a stopped invocation to be moved to reconciliation_required; it never refunds the attempt automatically. This is the conservative cost of accounting that does not depend on whether a worker managed to print a message.

One error does not imply one response

The cause must be classified before deciding to retry. The example handler returns a local result or raises one of the controlled failure types. The runner persists only an allowed code. Exception text does not become part of the operator export.

Situation Code Next state
Temporary unavailability with budget remaining transient_unavailable pending
The same failure on the final permitted attempt transient_unavailable closed
Input unsuitable for processing invalid_input Immediately closed
Unexpected or unknown outcome outcome_unknown reconciliation_required

A permanent failure here means that automatically repeating the same input is inappropriate. It does not prohibit correcting the input and separately considering another run. An unknown outcome, however, cannot be reduced to a transient failure: an external service might already have performed the action. A new delivery key does not prove the previous effect is absent.

The prepared example handler performs no external actions. An unexpected exception still stops automation so that the policy does not encourage treating every failure as safe to retry. Integration with a real service requires its own source of reconciliation evidence. This example has no button that turns an unknown outcome into “definitely not performed.”

The journal must survive another run

Each start records the task identity, stable operation identity, correlation ID, epoch, attempt number, and input and handler revisions. Its outcome is appended as a separate immutable record. This makes a start without an outcome visible and avoids rewriting the past when another epoch begins.

The delivery identity changes on every start. The operation identity stays the same: we are repairing the processing of the same synthetic card. If the operator actually intends to create a different card, that is another intent requiring separate admission. The redrive algorithm itself cannot determine this business distinction from a note.

In the lab, MySQL triggers support journal immutability by rejecting ordinary UPDATE and DELETE statements against history rows with SIGNAL SQLSTATE '45000'. The error propagates to the caller, and the code that opened the transaction owns its rollback. This usefully checks writing discipline, but it does not protect against an administrator who can change the database schema. Likewise, the symbolic revision handler-v1 explains the scenario without proving which production artifact was deployed. A working process needs a verifiable association between the revision and the executable code.

One selected record receives a new epoch

The initial scenario contains selected and neighbor. Both tasks deliberately remain broken and should close after three starts. The operator then corrects only the input of selected, assigns a new revision, and adds a private note about the verified repair. The selection contains an exact ID and the expected previous epoch number.

One transaction checks redrive eligibility, appends the decision record, and opens the second epoch. Its new budget is two starts. The current epoch counter begins at zero, but previous starts and outcomes remain. neighbor stays closed; a similar error code is not permission to retry it alongside its neighbor.

Each task permits only one manual redrive. The upper bound for this teaching lifecycle is therefore five starts: three initial and two additional. If the repair does not help, the second epoch closes as well. Another operator invocation cannot create a third epoch or replenish the budget. A different policy is possible, but it must explicitly state who grants fresh permission to work and on what grounds.

The decision record and the state change must share a commit in an InnoDB transaction. Otherwise, permission may exist without history, or history may describe permission that never took effect. Short transactions use row locks; lock-wait and deadlock errors are not hidden. The InnoDB documentation explains error handling; the code rolls back its own transaction on failure. This commit joins database changes, not the database and a remote service in one transaction.

What an operator reads before deciding

A useful failure record answers several concrete questions. Which logical operation stopped? How many starts were spent in each epoch? Which safe reason code was retained? Which input and handler took part? What exactly was repaired? Do we know that retrying will not duplicate an external action already accepted?

Server health cannot substitute for those answers. Sufficient memory, available disk space, or a process restart does not make invalid input valid or cancel spent attempts. An operator must distinguish restoring the environment from authorizing a particular operation to continue.

A repair note supports the decision, but it is not evidence of the repair by itself. A synthetic operator supplies it in the teaching scenario. Verifying that operator’s real identity, authority, and external evidence is outside the example. A revision change is also only a necessary condition: a new number without a repair does not guarantee a different outcome. That is precisely why the second epoch retains its own small limit.

A failure export should not spread the payload

To test privacy, the synthetic payload and note contain a recognizable secret canary. The controlled exception message can contain it too. The export uses an explicit field allowlist: it excludes the payload, free-text note, decision actor, and raw exception. A test must establish both the canary’s presence in private data and its absence from the exported result; checking only an empty string would prove nothing.

OWASP’s logging guidance explains why tokens, passwords, and other sensitive values should not be copied into logs. In this mechanism, allowed identifiers must also be synthetic and safe to display. A restricted alphabet removes control characters, but cannot recognize that somebody has written a secret using ordinary letters. An allowlist works alongside a data contract; it does not replace that contract.

How this relates to Messenger

Symfony Messenger provides a retry strategy, a failure transport, and commands for inspecting and retrying failed messages. Messages can be selected by ID. Those facilities do not automatically define business rules: whether retrying is allowed after an unknown effect, what note is required, how often a budget may be renewed, or which history must be retained.

Before integration, ordinary bounded retries must also be distinguished from exceptions that force retrying: the corresponding Messenger behavior can bypass the usual max_retries. The exact contract must be checked against the component version. “Three starts” in this example belongs to its own journal, rather than silently borrowing the value of a Messenger setting.

The teaching runner is invoked sequentially and does not wait between attempts. Backoff, jitter, competing workers, and lease transfer are not modeled here. If a transport is added, one owner of the budget must first be identified; another automatic retry must not silently multiply handler invocations.

Reproducing it in one application

The classes, command, tests, and separate services resource remain in the existing Symfony 8.1 application; the effective PHP minimum is 8.4.1. Running the example requires MySQL 8.4 and PDO_MYSQL with native prepared statements. The lab uses the shared App\Infrastructure\MysqlLab helper for a disposable schema: a separate migrator explicitly creates tables and triggers before business transactions, while the runtime connection has DML privileges only, without CREATE, ALTER, or DROP. DDL can cause an implicit commit, so this is neither an atomic schema upgrade nor an automatic data copy from the old SQLite store. From the application root, run the tests through the guarded MySQL fixture:

bash fixtures/mysql_labs/run.sh php vendor/bin/phpunit tests/PoisonRedrive

The scenario’s expected result is 7 starts, 7 outcomes, 1 redrive, and 1 local effect, CARD:CEDAR. selected is completed in epoch 2 with one spent attempt; neighbor is closed in epoch 1 with three attempts. Persisted state is checked with direct SQL through a separate native PDO connection sharing the MySQL schema, rather than only through objects from the current run. The canary must be present in the private payload and repair note but absent from safe export and stdout. Private database contents are not part of the safe export.

The store and command checks cover unsuccessful repair, the second budget, rollback, repeated operator calls, unknown-state refusal, and preservation of the neighbor row and previous starts/outcomes history after the selected task’s redrive. Test schema setup uses the helper and migrator; runtime operations and assertions do not create the schema. The Symfony kernel test checks command registration. This local trusted model proves neither real operator permissions, a queue, concurrent workers, nor external exactly-once behavior.

The shared MySQL fixture and its files are introduced in the transaction chapter. Run commands from the single article_demo root; do not create a separate Symfony application for each article.

Check the current example against an owned disposable MySQL schema:

  1. Databases Handler idempotency: repeat the task without duplicating its result
  2. Platform Engineering Who should retry a failed operation: one retry owner
  3. Platform Engineering Timeout after an external request: when the outcome is unknown

A project by the author · Weather Solution200

After reading, a look outside.

Temperature, rain and wind in your city. Check the forecast and plan the hours ahead.

Check the forecast
Next article