Upgrading¶
TaskQ's schema migrations are forward-only by design. There is no down
migration mechanism and none is planned, so this section explains why, and
what to do if you need to undo a change.
Forward-only migration policy¶
The migration runner (taskq.migrate) discovers *.sql files bundled under
taskq.migrations in lexicographic order ({ver}_{nn}_{pre|post}_{description}.sql),
applies any not already recorded in {schema}.schema_migrations, and records
a SHA-256 checksum of the rendered SQL after each successful apply.
There is no down operation. To revert a migration, restore the database
from a backup taken before it was applied.
This is a deliberate tradeoff, not a missing feature:
- Down migrations are rarely exercised in practice and rot quietly until the one time they're needed, at which point they often don't work.
- A schema rollback that isn't paired with a data rollback (e.g., a dropped column that already lost data) is not actually safe to run automatically.
- Point-in-time recovery / backup restore is the operation you actually want
for "undo a bad deploy" in a durable job queue, since job state itself
needs to roll back together with the schema (note: a schema migrated onto
PostgreSQL 18.6+ using
uuidv7()defaults and PG 18 storage options can only restore into PostgreSQL 18+, never pre-18).
Before upgrading TaskQ¶
- Take a backup. Since there is no automated rollback, a recent backup (or PITR window) is your only revert path.
- Check the Changelog for the target version: TaskQ is
pre-1.0 (see the Stability note in the README),
so breaking changes, including schema changes, may land in minor version
bumps (
0.x.0), not only majors. - Review pending migrations before applying them:
This lists every discovered migration and whether it has already been applied, without changing anything.
- Apply migrations explicitly, from a pre-deploy job or init container, before any worker starts — in the phased order the rolling-deploy law defines (Deployment: the pre phase while the workers roll, the post phase once by hand after the last worker is up):
taskq migrate up --phase pre # the pre-deploy job, before the roll
# ... roll the workers ...
taskq migrate up --phase post # once, by hand, after the roll completes
A bare taskq migrate up applies BOTH phases at once: the post phase
lands immediately, and an old worker still running at that moment
cannot write the workflow rows the new schema requires. Workers never
self-migrate. TASKQ_MIGRATE_ON_START=true is honoured only
by taskq ui serve; a worker warns and ignores it, and refuses to boot
while a pre-phase migration is pending, so relying on it there produces a
crash-loop rather than a migrated schema. N replicas racing to migrate is
the concurrent-migration hazard migrations exist to avoid.
The command is idempotent: migrations already recorded in
{schema}.schema_migrations are skipped. See cli.md
for the full option reference (--phase, --target, --max-steps,
--ddl-lock-timeout).
TASKQ_MIGRATE_ON_START=true is not a substitute here: it is honoured
only by taskq ui serve, which runs as a single process. The worker
ignores it (and warns when it is set): N worker replicas racing to migrate
is the hazard the migration advisory lock exists to prevent, and a worker
started against a schema still missing a pre-phase migration refuses to
boot rather than running against a schema behind its code.
PostgreSQL 18.6 is the floor¶
TaskQ refuses to run against a PostgreSQL older than 18.6. That is the
cloud major - 1 support policy's
floor, and it is enforced at startup, not documented as advice:
taskq migrate, worker startup and TaskQ.open() all probe the server and
raise UnsupportedPostgresVersionError — naming the detected version, the
floor, and the upgrade remedy — before any migration or queue statement runs.
On a direct connection the probe reads the startup metadata and costs no
statement; behind a declared transaction-mode pooler, whose startup packet
cannot be trusted, it costs one current_setting('server_version_num') query.
The patch level, not just the major, matters. TaskQ's cancel and
terminal paths read pre-update values from the row a write actually locked
(RETURNING OLD), and PostgreSQL only reports that version correctly under
BEFORE UPDATE triggers — which jobs carries — from 18.6 on. Earlier
18.x releases would report a stale row version, so they are refused rather
than supported with quietly wrong audit records.
Upgrade path: a PG 18 minor upgrade is a drop-in binary replacement, so a
server on 18.0–18.5 needs the patch (managed clouds schedule it for you), not
a migration. A server on PG 17 or older needs a major upgrade first. An
existing TaskQ schema and its jobs survive that database upgrade; once the
server is on 18.6 or newer, run taskq migrate up to apply this version's
pending migrations before starting the new workers.
Non-transactional migrations¶
By default every migration file runs inside its own transaction, so a failure
rolls the whole file back. PostgreSQL forbids some statements inside a
transaction block, notably CREATE INDEX CONCURRENTLY and
DROP INDEX CONCURRENTLY, the only forms that build or drop an index without
blocking writes on the table. On hot tables (jobs, job_events) a plain
CREATE INDEX takes a SHARE lock that blocks INSERT/UPDATE/DELETE
for the duration of a full-table scan and stalls the worker fleet, so index
migrations on those tables should use the concurrent forms.
A migration opts out of the transaction wrapper with a header directive in its
leading comment block (-- line comments only, before the first SQL token):
-- taskq:no-transaction
-- NOT redundant with IF NOT EXISTS below: an interrupted CREATE INDEX
-- CONCURRENTLY leaves an INVALID index that IF NOT EXISTS alone would
-- silently skip rebuilding, so drop the debris first.
DROP INDEX CONCURRENTLY IF EXISTS "{schema}".jobs_queue_idx;
CREATE INDEX CONCURRENTLY IF NOT EXISTS jobs_queue_idx ON "{schema}".jobs (queue);
The runner then executes the file statement by statement, each in its own
implicit transaction (the same semantics as Alembic's autocommit_block or
Rails' disable_ddl_transaction!). This changes the failure contract, so
three rules apply:
- The migration must be idempotent and re-runnable. Nothing rolls back: if
the third statement fails, the first two stay applied. The ledger records
the migration only after every statement succeeds, so the next
migrate upre-executes the whole file: every statement must tolerate being re-run (IF NOT EXISTS, guarded inserts, etc.). - An interrupted
CREATE INDEX CONCURRENTLYleaves anINVALIDindex behind. The standard remedy is drop-and-rebuild, written into the migration itself as shown above: theDROP INDEX CONCURRENTLY IF EXISTSline removes debris from an interrupted attempt before rebuilding. A plainCREATE INDEX CONCURRENTLY IF NOT EXISTSalone would silently skip the rebuild while the invalid index keeps its name. You never have to find these by hand: when a non-transactional migration fails,taskq migrate uplists any INVALID indexes in its failure report. - No transaction-control statements.
BEGIN/COMMIT/ROLLBACK(and aliases) are rejected before anything executes: they would silently re-open a transaction, defeating the directive. The statement splitter assumes the server defaultstandard_conforming_strings=on.
Operators can see the distinction two ways: taskq migrate status annotates
non-transactional migrations with (no transaction), and the
{schema}.schema_migrations ledger records how each migration ran in its
use_transaction column (false = ran outside a transaction). The runner
adds that column when recording the next migration, so deployments upgraded
from older TaskQ versions need no manual step; rows applied before the column
existed read true.
Workflow run-scoped strict reservations (workflow schema 3)¶
run_reservations= — a workflow's run-level buckets — ships with no
migration: the seats reuse reservation_slots as nullable-lease rows, and
the run's own rows only gain a new required_worker_schema floor. What changes
is the WORKER CONTRACT: a worker that predates this release ignores
root.metadata.run_reservations entirely, so a guarded run it claimed would
execute with no exclusion at all — silently.
Therefore the floor is physical and the rollout is worker first:
- Upgrade every worker that serves a guarded workflow's queues. A worker's
boot stamps its capability into its own
workersrow (metadata.workflow_execution_schema); the physical entry-to-running claim trigger refuses a workflow row whoserequired_worker_schemais above the claimant's. A run that declaresrun_reservationsstampsrequired_worker_schema = 3on its root and every node row — and a child flow spawned under a guarded ancestor inherits the floor through the parent pointer (never a copy of the ancestor's bucket list). The run stamps that reservation lineage in its own root metadata (metadata.wf_run_reservation_lineage) as well, so a descendant's spawn still reads the floor after retention archives the ancestor that declared the reservation. - Wait until no pre-upgrade worker is claiming those queues — read each
worker row's
metadata.workflow_execution_schemafrom the database. Until then, guarded runs are simply not claimable: their rows staypending(the stranded-work detectors surface them), which is the fail-closed outcome, not a fault. - Only then create guarded runs (deploy the authors, or the ingestion
code that calls
create_flowwith the guarded workflows).
The reverse order is the failure this floor exists to prevent: guarded runs
created while an old worker still claims the queue are refused by the trigger,
so they wait — they are never executed unprotected. Do not "fix" a waiting run
by manufacturing worker metadata or by relaxing required_worker_schema:
either hand-edits the fence that keeps an old worker out.
Two behaviour notes for the same upgrade:
- The in-process driver refuses guarded runs.
FlowRunner.drive(execute=True)and the packagedrun(..., execute=True)raiseWorkflowWorkerCapabilityErrorfor a run that declaresrun_reservations: the direct door cannot re-run a crashed run's claim and cannot honour the fleet's admission gate. Drive such a run withexecute=Falsebehind real workers. Ordinary (unguarded) runs keep driving directly, unchanged. - A nested spawn can be refused at spawn time.
ctx.spawn_flowraisesRunReservationAncestorConflictErrorwhen a child would acquire a bucket a live ancestor already holds; the same class fails a child NODE at run time when its bucket only resolves while the ancestor holds it. Both are the typed refusal of a structural self-deadlock — check the workflow's declarations rather than retrying the run.
Workflow terminal effects / run incarnation (01.00.38 + 01.00.41)¶
Apply all three PRE files, in this order, before deploying authors/workers that
declare RetrySpec.on_exhaustion:
01.00.38_01_pre_wf_worker_capability.sql— the nullablejobs/jobs_archiverequired_worker_schemacolumn and the physical entry-to-running claim trigger. Every effect-producing root's create transaction names this column, so it must exist before any such run is created.01.00.41_01_pre_wf_run_epoch.sql— nullable legacy-compatible rootrun_epochstorage (new roots begin at 1; only explicit locked reopen advances it).01.00.41_02_pre_wf_terminal_effect_intents.sql— the stable physical intent arbiter.
Existing rows retain NULL epochs/requirements and existing outbox rows remain
unchanged. (Applying the two existing 01.00.41 files (01.00.41_01 and
01.00.41_02) without 01.00.38_01 fails at
FlowRunner.create_flow() with
column "required_worker_schema" of relation "jobs" does not exist — the
create path stamps the requirement on the root and its rows.)
Guarded effect-producing workflows stamp the actual worker schema requirement and
refuse direct in-process execution. Upgrade all fleet workers serving their
queues before creating such runs; an insufficient/missing actual boot capability
(the worker's boot-stamped workflow_execution_schema metadata) fails at the
physical entry-to-running trigger before body execution. Do not manufacture
worker metadata or use queue membership as an upgrade assertion.
Slot-free emit backpressure, durable intent, and per-claim ledger (01.00.42_01)¶
Apply the one PRE file 01.00.42_01_pre_wf_step_ledger_claim_epoch.sql after the 01.00.38 + existing 01.00.41 files and before corrected bounded-emit/executor binaries; it installs the derived-capacity intent/rotation records, exact-park guard/indexes, and claim-epoch arbiter in one migration transaction.
Storage cost (§10.7): the intent record is one wf_emit_capacity row
per bounded run (four typed columns plus its CHECK constraints; the
pending-generation partial index covers only rows with a pending wake) and
one singleton rotation row total. The record's retention lifetime is the
run's own: the leader's retention pass (the same statement that deletes a
retained run's ledger rows) deletes the run's record — and only when the
run's root is terminal-aged AND no live (pending/scheduled/running) node
of the run still exists; retention cannot remove a record while a live
node references the run.
Operational facts (§10.7): the engine's hard ceilings are fixed and
not caller-tunable: a flow drain commits at most 200 winning
promotions/notifications per transaction (a full chunk continues into a
fresh one), and the global pending-intent selection reads at most 100
distinct flows per pass under the persistent rotation cursor. The normal
event wake target is < 1 s from the committing terminal's database
commit to the woken source's next claim, on a competent fleet with a
supported session-LISTEN configuration; crash/notification-loss
recovery is bounded by the leader lease, the maintenance interval, and
ordinary dispatch (never a time guarantee on a stalled database). A
parked waiter can exist only per declared chain source (parked <= S —
an exact park is a state of one durable source row), so the candidate
fit scan is Theta(parked) <= Theta(S). The derived-capacity observation
is hoisted (Theta(live + parked), terminal history never scanned); the
per-terminal exact-marker probe is one indexed zero-row read on
non-crossing terminals. The proven non-drainage refusal (a committed terminal root behind an
exhausted child failure, with an exact parked source still holding
un-emitted work — including the first page when no cursor has committed;
the absent key means zero pages have committed, not that the park is
empty) is exported only as the durable
error_class='WorkflowNotDrainingError' string and the
taskq.workflows.wf_not_draining metric counter — never as an
importable class.
The folded file's lock profile (one migration transaction; the cross-table
order is wf_step_ledger BEFORE jobs):
- On
wf_step_ledger:ADD COLUMN claim_epochtakesACCESS EXCLUSIVE(metadata-only), the arbiter rebuild'sDROP INDEXhalf takesACCESS EXCLUSIVE(subsumed by the already-held lock), the non-CONCURRENT replacementCREATE UNIQUE INDEXtakesSHARE(the populated-ledger stop-accepting-work window), andCOMMENT ON COLUMNtakesSHARE UPDATE EXCLUSIVE. - On
jobs: the non-CONCURRENTjobs_wf_emit_park_idxbuild takesSHARE(writes block, reads proceed), and the guard-trigger install — last — takesSHARE ROW EXCLUSIVE(writes block, reads proceed; its grant is immediate against writers because every conflicting mode also conflicts with the already-heldSHARE, but it can queue behind a concurrent reader holdingSHAREonjobs— this migration's ownSHAREis compatible with that reader while the trigger'sSHARE ROW EXCLUSIVEconflicts with it, measured on PostgreSQL 18.6). The jobs-side apply outage is ONE write-block window from SHARE acquisition through COMMIT (its acquisition wait can be extended by a concurrentSHAREreader); there is no second read-blocking window and ordinary SELECTs proceed throughout.
Drain the producer first (stop new bounded-flow production/emission), then
the full writer-role drain: old maintenance leaders, direct producers and
runners, executors, and cancel-serving binaries; wait for every in-flight
jobs/wf_step_ledger application transaction to finish and close or prove
idle the old writer pools. A residual opposite-order writer can deadlock
against the file's wf_step_ledger → jobs order, and PostgreSQL's victim
choice is nondeterministic (SQLSTATE 40P01): either the migration aborts
(rollback is fail-closed, no migration record, re-apply after completing the
drain — never reorder locks or blindly retry) or the residual writer aborts
(the application must roll back and retry its whole transaction under its
own retry policy; the migration commits the complete object set, no re-apply
owed). An operator lock_timeout bound reduces the exposure but cannot
eliminate it.
Widened record identity — map_index bigint on all five carriers (01.00.42_02)¶
01.00.42_02_post_wf_map_index_bigint.sql is a POST file. It widens
map_index from smallint to bigint on all five identity carriers
(jobs, jobs_archive, wf_step_ledger, wf_outbox, wf_signals) and
recreates the two identity arbiters in the same transaction:
wf_step_ledger_claim_uniq
((flow_id, step_key, COALESCE(map_index, -1), attempt, claim_epoch)) and
wf_signals_hold_identity_uniq
((workflow_id, node_key, signal_name, COALESCE(map_index, -1), hold_epoch)
WHERE resolved_at IS NULL).
Apply it only after every process that can emit, finalize, directly drive,
or lead workflow maintenance runs the release with the bigint SQL binds and
the schema-derived identity gate. An OLD binary's explicit smallint binds
cannot finalize, memoize, count, fence, collect, or drain a high identity,
and an old elected leader's smallint[] outbox bind rejects the whole drain
batch. Do not claim old workers are safe above 32767. Until this POST
applies, the new gate still refuses identities above 32767 on the old
schema, so a mixed old/new wave is supported in that window only.
Lock profile and outage. Each ALTER COLUMN ... TYPE bigint takes
ACCESS EXCLUSIVE and rewrites its table, rebuilding every index on it
(including unrelated indexes). The one migration transaction retains every
acquired lock until COMMIT, so all five tables block reads and writes for
their rewrite and every later statement in the file. ddl_lock_timeout
bounds lock acquisition only. Plan an operator-approved maintenance window
sized from jobs, jobs_archive and wf_step_ledger. Existing smallint
values and NULLs are already in-domain and need no backfill; nullable stays
nullable. There is no down migration — to revert, restore from backup or fix
forward.
Diagnostics you may see. On a pre-POST schema a candidate identity above
32767 raises MapIndexExhaustedError (deterministic, named). A candidate
above 32767 against a schema whose five carriers are mixed, missing,
NOT NULL, or of an unsupported type raises MapIndexSchemaError before any
row is written — a deployment error, not permission. An ordinary unbounded
page at or below 32767 takes the no-catalog-read path, so it writes rather than
detecting a broken carrier shape; inspect the five columns yourself before
relying on low-identity writes against a schema you have not verified.
Unbounded is the EXPLICIT opt-out (max_in_flight=None): bounded emit is the
default, and both of its paths — unreserved admission and reserved replay —
run the capability preflight, which re-reads the five carriers on every
call, so a bounded low page refuses the same broken shape with
WorkflowWorkerCapabilityError before any write. A hand-run ALTER
that widened the column without recreating
the claim arbiter leaves the stored int4 coercion in place; the ledger's
ON CONFLICT then fails with PostgreSQL 42P10, and the bounded-emit
preflight refuses with a remedy naming this file.
Chain-barrier indexes build under a write-blocking lock (01.00.45)¶
01.00.45_01 through 01.00.45_04 (pre) build four partial indexes on
jobs: jobs_wf_chain_barrier_idx, jobs_wf_chain_barrier_walk_idx,
jobs_wf_active_step_idx and jobs_wf_static_step_idx. Each file holds
nothing but its own build, so exactly one CREATE INDEX runs per migration
transaction and holds a SHARE lock on jobs — blocking every
INSERT/UPDATE/DELETE (the whole worker fleet) for that one table scan,
never for the sum of four.
On a large jobs table, pre-build them concurrently so the migration finds
them already present:
CREATE INDEX CONCURRENTLY IF NOT EXISTS jobs_wf_chain_barrier_idx
ON "{schema}".jobs (((metadata->>'flow_id')::uuid), id)
WHERE status = 'pending'
AND deps_pending > 0
AND metadata @> '{"blocking_reason": "chain_barrier"}'::jsonb;
CREATE INDEX CONCURRENTLY IF NOT EXISTS jobs_wf_chain_barrier_walk_idx
ON "{schema}".jobs (id) INCLUDE (created_at)
WHERE status = 'pending'
AND deps_pending > 0
AND metadata @> '{"blocking_reason": "chain_barrier"}'::jsonb;
CREATE INDEX CONCURRENTLY IF NOT EXISTS jobs_wf_active_step_idx
ON "{schema}".jobs (((metadata->>'flow_id')::uuid), step_key, id)
WHERE status IN ('pending', 'scheduled', 'running')
AND step_key IS NOT NULL
AND metadata ? 'flow_id';
CREATE INDEX CONCURRENTLY IF NOT EXISTS jobs_wf_static_step_idx
ON "{schema}".jobs (((metadata->>'flow_id')::uuid), step_key, id)
WHERE map_index IS NULL
AND step_key IS NOT NULL
AND metadata ? 'flow_id';
CREATE INDEX IF NOT EXISTS matches by NAME only. A pre-built index whose
definition differs (a different expression, a different partial predicate) is
kept silently, and the migration then believes it has built the index the
engine needs. Compare the definitions before running
taskq migrate up --phase pre, using the migration files as the source of
truth:
SELECT c.relname, pg_get_indexdef(i.indexrelid) AS definition,
i.indisvalid
FROM pg_index i
JOIN pg_class c ON c.oid = i.indexrelid
WHERE c.relname IN (
'jobs_wf_chain_barrier_idx',
'jobs_wf_chain_barrier_walk_idx',
'jobs_wf_active_step_idx',
'jobs_wf_static_step_idx'
);
An interrupted CREATE INDEX CONCURRENTLY also leaves an INVALID index with
the right name, which IF NOT EXISTS accepts the same way. Build any missing
index, and drop (DROP INDEX CONCURRENTLY) and rebuild any indisvalid = false
or definitionally different index before the migration runs. taskq migrate up
reports INVALID indexes in its failure report only for a failed
non-transactional migration — a file that failed inside its own transaction
rolls back entirely and leaves nothing to report — so this inventory read, not
the migrate output, is what proves the estate is ready on a fleet that
pre-built its indexes by hand.
Workflow indexes build under a write-blocking lock (01.00.46)¶
01.00.46_01 through 01.00.46_04 (pre) build four partial indexes on
jobs, one per file, each scoped to the workflow root rows only
(step_key = '__flow__'), so vanilla jobs and workflow step/map/chain nodes
carry zero entries and zero write amplification:
| file | index | what it serves |
|---|---|---|
01.00.46_01_pre_wf_active_roots_scope_index.sql |
jobs_wf_active_roots_scope_idx on (idempotency_scope) WHERE the root is active |
the max_active_runs admission count, taken under the workflow's advisory lock on the producer's hot path |
01.00.46_02_pre_wf_root_identity_index.sql |
jobs_wf_root_identity_idx on (idempotency_scope, identity_key, created_at DESC, id) INCLUDE (status, required_worker_schema) |
the unique_for window preflight (the window becomes an index range condition) |
01.00.46_03_pre_wf_on_terminal_pending_index.sql |
jobs_wf_on_terminal_pending_idx on (finished_at, id) WHERE the root is terminal and its hook is unsettled |
the on_terminal settlement backstop and the retention hold-back |
01.00.46_04_pre_wf_on_terminal_pending_status_index.sql |
jobs_wf_on_terminal_pending_status_idx on (status, finished_at, id) over that same unsettled population |
the per-status slices of the hook-backlog gauges every worker samples |
The four are pure additions over existing columns: no ALTER TABLE, no row
rewrite, no data backfill. Each file holds nothing but its own build, so
exactly one CREATE INDEX runs per migration transaction and holds a SHARE
lock on jobs — blocking every INSERT/UPDATE/DELETE (the whole worker
fleet) for that one build, never for the sum of four.
On a large jobs table, pre-build them concurrently so the migration finds
them already present and each file becomes a no-op:
CREATE INDEX CONCURRENTLY IF NOT EXISTS jobs_wf_active_roots_scope_idx
ON "{schema}".jobs (idempotency_scope)
WHERE step_key = '__flow__'
AND status IN ('pending', 'scheduled', 'running');
CREATE INDEX CONCURRENTLY IF NOT EXISTS jobs_wf_root_identity_idx
ON "{schema}".jobs (idempotency_scope, identity_key, created_at DESC, id)
INCLUDE (status, required_worker_schema)
WHERE step_key = '__flow__'
AND identity_key IS NOT NULL;
CREATE INDEX CONCURRENTLY IF NOT EXISTS jobs_wf_on_terminal_pending_idx
ON "{schema}".jobs (finished_at, id)
WHERE step_key = '__flow__'
AND status IN ('succeeded', 'failed', 'cancelled', 'crashed', 'abandoned')
AND metadata @> '{"wf_on_terminal_pending":true}'::jsonb;
CREATE INDEX CONCURRENTLY IF NOT EXISTS jobs_wf_on_terminal_pending_status_idx
ON "{schema}".jobs (status, finished_at, id)
WHERE step_key = '__flow__'
AND status IN ('succeeded', 'failed', 'cancelled', 'crashed', 'abandoned')
AND metadata @> '{"wf_on_terminal_pending":true}'::jsonb;
CREATE INDEX IF NOT EXISTS matches by NAME only, so an interrupted
CONCURRENTLY build leaves an INVALID index that the migration accepts
silently. Check validity and definition before applying, exactly as the
01.00.45 section above describes:
SELECT c.relname, pg_get_indexdef(i.indexrelid) AS definition, i.indisvalid
FROM pg_index i
JOIN pg_class c ON c.oid = i.indexrelid
WHERE c.relname IN (
'jobs_wf_active_roots_scope_idx',
'jobs_wf_root_identity_idx',
'jobs_wf_on_terminal_pending_idx',
'jobs_wf_on_terminal_pending_status_idx'
);
Drop (DROP INDEX CONCURRENTLY) and rebuild any missing, INVALID, or
definitionally different index before the migration runs.
Insert wakes fire only for immediately claimable rows (01.00.47)¶
01.00.47_01_pre_notify_job_insert_filter.sql replaces
notify_job_insert() so an INSERT into jobs notifies the schema wake
channel only when the new row is claimable right now: status = 'pending',
deps_pending = 0, and step_key IS DISTINCT FROM '__flow__'. Before it,
every pending insert woke its queue — including dependency-blocked rows and
the workflow run's __flow__ root, which no worker can claim. Creating a
workflow graph therefore woke every worker serving the queues of its blocked
steps and roots, and each wake bought a claim round that returned zero rows.
The channel and payload are unchanged (wake_channel(schema) and the row's
queue). No claimability change is lost: the trigger is AFTER INSERT and
never observed the UPDATEs that clear deps_pending, so it was never the
wake source for a row that becomes claimable later. Rows that become
claimable by UPDATE keep the wake sources they had before: scheduled
promotion, lock reclaim, vanilla operator retry, and chain-barrier release
notify their own queues, while workflow join decrements and workflow re-arms
were already left to the owning worker's slot-freed loop and every worker's
fallback poll. None of them ever rode this insert trigger.
The migration is a lock-free CREATE OR REPLACE FUNCTION (a catalog-only
update on pg_proc): it takes no lock on jobs, so the fleet keeps inserting
while it applies. The trigger, its WHEN clause, and the invoker-rights
contract are untouched. Workers refuse to boot with a pending pre migration,
so no new worker runs against the old function.
Run-level terminal hook (workflow schema 4)¶
on_terminal= — a workflow's run-level terminal hook — requires no table
alteration: the hook reuses wf_outbox, the run-epoch column and the
existing terminal-effect arbiter, and the release only adds the four
01.00.46 indexes above. What changes is the WORKER AND LEADER CONTRACT:
- a run that declares a hook stamps
required_worker_schema = 4on its root and graph rows, and the physical entry-to-running claim trigger refuses those graph rows to any worker whose own boot capability is below 4 (a schema-3 worker — therun_reservationsfloor — cannot claim them); - the retention hold-back that protects an unsettled root, and the isolated
wf_terminal_hook_settleleader sweep that recovers it, only exist in a leader running this release or later.
Therefore the rollout is two-stage, fleet first. Apply the 01.00.46 pre
migrations before either stage. They are additive, but each ordinary build
blocks writes on jobs; on a large or live table, use the concurrent pre-build
path above rather than treating the migration as non-blocking.
- Deploy schema-4-capable workers AND leaders everywhere — every process
that can claim a workflow row and every process that can be elected the
maintenance leader. The leader matters as much as the workers: it owns the
settlement backstop, the outbox drain and the retention hold-back. Confirm
each worker row's
metadata.workflow_execution_schemareads at least 4 before moving on. A mixed fleet fails closed rather than executing a hook incorrectly: old workers cannot claim hooked rows, whose node rows staypendingand are surfaced by the stranded-work detectors. That is a safety fence, not a supported steady state — hooked runs created early make no progress, and old workers can log claim failures until the fleet is uniform. - Only then enable
on_terminaldeclarations (deploy the authors, or the ingestion code that creates hooked runs).
Creating hooked runs before stage 1 completes leaves their node rows pending
behind the capability fence; an old leader also provides neither the settlement
backstop nor the retention hold-back. Bypassing the fence would let an old
worker execute the graph without ever settling the hook. Do not "fix" a waiting
hooked run by manufacturing worker metadata or by lowering
required_worker_schema — both hand-edit the fence that keeps an old worker
out. Workflows that declare only on_exhaustion keep their schema-2
floor and workflows that declare only run_reservations keep schema 3, so this
upgrade changes nothing for them.
BackendSettings.lock_lease (embedder settings stand-ins)¶
The BackendSettings protocol gained lock_lease (the claim lease the
reclaim sweep grants a caller-held page, and the one deferred lease the
sweep's deferral arm stamps). If you implement BackendSettings outside this
repository's settings classes, add the field; until you do, the backend reads
it with a fallback to DEFAULT_CLAIM_LEASE (60 s) exactly as it does for the
enqueue lock-timeout knobs, so an older stand-in keeps working and the moment
the field appears your configured value flows through.
If a migration goes wrong¶
taskq migrate up diagnoses its own failures: it tells you which migration
failed, what state the schema is in, and the one action to take. You never
need to inspect catalog state by hand.
Transactional migration (the default)¶
The whole file rolled back automatically, so the schema is exactly as it was
before the attempt. Fix the cause of the error, then re-run taskq migrate
up.
The migration gave up waiting for a table lock¶
A transactional migration's DDL (ALTER TABLE jobs, a plain CREATE INDEX)
needs a lock that any session holding even a read on the table blocks; an
actor's open transaction connection mid-job, an admin snapshot, pg_dump.
Postgres queues lock requests first-come-first-served, so once the DDL is
queued every later statement on that table (dispatch, enqueue, heartbeat)
queues behind it; left unbounded, the wait outlives the workers' heartbeat
budget and the fleet self-terminates while the migration is still waiting.
Each transactional migration therefore waits at most
DEFAULT_MIGRATION_DDL_LOCK_TIMEOUT (30 s, SET LOCAL lock_timeout inside
its own transaction) and then fails with MigrationLockTimeoutError; the
report names the migration, the bound, and this remedy. The migration rolled
back and nothing was applied: find the holder in pg_stat_activity /
pg_locks, end it or wait for it, then re-run taskq migrate up. To wait
longer, pass taskq migrate up --ddl-lock-timeout SECS, or
ddl_lock_timeout= to apply_pending / apply_pending_locked from your
own deploy tooling (0 waits indefinitely, at the cost of parking every
statement on the table behind the queued DDL). The
bound governs the wait only: a statement that already holds its lock,
such as an index build, is never interrupted by it. The runner's own upgrade
of the schema_migrations ledger (an ALTER TABLE before the first
migration of a run) waits under the same bound and reports the same error,
naming the ledger instead of a migration. -- taskq:no-transaction
migrations are not bounded: their CONCURRENTLY phases wait on heavyweight
locks by design.
Non-transactional migration (-- taskq:no-transaction)¶
Nothing rolls back: statements before the failure remain applied, and the
migration is not recorded. Re-run taskq migrate up; the migration is
idempotent, and the command's failure report lists any INVALID indexes the
interrupted attempt left behind; the drop-and-rebuild already written into
the migration cleans them up on the re-run. Only pin taskq-py back to the
previous version if the migration SQL itself is wrong and you need time to
ship a correction.
A migration applied successfully but broke older workers¶
Restoring from backup is for this scenario: the migration itself succeeded,
but not-yet-upgraded workers cannot run against the new schema. Stop the
workers pointed at the affected schema, restore the pre-migration backup,
and pin taskq-py back until every worker is upgraded.
Rolling taskq-py back with live workflows: the quarantine step¶
A code rollback (pin taskq-py back to a pre-workflows version) while
workflow rows are live has a boundary the rollback plan must name: the
v1 workers' dispatch will claim workflow rows whose (actor, queue)
collides with their own registry. The workflow actors are projected into
actor_config like any other cohort (that is the point — the estate
sees them), so a v1 worker subscribed to the same queue is a legal
dispatcher for those rows as far as its registry is concerned; its
process, however, never imported the workflow definitions, so the
claimed row cannot execute: the row parks at the snooze cadence
(actor-not-found), budget-free but unrunnable, and the run wedges for as
long as the v1 fleet keeps claiming the rows.
The operator's honest boundary: a rollback is not workflow-safe unless
the workflow queues are quarantined first. Before pinning workers
back, stop (or move) the workers that would claim the workflow cohorts —
or exclude the workflows' queues from the v1 fleet's subscription list
(TASKQ_QUEUES) — so no v1 process is ever handed a workflow row. The
rows themselves are safe to leave in place (they are ordinary jobs
rows; the upgraded fleet resumes them), but a v1 fleet that claims one
turns a live run into a wedged one.
- Stop workers pointed at the affected schema to avoid further writes.
- Restore the database from the pre-migration backup.
- Pin
taskq-pyback to the previous version until the issue is resolved, since the previous version's code may not be compatible with the new schema.
Breaking import path changes¶
taskq.worker.actor_config → taskq.actor_config¶
Released in v0.2.0-v0.2.2, moved in unreleased. This is a breaking change for anyone importing
ActorConfigfrom the old path.
The ActorConfig dataclass has moved from taskq.worker.actor_config to
the top-level taskq.actor_config module. It is a shared carrier used by
the client, CLI, and admin UI, not worker-internal.
Old (v0.2.0-v0.2.2):
New:
The old import path raises ImportError; update your imports.
taskq.worker.actor_config_ops → taskq.actor_config_ops¶
The actor_config_ops module (listing, inspecting, tuning, and
deregistering actors on a live deployment) has moved from
taskq.worker.actor_config_ops to the top-level
taskq.actor_config_ops. This module was introduced on the unreleased
branch; if you were importing it from the worker.* path during
development, update to the top-level path.
Old (unreleased branch only):
from taskq.worker.actor_config_ops import (
list_actor_configs,
get_actor_config,
set_actor_config_capacity,
deregister_actor,
)
New:
from taskq.actor_config_ops import (
list_actor_configs,
get_actor_config,
set_actor_config_capacity,
deregister_actor,
)
State-machine constants: taskq.backend.statemachine → taskq.backend¶
Unreleased. Not a breaking change: the old path still imports. This is guidance for embedders reviewing their imports against the public API surface.
TERMINAL_STATUSES (and ACTIVE_STATUSES, VALID_TRANSITIONS,
assert_valid_transition) are re-exported from the public
taskq.backend package. The defining module,
taskq.backend.statemachine, is an internal layout detail: taskq.backend
is the covered surface: tests/test_backend_init_coverage.py pins that
every taskq.backend.__all__ entry resolves and that each re-export is
identical to its submodule source, so that is the path that stays stable.
Old (internal defining module; works today, not the covered surface):
New:
The same one-line switch applies to ACTIVE_STATUSES,
VALID_TRANSITIONS, and assert_valid_transition.
TERMINAL_STATUSES and the JobStatus literal alias are additionally
re-exported from the top-level taskq package, the shortest spelling
for "is this job done" checks and JobStatus annotations:
Both paths are the same objects: tests/test_public_api_exports.py
pins that the top-level TERMINAL_STATUSES is (identical to, not
merely equal to) the taskq.backend one, so the two import paths can
never diverge.
Breaking API changes¶
skip= is refused on a fan-out source¶
Unreleased. Breaking for anyone wiring a
step(..., skip=…)as the source ofmap_source(...)orroute(...): on previous releases the declaration compiled, passedWorkflowApp.get/ boot-time registration, and ran as long as the predicate returnedFalse— and wedged the run permanently the first time it returnedTrue. Now the attachment raisesWorkflowBuildErrorat the wiring site, and a compiled graph mutated to carry the combination is refused byvalidate_compiled(E22-skip-fan-out-source) inCompiledWorkflow.validate()andFlowRunner.__init__.
The skip path finalizes the source succeeded with {"skipped": true}
and never spawns the fork, so the derived <source>.join row never
exists: a downstream consumer reserved on that join waits forever (the
root stays running with no error row anywhere) and a terminal map
(build(mapped)) reads succeeded over a result() of None. Refusing
at registration means no wedged rows are ever created.
A fleet boot does not fail on this declaration. The boot's workflow
projection catches the build/validation refusal, logs
workflow-projection-skipped at ERROR (the error class and the remedy on
the event), leaves that workflow's cohorts unprojected, and boots the rest
of the fleet. That workflow's existing rows will not claim until the
declaration is fixed — so treat the ERROR line as a deployment failure of
that workflow, not as a warning.
Migration: return [] from the source body when there is nothing to fan
out — the born-zero join fires immediately with the honest empty list —
or move skip= onto a step that does not fork. A graph mutated after the
runner's construction is caught by its fail-closed guard, which
terminal-FAILS the source on its first attempt
with SkippedFanOutSourceError on the row instead of entering the skip
path.
New workflow declarations refuse retry_kind="indefinite"¶
Unreleased. Breaking for anyone declaring an indefinite workflow actor or step: on previous releases
@app.actor(retry_kind="indefinite"),step(..., retry_kind="indefinite"),chain_fork(..., retry_kind=…)andRetrySpec(exceptions={…: "indefinite"})accepted the word; now each raisesWorkflowPolicyError(E21-execution-policy) at decoration, compile, construction or call time. Switch to"transient"with a finitemax_attemptsbudget, or to"non_retryable"(legacy spelling"permanent").
The same refusal closes the internal row-authoring doors:
ForkSpec/NodeSpec(retry_kind=…) and WorkflowDef(retry_kind=…) refuse
"indefinite" at construction, and the coroutines
emit_batch(..., retry_kind=…), drain_outbox(..., default_retry_kind=…)
and insert_flow_run(..., entry.retry_kind=…) refuse it at call time,
before any pool acquisition or write. None of those six is exported from
taskq.workflows.
A workflow row never sets schedule_to_close, so an indefinite workflow
row has no crash ceiling under the reclaim sweep: it is re-pended forever
once a worker dies mid-attempt. RetrySpec already refused the kind; the
remaining declaration and row-authoring doors did not, so a declared
indefinite step either looped or raised only later, mid-run, where a map_source
or route consumer is built. Already-persisted legacy workflow rows and
vanilla non-workflow indefinite actors keep their vocabulary in the
reclaim SQL, the deferral gate and the ladder's row reads.
A legacy indefinite workflow row can only exist on a deployment that
tracked unreleased main: no tagged release contains the workflow engine.
Such a row has no crash ceiling — the reclaim sweep re-pends it on every
dead worker, and it carries no schedule_to_close to end it — while its
body-failure ladder still stops at the max_attempts-th failure. No
engine-side action changes the kind: taskq flows retry re-arms the row's
status and never writes retry_kind, so cancelling the run is the only
remedy.
map_source no longer takes key=¶
Unreleased. Breaking for anyone passing
key=tomap_source(source, body, key=…): on previous releases every value raisedWorkflowBuildErrorat the wiring site (the map's join key is DERIVED — the engine's fork addresses the join by the source's own key +.join, so a custom join key could never be honored). The parameter is GONE: delete the argument (it was refused anyway; nothing else changes). To name the map's node, name the SOURCE (step(source_body, key=…)) — the join's key follows.
ctx.substep names are scoped to the calling node¶
Unreleased. Breaking for workflows that reuse a
ctx.substepname in more than one node, map, or loop iteration, for SQL that reads substep rows fromwf_step_ledgerby their bare name, and for any deploy that runs old and new workflow executors at the same time.
The behaviour change. A ctx.substep record now belongs to the node
execution that made it: the calling node's job row and, inside a loop
body, the loop iteration. Before, the record was keyed by the bare name
across the whole run. A second node calling ctx.substep("x") replayed
the first node's result and skipped its own side effect; a substep named
after a node key returned that node's stored envelope; two concurrent
nodes shared one row; and a loop's later iterations replayed iteration
0's value, so the loop never advanced. Now each owner runs its own fn.
Cross-node sharing was never documented. If code relied on it, move the
shared effect into one node. Two concurrent calls with one name inside
one body (for example, both in one asyncio.gather) used to run both
fns silently. Now the second raises DuplicateSubstepError (a
WorkflowRunError) before it claims anything, and the guard leaves the
first one running. Uncaught, the error fails the
node on its first attempt without spending the retry budget; in a loop
body the loop exhausts as a body failure whose message names it.
Fix the collision rather than retrying the node: the running call is not
cancelled, so an operator retry can run its effect a second time while
the first call is still inside fn.
idempotent=False calls write no row and are exempt.
The row shape. A substep row's step_key is now <job id>/<name>,
or <job id>.iter<n>/<name> in a loop body. SQL that selected substep
rows with step_key = '<name>' must select
step_key = job_id::text || '/<name>' instead, or
step_key = job_id::text || '.iter<n>/<name>' for loop iteration <n>.
To match the name in every post-upgrade shape, loops included, select
starts_with(step_key, job_id::text) AND substr(step_key, strpos(step_key, '/') + 1) = '<name>'.
Node rows keep the node key. Rows written before the upgrade keep the
bare name, so a query that must span the drain window selects the
complete parenthesized predicate
((starts_with(step_key, job_id::text) AND substr(step_key, strpos(step_key, '/') + 1) = '<name>') OR step_key = '<name>');
the post-upgrade predicate alone can never match a bare row because it
tests the row against its own job_id.
Runs in flight across the upgrade. A substep the old code recorded
under the bare name is still replayed by its own node job (the read is
owner-checked, so another node's bare row is never adopted). Inside a
loop, a bare row is replayed only by the iteration that recorded it, and
later iterations run their own fn. Each such replay logs a
workflow-substep-legacy-replay warning with the run, the job and the
bare key. Only pre-upgrade code writes bare rows, so the warnings stop
once no pre-upgrade run is in flight. One for a run started after the
upgrade means an old executor ran part of that run. Four pre-upgrade
shapes cannot be recovered as written:
- A substep named after its own node. The old code wrote it onto the node's own claim row, and such a node was already wedged. After the upgrade its reclaim re-runs the substep once.
- One row that two concurrent nodes shared. The node that owns the row replays the value it holds, and the other node's retry re-runs its side effect once.
- A bare row that one node wrote under another node's key, when that other node had not run yet. The other node's claim still lands on that row, as before the upgrade, so the run keeps the old behaviour for that one row.
- A substep in a loop body named like one of that loop's iteration keys:
<loop>.iter<n>, with<n>written the way the driver writes it (ASCII digits, no leading zero). Its bare row is spelled like the loop's own iteration rows, so it is never read as a substep record, and the iteration re-runs the substep once.
The executor cutover (required). This change has no migration, so
nothing forces the cutover. Do not run old and new workflow executors on
the same workflow queues at the same time: drain and stop the old
executors, then start the new ones. That holds in the pre-POST window of
the 01.00.42_02 map_index widening too, which otherwise allows a mixed
old/new wave. In a mixed window an old executor
that retries, reclaims or resumes a node misses the scoped record and
re-runs the side effect, and it can still adopt another node's bare row.
Both failures are silent: no error and no log line. (The
workflow-substep-legacy-replay warning fires only when a new executor
later replays a bare row; it does not see either failure.)
A new executor can re-run a side effect in that window too. If an old
executor's call is still inside fn when a new executor's later attempt
runs the same substep and fails, the read prefers that later attempt's
scoped failed row to the bare succeeded row the old call writes when
it returns. The next attempt then runs fn again, repeating an effect
the old call already completed.
The drain is the only fence. This change does not raise the workflow
execution-schema level, so the capability gate does not keep old
executors out. That gate fails a claim with WF001 when the worker is
below the run's required_worker_schema, but any such stamp also makes
the in-process FlowRunner refuse the run, and ctx.substep use is not
declared per workflow. Using the gate here would mean stamping every run
and refusing every direct taskq.workflows.run() or
FlowRunner.drive() call.
Rollback is not safe for live runs. A pre-upgrade binary runs workflow rows, and every live node it retries, reclaims or resumes re-runs, once, each substep the new code recorded. Draining first does not help runs parked on a hold or a timer. Either keep the workflow queues quarantined (no old binary subscribed to them, as in the quarantine step) until the fleet rolls forward again, or accept one re-run per recorded substep.
Queue and actor names are bounded at 255 characters¶
Unreleased. Breaking for anyone enqueueing to a queue name longer than 255 characters or declaring an actor name longer than 255 characters: on previous releases both were accepted and worked; now each raises
ValueErrorat its chokepoint (the queue at enqueue, the actor at@actor(...)registration).
jobs.queue and jobs.actor are carried in btree indexes (the
(queue, priority DESC, scheduled_at) dispatch order and the composite
dispatch probes), and a btree index item caps at 2704 bytes: an
incompressible name past that bound used to fail the jobs INSERT with
an opaque ProgramLimitExceededError ("index row size ... exceeds btree
version 4 maximum") at enqueue, far from the declaration that caused it.
Both names are now refused with a plain ValueError naming the bound and
echoing at most the first 64 characters of the rejected name.
The bound is deliberately a character count, stricter than the ~2700 bytes the storage mechanism alone forces, and that is the point: the composite dispatch index item carries the actor name and the queue name side by side, so a per-name bound has to compose with a second variable-length name in the same item. 255 characters is at most 1020 bytes at UTF-8's worst-case 4 bytes/char, and two of those plus the fixed-width tail columns fit inside one index item. A byte-measured single-name bound (~2500 bytes) would admit a queue name that only fails when paired with a legal actor name, resurfacing the same opaque storage error the cap exists to remove.
To upgrade: if you enqueue to queue names over 255 characters or
declare actors with names over 255 characters, shorten them before
deploying this release. A name past the bound now raises ValueError at
the call (enqueue or registration) instead of failing deep in the
storage engine.
/logout is now a POST with a session-bound CSRF token¶
Unreleased. Breaking for anything that ended an SSO session by fetching
GET /admin/logout.
Both SSO backends accepted GET /logout, so a forced top-level navigation
to it, a link, an image, a redirect from any page, cleared the admin
session. Logout is now POST-only and requires a CSRF token derived from the
live session cookie; GET /logout answers 405 and a POST without the token
answers 403. The admin UI's Sign out control posts the token. Switch
scripts that logged out via GET /admin/logout to POST (see
sso.md).
The same change scopes the OIDC state cookie to the callback route (matching
the SAML correlation cookie) and caches the OIDC discovery document and JWKS
per issuer with a 300 s TTL, so an unauthenticated /login flood no longer
translates into one outbound IdP fetch per request.
validate_actor_payload: actor_name= → actor=¶
Unreleased. Breaking for anyone calling
taskq.validate_actor_payloadwith the third argument passed by keyword. Passing it positionally is unaffected.
The public taskq.validate_actor_payload export previously resolved to a
duplicate implementation in taskq.exceptions that embedded the raw payload
in its exception message and attached pydantic errors with include_input.
That message is persisted to the job row's error_message and rendered in the
web admin, so attacker-controlled payload values could leak into both. The
export now resolves to the single sanitized implementation in
taskq._validation, whose third parameter is named actor.
Old:
from taskq import validate_actor_payload
model = validate_actor_payload(MyPayload, raw_payload, actor_name="send_email")
New:
from taskq import validate_actor_payload
model = validate_actor_payload(MyPayload, raw_payload, actor="send_email")
The positional form needs no change and works on both versions:
Three further changes to be aware of, none of which fail loudly:
actoris now optional (defaults toNone), so omitting it no longer raisesTypeError.- The exception message is shorter and no longer contains payload values.
It is now
Payload validation failed for actor '<name>': <model title>: the pydantic detail and theRaw payload: {...}dump are gone. Anything that parseserror_message(log pipelines, alert rules, admin tooling) must be updated. PayloadValidationError.validation_errorsentries no longer carryinputorurlkeys, because the errors are collected withinclude_url=False, include_input=False. Code readingerr["input"]will nowKeyError.
raw_payload also now accepts an existing BaseModel in addition to a
dict, a widening, so no action is required.
consume_one_job: payload validation moved before rate-limit acquisition¶
Unreleased. No action is required for workers. This affects only code that calls
taskq.worker._consumer.consume_one_jobdirectly withvalidated_payload=None.
On the normal dispatch path nothing changes: dispatch_one_job already
validates the payload and passes validated_payload, so consume_one_job
never runs its own fallback validation there.
For a direct caller, the fallback validate_actor_payload call now runs
before the rate-limit acquire block, and acquire_for_actor receives the
validated model rather than the raw row dict. Two consequences:
PayloadValidationErrornow escapes before any token is consumed. Previously the consumer acquired first, so an invalid payload burned a non-refunded rate-limit token (release_for_actorsetsrefund_on_release=False) for an actor body that could never run. If your caller was relying on acquire/release being invoked on the invalid-payload path, it no longer is.- Your caller owns the terminal write for the escaping error. This was
already true: the outer
tryhas noexceptclauses, so the error propagated from the in-tryfallback as well, but it now propagates earlier.dispatch_one_job's outer handler and the in-memory test runner both already do this.
This also fixes a defect you may have been working around: the registry
previously re-validated the raw dict against a keyed ref's own
payload_type, discarding the actor model's defaults. An actor model
defaulting tenant_id="unattributed" against a ref model requiring
tenant_id failed the job non-retryably on a payload that was valid for the
actor. If you added a redundant default to a ref model to work around this,
you can now remove it.
Keyed refs: payload_type is required, key_fn receives the model¶
Unreleased. Breaking for every
KeyedRateLimitRef/KeyedReservationRefdeclaration.
Old (broken):
KeyedRateLimitRef(
base_name="api-per-tenant", key_fn=lambda p: p["tenant_id"], capacity=10, refill_per_second=1.0
)
New:
KeyedRateLimitRef.typed(
MyPayload,
base_name="api-per-tenant",
key_fn=lambda p: p.tenant_id,
capacity=10,
refill_per_second=1.0,
)
payload_type is now required, and key_fn receives the validated Pydantic
model, not the raw dict. Use .typed() for compile-time type checking of
key_fn against the payload model.
Deploy hazard: if defaults or validators change a key-deriving field's value vs the raw row, new concrete names materialize fresh full-capacity buckets alongside old ones (a temporary over-admission window). Drain affected queues before deploying payload model changes that affect key derivation.
Truncated workflow joins read their full collect (and fail closed when it is gone)¶
Unreleased. Two authoring values change, and one new failure face appears on runs whose retained detail rows age out.
A join (map_join or gather) that collects more than the 64 KiB cap stores a
bounded summary on its row and keeps the full list on the parent rows. The
readers now rebuild that list instead of handing back the summary:
ChildOk.resultis the FULL collected list. It used to be the 64 KiB prefix re-validated into the declared model — a parent body that counted, deduplicated, or derived an idempotency key fromlen(items.root)now sees every item.- A
skip=predicate'sstate["results"][<join>]is the FULL collected list (a truncatedgatheris flattened exactly as it was packed). A predicate authored as "skip when fewer than N items are visible" flipped from always-skip to never-skip; re-check those comparisons.
When the full list can no longer be rebuilt — the parent detail rows were
purged, or their result TTL was swept (result_ttl) — the read raises
WorkflowResultDetailUnavailableError on the first attempt instead of
degrading to the prefix or to None. The class is deterministic: the ladder
spends no retries on it, the consuming node terminal-fails with the class on its
row, and the remedy is to re-run the flow. See
Workflows.
Workflow rows carry a fairness cohort¶
Unreleased. The dispatch BEHAVIOR change is confined to
round_robinqueues hosting workflows; the STORAGE rides every workflow row on every queue mode.
Every claimable workflow row (static steps, fork/emit children, join
nodes, outbox-drained consumers) is now born with its run's flow_id
as jobs.fairness_key, so on a round_robin queue each workflow run
dispatches as its own cohort — previously every workflow row collapsed
into the single __null__ cohort and drained as one FIFO stream, and
a deep run could starve a shallow one. Queues serving no workflows see
no dispatch change; vanilla enqueue callers still pass fairness_key
explicitly. On strict_fifo queues the stamp is stored and ignored
(the claim order is unchanged).
The storage face (every queue mode): the stamp is a 36-char uuid
text on every workflow row — about 40 B on the row itself, live until
the row archives/prunes — and, while the row is pending, the same
value in the probe indexes' key columns: the common pending probe
(jobs_round_robin_probe_idx, partial on pending) carries EVERY
pending row's stamp, and the population probes add a SECOND entry per
pending wf row — jobs_unrouted_round_robin_probe_idx for the
producer-placed rows, jobs_assignment_routed_probe_idx for the
re-pended rows (the entries leave when the row leaves pending).
Vanilla rows carry NULL: no workflow-face storage, no workflow-face
index change (a producer's own user cohort rides the same indexes by
design).
The pre-upgrade face: rows still pending from the pre-stamp code
keep the NULL cohort — the old code stamps nothing and no re-pend path
ever touches the column — so they drain in the __null__ FIFO cohort
until they terminalize. The post-phase migration backfills the cohort
for EVERY workflow row — terminal rows included (the full-history
top-up: one statement over the flow-nodes expression index, the
write-once column takes its value once) — and adds the structural
backstop (jobs_wf_fairness_cohort_check, NOT VALID): every workflow
row written after it carries its run's cohort — a regression's
unstamped insert is refused by the database itself.
The deploy face (the HOW): apply taskq migrate up --phase pre as
the pre-deploy job while the workers roll (the pre phase for this
feature is empty — the stamp rides the existing column); apply
taskq migrate up --phase post once, by hand, AFTER THE LAST WORKER IS
UP. The new CHECK constraint lands NOT VALID and needs one validation
pass (the same two-phase pattern the denial-counters and retry-curve
migrations document):
-- find a violator before validating (the constraint's own predicate,
-- reversed): a workflow row whose cohort stamp does not match its run
SELECT j.id, j.metadata->>'flow_id' AS run_id, j.fairness_key
FROM jobs j
WHERE j.step_key <> '__flow__'
AND j.metadata ? 'flow_id'
AND j.fairness_key IS DISTINCT FROM j.metadata->>'flow_id';
-- fix a violator by restamping it from its run (the backfill's own shape):
UPDATE jobs j
SET fairness_key = j.metadata->>'flow_id'
WHERE j.step_key <> '__flow__'
AND j.metadata ? 'flow_id'
AND j.fairness_key IS DISTINCT FROM j.metadata->>'flow_id';
-- validate (shares the table briefly; safe once no violator remains):
ALTER TABLE jobs VALIDATE CONSTRAINT jobs_wf_fairness_cohort_check;
The finder's query states the COMMON violator shapes (the linked
workflow row whose cohort stamp disagrees with its run); it is a
finding aid, not the contract's teeth — the CHECK's own predicate also
covers the pathological rows this query cannot name (a JSON-null
flow_id link with a NULL stamp, a linked row with a NULL step_key
whose stamp is not its link — NULL or wrong), and the VALIDATE CONSTRAINT itself fails loudly on ANY surviving
violator. Run the VALIDATE even if the finder reads empty; an empty
finder is not a clean bill.
THE BREAKAGE, PLAINLY: once the post phase is applied, an
old worker cannot write workflow WORK — the flow ROOT row is exempt
(its insert passes), but the STATIC NODE INSERTS are refused, so the
old worker's create_flow still fails, and its forks and emits refuse
the same way. The mixed old/new worker wave is viable in the
PRE-PHASE WINDOW ONLY; schedule the post phase after the wave
completes. The restart-based path cannot do this for you:
TASKQ_MIGRATE_ON_START (honoured only by taskq ui serve) and the
lifecycle migration path apply the PRE PHASE BY DEFAULT — the post
phase stays behind an explicit taskq migrate up --phase post on an
operator's decision, never a process lifecycle event.
The keyed rolling-deploy face: a keyed admission term's concrete
name (base:key) is stamped onto the row at the fork, and the worker
that CLAIMS the row materializes the bucket. During a rolling deploy,
an OLD worker claiming a keyed-stamped row cannot resolve the concrete
name against its own (pre-keyed) registry — the row PARKS budget-free
(the fail-closed arm, the warning naming the bucket) until the
upgraded workers claim it. The row is never admitted unprotected and
never lost; the run resumes when the upgrade wave reaches its queue.
A map on a truncated join or gather forks every collected item¶
Unreleased. Breaking for workflows whose run succeeded on the truncated prefix.
A map_source wired directly on a map join or gather whose collected
result passed the 64 KiB envelope cap used to fork only the prefix the
join row still spelled, and the run ended succeeded on partial data.
It now forks one child per collected item. Past 1000 items the source
node terminal-fails with FanInBoundExceededError unless the map
declares child_driven=True; on a widened (POST) schema — or at exactly
32,768 items on any schema — it terminal-fails even with child_driven,
on the join counter's FanInBoundExceededError.
While the identity carriers are still smallint, a map past 32,768
items fails first with error_class='MapIndexExhaustedError',
child_driven or not. Partition the source to stay under the bounds.
A join that finalized before the upgrade keeps the children it already
forked. Until the upgrade wave reaches every worker, a join CLAIMED by a
still-running pre-upgrade worker keeps the old behaviour: it forks only
the truncated prefix and the run still ends succeeded with no error.
To audit runs from before (or during) the upgrade, look for the
"__truncated__" marker on a join row's result envelope — and the
wf_collect_truncated receipt in its metadata — which identify a join
whose envelope was capped.
Dispatch-path malformed payloads fail immediately¶
Unreleased. Breaking for callers that relied on invalid payloads being retried.
Dispatch-path malformed payloads now fail immediately as
PayloadValidationError (non-retryable) instead of being retried as a
generic ValidationError. In-flight legacy rows with invalid payloads will
fail on first dispatch instead of exhausting the retry budget.
wait_for_batch defaults to on_empty="error"¶
Unreleased. Breaking for callers that relied on the silent empty return.
Previously, calling wait_for_batch on a batch_id with zero jobs and no
batches row returned an empty BatchCompletionStatus silently. The
default is now on_empty="error", which raises EmptyBatchError. Pass
on_empty="ok" to preserve the old silent-return behaviour.
Sub-enqueue failure events carry error_class/error_message¶
Unreleased. Breaking for log pipelines.
sub_enqueue_re_enqueue_error and sub_enqueue_flush_error now carry
error_class + error_message instead of the single message field,
matching the error_class/error_message convention used by every other
error event (job_timeout, job_exception, job_failed,
rate_limit_release_failed, savepoint_rollback_failed,
stranded_jobs_query_failed, and the failed_details payload of
sub_enqueue_flush_failed). Log pipelines querying fields.message on
these two events must switch to error_message.
dotenvmodel 1.x: environment-variable precedence flips¶
Unreleased. Breaking for deployments that rely on
.envfiles beating the process environment.
dotenvmodel is bumped to 1.x (>=1.1.0,<2), adopting its 1.0 defaults.
Environment-variable precedence flips: the process environment now beats
.env files by default (previously .env values overwrote os.environ);
restore the files-beat-env-vars behaviour with DOTENV_OVERRIDE=true or
TaskQSettings.load(override=True). load() no longer mutates
os.environ: read TASKQ_* values from the settings instance, not the
process environment, after a load. TaskQSettings.load() now forwards
dotenvmodel's full parameter surface (env, override, env_dir,
read_dotfiles, read_environ, load_local). Subclass string-field
defaults containing ${VAR} references are interpolated at load time
(unset references resolve to "").
Time is unified on the database clock¶
Unreleased. Breaking for
Backendimplementors and for callers passing absoluteschedule_to_closedatetimes.
EnqueueArgs.scheduled_at is now nullable: "immediate" enqueue passes
None and the server stamps it (no more client-side now() default), and
Backend implementations that require a non-None datetime fail loudly.
The raw schedule_to_close datetime form is deprecated in favour of
schedule_to_close_interval (or declaring retry.time_budget on the actor,
because absolute datetimes cross clock domains and can misbehave under skew);
every enqueue arm writes the deadline from one domain (server clock +
interval). The rate-limit Redis Lua scripts derive now from
redis.call('TIME'); the caller-supplied now ARGV is removed.
JobFilter.active renamed to unfinished¶
Unreleased. Not a breaking change: the old name still constructs. Positional callers are unaffected:
unfinishedwas appended aftercreated_beforerather than slotted intoactive's old position, so an 11-argument positional call binds its arguments exactly as before the rename.
JobFilter.active read as 'currently executing' but the predicate is
terminality: True selects every non-terminal status (pending, scheduled,
running), False the terminal ones. The field is now unfinished, which
states the predicate it applies. The old name stays accepted as a
deprecated constructor kwarg: it raises a DeprecationWarning once, at
construction, and feeds the same predicate. The warning fires once per
filter even across the dataclasses.replace copies the client's list
probe and the bulk-cancel sanitizer make. Update call sites to
unfinished=; JobFilter(active=True) becomes
JobFilter(unfinished=True).
Terminal writes raise on drifted outcome branches¶
Unreleased. Not a breaking change: a drifted row previously fell through the SQL arm silently, and nothing could observe that path without a schema or template drift the library itself introduces. The raise is the loud surface for a library bug, not a state your application code can produce or handle.
mark_snoozed, mark_failed_or_retry and mark_abandoned (and the
mark_retry arms behind them) branch on a typed outcome instead of
free-form SQL arms, so a terminal write whose row matches no branch —
a status the statements cannot emit — raises (AssertionError naming
the branch) instead of falling through an unhandled SQL arm and
returning a row that was never written. Nothing migrates: correct
deployments never see it, and the in-memory twins share the same typed
branches so the differential corpus holds. Related, and visible on the
happy path: the snoozed deadline exit's state-change event persists
denial_reason, so a denial-keyed row's terminal event names the
denial class the caller reported and an operator can see which
starvation killed the job without joining the counter columns.
firstof/allof DST strategies become live¶
Unreleased. Breaking for schedules that already exist and declare them.
The cron tick's SELECT never listed the dst_strategy column and
fire_schedule read it as row.get("dst_strategy", "skip"), so the stored
value was always skip in production whatever the schedule said;
branch that enqueues the second job for a DST fall-back overlap was
unreachable. The column is now selected and read, so a schedule configured
allof or firstof years ago changes behaviour on upgrade, with no
configuration change and nothing raised: on the autumn fall-back night an
allof schedule enqueues two jobs for the repeated local hour where it
used to enqueue one. Audit for non-skip schedules before rolling out,
and make sure their actors are idempotent.
worker_id is no longer a metric dimension¶
Unreleased. Breaking for dashboards, queries and alert rules that group or filter by
worker_id.
taskq.lock.expires_in_seconds, taskq.heartbeat.misses,
taskq.leader.election_attempts, taskq.leader.election_failures,
taskq.cron.lock_contention and the taskq.heartbeat.consecutive_failures
gauge now emit a single undimensioned series each: they return one series
where they used to return one per worker. worker_id is a fresh UUID per
worker process, so every deploy, restart and autoscale event minted new
time series without bound; Azure Monitor counts each unique (metric,
dimension key, dimension value) seen in 12 hours as an active series, caps
a subscription at 50,000 per region, and throttles ingestion for every
custom metric once the cap is passed, with no backfill of what was dropped.
Per-worker attribution is unchanged on the channels where cardinality is
free: worker_id is bound onto every log line via contextvars, and
taskq.worker_id is a cron-fire span attribute. The record_* helpers
still accept their worker_id argument; only the dimension is gone.
taskq.cron.consecutive_failures is labeled by actor, not schedule_id:
schedule rows accept any actor string at creation time, so the label is
capped at the emitter like queue. A dashboard grouped by schedule_id
loses its series; group by actor and read per-schedule attribution from
the cron-fire span and the log lines, where cardinality is free.
cron_auto_disable_threshold is still evaluated per schedule in the
database.
taskq._json.dumps() requires str dict keys¶
Unreleased. Breaking for raw (unvalidated) dicts with non-
strkeys.
taskq._json.dumps() no longer passes OPT_NON_STR_KEYS to orjson: dict
keys that are not str (e.g. int keys in job metadata, actor results, or
progress data) now raise TypeError instead of being silently coerced to
string keys. Callers must stringify keys before enqueue.
Pydantic-validated payloads are unaffected: dict[str, ...] model fields
reject non-str keys at validation (they do not coerce), so a payload that
reaches EnqueueArgs through jobs.enqueue already has string keys.
Non-str keys were always lossy on the wire: JSON objects and PG jsonb
can only carry string keys, so failing fast surfaces at the boundary what
used to surface as a silently rewritten key on read-back. Dropping the flag
is also 1.29-1.73x faster on str-keyed input (its only effect there). See
the taskq._json.dumps docstring for the full reasoning.
heartbeat_timeout is enforced by the reclaim sweep¶
Unreleased. New enforcement for a parameter that was previously accepted and silently ignored.
heartbeat_timeout, accepted by every enqueue API (JobsClient.enqueue,
the TaskQ facade, SubJobEnqueuer.enqueue() / enqueue_batch()), is now
enforced: the leader's reclaim sweep reclaims a running job whose holder
has been silent past the job's heartbeat_timeout, exactly as an expired
lock is reclaimed, through the same crash-recovery transitions and the same
reason='lock_expired' outbox channel (the event carries
cause='heartbeat_timeout'), even while the global TASKQ_LOCK_LEASE
lease is still valid. Previously the value was stored and read by nothing.
A non-positive value now raises ValueError at the enqueue boundary
(mirroring start_to_close's rule: a zero-or-negative timeout anchors the
deadline in the past and would reclaim a healthy job on the first sweep
tick). Size it >= 2x the fleet's TASKQ_HEARTBEAT_INTERVAL. The
supporting partial index ships as migration 01.00.10_01; fleets that set
no heartbeat_timeout keep an empty index and unchanged sweep cost.
Reservation and rate-limit denials are counters, not event rows¶
Unreleased. Breaking for anything that consumed per-denial event rows.
Reservation/rate-limit denials no longer persist per-occurrence rows: a
denial increments the bounded snooze_count/rate_limit_blocked_count
counter columns on the job row and emits an OTEL counter; it writes no
job_attempts/job_events row and no longer raises max_attempts.
Anything that consumed per-denial event rows (e.g. dashboards over
job_events) must read the counters or OTEL instead.
Snoozing and denials no longer raise max_attempts; both refund the claim's attempt¶
Unreleased. Breaking for anything that read
max_attemptsas a counter that deferrals inflate.
max_attempts is now immutable: no automatic code path raises it (the
ceiling is a bound, not a counter; nothing a deferral, denial or retry
loop does moves it). The one deliberate exception is the explicit operator
re-run, retry_job,
which raises the ceiling to GREATEST(max_attempts, attempt + 1) (capped
at the smallint bound) so a re-pended job can always run at least once
more; the ceiling rises only by explicit admin action. Two behaviours
follow from the immutability rule:
- Actor-requested deferrals are unbounded, and never spend budget.
A
Snooze, or aRetryAfter(consume_budget=False)honouring a server 429, refunds the dispatch claim'sattemptincrement (attempt - 1, floored at 0), when work is deferred without executing, the attempt reservation is released so the job can wait out an unready downstream indefinitely:attemptoscillates and never walks toward the smallint ceiling, andmax_attemptsnever moves. Backoff keys off real executions only. - Admission denials have HTTP-429 semantics. A reservation or
rate-limit denial means "come back later": the actor body never ran,
so the denial refunds the claim's
attemptincrement, spends no retry budget, never writes ajob_eventsorjob_attemptsrow, and never by itself terminally fails the job. A denied job is rescheduled with backoff for as long as the bucket stays saturated. The single bound on a job that is never admitted is itsschedule_to_closedeadline, which fails it through the ordinary deadline path: a queue or limiter misconfiguration cannot kill a job whose only offence is that the fleet was busy more times than itsmax_attempts.
Sustained contention stays visible on the aggregated counters the job
row already carries (rate_limit_blocked_count and snooze_count)
and on the denial metrics, rather than as one durable row per denial.
A consuming RetryAfter (the default, consume_budget=True) is
unaffected: it is a real execution asking for a known delay, so its
budget exhaustion still terminally fails the job, deadline or no
deadline.
Operator re-runs (retry_job) keep the attempt and raise the ceiling¶
Unreleased. Behaviour change for operator tooling that reads the job row after an admin retry; nothing breaks at a call site.
retry_job no longer resets the attempt counter. In v0.2.2 a re-run set
attempt = 0, handing the job a full fresh budget; the row now keeps its
attempt (an idempotent admin operation must not restart the counter, and
a re-pended job climbs to fresh attempt numbers so no job_attempts write
can collide on a spent epoch's primary key) and raises max_attempts to
GREATEST(max_attempts, attempt + 1), capped at the smallint bound
(32767). An exhausted 3/3 job comes back as 3/4: one fresh execution, not
three; a mid-budget 1/5 job stays 1/5 and keeps its remaining budget. When
the attempt already sits at the cap the retry is refused and the row stays
terminal rather than re-pending a job whose next claim would overflow the
attempt column. The retryable source statuses also widened: every
terminal status is now valid (succeeded: the replay path after a bad
deploy, and abandoned included), while running stays excluded because
re-pending a live row races its own terminal write.
Graceful shutdown interrupts: it no longer terminalises in-flight work¶
Unreleased. Behaviour change with one additive pre migration (
01.00.12_02_pre_job_interrupt_count.sql; apply it before rolling the code, as with everyprefile).
When a deploy's grace windows expire with a job still running, the worker
no longer writes a terminal state for it. The job is interrupted:
released back to the fleet as pending (the actor provably exited; an
async actor unwound on the cancel, a sync actor's thread finished, the
transactional unwind completed; the consumer parks on the tracked exit
handles, bounded by the remaining termination budget, before writing) or
scheduled behind the remaining TASKQ_TERMINATION_GRACE_PERIOD budget
plus the watchdog's exit tail (the dump-interval lag before the deadline
trip is observed, and the ~2s bounded flush before os._exit), when the
actor never provably exits (the row stays unclaimable until the exiting
process is provably gone; with TASKQ_WATCHDOG_ENABLED=false the hold is
TASKQ_LOCK_LEASE). The no-concurrent-run promise is two-legged: it holds
when the watchdog is enabled, or when the platform SIGKILL lands at or
before TASKQ_TERMINATION_GRACE_PERIOD plus the exit tail. The claim's
attempt increment is NOT refunded: the attempt did start executing, and
a refund would re-create the attempt epoch the interrupted handler still
holds, letting its late terminal write land on the re-dispatched attempt.
An interrupted claim therefore spends the attempt; a job
interrupted on every deploy climbs its retry budget until it finishes or
its schedule_to_close fails it with DeadlineExceeded. The release
writes one job_events transition with
reason = 'interrupted' and bumps the new interrupt_count column on the
row; taskq.jobs.interrupted{actor,hold} and
taskq.jobs.interrupted_noop are the OTEL counters.
What to audit:
- Sync actors are no longer assumed gone at the cancel. A plain
defactor's thread cannot be interrupted: before this change its row went straight back topendingwhile the body was still executing, and a second worker could claim it: two live runners for one row across every deploy that caught a sync actor mid-body. The release now waits (bounded by the remaining termination budget, capped by the lease) for the thread and holds the row behind the process's exit window when the thread outlives the wait. A fleet of sync actors should teach long loops to pollctx.should_abort()so they exit inside the cancellation grace and get the immediatependingrelease instead of the held one. - An actor that outlives its budget is now ended at the deadline trip.
The shutdown watchdog stays armed until every tracked actor handle is
reaped, and the trip carries a dedicated
tracked-actor-outlived-teardownreason. Previously the clean path disarmed the watchdog and then joined the detached thread for up toTHREAD_JOIN_TIMEOUT(300s): a released row could become claimable while its actor still ran. The thread's late completion accomplished nothing (the row was already released-with-hold and the fleet re-attempts the work), so ending it at the deadline loses nothing, but an embedder's own cleanup that expected the process to outlive a stuck actor no longer does. - Two new startup warnings, no new hard validation. The release park
is lease-capped (
lock_lease - heartbeat - write budget), which makes the mid-park lease expiry structurally impossible for every loadable config;release-park-lease-cappedfires when that cap binds before the budget bound (interrupted sync actors release earlier with longer holds safe but slower).lock-lease-below-disown-exit-floorfires at the shipped defaults (60 vs 63): both release writers failing their writes leaves a ~3s window in which the reclaim sweep can take the disowned row before the trip ends its actor. RaisingTASKQ_LOCK_LEASEto 63+ closes the residue; whether to spend those 3 seconds of lease on a double-write-failure shape is an operator call this release surfaces rather than makes. abandonednow means "operator cancel". A graceful shutdown never producescancelledorabandonedfor infrastructure reasons; any alert or dashboard that reads those statuses as deploy noise should now treat them as operator intent. (The abandoned-jobs alert is purely an operator-cancel signal now.)- Actors that return early on cancel persist that result. A cancel
request, operator or deploy, no longer overrides an actor that
returns a value: returning records
succeededand keeps the result. Actors that must not keep a partial result on a deploy should readctx.cancel_originand re-raise onSHUTDOWN(see cancellation.md). - The phase-4 name changed.
ShutdownPhase.ABANDONINGis nowShutdownPhase.RELEASING; the integer value4is unchanged, so/healthJSON and the CLI keep their numbers, but thephase="RELEASING"log string and any code importing the old enum member must move. - Long actors re-run from scratch on every deploy. Anything longer
than
cancellation_grace_period + cleanup_grace_periodis interrupted and re-claimed repeatedly; bound such actors withschedule_to_closeor checkpoint via progress state (the released row carries the last checkpoint).
Maintenance leadership is now a bounded lease¶
Unreleased. Requires one new pre-phase migration.
maintenance_leader gains an expires_at column
(01.00.12_01_pre_leader_lease.sql). Leadership is held by the row while
its lease is unexpired and renewed on the heartbeat cadence, so a leader
that dies without closing its connection is replaced within
TASKQ_LEADER_LEASE plus one heartbeat instead of waiting on the
server's connection-reaping horizon. The migration is pre-phase and
rolling-safe: it only adds a nullable column that pre-lease pods never
read, and rolling back to the previous release ignores it. Recovering a
dead leader now needs no privilege beyond table access, so the
pg_terminate_backend runbook steps are gone. The advisory lock a new
leader also takes is a transition courtesy for mixed-version fleets and
is never waited on; it is removed entirely in the release after every
pod in your fleet runs this one. Size TASKQ_LEADER_LEASE at four or
more heartbeat intervals (the default, 40 s, already is).
The SAML cookie-less ACS fallback is opt-in and defaults off¶
Unreleased. Breaking for SAML deployments whose users complete login with the correlation cookie withheld by the browser.
The SAML ACS callback previously accepted a response with no usable
taskq_saml_request correlation cookie whenever its validated
InResponseTo named a pending AuthnRequest the process had issued, a fallback for browsers that block the cross-site cookie. Two problems
came with it: nothing tied that response to the browser posting it, so a
party who starts a login and captures the signed response for their own
account could plant it on a cookie-less victim (login CSRF); and the
same process-local pending-set requirement rejected every SAML login whose
callback landed on a different admin replica or uvicorn --workers N
process than the one that issued it (#239).
One policy fixes both: the signed correlation cookie is the binding;
verifiable by every replica sharing session_secret, so cross-replica
callbacks now succeed with no sticky sessions, and the cookie-less
fallback moved behind TASKQ_SAML_ALLOW_COOKIELESS_FALLBACK, default
false. What to do on upgrade:
- Default deployments (flag unset): cookie-less callbacks are now refused with the standard login error. A user who hits it should retry from the same browser, which re-issues a fresh correlation cookie. If it recurs for users on third-party-cookie-blocking browsers, decide whether to opt in.
- Deployments that must serve cookie-blocking browsers: set
TASKQ_SAML_ALLOW_COOKIELESS_FALLBACK=trueand accept the login-CSRF tradeoff; it is stated directly in sso.md. With the flag on, put the SSO routes behind sticky sessions: the fallback's pending-request record is per process, so a cookie-less callback must land on the process that issued the login. - Sticky sessions are no longer required for the default (cookie)
path; multi-replica and
uvicorn --workers Ndeployments can drop them for SAML logins.
Silent behaviour changes¶
These change what your code does without changing what it accepts. Nothing raises, so nothing points you at the call site; audit for them explicitly.
-
State-change events now consume the progress
seq(it is the event stream's total order). A state-change event (the dispatchrunningtransition, retries, snoozes, and every terminal or interrupted exit) used to carry the last progress event'ssequnchanged; it now carries one past it, and the durablejobs.progress_seqends at the terminal event's consumed value. Consumers deduping or resuming byseqalone were the reason: a guard keyed onseqtreated every state-change event as a duplicate of the progress event sharing its number and dropped it, so a terminal event could never arrive and an SSE stream never closed. Existing consumers that dedupe progress events see extra, correctly-ordered values and need no change; consumers that special-cased the old repeats (or snapshotted from Postgres on every reconnect because seq-cursor delivery of state was unreliable) can drop the special cases. Scope the guarantee to events whose durable write landed: across worker death it does not hold, because the reclaim sweep does not touchprogress_seq, so the reclaimed job's next attempt re-publishesrunningat a seq the wire already carried (a terminal publish whosemark_*write failed repeats its seq on retry the same way), and a consumer can see the same seq twice with different payloads; the Postgres snapshot stays authoritative across the gap. During a rolling deploy, workers still on the previous release emit state-change events that repeat the head instead of consuming a new seq until they are upgraded; both windows produce duplicates a seq-cursor guard already drops. There is no migration: the counter keeps its column, type, and monotonicity, only the state-change increments are new. -
The wake payload names the inserted row's queue, and queue-scoped subscribers filter on it. The insert trigger's NOTIFY carried an empty payload and woke every worker's producer; it now names the row's queue (migration
01.00.16_01, applied automatically), and a worker's listener wakes its producer only when the payload names a queue the worker serves. An EMPTY payload wakes every subscriber unfiltered (the COPY fixup's bulk wake, or an older trigger still live in a rolling deploy). A filtered wake never drops work: the worker's jittered fallback poll stays authoritative, so the worst case for a dropped wake is one poll interval of added latency. External code that LISTENs on the wake channel and parses payloads (nothing in TaskQ does) sees the new payload shape. -
ctx.progress()coalesces Redis publishes: at most one publish per job is in flight at a time. Every call used to fire its own background publish; a call racing a running publish now latches onto the buffer and the running task re-publishes the latch when its round trip lands, so the final publish always lands and the latest state is what subscribers see. Intermediate events under publish pressure are skipped, which the consumer-side seq-discard discipline already treats as replaceable. Postgres-side coalescing is unchanged. -
Cron payload-factory budget exhaustion now defers instead of striking, and micro-grants no longer exist. A factory-backed cron schedule the tick's funded budget could not pay for used to take a failure strike (
consecutive_failures+1,last_fire_errorset to a "tick budget exhausted" reason), marching healthy schedules behind one hung factory to auto-disable in lockstep. It now advancesnext_fire_atone leader tick and retries: no strike, no error text. A leftover too small to honour was also previously granted as a micro-grant, cutting slower factories into manufactured "timed-out-after-0.08s" strikes behind a slow-but-successful monopolizer that never drains; a factory is now called only when the leftover can fund at leastTASKQ_CRON_PAYLOAD_FACTORY_TIMEOUTor a quarter of the tick's funded budget, whichever is smaller; smaller leftovers defer. Operators keying on the oldlast_fire_errortext should watch thecron-fire-budget-deferredlog event and the newtaskq.cron.budget_deferralscounter instead (see the cron guide's tick-budget section and theTaskQCronBudgetDeferralsrunbook; genuinely slow/hung factories still strike exactly as before). -
taskq_leader_lock_contention_totalstops rising in a healthy fleet. It previously incremented on every follower's every heartbeat, so the sustained-rate alert fired permanently wherever more than one pod ran. It now records one event per distinct holder a pod finds in its way. Dashboards that graphed the old always-rising counter will go flat. -
dispatch_scope_by_home_queueis a deprecated no-op. The setting (removed from the docs of the old probe-narrowing shape it applied to) is accepted again so configurations that set it keep loading, but dispatch is assignment-routed now and the flag has nothing left to apply. The worker logs adeprecated-setting-ignoredWARNING at startup when it is set; deleteTASKQ_DISPATCH_SCOPE_BY_HOME_QUEUEfrom the environment. -
Scrubbed exception messages on the
job_exception/job_timeoutlog lines are bounded at 2000 characters. The durableErrorInforow keeps the full text (the admin UI reads it there); only the log line truncates, and it reports the dropped remainder count. The bound followsTASKQ_EXCEPTION_MESSAGE_MAX_CHARSwhen raised. -
The dispatch fence refuses every row stamped
metadata.hold, and that refusal costs a heap visit per standing held row per dispatch round. A stamped row is the held representation (the in-process claim CAS already refused it; the fleet now agrees), so a dead stamp can no longer be re-claimed. The predicate is not indexable (jobs' only GIN index serves@>, not?), so on a HITL-heavy queue with deep standing untimed holds both dispatch statements' row work grows linearly with the held rows ahead of the first routable one, on every round, for as long as those holds stand (pinned bytests/test_dispatch_fence_hold_backlog_depth.py). The old depth-flat contract still holds for vanilla and routable rows. The trade-off: a queue whose pending population is mostly parked on human holds now pays a proportional read at the dispatch poll cadence. Keep standing untimed holds bounded where you can (timed waits expire; the reconcile clears dead stamps), and size a HITL-heavy fleet from the measured held-backlog numbers, not the vanilla depth curve. An indexable marker (a partial index on the pending population, or the stamp mirrored into a column) is the future migration that restores the old bound. -
An unkeyed
ctx.spawn_flowin a loop body gets a per-iteration run key, and a map item's unkeyed spawn gets a per-item run key. The default run key's node segment is now<key>.iter<i>in a loop body, so a re-run of iteration k adopts k's own children; on a map item it is<key>.item<m>(map items share onestep_key, so without the index every sibling adopted item 0's child). A loop run or a map in flight across the upgrade that spawned unkeyed under the old release mints that iteration's / item's unkeyed children once more when it runs again, and during a rolling deploy it can happen in either direction (old and new workers derive different keys). Keyed spawns and spawns outside a loop and outside a map item keep their keys.
Your action: either drain in-flight runs before rolling (let them reach terminal on the old release), or cancel-and-restart the ones you cannot drain — §6 of Workflows is the in-flight versioning contract and the cancel-then-restart path. Accepting the default means a duplicated child execution for each loop iteration or map item that re-runs across the deploy (its side effects run twice; the parent adopts the new child and leaves the old one's result unread). Detection: the old release's cursor family is the marker of a row it spawned on —
-- rows the previous release left mid-spawn (the old cursor key family)
SELECT id, step_key, status, metadata->>'flow_id' AS flow_id
FROM jobs
WHERE step_key <> '__flow__'
AND status IN ('pending', 'scheduled', 'running')
AND EXISTS (
SELECT 1 FROM jsonb_object_keys(metadata) AS k
WHERE starts_with(k, 'spawn_cursor_')
);
A count of zero means no in-flight row carries the old derivation. See the spawn's atomicity face in Workflows §3b.
-
A bare-decimal
ctx.spawn_flow(key=...)is refused.key="0",key=str(i)and any all-digit key reproduced the default run key's slot segment byte for byte, so a numeric key silently aliased the node's first unkeyed spawn (a plain node with two spawn sites handed one caller the other's child). The spawn now raisesSpawnKeyReservedError(aValueErrorsubclass, so callers that guarded the older shape keep working) naming the fix; every non-decimal key keeps its byte-identical run key, so only a caller that was already colliding observes the change. The refusal is DETERMINISTIC — an uncaught one terminal-fails the node on attempt 1 without burning the retry budget. Rename the key (f"item-{i}") or dropkey=to use the slot. -
A
ctx.spawn_flowtarget with no terminal node is refused deterministically, and the durableerror_classit records isChildWorkflowNoTerminalError. A child workflow whose step promises are all sunk (sink(...)) compiles with no terminal node, so the join could never read a result. The spawn used to record the baseChildWorkflowUnknownErrorand spend the node's retry budget. It now raisesChildWorkflowNoTerminalError, which subclassesChildWorkflowUnknownError, soexcept ChildWorkflowUnknownError:catches both. An author wrapper that catches the base and re-raises (raise MyError(...) from exc) does not launder it: the deterministic walker records the leafChildWorkflowNoTerminalError. The refusal is DETERMINISTIC — within a process, re-running cannot give the compiled graph a terminal — so the node terminal-fails without spending the retry ladder and writes exactly one failed ledger row (jobs.attemptis the claim ordinal, which a prior hold's resume bumps, so it is not always 1). During a mixed-version rolling deploy that adds a terminal to a previously terminal-less child, an in-flight parent landing on an older worker fails deterministically without retrying onto a newer worker. Your action: match both class names in any exact-match alert, dashboard, or saved query onChildWorkflowUnknownError— these rows record the subclass only. Give the child a terminal by returning its step promise (orbuild(...)it) instead of sinking it. -
The wait, timer and child-join replay cursors move from attempt-keyed metadata to claim-scoped ones. A wait site used to stamp
hold_cursor_{attempt}_{seq}(signal waits),hold_cursor_{attempt}_{signal_name}(timers) orchild_join_face_{attempt}(child joins) injobs.metadata. It now writeshold_replay_signal_*,hold_replay_timer_*orchild_join_replay_*: the same cursor, but carrying the executing claim's epoch so aSnooze/RetryAfter(consume_budget=False)refund cannot replay a cursor written by another execution. The legacy keys stay on every row, inert and unmigrated — nothing reads them, and deleting them is not required (row retention is the only reclaimer). A worker on the previous release reads no key under the new names, so it derives its cursor as 0 and replays the answer queue from its start: the rollback read direction is inert, not an error.
Until the upgrade wave reaches every worker, a wait node CLAIMED by a
still-running pre-upgrade worker keeps the old behaviour (the executing
binary chooses the key family; the claim does not carry it). Your
action: either drain in-flight HITL runs before rolling, or accept one
duplicate hold on a re-claimed wait node in that window. Rollback
caveat: rolling back re-activates the pre-fix defect on the exact rows
this release fixes — a legacy hold_cursor_* stamp left mid-refund is read
again by the older worker and can mint a second hold, because nothing
clears it. Detection: the old cursor families mark a row the previous
release stamped —
-- wait/timer/join rows still carrying the older release's cursor keys
SELECT id, step_key, status, metadata->>'flow_id' AS flow_id
FROM jobs
WHERE step_key <> '__flow__'
AND status IN ('pending', 'scheduled', 'running')
AND EXISTS (
SELECT 1 FROM jsonb_object_keys(metadata) AS k
WHERE starts_with(k, 'hold_cursor_')
OR starts_with(k, 'child_join_face_')
);
A count of zero means no in-flight wait row carries the old keys. See the wait, timer and child-join faces in Workflows.
Terminal outcome writes raise on drift instead of falling through silently¶
Unreleased. Backend implementors and test-twin drivers see a new exception in the drift window; application code using the client API through a worker is unchanged.
Terminal writes used to resolve through a final catch-all branch: when a
job row no longer matched the branch's preconditions (an operator cancel
landed between the read and the write, a claim epoch moved, a sibling
attempt terminalised first), the write quietly reported success while
writing nothing, and the drift was invisible. The outcome branches are now
typed and exhaustive: a row outside every branch's preconditions raises,
so the drift surfaces at the write instead of disappearing into a no-op
success. denial_reason also persists on the snoozed-deadline exit, where
it used to be dropped.
Code driving terminal writes directly (a custom Backend implementation,
or tests driving the taskq.testing in-memory twin) must handle the
raised error. Application code enqueues and awaits through
JobsClient/JobHandle and never touches a terminal write; the worker's
own drift handling is unchanged. The Postgres backend and the in-memory
twin enforce the same contract, pinned by the terminal-drift guard tests.
A crash reclaim honours an in-flight cancel: the row ends cancelled, not pending¶
Unreleased.
If a job's holder died while a cancel request was in flight and the lock
stayed expired past cancel_grace + cleanup_grace + 60s, the crash-reclaim
sweep used to put the row back pending with cancel_phase and
cancel_requested_at wiped whenever retries remained, so the retried attempt
ran to completion even though a cancel had been requested. The reclaim now
evaluates operator intent first: a row carrying cancel_phase != 0 past that
horizon terminalises cancelled whatever its retry budget, keeping
cancel_phase/cancel_requested_at as the audit trail of the honored
request and stamping finished_at. The attempt row still records
outcome='crashed'/WorkerCrashed; the job row left by a worker that
isolated itself on heartbeat loss now also carries error_class='HeartbeatLost'
where it used to be NULL. Automation that expected a cancel-addressed row to
re-run after its holder crashed now sees a terminal cancelled row instead
(see Cancellation and the
Crash-reclaim interaction
section of Architecture).
unique_for's default unique_states now includes succeeded¶
Unreleased. Breaking for actors using
unique_forwithout an explicitunique_states.
The default unique_states was ("pending", "scheduled", "running"); it is
now ("pending", "scheduled", "running", "succeeded"). unique_for reads as
"at most one job for this identity in this period"; leaving succeeded out
freed the identity the instant the first job completed, so a re-delivered
webhook or a double-clicked button inside a still-open window could run the
work a second time. The failure states (failed, cancelled, crashed,
abandoned) remain excluded: they mean the work did not happen, so matching
them would let one transient failure suppress every later attempt for the
rest of the window. This matches the default every comparable job queue
ships (the completed state is included in the uniqueness check by default).
To keep the old "block only concurrent execution" behaviour, pass
unique_states=("pending", "scheduled", "running") explicitly on the actor.
A dedup onto a job that already finished is now surfaced: the enqueue logs a
WARN-level enqueue_deduplicated line naming the matched status, and
JobHandle.deduplicated_onto_terminal is True.
migrate.apply_pending_locked defaults to the pre phase only¶
apply_pending_locked(...) previously applied every pending migration when
called without a phase argument; it now applies only pre-phase migrations.
The entry point exists to fire on process lifecycle events: a pod restart, a
rollout, an autoscale event, that nobody sequences, and a post-phase
migration exists precisely to be withheld until the whole fleet is confirmed
upgraded. Letting a restart apply one would close a rolling-deploy overlap
window mid-rollout (for example, dropping the old single-column idempotency
index while half the fleet still issues ON CONFLICT (idempotency_key) takes
that half's entire enqueue path down).
If you call apply_pending_locked from your own deploy tooling and relied on
the old all-phases default, pass phase=None explicitly to restore it; from a
context that knows the fleet is fully upgraded. The operator-sequenced path is
unchanged: taskq migrate up --phase post remains the way to close out a
phased migration.
Rate-limit refunds now credit the store that paid¶
If you run backend="redis" rate limits with rate_limit_pg_fallback_enabled
(the default), refunds were previously credited to Redis even when a Redis
outage had caused the acquire to fall through to Postgres and spend the token
there. Postgres was never repaid; permanently, for a fixed-quota bucket with
refill_per_second == 0, and Redis gained a token it never spent.
Refunds now dispatch on the store the acquire actually used. Expect your
effective quotas to shift after upgrading: Postgres-side buckets that had
silently drained will recover, and Redis-side buckets that had been inflated
will return to their configured capacity. If you had raised a capacity to
compensate for the drift, re-check it against the corrected behaviour rather
than leaving the compensation in place.
Two further refund defects in the same area are fixed: the in-memory and
Postgres log-style sliding-window refund() was a silent no-op (it now
properly frees slots), and the Postgres token-bucket refund() was likewise
a no-op (it now properly refunds tokens, capped at capacity, via FOR
UPDATE on rate_limit_buckets). Both were released behaviour:
release-and-retry cycle never gave the slot back, so fixed-quota buckets
may again admit work that had been permanently locked out.
@actor(...) capacity literals no longer win over the stored row¶
max_concurrent, max_pending and result_ttl are now operator-owned.
sync_actor_config seeds them on an actor's first registration and never
writes them again: the UPSERT omits them from its SET clause, and a
difference between the code literal and the stored row is logged at INFO as
actor-config-capacity-override instead of raising ActorConfigDriftList.
This is deliberate: it is what lets an operator retune a live fleet through
taskq actor set-capacity (or taskq.actor_config_ops) without a redeploy,
and all three fields take effect without a worker restart.
The upgrade hazard is on schemas that have already run a worker. There, a
row already exists, so changing an @actor(max_concurrent=...) literal and
redeploying now has no effect: the stored value continues to win, silently.
On 0.2.2 that same mismatch aborted worker startup, so the failure was loud and
you could not miss it.
Two consequences worth auditing before you upgrade:
- If you tune capacity in code and rely on redeploys to apply it, that workflow no longer works. Move the value to the operator surface, or clear the override to fall back to the literal.
- If an environment variable feeds an
@actor(...)capacity argument, it stops being the effective value on any existing schema.
To see where code and stored rows disagree, check for
actor-config-capacity-override in your worker logs; it names every field
whose literal is being ignored. To hand a field back to the code literal, clear
the override: --clear-max-pending and --clear-result-ttl write NULL, which
their enforcement paths read as use the @actor(...) value. However,
--clear-max-concurrent does not do this: the dispatch SQL reads NULL as
unlimited, because it cannot see the code literal once the row exists.
Schema-qualified advisory locks: adopt by restart¶
Unreleased. Silent for correctly-deployed fleets; a rolling deploy across the rename has a split-leader window.
The advisory-lock names are now schema-qualified:
taskq:maintenance_leader:<schema>, taskq:cron:<schema>,
taskq:prune:<schema>, taskq:archive_expiry:<schema>,
taskq:migrate:<schema>, replacing the unqualified (taskq:maintenance_leader,
…) forms outright. Advisory locks live in a per-database namespace, so the
unqualified names serialized every schema in the database against each other:
two schemas sharing one PG instance meant one schema's leader could silently
starve the other's. The qualified names give each schema its own locks.
The upgrade hazard is a rolling deploy. Old and new workers hold different
lock names, so during the roll both an old and a new worker can act as leader
of the same schema at once. The maintenance sweeps stay row-safe in that
window (every snap uses FOR UPDATE SKIP LOCKED), but cron gains a
double-fire window; its advisory lock is what serialises ticks. Nothing
errors anywhere; the fleet-level signal is sum(taskq_maintenance_leader_is_leader) != 1.
Adopt by restarting the fleet onto the new release, not by rolling it. Stop the old workers, start the new ones. The exposure window is the deploy itself, not the steady state. See maintenance-sweeps.md §5 for the full reasoning and runbooks.md for the alert whose remediation carries this note.
A cross-actor idempotency_key hit now raises¶
Unreleased. Breaking only for callers that share one idempotency key across actors and relied on the second enqueue returning the first actor's job.
enqueue / enqueue_batch with an idempotency_key that matches an
existing job of a different actor used to return that job's handle with
was_existing=True: a handle whose .result() belongs to another actor,
logged at INFO as an ordinary dedup. It now raises
IdempotencyKeyActorMismatchError (naming both actors, the key, the scope
and the existing job id) with nothing enqueued; in enqueue_batch the whole
batch is withdrawn. enqueue_batch_fast aborts the whole COPY either way
(all-or-nothing bulk-import semantics are unchanged) and now classifies the
abort the same way: a cross-actor pair raises
IdempotencyKeyActorMismatchError, a same-actor pair keeps
DuplicateIdempotencyKeyError. Same-actor hits on the single and batch
tiers are unchanged. Keys were always documented as unique per scope across
actors; namespace them per actor ("send_receipt:order_123") or use
per-actor idempotency_scope values. See
jobs-clients.md.
NOTIFY channels embed a hash of the schema: adopt by restart¶
Unreleased. Silent for correctly-deployed fleets; a rolling deploy across the rename leaves old workers polling instead of woken. Fixes a bug for schema names of 14 characters or more.
Every NOTIFY channel (the wake channel, the fleet events channel, the
per-worker cancel channel, the progress channels and the cron commit gate)
now embeds schema_channel_tag(schema) (the first 10 hex digits of
sha224(schema)) in place of the schema name: taskq_wake_taskq becomes
taskq_wake_124a200651. Channels are Postgres identifiers bounded by
63 bytes, LISTEN silently truncates longer ones and pg_notify rejects
them, and the schema name alone may be 63 characters. With the name
interpolated, the per-worker cancel channel (13 + schema + 37 bytes) broke
from a 14-character schema on: every cancel's NOTIFY errored, was logged
as cancel-request-notify-failed, and cancellation fell back to the
heartbeat poll, and the wake channel broke every enqueue from a 53-character schema. The tag
makes every channel's length independent of the schema; settings loading
now refuses any schema whose channels would not fit.
Migration 01.00.14_01_pre_wake_channel_schema_tag.sql redefines the wake
trigger to compute the same tag in SQL. Once it applies, workers of the
previous release stop receiving wakes (they LISTEN on the old name) and
claim on their poll interval until restarted; new workers are woken
normally. Nothing errors. Adopt by restarting the fleet onto the new
release after migrating, rather than rolling it; the same discipline as
the schema-qualified advisory locks above.
Anything outside TaskQ that issued SELECT pg_notify('taskq_wake_<schema>',
'') must switch to the derived name; see
workers.md for the SQL expression.
Retries at the backoff cap spread over [cap × (1 − jitter), cap]¶
Unreleased. Silent; only the distribution of capped retry delays changes. The documented bounds are unchanged and
jitter=0remains the identity.
Jitter was applied to the saturated curve value and the draw clipped at the
effective cap, so the upper half of the band collapsed onto the cap exactly
and about half of a cohort retrying at the cap came due at the same instant;
the herd jitter exists to spread, on the retries most likely to follow a
fleet-wide event. The band is now fitted under the cap before the draw: a
capped retry (the default exponential policy from attempt 11, any
fixed/linear policy whose base reaches the cap, any curve above
max_retry_backoff, every reclaimed cohort at the ceiling) is drawn
uniformly from [cap × (1 − jitter), cap] (e.g. [48 min, 60 min] for the
default policy). The RNG path and the row-derived reclaim path (Python and
SQL) evaluate the same expressions, so they remain bit-for-bit equal. See
retries.md.
Transactional migrations give up waiting for a table lock after 30 s¶
Unreleased. A migration that previously parked indefinitely behind a lock holder now fails with a typed error; nothing else changes.
Each transactional migration runs under SET LOCAL lock_timeout of
DEFAULT_MIGRATION_DDL_LOCK_TIMEOUT (30 s) and raises
MigrationLockTimeoutError, naming the migration (or the runner's own
ledger upgrade), the bound and the remedy, with the driver's
LockNotAvailableError as its cause, instead of waiting forever with
every jobs statement queued behind it until the fleet's heartbeats gave
out. Nothing is applied on a timeout; re-run after ending the holder. The
bound is settable with taskq migrate up --ddl-lock-timeout or
ddl_lock_timeout= on apply_pending / apply_pending_locked (0
restores the unbounded wait). -- taskq:no-transaction migrations are
unaffected. See
the migration gave up waiting for a table lock.
Migration 01.00.06_01 takes write-blocking index locks¶
Unreleased. Operational note for the
jobs/job_attemptsindex migration; nothing breaks, but the apply can stall fleet writes.
Migration 01.00.06_01_pre_cancel_and_cascade_indexes.sql adds the indexes
that serve the bounded bulk-cancel/deregistration drains and the stale-worker
cleanup fan-out. It uses plain transactional CREATE INDEX: each build takes
a write-blocking lock on its table for the duration, and jobs is the hottest
table in the system (enqueue, dispatch and heartbeat all write it). Build
time scales with the current row count: on a large, busy production jobs
table the apply can stall the worker fleet's writes for a noticeable window.
- Apply during a maintenance window, or when
jobsis small/quiescent (e.g. right after a prune sweep), on any deployment wherejobsis large. Most deployments see momentary builds, the bounded maintenance sweeps keep steady-statejobssmall. - The wait for the lock is bounded (
ddl_lock_timeout, 30 s by default, see the migration gave up waiting for a table lock): a session holdingjobsopen fails the migration cleanly instead of parking the fleet behind it. The bound never interrupts a build that already holds its lock. - It is transactional deliberately: the
CREATE INDEX CONCURRENTLYform deadlocks under the migration runner's own serialized-migrator advisory lock (the concurrent build waits on every transaction that started before it, including a second replica's blocking lock wait: a cycle the deadlock detector breaks by failing the apply). This follows the01.00.02_01precedent; the migration file's header carries the full derivation.
Rolling deploys from 0.2.2: old pods' prune sweep fails after 01.00.03¶
Known, bounded, self-healing. Documented in the
01.00.03_01_pre_idempotency_scope.sqlheader (RESIDUAL RISK, reviewed twice); repeated here because it is the one rolling-deploy cell the migration chain cannot protect.
A fleet rolling from 0.2.2 (whose schema predates 01.00.03) to this
release: 0.2.2's prune/archive sweep moves terminal rows with a positional
INSERT INTO jobs_archive SELECT j.*, ..., which relies on jobs and
jobs_archive sharing physical column order. 01.00.03 appends
idempotency_scope to both tables, and ADD COLUMN always appends at the
end of each table's OWN order, so on jobs_archive the new column lands
after archived_at/expire_at while on jobs it lands after tags: the
orders diverge, and every old-pod prune attempt fails with a type error
(the text lands in the archived_at timestamptz position) until the last
old pod exits. Non-destructive: the sweep's CTE rolls back cleanly, nothing
is lost or corrupted, and dispatch/enqueue/dequeue are unaffected. The cost
is retention lag while old pods lead: terminal rows accumulate for the
window and the old leader logs a prune failure per sweep tick. This
release's sweep names every column explicitly, so pruning drains as soon as
a new pod holds leadership. Fleets that need a bounded window: apply the
migrations and roll the pods back to back, or promote a new pod to the
maintenance leadership before the retention cutoff matters.
Migration 01.00.13_03 adds the batch open-members index¶
Unreleased. Operational note; nothing breaks. Same lock caveat as
01.00.06_01above.
01.00.13_03_pre_jobs_batch_open_members_index.sql adds
jobs_batch_open_members_idx, a partial index over the non-terminal
members of every batch keyed by batch_id. It serves the member probe
every batched job's terminal write runs (complete_batch's guard and the
remaining count the failure-counter writes return, the same probe as
count_batch_non_terminal) as one index range over the members still
open, where the metadata @> containment form walked the batch's whole
membership on every write. Pre-phase and rolling-safe: the previous
release's statements never reference the index and this release's run
without it (only the cost bound is lost). Like every sibling index
migration it is a plain CREATE INDEX; the build takes a write-blocking
lock on jobs, so on a large jobs table build it CONCURRENTLY by hand
first (the statement is in the migration file) and let the migration
no-op. As with 01.00.06_01, the wait for the lock is bounded by
ddl_lock_timeout and a held jobs fails the migration cleanly rather
than stalling the fleet; the build itself, once it holds the lock, is not.
The assignment-routed marker round applies in bounded lock windows¶
Unreleased. Operational note for the
01.00.12_05/01.00.12_07/01.00.12_08/01.00.12_09round; the upgrade's lock profile changes, the end state does not (same columns, same backfill, same indexes plus the two new probe indexes below).
The marker round originally shipped as one migration whose single
transaction held ACCESS EXCLUSIVE on jobs (taken by the ADD COLUMN)
across the re-pend backfill and two full-table index builds: every read,
heartbeat and claim on the table queued behind it for the whole run, long
enough to burn a live fleet's heartbeat budget during the apply
(the monolithic-migration lock-hold fix). It is now four
single-purpose migrations, each holding the narrowest lock its work
allows:
01.00.12_05: only the two metadata-onlyALTER TABLE ... ADD COLUMNstatements. TheACCESS EXCLUSIVEwindow is the catalog writes plus the commit: milliseconds, independent of table size.01.00.12_07: only the backfillUPDATE. AnUPDATEholdsROW EXCLUSIVE, which blocks neither readers nor other writers, so a deep re-pend backlog backfills for as long as it needs without parking the fleet.01.00.12_08/01.00.12_09: only theCREATE INDEXbuilds. Each build takes aSHARElock (writes queue, reads keep flowing). The runner wraps each file in one transaction, not each statement; so a file's builds share ONE write-block window whose duration is the sum of that file's builds (01.00.12_08's two builds run back-to-back with no drain between them; measured, a writer INSERT blocked 1.04 s behind both vs 0.49 s behind a single-build file). Postgres' FIFO lock queue grants the writes that queued behind a file when it commits, before the next file asks for the table: the fleet sees one write-block window per file, never one continuous window across the whole round, and reads never block.
Same caveat as 01.00.06_01 above on the builds themselves: build time
is proportional to the jobs row count, and on a deployment where a
single build would outrun the workers' heartbeat budget the statements to
pre-build CONCURRENTLY by hand are in each migration file's OPS NOTE
(the migration then no-ops via IF NOT EXISTS). The wait for each lock
is bounded by ddl_lock_timeout as everywhere else.
Two more changes land with the same round (the probe-index removal and the checksum-ledger cleanup):
- The dead probe index pair is gone. The unreleased stack built
jobs_repended_probe_idx(01.00.11_01) and dropped it again two files later (01.00.12_05:post); no shipped code ever read its predicate, so every upgrade paid one write-blocking full-table build for nothing. Neither file ships now. A database that ran a dev checkout of the unreleased stack carries the index only if its01.00.12_05:postnever ran: a pre-phase-only or intermediate-era database (one that ran the stack's full pre AND post phases already had the index dropped by the post file). Such a database also keeps the deleted files' ledger rows; if it carries the index, drop it by hand (DROP INDEX IF EXISTS "{schema}".jobs_repended_probe_idx;), nothing reads it. Released deployments never had it. - A database that ran a dev checkout of the unreleased stack will
also log a
migration-checksum-driftwarning on every futuremigrate up, for01.00.12_05:pre(the file was restructured into the columns/backfill/index files above) and01.00.13_03:pre(a comment-only header fix changed its rendered checksum). The warning means exactly what it says: the ledger's recorded checksum for that key no longer matches the bundled file: the runner compares them, warns, and skips the file because the ledger key is already recorded. It is permanent for as long as that ledger lives (released checksums are frozen and the files will not be reverted), and it is harmless-but-expected for pre-release dev checkouts: nothing fails, nothing re-applies, and every new migration applies normally. Released deployments never see it: their ledgers never held the pre-restructure checksums. 01.00.12_09adds the producer-placed population's two probe indexes (jobs_unrouted_actor_dispatch_idx,jobs_unrouted_round_robin_probe_idx), partial onstatus = 'pending' AND NOT assignment_routed. The label-routed dispatch arms filterNOT assignment_routed; on the pending-only twins that conjunct is a post-scan Filter, so every claim probe walked the re-pended rows ahead of the rows it could admit, so claim cost grew linearly in re-pend depth, exactly on the crash-reclaim tails a fleet-wide restart produces. The probes now ride the marker-partial indexes and visit zero re-pended rows; the re-pended population keeps its own probe index (jobs_assignment_routed_probe_idx, in01.00.12_08), so each arm's probe stops at its own population's rows.
Bulk cancel and force-deregistration now make bounded committed progress¶
Unreleased. Changes the failure semantics of
JobsClient.cancel_where()andderegister_actor(force=True); both remain correct to re-run.
These operations previously did all of their work in one unbounded
transaction; they now drain their match set in bounded committed batches
(event_writer_batch_size rows per transaction, each with a server-side
statement_timeout). A mid-operation failure therefore leaves the batches
that already committed as durable partial progress instead of rolling
everything back, and a re-run continues where the stopped one left off,
because already-cancelled rows fall out of the match set. If you relied on
all-or-nothing semantics (e.g. aborting a tenant offboard on any error and
expecting zero cancels), re-check the returned counts before retrying: they
now reflect only what the completed batches did. See
maintenance-sweeps.md for the full semantics,
including why the drain terminates on the window count rather than the
affected-row count.
Sub-jobs inherit parent tags by default¶
Unreleased. Silent for code that did not rely on sub-job tags being empty.
Every ctx.jobs.enqueue() call inside an actor body now propagates the
parent job's tags to the sub-job, making sub-jobs findable by
JobFilter(tags=...) and cancellable by cancel_where. Pass
inherit_tags=False per-call to opt out. This is a behaviour change for any
code that relied on sub-job tags being empty: inherited tags make sub-jobs
visible to tag-based filters and bulk cancels.
WorkerSettings post-load validation runs on every load path¶
Unreleased. Silent unless a
reload()or avalidate=Falseload produces values an earlier load would have accepted.
dotenvmodel is bumped to 1.x (>=1.1.0,<2, the same bump as the
environment-variable precedence change earlier in this guide) and
WorkerSettings uses dotenvmodel's
native post_load() hook instead of manual load()/load_from_dict()
overrides. The base DotEnvConfig._load_fields invokes post_load
automatically on every load path: load(), load_from_dict(), and
reload(), including under validate=False, so a reload() that produces
invariant-violating values now fails instead of silently succeeding.
log_format validation also moved from dotenvmodel's choices= constraint
(which load_from_dict(..., validate=False) skipped, so an invalid
TASKQ_LOG_FORMAT could previously load silently) to a validator hook
that runs regardless of validate=; its error message is now log_format
must be one of ['console', 'json'], got <value>.
Every mixed-clock decision is single-arbiter on the store's clock¶
Unreleased. Silent; behaviour under clock skew changes.
The application process and the database server keep separate clocks that
can diverge or step (VM pause/resume, NTP drift); every place that mixed the
two domains in one decision is anchored to the database clock: workgroup
supervisor freshness is computed server-side (a skewed supervisor host can
no longer kill healthy children); cron ticks read the server clock inside
the leader transaction, with the catch-up cutoff and beyond-window
recompute server-anchored (no fire-loops or silently skipped backlog under
leader-clock skew); rate limiting runs on the store's clock (PG window
predicates and GCRA/token-bucket epoch math are server-side; peeks measure
against the store clock too); prune/archive cutoffs and enqueue-pinned
result TTLs are stamped server-side; the batch COPY path is server-stamped
via an in-transaction fixup (status, created_at, scheduled_at,
schedule_to_close, result_expires_at), so dedup windows hold under skew.
The admin session cookie is scoped to the admin mount path¶
Unreleased. Silent; expect one session lifetime of cookie overlap on upgrade.
taskq_session carried no path=, so it defaulted to / and the browser
attached it to every request to the host application that mounts the admin
UI, including routes with no reason to see an admin session. Both SSO
backends now set path to their base_path, and logout clears it on the
same path (a delete on a different path clears nothing, which would have
left a live session behind). A stale path=/ cookie written by a previous
version is not replaced by the new one: the browser keeps both and sends
both, and the broader one can shadow the narrower until it expires.
Operators upgrading should clear the taskq_session cookie, or expect one
session lifetime (session_max_age_seconds, default 8h) of overlap.
ctx.progress() no longer blocks the actor¶
Unreleased. Silent; removes a synchronous Redis round-trip from the actor body.
Progress publishing was fire-and-forget in name only: ctx.progress()
blocked the actor on a synchronous Redis round-trip. It now publishes via
background tasks with a drain on shutdown.
Worker failure diagnostics are no longer swallowed¶
Unreleased. Silent; log volume and log fields change.
Timeout and generic-exception attempts log job_timeout / job_exception
WARNING events carrying error_class / error_message /
error_traceback; every terminal (non-retryable) failure across all five
handlers emits exactly one job_failed ERROR event (job_id, actor,
attempt, cause, error_class, plus handler context such as
snooze_count / consume_budget / bucket_name): one alertable event per
dead job, and per-attempt diagnostics at WARNING so retryable attempts
produce zero ERROR noise. A retry the row's schedule_to_close deadline
refuses at the write (the job lands failed with cause=DeadlineExceeded)
is a terminal failure like any other: it emits the same job_failed event
and fires on_retry_exhausted and the ErrorReporter once. Tracebacks are formatted from the explicit
exception object rather than the ambient sys.exception(), so handler
invocations outside an except block no longer record 'NoneType: None'.
The terminal-write-failed event now includes job_error_traceback and
infra_error_traceback. Timeout spans (lifecycle.scheduled /
lifecycle.failed) now report the concrete exception class instead of
hardcoded TimeoutError, agreeing with the log fields. Snooze / RetryAfter
/ ReservationUnavailable terminal outcomes and the stranded-jobs leader
sweep also log their failure details instead of continuing silently.
on_retry_exhausted awaits any Awaitable¶
Unreleased. Silent; non-coroutine Awaitable callbacks now actually run.
on_retry_exhausted now uses inspect.isawaitable() instead of
inspect.iscoroutine(), so a callback returning a non-coroutine Awaitable
(e.g. a Task or a custom awaitable) is awaited instead of silently
skipped.
TaskQ(redis_url=...) is validated at construction¶
Unreleased. Silent; invalid URLs fail earlier and with a different exception.
The URL routes through load_from_dict, so the RedisDsn field type
coerces and validates it: an invalid URL now raises TypeCoercionError
fail-fast at open() (previously a late ValueError from redis-py), and an
empty or whitespace-only redis_url raises ValueError at construction
instead of silently disabling Redis.
The .env-not-found warning filter is narrowed¶
Unreleased. Silent; real dotenvmodel warnings are visible again.
The .env-not-found warning suppression is narrowed to exactly that one
warning: a logging.Filter matched on message prefix, instead of raising
the whole dotenvmodel logger to ERROR, so real misconfiguration warnings
(e.g. an invalid DOTENV_* value) stay visible.
start_to_close now cancels the running actor¶
Unreleased. Silent unless an actor runs past its deadline.
start_to_close now actually cancels the running actor on the transactional
path. _run_actor_in_tx wrapped the actor in asyncio.shield() inside
the wait_for enforcing the deadline, and a shield keeps the shielded
awaitable running when its waiter is cancelled, so the timeout applied to
the wait and never to the actor. The attempt was marked timed out and became
eligible for retry on another worker while the original body kept executing,
running every side effect past the timeout point twice. An actor that
previously ran past its start_to_close deadline will now see
CancelledError at that deadline, so any cleanup it needs on interruption
belongs in a finally. The autonomous path already used a bare wait_for
and is unchanged; the outer shield(_run_actor_in_tx()), which decouples
external cancellation from an in-flight commit, is untouched.
Cancel state is cleared on every retry arm¶
Unreleased. Silent; cancels of jobs that retry mid-cancel now work.
A cancel that escalated to cancel_phase=2 in the same instant the actor
raised an ordinary retryable exception survived the retry write: mark_retry,
mark_snoozed and both mark_retry_after variants rewrote
status/scheduled_at but left cancel_phase and cancel_requested_at on
the row, and a retry reuses the same row. The next attempt was therefore
dispatched already at FORCED, so the cancel controller's PG-observation
fast-advance jumped straight to FORCED without ever calling task.cancel()
and the job could never be cancelled again, only abandoned while its
coroutine kept running. Both backends now clear the cancel columns on every
retry arm. Terminal arms still keep both columns: they are the audit trail,
and mark_abandoned's cancel_phase=2 guard reads them.
Keyed rate-limit key_fn errors no longer embed the payload¶
Unreleased. Silent; error text changes.
The RateLimitRegistry "key_fn returned an empty key" ValueError
interpolated the whole payload (for payload {payload!r}); that exception
propagates into the persisted error_message and the web admin through
generic exception handling, and payload values are attacker-controlled. The
message now names only the ref, matching the sanitization contract
PayloadValidationError follows in taskq._validation.
Packaging, dependencies, and documentation corrections¶
Unreleased. Silent; install behaviour changes.
humanizemoved from the core install to the[fastapi]extra (it was bloating core installs).starletteandprometheus_clientare declared as direct dependencies (they were transitive-reliance).- Dependency ranges in
pyproject.tomluse lower bounds without speculative upper caps; reproducibility and supply-chain verification are enforced byuv.lock+uv sync --lockedand CI dependency audits. - Stale
[web]extra references in the README and CI were replaced with[fastapi]; there is no[web]extra. - Docs corrected:
configuration.mdclaimedTASKQ_ENVIRONMENTselects.env.{env}files;ENVdoes;TASKQ_ENVIRONMENTis a deployment label that gates the unauthenticated-admin warning.
job_events rows past the retention period are deleted¶
Unreleased. Silent; event history older than the retention window disappears. A
watch_reclaimsconsumer whose cursor the horizon passed now fails visibly (EventRetentionGapError) instead of skipping silently.
job_events rows older than TASKQ_EVENT_RETENTION_PERIOD (default 7
days) are now deleted by a leader sweep regardless of parent-job status;
timedelta(0) disables it; the crash-reclaim outbox slice
(kind='state_change' AND detail->>'reason'='lock_expired') is carved out
of the ordinary window so an unread reclaim event survives it, but the
carve-out is bounded, not unconditional. The same sweep deletes that slice
once it is older than 100x the retention period
(RECLAIM_OUTBOX_RETENTION_MULTIPLIER), because a fleet with no
watch_reclaims consumer would otherwise retain every lock_expired event
forever. Shortening the retention period shortens that window
proportionally: a TaskQ.watch_reclaims consumer lagging past 100x
retention loses events - and since the event-prune watermark
(job_events_prune_state, the same change) records the highest deleted
event id, the resumed stream now ENDS LOUDLY with EventRetentionGapError
naming the cursor and the watermark instead of silently skipping to live.
Size the retention period against your slowest consumer's worst outage,
not only against event volume; the gate turns an over-long outage into an
actionable error, not into a recovered feed. Recovery from
EventRetentionGapError after a crash-before-consume is to recreate the
watcher fresh (watch_reclaims(after_id=0)), accepting the loss the error
reported: the deleted events cannot be refilled.
An expired result reads as expired: ResultUnavailable.reason and the expiry stamp¶
Unreleased. Silent; a late poller's error is now distinguished, and
result_expires_atsurvives the sweep it stamps.
Before this change, the result-TTL sweep nulled result, result_size_bytes
AND result_expires_at together, so a client polling JobHandle.wait after
the TTL got a ResultUnavailable that read exactly like a job whose actor
had returned None: the loss was observable but not explainable, and at the
instance level it was indistinguishable from a job that never stored a
result. The sweep now nulls only result and result_size_bytes and KEEPS
the past result_expires_at stamp, and ResultUnavailable grew a reason
attribute: "result_ttl_expired" (with the expiry instant in the message)
when the row carries the past stamp, "not_stored" when it carries no
stamp or a future one. One honesty note: the stamp proves the result's TTL
elapsed, no more. The completion write stamps result_expires_at even when
the actor returned None for a non-None result type (the sweep's
AND result IS NOT NULL guard never touches such a row), so a past stamp
cannot distinguish a swept result from a row that never stored one, and the
message asserts only that: the TTL elapsed at T and no result is stored
(swept after expiry, or the actor stored none). The in-memory backend's
read view applies the identical rule, so tests see the same failure mode on
both backends. A retried job cannot inherit a
stale receipt: retry_job re-pends with result_expires_at = NULL and the
terminal write recomputes from the actor's TTL at the new completion.
TaskQ-built client pools carry a 10 s per-query bound¶
Unreleased. Silent; a black-holed database now raises instead of parking the client forever.
Every pool TaskQ builds for a client (the DSN pool at TaskQ.open() and
the pg_provider sugar's factory pools) now carries an asyncpg
command_timeout of 10 s. Previously a black-holed Postgres (packets
dropped, no RST) parked the client's first enqueue/get/cancel
indefinitely: client processes arm no watchdogs, so nothing converted the
hang into a crash. The query now fails with TimeoutError after 10 s.
The trade-off cuts the other way for a slow-but-alive database: a
legitimate client query exceeding 10 s is now cancelled, so size
client-side expectations (and any outer retry) accordingly. The bound is
deliberately above the enqueue-path lock budgets (5 s defaults);
server-side lock_timeout still fires first, so a lock refusal surfaces
as the typed MaxPendingLockTimeoutError / UniqueForLockTimeoutError /
IdempotencyKeyLockTimeoutError rather than a bare TimeoutError. Pools
you supply yourself (pool= / pool_factory=) stay caller-owned: their
timeouts are your choice.
The queue-depth alert fires on oldest-pending age, not raw depth¶
Unreleased. Operator-visible: the bundled
TaskQQueueDepthHighalert's expression changed; any override of it must be re-expressed.
The bundled Prometheus rule TaskQQueueDepthHigh
(src/taskq/contrib/prometheus/rules.yaml) previously fired on raw depth;
taskq_queue_depth > 1000; it now fires on the oldest pending job's age,
max by (actor, queue) (taskq_jobs_oldest_pending_age_seconds) > 900,
sustained for 5 minutes. Depth alone is ambiguous: a deep queue that
drains is healthy throughput, and a queue-summed number cannot tell a
busy shared queue apart from an actor nobody consumes: a misrouted actor
produces no refusal and no failed job, its rows pile up pending
while every probe stays green, and its age series rises without bound
while its queue-mates stay flat. The per-(actor, queue) attribution
names exactly whose TASKQ_QUEUES coverage to check. taskq_queue_depth
is still emitted, so dashboards and any rules you wrote against it keep
working, but if you overrode the bundled alert's threshold, re-express
the override in seconds of oldest-pending age.
A map on another fan-out's join: the nested join has one row¶
Unreleased. Silent; runs whose outer fork ran on an earlier release can still show the old behaviour.
A map_source placed on another map's or route's join used to get two
<join>.join rows: the nested fork's own, and a second one the outbox
drain inserted under idempotency_key = 'wf:<step_key>'. Depending on
which landed first, the second row stayed pending on a finished run
(taskq flows list showed pending root=succeeded), ran the join work a
second time, or ran before the nested fork existed. In that last case the
run either wedged running forever, or the step after the nested map ran
on an empty join and the run succeeded with a wrong result. The outer
fork no longer lists the nested join as a consumer, so the nested fork
writes the only row.
The fix covers runs whose outer fork runs on the new release. A run whose
outer fork ran on an earlier release, including on an old worker during a
rolling deploy, keeps the old binding and can still show any of the
behaviours above. Nothing repairs those rows automatically. Three read-only
queries find them. The first finds second rows left pending on a
finished or pruned run:
SELECT n.id, n.metadata->>'flow_id' AS run_id, n.step_key, r.status AS root_status
FROM jobs n
LEFT JOIN jobs r
ON r.id = (n.metadata->>'flow_id')::uuid AND r.step_key = '__flow__'
WHERE n.metadata ? 'flow_id'
AND n.step_key LIKE '%.join.join'
AND n.idempotency_key = 'wf:' || n.step_key
AND n.status = 'pending'
AND (r.id IS NULL OR r.status NOT IN ('pending', 'scheduled', 'running'));
taskq job cancel <id> is the record-only repair, and its cost has to be
stated plainly: the row goes to cancelled, the root keeps its status and
the run's result does not change, but every surface that derives the run's
status from its rows — taskq flows list, the headline of taskq flows
status, the admin run page — then reports the successful run as
cancelled, permanently. The maintenance leg only re-derives a root that
is still running, so nothing ever reconciles a terminal root from its
rows again, and the estate's status-truth check (a succeeded root must
derive complete) keeps flagging the run.
Remove the row instead. A second row is a pure orphan: no edge row names
it as child or parent, no step-ledger row records a claim for it, and no
consumer belongs to it. The statement below deletes one only when every
one of those facts holds, the row is still pending under the drain's own
key, and the run it belongs to is finished or pruned — never a live run's
fresh drain row. A real join row has its source's edge and a claim
history, so it can never match:
DELETE FROM jobs n
WHERE n.metadata ? 'flow_id'
AND n.step_key LIKE '%.join.join'
AND n.idempotency_key = 'wf:' || n.step_key
AND n.status = 'pending'
AND NOT EXISTS (
SELECT 1 FROM jobs r
WHERE r.id = (n.metadata->>'flow_id')::uuid
AND r.step_key = '__flow__'
AND r.status IN ('pending', 'scheduled', 'running')
)
AND NOT EXISTS (
SELECT 1 FROM wf_edge e
WHERE e.child_id = n.id OR e.parent_id = n.id
)
AND NOT EXISTS (
SELECT 1 FROM wf_step_ledger l
WHERE l.job_id = n.id
);
The run's rows then derive complete under its succeeded root, so the
root's status, the run's result and every rows-derived surface agree.
Re-run the first query to confirm it no longer selects the run.
The second finds second rows that ran before the nested fork and were then adopted by it:
SELECT n.id, n.metadata->>'flow_id' AS run_id, n.step_key, n.deps_pending,
r.status AS root_status
FROM jobs n
LEFT JOIN jobs r
ON r.id = (n.metadata->>'flow_id')::uuid AND r.step_key = '__flow__'
WHERE n.metadata ? 'flow_id'
AND n.step_key LIKE '%.join.join'
AND n.idempotency_key = 'wf:' || n.step_key
AND n.status = 'succeeded'
AND n.deps_pending > 0;
The row is succeeded with deps_pending > 0 because the nested fork
adopted it after it had already run, so its children's count never drains.
If root_status is running, the run is wedged: stop it with
taskq flows cancel <run_id>. If it is succeeded, the step after the
nested map ran on an empty join, so treat that run's result as suspect and
re-run it. If it is failed or cancelled (a run you stopped with
taskq flows cancel stays on the list), the run ended without a result;
re-run it if you still need one.
A second row that ran while the nested fork's children were still running
is harmless when the nested map is the last fan-out: the run ends with two
succeeded rows and the right result, and nothing needs repair. It is not
harmless when another map sits on the nested map's join (three levels or
more). The second row forks that map again with no items, so the step after
it can run on an empty join, and the real nested join's own fork then fails
on a duplicate wf_edge row. The third query finds these runs:
SELECT n.id, n.metadata->>'flow_id' AS run_id, n.step_key, n.status,
r.status AS root_status
FROM jobs n
LEFT JOIN jobs r
ON r.id = (n.metadata->>'flow_id')::uuid AND r.step_key = '__flow__'
WHERE n.metadata ? 'flow_id'
AND n.step_key LIKE '%.join.join'
AND n.idempotency_key = 'wf:' || n.step_key
AND n.status NOT IN ('pending', 'cancelled')
AND EXISTS (
SELECT 1 FROM jobs f
WHERE f.metadata->>'flow_id' = n.metadata->>'flow_id'
AND f.step_key = n.step_key
AND f.id <> n.id
)
AND EXISTS (
SELECT 1 FROM jobs m
WHERE m.metadata->>'flow_id' = n.metadata->>'flow_id'
AND m.step_key = n.step_key || '.join'
);
If root_status is running, stop the run with
taskq flows cancel <run_id> (it stays on the list). Whatever its status,
treat the run's result as suspect and re-run it.
A fourth shape is not a repair case, so none of the queries selects it. If
the drain's second row had already run (or was still running) when the
nested fork reached it, the fork now refuses to adopt it and writes its own
row: the run completes with the right result, and the leftover row sits
succeeded with deps_pending = 0 — debris, not a wrong answer, and
invisible to the three queries above because a never-adopted row keeps
deps_pending = 0. The refusal is recorded as a
wf-fork-join-adoption-skipped log event naming the run, the step key and
the leftover row.
Bounded inputs¶
New upper bounds reject input that was previously accepted. Each is a clean error, not a crash, but a caller that exceeded the bound will now fail.
| Surface | New bound | Failure |
|---|---|---|
taskq queues set-max-concurrent --max-concurrent |
>= 1 (was >= 0) |
typer argument-parsing error, exit 2 |
taskq.worker.queue_ops.set_queue_max_concurrent |
>= 1 or None (was >= 0) |
ValueError |
SubJobEnqueuer.enqueue_batch(items) |
at least 1 item | ValueError |
BatchFilter(limit=...) |
<= 500 (default 100, 0 still means "no rows") |
ValueError at construction |
Admin /jobs, /jobs/count, /history (status) |
values outside the closed status set | HTTP 400 |
Admin /jobs (tags) |
255 chars each (no item-count cap) | HTTP 400 |
JobFilter: queue, actor, identity_key, tags |
no NUL bytes | ValueError in __post_init__ |
ScheduleCreateArgs: actor, name, timezone, payload_factory, identity_key |
no NUL bytes | ValueError in __post_init__ |
Admin text filters: actor, queue, search, identity_key, fairness_key, tags |
no NUL bytes | HTTP 400 |
ScheduleCreateArgs.dst_strategy |
a value in taskq.cron.DST_STRATEGIES |
ValueError in __post_init__ |
BatchHandle.status() / wait_for_batch(): schema |
schema-identifier regex | ValueError |
taskq.testing.pg: schema |
schema-identifier regex | ValueError |
Notes:
max_concurrent=0.0previously passed both the CLI and the ops-layer guard and then hit the table'sCHECK (max_concurrent IS NULL OR max_concurrent >= 1), producing a raw asyncpgCheckViolationErrortraceback, so scripts passing0were already failing, just messily.NULL(via--clear) is the uncapped state; an emergency drain to0belongs to the per-actortaskq actor-config set --max-concurrent 0, which still accepts it.enqueue_batch([]). Previously returned[]silently when no connection was in play, whileJobsClient.enqueue_batchalready raised. Guard the call site if your item list can legitimately be empty.- Admin
statusfilter. Values are deduplicated in first-occurrence order, so a request repeating a status still succeeds and returns the same rows: only requests containing a value outside the closed status set are rejected, and the dedup alone bounds the list to the set's eight members, however long the request is. - NUL bytes. Previously these reached Postgres and came back as an opaque
asyncpg
22021: a 500 from the admin routes. The values were never storable; the rejection surfaces the fault at the boundary instead. dst_strategy. An unrecognized strategy previously constructed fine and took the default branch at cron-tick time. The known set is newly exported astaskq.cron.DST_STRATEGIES. A schedule that already declaresfirstof/allofalso changes firing behaviour; see Breaking API changes.- SQL interpolation guards. The
schemaparameter of the batch public API (BatchHandle.status(),wait_for_batch()) was previously interpolated without validation, a SQL-injection surface; it is now validated against the canonical schema-identifier regex before interpolation, andtaskq.testing.pgfollows the same rule.
Configuration that no longer loads¶
WorkerSettings gained several load-time validators. A configuration
containing any of the values below stops the worker from starting;
get a settings-load error instead of the opaque mid-startup failure it used
to produce. Check these before rolling out, not during.
| Setting | Now rejected | Previously |
|---|---|---|
schema_name |
longer than 63 characters | Postgres truncated it silently; Redis channel templates used the full string, so the two stores diverged |
workgroup_instance |
not a valid UUID | raw ValueError mid-registration |
worker_label |
contains a NUL | opaque asyncpg 22021 CharacterNotInRepertoireError at startup |
queues[*] |
outside the queue-name charset | accepted; jobs stranded on a queue no worker drains |
The queue-name charset is: letters, digits, _, ., -, with the first
character a letter or _.
Workgroup TOML configs follow the same load-time rule through
WorkgroupConfig.from_toml:
[[workers]] nameis capped at 43 characters. The supervisor binds a health socket for every child at/tmp/taskq_health_<name>_<uuid>.sock(60 fixed chars around the name, and the path must fit every supported platform's AF_UNIXsun_pathbudget (104 bytes on macOS/BSD, 108 on Linux, NUL included). A name of 44-64 chars previously loaded and then died at child spawn withOSError: AF_UNIX path too long, restart-looping against the burst budget until give-up; longer names still do.queues = [](on a worker or in[defaults]) is refused. A worker that consumes no queue dispatches nothing; omit the key to inherit[defaults].queues, or["default"]when no default is set.
Both raise ValueError at config load, from taskq workgroup start /
taskq workgroup validate before any process spawns.
Two further invariants apply only when watchdog_enabled=True:
watchdog_loop_lag_budget + heartbeat_intervalmust be< lock_lease. A stalled event loop has to die before its leases expire, otherwise the leader sweep reclaims live jobs' locks mid-stall and the worker wakes to find its work reassigned.watchdog_loop_lag_budgetmust be> watchdog_check_interval. The lag detector samples once per check interval and schedules the beat it measures from the same poll, so a healthy loop's observed lag is roughly the check interval by construction. A budget at or below the sampling period trips on health rather than on stalls; measured, a budget of1.0against the default1.0s check interval force-exits an idle worker on its first armed poll.
If you tune either watchdog knob, move both together and keep the lag budget
comfortably inside lock_lease.
These raise dotenvmodel's ValidationError / MultipleValidationErrors, not
ValueError. The cross-field invariants (the lock_lease failed-beat-cascade
check, since sized with the command timeouts, see the unreleased note
below,
and the grace-budget checks) previously raised ValueError,
so callers that catch ValueError around WorkerSettings.load*() will no
longer catch them: catch DotEnvModelError (the common base) to cover both
single and aggregate cases, or ValidationError when at most one invariant
can fire. ConstraintViolationError (field validators) was already not a
ValueError; field-level validation (prune_retention_*,
default_start_to_close, log_format, etc.) already raised it and is
unaffected. See the dotenvmodel 1.x note under
Breaking API changes for the dependency-level
changes.
Structured-log event rename: state_change → state-change¶
Unreleased. Breaking for log pipelines.
state_changeshipped in v0.2.2.
The job state-transition event is now emitted as state-change, from every
backend that logs a transition; one name now covers the Postgres and
in-memory paths alike. Nothing fails; your saved searches and alert rules
stop matching. Update any query, dashboard panel, or alert rule that
selects on state_change before upgrading, or you lose visibility silently.
Three other event names were kebab-cased in the same pass,
batch_streaming_enqueued, pg_credential_refresh_failed, and
cancel_where_notify_failed, but none of them ever appeared in a release, so
no consumer can be matching the old spellings.
Trailing newlines in queue names, tags, and keyed keys¶
The queue-name, tag, and keyed rate-limit key regexes are now anchored
\A...\Z instead of ^...$. Python's $ also matches immediately before a
trailing newline, so "default\n", "mytag\n", and "key\n" all satisfied
the old patterns and are now rejected with a ValueError.
The realistic sources of a stray trailing newline are a shell $(...)
substitution, a value read from a file, and an unstripped environment
variable:
# This used to pass validation and now raises ValueError:
queue = pathlib.Path("/etc/taskq/queue").read_text() # "default\n"
# Strip at the boundary:
queue = pathlib.Path("/etc/taskq/queue").read_text().strip()
A queue name with a trailing newline was never actually usable;
jobs enqueued onto it were stranded, since no worker's queue = ANY($1) ever
matched. The new error surfaces a fault that was previously silent.
Separately, queue names are now validated at both the enqueue and the
actor-declaration chokepoints. The QueueName annotation is
inert at runtime (its AfterValidator only fires inside pydantic model
validation), so a typo'd queue name previously sailed through. It now raises
at decoration time, import time in the common case, so a typo that used
to strand jobs quietly will now stop your process from starting.
The default termination grace period rose from 75 seconds to 85¶
Unreleased. Action required before upgrading for any deployment that set its platform's stop grace against the old 75 s number: Kubernetes
terminationGracePeriodSeconds, an Azure Container Apps or ECS stop timeout, Docker Composestop_grace_period, or systemdTimeoutStopSec.
TASKQ_TERMINATION_GRACE_PERIOD (the worker's own SIGTERM-to-forced-exit
budget) now defaults to 85 s, up from 75 s. Nothing rejects the old value:
an explicitly set number keeps working, and a deployment that never set the
variable picks the new default up on its next image roll.
Why. Two provider-release closes joined the modelled teardown tail. The
bounded-close unwind that runs at the end of every shutdown (see
taskq._close.worst_case_teardown_tail) went from 6 sequential closes
(~32 s) to 8 (~42 s): the credential providers a managed-identity
deployment resolves (one Postgres, one Redis) each close once, after every
resource built through them. At the default phase graces (30 s + 10 s) the
modelled worst case rose from 72 s to 82 s, so the old 75 s default no
longer covered it and the new 85 s default does.
The action. A platform grace pinned to 75 s now sits ~10 s below what the worker needs, so the platform SIGKILLs the worker mid-teardown, right in the provider-release step that motivated the change. The kill truncates in-flight terminal writes, the jobs' leases expire, and the leader's crash-reclaim sweep re-runs the work later: the shutdown degrades to the crash-reclaim path instead of finishing cleanly. Before upgrading:
- raise the platform grace above the worker's worst case: at the shipped defaults, 85 s is the safe floor; or
- compute it from your settings:
TASKQ_CANCELLATION_GRACE_PERIOD + TASKQ_CLEANUP_GRACE_PERIOD + ~42 s. The formula and its caveats (the conditional per-slot pool, the ~87 s sibling-crash path) are in deployment.md's fail-closed grace notes; - and keep the platform grace at or above
TASKQ_TERMINATION_GRACE_PERIODitself, so the worker's own watchdog, not the platform, owns the shutdown deadline.
Two surfaces help confirm the sizing. The worker logs
shutdown-budget-exceeds-termination-grace at startup when its own
settings fall short of the model, but that warning compares settings to
settings: the platform's grace is invisible to the worker, so a manifest
still pinned to 75 s produces no warning anywhere and can only be caught
by auditing the deployment config against the formula above. The settings
tables in configuration.md and
workers.md carry the new default.
Unreleased features¶
The features and notes below land with the next release. The canonical
release notes for every release are generated by release-please from the
repository's conventional commits (CHANGELOG.md is generator-owned, and a
hand-written block there is invisible to the release-notes pipeline),
is why the pending notes live in this guide. At release time the generated
changelog becomes the authoritative record and these notes age out.
Workflows (the DAG engine)¶
The workflow round's pending notes, moved here from hand-written
CHANGELOG.md blocks (the generator owns that file — these entries were
invisible to the release-notes pipeline there; CERT2 F-CERT2-1's resolution —
nothing was lost, the move is documented here).
Added¶
- Admin: the workflow-run explorer — the runs list + the run
page (
/taskq/workflows/{id}): the rows-alone Mermaid graph (the collapsed map = one hexagon + the done/total counter), the node detail panel (the attempts, the trace id, the captured error, one upstream hop, the attempt ledger), the holds & decisions panel (the waiting-on state + the declared payload schema + the prefilled example), the audit trail (every operator action is a ROW), and the SSE revisioned-snapshot feed (the seq-cursor +Last-Event-IDreplay — the reconnect never loses state). The page setssuppress_refresh(the meta refresh is the killer); the no-JS surface is the server-rendered snapshot, stated on the page. The nodes are keyboard operable (tab + Enter). The vendoredmermaid.min.jsv11.12.2 (2,754,895 B / 774 KB gzipped) joins alpine/htmx/lucide in/static— no bundler, no React, no CDN. - The typed actions — the admin's
resolve/delivervalidate through the MOUNTED WorkflowApp's bound gates (create_router( workflow_app=...)); without definitions the doors answer 501 — no untyped deliver surface ships. - CLI:
taskq flows— list/status/holds/signal/resolve/ cancel/retry: one question, one command; the analysis lives in the pure module (workflows/_cli.py, the same seamtaskq.doctor's package draws — the shared status derivation + the why-stuck arm); the typed door validates the shell's JSON against the bound gates (the named pydantic refusal; the hold survives); the write verbs ride the engine's audit rows with thecli:<user>principal; the read verbs are read-only (pinned). - Examples: the doc-ingest pipeline — the nine shapes
(heterogeneous fork, batch collect with the partial failures, the
typed HITL hold inside the budget-capped loop, the worked duality of
the edge policies, the union routing with
assert_never, the typed terminal verdict, the cron-slot run key) in ONE flow, shipped abstract, executed in CI (the fast-tier smoke + the Mermaid golden + the examples lane: the join fires exactly once across 3 rounds; the cron slot's idempotency live). The grep gate: zero case-study strings in the shipped tree. - Demo: the doc_ingest graph LIVE —
examples/workflows.py+ the app's trigger route (the F3 envelope) + the mounted WorkflowApp + the in-process drive loop; the admin's run explorer renders the demo's runs live. - The context contract — the body's ctx carries the runtime info: the flow name, the queue, the claim timestamp, the loop's budget_remaining_ms, the consumed hold's epoch (the observability primitive for body authors; the pins are surface-driven).
- loop(gates=...) — the mid-loop hold's gate is declared at wiring (the typed door's compile visibility).
Fixed¶
- The corrupted terminal (the case study's own incident class): a node downstream of a map-join consumer dispatched before its parent existed — the gather fired on an EMPTY collect and the run terminalized SUCCEEDED with nothing done. The full static insert: every non-item node exists before the run is live; the fork ADOPTS the pre-inserted join; the drain's spawn is join-wait (deps 1 + the edge-ledger row) so a consumer's claim follows the join's RESULT write; the spawn key is the static key (the arbiter unifies the births — no double rows).
- The held-drive livelock:
drive(until="held")read the hold throughscheduled_at > now()— NULL for a legal no-deadline hold — and spun max_ticks (5000 polls). The hold MARKER is the question. - The held-drive starvation: the hold check ran before the tick — one held node starved the run's other claimable work. The held answer is the quiescent one.
- The coercion completeness: a list/union/generic param walks the
TypeAdapter (the collect's dicts reached the body raw and the union's
matchfell to the never-arm). - The gather's packer delivers the FLAT shape its contract promises (a gather over list-parents flattens one level; the map join packs the items as-is).
- The capture policy lands: the workflow's declared
capture=now reaches the failing node's capture jsonb (it was inert); a refused capture writes NULL, never{}; the truncation loop no longer crashes on its own marker's int.
Added¶
- Workflows: the failed-parent propagation — a parent's TERMINAL
failure resolves the joins counting it by the edge's declared
failure_policy:fail_closed(the default) blocks the join (the record names the failed parent), peer-cancels the running siblings (CancelledByPeerFailure+metadata.peer_cancel) and fails the flow;collectfans the failure in as a typedFailureInfoitem (the estate'sErrorInfoenvelope, the full attempt history) and fires the join with the partial result. A skip fans in with zero ledger rows. - Workflows: the declared maximum fan-in per join (1000) refused
at validate with the child-driven alternative named; the child-driven
escape (
JoinSpec(child_driven=True)) counts terminal children from the edge ledger; themaybeedge policy (absorbed + SURFACED); the scale curve pinned across the boundary (the refit + the 100k-edge plan assert). - Workflows: the status + progress rollup — the status derivation
table (the absorbed-failure clause stated first), the rows-only
reconstruction (the current jobs rows are the current-node record; the
reconstruction reads the node rows and the never-granted terminal rows
and consults NO ledger — wf_step_ledger is claim/attempt history and
replay data, never a status source; a node terminal and its own ledger
terminal commit in one transaction, so a live row beside ledger
history is a deliberate live shape, never a partial commit), the
G7 always-on reported==reconstructed assertion in every workflow
integration test, the
taskq.wf_progress_nodes_total{workflow, state}gauge (the declared-workflow dimension, the_other_collapse, sampled by the maintenance leader on the admin surface), theTaskQWorkflowBlockedStuckalert in both rule files, the runbook row, the insights SQL recipes, the hypothesis totality property, the (state, event) totality table (64 cells, zero undefined), one-run-one- trace ×10 concurrent, the index-driven rollup cost gate (jobs_wf_flow_nodes_idx, migration 01.00.26_02).
Jobs and batches¶
JobsClient.cancel_where(filter, reason): bulk cancel all jobs matching aJobFilterin a single set-based operation. Pending/scheduled jobs go straight to terminalcancelled; running jobs get cooperative cancel (cancel_phase=1). ReturnsBulkCancelResultwith counts and affected IDs. Empty filters are rejected withEmptyFilterErrorunlessallow_empty_filter=Trueis passed.BulkCancelResultandEmptyFilterErrorare exported from thetaskqtop level.- Batch failure policies (
AbortBatchAfter): an opt-infailure_policyparameter onenqueue_batch()/enqueue_batch_streaming()creates abatchesrow and drives abort-on-consecutive-failure semantics via theapply_batch_terminal_outcomehook. When the threshold is reached the batch is aborted: pending/scheduled child jobs are cancelled and the batch row is set toaborted. - Batch finalizer (transactional enqueue with batch): a
finalizerparameter onenqueue_batch()/enqueue_batch_streaming()enqueues a finalizer job alongside the batch in the same transaction. The finalizer is NOT stamped withbatch_id(deadlock prevention);wait_for_batchautomatically excludes it from counts via the batch row'sfinalizer_job_id. - Batch discovery (
list_batches,BatchSummary):JobsClient.list_batches(BatchFilter)returnsBatchSummaryobjects with live job-count aggregates.BatchFiltercarries only batch-relevant fields (queue,active,batch_id,limit). enqueue_batch_streamingfor unbounded iterables: accepts anIterable[EnqueueItem](including generators) and inserts in chunks ofchunk_size(1-1000). All items share the samebatch_id.wait_for_batchwithexpect_at_least,on_empty,exclude_job_id:expect_at_leastraisesEmptyBatchErrorwhen fewer than the expected number of jobs are present;on_emptycontrols behaviour when zero jobs and nobatchesrow exist ("error"raises,"ok"returns empty status);exclude_job_idomits a specific job from counts (defaults to the batch row'sfinalizer_job_id).- Backend protocol batch methods (10 new methods):
enqueue_batch_atomic,create_batch,increment_batch_failures,reset_batch_failures,abort_batch,complete_batch,get_batch,list_batches,count_batch_non_terminal,prune_old_batches. - Batches table migration (01.00.05_01): adds the
batchestable with columns for status tracking, failure counters, finalizer linkage, and batch-level metadata.
Sub-job enqueueing¶
SubJobEnqueuer.enqueue()now acceptstags,inherit_tags,schedule_to_close, andstart_to_closeparameters. Sub-jobs inherit the parent job's tags by default (inherit_tags=True); passinherit_tags=Falseto suppress inheritance for a specific sub-job.
Managed identities and connections¶
- Connection hook points for managed-identity / BYO connections:
WorkerConnectionsdataclass with per-role pre-constructed resources (caller-owned) or zero-arg async factories (TaskQ-owned) for the worker's three PG pools, notify/leader dedicated connections, and Redis client.worker_main(..., connections=...)andopen_worker_deps(..., connections=...)accept it; fields leftNonefall back to DSN construction.PoolFactory,ConnFactory,RedisFactorytype aliases are exported from thetaskqtop level. - Vendor-neutral credential provider abstraction (
taskq.auth):PgCredentialProviderandRedisCredentialProviderasync Protocols with reusablemake_pg_pool_factory,make_dedicated_conn_factory,make_redis_client_factorybuilders. Any provider implementing the Protocols gets all factory builders for free. The PG factories pass the credential to asyncpg asuser=/password=keyword arguments (which take precedence over both DSN userinfo and DSN query parameters), so the token never appears in the DSN string;enrich_pg_dsnremains as the string-helper variant (writes the credential into DSN userinfo; addssslmode=requireonly when the DSN has no explicit sslmode,verify-fullis never downgraded). All four helpers are exported from thetaskqtop level as well astaskq.auth. - Per-worker Postgres credential providers in workgroup configs: a
pg_credential_provider = "module:attr"key on a[[workers]]entry (or thepg_credential_provider=field onWorkerSpec) is forwarded to that worker's child command line as--pg-credential-provider, so two workers in one workgroup can use different providers. taskq-py[aad]extra:taskq.aadmodule with Microsoft Entra ID providers (EntraIdProvider,EntraIdPgProvider,EntraIdRedisProvider) backed byazure.identity.aio(the extra includesaiohttp, required by the async credentials). Providers constructed withcredential=Nonelazily create oneDefaultAzureCredentialand reuse it; syncazure.identitycredentials are supported and offloaded to a thread. See managed-identities.md.taskq-py[aws]extra:taskq.awsmodule withRdsIamProviderfor AWS IAM RDS Postgres authentication, backed byboto3.taskq-py[vault]extra:taskq.vaultmodule withVaultDynamicDbProviderfor HashiCorp Vault database secrets engine dynamic credentials, backed byhvac.TaskQstream hooks:pg_conn_factoryandlisten_connparameters for the LISTEN/NOTIFY transport inTaskQ.stream(), so pool-only / AAD deployments can stream without a DSN.stream()now usescontextlib.aclosingto ensure the inner generator'sfinally(conn close) runs promptly on early return.migrate.apply_pending_lockedhooks:conn(caller-owned) andconn_factory(TaskQ-owned) parameters replace the DSN-only path.- Credential hot-reload (SIGHUP / interval / programmatic): hot-swaps
every factory-backed PG pool, dedicated connection, and Redis client with
freshly-built replacements (each factory fetches a fresh credential).
Triggers: SIGHUP;
TASKQ_RELOAD_INTERVAL(seconds, unset by default) for periodic reloads with no external signal: the only rotation path on Windows; andWorkerDeps.request_reload()/reload_credentials(deps)for embedders. Each factory call is bounded byTASKQ_RELOAD_FACTORY_TIMEOUT(default 30 s). The swap is atomic: the old pool stops serving new acquisitions immediately and is closed in the background with a bounded drain (default 5 s), then terminated; in-flight actor that outlives the drain sees its next acquire fail and the job retries on the new pool. DI-injecteddb: asyncpg.Poolactors resolve the new pool (LOOP-scope cache refresh) and progress flushing follows the swap. A SIGHUP arriving mid-reload (success or failure) triggers exactly one follow-up reload; reloads are skipped while shutdown is in progress. Each resource reloads independently; one factory failure is logged and does not abort the rest; thecredentials-reloadedlog line'sfailedfield reports any resource that didn't rotate. Caller-owned resources are not swapped. - NOTIFY listener resilience: the reconnect loop rebuilds a dropped
LISTEN connection through the user-supplied
notify_conn_factory(or the DSN closure it was opened with) instead of a stale/absent DSN. A caller-ownednotify_connthat drops disables the listener (poll-based dispatch fallback) instead of crashing the worker. - Ownership-contract enforcement: caller-owned pools/connections/Redis
clients are never closed by TaskQ (including shutdown paths). A
caller-owned
leader_connwith noleader_conn_factoryand nopg_dsn_directis a startupValueError(no rebuild path). TaskQ-owned dedicated connections (DSN- or factory-built) get TCP keepalive. taskq.workerre-exportsWorkerConnectionsandreload_credentials(lazy, alongside the existingWorkerDeps/open_worker_deps).
Actor and retry hooks¶
ErrorReporterProtocol for vendor-neutral terminal failure routing (Sentry, Datadog, DLQ) withNullErrorReporterdefault and ataskq.error_reporter.failuresOTel counter.report()takes(job, exception)(the same argument order ason_retry_exhausted), and is guarded by theerror_reporter_timeoutsetting (default 3 s). The registration's scope is validated at worker startup: a reporter registered atTRANSIENTscope (which the hook, running after the actor's scope closed, could never resolve) fails the boot with aDIErrornaming the scope and the allowed ones, where dispatch time previously raised per job. A dispatch that never bootstrapped (in-process runners) degrades instead: the hook is skipped behind a window-gatederror-reporter-defectWARNING, and a provider resolving to a value without the reporter protocol warns the same way.retry_classifierhook on@actorfor exception-instance-level retry classification (inspect attributes like HTTP status codes, returnRetryOverrideto refine kind/delay per occurrence). Non-RetryOverridereturns are caught and logged rather than crashing, and the hook is skipped fornon_retryable_exceptionsandPayloadValidationError, matching the documented contract.RetryOverrideandRetryClassifierHookare exported from thetaskqtop level.on_successhook on@actorfor success callbacks (mirrorson_retry_exhaustedwith timeout guard).start_to_closeper-attempt execution timeout with precedence chain: per-enqueue >@actor(start_to_close=...)>TASKQ_DEFAULT_START_TO_CLOSEworker fallback.KeyedReservationReffor dynamic per-key (session/tenant) concurrency caps computed from job payload at dispatch time.max_keyed_reservationssetting to guard against unbounded keyed reservation growth.
Cron, queries, and admin¶
- Cron schedule ownership model (
disabled_by, migration01.00.19_02):cron_schedulesgains a nullabledisabled_by textcolumn recording WHO disabled a schedule:'auto'(the cron loop's failure-count auto-disable),'operator'(schedule handledisable(), the CLI, the admin UI, actor deregistration), or NULL (enabled, or a row an old pod wrote during a mixed-version deploy; see below). A CHECK constraint enforces the two values. The worker's startup registration pass now re-enables a schedule auto-disabled on a transient failure blip only when the re-declaring spec is code-owned (CronScheduleSpec.owner="code", the default) and declaresenabled=True; operator-disabled rows stay disabled across restarts, the guarantee the create-only registration design always intended but could not express. Upgrades are safe by construction: the follow-up backfill (migration01.00.19_05) stamps every disabled row that predates it'operator', so every schedule a human or auto-disable left disabled before the upgrade stays disabled until the operator acts -- the old behavior, unchanged. The residual NULL reading after the backfill covers the mixed-version deploy window: the previous release's failure UPDATE cannot name the marker, so an old pod's auto-disable during a rolling deploy landsenabled=false, disabled_by=NULL, and the boot revert also recovers a NULL-marked row carrying that write's fingerprint (consecutive_failuresat or past the threshold,last_fire_errorset) -- without the fix, such a row matched nothing and the schedule stayed disabled until a human re-enabled it (issue #460). Fresh installs get the column from the migration chain. The boot is not the only moment the old write can land: during the roll the previous release can hold (or win) leadership after every new pod has booted, and its cron tick keeps firing schedules, so its unmarked auto-disable can postdate every boot pass. Each new-release leader therefore re-runs the same ownership predicates over the code's declared specs when it assumes leadership (thecron-schedule-auto-disable-reverted-at-takeoverlog line): any old leader's disable is reverted the first time a new pod leads after it landed, not only at the next full restart. See cron.md. nameandidentity_keyfields onCronScheduleSpecfor per-property cron schedules and cron↔on-demand dedup.JobSortFieldenum andJobFilter.order_byfor "latest run by business key" queries.- Admin UI security settings:
admin_actions_enabledandadmin_ui_require_auth. The admin UI fails closed by default in non-dev environments:admin_ui_require_auth=True(default) raisesRuntimeErrorat startup when noauth_dependencyis configured, with explicit opt-outTASKQ_ADMIN_UI_REQUIRE_AUTH=false; the health endpoints follow the same fail-closed pattern:health_require_token=True(default) raisesRuntimeErrorin non-dev whenhealth_tokenis empty (TASKQ_HEALTH_TOKEN/TASKQ_HEALTH_REQUIRE_TOKEN=falseto opt out). Destructive admin actions (run-schedule, retry-job, cancel-job) are gated behindadmin_actions_enabled(defaultFalse);POST /schedules/{id}/runchecks the schedule'senabledflag and has per-process cooldown rate limiting, and its cronpayload_factoryerror redirect uses a generic error code instead of reflecting exception text. TASKQ_ADMIN_UI_SECURE_COOKIES(admin_ui_secure_cookies, defaultTrue): sets theSecureflag on the admin UI's CSRF cookie. The flag was previously derived fromrequest.url.scheme, so behind a TLS-terminating edge (Azure Application Gateway, App Service) the app saw plainhttpand silently droppedSecureon exactly the deployments that need it; the session cookie, which already used a configured flag, kept it. Set it toFalseonly for local http dev, where aSecurecookie is rejected by the browser and the UI stops working. A one-shotadmin-ui-cookie-scheme-mismatchwarning fires when the configured value contradicts the observed scheme; run uvicorn with--proxy-headerssoX-Forwarded-Protois honoured.TASKQ_ADMIN_UI_FRAME_ANCESTORS(admin_ui_frame_ancestors, defaultnone): who may frame admin pages. Every admin response now carriesContent-Security-Policy: frame-ancestors '<value>'and the legacyX-Frame-Options(DENYfornone,SAMEORIGINforself). Admin pages can no longer be iframed: a host application that embeds the admin UI in its own dashboard must setTASKQ_ADMIN_UI_FRAME_ANCESTORS=selfor the frame renders blank. Onlynoneandselfare accepted; anything else fails at settings construction rather than silently emitting no header. CSRF is no defence against UI redress: the framed page is the real, authenticated, same-origin page, so a tricked click carries a valid token.- SSO / SAML auth for admin UI: OIDC backend (
taskq-py[oidc]), PKCE flow, JWKS validation, signed-cookie sessions; SAML backend (taskq-py[saml]): python3-saml, SP metadata, attribute extraction; sharedAuthBundle/IdentityClaimsabstraction (both backends use the same session handling and group/role allowlist);token_auth()helper for machine-to-machine bearer-token auth;TASKQ_SSO_BACKEND=none/oidc/samlCLI integration for standalonetaskq ui serve. Thetaskq-py[oidc]extra no longer installshttpx; itsauthlibfloor is now>=1.8.0(authlib 1.8.0'shttpx_clientintegration is httpx2-first, the direct OIDC calls usehttpx2, and nothing undersrc/taskqimportshttpx).OIDCSettings/SAMLSettingsare separate DotEnvConfig classes with prefix scoping.
Testing and documentation¶
- Consolidated testing guide (testing.md).
Fixes and internal notes¶
_di/solver.pydebug log now reports the realcache_hitvalue instead of a hardcodedFalse.worker/_leader_sweeps.pylogs a warning on invalid schema and includes error detail in exception handlers.worker/notify.pylogs debug on NOTIFY payload parse failures.- Test containers are shared singletons: one Postgres and one Dragonfly container per pytest invocation, shared across all xdist workers (filelock refcount, stale-leftover sweep) with per-module database and per-test schema isolation preserved; full suite ~152 s vs the ~226-240 s baseline.
- Docker/testcontainers calls in tests run off the event loop
(
asyncio.to_thread), so docker-py's blocking HTTP round-trips no longer stall the event loop mid-test. - Behavioral timing tests assert in a single clock domain (one statement reads the server clock and the row together), so application/database clock divergence cannot corrupt an assertion; liveness freshness is bounded by the missed-at-most-one-tick contract.
Workflow steps default to the default queue¶
Unreleased. Strict-mode workers (
TASKQ_QUEUES_STRICT=1, or the app declaringWorkflowApp(queues_strict=True)) that import a WorkflowApp whose cohorts project onto queues the worker does not consume now refuse the boot (WorkflowQueueUnconsumedError); non-strict boots warn. Deployments whose workers consumedefaultare unaffected. The audit: everystep(/map_source(/route(wiring in a WorkflowApp, and the queue set each worker actually consumes.
Every workflow wiring verb places its node on the default queue unless
told otherwise (step's queue=, the map's map_queue=, the typed
route's RouteArm fallback, the Chain's rows, the loop's nodes) — the
same default the vanilla @actor carries. The trap is the deployment
shape, not the default: a fleet whose workers are queue specialists
(each consuming its own TASKQ_QUEUES subset, nobody consuming
default) never claims the workflow's rows. The strand is silent by
construction: the fork's INSERT succeeds, the dispatch claim matches
only the claiming worker's own queues, so the rows sit pending forever
with no error and no log — the workflow face of the "jobs stranded on a
queue no worker drains" failure mode.
The discipline — declare the queue when your workers don't run
default: pass queue= explicitly on the wiring verbs (and the
per-arm / per-chain placements), keeping the one-actor-one-queue
placement law — a heterogeneous placement is distinct actor names per
queue (see
Workflows).
The boot-time loud check (the app's queues_strict=True declaration
OR TASKQ_QUEUES_STRICT): every
worker that imports the app projects its cohorts, and a boot whose
consumed set names none of a projected cohort's queues fails LOUD —
gated on the vanilla queues' own opt-in law: strict mode
(TASKQ_QUEUES_STRICT=1) REFUSES the boot —
WorkflowQueueUnconsumedError (a RuntimeError) naming the unconsumed
queues, the consumed set, and the two remedies: add each queue to a
worker's TASKQ_QUEUES / --queues, or route the step elsewhere
(step(..., queue=...) / @app.actor(queue=...)). Non-strict boots
proceed with the ONE aggregated workflow-cohorts-on-unconsumed-queues
warning (the vanilla warning's own shape, the remedy spelled: a sibling
worker in the fleet may consume the queue — a per-queue worker
specialization legitimately imports the shared apps module while its
siblings run the foreign queues). The gate has a second, app-declared
face: WorkflowApp(queues_strict=True) declares the strictness in
CODE, riding the app every worker child already imports (a
heterogeneous fleet whose children each subscribe to a queue subset
cannot coordinate a fleet-wide env var). The faces OR-combine — the
boot refuses when EITHER is set — and the env can only ADD strictness:
ops tightening stays possible; silently disabling a declared contract
is not a thing. One app's declaration tightens the gate for every
co-resident app too: in a process importing several apps,
queues_strict=True on ONE app makes the gate strict over the WHOLE
projected cohort set — a co-resident app's sibling-served cohorts
refuse as well (the refusal names the queues and the remedy). The check
runs before the cohorts'
actor_config sync, so a refusing process writes nothing; a worker
consuming nothing at all keeps the separate worker-consumes-no-queues
warning.
The admin SSE gained a fifth topic: holds¶
Unreleased. Breaking for any consumer that derives resource budgets from the admin SSE topic vocabulary: a budget derived from the topic list under-counts by one.
The admin's GET /admin/sse/{topic} endpoint validates topic against
a closed vocabulary; the workflow round added holds (the
hold/decision stream the run explorer's holds panel rides) alongside the
existing jobs, workers, queues and history. Anything that
enumerates the topic list to size its own resources — a semaphore keyed
per topic, a connection-pool budget allocated per topic — now
under-counts by one: the fifth topic's connections arrive and no budget
was reserved for them. Count holds (found live: a downstream portal's
pool budget keyed on the topic list came up one short). The endpoint is
capped per topic by TASKQ_ADMIN_MAX_SSE_CONNECTIONS; see
the admin UI.
Bulk enqueues partition max_pending admission per actor¶
Unreleased. Breaking for handlers of bulk cap refusals.
enqueue_batch() / enqueue_batch_fast() (and the chunked arm of
enqueue_batch_streaming()) now admit the within-cap actors' items and
refuse only the over-cap actors' items as whole groups, raising
BatchMaxPendingExceededError after the admitted items are stored.
Previously one capped actor aborted the whole call with
MaxPendingExceededError and nothing enqueued.
except MaxPendingExceededErrorno longer catches bulk cap refusals, the new error is deliberately not its subclass. Catch it explicitly; it names each refused actor (refusals), the refused item indices (refused_indices), and the admitted count (admitted_count).except BackpressureErrornow catches an error under which part of the batch is stored: a handler that blindly retries the whole batch duplicates the admitted items. Consultadmitted_count/refused_indicesand retry only the refused items, or rely onidempotency_keys.- Durability is path-dependent: committed when the call owned its
transaction; uncommitted on a caller-supplied open transaction (that
transaction decides); on the streaming no-connection path a refusal
surfaces after a durably committed chunk prefix (indices are
stream-global). The atomic path keeps the legacy all-or-nothing
contract and still raises plain
MaxPendingExceededError.
taskq.cron.consecutive_failures is relabeled and bounded¶
Unreleased. Breaking for dashboards and alert rules keyed on the old label.
The metric's dimension is now the schedule row's actor (bounded to the
first 100 distinct names a worker process sees; later names collapse
onto the fixed _other_ value) instead of the per-schedule UUID.
Dashboards grouping by schedule_id lose their series on upgrade.
Per-schedule attribution lives on the cron fired / cron fire failed
log lines and the cron fire span's taskq.cron_schedule_id attribute.
The per-actor balance is reconciled against the database every tick;
each tick re-derives the per-actor sum over the whole
cron_schedules.consecutive_failures table, so disable, re-enable and
delete actions taken in any process self-correct on the next tick with
due work rather than stranding residue, and the value returns to zero
once no schedule is failing. cron_schedules.consecutive_failures and
the logs remain the authoritative per-schedule record; alert on
taskq.cron.disabled_schedules > 0 for the auto-disabled condition.
The dead-connection retry no longer re-runs committed writes¶
Unreleased. Silent unless your database kills connections mid-flight; when it does, the behavior you get is the one you already wanted.
The retry guard behind the enqueue paths and the bulk-cancel drain
(_with_fresh_connection_retry) covered the whole
acquire-run-release cycle. A pooled connection whose server died between
the op's last acknowledged statement and the pool's release-time reset
raised asyncpg's InternalClientError from the RELEASE: the old wrapper
read that as dead-on-acquire and re-ran the op with the same arguments
(the pooled-connection re-run bug). Because the enqueue table's id is the primary key and the
op carries its id, that re-run could not land a second row: it raised
UniqueViolationError for an enqueue that had already committed and
would run (observed live under an old-contract emulation: 11
UniqueViolations across 400 jittered kills). The harm was that error
returned for work that SUCCEEDED, and the invitation it created: a
caller that retried on the error issued a fresh-id enqueue, and THAT row
landed, which is the route that actually runs the job twice. Two
mechanisms now split the concern:
- The guard's checkout bounds the release (
pool.release(conn, timeout=...), 5 s) and never raises a release failure: an op whose work committed gets its result back (onepool-release-failedWARNING is logged instead). The bound also un-wedges the hang the old path could hit: against a silently dead server (no FATAL, no FIN, a frozen or partitioned endpoint) the unbounded reset parked the caller's task ANDpool.close()forever; it now times out after 5 s, asyncpg terminates the connection, and the pool reopens one on the next acquire. - The retry is refused once the op marked a write durable (the INSERT's acknowledgement on the autocommit arms, the transaction COMMIT's on the batch/COPY/cancel arms). A connection that dies between the write and a LATER statement of the same attempt surfaces its error instead of re-issuing the write; the ambiguous outcome is handed to the caller rather than papered over with a re-run that conflicts with the committed row. A connection poisoned BEFORE the first statement still costs exactly one transparent retry: nothing was sent, so the retry cannot conflict with anything.
For context, the peer doctrine: procrastinate scopes its own
dead-connection retry to the LISTEN connection only
(psycopg_connector.py:313-353) and never auto-retries query paths.
Pre-fix TaskQ sat at the opposite pole: any InternalClientError,
including one raised after an acknowledged write, was retried. Post-fix
TaskQ retries only the provably-nothing-sent case and surfaces ambiguous
outcomes instead of re-running them: closer to the peer's conservatism
than base, deliberately not as absolute, because the first-statement
local failure it still absorbs is provably duplicate-free (nothing
reached the server).
A mid-QUERY kill is unchanged: it raises
ConnectionDoesNotExistError (a Postgres error, not retried by this
wrapper) and whether the statement committed before the server died is
unknowable from the client; idempotency keys remain the dedup channel
for the retry YOU choose to issue in that case.
Worker pools send no per-connection GUCs in the startup packet¶
Unreleased. Breaking only in the sense that a worker that failed to boot behind a strict pooler now boots, and a client-side
jit = offthat silently rode every dispatcher connection is gone; set it server-side if you want it.
Every pool the worker builds opens with no server_settings=. asyncpg
rides each entry in the Postgres startup packet, and a pooler that
rejects unknown startup parameters (PgBouncer: unsupported startup
parameter: jit) refuses the connect before authentication, so with a
single TASKQ_PG_DSN pointing at the pooler, the eagerly-opened boot
pools never came up and the error named neither the parameter nor the
pool (the PgBouncer jit startup-parameter rejection). The dispatcher pool's jit = off entry was a guard
whose measured win had already moved into the dispatch statement itself
(the depth oracle passes with JIT enabled on a plain connection); a
per-claim SET LOCAL jit = off is not a replacement: the claim runs in
autocommit, so there is no transaction to scope it to. Operators who
want the guard should set it where no startup packet is involved:
or append ?options=-c%20jit%3Doff to the DSN; see
ops.md. The per-slot transaction
pool's inherited search_path/role remain startup parameters by
design: they are session state a LOOP-scope connection declared, they
must survive the pool's release-time RESET ALL (startup-packet values
do; a post-connect SET does not), and the slot pool always rides the
direct DSN. If your direct DSN itself routes through a pooler and you
register a LOOP-scope connection, add
ignore_startup_parameters=search_path,role (or whichever parameters
you actually inherit) to the pooler's config.
The TaskQ client reads the .env cascade for its lock budgets and schema default¶
Unreleased. Silent widening; a constructor failure class is gone.
The TaskQ client's lock-budget probe (TASKQ_MAX_PENDING_LOCK_TIMEOUT_MS
and its two siblings) previously read the process environment only, so a
widening set in .env reached the worker's server-side budgets but not
the client pool's derived command_timeout: the two sides silently
disagreed (the lock-budget probe bug). The probe now resolves through the same layers
the worker's TaskQSettings.load() reads (process environment, then the
.env cascade, honoring DOTENV_OVERRIDE / DOTENV_READ_DOTFILES /
DOTENV_READ_ENVIRON), never writing into os.environ.
TaskQ(...)'s default schema resolution also changed twice, once when
this release's connection stack landed and once now:
- Previously (≤ v0.2.2): the default was the literal
"taskq"; no environment or.envvalue was read at all. - At this release's first connection-stack landings: the constructor
ran a full validating
TaskQSettings.load(), soTASKQ_SCHEMA_NAMEwas honored (process env and.env), but any OTHER malformedTASKQ_*value (e.g.TASKQ_ADMIN_PORT=not-a-port, a setting the client never reads) raised in an embedder's constructor. - Now: the value resolves through the same cascade, then validates
ALONE: a malformed
TASKQ_SCHEMA_NAMEstill raises (it is the client's own field, reaching raw SQL; the worker's load fails the same value), and an unrelated malformed setting cannot breakTaskQ()construction.
An explicit schema= argument keeps winning over every layer, so
embedders that pass their loaded schema explicitly are unaffected.
The lock_lease invariant accounts for heartbeat command timeouts¶
Unreleased. Tightened validation: a lease between the old edge and the new floor stops loading.
The load-time invariant on WorkerSettings.lock_lease was
lock_lease >= 4 * heartbeat_interval. It ignored the per-command timeouts
a heartbeat tick pays: a failed beat's cycle spans the interval plus one
heartbeat_command_timeout budget (the tick's command sequence AND its
bounded rollback-or-close teardown sharing that ONE budget, made true by
enforcement by the per-tick command budget), and the isolate decision lands
on the (max_heartbeat_failures + 1)-th consecutive failed beat, so the
lease could lapse before the isolate decision even at the defaults under
contention.
The validator now requires
lock_lease >= max(heartbeat_interval, heartbeat_command_timeout) +
(max_heartbeat_failures + 1) *
(heartbeat_interval + heartbeat_command_timeout)
, the same sizing the lease-renewal threshold derives in
taskq.worker.heartbeat._lease_renewal_threshold, so the threshold's floor
can never exceed the lease it guards. The max(...) term is the LAST good
beat's tail - from its mid-tick renewal point to the next tick's start -
the span the failed cycles do not cover. At the defaults this is
10 + 4 * (10 + 2) = 58 against the 60 s lease: the shipped defaults still
load. A config tightened to the old edge (lock_lease at exactly
4 * heartbeat_interval, or any lease below the new floor) now stops
loading with the new message naming the command-timeout term: raise
TASKQ_LOCK_LEASE past the floor, or lower
TASKQ_HEARTBEAT_COMMAND_TIMEOUT / TASKQ_MAX_HEARTBEAT_FAILURES.
The bootstrap's ensure-slots pass is bounded¶
Unreleased. Robustness fix; a hang class is gone.
The worker bootstrap's per-reservation ensure pass called
ConcurrencyReservation.ensure_slots with no bound; under dispatcher-pool
starvation the bare pool.acquire waited forever, observed
once as a 300 s CI hang). The pass now carries the same
dispatcher_command_timeout budget every sibling bootstrap await has, and
an acquire lapse logs the typed ensure_slots_timeout event (distinct from
the generic ensure_slots_failed) and continues booting, the next restart
re-runs the idempotent materialisation. ensure_slots, slot_rows_exist,
and ConcurrencyReservation.acquire grew an optional timeout= forward to
asyncpg.Pool.acquire for callers with a budget in hand (default None
keeps the previous unbounded-acquire behaviour for callers that wrap their
own).
The terminal-write fence survives the attempt ceiling¶
Unreleased. Correctness fix with one additive pre migration (
01.00.18_02_pre_claim_epoch.sql; apply it before rolling the code, as with everyprefile).
At the attempt ceiling the terminal writes could record the wrong outcome.
The displayed attempt counter is stamped by the claim with a saturating
increment (LEAST(attempt + 1, 32767)), so a row parked at the smallint
ceiling (retry_kind='indefinite' climbs there after enough retries) claims
at 32767 again and again. A reclaim plus a redispatch to the same worker
then gave the stale execution and the live one the same
(status, locked_by_worker, attempt) fence: the stale execution's
mark_succeeded won, the job recorded the stale result, and the live
execution's write read WorkerOwnershipMismatch. The displayed counter
keeps its saturating semantics on purpose (the clamped row must still run,
and its budget arms must still land), so the fix adds a second, non-saturating
fence column instead of touching it.
Every row now carries claim_epoch bigint NOT NULL DEFAULT 0
(jobs and jobs_archive; ADD COLUMN with a constant default, metadata
only, no table rewrite). The dispatch claim bumps it by exactly 1 per claim,
and every terminal/ownership write that already fenced on attempt gained
the conjunct claim_epoch = <the writer's own claim view>:
mark_succeeded, mark_failed, mark_cancelled, mark_retry,
mark_snoozed, both mark_retry_after variants, and mark_interrupted,
every arm of the multi-arm arbiters included.
The invariant itself lives in the migration file. The operational shape: the
value the writer presents is the claim_epoch of the JobRow its own
dispatch returned (and of the actor context, ctx.claim_epoch, which the
shutdown release reads); a caller that cannot present one (a None bind)
no-ops through the same machinery the attempt fence uses, the same
cannot-prove-it doctrine both fences apply. The in-memory testing backend
mirrors the semantics exactly. No operator action is needed beyond applying
the migration first; the column is never read by user-facing surfaces and
the displayed attempt counter is unchanged.
The per-attempt due-time stamp (job_attempts.due_at)¶
Unreleased. Observability addition with one additive pre migration (
01.00.20_04_pre_attempt_due_at.sql; apply it before rolling the code, as with everyprefile). Nothing breaks; no consumer of the old shape changes.
Every job_attempts row (and its job_attempts_archive twin) now carries
due_at timestamptz: the jobs.scheduled_at the attempt's claim took the row
against — the due time the attempt was waiting for when it was dispatched.
Before this, only the FIRST attempt's wait was reconstructable from the row:
jobs.scheduled_at is overwritten by every retry's reschedule
(mark_retry/mark_retry_after and the reclaim re-pends stamp it for the
NEXT attempt), so attempts 2..N had no surviving due time and a retry chain's
wait spans were unreconstructable from the ledger.
The stamp is written by every attempt-row writer (the terminal mark_*
statements, the reclaim sweeps' batched INSERTs, the isolate write): each
sources due_at from the job row's scheduled_at as it stood at that
attempt's claim. On the arms that reschedule in the same statement that write
an attempt row (mark_retry's retried arm, mark_retry_after's consuming
snoozed arm), the UPDATE returns OLD.scheduled_at AS due_at for the attempt
insert — the locked pre-update row carries the claim-time value, while the
RETURNING new row carries the NEXT attempt's. The chain therefore reconstructs
from the ledger alone:
due_at(k) → started_at(k) → due_at(k+1) is attempt k's wait, execution, and
the next attempt's wait. There is deliberately NO index on the column: its
reads are per-job (served by the primary key) or archive-analytics scans that
already bound by time, and the archive twin's hypertable conversion keeps
started_at as its chunk key untouched.
NULL semantics: NULL means a pre-migration attempt (or, during a rolling
deploy, a row written by an old worker that named no such column). Historical
due times are unrecoverable — jobs.scheduled_at was overwritten by every
subsequent reschedule before this column existed — so there is no backfill;
a backfill would fabricate data the ledger never recorded. Consumers reading
attempt history should treat due_at IS NULL as "wait span unknown", never as
"zero wait". The in-memory testing backend stamps the same semantics (the
pre-write row's scheduled_at) so the differential tier exercises the column.
Migration 01.00.17_01 holds ACCESS EXCLUSIVE on jobs for the whole index rebuild¶
Unreleased. Operational note for the archive-candidate index migration; nothing breaks, but the apply blocks reads and writes on
jobsfor the duration of the build.
01.00.17_01_pre_archive_candidate_index_composite.sql rebuilds
jobs_finished_at_idx as (status, finished_at) INCLUDE (id): a DROP
INDEX then a CREATE INDEX, sharing the runner's one transaction. The
migration file's own header (frozen text: the ledger records a SHA-256 of
every bundled file and migrate up fails closed on checksum drift, so the
header cannot be corrected in place) calls the rebuild "instant (one index,
metadata-only lock windows)". Measured through the real migration runner,
it is neither:
- The
DROP INDEXtakesACCESS EXCLUSIVEonjobswithin about a millisecond and, because it shares the transaction with theCREATE INDEX, holds it untilCOMMIT, i.e. for the whole build. Measured: roughly 0.03 s at 100k rows (36 MB), 0.37 s at 1M (305 MB), 3.1 s at 10M (2980 MB). For that whole window every enqueue, every dispatchUPDATEand even a plaincount(*)queue behind it: the lock blocks reads and writes alike, not writes only. ddl_lock_timeoutbounds the WAIT for the lock, not the hold: once theDROP INDEXholdsjobs, a build that runs long runs long inside the lock (see the migration gave up waiting for a table lock).- A build longer than
dispatcher_command_timeout(5.0 s by default) is worse than a latency stall: the dispatch claim runs on the dispatcher pool under that per-query budget, so past the budget the fleet's dispatch iterations error instead of queueing, until the migration commits. - The transaction is still the right shape on the abort side: a
lock_timeoutabort rolls back cleanly, the old index survives, the ledger stays empty, and noINVALIDindex is left behind. And exactly one index changes hands, so a moment of concurrent prune-and-retry sees the old plan shape, not an error.
The scale is modest at defaults: the shipped 30-day
prune_retention_succeeded keeps the hot jobs table at roughly a month
of terminal throughput, so 10M rows and a 3 s stall is reachable without
being typical. Apply during a maintenance window, or when jobs is small
or quiescent (e.g. right after a prune sweep), on any deployment where
jobs is large.
Worker startup now rewrites actor_config.max_attempts and retry_kind¶
Unreleased. Correctness fix, no migration: both columns already exist (
01.00.00_01_pre_initial.sql) and areNOT NULLwith defaults.
Before this fix, sync_actor_config's UPSERT wrote these two columns only
in the INSERT arm, i.e. the first time a row was created. The conflict arm
left them untouched, and nothing else in the codebase wrote them, so the row
kept the DDL defaults (3, 'transient') or whatever the first registration
had seeded, forever. Server-side fires build their enqueue arguments from the
stored row (cron ticks and the admin run-now in the cron leader), so an actor
whose code declared, say, RetryPolicy(kind="indefinite", max_attempts=50)
was fired server-side with 3 'transient' attempts. Producer-side enqueues
were never affected: they carry the ActorRef's literal directly.
The conflict arm now assigns both columns from the registered literal on
every boot. These columns are code-owned, the opposite of the capacity
family (max_concurrent, max_pending, result_ttl, queue), which stay
operator-owned-once-created and untouched by boots: no operator surface can
write the retry contract (taskq actor-config set moves capacity,
move-queue moves the queue, neither touches these), so the code literal is
the only declaration of record and a changed @actor retry literal must
reach the next server-side fire.
Operational consequence: if you have edited these columns out-of-band
(direct SQL against actor_config), the next worker boot overwrites your
edit with the code literal and logs
actor-config-retry-contract-change (warning level, per actor, with both
the registered and the stored pair). That warning means the stored retry
contract changed at this boot; it is informational, never an error, and no
force flag is involved. To make a hand edit durable, change the
@actor(...) literal in code to match instead.
Shipped migration files are immutable¶
A migration file's bytes are part of its contract. The runner records a
SHA-256 of the file's rendered SQL — every byte, comments included — in
each database's schema_migrations ledger at apply time, and the drift
guard refuses every future upgrade the moment a bundled file no longer
renders to what a database's ledger recorded. The refusal is deliberate:
a changed file means the schema was built from different SQL than the
tree carries, and the runner will not build on unverified provenance.
Consequence for contributors: never edit, rename, or delete a migration
file that has shipped. Ship the change as a NEW migration instead. This
is not bureaucratic — editing 01.00.19_01 post-ship blocked every
existing database from upgrading (the guard refused the customer's deploy
at the migration step); the files are restored byte-exact and the
improvements they carried ship as 01.00.21_02
(the fence-probe index's pg_index-keyed rebuild) and 01.00.21_03
(the batches CHECK constraints, NOT VALID + VALIDATE).
Operator consequence, one class only: a database that applied the
REWRITTEN files (created from main between Sep 27 and this fix — e.g.
built at pin bea355f7) holds the rewrites' checksums and will refuse
against the restored files. The schema is correct — the carriers converge
it — but the bookkeeping cannot be made true (the rewritten files no
longer exist). For such a database: rebuild from a fresh database if
practical; otherwise run taskq migrate up --allow-checksum-drift on it
and keep that flag in its deploy pipeline — every run logs the drift as a
warning, which is the honest state: that database's ledger refers to SQL
that no longer exists anywhere.
Published variants: the one exception to immutability¶
Restoring a byte-exact file fixes the guard going forward, but databases
that applied the PREVIOUS published bytes of an amended file carry that
older checksum in their ledgers permanently — and no single file can
render to two checksums. The _variants/ directory inside
taskq.migrations carries the published history: for each amended file,
the exact bytes of the version that shipped first (one .sql file per
vintage, named for the commit that published it). The drift guard accepts
a ledger checksum when it matches the current file OR any bundled
variant's, each rendered with the checking database's own schema — so an
accepted checksum is schema-agnostic by construction, and a checksum
rendered under a different schema is still drift.
A ledger checksum nothing bundled produced — current file or variant — is drift exactly as before; the variants widen what counts as published history, never what counts as legitimate SQL. Variants are code: reviewed, bundled, and versioned with the package (the wheel ships them, and the guard degrades to fail-closed refusal if an install loses them) — adding one is a PR, never a runtime knob. Never add a variant for a file that has not actually shipped amended bytes: a variant legitimises a checksum forever.
Planning the 01.00.44 round¶
The round's twelve files change storage, defaults, and indexes; none of them rewrites row data. Three lock classes decide the window you run it in:
- Four
ShareUpdateExclusivereloption files (_01,_04,_05,_06):ALTER TABLE ... SET (...)touches catalogue metadata only and does not block ordinary DML._04and_06are separate files on purpose: on a TimescaleDB hypertable the setting propagates to every chunk, and that chunk walk must not hold the live tables' locks while it runs. - Six
ACCESS EXCLUSIVEmetadata-only files:_03(server-sideuuidv7()defaults on the child/workflow tables),_07–_09(per-column LZ4 TOAST compression; existing rows keep their current representation until the row is next rewritten),_11(the transactional archive-index drop), and_12(the queue's own default, isolated so thejobslock is never held while queuing for a child table). - Two non-transactional
DROP INDEX CONCURRENTLYfiles (_02,_10, both carrying the-- taskq:no-transactiondirective): they take noACCESS EXCLUSIVElock at all.
Run the ACCESS EXCLUSIVE files in a quiet window. The lock each one holds
is brief, but a queued ACCESS EXCLUSIVE request stalls every later
statement on that table behind it — so one long-running transaction turns a
millisecond of DDL into a queue-wide wait. If a transactional file fails on
the migration's lock timeout or a deadlock it rolled back whole: drain the
holder and re-run taskq migrate up. The two concurrent drops are re-run
the same way, and the runner's failure report names any INVALID index an
interrupted attempt left behind; see
If a migration goes wrong.
Default-on workflow leader sweeps¶
Two leader-sweep arms switch ON with this upgrade and start acting at the first post-upgrade sweep — no flag, no migration step:
- the workflow outbox arm (the fired joins' consumer deliveries): delivered outbox rows past the retention period prune, one bounded batch per pass — the period defaults to 24h;
- the step-cache sweep: the cross-run cache's expired results prune on the leader's cadence — the sweep period defaults to 1h.
The other five flow-history retention arms stay OFF until an operator sets their retention period (the zero-means-off setting: nothing is armed until a period is declared). The two on-by-default arms delete only EXPIRED or DELIVERED data — never a run's history.
The adoption checklist¶
The whole sequence, in order — each step's failure stops the upgrade at the step that can still fix it:
- Bump the pin (
taskq-py==<new version>), sync, and confirm the app imports. taskq migrate status— expect the new round's count pending and zero drift. A drift line here means a database applied bytes this tree no longer ships: stop and reconcile before anything else.- The pre-phase job:
taskq migrate up --phase pre— additive DDL, safe against every running worker. - Roll the workers. The mixed fleet is safe in this window: old
workers read the new row shape unchanged; new workers read the old
rows unchanged. One exception: workflow executors across the
ctx.substepscope change must not overlap; see its cutover rule. - The post phase, once, by hand:
taskq migrate up --phase post— after the LAST worker is up. Never a baretaskq migrate upahead of the roll: the post phase lands immediately and old workers lose the ability to write workflow rows. - Validate the backfill (the round's VALIDATE step above): find a
violator, fix it,
ALTER TABLE ... VALIDATE CONSTRAINT. taskq migrate statusagain — zero pending, zero drift — then one smoke flow end to end (taskq flows listshows the run; the run page renders its graph).