HTTP transport options
Options, wire values and result mapping for the direct HTTP transport.
Import createHttpDeliveryProvider, createDirectHttpAdapter, httpTransportDefaults, httpDeliveryHeaders, HttpLifetimeMode, and HttpResponseType from @runlane/transport-http. The package requires Node.js >=22.18.0.
Provider
createHttpDeliveryProvider(options) returns { publisher, queues, surface }. Compose its publisher and surface into createLane(); call the runtime's createDeliveryHandler() to obtain (Request) => Promise<Response>. The native factory receives the receiver environment from core.
| Option | Meaning / default |
|---|---|
adapter | Required HttpDeliveryAdapter; owns service publishing, verification and response rules. |
queues | Required non-empty list of distinct full queue definitions. Producers and receivers must agree on policies. |
lifetime | Required, with no default: HttpLifetimeMode.InRequest ('in_request') or HttpLifetimeMode.Process ('process'), or (work: Promise<void>, request: Request) => void. The function registers active work with the host before the reply. |
maxInFlight | Pre-claim HTTP admission limit, default 8 from httpTransportDefaults.maxInFlight. Claim acknowledgment releases admission while work continues. |
maxWaiting | Maximum waiting requests, default 100. Excess requests get 429 immediately. |
admissionWait | Positive duration, default '3s'; maximum wait for a pre-claim permit before 429. |
handoffBefore | Requires lifetime: 'in_request' and maxDuration. Positive duration reserved before maxDuration for saved-step handoff, or false to disable. Unset reserves 25% of the budget. See handoff guidance. |
maxDuration | Optional cooperative handler deadline, allowed only with in_request. When the adapter advertises publishTimeout, it must be greater than maxDuration plus contractDefaults.delivery.outboxSettlementReserve; otherwise provider construction fails with configuration_invalid. Core's maxAttemptDuration still applies. Expiry aborts with the task_interrupted Runlane error. A handler error then interrupts the attempt without spending a retry. See Stop crash loops for the interruption allowance. Core may use an invocation handoff before the deadline. See Continue across request budgets for how each adapter delivers the next attempt. |
onFailure | Optional synchronous error observer receiving { level: 'error', phase, error }. Connect it to your logger. Causes remain local; do not serialize them to clients. Expected queue paused/full retries and shutdown cancellation do not emit error events. Observer exceptions propagate and are also surfaced by close after draining. |
Core native-handler tracking does not cap active task execution. HTTP admission is separate from storage-backed queue concurrency and host execution limits. If both execution limits are absent, execution is unbounded. A client disconnect aborts only before core saves a run claim, in every lifetime mode. After claim, storage ownership and execution deadlines govern the attempt. in_request holds its admission permit through execution; nested child publication requires more incoming slots than the active nesting depth. It also needs maxConcurrentPublishes above the number of concurrent in-request parents, with spare slots for children, or every parent can stall until the publish timeout. Bound parent concurrency and leave queue capacity for children; otherwise avoid nested triggers inside in-request handlers. See capacity guidance.
Close stops new HTTP admission, cancels waiting/body-read admission, drains started delivery, and closes adapter resources. The app owns the listening server. Close is idempotent. It settles all tracked work and closes the adapter before rejecting with a recorded observer error. Multiple errors are returned as an AggregateError. createWorker() throws capability_unsupported with createDeliveryHandler() guidance. Lifecycle-hook deliveries always run in-request because core does not acknowledge them at an ordinary run claim.
in_request works on every supported host. The sending request and await runlane.trigger() wait for the attempt. process replies 202 at claim and continues in the app process; use it only on long-lived servers or through a host lifetime callback. Serverless background replies require a host lifetime callback such as Next.js after or Vercel waitUntil; bare process is unsafe there. See host guidance.
Lane factories
Import postgresHttpLane and PostgresHttpLaneOptions from @runlane/lane-postgres-http, or redisHttpLane and RedisHttpLaneOptions from @runlane/lane-redis-http. Options are { postgres, http, name?, runHints? } or { redis, http, name?, runHints? }. http accepts HttpDeliveryProviderOptions, including its required adapter, queues, and lifetime. Storage options match their driver, except nested runHints and workHints are rejected. Use top-level runHints, which defaults to contractDefaults.realtime.runHints. Work hints are disabled. Names default to postgres-http and redis-http. Both expose operator reads and the native fetch handler; Postgres also exposes its CLI adapter. HTTP remains best-effort.
Direct adapter
createDirectHttpAdapter(options) POSTs one wakeup per message. It returns a service adapter, not a Runlane instance. Its profile is best_effort, ordering none, batch limit 100, message limit contractDefaults.delivery.maxEnvelopeBytes (currently 65,536 bytes), and no native delay. No deduplication or retention is promised. Raw publish commands requesting future delivery are rejected before any batch prefix is sent, matching other due-only transports.
| Option | Meaning / default |
|---|---|
url | Required absolute HTTPS URL without credentials or a fragment. Redirects are never followed. |
secrets.current | Required whsec_ plus canonical base64 encoding 24–64 random bytes. Padding is required when the encoding needs it; base64url is not accepted. Maximum encoded length is 94 characters including the prefix. |
secrets.next | Optional second signing and verification key with the same rules. Senders emit a signature for each configured key; receivers accept a matching signature from either key. |
allowInsecureLocalhost | Default false. Allows HTTP only for localhost, 127.0.0.1 or [::1]. |
maxConcurrentPublishes | Shared outgoing POST limit per adapter, default 8 from httpTransportDefaults.maxConcurrentPublishes. Outgoing waits are bounded as well. The required command signal bounds permit waits and outgoing requests by the original outbox claim deadline supplied by core. Unsent messages receive retryable per-message failures on abort; an interrupted request makes the batch ambiguous. |
publishTimeout | Positive duration, default '30s', covering the HTTP exchange after acquiring a permit. With in_request, it must exceed maxDuration plus contractDefaults.delivery.outboxSettlementReserve when both budgets are known. Set it above the longest expected attempt (at least maxAttemptDuration plus admission/startup/settlement margin), or the sender will retry while execution continues; duplicates are ignored under the active lease. Core derives the outbox claim from this timeout plus contractDefaults.delivery.outboxSettlementReserve, with contractDefaults.lease.duration as the minimum. There is no five-minute cap. |
replayWindow | Positive duration, default '5m' (300 seconds each way). Compares integer Unix seconds, including both boundary seconds. The spec permits a configured tolerance; narrower or wider windows change replay exposure. |
endpointCooldown | Positive duration, default contractDefaults.maintenance.outboxRetryDelay (currently '30s'). Applies after endpoint configuration errors and 503. A 429 retries only that message without cooling the endpoint. |
onFailure | Error-level endpoint/publish observer, same event shape as provider onFailure. |
Package defaults live in httpTransportDefaults. The body cap and Retry-After cadence read their existing contract owners. Body reading has a fixed internal five-second deadline. Request/deadline timer options must fit Node's timer range. Provider-local cooldown is lost on process restart. v1 does not parse Retry-After; this handler omits deliveryCount because HTTP has no native receive count, so claim conflicts use the shared outbox delay in Retry-After.
Wire and authentication
The body is the existing canonical version-2 delivery envelope, unchanged. Content-Type is application/json; optional charset is accepted. Non-identity Content-Encoding gets 415. The handler enforces its byte cap while streaming, even without Content-Length, before authentication or JSON parsing.
| Exported header field | Wire name |
|---|---|
httpDeliveryHeaders.messageId | webhook-id |
httpDeliveryHeaders.timestamp | webhook-timestamp |
httpDeliveryHeaders.signature | webhook-signature |
The direct adapter follows the Standard Webhooks signature scheme. The timestamp is integer Unix seconds, generated for each send. HMAC-SHA256 signs the UTF-8 metadata prefix followed by the exact raw body bytes:
<message id>.<timestamp>.<body>The body is never decoded or reserialized for signing or verification. A signature is v1, plus the canonical base64 SHA-256 digest. With two configured keys, the sender joins their signatures with one space. Verification accepts any matching v1 entry, ignores well-formed entries for other versions, and rejects the entire header if any entry is malformed. Only symmetric HMAC signatures are supported. Verification uses Node createHmac and timingSafeEqual; the reference npm verifier is not a runtime dependency.
After authentication, the handler uses decodeDeliveryEnvelope from contracts and compares its environment with the receiver runtime environment. A mismatch returns empty 401 before core runs and emits a structured configuration_invalid failure through onFailure, naming both environments. Each provider reports a distinct envelope/receiver environment pair at most once. An authenticated malformed envelope maps to the adapter's permanent Reject response (422 for direct HTTP). Missing, malformed, changed, expired or too-far-future authentication also returns empty 401.
ID and timestamp headers must be single values. The signature header contains one space-separated list, not comma-joined duplicate headers. Message IDs must fit unchanged in Latin-1 headers without surrounding whitespace, control characters, commas or periods; maximum length is 1024 characters. Core-generated outbox IDs use outbox_ plus a UUID and meet these rules. The sender checks the whole batch before sending anything. Invalid IDs or canonical envelopes receive non-retryable per-message failures; valid unsent siblings receive retryable failures.
The transport command has no durable publish-attempt count, so no attempt header is sent. The outbox ID is correlation, not task idempotency. Retries can reuse that ID; recovery can create another ID for the same run. In-window replays still reach core's authoritative claim checks. This is time-bounded replay protection, not one-time-use authentication.
Rotate keys by deploying receiver current=A/next=B, enabling both signing keys on senders, then promoting B while retaining A during overlap. Retire A after old senders, in-flight requests and the replay window drain. See the rotation steps. Use separate secrets per endpoint/environment. Keep TLS verification enabled. HMAC does not satisfy Cloud Run IAM or Lambda AWS_IAM access control; configure an ingress path that reaches the verifier or add a separately reviewed infrastructure auth layer.
Results
| Result | Direct publisher outcome |
|---|---|
| 202 (committed claim) or 204 (Handled) | Published. It promises neither retained broker data nor completed task execution. |
| 413 / 415 / 422, including core Reject | Failed, non-retryable; core dead-letters the outbox row. |
| 401 / 403 / 404 / 405, other endpoint 4xx, any 3xx, unexpected 2xx | Failed, retryable; error-level endpoint report and cooldown. |
| 408 / 425 / 429 / any 5xx | Failed, retryable. Only 503 starts cooldown. |
| No reliable response: timeout, DNS/TLS failure, reset or lost reply | Reject the publish batch with retryable TransportUnavailable; core records failure and may retry known successes from that batch. |
The handler maps core Retry to empty 503 with Retry-After, rejects invalid envelopes with 422, returns 429 when pre-claim admission is full, and returns 503 after close begins. It sends no raw errors or task results. Core owns saved task retries and backoff; these produce Handled when a durable decision was reached.
Timer durations, including publishTimeout and handoffBefore, must fit the Node timer platform limit of 2,147,483,647 ms.