# Remote relay contract, first implementation increment This describes the implemented relay library, not a promise of usable desktop control. The host streaming API remains unimplemented. All payloads stay in the external Tentacle; no reader internals or output backends are imported here. ## Sources and provenance Reference heads were checked on 2026-11-03: - Cthulhu `testing`: `a47253d697c1aa44dea80646cad99a4fe163c7f1`. - Cthulhu Tentacles `master`: `bc305993b8ad5c2374c8fc2c8b886c9cd6697b52`. - NVDA current head: `84756356cd19a57cfeb4ef265619e54850e06568`. - NVDA local reference: `2843e703ce19757711e976ebb6e9c5b689fc2017`. - NVDA Remote add-on: `301248945481e462601248c5e423731bd58d5e0a`. - churst90/orca-remote: `391f0c52044071e7cd34e3900fc13474826c312d`. - serrebidev/orca-remote: `9260d8284bb9f0761633dca958f5e1d9ccc37485`. The current NVDA [serializer](https://github.com/nvaccess/nvda/blob/84756356cd19a57cfeb4ef265619e54850e06568/source/_remoteClient/serializer.py), [session](https://github.com/nvaccess/nvda/blob/84756356cd19a57cfeb4ef265619e54850e06568/source/_remoteClient/session.py), [transport](https://github.com/nvaccess/nvda/blob/84756356cd19a57cfeb4ef265619e54850e06568/source/_remoteClient/transport.py), [server](https://github.com/nvaccess/nvda/blob/84756356cd19a57cfeb4ef265619e54850e06568/source/_remoteClient/server.py) and [input adapter](https://github.com/nvaccess/nvda/blob/84756356cd19a57cfeb4ef265619e54850e06568/source/_remoteClient/input.py) were downloaded for source review. Speech command fields and priorities were also inspected in the local NVDA reference. The current serializer, session and input adapter matched that local revision; the server now bounds incoming messages but retains the reviewed membership fields. No implementation, mapping table or test fixture was copied from NVDA or Orca. `src/testdata/nvda-v2.jsonl` contains independently authored synthetic examples of reviewed field shapes, with generic IDs and text. The optional `scan_code` example exercises a documented optional field, not an observed NVDA emission. Private test certificates are generated in memory, never distributed. No Windows NVDA process, standalone add-on or Orca plugin has been run against this code. Live captured fixtures and versioned interoperability results remain required. ## Framing and validation TLS is mandatory. Each frame is a UTF-8 JSON object followed by LF. A relay frame may contain at most 1 MiB before LF. EOF with a partial frame fails. Parsing rejects invalid UTF-8, duplicate keys at every depth, trailing values, nesting beyond 24, more than 4,096 members per collection or more than 16,384 values. Additional fields are allowed but still undergo structural validation. The `type` is a nonempty printable ASCII string of at most 64 bytes. `origin`, when present, is a positive 32-bit integer. Boolean and numeric types are not interchangeable. Required values cannot be null. Errors contain fixed local messages; they never include channel keys, remote output or server text. | Message | Implemented representation and limits | | --- | --- | | `protocol_version`, `join` | Outbound authentication only: version 2, channel and `connection_type` of `master` or `slave`. | | `channel_joined` | Matching channel required. Missing `clients` means empty. A maximum of 16 peers may be parsed; session policy accepts at most one. `user_ids`, if present, must exactly match typed peers. Nonempty legacy IDs without roles fail. The echoed key is removed from returned membership. | | `client_joined`, `client_left` | Typed `client` requires positive `id` and known `connection_type`. Optional `user_id` must agree. ID-only legacy membership is unsupported. | | `speak` | Up to 1,024 sequence entries. Strings preserve whitespace and order. Numeric priority 0, 1 or 2; absence defaults to 0. Null and string priorities fail. | | `cancel`, `pause_speech` | Typed cancel or required boolean `switch`. No output backend is called. | | `key` | Required integer `vk_code` 1–255 and booleans `extended`, `pressed`. Optional integer `scan_code` 0–65,535. Isolated [mapping, key-pair planning and SDK conversion](keyboard.md) cover an explicit subset. The reader has typed input admission but no production input owner; the coordinator still discards keys. | | `set_braille_info` | Name at most 256 UTF-8 bytes; width 0–4,096. Absent fields permit the controlled peer's geometry request. Zero means no display. | | `set_display_size` | Required `sizes` array, at most 16 widths, each 0–4,096. | | `display` | Required array of at most 4,096 integer cells, each 0–255. Null cells and base64 strings fail. | | `braille_input` | Only the fixed global-command pan/route paths described below produce actions. Other gestures remain inert. | | `set_clipboard_text` | Required string, at most 8,192 UTF-8 bytes. No clipboard access is performed. | | `ping`, `motd` | Relay-only housekeeping. Required `motd` text is bounded and discarded; optional boolean `force_display` cannot authorize an action. | | `error`, `version_mismatch`, `nvda_not_connected` | Terminal session failures; no automatic reconnect. Server error text is discarded. | | Other types | Structurally validated and inert. Post-join peer extensions require the selected peer origin. Includes `tone`, `wave`, `send_SAS` and `index`; no path is opened or script executed. | NVDA speech commands use `[name, fields]` arrays. The parser recognizes `CharacterModeCommand.state`, `LangChangeCommand.lang` (null restores the default language) and `EndUtteranceCommand`. Extra fields such as `isDefault` are tolerated. Unsupported command arrays increment an utterance-local bounded count without retaining their names or executing them. Dictionary-shaped command objects are rejected. Backend language, priority and character-mode conversion, UTF-8 splitting into host operations, cancellation ownership and cancel-on-pause policy still need reader integration. The 1 MiB relay limit is not permission to send a 1 MiB host presentation. Braille scripts must have exactly the form `["globalCommands", "GlobalCommands", name]`. The only recognized names are `braille_scrollBack`, `braille_scrollForward` and `braille_routeTo`. Routing accepts a single `cellIndexes` item or legacy `routingIndex`, each 0–4,095. When both are supplied they must agree. Multiple routing cells are unsupported. Unknown modules, plugins, arbitrary script names and `kb:` commands are inert. Actual viewport width and generation must still be checked in core. ## Session policy and ownership The external `session` state has one owner and no locks or background workers. It starts `joining`, becomes `waiting` after an empty channel acknowledgement, and becomes `ready` only with one opposite-role peer. Additional/repeated joins, same-role peers, peer departure, ambiguous origins and wrong-direction effects suspend it and clear peer identity. A suspended or closed session cannot resume; a local action must create a new connection and core-issued epoch. Stale-epoch events are rejected without changing the current state. Speech/cancel/pause/display travel from controlled to controller. Keys, Braille input and display sizes travel from controller to controlled. Clipboard and Braille information can travel both ways. None of this grants desktop access. Core consent and per-operation grants must be checked separately at delivery. `relayConn` owns one reader, a serialized writer and a lifetime context. Its context remains active after `connect` returns. Read/decode failure closes the socket. Explicit close and cancellation interrupt blocked I/O. Writes have a five-second deadline covering queue wait and transmission, at most 32 admitted calls and a 256 KiB aggregate byte ceiling. Overflow closes the connection; cleanup does not wait for writer admission. Concurrent writes cannot interleave frames; their relative order is unspecified, so the session owner must sequence speech/cancel and key transitions before submitting them. The [library coordinator](lifecycle.md) now closes the transport on terminal session errors, requests core lease closure on failure and rejects cancelled worker results. Private fixtures test those layers together using the public Go SDK. The source command now supplies production consent wiring. Typed speech uses the [coordinator's bounded speech bridge](speech.md); other desktop payloads are counted and discarded. Transport write capacity does not replace separate host control/input/output queues or production reader output ownership. ## Timeouts, trust and liveness Dial plus TLS has a 15-second bound. Join has a separate 15-second bound and at most 32 pre-join notices. Unexpected pre-join peer effects fail. Disconnect cancels the entire connection lifetime. No reconnect/backoff is implemented; authentication/trust failures require a fresh explicit attempt. CA mode uses normal system roots and hostname/IP checks. Pin mode accepts only the exact SHA-256 leaf certificate digest previously approved for that exact host string and port, replacing CA/name validation for that endpoint. Even a CA-valid replacement certificate fails an existing pin. Endpoint-bound pin persistence is implemented in [storage.md](storage.md); local approval/display UI and fingerprint discovery remain unimplemented. Callers cannot obtain consent merely by constructing a pin. There is no plaintext or generic insecure mode. Host names are separate from ports; bare IPv6 literals use `JoinHostPort`. NVDA's embedded relay sends one-way `ping` every 300 seconds. Accordingly the initial read deadline is six minutes; receiving a complete next frame resets it. TCP keepalive requests idle 10 seconds, interval 3 seconds and three probes. These are development transport settings, **not a proven desktop recovery bound**. A relay process can hang while its kernel still acknowledges probes; the coordinator now sends one-second core heartbeats and relies on independent three-second reader lease expiry. Remote-peer liveness beyond relay membership remains unresolved. Idle/dead relay trials, abrupt network loss, IPv6 connections and installed-package behavior have not been verified.