# RPC subsystem plan — NEW Status: NEW design only; all feature tasks PLANNED. Baseline `f1f9ba375b22abf1adcc7c550ec21ac20895c0a4`, inspected 2026-11-24. Authority: [requirements](../REQUIREMENTS.md) R-009–R-016; [architecture](../ARCHITECTURE.md) C-02–C-06, C-07, C-11–C-13. ## Starting point and package boundary No current RPC source directory or target is claimed. Existing [Net client](../../../include/Void/Net/Http.hpp) and [router/session abstractions](../../../include/Void/Net/Server.hpp) are building blocks, not RPC transport, dispatch or schema negotiation. Scoped coverage checks identify parse gaps in these headers (Http 112/115, Server 207/211/214); those declarations were read directly. New source roots `include/Void/RPC`, `src/RPC`, and `tests/standalone/RPC` are PROPOSED and require implementation-time build ownership. RPC depends downwards on [Net](../modules/Net.md), [IO](IO.md), [Async](../modules/Async.md), [Data](../modules/Data.md) and [Binary](../modules/Binary.md). It does not import Coordination, Discovery, Replication or platform hosts. Endpoint selection is injected; a Discovery adapter belongs above RPC. Authentication hooks take Security-owned immutable principals; no socket is a principal merely because TLS succeeded. Choose native Void envelope/dispatch logic with HTTP/1.1 POST unary transport first; WebSocket multiplexed streaming follows Net conformance. Initial backend is the selected Net transport, with Boost/native parity inherited from Net. No gRPC compatibility claim and no new protobuf dependency are implicit. ## NEW contracts and concrete wire design ```cpp // NEW illustrative Void::RPC shapes; not currently available APIs. struct MethodId { std::uint64_t service; std::uint32_t method; }; struct CallContext { RequestId id; PrincipalView principal; OperationOptions operation; }; class Client { Task> call(MethodId, OwnedBytes, OperationOptions); Task> open_stream(MethodId, OperationOptions); }; class Server { Result bind(MethodDescriptor, Handler); Task> shutdown(OperationOptions); }; ``` Task/options are Async-owned; Result is C-02 shorthand. RPC owns MethodDescriptor, request/correlation IDs, status mapping and call handles. Shared binary encoding and schema primitives are referenced from Binary/Data, not reimplemented here. Registration retains handler/provider ownership; destruction unregisters future admission and offers an explicit drain operation for already admitted calls. Borrowed views expire on callback return; handlers retaining data must take ownership. Wire v1 is versioned length-delimited Binary encoding, explicit network byte order: four-byte magic `VRPC`, u16 major/minor, u32 header length/total frame length, u8 frame kind/flags, u16 reserved (zero), 128-bit call ID, u64 service ID, u32 method ID/schema version/remaining timeout milliseconds, u16 metadata count and length-delimited metadata. The total length includes the fixed header, metadata and payload; validate overflow and minimum length before subtracting. Reserved flags and required unknown fields fail closed. No native struct dump, pointer or std::string layout crosses the wire. Header ≤16 KiB, 64 metadata entries; payload ≤4 MiB/frame. Unknown major/required fields fail negotiation; minor optional fields are length-skippable. Initial unary POST uses one envelope under `/void-rpc/v1/call`, with an envelope response carrying domain status. Transport HTTP errors and RPC domain errors remain distinguishable. Data owns schema compatibility rules; numeric method IDs are explicit checked manifest assignments, not unstable reflection order. Streaming uses WebSocket subprotocol `void.rpc.v1`: OPEN, DATA, CREDIT, HALF_CLOSE, CANCEL and TERMINAL frames. One ordered sequence per direction/call; at most one terminal frame, at most 128 calls/connection. Initial credit 256 KiB/direction; each acknowledged consumed byte replenishes credit. Data frames ≤64 KiB; control frames have a separate bounded 64 KiB reserve so saturated data cannot prevent CANCEL/TERMINAL. Half-close stops that sender only. On disconnect every unfinished stream returns transport_lost; no hidden resumption. Schema negotiation and method permission happen before handler admission. Client dataflow: acquire budget → resolve injected endpoint → encode → Net send → decode bounded envelope → terminal result. Server: bounded decode → protocol/schema validation → authenticate/authorize → method admission → handler scope → encode result → release. User handlers and hooks execute outside dispatch locks. Relative timeout travels across machines; receivers create a local steady deadline, clamped to server max 30 seconds. Each forwarder subtracts its elapsed time, never sends a steady-clock timestamp from another process. Caller deadline includes connection/admission and all frames. Expiry cancels the server scope but cannot undo an application commit. The peer may complete after the caller loses its reply. ## Bounds, retry and failure matrix NEW defaults: 1,024 client calls, 256 executing server calls, 512 waiting, 64 MiB queued payload budget, 8 MiB aggregate retained payload/call. Reject before parsing/allocating an oversized frame. Metadata disallows secrets in tracing labels; trusted identity metadata is authenticated by the transport/hook, never accepted from an arbitrary caller field. Retries default off. A method may declare read-only/replay-safe, or require an explicit application operation ID and durable dedup contract. A correlation call ID alone provides no exactly-once processing. Stop propagation is best effort; client cancellation completes only when local backend access ends. Graceful shutdown rejects new calls, drains for 10 seconds, cancels remaining scopes, joins then releases registrations and transports. | Fault | Result / resource action | Required test | | --- | --- | --- | | Unknown method/schema/major version | Typed protocol status; no handler invocation | Mixed-version fixtures | | Bad length / malformed metadata | Protocol error; close if frame boundary uncertain | Fuzz/truncated frame corpus | | Handler error/exception | Mapped sanitized status; exactly one terminal result | Throws before/after suspension | | Unauthorized request | Denied before method dispatch | Spoofed identity and role tests | | Queue/credit exhaustion | Overload or explicit cancellable capacity wait | Slow stream consumer RSS bound | | Deadline/cancel races with reply | One local outcome; remote commit may be unknown | Terminal-vs-cancel permutation tests | | Lost reply after durable write | Unknown outcome; caller queries/retries by domain ID | Replication adapter fixture | | Connection/provider shutdown | Stop/join owned scopes; no handler or buffer use after release | Unregister and reconnect races | ## Ordered work and acceptance | ID | Phase / dependencies | Scope and evidence gate | Recommended role | | --- | --- | --- | --- | | S-RPC-01 | P0; baseline Net inventory | Record transport and schema prerequisites; independent package/dependency fixture plan | sol_implementer | | S-RPC-02 | P1; Async/IO/Data/Binary contracts, S-RPC-01 | NEW envelope/status/schema manifest and deterministic codec; limits/fuzz/round-trip fixtures pass | astra_implementer | | S-RPC-03 | P2; S-RPC-02, Net HTTP server/client gate | Unary transport and ownership-safe dispatch; deadlines/errors/authorization and consumer checks | sol_implementer | | S-RPC-04 | P3; S-RPC-03, Net WebSocket gate | Streaming credit/half-close/cancel protocol; no memory growth under stalled consumers | astra_implementer | | S-RPC-05 | P3; S-RPC-03, Security/Observability gates | Host adapters, bounded observations and version migration; embedded and managed modes pass | sol_implementer | | S-RPC-06 | P4; S-RPC-05, Replication protocol fixtures | Consensus traffic adapter conformance, duplicate/reorder/lost-reply coverage; RPC remains independent of Coordination | astra_implementer | ## Validation and migration CURRENT checks belong to the linked Net modules; no RPC tests or runner exist. PROPOSED codec property/fuzz tests, loopback client/server tests, independent language byte fixtures, handler-lifetime races, credit starvation and partition proxies precede implementation acceptance. Register future targets before using command templates in [VALIDATION](../VALIDATION.md) / [BUILD-AND-DISTRIBUTION](../BUILD-AND-DISTRIBUTION.md). Measure unary small/large payload, persistent connection and concurrent streams; report p50/p95/p99, throughput, allocations, RSS/CPU and build cost via [PERFORMANCE](../PERFORMANCE.md), including overload and cancellation latency. Rollout negotiates envelope/schema before methods become ready. Support old+new major listeners side by side during migration; never reinterpret frames after a failed decode. Rollback stops new-major admission, drains calls and preserves old schema readers. Handler side effects require domain-level forward/rollback policy. See [MIGRATION](../MIGRATION.md), [Replication](Replication.md) and [NetworkedApplications](../platforms/NetworkedApplications.md).