@techsavvyash/pad records work that agents and people share: tasks with dependencies and owners, claims on them, the attempts that run them on executors, and the blockers that stop them. Every change goes through a checked state machine and is published as an event, so other parts of dough can react.

It’s the pad from clanker (dough-quiver, packages/clanker/src/pad), moved into dough as its own package. The names, the behaviour and the store contract are clanker’s. The internals now run on Effect 4, with a Promise API on top for code that doesn’t use Effect.

There is no dough pad command yet. This is the library.

npm install @techsavvyash/pad @techsavvyash/bus effect

The model

  • Task: a unit of work, draft or created to start with. It moves through ready, assigned, in_progress, blocked and review_required to completed, failed or cancelled. canTransition holds the allowed moves; the three end states have none.
  • Tree and owner: a task can have a parent. A tree has one rootTaskId, which every event carries as its correlationId, and at most one ownerId. Children inherit the owner, and dependencies never cross owners, so one user’s task data never flows into another user’s work.
  • Dependencies: a task can’t become ready until every dependency is completed. When the last one completes, a created dependent is promoted to ready on its own.
  • Claim: a lease on a task. The store’s claim is a compare-and-set: it succeeds when the task is unclaimed, already held by the same actor, or held by a claim that has expired.
  • Attempt: one run of a task on an executor, requested to completed, failed, timed_out or cancelled. Its status drives the task’s: running starts the task, completed completes it, and failed or timed_out fails it.
  • Blocker: a reason a task can’t continue. Opening one blocks the task. Resolving the last one makes it ready again. An expired blocker leaves the task blocked.

Pieces

ExportWhat it does
PadServiceEvery mutation: create, update, assign, claim, transition, attempts, blockers. It persists, then emits.
TaskStoreThe storage contract (22 methods). MemoryTaskStore, JsonlTaskStore and RemoteTaskStore implement it.
runTaskStoreConformanceA node:test suite any TaskStore must pass. The memory, JSONL and remote stores all run it.
ExecutorDispatcherPicks an executor for each requested attempt and hands the run to the ExecutorHandler for its kind.
ReconcilerA sweep to run on a timer: times out stale attempts, expires blockers, reaps expired claims, promotes ready.
createPadServer, handlePadRpcThe TaskStore over HTTP: POST /v1/pad/<method> with { "args": [...] }.
canTransition, matchesTaskFilter, and moreThe plain helpers: transition tables, filter and ordering predicates, isStaleAttempt, capability matching.
PAD_EVENT_TYPES, registerPadEventTypesThe event types the pad emits on the bus (pad.task.*, pad.attempt.*, pad.blocker.*, executor.run.*).

Promise API

The same shape as clanker’s:

import { EventBus, EventTypeRegistry, MemoryEventStore } from "@techsavvyash/bus/promise";
import { JsonlTaskStore, PadService, registerPadEventTypes } from "@techsavvyash/pad";
 
const registry = new EventTypeRegistry();
registerPadEventTypes(registry);
const bus = new EventBus({ store: new MemoryEventStore(), registry });
 
const store = new JsonlTaskStore(".pad");
const pad = new PadService({ store, bus });
 
const task = await pad.createTask({ title: "Review the PR", requiredCapabilities: [{ name: "review" }] });
await pad.transitionTask({ taskId: task.id, toStatus: "ready" });
await pad.createAttempt({ taskId: task.id }); // emits executor.run.requested

Errors are classes you can instanceof: PadNotFoundError (with entityKind and entityId), PadConflictError, PadStoreClientError (with the HTTP status, -1 for a transport failure) and PadServerConfigError. An error your own store throws comes back to you unchanged.

Effect API

Each Promise class has an Effect twin, and the Promise class is a thin wrapper over it:

PromiseEffect
TaskStoreTaskStoreEffect (the same methods, as Effects)
new MemoryTaskStore()memoryTaskStore()
new JsonlTaskStore(dir)jsonlTaskStore(dir)
new RemoteTaskStore(options)remoteTaskStore(options)
new PadService(options)makePadService(options), also pad.effect
new Reconciler(options)makeReconciler(options), also reconciler.effect
handlePadRpchandlePadRpcEffect
registerPadEventTypesregisterPadEventTypesEffect

The Effect API takes the Effect bus (EventBusService from @techsavvyash/bus); the Promise classes take the Promise EventBus from @techsavvyash/bus/promise and use its .effect.

Store failures are typed as PadError: PadNotFoundError, PadConflictError, PadStoreClientError, or PadIOError for anything else, with the original error as its cause. Service calls can also fail with the bus’s BusError (together, PadServiceError). fromTaskStore(store) wraps a Promise store as an Effect store; EffectTaskStore (or toTaskStore) goes the other way.

import { EventTypeRegistry, makeEventBus, makeMemoryEventStore } from "@techsavvyash/bus";
import { Effect } from "effect";
import { makePadService, memoryTaskStore, registerPadEventTypesEffect } from "@techsavvyash/pad";
 
const registry = new EventTypeRegistry();
await Effect.runPromise(registerPadEventTypesEffect(registry));
const bus = makeEventBus({ store: makeMemoryEventStore(), registry });
 
const pad = makePadService({ store: memoryTaskStore(), bus });
const program = pad.transitionTask({ taskId: "t1", toStatus: "ready" }).pipe(
  Effect.catchTag("PadNotFoundError", (e) => Effect.logWarning(e.message))
);

The JSONL store

JsonlTaskStore(dir) appends one record per line to dir/pad.jsonl. The last record for a task, attempt or blocker wins, and transitions accumulate. Every operation reads the file again, so two instances on one directory see each other’s writes. Each line is decoded with a Schema. A line that doesn’t decode is skipped and left in the file. If a crash cut off the last record before its newline, the next write starts a new line, so it isn’t lost with the fragment.

Operations on one instance run one at a time, so claim is a real compare-and-set within a process. Two processes sharing the file can still race a claim. For that, use a store with storage-level locking, like the gateway’s Postgres store.

Events and the bus

The pad publishes on @techsavvyash/bus. Events carry source: "pad" ("reconciler" and "executor-dispatcher" for theirs), subject (the task id) and correlationId (the root task id), so one job’s events can be followed across a tree. Register the types on the bus’s registry first, with registerPadEventTypes (Promise registry) or registerPadEventTypesEffect (Effect registry). An unregistered type fails when it’s emitted.

The pad emits after it persists: a call does all its writes, then publishes their events in order. If the bus refuses an event, the call fails with the bus’s error, but what was written stays written. Subscribers run after the writes, so they can call back into the pad. The ExecutorDispatcher subscribes to executor.run.requested on the same bus.

How the gateway will use it

dough-gateway runs pad as a product. It keeps tasks in Postgres with its own TaskStore, PadRepo, and serves the RPC with clanker’s handlePadRpc and isPadMethod. Moving it from @techsavvyash/clanker to this package is an import change:

  1. Depend on @techsavvyash/pad and change the pad imports (TaskStore, the record and filter types, PadConflictError, PadNotFoundError, handlePadRpc, isPadMethod, canTransition, sameActor, matchesTaskFilter, orderTasks, isStaleAttempt and the other helpers) from @techsavvyash/clanker to @techsavvyash/pad. The names and signatures are the same.
  2. PadRepo keeps implementing TaskStore with Promises. It needs no Effect.
  3. Its conformance test imports runTaskStoreConformance from @techsavvyash/pad and passes as it does today.
    transitionTask still records the transition before it replaces the task, with the same status and time, so PadRepo’s cleanup of a transition it refused still matches.
  4. Hosts that talk to the gateway’s pad keep using RemoteTaskStore. The wire format hasn’t changed.

Errors are now Data.TaggedError classes, so they also carry a _tag. instanceof, message, name, entityKind and entityId behave as before.

How dough agents will use it

A dough agent, or the dough CLI, runs makePadService over a TaskStoreEffect: jsonlTaskStore for a local pad, or remoteTaskStore pointed at the gateway. It gets typed errors without a Promise layer in between. The same task, attempt and blocker records then show up in the gateway’s dashboard and in local tools.

Changes from clanker

The port keeps clanker’s behaviour. These are the differences:

  • A call’s writes happen together, then its events go out. Each PadService call does its writes, and every write they cause (auto-readiness, an attempt’s effect on its task, a blocker’s), as one step under a per-service lock. Then it publishes their events, in the same order as before. In clanker each write emitted as it went, so a subscriber could act in between: a claim or update could be overwritten by a transition, two racing transitions could both succeed, and an inline subscriber that completed an attempt as soon as it started left the task in_progress for good. pad.effect.exclusive(...) lets other code (the reconciler’s claim reaping) take the same lock. If publishing fails, the call fails, and the writes stay. The lock is per service, so two processes on one store can still race; that needs a compare-and-set in the store.
  • Transitions write over the current record. After recording the transition, transitionTask and transitionAttempt read the record again and change only its status (and output, error and timestamps), so a claim, update or heartbeat written meanwhile by anyone else is kept. If the status itself moved meanwhile, the call fails with PadConflictError. Clanker wrote back the copy it read first.
  • Re-parenting keeps the tree consistent. Moving a task under a new parent moves it and its descendants to the new tree’s rootTaskId (each gets a pad.task.updated), and detaching it (parentId: null) makes it its own root. Moving a task under itself or one of its descendants fails. Clanker changed only parentId, leaving the subtree on its old root.
  • The reconciler decides again before it acts. It reaps a claim, or times out an attempt, only if that still holds for the record as it is under the service’s lock (pad.effect.exclusive, pad.effect.transitionAttemptIf). A claimant that renewed, or a worker that sent a heartbeat, after the sweep listed its candidates keeps its lease or its run. A task the readiness sweep finds has moved on is skipped instead of failing the sweep. Clanker acted on what it had listed.
  • Reconciler batches count only eligible work. Each sweep lists all candidates and stops after batchSize it acted on. Clanker asked the store for the first batchSize candidates, so ones it couldn’t act on (an attempt with no timeout policy, a dependent with open dependencies, a blocker that only reminds) could fill every batch and starve the rest. Expiries now go before reminders for the same reason. With a remote store, a sweep fetches every candidate.
  • An attempt’s own capabilities pick its executor. The dispatcher matches executors against attempt.requiredCapabilities, which is the task’s unless createAttempt overrode it, and uses the default executor when the attempt names none. Clanker matched against the task’s, so an override was ignored and a later edit to the task rerouted queued attempts.
  • The reference server survives a malformed request. A bad Host header gets a 400, and anything unexpected in a request is a 500. In clanker it crashed the process.
  • A write after a torn JSONL record is kept. Clanker appended straight after a fragment with no newline, so the next record joined it and was skipped on read.
  • JSONL claims are serialised. Clanker’s JsonlTaskStore read and then appended with awaits in between, so two concurrent claims on one instance could both win. Operations on one instance now run one at a time. There’s a test for it.
  • JSONL records are Schema-decoded. A line that’s valid JSON but not a valid record (a missing field, an unknown status) is now skipped like an unparseable one, where clanker would have loaded it.
  • Store errors keep their identity. A foreign store’s error passes through the Effect core and reaches the Promise caller unchanged. Inside Effect it’s a PadIOError with the original as cause.
  • Errors carry a _tag. See above.
  • The bus is @techsavvyash/bus. Clanker’s own EventBus is replaced by the ported one, so the Promise classes take EventBus from @techsavvyash/bus/promise.
  • RPC arguments and results aren’t Schema-decoded. They’re positional TaskStore arguments, as in clanker. Decoding them would drop fields a newer peer sends.
  • Bus: pad’s only dependency in dough. Every Promise or Effect pad service needs a bus to publish on.
  • Messages, Sesh and Threads: not used, and none of them use pad.

Not yet

  • A dough pad command in the CLI.
  • Pad tools for the Claude Code plugin and the Pi extension.