Wire Protocol
@sora/protocol (packages/protocol, version 0.1.0) is the single definition of how Sora devices, the Desktop client, and the self-hosted Relay talk to each other. The package holds frame types, runtime validators, route-method validation, Memory v3 sync schemas, HTTP DTOs, and shared JSON vectors. The Kotlin clients mirror the same shapes in core/relay/src/jvmCommonMain/.../RelayFrames.kt.
Transport and handshake
- WebSocket over TLS at
/v1/ws(defaultwss://<relay-host>:8443/v1/ws). Every message is a JSON object in a text frame; the relay does not batch multiple frames per message. - HTTP over TLS for pairing, device management, and Memory v3 sync. Plain HTTP is only used in local development.
- The client authenticates the WebSocket upgrade with
Authorization: Bearer <device-token>. - First frame from the client is
hello; the Relay answershello_ok. A version mismatch or an unauthorized token closes the connection. The client gives the handshake a bounded timeout and reconnects with backoff. - TLS identity is pinned: the Relay advertises its CA at
GET /v1/ca, and pairing links carry the CA SHA-256 fingerprint as#fp=.... Clients pin that CA instead of trusting the system store alone.
Values fixed by the schema:
| Constant | Value |
|---|---|
PROTOCOL_VERSION | 1 |
RELAY_CAPABILITIES count | 17 (remote-bot, super-worker, mesh-v2, memory-v3, …) |
| Memory access scopes | PERSONAL, WORK_ONLY, OFF |
| Route methods | 81 |
| Error codes | 14 |
Frame types
Client → Relay
| Type | Purpose | Key fields |
|---|---|---|
hello | Register a device | protocolVersion, deviceId, platform (android/desktop/cli/unknown), appVersion, bots[], capabilities[] |
route | Send a method call to another device | id, to, method, params |
route_ok | Successful response to an inbound route | id, result |
route_error | Failed response to an inbound route | id, code, message |
route_event | Streaming event for an inbound route | id, seq, event |
sync_event | Coarse change notification | kind, botId, sessionId?, busy?, pendingApprovals?, ts |
ping | Keepalive | — |
Relay → Client
| Type | Purpose | Key fields |
|---|---|---|
hello_ok | Accepted device + account snapshot | accountId, devices[], memoryVersion, capabilities[]?, superHost?, profile? |
presence | A device came online/offline or changed bots | deviceId, online, lastSeen, bots?, capabilities? |
route | Inbound route from another device | adds from to the client route shape |
route_ok / route_error / route_event | Responses and streamed events | as above |
sync_event | Change notification from another device | deviceId required |
memory_changed | Memory graph version changed | version |
super_host_changed | Orch host owner changed | superHost, reason (init / switch / failover_revoke) |
profile_changed | Account profile updated | profile |
pong | Keepalive reply | — |
encodeFrame / decodeFrameLine provide the newline-delimited JSON form used by the shared vectors and tests; live WebSocket traffic carries one parsed JSON object per message.
Route methods
A route is addressed to a device (to), validated against a fixed method list, and forwarded only if the target device is online. Responses and streamed events match the route id; a route expires after two hours, and results larger than 4 MiB are rejected with payload_too_large without dropping the connection.
| Family | Count | Examples |
|---|---|---|
bot.* | 21 | bot.prompt, bot.steer, bot.follow_up, bot.abort, bot.approval, bot.sessions, bot.history, bot.set_model, bot.commands, bot.capabilities.set |
session.* | 6 | session.create, session.rename, session.delete, session.compact, session.retry, session.update_meta |
file.* | 7 | file.list, file.stat, file.read_chunk, file.write_chunk, file.mkdir, file.rename, file.delete |
artifact.* | 1 | artifact.read_chunk |
worker.* | 12 | worker.start, worker.continue, worker.steer, worker.inspect, worker.approval, worker.set_model, worker.tool_approval |
super.* | 34 | super.prompt, super.state, super.subscribe, super.team.set, super.prepare_handover, super.worker.*, super.timers.*, super.settings.* |
Validation is method-aware, not generic. Examples:
bot.promptrequiresproviderandmodelIdtogether; images are validated by magic bytes (JPEG/PNG/WebP/GIF), at most 4 per call and with a bounded total payload.bot.instructions.setandsuper.instructions.setcap content at 64 KiB.- File and artifact chunks cap at 256 KiB per chunk and 50 MiB per transfer; relative paths reject absolute paths,
..,\,:, and NUL. worker.*andsuper.worker.*identifiers are bounded,tailis 1–200, and model changes requireproviderId+modelIdor a thinking level.super.*mutable calls accept an optionalexpectedEpochto reject writes from a stale Orch host.
Bot events
Streamed work inside a route is carried as BotEvent in route_event.event:
| Category | Event types |
|---|---|
| Lifecycle | agent_start, agent_end, agent_settled, error |
| Text/reasoning | message_update (text_delta / reasoning_delta) |
| Tools | tool_call, tool_result |
| Interaction | approval_request (can carry questions[]), user_message, queue_update |
| Plugins | plugin_custom_message |
| Maintenance | compaction_start / compaction_end, retry_start / retry_end |
| Orch | super_event (kind ≤ 64 chars) |
Sync events
sync_event.kind is one of sessions_changed, bot_activity, approval_changed, model_changed, capabilities_changed, super_changed. Sync events are rate-limited per connection window; they tell peers to refresh state, not to replicate it.
Error codes
route_error.code and HTTP ApiErrorBody.code share one enum:
unauthorized · protocol_mismatch · device_offline · bot_not_found · session_not_found
memory_conflict · rate_limited · bad_request · not_found · permission_denied
already_exists · payload_too_large · conflict · internalMemory v3 HTTP endpoints
Memory sync is HTTP on the same TLS origin, authenticated with the device bearer token. Expectations are mergeable records, not full documents.
| Method | Path | Request | Response | Notes |
|---|---|---|---|---|
POST | /v3/memory/push | MemoryV3PushRequest: ops[] (block / entity / event / relation / proposal) + optional consolidationCompletedAt | serverSeq, appliedCount, skippedCount, lastConsolidationAt, rejected[] | Max 200 ops per batch, 4 MiB body; idempotent by opId; failed ops are reported, not silently dropped |
GET | /v3/memory/pull?since=<seq>&limit=<n> | — | serverSeq, hasMore, nextSince, entries[] | Default limit 200, max 500; entries carry their kind, deviceId, and typed record |
POST | /v3/memory/consolidation-lease | optional ttlMs, minIntervalMs | acquired, leaseId?, holderDeviceId?, expiresAt, lastConsolidationAt, serverSeq | TTL 30 s – 30 min (default 10 min); prevents two devices consolidating the same memory at once |
DELETE | /v3/memory/consolidation-lease?leaseId=<id> | — | released | Only the holder can release |
Record kinds are block, entity, event, relation, and proposal. Every replicated record carries id, revision, updatedAt, deletedAt, and updatedByDeviceId; the Relay merges last-writer-wins per record and rejects malformed ops. Limits are per-field (for example block content 32 KiB, event content 8 KiB, summaries 2 KiB, IDs 128 chars).
Relay HTTP endpoints
| Method | Path | Auth | Purpose |
|---|---|---|---|
GET | /v1/health | none | Version, protocol version, CA fingerprint, capabilities |
GET | /v1/ca | none | CA PEM used for pinning |
POST | /v1/pair/enroll | login secret or pair code | First device enrollment: returns deviceId, bearer token, account id, pairing entries |
POST | /v1/pair/code | device token | Short-lived pairing code (10 min TTL) for another device |
GET | /v1/devices | device token | Device list with presence and bots |
GET/PUT | /v1/profile | device token | Account profile |
GET/PUT | /v1/super/host | device token | Current Orch host owner |
POST/GET | /v1/super/snapshot | device token | Push/read the Orch handover snapshot (8 MiB limit) |
Body limits: 64 KiB for normal JSON, 4 MiB for memory push, 8 MiB for Orch snapshots; enrollment bodies time out after 15 s and failed enrollment is rate-limited (10 failures per 15 min window by default).
Limits and constraints
| Constraint | Value |
|---|---|
| WebSocket payload | 8 MiB |
| Route result | 4 MiB (payload_too_large on overflow) |
| Route lifetime | 2 hours |
| Pending sockets / routes | 256 / 2048 global, 8 pending and 64 active routes per device |
| Resumable routes per device | 12 |
| Sync events | 30 per connection window |
| File chunk / transfer | 256 KiB / 50 MiB |
| Image attachments | 4 per call, bounded per-image and total base64 size |
| Identity lengths | identifiers 128 chars, bot names 128, avatars 64 KiB base64 |
Versioning and compatibility
PROTOCOL_VERSIONis an integer bumped only for breaking frame changes. Ahellowith a different version is rejected withprotocol_mismatch.- Within one protocol version, changes are additive: new optional frame fields, new route methods, new event types, new error codes. Unknown route methods are rejected explicitly (
UnknownRouteMethodError), never silently ignored. - Capabilities (
RELAY_CAPABILITIES,hello.capabilities,hello_ok.capabilities) let peers discover features instead of branching on versions. memoryVersioninhello_okandmemory_changedgives a cheap "did memory change" signal before pulling.- Plugin compatibility is a separate axis:
.ddpplugins use pluginapiLevel(currently 7) andminHostVersion, not the wire protocol version.
Test vectors
packages/protocol/vectors/ contains canonical frames parsed by the TypeScript test suite and mirrored by Kotlin tests:
| Vector | Covers |
|---|---|
client-hello.json | Device registration with bots and capabilities |
client-route.json | A bot.prompt route to another device |
server-hello-ok.json | Account snapshot with two devices and memory version |
server-presence.json | Device presence update |
server-route-event.json | A streamed message_update event |
Run pnpm test in the repository root to validate vectors and validators together.
