Local wire framing
The SDK supplies asynchronous framing for the owner–child connection. Use read_message and write_message instead of implementing a second serializer.
from skulk_capability_sdk.wire import read_message, write_message
message = await read_message(reader)
await write_message(writer, response)
Framing and backpressure
Each frame has a four-byte, network-order length followed by canonical JSON. The maximum message is 64 KiB. Reads reject lengths below two bytes or over the cap. Writes wait for the stream’s backpressure through drain().
The surrounding lifecycle owns the deadline. A successful read does not start a new independent timeout budget; cancellation and the original invocation deadline still apply.
Validation and failures
Incoming frames are validated against the discriminated wire contract in strict mode. Duplicate JSON keys, non-finite values, oversized frames, and excessive parser nesting are refused. ProtocolError reports framing violations; typed validation and incomplete stream reads can also fail. Handle them at the connection boundary with a useful diagnostic and controlled shutdown.
Streaming media uses the separate streams channel: a bounded header followed by raw bytes. Continue answering health on the primary control channel while executing a stream. Large immutable results use the host's declared result transport and its bounds.