Exceptions¶
taskq.exceptions is the single home for the classes the library raises on
the job surface — the errors application code meets in ordinary operation
(the tables below). It also hosts the subsystem exceptions and internal
runtime helpers that share its base classes: SystemExitCarrierError with
unwrap_system_exit (the carrier that lets a SystemExit cross an asyncio
task boundary without killing the loop), the settlement-stage helpers, and
the worker/subsystem errors (BatchIdExistsError, PgCapabilityProbeError,
ReservedTimerNamespaceError, the Signal* family). Those render under
Module reference below but are not job-operation errors, so the consumer
taxonomy does not index them. Operator machinery keeps its own typed errors
beside its code, not here: taskq.migrate's MigrationLockTimeoutError /
ChecksumDriftError (the CLI surfaces them as SystemExit), the worker
health probes' bind errors, OtelExporterConfigurationError,
TimescaleDBUnavailableError. None of them is a job-operation error.
Import errors from it (or from taskq for the names the package re-exports;
the Package Overview shows which) and catch TaskQError as the
fallback in handlers that must never let a library error escape.
Every error's full contract — fields, message shape, and the reasoning behind the classification — renders under the module directive below; this page's tables are the when/why/what-to-do index.
Consumer-facing taxonomy¶
The errors application code meets in ordinary operation. Ordered roughly by the surface that raises them: enqueue-time, then result-reading, then infrastructure.
| Exception | Raised when | Why this class | What to do |
|---|---|---|---|
MaxPendingExceededError |
enqueue() on an actor whose pending + scheduled count is at its max_pending cap. |
Capacity is exhausted; the library never blocks on it. | Retry later, shed load, or inside an actor body raise Snooze instead of letting this reach the retry classifier. |
MaxPendingLockTimeoutError |
The advisory-lock wait bounding a capped actor's exact count-then-insert expired its budget: the cap check never ran. | A BackpressureError sibling of MaxPendingExceededError — same response, but nothing was counted. |
Retry later or shed load, exactly as for a cap rejection. Fields: actor, timeout_ms. |
UniqueForLockTimeoutError |
A unique_for single-flight advisory lock wait expired — either a vanilla unique_for enqueue or a workflow run create carrying identity_key + unique_for: the dedup answer was not determinable in time. Nothing was inserted. |
Deliberately NOT a BackpressureError — nothing about capacity is wrong, so load-shedding handlers must not misfire. |
Retry the SAME enqueue or create: by then the winner's row is typically committed and the retry dedupes against it. Fields: actor (the actor or workflow name), identity_key, timeout_ms. |
MaxActiveRunsExceededError |
A workflow run create at the workflow's max_active_runs cap (the workflow's declared value, or a tighter per-call override). Nothing was created. |
Capacity is exhausted; the library never blocks on it. Subclasses BackpressureError, so an existing except BackpressureError handler (HTTP 503 + Retry-After) catches it unchanged. |
Retry later or shed load; inside a workflow body raise Snooze(delay) so a parent adopting a child flow defers without spending retry budget. Fields: workflow, active_runs, max_active_runs. |
MaxActiveRunsLockTimeoutError |
The bounded advisory-lock wait that serialises a workflow's active-run admission expired: the cap was never observed. Nothing was created. | Sibling of MaxActiveRunsExceededError — same response, but nothing was counted. Counted on taskq.backpressure.errors as max_active_runs_lock_timeout. |
Retry later or shed load, exactly as for a cap rejection. Fields: workflow, timeout_ms. |
IdempotencyKeyLockTimeoutError |
The bounded wait for an idempotency-token INSERT expired: the dedup answer for one (idempotency_scope, idempotency_key) pair was not determinable in time. Nothing was inserted. |
Third member of the enqueue-serialization family (with the two lock timeouts above); takes UniqueForLockTimeoutError's treatment. |
Retry the same enqueue: once the holder's transaction resolves, the retry dedupes or inserts fresh. |
SingletonCollisionError |
A singleton actor already has a job in pending/scheduled/running. |
Enqueue-time backpressure for the singleton discipline. | Fields: blocking_job_id (the UUID of the existing job), retry_after (from its schedule_to_close, may be None). |
BatchMaxPendingExceededError |
A bulk enqueue partitioned admission per actor and refused some: within-cap actors' items were inserted FIRST, then this raised. | The bulk-tier sibling of PartialBatchError: partial admission is typed so a blind whole-batch retry cannot silently duplicate. |
Retry only the refused indices (refusals, refused_indices, admitted_count) or give items idempotency_keys. |
PartialBatchError |
An autonomous ctx.jobs.enqueue_batch() partially failed: items enqueued before the first failure are committed, the rest are not inserted. |
The house shape for partial batch admission: succeeded count + failed indices + typed per-failure exceptions. | Fields: succeeded_count, failed_items (index → exception), total. Retry only the failed indices. |
SubEnqueueError |
flush_buffer() failed for one or more buffered sub-job enqueues AFTER the parent job committed and was marked succeeded: child jobs were lost. |
The parent's success is already durable; this error must be loud, not silent. | Fields: failed_items (each failed EnqueueArgs + its exception). Re-enqueue the lost children. |
UnknownQueueError |
With TASKQ_QUEUES_STRICT=true: a submit whose queue is declared in neither the fleet's registered assignments nor the process's own queue set (at the submit door, nothing stored), or a worker boot whose configured TASKQ_QUEUES contains a queue nothing routes to. |
Silent message loss is the worst queueing failure class; strict converts it into a loud refusal at the door. The asymmetry is the spine: refusals require positive two-source evidence; every ambiguous state (empty snapshot, read failure, env-vs-snapshot disagreement, the TTL window) resolves to ALLOW + advisory — over-rejection is strictly worse than over-permission. | Fix the queue name, register an actor on it, pass allow_unregistered=True for a genuinely dynamic name, or disable the knob. Safe deploy order for new queues: migrate → workers → clients; a client with no declared queue set judges on the snapshot alone (the message says so), so workers-first protects the first submits. |
PayloadValidationError |
Pydantic validation of a payload failed at enqueue ('fail at the door') or dispatch. | Non-retryable in both cases regardless of retry policy. | Fix the payload. Fields: actor, payload_schema_ver, validation_errors, item_index. |
IdempotencyKeyActorMismatchError |
An idempotency hit resolved to a job of a DIFFERENT actor. | A cross-actor hit is not a dedup: the caller would get another actor's result, indistinguishable from success. | Namespace keys per actor or give the actors different idempotency_scopes. Nothing was enqueued. |
JobFailed |
JobHandle.wait() observed a non-success terminal state. |
Carries the row so callers can inspect status/error_class/error_message. |
Inspect exc.row; distinct from ResultUnavailable. |
ResultUnavailable |
JobHandle.wait() observed a terminal state but no usable result (TTL expired, actor returned None for non-None R, or none stored). |
Distinguishes "terminal, no result" from "failed". | Read exc.reason ("result_ttl_expired" / "not_stored"); re-run the work if the result matters. |
CorruptJobDataError |
A stored jsonb column decoded to something its boundary refuses (invalid JSON, or a non-object in a row-contract dict field). | Non-retryable by construction: the bytes on disk cannot change by re-reading them. The dispatch claim boundary fails the row terminally and moves on. | Investigate the row (field: column) — a hand-corrupted row, schema drift, or a foreign writer. |
UnencodableValue |
A value no UTF-8 JSON encoding accepts (the canonical case: a lone surrogate like "\udcff", exactly what os.fsdecode of a non-UTF-8 filename byte yields). |
Subclasses TypeError deliberately, keeping the historical orjson contract: an except TypeError swallows it — write handlers accordingly. |
Non-retryable wherever the producer already ran; fix the value at the source. |
SchemaNotMigratedError |
The backend raised UndefinedTableError: the TaskQ schema is missing. |
Translated from raw asyncpg so operators see an actionable message (the original is chained via __cause__). |
Run taskq migrate up from a pre-deploy job; workers never self-migrate. |
StreamUnavailable |
A TaskQ.stream() / progress_stream() transport could not re-read its job row for at least its failure budget — the Postgres poll transport's fetches, and on the Redis path, the safety-net re-reads behind the subscription. |
A blip shorter than the budget is retried silently; this is the END of the stream — the caller's async for cannot wait forever on a database that is not coming back. |
Handle the stream ending; the last failure is chained as __cause__. |
RateLimitDependencyUnavailable |
A rate limiter's PG store was never wired (no pool injected) at acquire time. | Subclasses RuntimeError deliberately (the historical contract); the acquire boundary fails CLOSED — a non-consuming denial, never a burnt attempt. |
Fix the wiring: inject the pool the limiter's fallback needs. |
RateLimitStoreCorrupt |
A limiter store answered, but the reply violates the reply contract (a token count outside [0, capacity], a malformed TIME tuple, ...). |
A store that LIES is failed closed exactly like a store that cannot serve, and re-runs admission against the durable PG row. | Treat as a store outage; investigate the store's integrity. |
ActorDeregistrationError |
Base for actor deregistration refusals. | Lets cleanup code catch every refusal shape with one clause. | See the Actor API: Actor deregistration. |
ActorHasActiveJobsError |
Non-terminal jobs reference the actor being deregistered. | Carries active_count and per-status status_counts so the caller can decide: cancel first, or force=True (which still refuses on RUNNING jobs). |
Cancel the blocking jobs, or pass force=True for pending/scheduled ones and wait out the running. |
ActorHasEnabledSchedulesError |
Enabled cron schedules reference the actor being deregistered. | Carries schedule_ids so the caller can disable or delete them first. |
Disable/delete the named schedules, or pass force=True to disable them automatically. |
ActorNotFoundError |
Deregistering an actor with no stored actor_config row. |
Lets idempotent cleanup loops treat "already gone" as success. | Catch and continue. |
WorkflowCancellationRequiredError |
A generic cancel (cancel, write_cancel_request) aimed at a non-terminal workflow graph node or __flow__ root. |
A node's terminal is the workflow engine's to write against its wf_step_ledger; the generic verb would strand its dependents. |
Nothing was written. Cancel the run: cancel_workflow_run(flow_id=...) / taskq flows cancel <run_id> / POST /api/runs/<run_id>/cancel. Fields: job_id, step_key, flow_id. |
WorkflowRetryRequiredError |
A generic retry (retry_job) aimed at a workflow graph node or __flow__ root. |
The generic re-pend skips the root lock, the closure reopen, the failed_parent clear and the run-epoch advance; the node returns pending while its run still counts it settled. |
Nothing was written. For a failed node in a non-cancelled run, re-arm it with retry_workflow_node(flow_id=..., node_key=...) / taskq flows retry <run_id> <node_key>. Other terminal node states, cancelled runs, and a __flow__ root require a new run. Fields: job_id, step_key, flow_id. |
TaskQError |
— (base class). | The catch-all for every library-raised error EXCEPT the deliberate builtin-base escapees: UnencodableValue (a TypeError) and RateLimitDependencyUnavailable + RateLimitStoreCorrupt (a RuntimeError). |
An except TaskQError handler misses exactly those three; add explicit clauses if they matter to you. |
Control-flow signals Snooze and RetryAfter also live in this module but
are NOT errors — they are signals an actor raises to translate into state
transitions; see Actors: Control-flow exceptions
and Retries.
Names outside the package __all__
The five consumer errors in the table above that are public here but
deliberately not re-exported from taskq.__all__ — the export surface is
frozen pending a separate decision — are CorruptJobDataError,
UnencodableValue, IdempotencyKeyLockTimeoutError,
RateLimitDependencyUnavailable, and RateLimitStoreCorrupt. Import them
from taskq.exceptions (as this page does).
The subsystem and runtime names rendered under Module reference below
are likewise imported from taskq.exceptions, not from the top-level
taskq: BatchIdExistsError, PgCapabilityProbeError,
ReservedTimerNamespaceError, SignalAbandonedError,
SignalPayloadAmbiguousError, SignalPayloadError, SignalTimeoutError,
SystemExitCarrierError, settlement_stage_of, tag_settlement_stage,
and unwrap_system_exit.
Every other name in the table above resolves from both homes.
Module reference¶
exceptions ¶
Exception hierarchy for TaskQ.
Mirrors: control-flow exceptions like Snooze and RetryAfter are not errors, they are signals the consumer translates into state transitions.
TaskQError ¶
Bases: Exception
Base for all library-raised exceptions.
JobFailed ¶
Bases: TaskQError
:meth:JobHandle.wait saw a non-success terminal state.
Carries the row so callers can inspect status, error_class,
error_message, and error_traceback. Distinct from
:class:ResultUnavailable (which means terminal but no result
stored) and from the original actor exception (which is recorded on
the row, not raised).
Source code in src/taskq/exceptions.py
ResultUnavailable ¶
Bases: TaskQError
:meth:JobHandle.wait saw a terminal state but no usable result.
Causes:
- result TTL expired before the call;
- actor returned None while R is non-None
(treated as schema mismatch, not a value);
- row stored result=NULL for a non-success status.
reason distinguishes the two live-result causes at the instance:
"result_ttl_expired" when the row itself carries the expiry
evidence (result_expires_at in the past, which the retention
sweep leaves in place on the rows it nulls). The stamp proves the
TTL elapsed, no more: the completion write stamps
result_expires_at even when the result itself is NULL (an
actor that returned None) and the sweep only nulls rows whose
result was still stored, so a past stamp cannot distinguish a swept
result from a row that never stored one. The message asserts only
what the row proves. "not_stored" covers every other case.
Carries the row for inspection.
EventRetentionGapError ¶
Bases: TaskQError
A watch_reclaims stream resumed a cursor the retention horizon passed.
The event-prune watermark (job_events_prune_state.pruned_through_id,
migration 01.00.20_02) records the highest job_events id any retention
deleter has committed a delete below-or-at. A resumed cursor strictly
below that bound means at least one event id the consumer never received
was deleted: the hole can never be refilled, so the stream ends here
instead of silently skipping to live and letting the consumer believe it
saw everything.
This makes a loss loud that silent polling would hide:
no error is raised on either side, the poll simply returns the
surviving rows and the consumer's async for read like a quiet fleet.
The signal is conservative by design: the watermark is a union bound across event kinds, so it proves the feed is incomplete without proving which slice a consumer filters for lost a row. A cursor AT or above the watermark never raises: every deleted id was at or below a position the consumer had already been delivered.
Attributes:
| Name | Type | Description |
|---|---|---|
cursor |
the resumed cursor the poll rejected. |
|
pruned_through_id |
the watermark it sits behind. |
Remediation: reposition the consumer past the watermark (accepting the
recorded loss) or size event_retention_period against the slowest
consumer's worst outage so the horizon cannot pass a live cursor.
Source code in src/taskq/exceptions.py
StreamUnavailable ¶
StreamUnavailable(
job_id: JobId,
*,
consecutive_failures: int,
elapsed: float,
last_error: BaseException,
)
Bases: TaskQError
A job stream could not re-read its job row for at least its failure budget.
Raised by either transport behind :meth:TaskQ.stream and
:meth:JobHandle.progress_stream — the Postgres poll transport's
fetches, and on the Redis path, the safety-net re-reads behind the
subscription — when every fetch has failed with a pool or connection
error for elapsed seconds (the transport's failure budget). A
blip shorter than the budget is retried silently beyond a warning
per failed poll; this is the end of the stream, so the caller's
async for cannot wait forever on a database that is not coming
back. The last failure is chained as __cause__.
Source code in src/taskq/exceptions.py
BackpressureError ¶
Bases: TaskQError
Base class for synchronous enqueue-time backpressure signals.
Subclassed by SingletonCollisionError (singleton collision) and used directly by max_pending enforcement. The caller decides whether to retry, fail, or wait; the library does not block on capacity.
Source code in src/taskq/exceptions.py
SingletonCollisionError ¶
SingletonCollisionError(
actor: str,
blocking_job_id: UUID | None = None,
retry_after: timedelta | None = None,
)
Bases: BackpressureError
Raised when a singleton actor already has a job in pending/scheduled/running.
blocking_job_id is the UUID of the existing job from the Layer 1
pre-flight query; it is None when raised from the Layer 2
UniqueViolationError catch (the race path) because no pre-flight row
was fetched.
retry_after is computed from the blocking job's schedule_to_close
when available. It is None when the blocking job has no
schedule_to_close set, or when raised from the Layer 2 catch path.
The heartbeat_interval * 4 fallback is intentionally not
implemented, retry_after is computed from schedule_to_close only.
Callers who need a poll cadence when retry_after is None should poll on
their own schedule (research.md Gap 1, resolution path (a)). Reason:
heartbeat_interval is not available at the backend enqueue boundary;
propagating it would require enlarging the backend constructor surface and
is out of scope.
Source code in src/taskq/exceptions.py
MaxPendingExceededError ¶
Bases: BackpressureError
Raised when an actor's max_pending queue-depth limit is reached.
current_count is the count of pending+scheduled jobs at the time
of the pre-flight check. max_pending is the configured limit.
The caller decides whether to retry, fail, or wait; the library does
not block on capacity.
Source code in src/taskq/exceptions.py
hint
class-attribute
instance-attribute
¶
hint = "Inside an actor body, prefer `raise Snooze(delay)` over letting this reach the retry classifier: a full queue is backpressure, not a failure, and a Snooze defers without spending the job's retry budget."
MaxPendingLockTimeoutError ¶
Bases: BackpressureError
Raised when the advisory-lock wait bounding a capped actor's exact count-then-insert exceeded its budget.
Distinct from :class:MaxPendingExceededError: the cap was never
observed -- this enqueue lost the race to even run the check, waiting
behind other producers on the same (schema, actor) lock until the
budget expired. The caller's correct response is the same as for a cap
rejection (retry later, or shed load), so this is raised from the same
:class:BackpressureError family and recorded against the same
taskq.backpressure.errors counter (kind="max_pending_lock_timeout").
timeout_ms is the budget that expired. pending is 0 and
max_pending is None -- no count was taken.
Deliberately not a subclass of :class:MaxPendingExceededError: that
class means "the cap is full" and carries the observed count; a lock
timeout means "too contended to check" and conflating the two would
mislead handlers that react to a full queue (e.g. by logging the
count). Catch :class:BackpressureError to treat both the same way.
Source code in src/taskq/exceptions.py
args
instance-attribute
¶
args = (
f"backpressure: enqueue for actor {actor!r} could not acquire the max_pending advisory lock within {timeout_ms:g} ms of contention (the exact cap check was not reached). Retry later or shed load, exactly as for MaxPendingExceededError.",
)
MaxActiveRunsExceededError ¶
Bases: BackpressureError
Raised when a workflow's declared max_active_runs cap is full.
A workflow root cap bounds every non-terminal run of that workflow
(pending, scheduled, running) — including HITL-held and
backpressure-parked runs, which is why the cap cannot reuse the
vanilla max_pending semantics (that count excludes running).
The refusal is backpressure, not failure: the caller decides to retry
later or shed load, and a parent step adopting a child flow turns it
into a Snooze instead of spending retry budget.
workflow names the workflow whose cap was reached (the registered
name, bounded cardinality), active_runs is the count observed
under the admission lock, and max_active_runs is the effective
cap (the declared value, or the caller's tighter per-call override).
Source code in src/taskq/exceptions.py
hint
class-attribute
instance-attribute
¶
hint = "Inside a workflow body, prefer `raise Snooze(delay)` over letting this reach the retry classifier: a full active-run window is backpressure, not a failure, and a Snooze defers without spending the job's retry budget."
args
instance-attribute
¶
args = (
f"backpressure: workflow {workflow!r} already has {active_runs} active runs (max_active_runs={max_active_runs}); no fresh run was created. Retry later or shed load.",
)
MaxActiveRunsLockTimeoutError ¶
Bases: BackpressureError
Raised when the advisory-lock wait bounding a workflow's active-run admission exceeded its budget.
Distinct from :class:MaxActiveRunsExceededError: the cap was never
observed — this create lost the race to even run the count, waiting
behind other producers of the same workflow on its
taskq:wf:max_active_runs:<schema>:<workflow> lock until the budget
expired. The caller's correct response is the same as for a cap
rejection (retry later, or shed load), so this is raised from the
same :class:BackpressureError family and recorded against the same
taskq.backpressure.errors counter
(kind="max_active_runs_lock_timeout").
workflow names the contended workflow. timeout_ms is the
budget that expired.
Source code in src/taskq/exceptions.py
args
instance-attribute
¶
args = (
f"backpressure: a fresh run of workflow {workflow!r} could not acquire the active-run admission lock within {timeout_ms:g} ms of contention (the cap check was not reached). Retry later or shed load, exactly as for MaxActiveRunsExceededError.",
)
UniqueForLockTimeoutError ¶
Bases: TaskQError
Raised when the advisory-lock wait bounding a unique_for
single-flight check exceeded its budget.
Two surfaces share it because the situation is one situation: a vanilla
unique_for enqueue's preflight-then-insert, and a workflow run create
carrying identity_key + unique_for. In both, the contention scope
is a single logical entity's identity, the dedup answer could not be
determined in time, and nothing was written.
Distinct from :class:MaxPendingLockTimeoutError on purpose. That
error is a :class:BackpressureError: the caller's own load filled
the contention scope (every producer of a capped actor), the cap
check never ran, and the correct response is the same as for a cap
rejection, retry later or shed load. This error means the DEDUP
ANSWER for one (schema, actor, identity_key) could not be
determined in time: the contention scope is a single logical
entity's identity (a same-key stampede, or a black-holed holder the
server has not yet reaped), nothing about capacity is wrong, and the
correct response is to RETRY the same operation, by then the winner's
row is typically committed and the preflight returns it as a dedup
hit, which is the very outcome the wait existed to produce.
Deliberately not a :class:BackpressureError so handlers that react
to backpressure by shedding load or logging queue counts cannot
misreact. The vanilla enqueue records kind=unique_for_lock_timeout
separately from its capacity kinds; the workflow create emits its own
workflow_unique_for_lock_timeout warning without recording
backpressure.
identity_key names the contended entity. timeout_ms is the
budget that expired. The dedupe attempt inserted nothing. On a
pool-owned transaction the loser's transaction rolled back before any
write; on a caller-owned vanilla transaction (enqueue_with_conn /
TaskQ.with_conn) the savepoint the bounded acquire used rolled
back, the transaction remains usable, and durability of anything the
CALLER wrote alongside is the caller's decision, not this error's
claim to make. A workflow create owns its create transaction.
Source code in src/taskq/exceptions.py
IdempotencyKeyLockTimeoutError ¶
IdempotencyKeyLockTimeoutError(
actor: str | None,
idempotency_key: str,
timeout_ms: float,
*,
idempotency_scope: str | None = None,
)
Bases: TaskQError
Raised when the bounded wait for an idempotency token insert exceeded its budget.
The third member of the enqueue serialization family, after
:class:MaxPendingLockTimeoutError (capacity) and
:class:UniqueForLockTimeoutError (single-flight identity): the
speculative ON CONFLICT (idempotency_scope, idempotency_key) DO
NOTHING token INSERT blocks on another transaction's UNCOMMITTED
same-pair row, Postgres must wait for that transaction's uniqueness
verdict, and on a transactional consumer the holder IS the actor's
own open transaction, whose runtime is unbounded by default
(default_start_to_close = None). The wait is bounded by a
lock_timeout scoped to the INSERT's savepoint; on expiry the
DEDUP ANSWER for that one (idempotency_scope, idempotency_key)
pair could not be determined in time, which is
:class:UniqueForLockTimeoutError's exact situation and therefore
takes its treatment: retry the same enqueue, once the holder's
transaction resolves, the retry either dedupes against the committed
token or inserts fresh. Deliberately not a
:class:BackpressureError (nothing about capacity is wrong) and
deliberately not recorded against taskq.backpressure.errors;
the idempotency-lock-timeout log event carries the
observability instead.
This enqueue wrote nothing: the savepoint that carried the GUC and the INSERT rolled back first, so the caller's transaction remains usable, the same caller-owned-transaction discipline the singleton collision's savepoint established.
Source code in src/taskq/exceptions.py
IdempotencyKeyActorMismatchError ¶
IdempotencyKeyActorMismatchError(
*,
actor: str,
existing_actor: str,
existing_job_id: UUID | None,
idempotency_key: str,
idempotency_scope: str | None,
)
Bases: TaskQError
An idempotency hit resolved to a job of a DIFFERENT actor.
Uniqueness is (idempotency_scope, idempotency_key), schema-wide, so
two actors sharing a key collide. A same-actor hit is a dedup and returns
the existing row; a cross-actor hit cannot be one, the caller asked for
THIS actor's job and would receive a handle whose result is another
actor's, indistinguishable from a successful dedup, so it is refused.
The composite index here cannot include the actor without a migration,
so the hit is checked after the fact and refused instead of silently
resolved.
Nothing was inserted (single enqueue: the arbiter skipped the row; batch:
the whole batch is rolled back, all-or-nothing like a singleton
collision; batch fast: the COPY aborts the whole batch the same way).
Namespace keys per actor ("send_receipt:order_123") or
give the two actors different idempotency_scope values.
existing_job_id names the stored job the key matched; it is None
when the collision is between two items of the same fast-path batch,
where no row was stored for either.
Source code in src/taskq/exceptions.py
BatchMaxPendingExceededError ¶
BatchMaxPendingExceededError(
*,
refusals: list[MaxPendingExceededError],
refused_indices: dict[str, list[int]],
admitted_count: int,
)
Bases: BackpressureError
A bulk enqueue partitioned its admission per actor and refused some.
Raised by :meth:~taskq.backend._protocol.Backend.enqueue_batch /
:meth:~taskq.backend._protocol.Backend.enqueue_batch_fast (and every
client path riding them) when one or more actors' items exceed their
effective max_pending: the within-cap actors' items are inserted
first, then this error raises naming the refusals, the bulk-tier
sibling of :class:PartialBatchError, which is the house shape for
partial batch admission (succeeded count + failed indices + typed
per-failure exceptions).
An over-cap actor's items are refused as a whole group, never partially filled up to the cap: the single-enqueue path refuses a capped enqueue outright, and a partial fill would admit an arbitrary prefix of the caller's items that the caller never chose.
Fields:
refusals, one :class:MaxPendingExceededErrorper over-cap actor (actor,current_countat the admission check, the effectivemax_pending).refused_indices, actor name -> indices into the caller's items list of that actor's refused items. For :meth:~taskq.client.JobsClient.enqueue_batch_streaming's chunked path the indices are stream-global and the stream stops at the refusing chunk: items after it were never attempted.admitted_count, how many items were admitted and inserted by the raising call.
Durability of the admitted items depends on the path: committed when
the call owned its transaction (no caller-supplied connection, one
pool transaction per call/chunk); inserted-but-uncommitted on a
caller-supplied connection with an open transaction, where that
transaction's commit/rollback decides. enqueue_batch /
enqueue_batch_streaming with failure_policy or finalizer
and no connection (the atomic path) never raises this error, its
single transaction keeps the legacy all-or-nothing contract and
raises plain :class:MaxPendingExceededError with nothing committed.
Deliberately not a :class:MaxPendingExceededError subclass: handlers
written for the pre-partition contract assume that a raised
MaxPendingExceededError left nothing enqueued. Under this error
part of the batch IS stored, a blind whole-batch retry would
duplicate the admitted items. Catch this type explicitly and retry
only the refused indices, or give items idempotency_keys so a
whole-batch retry deduplicates against the admitted rows.
The same hazard reaches handlers written against the shared base:
except BackpressureError catches this error too, and the
base's contract ("the caller decides whether to retry, fail, or
wait") predates partial admission. A generic backpressure handler
that retries the whole batch MUST first consult
admitted_count / refused_indices, retry only the refused
items, or rely on idempotency_keys, otherwise it duplicates
the admitted items on every retry.
Source code in src/taskq/exceptions.py
PayloadValidationError ¶
PayloadValidationError(
detail: str,
*,
actor: str | None = None,
payload_schema_ver: str | None = None,
validation_errors: list[dict[str, object]]
| None = None,
item_index: int | None = None,
)
Bases: TaskQError
Pydantic validation failed at enqueue or dispatch.
At enqueue: raised before the row is inserted ('fail at the door'). At dispatch: causes the job to transition to 'failed' with error_class='PayloadValidationError'. Non-retryable in both cases regardless of the actor's retry policy.
item_index is the failing item's position in the CALLER's
coordinate space (the batch list / the streaming caller's stream)
whenever the raise site knows one, batch per-item guards and their
remapping boundaries populate it, so a handler or retry tool reads
the position as a field instead of parsing the message. None
is the no-coordinate case: single-item enqueue, dispatch-time
validation, non-itemized configuration errors. The message embeds
the same index for humans; the field is the machine-readable copy.
Source code in src/taskq/exceptions.py
CorruptJobDataError ¶
Bases: TaskQError
A stored jsonb column decoded to something its boundary refuses.
Two shapes trigger it, both classified at the decode boundary:
- Text that is not valid JSON at all (a hand-corrupted row, schema
drift to
text, an interop writer), through :func:taskq.backend._records.jsonb_to_dictor its user-content sibling :func:taskq.backend._records.jsonb_to_value. - Valid JSON whose body is not the object the row contract declares
(a list or scalar in a dict-typed field, e.g. a row written by a
different version's codec), through :func:
jsonb_to_dictonly. That shape gate covers the ROW-CONTRACT dict fields TaskQ itself owns and indexes into (metadata,progress_state, the rate-limitstate,detail). The USER-CONTENT columns (result,payload) hold the actor's data and declare no shape, so they decode through :func:jsonb_to_valuewith only the malformed-text guard: a valid list or scalar round-trips.
The raw driver/JSON errors (orjson.JSONDecodeError, a
ValueError) are re-raised as this class so every consumer sees
one named error_class instead of a driver vocabulary word.
Non-retryable by construction: the bytes on disk cannot change by
re-reading them. The dispatch claim boundary
(:mod:taskq.backend._dispatch) catches this class per claimed row,
writes the row's terminal failure with
error_class='CorruptJobDataError' through the same fused
mark_failed statement every other failure uses, and dispatches
the round's remaining healthy rows, so one poisoned row can neither
crash the worker through the producer loop's unexpected-failure
backstop nor loop forever through claim and lease-sweep reclaim.
Source code in src/taskq/exceptions.py
ResultTooLarge ¶
Bases: TaskQError
Terminal result exceeded WorkerSettings.result_max_bytes.
Non-retryable: the actor already ran to completion and a re-run returns
the same oversized value, so retrying only burns the remaining attempts
(re-running the actor's side effects each time) before the job fails
anyway. Classified alongside PayloadValidationError in
:meth:taskq.retry.RetryClassifier.classify.
UnencodableValue ¶
Bases: TypeError
A value no UTF-8 JSON encoding accepts, so no PG text/jsonb
form of it exists.
The canonical case is a lone surrogate ("\udcff", exactly what
os.fsdecode of a non-UTF-8 filename byte yields): a legal Python
str that orjson refuses to encode. Non-str dict keys and
objects the fallback cannot convert raise the same class. Raised by
:func:taskq._json.dumps, the single serialization boundary, so
every producer sees one class; subclassing :class:TypeError keeps
the historical orjson contract every except TypeError caller and
wording pin already relies on.
Non-retryable wherever the producer already ran (an actor result): a
re-run reproduces the same unencodable value, so retrying only burns
the remaining attempts, the exact burn :class:ResultTooLarge
exists to prevent. Classified alongside it in
:meth:taskq.retry.RetryClassifier.classify. The durable-write
boundary (:func:taskq._json.dumps_jsonb_str) instead escapes the
unencodable codepoints, mirroring :func:taskq._json.sanitize_nul_str:
rejecting there would strand the very work the value describes.
ProgressTooLarge ¶
Bases: TaskQError
Raised when progress data payload exceeds the configured size limit.
limit is the configured cap in bytes (WorkerSettings.progress_data_max_bytes).
actual is the serialised byte length of the data dict that was rejected.
Non-retryable: the caller must reduce the payload before retrying.
Source code in src/taskq/exceptions.py
ScopeViolation ¶
Bases: TaskQError
A provider depends on a shorter-lived scope than its own.
Source code in src/taskq/exceptions.py
DependencyCycle ¶
Bases: TaskQError
A cycle was detected in the provider graph.
Source code in src/taskq/exceptions.py
MissingProvider ¶
Bases: TaskQError
A type was injected but no provider is registered.
Source code in src/taskq/exceptions.py
DIError ¶
Bases: TaskQError
Base for DI engine errors not covered by startup-validation.
Raised by the solver at resolution time for malformed annotations (e.g. multiple Scope markers in one Annotated parameter) or unresolvable forward references in actor signatures. Distinct from MissingProvider / ScopeViolation / DependencyCycle, which are raised at startup validation.
Snooze ¶
Bases: TaskQError
Job returns control with new scheduled_at; does not consume retry budget.
Source code in src/taskq/exceptions.py
RetryAfter ¶
Bases: TaskQError
Schedule retry at specific delay. Consumes retry budget by default.
Source code in src/taskq/exceptions.py
ReservationUnavailable ¶
ReservationUnavailable(
bucket_name: str,
retry_after: timedelta,
*,
source: Literal[
"reservation", "rate_limit"
] = "reservation",
)
Bases: TaskQError
A ConcurrencyReservation slot could not be acquired.
When the upstream RateLimitDecision.retry_after is None, callers
MUST substitute DEFAULT_RESERVATION_BACKOFF. When it is
timedelta(0) (allowed decisions) callers MUST pass it through
unchanged, do not use a truthiness coalesce
(x or DEFAULT_RESERVATION_BACKOFF) because timedelta(0) is falsy
and would be wrongly replaced.
RateLimitDependencyUnavailable ¶
Bases: RuntimeError
A rate limiter's PG store was never wired, no pool was injected.
Raised by every ratelimit PG delegate's no-pool branch (the token
bucket's acquire/peek/reset/refund and both sliding-window styles)
when the delegate is reached with pg_pool=None: most often the
Redis→PG fallback funnelling into a fallback pool the caller never
injected, but a directly PG-backed limiter with no pool is the same
condition. The store dependency cannot answer, so the acquire
boundary's correct response is the limiter's fail-closed denial ,
:data:taskq.worker._consumer._RATE_LIMIT_DEPENDENCY_EXCEPTIONS
includes this class for exactly that; an escapee would instead be
misattributed to the job as a failure (a retry attempt burnt and a
wiring gap persisted as the job's error_class).
Deliberately not a :class:TaskQError: subclassing
:class:RuntimeError keeps the historical contract every existing
caller and wording pin relies on, the except RuntimeError /
pytest.raises(RuntimeError, match="pg_pool not injected...") pins
and the chaos tier's fail-loud pytest.raises(RuntimeError) all
hold unchanged (the same builtin-base precedent as
:class:UnencodableValue).
RateLimitStoreCorrupt ¶
Bases: RateLimitDependencyUnavailable
A limiter store answered, but the reply violates the reply contract.
The trust-boundary verdict for a store that LIES: a semantically
wrong reply (a value outside the reply's type or range domain, a
truncated or wrongly-shaped payload) is indistinguishable from a
store that cannot serve, so it is failed closed as exactly that.
Raised by the Redis reply validators (the token-bucket and
sliding-window Lua decoders, the peek-path parsers, the store-clock
read) when a reply carries a value no honest script could produce:
a token count outside [0, capacity], a negative token count, a
non-finite or negative retry hint, a window count outside
[0, limit], a retry hint past the key's own TTL, a malformed
TIME tuple.
Subclassing :class:RateLimitDependencyUnavailable is the routing
mechanism, not a convenience: the acquire boundary's
_RATE_LIMIT_DEPENDENCY_EXCEPTIONS family already includes the
parent, so a lie synthesizes the same non-consuming fail-closed
denial an outage gets (never a burnt attempt, never the lie's value
persisted as the job's error), and :func:taskq.ratelimit
._redis_utils.with_pg_fallback names this class explicitly beside
the outage exceptions so a suspected lie re-runs admission against
the durable PG row, the same fallback path an outage takes.
IllegalStateTransition ¶
Bases: TaskQError
Attempted to transition a job to a status not reachable from its current status.
Best-effort fast-path check only; the SQL WHERE clause is the authoritative serialization gate for concurrent writes.
Source code in src/taskq/exceptions.py
WorkerOwnershipMismatch ¶
Bases: TaskQError
Terminal write predicate failed: job exists but is owned by a different worker.
Source code in src/taskq/exceptions.py
ActorConfigDriftError ¶
ActorConfigDriftError(
actor: str,
field: Literal["metadata"],
registered: dict[str, object] | None,
stored: dict[str, object] | None,
)
Bases: TaskQError
One actor whose registered structural config differs from the stored row.
Only metadata is structural, no operator surface can move it, so a
mismatch there is always a correctness bug and refuses boot. The queue
assignment is operator-owned once a row exists (moved by
taskq actor-config move-queue): a differing literal never raises,
it logs actor-config-queue-override at boot and the stored
assignment wins. Capacity fields (max_concurrent,
max_pending, result_ttl) are likewise operator-owned and never
raise this error; see :func:taskq.worker.startup.sync_actor_config.
Source code in src/taskq/exceptions.py
ActorConfigDriftList ¶
Bases: TaskQError
Collected wrapper raised at worker startup when one or more actors have drift.
Source code in src/taskq/exceptions.py
ActorDeregistrationError ¶
ActorHasActiveJobsError ¶
ActorHasActiveJobsError(
actor: str,
active_count: int,
status_counts: dict[str, int],
*,
force: bool = False,
workflow_jobs: bool = False,
)
Bases: ActorDeregistrationError
Non-terminal jobs reference the actor.
Carries the count and per-status breakdown of the blocking jobs so the
caller can decide whether to cancel them first or use force=True.
When workflow_jobs is True, the blocking rows belong to active
workflow runs (__flow__ roots or graph nodes) which cannot be
cancelled by force=True — the caller must cancel the owning
workflow runs via cancel_workflow_run or taskq flows cancel
first.
When force is True and workflow_jobs is False, the message
reflects that running jobs cannot be cancelled by force=True — the
caller must wait for them to finish or cancel them individually first.
Source code in src/taskq/exceptions.py
ActorHasEnabledSchedulesError ¶
Bases: ActorDeregistrationError
Enabled cron schedules reference the actor.
Carries the schedule IDs so the caller can disable or delete them first.
Source code in src/taskq/exceptions.py
ActorNotFoundError ¶
Bases: ActorDeregistrationError
The actor_config row does not exist, nothing to deregister.
Currently raised only by :func:deregister_actor. Other ops
(get, set_capacity) return None for missing rows.
Source code in src/taskq/exceptions.py
PartialBatchError ¶
PartialBatchError(
*,
succeeded_count: int,
failed_items: list[tuple[int, Exception]],
total: int,
)
Bases: TaskQError
Raised when an autonomous enqueue_batch partially fails.
Items enqueued before the first failure are committed; remaining
items are not inserted. succeeded_count is the number of items
that were successfully enqueued. failed_items maps the index
of each failed item to its exception. total is the original
batch size.
Source code in src/taskq/exceptions.py
SchemaNotMigratedError ¶
Bases: TaskQError
Backend raised UndefinedTableError, the TaskQ schema is missing.
Translated by the client layer (:mod:taskq.client._jobs) from an
asyncpg.exceptions.UndefinedTableError on the enqueue/get/list/cancel
paths, so operators see an actionable message instead of a raw asyncpg
traceback. The original exception is chained via __cause__.
Source code in src/taskq/exceptions.py
EmptyFilterError ¶
Bases: TaskQError
Raised when cancel_where is called with a filter that has no predicates.
A filter with no queue, status, actor, identity_key, batch_id, tags, or
active predicate would match every job in the table, almost certainly
a bug. The guardrail is intentionally loud: the caller must add at least
one predicate or explicitly bypass with allow_empty_filter=True.
Source code in src/taskq/exceptions.py
WorkflowCancellationRequiredError ¶
Bases: TaskQError
A generic cancel was aimed at a workflow graph row or a flow root.
flow_id is the run to cancel — the root row's own id for a
__flow__ root, the owning run otherwise. A root's step_key is
"__flow__".
Source code in src/taskq/exceptions.py
WorkflowRetryRequiredError ¶
Bases: TaskQError
A generic retry was aimed at a workflow graph row or a flow root.
flow_id is the run that owns the row — the root row's own id for a
__flow__ root, the owning run otherwise. A root's step_key is
"__flow__": the root is not a retryable node, and a generic re-pend
would leave an unclaimable pending root behind, so the message names the
node retry and the new-run route instead.
Source code in src/taskq/exceptions.py
PgCapabilityProbeError ¶
Bases: TaskQError
The server answered the capability probe with a non-integer server_version_num.
Source code in src/taskq/exceptions.py
UnsupportedPostgresVersionError ¶
UnsupportedPostgresVersionError(
*,
detected_version: int,
minimum_version: int,
detected_text: str,
context: str | None = None,
)
Bases: TaskQError
The connected server is older than TaskQ's PostgreSQL floor.
Source code in src/taskq/exceptions.py
ScopedIdempotencyMigrationPendingError ¶
ScopedIdempotencyMigrationPendingError(
*,
actor: str | None = None,
idempotency_key: str | None = None,
idempotency_scope: str | None = None,
detail: str | None = None,
)
Bases: TaskQError
idempotency_scope was used, but the schema has not yet had
01.00.03_01_post_idempotency_scope_drop_old_index.sql applied.
Between applying 01.00.03_01_pre_idempotency_scope.sql and its
post counterpart (the rolling-deploy window every worker's schema
passes through), both the old global jobs_idempotency_key_uniq
index (on idempotency_key alone) and the new composite
jobs_idempotency_scope_key_uniq index (on (idempotency_scope,
idempotency_key)) exist simultaneously, this is deliberate, see the
"PHASE OBLIGATIONS" comment in the pre migration file, and is what
keeps pre-this-release code's unscoped ON CONFLICT (idempotency_key)
working unmodified during the window.
The cost of that safety: enqueuing the same idempotency_key under
two different idempotency_scope values satisfies the new
composite index's ON CONFLICT target (no conflict there, the
(scope, key) pair is new) but still violates the still-present old
global index, which is not covered by that ON CONFLICT target.
PostgreSQL raises UniqueViolationError for a conflict against a
non-arbiter unique index unconditionally, the library deliberately
does not catch that and silently fall back to a different scope's row,
because doing so would return the wrong job for the scope the caller
actually asked for, silently, which is a worse failure mode than a
loud, explicit error for a purely transitional migration-window
condition. Raised instead of letting the raw
asyncpg.UniqueViolationError propagate.
Any call, scoped or unscoped, is affected whenever its
idempotency_key already exists under a different scope: an
unscoped call that reuses a key first written under a non-default
scope raises this error just as a scoped call reusing an unscoped
key does (verified against live PostgreSQL). Only brand-new keys and
same-scope repeats are unaffected, a repeated key under the same
scope (including two unscoped calls, which share the default ''
scope) conflicts identically against both indexes for the exact same
row, which ON CONFLICT DO NOTHING on the composite index resolves
cleanly.
Resolution: confirm every worker is running the release that shipped
idempotency_scope, then apply
taskq migrate up --phase post (or a plain taskq migrate up) to
drop the old index and activate scoped dedupe, or avoid passing
idempotency_scope until that migration has run.
Source code in src/taskq/exceptions.py
DuplicateIdempotencyKeyError ¶
DuplicateIdempotencyKeyError(
*,
idempotency_key: str | None = None,
idempotency_scope: str | None = None,
detail: str | None = None,
)
Bases: TaskQError
enqueue_batch_fast aborted: an item's
(idempotency_scope, idempotency_key) pair is already enqueued by the
same actor. A pair spanning two actors raises
:class:IdempotencyKeyActorMismatchError instead, the same refusal the
single and batch tiers apply.
COPY has no ON CONFLICT arbiter, so a same-pair duplicate ,
repeated within the batch or raced against a row the composite
jobs_idempotency_scope_key_uniq index already covers, aborts the
ENTIRE batch before a single row is written (all-or-nothing; the
abort is deliberate bulk-import semantics, unchanged by the
classification this error introduced). The non-fast paths never
raise for this condition: their ON CONFLICT arbiter dedupes and
RETURNS the existing row, so a typed domain error for a
deduplication-constraint violation on the enqueue path does not exist
there, hence this class, expressing the same idempotency constraint
at the bulk-import boundary in both the SQL and in-memory backends.
Distinct from :class:ScopedIdempotencyMigrationPendingError, which is
the rolling-deploy window's cross-scope reuse signal.
idempotency_key / idempotency_scope carry the offending pair,
resolved exactly on both backends by one shared rule
(first_duplicate_idempotency_pair): the first item in batch order
whose pair repeats an earlier item or is already stored. The PG path
resolves the stored half with a targeted post-abort lookup inside the
caller's transaction scope, never by parsing the violation's detail
text, which renders values raw and unquoted (ambiguous under
positional reading for comma-bearing scopes, unusable when localized
or truncated). Both fields are None only when the conflicting
row could not be resolved at all, a committed-and-instantly-deleted
racer, where the detail-text match is the last word and still never
guesses. detail carries the postgres detail verbatim when
present.
Resolution: pre-deduplicate the items, or use
:meth:~taskq.client.JobsClient.enqueue_batch, which dedupes and
returns the existing rows.
Source code in src/taskq/exceptions.py
SubEnqueueError ¶
Bases: TaskQError
Raised by flush_buffer() when one or more buffered sub-job enqueues fail after parent commit.
failed_items carries each failed EnqueueArgs and the exception
that caused the enqueue to fail. The parent job has already been
marked succeeded, this exception signals that child jobs were lost.
Source code in src/taskq/exceptions.py
BatchAbortedError ¶
Bases: TaskQError
A batch was aborted because consecutive failures exceeded the threshold.
Running jobs are not cancelled by the abort, only pending and scheduled jobs are cancelled. Running jobs continue to completion. This matches the post-terminal-write hook design: the hook runs after the terminal write, so a job that was dispatched before the abort triggered will run to completion.
Source code in src/taskq/exceptions.py
EmptyBatchError ¶
Bases: TaskQError
A batch has fewer jobs than the expected minimum, or is unknown.
This can happen when jobs were pruned before wait_for_batch ran,
when expected_size was set but jobs were never created, or when
wait_for_batch is given a batch_id this client never
enqueued (no jobs and no batches row: the expected=None arm,
whose message names the truth instead of a fabricated minimum).
Pass on_empty="ok" to wait_for_batch to suppress the
no-batch-row variant of this error.
Source code in src/taskq/exceptions.py
BatchIdExistsError ¶
Bases: TaskQError
A caller-supplied batch_id already exists in the batches table.
Raised when :meth:~taskq.client.JobsClient.enqueue_batch or
:meth:~taskq.client.JobsClient.enqueue_batch_streaming is called with
an explicit batch_id that collides with an existing batch row, and
when a member append (the chunked arms, the sub-job enqueuer's
fallback) targets a batch row that already reached a terminal status:
a terminal batch must not gain a member, every counter write guards
status = 'active' so its failure policy would be dead and the
stale-batch sweep (active rows only) could never reconcile. An ACTIVE
row keeps accepting appends (resumption). Appending is a backend-level
rule, so both backends refuse it the same way.
The original asyncpg.UniqueViolationError (PG) is chained via
__cause__ when available.
The two raising situations are distinguishable on the instance:
reason is "exists" for a create-collision (the batch_id names a
row this call did not mean to append to) and "terminal" for a
member append against a row that already finished. The remedy is the
same shape (use a batch_id that names the batch you mean), but a caller
driving resumption-by-append reads reason to tell "stop appending,
this batch is finished" from "you picked an id that is taken".
Source code in src/taskq/exceptions.py
UnknownQueueError ¶
UnknownQueueError(
queues: Sequence[str],
known_queues: Sequence[str],
*,
actor: str | None = None,
source: Literal["submit", "worker_boot"] = "submit",
snapshot_is_ttl_bounded: bool = False,
env_queues: Sequence[str] | None = None,
)
Bases: TaskQError
Raised when strict queue-name validation refuses a queue name.
With TASKQ_QUEUES_STRICT=true the enqueue-time unserved-queue
check (ActorCapacityCache.maybe_warn_unserved_queue — the same
zero-I/O TTL-snapshot verdict every enqueue arm already consults)
becomes HARD: a queue no registered actor's assignment routes to
raises here, before any backend write, instead of storing an
orphaned row on a queue no worker claims. Silent data non-delivery
is the worst failure class a queueing library has, and a
one-character typo is enough to cause it.
Two raising sites, one class, both naming the offending queue and the set it was judged against (the unserved-queue note's quality bar: the fix is obvious from the message alone):
- At submit (
source="submit"): the judged sets are TWO — the registered queue assignments (actor_configrows, fleet-wide DB truth the client can read without actor registration — the split-deployment constraint) and, when the process's settings carry one, its own declared set (TASKQ_QUEUES). A refusal requires the queue to miss both: an env-declared but snapshot-absent queue is a new queue mid-deploy and is allowed through the registration lag; an EMPTY snapshot (no worker ever started, the first deploy) carries zero evidence of stranding and never refuses; an UNAVAILABLE snapshot (read failure, capability-less backend) never refuses — a database blip or migration window must not become a submit outage, and the check re-arms on the next refresh. Every ambiguous state resolves to ALLOW + the advisory note; over-rejection is strictly worse than over-permission. The snapshot is TTL-bounded, so a queue registered seconds ago may not be in it yet; when the process declares no queue set the snapshot is the only source and the message says so — deploy workers before clients for new queues, that deploy order is the operator's protection for the first submits. Nothing was stored when this raises — the refusal is at the door. - At worker boot (
source="worker_boot"): the judged set is the worker's own configured consume set (TASKQ_QUEUES), and the coverage is the fleet's stored assignments read back aftersync_actor_config. A configured queue nothing routes to is config drift between deploy and code; the worker refuses to boot. Deliberately worker-only: actors register only in the worker process, so a client-side boot check of this shape would brick split deployments (web submits, worker consumes).
Source code in src/taskq/exceptions.py
1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 | |
env_queues
instance-attribute
¶
SignalTimeoutError ¶
Bases: TaskQError
A held signal's deadline passed under on_timeout="fail" — the
dedicated typed failure (the glossary shape: the
Signal prefix, the :class:TaskQError base; not
TaskQSignalTimeout, which would break the exceptions glossary's
one-prefix rule). The named state's ledger record: the hold row's
abandoned + the node's typed failure — never a silent orphan.
The workflow machinery never raises this exception automatically: expiry
is returned as an Expired value in the wait union, and bodies that
want a failure raise SignalTimeoutError explicitly when matching
Expired.
See also :class:SignalAbandonedError (the operator-abandon shape —
the same defined state, a different door).
SignalAbandonedError ¶
Bases: TaskQError
A held signal was abandoned by the operator's door (the same
defined state as :class:SignalTimeoutError — a named ledger
record, never a silent orphan): the operator abandon
(HitlClient.abandon / taskq flows abandon <hold_id> / the
admin run page's Abandon) wrote abandoned_by='operator' on the
row's payload and resumed the node. The distinction is the door
(the timeout sweep vs the operator's action), not the state.
the machinery never raises this (the same value-not-machinery law
as :class:SignalTimeoutError): the wait site returns the closed
union's Expired member with abandoned_by='operator' and the
body matches the fail-close arm; a body that wants the failure
raises this exception itself off the member (the escalation
ladder's own use — the raised error is a body exception exactly
like any other). A timer hold never reaches this door: the
__timer__ prefix's abandon is refused — the clock is its only
resolver.
SignalPayloadError ¶
Bases: TaskQError
A delivered payload validated against NONE of the wait's declared
models (the typed door's runtime boundary — the unknown-field refusal):
the refusal happens before the deliver CAS consumes the hold, so the
hold SURVIVES and the operator sees WHY. Never a silent drop into the
body's re-validation (that shape consumes the payload, then
the body's laddering ValidationError kills the flow).
See also :class:SignalPayloadAmbiguousError — the same refusal when
the payload fits MORE than one declared model and the gate declared
no discriminator.
SignalPayloadAmbiguousError ¶
Bases: SignalPayloadError
A delivered payload fit MORE than one of the wait's declared
models and the gate declared no discriminator: which member the body
receives would be decided by DECLARATION ORDER (the rejected
first-fit mis-narrowing — the union's own narrow rule), so the delivery is refused
instead. The gate's escape is the explicit discriminator= on the
wait site; the operator's escape is a payload whose shape names one
model unambiguously.
ReservedTimerNamespaceError ¶
Bases: TaskQError
E17 — the RESERVED TIMER NAMESPACE (the timer hardening's fix
1): a HAND-facing mint named its hold inside the durable timer's
reserved __timer__ signal prefix — a payload model named
__timer__Approval, or a wait_until key beginning with the
prefix. The minted row is one every reader mis-identifies as the
CLOCK's: invisible to HitlClient.list(), unanswerable (the
boundary refuses every hand delivery as a timer forgery), never
fail-closing (the expiry arm never abandons the prefix), and fired
at the deadline into a SignalPayloadError death (the wake cannot
fit a human payload model). The refusal is at the MINT — no row is
written; the fix is named in the message (rename the payload model /
choose a key outside the reserved namespace).
SystemExitCarrierError ¶
Bases: Exception
Typed carrier for a SystemExit crossing an asyncio task boundary.
CPython's Task.__step re-raises (KeyboardInterrupt, SystemExit)
bare past the loop's exception handler, crashing the event loop before
awaiting handlers can observe the failure. Wrapping SystemExit in an
ordinary Exception lets it cross task/executor boundaries cleanly;
the owning handler unwraps it via :func:unwrap_system_exit so logs and
persisted failure records name the original SystemExit.
Source code in src/taskq/exceptions.py
__getattr__ ¶
Lazy runtime re-export of validate_actor_payload.
The implementation lives in :mod:taskq._validation (the sanitized
variant: include_url=False, include_input=False and no raw-payload
embedding). It cannot be re-exported at module level here because
taskq._validation imports PayloadValidationError from this
module, a module-level from taskq._validation import ... would be
circular and blow up whenever taskq._validation is imported first.
PEP 562 module __getattr__ resolves the name only when requested,
by which time both modules are fully initialized.
Source code in src/taskq/exceptions.py
tag_settlement_stage ¶
Name the settlement step exc escaped from (see the attribute above).
settlement_stage_of ¶
The settlement step exc was tagged with, or None when untagged.
Lets a caller that only holds the exception (a shutdown arm logging a failed operator-cancel write) report the stage without importing the engine module that performed it.
Source code in src/taskq/exceptions.py
unwrap_system_exit ¶
Return the wrapped SystemExit for a :class:SystemExitCarrierError,
or exc unchanged otherwise.