Harness APIs
Public harness subpaths and commonly used exports.
Import feature APIs from explicit subpaths. The root package is intentionally empty.
@yolk-sdk/harness is introduced after 0.1.0-canary.76. See Harness package for installation and a runnable memory-host drain.
Coordinator
@yolk-sdk/harness/coordinator
| Export | Purpose |
|---|---|
Promotable | 'input' | 'steer'; input subsumes steer when coalescing wakes |
CapturedRun | Started / Joined / Stopping waiter |
StopReceipt | Idle / Interrupted / LiveStopping / Settling |
Coordinator | Process-local doorbell coordinator shape |
makeCoordinator | Build a process-local coordinator |
RunCoordinator | Owning service; .layer({ drain, keepClaimOnSettle }) needs RunStore; keepClaimOnSettle true keeps an uninterrupted owner's claim |
The drain callback of RunCoordinator.layer and makeCoordinator gets a fourth argument,
stopping: an effect reading that execution's stopping flag. Forward it to Inbox.beginDrain.
Store
@yolk-sdk/harness/store
| Export | Purpose |
|---|---|
RunStore | Claim/release service |
RunStoreApi | Claim, release, claimed-id, and resume-count methods |
DurableRunStoreSnapshot | { claimed, resumes } snapshot |
makeInMemoryRunStoreLayer | Process-local claim store |
makeSnapshotRunStoreLayer | Persist claims through host load / save |
RunStore.inMemoryLayer() owns process-local claims; RunStore.snapshotLayer({ load, save })
owns snapshot-backed claims. Both build fresh layers without service dependencies. The existing
makeInMemoryRunStoreLayer / makeSnapshotRunStoreLayer factories delegate to these owners.
The snapshot stores claimed ids and resume counts. It is not transcript storage and does not persist Inbox items or HITL parks.
Inbox
@yolk-sdk/harness/inbox
| Export | Purpose |
|---|---|
Inbox | Admission, park, and drain-token service |
InboxApi | Service methods for admission, queueing, HITL parks, and drain tokens |
InboxItem | Queued input/HITL item (id, runId, delivery, kind) |
InboxKind | 'input' | 'hitl' |
ParkedResponse | { itemId, requestId } |
ParkedState | Generation, non-empty request ids, responses, ready |
HitlAdmission | { itemId, requestId, generation } |
HitlDecision | Accepted / Ready / Duplicate / Stale / UnknownRequest / NotParked |
PauseDecision | Parked or Stale |
DrainBegin | Skip or Run with drainToken and ready responses |
makeInMemoryInboxLayer | Process-lifetime Inbox |
DrainToken and ParkGeneration are also schema/type exports from this subpath. DrainContext,
dequeue/pause/end-drain contracts use DrainToken; park state, admission, and clearPark use
ParkGeneration. Forward values returned by the live Inbox. Custom adapters must construct/decode
these types; they still serialize as strings. The schemas intentionally validate only string shape,
not token format, freshness, or authorization.
Inbox.layer() owns a fresh process-local queue, admission gate, and HITL generations with no
service dependencies. makeInMemoryInboxLayer delegates to it.
park(runId, requestIds, drainToken) (and Driver.pause) takes a non-empty
Array.NonEmptyReadonlyArray<string>: a park with no request ids would be Ready at once and keep
the claim with nothing to wake the run. Map StepOutcome.AwaitingInput requests (non-empty) with
Effect's Array.map; check a host-built list with Array.isReadonlyArrayNonEmpty. The type
enforces this; an empty list at runtime (an untyped caller) is a defect that dies before any park
state changes.
takePromotable(runId, scope, drainToken) requires the live beginDrain token. Missing, empty, inactive, stale, or wrong-run tokens return undefined and do not dequeue.
beginDrain(runId, scope, stopping?) returns Skip without consuming pending intent when stopping reads true under the admission gate. Driver passes the owner's stopping flag, so a message admitted right after an interrupt drains in the successor. An Inbox implementation must read stopping under the same lock that consumes intent and, when it is true, return Skip without touching pending intent; a wrapper must forward it. Driver now runs beginDrain uninterruptibly, so keep it short and non-blocking.
Driver
@yolk-sdk/harness/driver
| Export | Purpose |
|---|---|
Driver | Run, wake, interrupt, admit, pause, resume, clear park, stop |
DriverApi | Driver service method contract |
Drain | Host execution; see signature below |
DrainContext | { drainToken, readyResponses } |
makeDriverLayer | Driver layer; default drain is Effect.void |
makeHarness | Merge driver + store + inbox layers |
admit | Enqueue an inbox item and wake |
defaultMaxResumeAttempts | 10 |
InvalidMaxResumeAttempts | Layer-init failure for invalid budgets |
ResumeSuspendedResult | { resumed, exhausted } |
StopDecision | Interrupted / ParkCleared / Idle |
InterruptReason | 'user' | 'shutdown' |
Driver.layer({ maxResumeAttempts }) requires RunStore, Inbox, and RunCoordinator.
Driver.coordinatedLayer({ drain, maxResumeAttempts }) wires the coordinator and requires only
RunStore and Inbox; makeDriverLayer delegates to it. Omitted budgets use the default; invalid
numeric budgets fail layer initialization with InvalidMaxResumeAttempts. Share the same store
and inbox instances across the composed layers, or use the memory/durable-object factories below.
Fragment. Exported Drain type:
type Drain = (
runId: string,
force: boolean,
scope: Promotable,
context: DrainContext
) => Effect.Effect<void, never, Inbox | RunStore>The driver provides Inbox and RunStore to the drain. Provide any additional host dependencies before passing drain.
interrupt acknowledges request delivery, not owner settlement. User stop releases a leftover claim after that owner has settled. Shutdown interrupt keeps the claim. A drain defect releases it, except while the run has a Ready park: the claim stays (also through a successor that skips and succeeds), and a later resumeSuspended in the same process re-delivers those answers under maxResumeAttempts. Hosts that want in-process recovery after a crashed continuation run resumeSuspended during runtime, not only at boot; after a restart the host rebuilds the park from its checkpoint.
clearPark(runId, generation) drops a park without its answers and wakes the run for input admitted while it blocked. Raw Inbox.clearPark takes that wake effect as its third argument.
@yolk-sdk/harness/driver/memory
| Export | Purpose |
|---|---|
makeInMemoryDriverLayer | In-memory driver over Store/Inbox |
makeInMemoryHarnessLayer | In-memory driver + store + inbox |
@yolk-sdk/harness/driver/durable-object
| Export | Purpose |
|---|---|
makeDurableObjectDriverLayer | Snapshot RunStore plus driver; Inbox stays in-memory |
DurableRunStoreSnapshot | Re-exported claim snapshot |
Fragment. Hosts supply load / save; this is not a Cloudflare runtime API:
import { Effect, Ref } from 'effect'
import { makeDurableObjectDriverLayer } from '@yolk-sdk/harness/driver/durable-object'
import type { DurableRunStoreSnapshot } from '@yolk-sdk/harness/store'
const snapshot = await Effect.runPromise(Ref.make<DurableRunStoreSnapshot | undefined>(undefined))
const DurableLayer = makeDurableObjectDriverLayer({
load: Ref.get(snapshot),
save: next => Ref.set(snapshot, next)
})That adapter does not persist Inbox, closures, or automatically reconstruct work.
Outcome
@yolk-sdk/harness/outcome
| Export | Purpose |
|---|---|
attemptModelTurn | Classify one runModelTurn after that stream's inner retries |
attemptToolBatch | Classify one runToolBatch; pending HITL fences the whole batch |
ModelTurnOutcome | Completed / Retry / Continue / RecoverFull / Compacted |
ToolBatchOutcome | Completed / AwaitingInput (non-empty requests) |
StepOutcome | Model or tool-batch outcome |
matchHitlResponse | Protocol identity match for a HITL response |
resumeHitlIfMatched | Resume only when kind/request/tool-call identity matches |
attemptModelTurn does not add an outer retry loop. Configured LoopConfig.maxRetries and provider retry decorators still apply inside that invocation. Hosts that own physical-attempt scheduling should pass maxRetries: 0 and skip retry decorators.
onEvent sink errors, compact errors, Abort, and mixed defect/interrupt Causes are not classified as provider Retry / Continue. Incomplete streams use responseIssue: 'missing_done' only (set by the kernel, or by a provider whose stream ended without its terminal event).