Skip to content

@usine/durable/harness

The orchestrator’s pi-durable Harness over one storage. A commit that fails after storage admission poisons the whole Session; the harness detects it, closes the Session, opens the storage again, and resumes its tasks. A step pi-durable keeps retrying without progress is handled the same way, and stops the harness for good when the reopened harness gets stuck again.

  • Context.ServiceClass

readonly Service: object

The service’s operations: what yield* DurableHarness returns.

readonly defaultModel: Option.Option<ModelRef>

readonly install: (extension) => Effect.Effect<void>

Installs or replaces an extension; conversations that select it by name use the new code from their next phase.

Parameter Type
extension Extension

Effect.Effect<void>

readonly models: Models

readonly resume: (beforeResume) => Effect.Effect<void, DurableHarnessError>

Runs beforeResume on the open harness, then starts the task scheduler; every reopen does both again. Call it once every extension is installed: a generation resumed earlier would be prepared without the tools its conversation selects.

Parameter Type
beforeResume BeforeResume

Effect.Effect<void, DurableHarnessError>

readonly subscribe: (listener) => Effect.Effect<void, never, Scope.Scope>

Observes commits, reopens, and the stop while the scope is open.

Parameter Type
listener HarnessListener

Effect.Effect<void, never, Scope.Scope>

readonly use: <A>(operation, run) => Effect.Effect<A, DurableHarnessError>

Runs one call against the open harness. A call that fails because the Session was poisoned or replaced runs once more on the reopened harness, so it must be safe to repeat. Once the harness has stopped, every call fails with the reason it stopped.

Type Parameter
A
Parameter Type
operation string
run (harness, context) => Promise<A>

Effect.Effect<A, DurableHarnessError>


A pi-durable call failed: the harness could not open, commit, read, or wait.

  • Schema.Class

new DurableHarnessError(…args): DurableHarnessError

Parameter Type
…args [props: object, options?: MakeOptions]

DurableHarnessError

readonly cause: unknown

readonly message: string

readonly operation: string

What the harness runs on.

readonly defaultModel: Option<ModelRef>

The parent model when an Attempt names none; absent means the first model with a configured credential.

readonly models: Models

pi-ai model access for generation and parent model resolution.

readonly openStorage: Effect<Storage, DurableHarnessError>

Opens the storage; run again to reopen after a poisoned or stuck Session.


Observes the open harness, across reopens.

readonly onCommit: (publication) => void

Runs synchronously after every adopted commit; it must not block, throw, or call the harness.

Parameter Type
publication CommitPublication

void

readonly onReopen: () => void

Runs once a poisoned or stuck Session has been replaced by a freshly opened and resumed harness.

void

readonly onStop: () => void

Runs once the harness has stopped for good; every later call fails with the reason.

void

BeforeResume = (harness) => Effect.Effect<void>

Repairs storage through a freshly opened harness before its tasks run; it logs its own failures and never fails.

Parameter Type
harness Harness

Effect.Effect<void>

const durableError: (operation, cause) => DurableHarnessError

Wraps a failed pi-durable call, naming what it was doing.

Parameter Type
operation string
cause unknown

DurableHarnessError


const layer: (options) => Layer.Layer<DurableHarness, DurableHarnessError>

Opens the harness for the layer’s lifetime; it is closed, without writing any task outcome, when the layer ends.

Parameter Type
options DurableHarnessOptions

Layer.Layer<DurableHarness, DurableHarnessError>


const StuckStepReports: Context.Reference<number>

How many reports of one failure, with no commit adopted between them, mean pi-durable keeps retrying a step that cannot succeed. Its scheduler retries such a step at once, in microtasks, so until the harness closes the process runs no timer and no I/O. Provide another value to change it.