Skip to content

get_batch/get_row return None for three different facts: add unambiguous lookup_batch sibling (DO LATER) #145

Open

Description

@rcbevans

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 wrapper src/taskq/client/_jobs.py:959) — None conflates: never existed; existed and was pruned (prune_old_batches, _batch_sql.py:437-446); and created without a failure_policy/finalizer so no row was ever written (_jobs.py:579).
  • JobsClient.get_row → JobRow | None (src/taskq/client/_jobs.py:1122) — None also silently covers "pruned to jobs_archive", which a caller cannot distinguish from "bad job id" without a second query nobody writes.
  • increment_batch_failures encodes 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: ...
  • BatchPruned is honestly distinguishable in principle — a terminal job in jobs_archive carrying that metadata.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_row sibling distinguishing jobs_archive), and increment_batch_failures' sentinel tuple should grow a typed result when touched for other reasons — not worth a standalone change.

Acceptance criteria

  • lookup_batch returns a three-way typed result; get_batch unchanged 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_archive distinction included.
  • No change to wait_for_batch (already correct).

Related: terminal-dedup warning issue (review §P1) — both convert silent ambiguity into named outcomes.

Activity

  1. self-assigned this
    on Sep 13, 2026
  2. rcbevans commented on Sep 13, 2026

    @rcbevans
    ContributorAuthor

    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.

  3. rcbevans commented on Sep 15, 2026

    @rcbevans
    ContributorAuthor

    Disposition: deferred (DO LATER), per I-04 spec

    Verified against current tree (redteam/issue-sweep-post-203):

    • JobsClient.get_batch still returns BatchRow | None (src/taskq/client/_jobs.py:1341; also exposed via TaskQ.get_batch, src/taskq/client/_taskq.py:733, and the backend implementations src/taskq/backend/postgres.py:1305, src/taskq/backend/_batch_sql.py:349).
    • JobsClient.get_row still returns JobRow | None (src/taskq/client/_jobs.py:1536).
    • No lookup_batch (or job-read sibling) exists anywhere under src/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).

  4. removed their assignment
    on Sep 15, 2026
  5. rcbevans commented on Sep 17, 2026

    @rcbevans
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions