Repository navigation
Description
Source: API ergonomics review, PR #138 — docs/review/2026-09-12-api-ergonomics-review.md §P4 (verdict: DO LATER). Verified against current main.
Summary
Read paths return None for facts that are not the same fact:
get_batch→BatchRow | None(src/taskq/backend/_batch_sql.py:289-290; client wrappersrc/taskq/client/_jobs.py:959) —Noneconflates: never existed; existed and was pruned (prune_old_batches,_batch_sql.py:437-446); and created without afailure_policy/finalizer so no row was ever written (_jobs.py:579).JobsClient.get_row→JobRow | None(src/taskq/client/_jobs.py:1122) —Nonealso silently covers "pruned tojobs_archive", which a caller cannot distinguish from "bad job id" without a second query nobody writes.increment_batch_failuresencodes absence as a value —(0, None, 0)(_batch_sql.py:304).
TaskQ already solved this correctly once, in the newest part of the API: wait_for_batch defaults to on_empty="error" and raises EmptyBatchError rather than an ambiguous empty status (src/taskq/batch.py:392-393, src/taskq/exceptions.py:637-644), plus BatchAbortedError for the aborted case. The precedent simply was never applied to the older read paths.
Priority
DO LATER, deliberately: the measured harm in the source deployment was entirely in consumer code over a consumer-owned table; fixing TaskQ's get_batch would not have prevented any of the 20 defects. Right change on the merits, wrong change to prioritize against the dedup-warning, resolved-capacity, and per-item-isolation issues.
Proposal (additive — do not change existing signatures)
type BatchLookup = BatchFound | BatchPruned | BatchNeverExisted
async def lookup_batch(self, batch_id: UUID) -> BatchLookup: ...BatchPrunedis honestly distinguishable in principle — a terminal job injobs_archivecarrying thatmetadata.batch_id— which is what makes the three-way split real rather than cosmetic. Cost: an archive probe (second query) on a cold path; acceptable because lookups-by-id are operator/debug paths, not hot paths.- Same treatment available for job reads (
lookup_row/get_rowsibling distinguishingjobs_archive), andincrement_batch_failures' sentinel tuple should grow a typed result when touched for other reasons — not worth a standalone change.
Acceptance criteria
lookup_batchreturns a three-way typed result;get_batchunchanged and documented as ambiguous (docs note: "returns None for never-existed, pruned, and never-written — prefer lookup_batch").- Archive probe only runs when the live table misses.
- If/when a job-read sibling lands,
jobs_archivedistinction included. - No change to
wait_for_batch(already correct).
Related: terminal-dedup warning issue (review §P1) — both convert silent ambiguity into named outcomes.
Activity
rcbevans commentedon Sep 13, 2026
Triage note: this one carries its own deferral verdict (DO LATER, per the review's §P4) but had no owner — now assigned so the deferral is owned rather than silent.
rcbevans commentedon Sep 15, 2026
Disposition: deferred (DO LATER), per I-04 spec
Verified against current tree (
redteam/issue-sweep-post-203):JobsClient.get_batchstill returnsBatchRow | None(src/taskq/client/_jobs.py:1341; also exposed viaTaskQ.get_batch,src/taskq/client/_taskq.py:733, and the backend implementationssrc/taskq/backend/postgres.py:1305,src/taskq/backend/_batch_sql.py:349).JobsClient.get_rowstill returnsJobRow | None(src/taskq/client/_jobs.py:1536).lookup_batch(or job-read sibling) exists anywhere undersrc/taskq/.So the three-way ambiguity this issue describes (never-existed / pruned / created-without-finalizer-so-never-written) is real and still present. That said, this is unchanged, additive API surface — a new typed lookup alongside the existing (documented-as-ambiguous)
get_batch/get_row— not a defect, data-loss vector, or operationally critical gap. It carries no operator impact today: nothing silently corrupts state or misleads an operator: it's an ergonomics gap for a rare debug/id-lookup path, and the issue's own title already marks it "DO LATER."The I-04 initiative spec (
.shipwright/initiatives/I-04/spec.md) explicitly places this issue in Non-Goals and in the Decisions table (decision 1): scope is fixing defect/perf/data-loss/operationally-critical issues among the 53 triaged; #145 is deferred with a rationale comment and left open, alongside #68, #69, #142, #144.No code or test change follows from this triage pass. Left open, unassigned, per the deferred disposition (assignment is reserved for issues we are actively fixing).
rcbevans commentedon Sep 17, 2026
Deferred per the 0.3.0 triage decision and the author's DO LATER marker: the lookup_batch sibling is net-new functionality. The batch read machinery it would build on is stable.