Skip to content

Durable, lease-based task queue (crash-recovery + exactly-once)#38

Merged
Jacobobber merged 1 commit into
mainfrom
feat/task-queue
Jul 8, 2026
Merged

Durable, lease-based task queue (crash-recovery + exactly-once)#38
Jacobobber merged 1 commit into
mainfrom
feat/task-queue

Conversation

@Jacobobber

Copy link
Copy Markdown
Owner

Closes the two gaps the harness research flagged as the biggest: a crash loses in-flight work, and a shared backlog double-runs. TaskQueue is crash-recovery + exactly-once on SQLite.

  • enqueue(do, args=...) writes a pending task to disk.
  • claim(worker) hands one worker exactly one task under a write-locked transaction, so concurrent workers never grab the same one, and leases it.
  • If the worker that claimed a task dies without completing it, the lease expires and the task becomes claimable again (at-least-once; a dead worker doesn't strand it).
  • complete(id) is idempotent by id, so a re-run cannot overwrite a recorded result.
  • result / outstanding survive a restart, so a resuming orchestrator sees what is still in flight.

A coordination/durability primitive; the auth boundary stays on the tools a worker calls with its scoped token. Complements the A2A orchestrator (broadcast/addressed coordination) with a claimed, durable work queue.

7 new tests: enqueue/claim/complete/result, one-task-per-worker (no double hand-out), empty-queue claim, expired-lease reclaim, idempotent complete ignoring a stale re-run, outstanding/pending counts, and survives-across-instances (restart). 286 tests, mypy --strict, ruff (whole repo), catalog-freshness green. Backward compatible; v1.5.0.

Closes the two gaps the harness research flagged: crash loses work, and a
shared backlog double-runs. TaskQueue on SQLite:

- claim() hands one worker exactly one task under a write-locked transaction,
  so concurrent workers never grab the same one.
- an expired lease makes an abandoned task claimable again (a dead worker does
  not strand it); complete() is idempotent by id, so a re-run cannot overwrite
  a recorded result.
- results + backlog survive a restart; outstanding() lets a resuming
  orchestrator see what is still in flight.

A coordination/durability primitive; the auth boundary stays on the tools a
worker calls with its scoped token.

286 tests (+7), mypy --strict, ruff (whole repo), catalog freshness all green.
v1.5.0.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Jacobobber Jacobobber merged commit cdbce31 into main Jul 8, 2026
12 checks passed
@Jacobobber Jacobobber deleted the feat/task-queue branch July 8, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant