Skip to Content
Runlane
Build providers

Transport provider

Publish wakeups and connect a broker-native worker to Runlane.

A transport provider connects Runlane to a broker such as SQS. The broker carries wakeups. Storage still holds the task payload and current run state.

A complete transport provider has two sides:

Runlane run outbox or schedule hints --> TransportDriver.publish() --> broker

broker --> ProviderDeliverySurface --> Runlane worker
                                      |
                                      v
                              handled / retry / reject

Import both contracts from @runlane/contracts.

Publish wakeups

TransportDriver.publish() receives a bounded array of messages. Each message already has canonical bytes, a message id, a logical queue, and an optional partition key.

PublishMessagesCommand.signal is required and remains the same AbortSignal instance after parsing. Core measures one monotonic budget from before the outbox claim write, including delayed commit responses and earlier chunks. It keeps contractDefaults.delivery.outboxSettlementReserve (currently 1 second) for recording results. When the budget runs out, core starts no more chunks, logs outbox_claim_budget_exhausted, and returns untouched rows for maintenance to publish.

The signal aborts when the outbox claim may expire. Stop waiting for capacity and do not start new sends after abort. parsePublishMessagesCommand() rejects a command whose signal is already aborted with a retryable transport_unavailable error, so call it before any I/O. If the signal aborts later, return retryable failed outcomes for messages not yet sent. A send already in flight may still arrive. Await every started request; return definite failures only for messages known not to have been sent, and reject when results are unknown. Cancellation does not replace exact claim-token settlement or prevent all duplicates.

The provider may group messages by destination or split them into native batches. It must return one outcome for each input, at the same array index.

What happenedWhat the provider returns
The broker accepted one itempublished at that item's index
One item failed and the result is certainfailed at that item's index
The whole request failed and item results are unknownReject the call

A message can also carry availableAt, its earliest delivery time. Advertise profile.limits.maxDelaySecondsByQueue for destinations that support per-message delayed delivery, with each logical queue mapped to its supported window in seconds. Missing queues or zero retain due-only publication. Core can then publish scheduled wakeups before their fire time; the provider must hold them until availableAt. Round coarse broker delays up so a future wakeup cannot be acknowledged before storage permits execution. Without the capability, core leaves armed schedule fires for maintenance and publishes run wakeups only when due. Reject unsupported delays with a structured adapter error.

Do not change the canonical message bytes. Return copies of mutable bytes and dates.

Deliver wakeups

ProviderDeliverySurface connects a native consumer to one Runlane DeliveryProcessor.

For each broker message:

  1. Read its Runlane bytes.
  2. Pass the bytes to the processor.
  3. Map the returned disposition to the broker action.
Runlane dispositionBroker action
handledAcknowledge, delete, or commit the message
retryLeave it available for another delivery
rejectComplete the configured terminal action

If terminal handling fails, do not acknowledge the original rejected message. An unexpected processor error is retryable.

Supply the broker's receive count through DeliveryAttempt.deliveryCount when available. See delivery counts for the contract and retry policy.

Retry may include retryAfterMs, a positive integer delay in milliseconds measured from the retry decision. Core owns when to request it: retryable storage conflicts on native delivery 1 at the run-claim boundary use contractDefaults.delivery.claimConflictRetryDelayMs. Do not derive a delay from the failure code; core omits the field for later deliveries and for conflicts outside the claim. When the field is absent, preserve the provider's existing visibility or retry backoff. Do not accelerate retries for pauses, missing handlers, outages, unexpected processor errors, or malformed dispositions.

Providers that can change native retry timing should apply the requested delay without acknowledging or republishing the message. Round coarse native delays up. Keep receipt ownership and generation fences, drain renewal first, and never change an early-acknowledged receipt or one whose renewal failed. Native limits or platforms that cannot apply the delay retain their existing retry behavior. This is a scheduling hint, not a guarantee of delivery at that time; duplicate delivery remains possible.

SQS workers change visibility (up to the native 12-hour limit). Redis Streams adjusts the fenced pending receipt's idle time for delays within its visibility interval; normal bounded reclaim scans still determine pickup time. Direct HTTP omits deliveryCount and uses the shared outbox delay for Retry-After; its best-effort publisher keeps the existing outbox/cooldown retry policy. Lambda returns partial batch failures and leaves timing to the event source mapping. Storage-polling and local lanes have no retained native receipt to reschedule.

The provider owns receipt handles, offsets, visibility extensions, consumer groups, dead-letter configuration, and settlement. Those details do not enter core.

Defer the next schedule fire

Set DeliveryAttempt.scheduleNextFire: TriggerDispatchMode.Deferred when a platform limits recursive delivery chains. When accepting a schedule wakeup, core then leaves the next fire's arming and wakeup to maintenance. Omission or TriggerDispatchMode.Eager preserves runtime lookahead. The current fire's run, run wakeups, refill, and handoffs keep their existing behavior. See SQS Lambda policy for the first-party use.

Acknowledge after the claim

DeliveryAttempt.acknowledge?: () => void lets a provider settle its native message before the handler finishes. Core calls it at most once, just after storage commits the worker's claim on the run and before the handler runs. Core does not call it for an ignored wakeup or a failed claim. From that point, the lease and maintenance own run recovery. A schedule wakeup has no claim: core calls acknowledge once storage saves the run for its fire, before that run's wakeup is published. From then on, the saved run, not the message, drives its delivery.

The callback should not throw. If it does, core logs delivery_acknowledge_failed and still runs the handler under the committed lease. The provider owns asynchronous settlement, failure reporting, and draining that work on close. Stop native visibility or lock renewal before early settlement, and wait for any renewal already in flight. Make repeated calls safe and avoid settling the same message again when the processor returns handled.

Omit the callback when the native message must stay held until completion. For example, an in-flight SQS FIFO message keeps the next message in its group from starting on another worker. Such providers keep using the final disposition for settlement.

Report the time budget

DeliveryAttempt.handoffAt?: Date is a host-clock deadline. Derive it from the host budget and handoffBefore; when unset, reserve contractDefaults.delivery.handoffReserveFraction of the budget. See invocation handoff.

Abort DeliveryAttempt.signal with createPlatformTimeLimitError() when the host's time limit is reached. Core treats any other abort reason as an external abort, which never counts as an interruption.

Capacity refill on synchronous delivery

DeliveryAttempt.refill?: TriggerDispatchMode can defer unrelated capacity-release dispatch for one attempt. Omit it to use the runtime policy. Eager does not turn on eager dispatch in a runtime configured for deferred dispatch. Use TriggerDispatchMode.Deferred when publication directly waits for the next task to execute, so settling one completed message does not recursively execute the backlog. Core leaves those waiting runs in storage for maintenance. The HTTP provider selects this automatically for best-effort in_request delivery. Durable broker-backed HTTP adapters keep eager refill.

This policy does not defer the delivered attempt. Producer calls within that delivery try only their named runs, including explicit children and the delivered run’s ready continuation. They preserve queue order: if an older head blocks a named run, maintenance admits it later. It starts no after-response work. Keep maintenance enabled. Broker providers normally omit it because publishing a successor waits for broker acceptance rather than task execution. No application setting or required provider operation is added.

Choose the worker shapes

A provider can expose either or both:

  • createWorker() for a long-running receive loop;
  • createHandler({ deliver, environment }) for a platform-native serverless handler. The receiving runtime environment is required, including when calling the factory directly. Use it for receiver-bound authentication rather than trusting the message.

A long-running worker must support cooperative close() and observable waitUntilClosed(). Repeated closes should be safe. A background failure must reject waitUntilClosed().

Core passes its environment to native handler factories for receiver-bound authentication. HTTP requires it; other providers can ignore it. The native handler generic remains provider-owned. See HTTP delivery adapters.

Keep a serverless handler's native type in the lane generic. Do not add platform-specific event unions to Runlane core.

Report the real transport profile

Declare:

  • maximum bytes in one message;
  • maximum messages in one publish call;
  • durability after the broker acknowledges a publish;
  • whether ordering is absent or preserved within a partition for messages the broker accepts.

Broker ordering and Runlane queue concurrency are separate controls.

A failed per-message publish outcome has no broker position. If the caller retries it later, that retry is a later publish and may follow messages the broker already accepted from the original command. Do not claim original-command ordering across rejected entries unless the provider implements a durable sequencer or an equivalent guarantee.

Expect duplicate wakeups

A publish can succeed just before the publisher loses the response. Brokers can also redeliver messages.

Pass every valid wakeup to core. Do not treat the broker message as the job or invent provider-side run state. Core re-reads storage and decides whether the run can execute.

Prove the provider

Test batch results, partial failures, settlement, malformed messages, visibility or lock refresh, ordering, cancellation, and shutdown. Then run the same cases against the real broker.

Continue with test a provider. @runlane/transport-sqs provides a reference implementation, and the exact stable values are in delivery values.

Wakeup purpose

Canonical envelopes are version 3 and form a union tagged by type. run_wakeup and run_hooks_wakeup carry runId. schedule_wakeup carries scheduleId and fireAt, with no run ID. All types carry environment, queue, optional request time, and optional trace fields. Encode and decode through the shared contract functions. Providers carry these bytes without interpreting schedule or task policy.

Schedule hints publish directly when a future fire is armed and the queue can delay delivery until availableAt. They have no outbox row. Their publish failures are logged; the armed record provides recovery. Every outbox row still belongs to a run. Deliver all valid message types to core, which routes them by their type tag.

Publish lifetime

A transport profile may advertise publishTimeout, a positive whole number of milliseconds. Derive it from the provider's configured publish timeout. Core claims outbox rows for the larger of the default lease and this timeout plus contractDefaults.delivery.outboxSettlementReserve. The same duration bounds eager claims, maintenance claims, and publish abort signals. This lets slow synchronous transports keep ownership while they await a response. Omit it when the provider uses the default claim budget.

On this page