Skip to content

@usine/engine/engine

The Run is canceled, but interrupting its active Attempt failed.

  • Schema.Class

new AttemptCancellationError(…args): AttemptCancellationError

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

AttemptCancellationError

readonly attemptId: string & Brand<"AttemptId">

readonly cause: unknown


The Event now owns a Run; submitting it again returns the same run id.

  • Schema.Class

new Claimed(…args): Claimed

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

Claimed

readonly eventId: string & Brand<"EventId">

readonly runId: string & Brand<"RunId">


No Run opened because this Item requires an explicit cycle-budget reset.

  • Schema.Class

new CycleBlocked(…args): CycleBlocked

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

CycleBlocked

readonly ask: CycleBudgetAsk

readonly eventId: string & Brand<"EventId">


An operation could not read or update the instance’s durable records.

  • Schema.Class

new EnginePersistenceError(…args): EnginePersistenceError

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

EnginePersistenceError

readonly cause: unknown

readonly operation: string


The Event stays in the ledger but can no longer open a Run.

  • Schema.Class

new Ignored(…args): Ignored

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

Ignored

readonly eventId: string & Brand<"EventId">

readonly reason: "superseded" | "revoked"


A running Attempt on the same Item must finish before this Event is reconsidered.

  • Schema.Class

new Queued(…args): Queued

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

Queued

readonly eventId: string & Brand<"EventId">


Records Events and manages their Runs through approval, execution, retry, and cancellation.

  • Context.ServiceClass

readonly Service: object

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

readonly approve: (runId, approval) => Effect.Effect<void, RunEngineError>

Records the operator’s approval Event and opens the Run’s gate; execution still waits for a Worker slot.

Parameter Type
runId RunId
approval Event

Effect.Effect<void, RunEngineError>

readonly cancel: (runId) => Effect.Effect<void, RunEngineError>

Cancels an open Run and interrupts its active Attempt. An already closed Run is unchanged.

Parameter Type
runId RunId

Effect.Effect<void, RunEngineError>

readonly drain: () => Effect.Effect<void>

Stops admitting Attempts, including retries, and waits for admitted work to settle. Interrupting this wait keeps admission closed until restart.

Effect.Effect<void>

readonly inspect: (runId) => Effect.Effect<RunSnapshot, RunEngineError>

Reads the Run’s current state, effective task and Agent, Step result, and Attempt history.

Parameter Type
runId RunId

Effect.Effect<RunSnapshot, RunEngineError>

readonly intervene: (runId, attemptId, intervention) => Effect.Effect<void, RunEngineError>

Addresses one current Attempt explicitly so an old drawer cannot steer its replacement.

Parameter Type
runId RunId
attemptId AttemptId
intervention Intervention

Effect.Effect<void, RunEngineError>

readonly reconcile: () => Effect.Effect<void, RunEngineError>

Starts a fiber for every open Run without one in this process, except Runs waiting for their approval, and opens the queued Events no closed Run continued. Also runs when the engine starts, then every ReconcileInterval.

Effect.Effect<void, RunEngineError>

readonly resolveFailure: (runId, attemptId) => Effect.Effect<void, RunEngineError>

Resolves the current failed Attempt’s attention without changing its outcome or starting work.

Parameter Type
runId RunId
attemptId AttemptId

Effect.Effect<void, RunEngineError>

readonly retry: (runId, amendment?) => Effect.Effect<void, RunEngineError>

Requests another Attempt for a failed Run using its existing Event and effective task and Agent.

Parameter Type
runId RunId
amendment? Option.Option<AttemptContext>

Effect.Effect<void, RunEngineError>

readonly revoke: (loop, itemKey) => Effect.Effect<ReadonlyArray<RunId>, RunEngineError>

Cancels unstarted Runs and discards queued Events for a Loop’s Item when it stops matching; running Attempts continue.

Parameter Type
loop LoopName
itemKey ItemKey

Effect.Effect<ReadonlyArray<RunId>, RunEngineError>

readonly submit: (submission) => Effect.Effect<SubmissionResult, RunEngineError>

Records a matching Event and claims its Run, or queues it behind the Item’s running Attempt. Repeated Events are deduplicated; execution continues separately.

Parameter Type
submission Submission

Effect.Effect<SubmissionResult, RunEngineError>

readonly transcript: (query) => Effect.Effect<ReadonlyArray<TranscriptEntry>, RunEngineError>

Reads the requested portion of an Attempt’s persisted transcript in append order.

Parameter Type
query TranscriptQuery

Effect.Effect<ReadonlyArray<TranscriptEntry>, RunEngineError>


Optional host-owned shutdown latch, provided before building an engine runtime. Completing it closes Attempt admission even while startup recovery is running. After startup, RunEngine.drain waits for admitted Attempts to persist their outcomes. Allocate a fresh latch for each runtime; it cannot be reopened (ADR 0023).

  • Context.ServiceClass

readonly Service: Deferred.Deferred<void, never>

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


The requested Attempt is no longer live, or its channel could not accept operator input.

  • Schema.Class

new RunInterventionRejectedError(…args): RunInterventionRejectedError

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

RunInterventionRejectedError

readonly attemptId: string & Brand<"AttemptId">

readonly message: string

readonly runId: string & Brand<"RunId">


No Run with the requested identity exists in this instance’s records.

  • Schema.Class

new RunNotFoundError(…args): RunNotFoundError

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

RunNotFoundError

readonly runId: string & Brand<"RunId">


The Run’s current state does not allow the requested operator action.

  • Schema.Class

new RunOperationRejectedError(…args): RunOperationRejectedError

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

RunOperationRejectedError

readonly operation: "approve" | "retry" | "resolveFailure"

readonly runId: string & Brand<"RunId">

readonly state: string


A matched Event with the Loop, Item, and execution choices that determine the work owed.

  • Schema.Class

new Submission(…args): Submission

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

Submission

readonly agent: Agent

readonly approval: "required" | "none"

readonly cycleGeneration: number & Brand<"CycleGeneration">

Capture before fetching trigger input. A reset supersedes older observations.

readonly cycleLimit: Option<number & Brand<"CycleLimit">>

Item Runs default to three rounds; schedule adapters explicitly supply None.

readonly event: Event

readonly itemKey: string & Brand<"ItemKey">

readonly loop: string & Brand<"LoopName">

readonly parentModel: Option<string & Brand<"ModelId">>

readonly repository: string & Brand<"RepositoryName">

readonly revision: string & Brand<"RepositoryRevision">

readonly step: string & Brand<"StepName">

readonly task: string & Brand<"AttemptTask">

IgnoreReason = typeof IgnoreReason.Type


RunEngineError = typeof RunEngineError.Type

The store’s failures plus the cancellation handshake failure only the engine raises.


RunStoreError = typeof RunStoreError.Type

Everything the store itself can fail with.


SubmissionResult = typeof SubmissionResult.Type

Whether a recorded Event owns a Run, waits behind running work, or can no longer open a Run.

const IgnoreReason: Schema.Literals<readonly ["superseded", "revoked"]>


const layerWithDatabase: <DatabaseError, DatabaseRequirements>(database) => Layer.Layer<CursorStore | CycleBudgets | ItemProjectionReader | ItemProjectionWriter | LoopControl | RepositoryLabelProjectionReader | RepositoryLabelProjectionWriter | RunEngine | RunReader, RunEngineError | DatabaseError, Crypto.Crypto | StepExecutor | TriggerCondition | DatabaseRequirements>

Provides Run execution and recovery on the supplied database, whose run tables are the only durable state of the Run lifecycle. The deployment supplies Crypto, which hashes dedup keys into Run ids, the Worker implementation through StepExecutor, and the trigger re-check for queued Events through TriggerCondition.

Type Parameter
DatabaseError
DatabaseRequirements
Parameter Type
database Layer.Layer<RunDatabase, DatabaseError, DatabaseRequirements>

Layer.Layer<CursorStore | CycleBudgets | ItemProjectionReader | ItemProjectionWriter | LoopControl | RepositoryLabelProjectionReader | RepositoryLabelProjectionWriter | RunEngine | RunReader, RunEngineError | DatabaseError, Crypto.Crypto | StepExecutor | TriggerCondition | DatabaseRequirements>


const ReconcileInterval: Context.Reference<Duration.Input>

How long the engine waits between reconciles after the one at startup, so an open Run whose fiber stopped, as on a store failure that outlasted its retries, is driven again without a restart. Provide another value to change it.


const RunEngineError: Schema.Union<readonly [typeof RunNotFoundError, typeof RunOperationRejectedError, typeof EnginePersistenceError, typeof AttemptCancellationError, typeof RunInterventionRejectedError]>

The store’s failures plus the cancellation handshake failure only the engine raises.


const RunStoreError: Schema.Union<readonly [typeof RunNotFoundError, typeof RunOperationRejectedError, typeof EnginePersistenceError]>

Everything the store itself can fail with.


const SubmissionResult: Schema.Union<readonly [typeof Claimed, typeof Queued, typeof Ignored, typeof CycleBlocked]>

Whether a recorded Event owns a Run, waits behind running work, or can no longer open a Run.