connectrpc 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +57 -21
  3. data/docs/design.md +245 -52
  4. data/docs/development.md +102 -14
  5. data/docs/grpc-web.md +30 -13
  6. data/docs/grpc.md +98 -5
  7. data/docs/rbs.md +56 -19
  8. data/docs/streaming.md +80 -34
  9. data/docs/unary.md +269 -45
  10. data/lib/connectrpc/bindings/google_protobuf.rb +20 -7
  11. data/lib/connectrpc/client.rb +47 -22
  12. data/lib/connectrpc/deadline.rb +27 -6
  13. data/lib/connectrpc/error.rb +2 -2
  14. data/lib/connectrpc/generator/names.rb +17 -0
  15. data/lib/connectrpc/generator/rbs_renderer.rb +4 -3
  16. data/lib/connectrpc/generator/renderer.rb +35 -3
  17. data/lib/connectrpc/generator/runtime_names.rb +23 -5
  18. data/lib/connectrpc/generator/schema.rb +14 -7
  19. data/lib/connectrpc/grpc.rb +7 -4
  20. data/lib/connectrpc/grpc_client.rb +2 -2
  21. data/lib/connectrpc/grpc_server.rb +14 -14
  22. data/lib/connectrpc/grpc_web_cors.rb +12 -4
  23. data/lib/connectrpc/grpc_web_server.rb +19 -13
  24. data/lib/connectrpc/instrumentation.rb +47 -7
  25. data/lib/connectrpc/keepalive.rb +40 -0
  26. data/lib/connectrpc/method.rb +8 -8
  27. data/lib/connectrpc/metrics/connection_observer.rb +46 -17
  28. data/lib/connectrpc/metrics/definitions.rb +6 -2
  29. data/lib/connectrpc/protocol.rb +64 -11
  30. data/lib/connectrpc/proxy.rb +425 -0
  31. data/lib/connectrpc/server.rb +97 -13
  32. data/lib/connectrpc/streaming/client.rb +22 -25
  33. data/lib/connectrpc/streaming/client_execution.rb +2 -1
  34. data/lib/connectrpc/streaming/client_scope.rb +14 -7
  35. data/lib/connectrpc/streaming/server.rb +1 -0
  36. data/lib/connectrpc/streaming/server_terminal.rb +57 -14
  37. data/lib/connectrpc/streaming/session_messages.rb +12 -5
  38. data/lib/connectrpc/streaming/streams.rb +17 -6
  39. data/lib/connectrpc/streaming/terminal.rb +3 -5
  40. data/lib/connectrpc/transports/net_http.rb +512 -52
  41. data/lib/connectrpc/version.rb +1 -1
  42. data/lib/connectrpc.rb +1 -0
  43. data/sig/connectrpc.rbs +63 -17
  44. metadata +6 -2
data/docs/design.md CHANGED
@@ -6,24 +6,40 @@ boundary and the remaining adoption gates.
6
6
  The gem implements typed Connect RPCs and native HTTP/2 gRPC in all four RPC shapes.
7
7
  Falcon also serves Connect HTTP/1.1 server/client streaming. The explicit Async
8
8
  HTTP1Transport supports Connect unary and server/client streaming; standalone
9
- Async Host remains H2-only. The streaming guide records
10
- the response-first discard limits and cooperative 500 ms total final-close
11
- policy. Shared protocol code is independent of HTTP hosting and concrete
12
- protobuf classes. The public require is `connectrpc`, and the Ruby namespace is
13
- `ConnectRPC`. The API is experimental.
9
+ Async Host remains H2-only. The streaming guide records the read of unread input
10
+ before the response and the cooperative 500 ms total final-close policy. Shared
11
+ protocol code is independent of HTTP hosting and concrete protobuf classes. The
12
+ public require is `connectrpc`, and the Ruby namespace is `ConnectRPC`. The API
13
+ is experimental.
14
14
 
15
15
  ## Shared boundaries
16
16
 
17
17
  `Method` holds validated service/method names, request/response binding types,
18
18
  `cardinality: :unary`, `idempotency: :unknown` (or `:no_side_effects` / `:idempotent`),
19
- and a case-sensitive path. Only `:no_side_effects` admits GET. `Service` validates its method
20
- set. Streaming uses invariant sibling declarations, keeping unary Method
19
+ and a case-sensitive path. Only `:no_side_effects` admits GET. `Service` validates its
20
+ declaration set, exposed as `rpcs` so that `Object#methods` keeps its reflection
21
+ meaning. Streaming uses invariant sibling declarations, keeping unary Method
21
22
  assignability intact. Generated service glue reuses these objects.
23
+
24
+ `ConnectRPC::Method` keeps its name. Inside `module ConnectRPC`, including
25
+ library code and application code nested in that namespace, a bare `Method`
26
+ resolves to the library class; write `::Method` for Ruby's bound-method class.
22
27
  The [streaming guide](streaming.md) owns its scoped APIs, publication/completion
23
28
  boundaries, finite transport SPI and absolute recovery/tail policies.
24
29
 
25
30
  `Client` owns request encoding, protocol headers, response validation, errors,
26
31
  metadata, byte limits and the deadline. Base URL path prefixes are retained.
32
+ Each call selects one effective deadline at setup, the earlier of
33
+ `Deadline.new(timeout)` on the shared monotonic clock and an explicit
34
+ `deadline:`, reusing the supplied object when it is strictly earlier. Deadlines
35
+ on that clock compare absolute expiries. A `deadline:` built on a custom
36
+ `clock:` is compared with the call's timeout by remaining time at call setup,
37
+ so the choice can be off by the time between those two clock reads; deadlines
38
+ on the default clock compare exactly. The selected deadline drives local
39
+ cancellation, the wire timeout and interceptor-visible facts. A zero or negative budget is already expired and
40
+ fails before transport dispatch. Deadlines never propagate implicitly through
41
+ thread or fiber storage: storage copied into a lazily created pool thread would
42
+ leak one request's deadline into later jobs.
27
43
  A binding provides `encode(message, type:, codec:)` and
28
44
  `decode(bytes, type:, codec:)`. Custom bindings raise `CodecError` for invalid
29
45
  messages. The optional Google binding delegates binary and
@@ -37,7 +53,7 @@ A transport provides `call(request)` with these host-neutral value objects:
37
53
  | Object | Fields |
38
54
  | --- | --- |
39
55
  | `TransportRequest` | `url` (URI), `http_method`, `headers` (lower-case keys, string arrays), `body` (bytes), `response_limit`, `deadline`, `lifecycle`, `cancellation` |
40
- | `TransportResponse` | `status` (integer), `headers` (repeated string arrays), `body` (bounded bytes) |
56
+ | `TransportResponse` | `status` (integer), `headers` (repeated string arrays), `body` (bounded bytes); optional `cause` accessor, outside the record members, holding an in-process exception that is never sent |
41
57
  | `Response` | `message` (binding type), `metadata`, `trailers` (Metadata objects) |
42
58
 
43
59
  `TransportRequest.deadline` is a `Deadline` or `nil`. Custom transports must
@@ -52,11 +68,15 @@ an optional downstream app and routes `PATH_INFO`; unrelated service paths
52
68
  fall through, while unknown methods within registered services fail explicitly.
53
69
  Neither core nor handlers need Rack envs. The optional `connectrpc-rack` package
54
70
  owns `connectrpc/rack` exclusively and loads core through `require "connectrpc"`.
55
- Applications add `gem "connectrpc-rack", "~> 0.2.0"` while keeping the require
71
+ Applications add `gem "connectrpc-rack", "~> 0.3.0"` while keeping the require
56
72
  and `ConnectRPC::Rack` API unchanged. Core has no middleware file or runtime
57
73
  dependencies; requiring middleware without its package raises an ordinary
58
74
  `LoadError`. Google loads only through `connectrpc/bindings/google_protobuf`;
59
- its missing/incompatible dependency diagnostic remains useful. The middleware
75
+ its missing/incompatible dependency diagnostic remains useful. An omitted or nil
76
+ `binding:` on Client, Server and `ErrorDetail#decode` resolves to a new Google
77
+ binding only when that file is already loaded; otherwise the constructor raises
78
+ `ArgumentError` naming the require. Core never requires it on the caller's
79
+ behalf. The middleware
60
80
  retains its own Rack version activation diagnostic.
61
81
 
62
82
  A default invoker calls the registered plain handler with `(request, context)`.
@@ -83,8 +103,9 @@ Single identity/gzip content codings are case-insensitive; empty, repeated,
83
103
  stacked and unknown content codings are rejected. Identity-only servers continue
84
104
  to reject gzip. Client response preferences use distinct symbol arrays and
85
105
  normalize identity to the last fallback. Server gzip capability negotiates
86
- supported nonidentity accept tokens before identity, ignoring unknown/quality
87
- value tokens. Absent accept inherits request coding; empty accept selects identity.
106
+ supported nonidentity accept tokens before identity, ignoring unknown tokens
107
+ and nonzero quality values; `gzip;q=0` refuses gzip. Absent accept inherits
108
+ request coding; empty accept selects identity.
88
109
  Repeated accept fields combine in field order. Gzip-selected empty serialization
89
110
  produces a valid nonempty member; zero-length HTTP content bypasses inflation
90
111
  after header validation. Every concatenated member validates CRC/ISIZE/completion;
@@ -186,17 +207,22 @@ valid metadata/trailers; malformed gzip 200 is internal. Header rejection stays
186
207
  internal, local size excess stays resource_exhausted, and actual expiry stays
187
208
  deadline_exceeded. No generic error-body rescue changes those classifications.
188
209
 
189
- The default timeout is 30 seconds. Explicit `timeout: nil` means no logical
190
- client deadline, timeout header or expiry watchdog. Native operation waits still
210
+ The default timeout is 30 seconds. Explicit `timeout: nil` removes only the
211
+ relative budget; a call has no logical client deadline, timeout header or expiry
212
+ watchdog only with both `timeout: nil` and no `deadline:`. Native operation waits still
191
213
  use the exact `9_999_999.999` second cap, returning `unavailable` on timeout.
192
214
  Sustained progress can outlast this per-operation cap. For finite positive
193
215
  timeouts, one monotonic client deadline begins before encoding. Remaining timeout milliseconds are
194
216
  rounded up and clamped to ten digits without extending actual expiry. NetHTTP
195
217
  recomputes the header at dispatch and checks the budget around connection,
196
218
  codec and body progress. Each call owns one connection; a finite deadline also owns one watchdog. The
197
- watchdog closes the owned raw socket on expiry, including during header
198
- trickle, stalled reads and blocked writes, and is joined on every exit.
199
- NetHTTP depends on the pinned stdlib BufferedIO socket layout for that close.
219
+ watchdog starts before TCP connect and closes whichever raw socket the call
220
+ currently owns on expiry, including during TCP connect, a proxy `CONNECT`
221
+ exchange, the TLS handshake, header trickle, stalled reads and blocked writes,
222
+ and is joined on every exit. NetHTTP's `Connection` overrides `Net::HTTP#connect`
223
+ to own TCP, proxy `CONNECT` and TLS setup, so it no longer reads Net::HTTP's
224
+ BufferedIO socket layout; Net::HTTP still writes the request and parses the
225
+ response.
200
226
  Request preparation finishes before connecting, with an expiry check afterward.
201
227
  The connection checks expiry and recomputes the wire timeout immediately before
202
228
  dispatch, and rejects Net::HTTP's implicit reconnect of a closed socket. This
@@ -210,12 +236,27 @@ it after each capped wait and only closes the socket at actual expiry. Local
210
236
  huge-budget calls verify conversions on the exercised plain TCP paths, not an
211
237
  actual 115-day duration or runtime TLS behavior.
212
238
 
213
- DNS/native resolution may outlast the budget. Net::HTTP's internal connection
214
- implementation can itself use `Timeout.timeout` on Ruby 3.4; ConnectRPC never
215
- calls it or asynchronously interrupts application code. TLS handshake timeout
216
- uses the remaining budget after TCP/DNS. Peer/hostname verification stays on.
217
- There is no pooling, proxy-env routing, retries, redirect following, automatic
218
- decompression. NetHTTP constructs requests with the actual explicit accept
239
+ DNS/native resolution may outlast the budget. Resolution passes the remaining
240
+ budget to `Addrinfo.getaddrinfo`. Resolved addresses are dialed as Go's
241
+ `net.Dialer` does: addresses of the first address's family are tried in order,
242
+ each with an equal share of the remaining deadline but at least 2 seconds, and
243
+ the other family starts 300 ms later, or at once if the first family fails. At
244
+ most two nonblocking connects, one per family, are in flight in the calling
245
+ thread, without `Timeout.timeout`; ConnectRPC never asynchronously interrupts
246
+ application code. The first connection wins and every other attempt closes.
247
+ TLS handshake timeout uses the remaining budget after TCP/DNS. Peer/hostname
248
+ verification stays on (TLS 1.2 minimum, ALPN `http/1.1`, session cache off).
249
+ Transports without TLS options share one default TLS context, built with the
250
+ system trust store on first HTTPS use; a transport with TLS options builds its
251
+ own at construction. Since 0.3.0,
252
+ `ConnectRPC::Proxy` resolves the proxy for each URL, from a per-transport
253
+ snapshot of the Go `net/http` proxy environment or an explicit `proxy:`. HTTPS
254
+ targets tunnel with a transport-owned `CONNECT` exchange: its reply head is
255
+ read with a 10 MiB bound and a 60 second cap, must be exactly status 200 with no
256
+ trailing bytes, and only fixed phrases reach errors. HTTP targets use
257
+ Net::HTTP's absolute-form proxy requests. There is no pooling, retries, redirect
258
+ following or automatic decompression. The wire carries exactly the request's
259
+ `user-agent` values. NetHTTP constructs requests with the actual explicit accept
219
260
  advertisement so the default HTTP gem never transparently inflates or rewrites
220
261
  content encoding/length; transports carry opaque encoded bytes.
221
262
 
@@ -246,8 +287,14 @@ serialized winner. Completion directly rechecks source state, including after
246
287
  decoding or exceptional codec/transport paths. HTTP response receipt alone
247
288
  cannot complete the client. Instrumentation and callbacks run outside state
248
289
  locks, and only the executing fibers complete instrumentation. Every error core
249
- normalizes from a rescued exception has a fixed safe message and no `cause`;
250
- lifecycle observers receive the original failure.
290
+ normalizes from a rescued codec, compression or metadata exception has a fixed
291
+ safe message and no `cause`; lifecycle observers receive the original failure.
292
+ Client transport connection failures are local to the caller, so they carry a
293
+ fixed classified phrase, such as `HTTP transport failed: connection refused`,
294
+ and keep the original exception as `cause`. The phrase never includes hosts,
295
+ addresses, paths or certificate text. A handler that re-raises such an error
296
+ sends only its code and message to its peer; `cause` is never serialized, and
297
+ server-produced, peer-facing messages stay redacted.
251
298
 
252
299
  `TransportRequest.deadline` remains the actual Deadline or nil.
253
300
  `TransportRequest.cancellation` and `StreamRequest.cancellation` implement
@@ -264,10 +311,19 @@ Custom transports migrating from earlier releases receive the read-only view.
264
311
  Code that called `commit!` or `close` on `request.cancellation`, which was never
265
312
  part of the typed SPI, must stop; core completes the call itself.
266
313
 
267
- NetHTTP installs socket ownership before startup, attaches raw TCP at the TLS
268
- hook or after plain startup, and closes a newly exposed socket immediately if
269
- cancellation already won. TLS/read/write/header waits are interruptible; native
270
- DNS/TCP before exposure remains cooperative. Per-call retirement prevents late
314
+ NetHTTP installs socket ownership before startup and attaches each raw socket
315
+ when it is created, before its TCP connect starts. A socket created after
316
+ cancellation or expiry won is closed immediately. While dialing, the owner
317
+ holds at most two attempts, one per address family; once connected it holds
318
+ exactly the call's one connection. Every attempt that does not become the
319
+ connection is closed, including when an outer interruption such as
320
+ `Thread#raise` lands mid-dial. Cancellation and expiry shut sockets down
321
+ before closing them: on Linux that aborts a pending connect and wakes the
322
+ dialer's `IO.select`, which a close from another thread alone does not. A
323
+ socket that cannot shut down because it never started connecting is still
324
+ closed. TCP connect, proxy `CONNECT`, TLS, read, write and
325
+ header waits are interruptible; native DNS resolution remains cooperative.
326
+ Per-call retirement prevents late
271
327
  callbacks from accessing completed/recycled resources. Nil deadlines have no
272
328
  watchdog or wire timeout; the exact independent native cap remains
273
329
  `9_999_999.999`. Retry/reconnect guards and TLS verification remain enabled.
@@ -276,7 +332,7 @@ Async foreign-thread listeners only resolve a tagged Promise. Its owner reactor
276
332
  arbitrates, stops private operation/setup tasks and performs bounded cleanup.
277
333
  Promise resolution order does not decide the RPC outcome. Healthy stream reset
278
334
  preserves the shared connection and siblings; a stuck deferred frame retains the one
279
- 100 ms cleanup budget and raw-first whole-connection fallback.
335
+ 1-second cleanup budget and raw-first whole-connection fallback.
280
336
 
281
337
  Native HTTP/2 creates a request cancellation source before processing,
282
338
  independently of instrumentation. Only peer RST_STREAM with CANCEL (0x8) signals
@@ -354,7 +410,7 @@ required. Full TLS snapshots enable required client authentication, same-listene
354
410
  credential reload and older-generation retirement. The exact-task client leaf
355
411
  accessor is the optional authorization seam; peer-presented chains are not
356
412
  claimed to be verified chains. See the package guide for session isolation,
357
- cleanup's 100ms allowance and deliberate whole-connection failure for a stuck
413
+ cleanup's 1-second allowance and deliberate whole-connection failure for a stuck
358
414
  frame. Native streaming uses the same ingress and cleanup boundaries. No production daemon claim is made.
359
415
  The H2 client's private, reactor-owned connection manager runs shared connection
360
416
  attempts outside every RPC lifecycle and owns stream accounting, capped jittered
@@ -398,7 +454,7 @@ actual final HTTP/2 HEADERS, as described in the [gRPC guide](grpc.md).
398
454
  For Connect, the Async backend preserves leading repeated fields and leading
399
455
  `trailer-*` metadata while ignoring actual trailing HEADERS after backend validation.
400
456
  It reconstructs lengths normalized by the backend; malformed lengths and some
401
- singleton repeats can fail before core. Conservative frame/window settings do
457
+ singleton repeats can fail before core. Bounded frame/window settings do
402
458
  not provide a hard process-memory/header-size guarantee. Independent connect-go
403
459
  unary h2c/TLS/mTLS results are separate from core's identity and gzip conformance
404
460
  profiles. Combined gzip specs exercise opaque bytes and wire/decompressed bounds
@@ -417,10 +473,11 @@ and callback boundaries during retirement. On a successful write,
417
473
  protocol-http1 closes the body only after the final flush. A private
418
474
  response-body wrapper establishes one absolute 500 ms final-close expiry at
419
475
  that error-free close after EOF or HEAD, before the body's close callbacks. A
420
- response without a body anchors when the writer returns. Successfully delivered
421
- retiring Connect responses half-close raw TCP writes, retain the original
422
- 100 ms / 256 KiB bounded discard, then wait only the remaining total budget
423
- without further reads. Admission/socket ownership joins original processing and
476
+ response without a body anchors when the writer returns. Retiring Connect
477
+ requests read up to 256 KiB of unread input before the response head, as
478
+ net/http does. Successfully delivered retiring responses half-close raw TCP
479
+ writes, then wait only the remaining total budget without further reads.
480
+ Admission/socket ownership joins original processing and
424
481
  retirement; owner shutdown can shorten either phase. These cooperative timers
425
482
  can overshoot under scheduler delay and do not guarantee peer receipt. The
426
483
  independent Web rejected-input policy is unchanged. Only explicit Rack fallback
@@ -437,14 +494,26 @@ return `CodeGeneratorResponse.error`, no partial files and exit zero. Unexpected
437
494
  implementation exceptions remain visible. Only `FEATURE_PROTO3_OPTIONAL` is
438
495
  advertised; editions are unsupported.
439
496
 
440
- Each service-bearing target emits `_connect.rb`, requiring core, its official
441
- `_pb.rb` and any additionally referenced message files. Imported streaming
497
+ Each service-bearing target emits `_connect.rb`, requiring core, the Google
498
+ binding, its official `_pb.rb` and any additionally referenced message files. Imported streaming
442
499
  services are not targets. Generated modules
443
500
  contain frozen RPC declaration constants, `SERVICE`, a `Client` initialized with
444
- `client:`, and `.handlers` with required callable RPC keywords. Unary wrappers forward `call(METHOD, request, **options)` unchanged. Streaming
445
- wrappers forward the matching scoped operation, its required block and all options.
446
- Partial handlers/custom invocation remain core Server features. No framework,
447
- transport configuration or binding auto-require is added.
501
+ `client:`, `.handlers` with required callable RPC keywords, and
502
+ `.handlers_for(impl, strict: false)`, which maps each RPC path to
503
+ `impl.public_method(name)` when `impl.respond_to?(name)` for the RPC's
504
+ snake-case name and omits the rest (`strict: true` raises naming them). A
505
+ method whose owner is in `Class.ancestors` at lookup time also counts as
506
+ missing. That set holds `Object`'s ancestors, including modules frameworks
507
+ include or prepend later, plus `Module` and `Class`, which only module
508
+ implementations inherit from. Inherited core and framework methods such as
509
+ ActiveSupport's `Object#try` are therefore never bound. A handler module that
510
+ is also mixed into `Object`, `Module` or `Class` counts as a core method and is
511
+ not bound. Unary wrappers forward
512
+ `call(METHOD, request, **options)` unchanged. Streaming wrappers forward the matching scoped operation, its
513
+ required block and all options. Partial handlers/custom invocation remain core
514
+ Server features. The generated file requires the Google binding because its
515
+ declarations already use Google message classes; no framework or transport
516
+ configuration is added.
448
517
  Optional [RBS signatures](rbs.md) preserve these runtime boundaries and require
449
518
  `rbs=true` for service signature generation.
450
519
  Concrete types come from the official generated descriptor pool, preserving
@@ -471,8 +540,19 @@ roots the runtime loads, such as `URI`, `Zlib`, `Net` and `OpenSSL`), and concre
471
540
  protobuf runtime names such as `Google::Protobuf::DescriptorPool` are rejected. Known
472
541
  official protobuf types are accepted only under their canonical file, proto name
473
542
  and Ruby namespace, preserving WKT imports without allowing application types to
474
- replace them. The fixed policy follows the pinned protobuf sources, rather than
475
- reflecting the generator process's constants. A service cannot merge with
543
+ replace them. Packages may also nest under the interpreter's plain modules that no
544
+ other module includes or extends and that core does not load from the standard
545
+ library: `FileTest`, `GC`, `Marshal`, `Math`, `ObjectSpace`, `Process` and
546
+ `Signal`. Official output reopens them, so `math.v1` becomes `Math::V1`. Their
547
+ existing constants stay protected: a package may reopen a module child such as
548
+ `Process::Sys`, but no message, enum or service may replace one, and nothing may
549
+ be declared at or below a value or class child such as `Math::E` or
550
+ `Process::Status`. A top-level message, enum or service named after one of these
551
+ roots, mixed-in modules such as `Kernel` and `Comparable`, `Errno` and class roots
552
+ stay rejected. Reserved-constant errors suggest the `ruby_package` file option.
553
+ The fixed policy follows the pinned protobuf sources and the Ruby 3.4/4.0
554
+ builtin modules, rather than reflecting the generator process's constants; a
555
+ spec compares the builtin data with the running interpreter. A service cannot merge with
476
556
  another package. No global registry spans generator invocations.
477
557
  Generated files guard directly defined `SERVICE`, `Client` and RPC constants;
478
558
  normal `require` is idempotent, while deliberate `load`/redefinition fails clearly.
@@ -487,6 +567,46 @@ and [Rack specification](https://github.com/rack/rack/blob/v3.2.7/SPEC.rdoc).
487
567
 
488
568
  See the optional [in-process testing package](../gems/connectrpc-testing/README.md) for real encoded client/server round trips without sockets.
489
569
 
570
+ ## Async teardown and interrupts
571
+
572
+ New and changed code in the Async and Falcon packages follows five rules for
573
+ close, abort, retirement and interrupts. Each guarantee should protect the
574
+ wire, a descriptor or a documented result. Precision beyond that costs more
575
+ than it returns. async-http, grpc-go and net/http keep teardown similarly
576
+ simple: grpc-go returns a cancelled stream at once and cleans up on the
577
+ connection's writer, and net/http's `Shutdown(ctx)` returns when its context
578
+ ends and leaves the remaining connections to `Close`.
579
+
580
+ 1. Interrupts end waits, not work. Teardown runs in a task the resource owns.
581
+ Grace bounds the connection drain, after which teardown forces retirement,
582
+ which still waits for cooperative tasks to leave (see the package guide's
583
+ cleanup allowance and task joins). A caller that is cancelled, times out or
584
+ is interrupted gets its exception promptly while teardown continues on its
585
+ own. A later close joins it, and `close(grace: 0)` forces it.
586
+ 2. Inside a reactor, only cooperative cancellation is supported: deadlines,
587
+ `CancellationToken`s, Async task cancellation, `with_timeout` and
588
+ `Timeout.timeout` called from an Async task, which Ruby routes through the
589
+ fiber scheduler. These land only where a fiber suspends. `Thread#raise` and
590
+ `Thread#kill` from another thread into a reactor thread are unsupported.
591
+ Ruby delivers them to whichever fiber is running, Async's own scheduler
592
+ included, and `Thread.handle_interrupt` masks are per thread, so no library
593
+ mask can confine them to one task. A caller on a thread that runs no
594
+ reactor, such as a `ThreadedTransport` caller or `PerCallTransport` outside
595
+ a reactor, can use them.
596
+ 3. Joins exist for descriptor safety: a connection's descriptor closes only
597
+ after every fiber that might touch it has left. Listener shutdown likewise
598
+ cancels and joins each accept loop before it closes the listening socket.
599
+ 4. Teardown failures don't become caller outcomes. A close reports whether it
600
+ drained or forced. A failed step never skips a later one and is written as
601
+ a warning that names only its class.
602
+ 5. Wire behavior keeps its precision: the two-phase GOAWAY,
603
+ `RST_STREAM(CANCEL)`, the cleanup allowance, write watchdogs and raw-first
604
+ retirement. Whether a drain succeeded should depend on whether its streams
605
+ finished in time, not on how the peer left afterwards.
606
+
607
+ Rule 3 may let most of the private completion join go.
608
+ [#200](https://github.com/jimeh/connectrpc-ruby/issues/200) tracks this.
609
+
490
610
  ## RPC lifecycle observation
491
611
 
492
612
  `Instrumentation.new(subscribers:, on_error: nil)` freezes a copied subscriber
@@ -524,6 +644,21 @@ Prometheus and Yabeda packages.
524
644
 
525
645
  Call facts contain role, Connect protocol, recognized immutable Method or nil,
526
646
  client endpoint host/port and a propagation carrier, never message objects.
647
+ Since 0.3.0, client calls also carry the request's `url_scheme`, its `url_path`
648
+ (base path plus method path, never a GET query, which can carry the message)
649
+ and the client transport's `transport_class`, so a subscriber can match URL
650
+ propagation targets and recognize transports that its SDK already patches.
651
+ These are nil on servers and default to nil for earlier `Call.new` callers.
652
+ Since 0.3.0, server calls carry the address the client used, from a single
653
+ `host` header value (Rack passes `Host`; the native Async and Falcon hosts pass
654
+ the request authority, which wins over an ordinary `host` field, even when
655
+ empty): host names of dot-separated letter, digit, `_` and inner `-` labels
656
+ (IPv4 addresses included, one trailing dot allowed) and bracketed IPv6
657
+ addresses that `IPAddr` accepts, without a zone (stored without brackets),
658
+ with a port only when the authority states one whose value is between 1 and
659
+ 65535. Repeated, empty, over-255-byte, non-ASCII, invalidly encoded or
660
+ otherwise invalid values yield neither fact, and reading the authority never
661
+ fails the call.
527
662
  The client starts before timeout/metadata validation and applies validated staged
528
663
  injection transactionally to copied metadata. An injected key replaces the
529
664
  caller's values, except `baggage`, which becomes the caller's values followed by
@@ -542,6 +677,31 @@ normalized/replacement exceptions, emitted Connect code, HTTP status, monotonic
542
677
  processing duration and measured encoded byte counts. Unknown byte counts are
543
678
  nil. Metadata snapshots retain repeated arrays.
544
679
 
680
+ `Outcome#response_metadata` holds response headers and, since 0.3.0,
681
+ `Outcome#response_trailers` holds trailing metadata without any `trailer-`
682
+ wire prefix; both are frozen snapshots and `Outcome.new` defaults trailers to
683
+ empty. Connect unary splits its `trailer-*` headers into trailers, dropping
684
+ reserved and invalid names. The Connect unary response writes no field for a
685
+ trailer without values, as Go net/http does on every host, and the outcome
686
+ omits it too. A server stream, gRPC or gRPC-Web outcome keeps
687
+ `Context#response_metadata` at observation time as its headers (what the
688
+ handler set for the head, published or attempted, without generated Web fields
689
+ such as `vary` or CORS), and as trailers the application and error metadata
690
+ that the rendered terminal carries. When processing has already recorded a
691
+ failure as terminal rendering begins, including one raised after the handler
692
+ returned, such as a response over its limit, the outcome is observed before the
693
+ head and terminal are written. Otherwise, including when rendering itself
694
+ replaces the terminal for its byte limit, it is observed after the terminal is
695
+ handed to the output. gRPC and gRPC-Web write one field line per value, so they
696
+ omit a trailer name without values, which the Connect stream terminal JSON
697
+ keeps. A terminal replaced for its byte limit or a status codec failure carries
698
+ none, and a stream that fails before its terminal is serialized has none.
699
+ Streaming clients, including gRPC unary, record only metadata the session
700
+ already accepted, never reading at finish: the validated response head (empty
701
+ when the head was rejected or not yet read, and for a gRPC trailers-only
702
+ response) and the parsed terminal trailers, which stay recorded when a later
703
+ count, tail or transport check fails.
704
+
545
705
  `Server#start_call(path:, headers:, http_method: "POST")` is the explicit host
546
706
  SPI. Hosts pass the actual method so Connect GET selection precedes subscriber
547
707
  start, regardless of ignored POST content headers. It resolves a known method
@@ -565,13 +725,15 @@ Admission-only calls have no fabricated processing result. Portable Rack
565
725
  response-finished callbacks take precedence over body close and have their own
566
726
  label; they never claim native full-write completion. A consumer that neither
567
727
  closes a body nor runs promised callbacks can leave observation unfinished.
568
- Native Async/Falcon own explicit request exchanges before admission, independent
569
- handler activation and write/reset/cleanup evidence. Connection setup before an
570
- RPC exists remains outside this scope. See the
728
+ Native Async/Falcon own explicit request exchanges before handler start,
729
+ independent handler activation and write/reset/cleanup evidence. An HTTP/2
730
+ stream that full host admission refuses while its HEADERS are read gets its
731
+ exchange after the refusal, in a session task, and is never activated.
732
+ Connection setup before an RPC exists remains outside this scope. See the
571
733
  [OTel guide](../gems/connectrpc-otel/README.md) for trace semantics, privacy,
572
734
  HTTP instrumentation nesting and synchronous processor costs.
573
735
 
574
- The optional Sentry package uses the same callbacks without core changes. Its
736
+ The optional Sentry package uses the same callbacks and call facts. Its
575
737
  server observation nests under an open host span and ends at
576
738
  `processing_finished`, because Rack and Rails hosts send their request
577
739
  transaction before delivery completes; without a host span it owns a
@@ -585,10 +747,11 @@ its callbacks is independent of the executing context. See the
585
747
 
586
748
  The Async package's independent `HTTP1Transport` uses exclusive reactor-owned
587
749
  leases for Connect unary, safe GET and SS/CS. Reservations precede yielding
588
- TCP/TLS setup; retiring resources count toward the cap until raw close and task
589
- joins finish. Idle reuse requires normal writer completion, full HTTP EOF,
590
- successful cleanup and native persistent/idle state. A nonblocking acquisition
591
- probe retires FIN or unsolicited data before dispatch. No failed call is replayed.
750
+ TCP/TLS setup; retiring resources count toward the cap until their task joins
751
+ and final raw close finish. Idle reuse requires normal writer completion, full
752
+ HTTP EOF, successful cleanup and native persistent/idle state. A nonblocking
753
+ acquisition probe retires FIN or unsolicited data before dispatch. No failed call
754
+ is replayed.
592
755
 
593
756
  A private H1 stream separates response reads from output flushing and caps native
594
757
  body fragments at 16 KiB. Strict HTTP/1.1 status syntax preserves three-digit
@@ -602,3 +765,33 @@ TLS offers only `http/1.1`, accepts nil or H1 ALPN, and rejects other negotiatio
602
765
  before dispatch. Hostname/peer verification and mTLS remain enabled. The shared
603
766
  private TLS helper retains H2's existing default. H1 changes no server runtime
604
767
  policy, H2 connection ownership, or Web rejection behavior.
768
+
769
+ ## Reactor-free native client transport
770
+
771
+ Since 0.3.0, the optional `connectrpc-hyper` package provides
772
+ `ConnectRPC::Hyper::Transport`, a client transport for core's unary, streaming
773
+ and native gRPC SPIs that needs no Async reactor. Core keeps every protocol
774
+ decision: encoding, framing, headers, limits, deadlines, cancellation and error
775
+ mapping. The transport only moves the encoded request and response over hyper,
776
+ h2 and rustls in a Rust extension, so it adds no protocol code and core gains
777
+ no dependency on it.
778
+
779
+ Rust owns connections, streams, flow control and waits; Ruby owns option
780
+ validation, TLS input validation (with OpenSSL, as core NetHTTP), fixed error
781
+ phrases and the lifecycle hooks. Each native wait releases the GVL with an
782
+ unblocking function that only signals, runs under `rb_protect`, and resumes the
783
+ same operation after a wake without a pending interrupt, so `Thread#raise`,
784
+ `Thread#kill`, deadlines and cancellation tokens land at every stage without
785
+ repeating a side effect. Rust never calls Ruby from a worker thread. A
786
+ process-wide tokio runtime with two workers is created lazily and checked
787
+ against the owning PID, so a forked child builds its own runtime and
788
+ connections and closes the inherited connection sockets it can identify.
789
+
790
+ One admitting HTTP/2 connection per origin is shared by every thread; GOAWAY
791
+ retires it while a new connection admits, and reconnection is lazy, without
792
+ backoff or `wait_for_ready`. That connection policy is deliberately smaller
793
+ than connectrpc-async's. Applications already on Async keep its transports;
794
+ calls from inside a reactor block it unless Ruby 4.0 and async's worker pool
795
+ offload the wait. The [package guide](../gems/connectrpc-hyper/README.md) owns
796
+ its options, platform gems and rustls differences, and
797
+ [the plan](plans/hyper.md) records the decisions.