Model a task as a business resource
A task record should contain its owner, business case identifier, input version, idempotency key and explicit state. Separate accepted from completed. Acknowledging acceptance creates an expectation of continued handling, so the commitment cannot exist only in application memory or a browser tab.
Choose an atomic acceptance mechanism. When the business record and work request live in different systems, arrange recovery from discrepancies, for example through an outbox. Calling the broker after updating a database leaves a gap in which the application can stop between those steps.
Claims need an expiry
Claim work atomically and record the worker identifier, lease expiry and claim token. A heartbeat renews ownership, but does not prove an external effect succeeded. Work can be recovered after expiry. An old worker returning after a network interruption must not publish a result after losing ownership.
A fencing token becomes a control when result storage or an execution intermediary verifies the current claim. Checking it only at the start of a long operation is insufficient. If the destination cannot enforce it, design an execution boundary and business-operation idempotency rather than assuming a lease alone prevents duplicate consequences.
Failure meaning depends on the stage
In an illustrative scenario, a worker extracts an invoice, prepares fields and submits an ERP entry. A failure before submission normally permits another processing attempt. A failure after the request was sent but before confirmation creates an uncertain outcome. Blind repetition may create a second document.
Consequently, failed should not be the only exception state. Useful categories include transient failure, invalid business data, revoked permissions and reconciliation required. Each needs a different response and owner. The operations interface should expose those differences without requiring a business operator to interpret model logs.
Retry policy and resource budgets
| Situation | Recommended design decision |
|---|---|
| Temporary model unavailability | Bounded retry with delay |
| Invalid input data | Stop and correct the source |
| Unknown ERP write outcome | Reconcile before another attempt |
| Expired worker lease | Recover using a new claim token |
Every task needs limits on attempts, execution time and expenditure. The queue also needs admission limits, priorities and concurrency control. Otherwise, a provider outage can create a retry surge that overloads integrations and incurs unexpected costs when service returns.
Consider the recovery backlog separately from new traffic. Recovery work should not consume all capacity and prevent current urgent cases from progressing. Reserve capacity or apply explicit prioritisation, and make the resulting business trade-off visible to the process owner.
Acceptance testing includes restarts
Stop workers before the model call, after the response, after an external request and immediately before final status storage. Verify that the case remains discoverable, stale claims are rejected and the user sees an accurate state. Repeat with competing workers and revoked owner permissions.
Measure the oldest task's age, waiting time, recovered leases and cases awaiting reconciliation. Average worker duration will not reveal work abandoned in the queue. The process owner should define when backlog becomes a business incident and who can approve controlled recovery.
Exercise late completion and cancellation
An important test allows a worker that lost its lease to receive a late model response. Start a new claim for the same task, then let the old worker finish. Acceptance requires evidence that its stale token cannot change status or overwrite the current result. A restart test in which the old process never returns does not cover this risk.
Also cancel a task while it is running. Cancellation should prevent new consequences without pretending to reverse an external write already completed. Define the cancellation boundary and a state representing partial completion. Operators need to know whether to stop work, reconcile an outcome or perform an explicitly approved compensating action.
A manual retry days later should recheck permissions and approval validity. The request may have originated under a broader user role or a different price. Preserving the original input supports history; it does not automatically authorise execution under new conditions. Show operators that distinction before they decide.
Moving a task to a failure queue should preserve business ownership and discoverability. Removing infrastructure backlog is not equivalent to withdrawing the underlying business commitment. Otherwise queue maintenance can merely hide unfinished work from the process owner instead of resolving it.
Build resilient automation with Geekforce
We help design queues, integrations and recovery for AI workflows. Together, we can establish how your business continues after failure and which operations need particular protection against repeated execution.


