Skip to main content
iii 0.27 changes every SDK: TypeScript (Node and browser), Python, Rust, and Go. Streaming between functions no longer has an API of its own: a stream is a value of a call. Put a file, a readable, or a generator in a payload or a result, and the function on the other side receives an InputStream to read; put a writable or a file to create there, and it receives an OutputStream to write.
  • The Channels API is removed from all five SDKs. createChannel, ChannelReader, ChannelWriter, readerRef, and writerRef (Python create_channel, create_channel_async, reader_ref, writer_ref; Rust iii_sdk::helpers::create_channel and iii_sdk::channel::*; Go CreateChannel, Channel, ChannelReader, ChannelWriter, OpenReader, OpenWriter, and ExtractChannelRefs; the browser’s createChannel, Channel, ChannelReader, and ChannelWriter) give way to InputStream and OutputStream, and to iii.pipe() for an explicit pipe. This is a breaking change with no deprecated aliases.
  • The wire is unchanged. A 0.26 engine serves 0.27 SDKs, and a ref has the same JSON in every SDK, so workers on 0.26 and 0.27 SDKs work together in one project. For streaming, the 0.27 engine changes only the text of its payload_too_large errors, which now link to Streaming / Payload size, as the errors of every 0.27 SDK do.
  • VM workers are explicit in worker-compose.yaml. A container that runs in a microVM now says so in its scripts, and Compose rewrites a 0.26 file on its next run. A project with a VM worker also follows Upgrading VM workers from 0.26.x.
  • Container keys are directory names. A key that starts with . or holds /, among others, loaded in 0.26 and now fails with INVALID_CONTAINER_KEY.
  • iii call resolves in default without -n, also in a script that Compose starts. See iii call.

Before you upgrade

Who needs to migrate

Every project, once, for the changes in Upgrade the project: the compose file and the scripts that run iii call. For streaming, only the workers whose SDK you upgrade to 0.27, and in them only the code that uses channels. A project that keeps its SDKs on 0.26 needs no streaming change, an engine upgrade alone changes nothing for streaming, and you can move one worker at a time.

Upgrade the project

Do this once per project, before the first run of the 0.27 iii:
  1. Stop the project, and commit worker-compose.yaml and worker-compose.lock. The 0.27 Compose rewrites the containers that 0.26 ran in a VM on its next run, and a rewritten file no longer loads in 0.26: the commit is your way back.
  2. Rename each container key that is empty or blank, holds / or \, starts with ., or holds a NUL, such as .internal or a/b, and the start_after entries that name it. A container key is now also the name of its directories, .iii/build/<key>/ and .iii/workers/<key>/, so such a key fails with INVALID_CONTAINER_KEY in any project, with or without a VM worker.
  3. If the project has VM workers, a registry bundle or a path:// worker whose iii.worker.yaml sets runtime.base_image, follow Upgrading VM workers from 0.26.x. It covers the sandbox adapter, which must be a 0.5 release, and the containers that must stay on the host.
  4. Add -n <namespace> to each iii call in a script that targets a function of the project’s namespace, as in iii call.

Compatibility

Mixed fleets

A ref is the same JSON whichever SDK sent it, so a stream crosses SDK versions. What the receiving worker gets depends on its SDK: The 0.27 lifecycle rules apply on the 0.27 side only. A handler on a 0.26 SDK that receives a writer still has to close it, and a 0.27 caller that passed it a sink waits until it does: its call resolves only after the sink has received the whole stream. If the 0.26 handler never opens the writer, the call fails with TIMEOUT when its timeout expires, and the SDK aborts the sink. A 0.26 TypeScript or Python writer that closes without writing anything never opens its socket, so its reader, on any SDK version, waits until the engine expires the pipe. This is 0.26 behavior: a 0.27 writer opens the socket to close it, so its reader sees an empty stream at once. Upgrade the writing side to fix it.

Payload size with older SDKs and engines

When a worker registers, the engine gives it one of two receive limits for JSON messages. For the limits, see Streaming / Payload size. A worker on a Rust, Node, Python, or Go SDK from 0.25.0 declares the large-messages.v1 protocol feature and gets the larger limit. These rules apply to older SDKs and to older engines:
  • A worker on an older Rust, Node, Python, or Go SDK does not declare the feature. The engine then sets the limit from the SDK version that the worker reports. The worker gets the larger limit when the version is 0.24.5 or later. It gets the smaller limit when the version is missing, when the engine cannot read it, or when it is older than 0.24.5.
  • The engine reads the version as semver or as PEP 440. Examples of semver are 0.24.6 and 0.25.0-rc.5. Examples of PEP 440 are 0.25.0rc5 and 0.24.5.post1. A pre-release of 0.24.5 is older than 0.24.5.
  • A Rust worker can report its own version. SDKs 0.24.5 through 0.25.0-rc.5 do not declare large-messages.v1. A Rust worker on one of these SDKs can set WorkerMetadata.version to its own version. If that version is older than 0.24.5, the worker gets the smaller limit. Upgrade the worker to SDK 0.25.0 or later.
  • The engine accepts the large single frames that SDKs before 0.24.5 send. The engine accepts a message as one frame or as fragments.
  • An engine from before the receive limit check does not check the limit of the target. It sends each message as one frame. A worker on an older SDK can then disconnect. Use an engine and SDKs from the same release, or newer.

Find what to change

Search each worker for the removed APIs. A few hits, such as sendMessage on another library’s socket, may be unrelated:
Then work through the sections below:
  1. Send a stream where a caller creates a channel and passes its readerRef.
  2. Return a stream or write into the caller’s sink where a caller creates a channel and passes its writerRef.
  3. HTTP request_body and response in route handlers that stream.
  4. Messages where code calls sendMessage or onMessage.
  5. Abort where a writer destroys its stream or is dropped on failure.
  6. Ref helpers where code finds refs by hand.
  7. createChannel to iii.pipe() where a pipe has to exist before its data.
  8. The browser SDK for a page that streams.
  9. Check the behavior changes, iii call, and the checklist.

What changed

The SDK also detects streams in what it sends and turns refs back into streams in what it receives, in handler input and, new in 0.27, in call results. See Using iii / Streaming for the full API.

Send a stream

Put the source in the payload. The SDK creates the pipe, sends the ref, and pumps the data while the call runs, so the caller no longer writes a channel next to the call. The handler reads the field the same way as before, without .stream in TypeScript. The payload field keeps its name: it is your function’s contract.
Before (0.26)
After (0.27)

Return a stream

In 0.26, refs in a result were not turned into readers, so a function that produced a stream needed its caller to create a channel and pass a writerRef in. In 0.27 the function returns the stream and the caller reads it from the result. The caller no longer passes a writer, so this changes the function’s payload: move its callers in the same change. When the caller has a place for the bytes, such as a file, pass a sink instead.
Before (0.26)
After (0.27)

Write into the caller’s sink

When the caller copied the reader end of its channel into a file or another writable, pass that sink in the payload instead. The handler receives an OutputStream, and the caller’s call resolves once the sink has received everything.
Before (0.26)
After (0.27)
A sink takes bytes only: messages the handler sends on the OutputStream are dropped, and the call still succeeds. If the caller also read the channel’s messages (onMessage), pass the output of a pipe instead and read its input.

HTTP request_body and response

The HTTP worker still passes a route’s request body and response as refs in request_body and response, and it reads the status and the headers from the same JSON messages. Only their SDK types change: request_body is an InputStream and response is an OutputStream. The request_body of the TypeScript HttpRequest and StreamRequest types and of the Python StreamRequest is an InputStream too. In Go, the RequestBody of iiihttp.Request, iiihttp.InternalRequest, and iiihttp.StreamRequest is an *iii.InputStream, and InternalRequest.Response is an *iii.OutputStream.
Before (0.26)
After (0.27)
A route handler that returns a buffered response ({ status_code, body }) without touching response needs no change: the HTTP worker calls a route through an observer, and in that case the SDK leaves an untouched response alone when the handler returns a value.

Streaming response helpers

The StreamResponse helpers (the res of the TypeScript http() wrapper, of the Python StreamResponse, and of the Go iiihttp.Wrap) wrap the OutputStream now. In TypeScript and Python, every method that writes is asynchronous: In Go, Status, Headers, Write, and Close keep their signatures. Wrap closes the response when the handler returns and aborts it when the handler fails, as before: Before (0.26)
After (0.27)

Messages

send takes a value and sends it as JSON in one text frame, so drop your own JSON.stringify or json.dumps. messages() parses each text frame, and yields a frame that is not JSON as its raw string, so messages from a writer on a 0.26 SDK that sent plain text still arrive. A reader on a 0.26 SDK receives what send wrote as JSON text: a bare string arrives quoted.
Before (0.26)
After (0.27)
A reader that needs both the bytes and the messages, in order, iterates frames().

Abort

In 0.26 each SDK aborted differently: Node with writer.stream.destroy() and no argument, Rust by dropping the writer without close(), Go with a Close() after a failed Write, and Python and the browser had no abort call. In 0.27 the SDK aborts for you in the common cases, and abort(reason) is one call everywhere:
  • A source the SDK pumps (a generator, a readable, a file) that fails aborts its stream.
  • A handler that throws aborts every received OutputStream it has written to.
  • await output.abort(reason) aborts on purpose. If the stream’s socket never opened, it opens it first, so the reader always learns of the failure.
A handler that throws before it touched a received OutputStream leaves that stream alone, as in 0.26: the caller learns of the failure from the call’s error. The reader gets a typed error after the data that was already sent.
Before (0.26)
After (0.27)
The reader’s reason is the engine’s description of the close, such as channel writer aborted: closed with code 1011: the engine does not relay the writer’s own reason. Report the cause in the call’s error or result. A caller that passed a sink gets the abort as its call’s error, with the code STREAM_ABORTED, even when the function returned.

Ref helpers move to the protocol module

The SDK now finds refs and turns them into streams, so most code that called extractChannelRefs or isChannelRef can drop it. Code that still works with the raw ref JSON, such as a router that inspects payloads, imports the helpers from the low-level protocol module: In Go, iii.StreamChannelRef and iii.ChannelDirection stay in package iii, and iii.ExtractChannelRefs is removed: unmarshal the raw ref JSON into an iii.StreamChannelRef. The helpers see refs as JSON. A handler on a 0.27 SDK receives streams, not refs, so call them on the raw JSON you hold, such as a value read from storage.

createChannel to iii.pipe()

Most channels become a value in the payload or the result, as above. Keep an explicit pipe when the stream has to exist before its data, when it goes to a call made later, or for a two-way session (two pipes). iii.pipe() returns its two ends, input and output; put the end the other side uses in the payload, where 0.26 code put a ref.
Before (0.26)
After (0.27)
In Go, client.Pipe(ctx) returns the two ends as (input, output, err): channel.Writer becomes output, channel.Reader becomes input, and the ends go in the payload where channel.ReaderRef and channel.WriterRef went. In the browser, createChannel(worker, bufferSize) becomes worker.pipe({ bufferSize }). The worker that calls pipe() owns the pipe, as with createChannel: keep it connected until the other side has attached.

The browser SDK

The browser SDK follows the TypeScript API, with Web streams only. A File or a Blob from an <input type="file">, a ReadableStream such as response.body of a fetch, and an async generator are sources. A WritableStream, such as the one a File System Access handle returns from createWritable(), is a sink. Send a file from a page: Before (0.26)
After (0.27)
Read a stream that a function returns: Before (0.26)
After (0.27)
There is no toReadable() or toWritable() in the browser: toWebStream() returns the Web stream of an InputStream or an OutputStream. abort(reason) closes the stream’s socket with code 4011, because a browser can only send 1000 or a code from 3000 to 4999. The engine treats it as an abort, so a reader on any 0.27 SDK gets STREAM_ABORTED, with the reason channel writer aborted: closed with code 4011.

Behavior changes

Beyond the renamed API, these rules are new for a worker on a 0.27 SDK:
  • A received OutputStream is closed when the handler returns, and aborted when it throws. A 0.26 handler that returned and kept writing in the background calls keepOpen() (Python and Rust keep_open(), Go KeepOpen()) first, and then closes or aborts the stream itself. A stream the handler never touched is closed as well when it returns, except in a call through an observer (an HTTP route, for example), where it is closed only when the handler returns nothing.
  • A received InputStream that the handler started reading and did not finish is cancelled when the handler returns. Finish reading before returning: a read still running after it, in a background task for example, fails with STREAM_CLOSED.
  • Refs in call results arrive as streams. In 0.26 a ref in a result stayed JSON. Code that read a ref out of a result and opened it now receives an InputStream or an OutputStream instead.
  • A stream has one reader. A second read of the same InputStream fails; call tee() before the first read for copies in the same process. Go has no tee(): copy the bytes with io.TeeReader or io.MultiWriter as you read.
  • Streams need a live call. A call sent with CallAction.Enqueue (Go iii.EnqueueAction(queue)) and a stream or a ref anywhere in its payload is refused before it is sent, with the code STREAM_NOT_ALLOWED. Store the data and enqueue its key. CallAction.Void is allowed.
  • Observers receive StreamInfo. When an observer captures the input or output of a call that carried a stream, its target receives { stream: true, direction, id } in that field (Go iii.StreamInfo). A 0.26 TypeScript, Python, or browser target got a live reader there, and a 0.26 Go target got the ref; opening either raced the observed function for the bytes. See Observe a stream.
  • Rust streams bind lazily. An InputStream or OutputStream decoded from JSON binds to the handler’s worker inside a handler, and to the only client in the process elsewhere. A process with several clients calls stream.bind(&worker) before using a stream decoded outside a handler.
  • Go streams bind lazily too. A stream unmarshalled from a handler’s input or from a call’s result binds to that client. One unmarshalled from other JSON binds to the only client in the process; with several, call stream.Bind(worker) before using it.
  • The payload_too_large error links to the new page: https://iii.dev/docs/creating-workers/streaming#payload-size.

iii call

The 0.27 iii call changes for scripts:
  • Without -n, iii call resolves in default. In 0.26 it took the namespace of III_NAMESPACE when that variable was set, and Compose sets it for every process it starts. A scripts line, or a script it runs, reached a function of the project’s namespace with a plain iii call <function>. In 0.27 that call looks in default and does not find the function. Name the namespace with iii call -n <namespace> <function>. A project in default needs no change, and neither does a call to a function in default, such as the engine’s sandbox::build and sandbox::start.
  • Arguments that cannot make a call exit with 2.
  • A function that fails prints its Error: JSON on one line when standard error is not a terminal, so a script can parse it. Other failures print plain text.

Checklist

  • Commit worker-compose.yaml and worker-compose.lock before the first run of the 0.27 iii
  • Rename each container key that fails with INVALID_CONTAINER_KEY, and the start_after entries that name it
  • In a project with VM workers, follow Upgrading VM workers from 0.26.x
  • Add -n <namespace> to each iii call in a script that targets a function outside default
  • Upgrade one worker’s SDK at a time; workers on 0.26 SDKs keep working unchanged on the same engine
  • Replace each createChannel / create_channel / create_channel_async whose writer feeds a call with the source itself in the payload
  • Replace each writerRef / writer_ref passed in for a function to fill with a returned stream, or with a sink in the payload, and move that function’s callers in the same change
  • Type stream fields as InputStream and OutputStream; in Rust, replace extract_channel_refs and ChannelReader::new / ChannelWriter::new with typed struct fields; in Go, replace ExtractChannelRefs, OpenReader, and OpenWriter with *iii.InputStream and *iii.OutputStream fields
  • In Go, wrap what you send with iii.InputStreamFromReader, iii.InputStreamFromBytes, or iii.OutputStreamToWriter, and change iiihttp.Wrap(client, fn) to iiihttp.Wrap(fn)
  • In the browser, pass a Blob, a File, or a ReadableStream in the payload instead of writing a channel
  • Replace reader.stream and writer.stream with the stream itself, write, or the native bridges (toReadable, toWritable)
  • Replace sendMessage / send_message with send, and onMessage / on_message with messages(), without your own JSON encoding
  • Replace writer.stream.destroy(), dropping a Rust writer, and a Go Close() after a failed Write with abort(reason) or a throw, and catch StreamAbortedError (Rust Error::StreamAborted, Go an *iii.InvocationError with iii.CodeStreamAborted) where you caught the old errors
  • Remove explicit closes the handler no longer needs, and call keepOpen() (Go KeepOpen()) where a handler keeps writing after it returns
  • Import extractChannelRefs, isChannelRef, StreamChannelRef, ChannelDirection, and ChannelItem from the protocol module
  • Move calls queued with CallAction.Enqueue that carried a ref to stored data and a key
  • Update observer targets that read a captured stream field to expect a StreamInfo
To call functions with streams, see Using iii / Streaming. To write functions that receive and return streams, see Creating workers / Streaming. For how a stream works, see Understanding iii / Streaming. For each SDK’s API, see the SDK reference: Node, Python, Rust, Go, and Browser.