Yolk SDK
API reference

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

ExportPurpose
Promotable'input' | 'steer'; input subsumes steer when coalescing wakes
CapturedRunStarted / Joined / Stopping waiter
StopReceiptIdle / Interrupted / LiveStopping / Settling
CoordinatorProcess-local doorbell coordinator shape
makeCoordinatorBuild a process-local coordinator
RunCoordinatorOwning 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

ExportPurpose
RunStoreClaim/release service
RunStoreApiClaim, release, claimed-id, and resume-count methods
DurableRunStoreSnapshot{ claimed, resumes } snapshot
makeInMemoryRunStoreLayerProcess-local claim store
makeSnapshotRunStoreLayerPersist 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

ExportPurpose
InboxAdmission, park, and drain-token service
InboxApiService methods for admission, queueing, HITL parks, and drain tokens
InboxItemQueued input/HITL item (id, runId, delivery, kind)
InboxKind'input' | 'hitl'
ParkedResponse{ itemId, requestId }
ParkedStateGeneration, non-empty request ids, responses, ready
HitlAdmission{ itemId, requestId, generation }
HitlDecisionAccepted / Ready / Duplicate / Stale / UnknownRequest / NotParked
PauseDecisionParked or Stale
DrainBeginSkip or Run with drainToken and ready responses
makeInMemoryInboxLayerProcess-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

ExportPurpose
DriverRun, wake, interrupt, admit, pause, resume, clear park, stop
DriverApiDriver service method contract
DrainHost execution; see signature below
DrainContext{ drainToken, readyResponses }
makeDriverLayerDriver layer; default drain is Effect.void
makeHarnessMerge driver + store + inbox layers
admitEnqueue an inbox item and wake
defaultMaxResumeAttempts10
InvalidMaxResumeAttemptsLayer-init failure for invalid budgets
ResumeSuspendedResult{ resumed, exhausted }
StopDecisionInterrupted / 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

ExportPurpose
makeInMemoryDriverLayerIn-memory driver over Store/Inbox
makeInMemoryHarnessLayerIn-memory driver + store + inbox

@yolk-sdk/harness/driver/durable-object

ExportPurpose
makeDurableObjectDriverLayerSnapshot RunStore plus driver; Inbox stays in-memory
DurableRunStoreSnapshotRe-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

ExportPurpose
attemptModelTurnClassify one runModelTurn after that stream's inner retries
attemptToolBatchClassify one runToolBatch; pending HITL fences the whole batch
ModelTurnOutcomeCompleted / Retry / Continue / RecoverFull / Compacted
ToolBatchOutcomeCompleted / AwaitingInput (non-empty requests)
StepOutcomeModel or tool-batch outcome
matchHitlResponseProtocol identity match for a HITL response
resumeHitlIfMatchedResume 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).

On this page