Transformer worker protocol, version 1
Use this specification to write a Transformer worker in another language. It describes the messages exchanged by Decoy and the TypeScript SDK. To configure a worker for a Route, see Configure a Transformer Pipeline.
Process
- Decoy starts one process per
transformersentry with aworkerargv list, in the directory ofdecoy.yaml, withDECOY_TRANSFORMER=1added to the environment. - stdin and stdout carry the protocol and nothing else: anything else on stdout is a protocol error
that ends the worker, so an SDK sends console output to stderr. stderr is free text: Decoy forwards each line
as
[<key>: <name>@<version>] <line>and keeps the last 20 lines for exit reports. - The process lives as long as Decoy. Decoy sends
shutdownwhen it stops and kills the process if it is still running 2 s later. If the process exits on its own, Decoy reports the exit code and stderr tail and exits non-zero. Decoy never restarts a worker, not even on a--watchreload.
Framing
Each message is a 4-byte big-endian length, then that many bytes of one msgpack map. A message is at
most 16 MiB; a longer length ends the worker as a protocol error. Decoy never sends a longer one: a
call that wouldn't fit fails as a worker error for that frame only. Every map has a string kind.
Values
Values are msgpack. Wire bytes are msgpack bin; everything else is the JSON data model (nil, bool,
integer, float, str, array, map with str keys). Each transport defines how the final value becomes a Case input or a wire payload.
See the HTTP, gRPC,
and WebSocket guides.
Messages
Decoy → worker:
Worker → Decoy:
Handshake
Decoy writes hello first. The worker answers ready with the directions it provides. Startup fails if it advertises a different protocol version, exits before readiness, sends no valid ready within 10 s, or a Pipeline uses a direction it did not announce.
Calls
callids are Decoy's, unique per process. A worker may answer calls in any order and may run them concurrently. Decoy sends a connection's next call only after the previous one answered or timed out, so a step that keeps state per connection sees its messages in order unless one timed out. After a timeout the late call may still run, even after the connection'sclose.- WebSocket calls carry
connection: { id, route, session }. HTTP, gRPC, and startup checks omit it. WebSocketinputalso carriesframe("text"or"binary"). - HTTP
inputandoutputcalls carryrequest: { method, path, headers }alongside the payload.pathexcludes the query.headersis the original request's normalized header map (lowercase names, string values), includingcookieandauthorizationwhen present. Workers should not log those values. Non-HTTP calls and startup checks omitrequest. inputruns before Case matching. On WebSocket the first step gets the frame payload asbin. Each later step gets the previous step's result. The final result must be suitable for the transport's Message envelope.outputruns on the rendered Behavior payload, an HTTP Passthrough response body, or a Control API push. Each later step gets the previous step's result. WebSocket sends a finalstras text orbinas binary.checkoptionally validates a startup literal for the first worker in the output direction when that worker receives the untransformed value. A worker without acheckcallback answersok: true.- A
missresult oninputrecords a Case miss for the frame. Amissresult onoutputis a transform error. - Set
timeouton the Transformer definition inmsors. The default is5s. Decoy reports a worker error when the timeout expires and ignores any laterresult.
Host calls
A worker sends host to use what Decoy loaded; Decoy answers with hostResult of the same id.
During startup checks (before Decoy serves; a reload runs none), protobuf.encode only validates: string leaves holding ${ are
skipped, field names and the other leaves are still checked, and the value is an empty bin.