Why a lease, not a queue pop
A worker that pops a task and then crashes has taken the task out of the queue with no record of who holds it. A lease records the worker, the attempt, and the start time. If the worker disappears, the platform can mark it offline and the task can be requeued or expired.
The lease is also the point where routing happens. A worker advertises capabilities, and the platform only gives it task types it can solve. That is how a FunCaptcha-only host avoids picking up a Cloudflare Challenge it cannot handle.
worker_id
- Purpose
- Identifies the lease holder and updates its active count.
capabilities
- Purpose
- Limits leases to task types the worker advertised.
concurrency
- Purpose
- Stops a worker from taking more tasks than it can run.
status
- Purpose
- Online, draining, or offline; draining finishes current work only.
attempt
- Purpose
- Counts leases so retryable failures can be bounded.
Registration and heartbeat
Registration is an upsert by worker name. It sets capabilities, concurrency, version, and online status, and returns a worker ID. The worker uses that ID for leases and heartbeats.
The heartbeat carries active task count and reported queue depth. The platform marks a worker offline after 90 seconds without one. A heartbeat can recover a stale-offline worker, but an admin-set offline state stays disabled until an admin re-enables it.
{
"worker_id": "wkr_...",
"active_tasks": 1,
"queue_depth": 0
}Retryable failures
A solver error can be temporary: a proxy timed out, the target returned a transient page, or the browser process crashed. A lease result can mark the error retryable. The platform requeues the task without releasing the credit hold while attempts remain.
A non-retryable error, or the last allowed attempt, marks the task failed, releases the hold, and emits task.failed. The worker does not need to know the billing rules; it just reports the outcome.
{
"status": "failed",
"error": {
"code": "proxy_timeout",
"message": "Proxy did not respond",
"retryable": true
},
"duration_ms": 8400
}What the worker must not do
Do not report a result for a task you did not lease. Do not keep working after the task deadline and report late; the task may already be requeued or expired. Do not treat a 204 lease response as an error; it means there is no matching work right now.
The platform is the source of truth for task state. A worker that loses its lease should stop and let the platform decide whether to requeue.
- Lease only task types you advertise.
- Heartbeat during long solves.
- Report duration and a stable error code.
- Stop when the deadline passes.
- Expect 204 when no work matches.