Jeff Bahr
90d · built 2026-11-22
Performance
What Jeff Bahr shipped in the selected window, measured in ETV, and how it compares with the 90 days before it.
Effective capacity
+52.8engineers
delivers like 53.8 (53.8x pre-AI)
Output (ETV)
38.2ETV
+388.1% vs 7.8 prior
Features share
22.0%
−4.9 pp vs prior window
Fixes share
9.6%
−2.4 pp vs prior window
Work mix
22% Features4.4% Maintenance62.5% Tests1.5% Docs9.6% Fixes
61 commits over 90 days, ending 2026-11-22.
Daily performance
Daily ETV, stacked by Features, Maintenance, Tests, Docs and Fixes.
Repository spread
Where this developer's commits land. Concentrated work (top1 > 80%) vs polymath spread (top1 < 30%).
Most impactful commits
Top 10 by ETV in the last 90 days.
- 3.3ETVReturn Mono<ResponseAndStream> for streams with a first response Summary: Change the Java API for a stream method that has a first response. The method now returns `Mono<ResponseAndStream<F, E>>` instead of `Flux<StreamResponse<F, E>>`. The change applies to the generated client, the service interface that a server implements, and interaction members. The new API keeps the first response and the stream elements separate. The first response has its own type, and errors have a clear scope. ## API change The IDL does not change: ``` service Feed { FeedHeader, stream<FeedItem throws (1: FeedError err)> subscribe(1: Request req) throws (1: AuthError err); } ``` The generated Java signature changes: ```java // Before: one Flux of a union type. Element 0 holds the first response. Flux<StreamResponse<FeedHeader, FeedItem>> subscribe(Request req); // After: a Mono that holds the first response and the stream. Mono<ResponseAndStream<FeedHeader, FeedItem>> subscribe(Request req); ``` The `Wrapper` variant keeps the headers of the first response and of each element: ```java Mono<ResponseWrapper<ResponseAndStream<FeedHeader, ResponseWrapper<FeedItem>>>> subscribeWrapper(Request req, RpcOptions options); ``` `ResponseAndStream<F, E>` (package `com.facebook.thrift.model`) has these members: ```java F getFirstResponse(); // never null Flux<E> getStream(); // subscribe one time only <E2> ResponseAndStream<F, E2> mapStream(Function<Flux<E>, Flux<E2>> mapper); void dispose(); // abandons the stream (see the rule below) static <F, E> ResponseAndStream<F, E> of(F firstResponse, Flux<E> stream); ``` ## Client usage Read the first response, then the stream: ```java client.subscribe(req) .flatMapMany(ras -> { onHeader(ras.getFirstResponse()); return ras.getStream(); }) .subscribe(this::onItem, this::onError); ``` Use the first response only, and drop the stream: ```java FeedHeader header = client.subscribe(req) .map(ras -> { ras.dispose(); return ras.getFirstResponse(); }) .block(); ``` Handle each error scope: ```java client.subscribe(req) .flatMapMany(ResponseAndStream::getStream) .onErrorResume(AuthError.class, e -> ...) // function error: the outer Mono failed .onErrorResume(FeedError.class, e -> ...); // stream error: the inner Flux failed ``` **Rule: subscribe or dispose.** When the outer `Mono` emits the holder, the transport stream is already open and holds credits. Do one of these: - Subscribe to `getStream()` one time. - Call `dispose()`. If you do neither, the transport stream and its credits stay in use until the connection closes. Do not call `dispose()` on a stream that you read: on an active stream, `dispose()` cancels it. After the stream ends, `dispose()` has no effect. The `ResponseAndStream` javadoc and the agent rules in `thrift/lib/java/.llms/rules/thrift_java.md` state the same rule, plus the leak-proof `Flux.usingWhen` consumption, the operator-placement table, and the `1 + 100` pre-subscribe window. ## Server usage A server implements the same signature: ```java Override public Mono<ResponseAndStream<FeedHeader, FeedItem>> subscribe(Request req) { return auth(req) // Mono<User> .map(user -> ResponseAndStream.of( new FeedHeader(user.id()), // the first response feed.items(user))); // Flux<FeedItem>, the stream } ``` The server sends errors as follows: ```java // Before the first response: initial error with function scope. return Mono.error(new AuthError("denied")); // An empty Mono is also an initial error: "the first response must not be null". // After the first response: stream error with stream scope. return Mono.just(ResponseAndStream.of(header, Flux.error(new FeedError("gone")))); ``` A handler can forward a call to a backend with no other code, because the client and the server use the same type: ```java return backendClient.subscribe(req); ``` The server subscribes to the stream after it sends the first response. If the client cancels first, the server disposes the holder, so the backend stream closes. A plain stream method (`stream<E>` with no first response) keeps its `Flux<E>` signature. ## Background A method declared as `First, stream<Elem>` sends two kinds of values on one `Flux`: the first response, then the elements. Each caller had to examine every item with `isSetFirstResponse()`. A method error and a stream error used the same `onError` signal. There was no event for "the first response arrived". The C++ server and client already keep the two parts separate (`ResponseAndServerStream`, `ResponseAndClientBufferedStream`). The Rust, Go, and Python generators use the same shape. ## Implementation Server: - Each server stream has two phases: the response phase, then the stream phase. A plain stream is a stream with an empty first response. - The generated code makes one `StreamMethod<F, E>` descriptor for each method. The descriptor holds the request readers, the typed `invoke`, the writers for the first response and the elements, and the tables of declared exceptions. - The shared helper `ServerStreams.handleStream` runs the phases. An error in the response phase is an initial error. An error in the stream phase is a stream error. ``` invoke(args) : Mono<ResponseAndStream<F, E>> ├─ throw / Mono.error / empty ──▶ initial-error frame (function exceptions) └─ holder ──▶ first-response frame ──▶ stream.map(element frame) └─ Flux error ──▶ stream-error frame (stream exceptions) ``` - This diff removes the old server path: `StreamResponseHandlerTemplate`, `StreamResponseHandler`, `StreamWithFirstResponseHandler`, `StreamHandler`, and the `SingleRequestStream*Delegate` adapters. The metadata and exception builders move to `RpcPayloadUtil`. Client: - The generated code sends the transport stream to `ResponseAndStreamBridge.toResponseAndStream`. - The bridge emits the holder when the first payload arrives. It decodes the remaining payloads as elements and keeps the headers of each element. - The holder has a lifecycle state machine (`StreamLifecycle`). It allows one subscription. It also makes sure that a dispose before, during, or after a subscription closes the transport stream exactly one time. - The first request asks for `1 + 100` credits, then adds credits as elements are consumed. This is the same as the C++ client. - Interaction methods use `toInteractionResponseAndStream`, which keeps the existing hop off the event loop. All callers that use a first response are changed: the iris worker client, jdKickStream, the rtgw stateful socket writer and its test, `SRDemo`, the Java examples, and the runtime, integration, and conformance tests. ## Result The first response has its own type. Errors have a scope: the outer `Mono` for function errors, the inner `Flux` for stream errors. The bytes on the wire do not change. Java-to-Java integration tests that decode each frame, and the conformance suites, verify this. The golden test files are removed. Reviewed By: echistyakov Differential Revision: D127765225 fbshipit-source-id: 2573342024355dae5e48b274d777544ec3d51ab4github.com-facebook-fbthrift · fe2b2ffb · 2026-11-03
- 3.2ETVReturn Mono<ResponseAndStream> for streams with a first response Summary: Reland of D127765225 (backed out in D129408444). It uses the `ServerResponsePayload` factory API (`create` for declared errors, `createWithTApplicationException` carrying the actual exception for unknown errors) that D129714868 landed. Change the Java API for a stream method that has a first response. The method now returns `Mono<ResponseAndStream<F, E>>` instead of `Flux<StreamResponse<F, E>>`. The change applies to the generated client, the service interface that a server implements, and interaction members. The new API keeps the first response and the stream elements separate. The first response has its own type, and errors have a clear scope. ## API change The IDL does not change: ``` service Feed { FeedHeader, stream<FeedItem throws (1: FeedError err)> subscribe(1: Request req) throws (1: AuthError err); } ``` The generated Java signature changes: ```java // Before: one Flux of a union type. Element 0 holds the first response. Flux<StreamResponse<FeedHeader, FeedItem>> subscribe(Request req); // After: a Mono that holds the first response and the stream. Mono<ResponseAndStream<FeedHeader, FeedItem>> subscribe(Request req); ``` The `Wrapper` variant keeps the headers of the first response and of each element: ```java Mono<ResponseWrapper<ResponseAndStream<FeedHeader, ResponseWrapper<FeedItem>>>> subscribeWrapper(Request req, RpcOptions options); ``` `ResponseAndStream<F, E>` (package `com.facebook.thrift.model`) has these members: ```java F getFirstResponse(); // never null Flux<E> getStream(); // subscribe one time only <E2> ResponseAndStream<F, E2> mapStream(Function<Flux<E>, Flux<E2>> mapper); void dispose(); // abandons the stream (see the rule below) static <F, E> ResponseAndStream<F, E> of(F firstResponse, Flux<E> stream); ``` ## Client usage Read the first response, then the stream: ```java client.subscribe(req) .flatMapMany(ras -> { onHeader(ras.getFirstResponse()); return ras.getStream(); }) .subscribe(this::onItem, this::onError); ``` Use the first response only, and drop the stream: ```java FeedHeader header = client.subscribe(req) .map(ras -> { ras.dispose(); return ras.getFirstResponse(); }) .block(); ``` Handle each error scope: ```java client.subscribe(req) .flatMapMany(ResponseAndStream::getStream) .onErrorResume(AuthError.class, e -> ...) // function error: the outer Mono failed .onErrorResume(FeedError.class, e -> ...); // stream error: the inner Flux failed ``` **Rule: subscribe or dispose.** When the outer `Mono` emits the holder, the transport stream is already open and holds credits. Do one of these: - Subscribe to `getStream()` one time. - Call `dispose()`. If you do neither, the transport stream and its credits stay in use until the connection closes. Do not call `dispose()` on a stream that you read: on an active stream, `dispose()` cancels it. After the stream ends, `dispose()` has no effect. The `ResponseAndStream` javadoc and the agent rules in `thrift/lib/java/.llms/rules/thrift_java.md` state the same rule, plus the leak-proof `Flux.usingWhen` consumption, the operator-placement table, and the `1 + 100` pre-subscribe window. ## Server usage A server implements the same signature: ```java Override public Mono<ResponseAndStream<FeedHeader, FeedItem>> subscribe(Request req) { return auth(req) // Mono<User> .map(user -> ResponseAndStream.of( new FeedHeader(user.id()), // the first response feed.items(user))); // Flux<FeedItem>, the stream } ``` The server sends errors as follows: ```java // Before the first response: initial error with function scope. return Mono.error(new AuthError("denied")); // An empty Mono is also an initial error: "the first response must not be null". // After the first response: stream error with stream scope. return Mono.just(ResponseAndStream.of(header, Flux.error(new FeedError("gone")))); ``` A handler can forward a call to a backend with no other code, because the client and the server use the same type: ```java return backendClient.subscribe(req); ``` The server subscribes to the stream after it sends the first response. If the client cancels first, the server disposes the holder, so the backend stream closes. A plain stream method (`stream<E>` with no first response) keeps its `Flux<E>` signature. ## Background A method declared as `First, stream<Elem>` sends two kinds of values on one `Flux`: the first response, then the elements. Each caller had to examine every item with `isSetFirstResponse()`. A method error and a stream error used the same `onError` signal. There was no event for "the first response arrived". The C++ server and client already keep the two parts separate (`ResponseAndServerStream`, `ResponseAndClientBufferedStream`). The Rust, Go, and Python generators use the same shape. ## Implementation Server: - Each server stream has two phases: the response phase, then the stream phase. A plain stream is a stream with an empty first response. - The generated code makes one `StreamMethod<F, E>` descriptor for each method. The descriptor holds the request readers, the typed `invoke`, the writers for the first response and the elements, and the tables of declared exceptions. - The shared helper `ServerStreams.handleStream` runs the phases. An error in the response phase is an initial error. An error in the stream phase is a stream error. ``` invoke(args) : Mono<ResponseAndStream<F, E>> ├─ throw / Mono.error / empty ──▶ initial-error frame (function exceptions) └─ holder ──▶ first-response frame ──▶ stream.map(element frame) └─ Flux error ──▶ stream-error frame (stream exceptions) ``` - This diff removes the old server path: `StreamResponseHandlerTemplate`, `StreamResponseHandler`, `StreamWithFirstResponseHandler`, `StreamHandler`, and the `SingleRequestStream*Delegate` adapters. The metadata and exception builders move to `RpcPayloadUtil`. Client: - The generated code sends the transport stream to `ResponseAndStreamBridge.toResponseAndStream`. - The bridge emits the holder when the first payload arrives. It decodes the remaining payloads as elements and keeps the headers of each element. - The holder has a lifecycle state machine (`StreamLifecycle`). It allows one subscription. It also makes sure that a dispose before, during, or after a subscription closes the transport stream exactly one time. - The first request asks for `1 + 100` credits, then adds credits as elements are consumed. This is the same as the C++ client. - Interaction methods use `toInteractionResponseAndStream`, which keeps the existing hop off the event loop. All callers that use a first response are changed: the iris worker client, jdKickStream, the rtgw stateful socket writer and its test, `SRDemo`, the Java examples, and the runtime, integration, and conformance tests. ## Result The first response has its own type. Errors have a scope: the outer `Mono` for function errors, the inner `Flux` for stream errors. The bytes on the wire do not change. Java-to-Java integration tests that decode each frame, and the conformance suites, verify this. The golden test files are removed. ## Canary fix (MQTT R19912) The canary lost all header-only stream frames. Bladerunner (C++) sends flow status, termination, drain, and rewrite signals as payloads with an empty body. `decodeElements` dropped these frames, so `handler.processStreamResponse` did not receive them. Flow status 'accepted' went from about 710 to 0 per task. Now `decodeElements` sends each header-only frame as an element with null data and its headers. Before this stack, all elements reached the caller in the same way. The generated plain methods remove null-data elements before `map`, because Reactor `map` does not accept null. Reviewed By: echistyakov Differential Revision: D131004115 fbshipit-source-id: cbfa3e53d2df52ce5dc65274d5d4903961967de5github.com-facebook-fbthrift · f8a445ce · 2026-11-11
- 3.1ETVServe requestChannel for sink and bidi calls in the Rocket transport Summary: This change makes `ThriftServerRSocket` serve REQUEST_CHANNEL, the Rocket frame of Thrift sink and bidi calls, on the channel responder of rsocket-java. The transport controls the credit and the cancel of the sink, so it keeps the rules of the C++ client for every handler, and it ends the handler's sink reader with the call. Background: Master does not override `requestChannel`, so every channel call fails. In a sink or a bidi call, the client-to-server half is the sink, and the server-to-client half is the stream. The C++ client sets these rules (fbcode/thrift/lib/cpp2/transport/rocket/client/RocketClient.cpp): - Before the first response, a REQUEST_N, CANCEL or EXT frame closes the connection (`handleRequestNFrame` :834-855, `handleCancelFrame` :857-868, `handleExtFrame` :893-903). A first frame without a payload also closes it (:526-532). - After the first response, the client reads an ERROR frame as a `StreamRpcError` (RocketBiDiServerCallback.cpp `onStreamError` :136-152; GeneratedCodeHelper.h:1653-1672). For a sink, it is the final error (`handleErrorFrame` :817-818). - A bidi client keeps its sink open after the server's stream completes (`handleBiDiResponse` :792-798). - The client compresses each sink payload on its own (RocketSinkServerCallback.cpp:25-35). The C++ server stops the task timeout when it sends the first response (fbcode/thrift/lib/cpp2/transport/core/ThriftRequest.h:236-316), and its default sink buffer holds 100 payloads (fbcode/thrift/lib/cpp2/async/Sink.h:135). Problem: The inbound subscription of rsocket-java turns each request into a REQUEST_N frame and a cancel into a CANCEL frame, from any thread. Thus the transport must hold the credit and the cancel of a reader until the responder queued the first response. It must also tell the reader how the call ended, because a reader that completes when the call was cancelled takes a cut sink for a whole one. Change: - `requestChannel` subscribes one `SinkPayloadSubscriber` to the channel. It takes the setup without a REQUEST_N and buffers the sink payloads. `ThriftServerRSocket` gives it the scheduler for sink decoding: the off-loop scheduler when execution is forced off the event loop, else `Schedulers.immediate()`. - The reader's demand and cancel wait in `delaySubscription` until the responder queued the first response. A pass-through subscriber marks that point after the responder's onNext returned, downstream of the task timeout, so a response that the timeout drops never opens the sink. Then a `publishOn` window gives the peer at most 100 credits and refills them as the reader reads. - A reader cancel before the first response stays local. After it, a bidi reader cancel sends CANCEL; a sink reader cancel stays local, because a sink peer rejects a CANCEL before the final response. - The end of the call ends the reader, also while it waits for the first response. `takeUntilOther` sees a completion and cancels the window, which releases the sink payloads it holds; then a normal end completes the reader, and any other end fails it with a `CancellationException`. An error from the other source would fail the reader without that cancel, and the window would keep its payloads. When the stream of a bidi call completes, a sink that a reader took stays open until the peer ends it or the reader cancels; a sink that no reader took ends at once, and a later reader fails. - `serveSink`: a sink that ends after one payload, its initial error, ends with ERROR. `serveChannel`: a call without a response ends with ERROR. An error after the first response, like a response that does not serialize, becomes a `StreamRpcError` (`RocketErrorUtil.streamError`, logged at ERROR with the exception). An error before it keeps the mapping of the other request kinds. - `decodeChannelSetup` decodes the setup like `requestStream`. Any failure releases every buffer, gets REQUEST_PARSING_FAILURE and a WARN log line with the original failure. `decodeSinkPayload` decodes each sink payload with its own compression: an undeclared peer error becomes an error signal; a declared error stays in the body for the dispatch. - When a call ends, `SinkPayloadSubscriber.end` releases the sink payloads that no reader took. A reader that took the buffer releases its own payloads when it is cancelled, so no payload is released twice. - The default `RpcServerHandler.streamingRequestStreamingResponse` sends `UnknownMethodException`, like the other default methods, so a channel call to a server without channel methods gets UNKNOWN_METHOD. Result: - No REQUEST_N, CANCEL or EXT frame goes before the first response, also when the first response comes from another thread or the task timeout drops it. A reader that subscribes early gets its credit right after the first response. - A sink gets no server CANCEL before its final response. - A handler's sink reader fails when the call is cancelled, fails or loses its connection, so a handler never commits a cut sink. - One call holds at most 100 unread sink payloads, and no sink payload stays unreleased when a call ends. - For a sink initial error, the C++ server sends one NEXT|COMPLETE payload; this server sends the payload and then ERROR. The C++ client accepts both. - The generated service handlers dispatch sink and bidi methods only from the codegen commit on. Until then, only a hand-written `RpcServerHandler` uses this path. Known gaps: - Bidi half-close gaps, in wire form. In C++, each half of a bidi call can end on its own. This server keeps that when the client completes its sink (COMPLETE), when the client ends its sink with a declared or undeclared exception in a payload (NEXT|COMPLETE with exception metadata; a C++ client sends `EncodedStreamError`, `appUnknownException` included, this way: `sendSinkError` RocketClient.cpp:1478-1486), and when the server's stream completes (the client keeps its sink open: `handleBiDiResponse` RocketClient.cpp:792-798). Two wire forms end the whole call: - B) An ERROR frame from the client on the sink half, after the first response. A C++ client sends it only for a sink error that is a `RocketException` (RocketBiDiServerCallback.cpp `onSinkError` :37-63). The stock rsocket-java responder ends both halves on any inbound ERROR (RequestChannelResponderSubscriber.java `handleError` :488-534, rsocket-core 1.1.5). The server then sends ERROR (StreamRpcError SERVER_CLOSING_CONNECTION) to end the client's stream half (RocketClient.cpp `handleErrorFrame` :819-826), and the server's sink reader fails. A possible fix: change that ERROR into the payload form of an undeclared sink error in `RocketDuplexConnection`, so that rsocket-java sees the end of one half. - C) A CANCEL frame from the client after the first response, while its sink stays open (RocketBiDiServerCallback.cpp `onStreamCancel` :101-106). The stock responder's `handleCancel` (:332-367) ends both halves, and `RequestChannelResponderSubscriber` is final and package-private (:53). The server then sends CANCEL to end the client's sink half (RocketClient.cpp `handleCancelFrame` :870-880), and the server's sink reader fails. A possible fix: rsocket-java support for CANCEL as the end of one half, or a server-side REQUEST_CHANNEL responder. - In both cases nothing hangs: the server tells the client that the whole call ended. - There is no sink chunk timer. - The setup metadata is decoded twice: here and in `RocketDuplexConnection`. rsocket-java gives the handler no stream id, so the two decodes cannot share a result. Reviewed By: echistyakov Differential Revision: D131471917 fbshipit-source-id: bd2b90d97e1b2519d8e8cf0b83038b77f229ea2cgithub.com-facebook-fbthrift · 05612e38 · 2026-11-17
- 2.0ETVJava THeader overload responses carry explicit ex codes Summary: Make Java THeader overload replies carry the error code that Service Router needs to classify the failure and select a retry policy. Background: A THeader frame carries a Thrift message and response headers. The `LOADSHEDDING` exception type (`11`) is in the message body. The `ex` header is a separate RPC reason code: `1` for host overload, `5` for queue overload, and `22` for application overload. Service Router groups codes `1` and `5` as `HOST_OVERLOAD`. A oneway call must not receive a response. Problem: The generated asynchronous handler changed a known `TApplicationException` into `INTERNAL_ERROR`. Response payloads kept a writer and a flag, but not the actual exception. Java Header overload replies did not supply `ex`. The legacy server also sent error and timeout replies for oneway calls. Both decoders could misclassify a C++ Header oneway frame. Change: - Add the `OverloadedException.host`, `queue`, and `application` factories. Keep the RPC reason as an integer. Keep the Thrift body type as `LOADSHEDDING`. Share the reason classification in `OverloadedException.rpcErrorCodeOf` so a future Rocket encoder can use it. - Make the Java generator keep the original `TApplicationException` and its subtype. Keep declared Thrift errors in the result reply. Keep the existing `INTERNAL_ERROR` handling for other unexpected errors. - Store the actual exception in `ServerResponsePayload` and forward it through the load-header wrapper. Derive the application-exception flag from the stored object; all TApplicationException payloads carry the actual exception. - Add `HeaderOverloadError` at the Header transport boundary. After the body writer, write hooks, and metadata merge, add `ex` for a real overload. Remove conflicting user and proxy error headers only for that overload. Convert the integer reason to a string at this boundary. - Keep `RpcPayloadUtil` limited to the body writer and existing metadata. Remove cause recovery, marker wrappers, and shared Header filtering. Keep Rocket metadata unchanged. - Encode a raw executor rejection as host overload (`1`). Recognize the C++ oneway frame sequence (`-1`), with message sequence `0`, and keep the legacy message marker. Send no oneway error or timeout reply. - Regenerate all 35 affected Java handler fixture files with the compiler. - Remove the Unity `OverloadErrorCodeHandler`, its `setHandlers` registration, and `FbLiteThriftServerOverloadErrorCodeTest`. Unity rejects requests through `isOverloadedFn` in `LoadSheddingHandler`, which now throws `OverloadedException.application`. The runtime sends `ex: 22` for that reply, so the handler is not necessary. The knob `fblite/killswitches:enable_thrift_overload_error_code` can no longer turn off the header. The Unity owners will delete the knob after this diff lands. Result: Service Router can classify Java Header overload replies. A bare `LOADSHEDDING` exception uses application code `22`. Normal error metadata, custom `ex` and `uex` headers, and Rocket metadata keep their existing behavior. Valid oneway calls receive no response. Each Java service that rejects a request through `isOverloadedFn` now sends `ex: 22`, as a C++ server does. Service Router can then retry the request on a different host. Reviewed By: echistyakov Differential Revision: D129714868 fbshipit-source-id: 1ce6a6869e6df212af09f97455a964a52bcfc7c7github.com-facebook-fbthrift · 087e8613 · 2026-11-05
- 1.9ETVSend Rocket overload rejections as REJECTED errors Summary: This diff makes the Java Rocket server send load shedding as a REJECTED error frame. Clients and ServiceRouter can then identify the rejection as overload. The diff also makes sure that a handler exception never goes out as a raw error. This diff is rebased onto master after D122608380. The generated handler calls the delegate in `Mono.defer`, and the `ASSEMBLY_SENTINEL` scope is inside the `Mono.defer`. Thus a synchronous handler exception becomes an error signal, and a static context read in the handler body still fails. Background: - Rocket can send an error in two ways. A PAYLOAD frame with exception metadata tells the client that the method ran and failed. An ERROR frame with the code REJECTED tells the client that the server refused the request. - The REJECTED frame contains a compact `ResponseRpcError`. Its code gives the reason: OVERLOAD, QUEUE_OVERLOADED or APP_OVERLOAD. ServiceRouter uses this code to try a different host or to back off. - The C++ server sends load shedding as a REJECTED frame. - D129714868 added `OverloadedException`. It gives each overload a reason code: 1 (host), 5 (queue) or 22 (application). The Header transports send this code in the `ex` header. Problem: 1. The Java Rocket server sends an overload as a PAYLOAD frame. The client cannot identify it as load shedding. 2. When the off-loop scheduler is full, it throws `RejectedExecutionException`. On Rocket, no code converts this exception. rsocket-java then sends an ERROR frame with the code APPLICATION_ERROR. The C++ client does not accept this code and reports Unexpected error frame type: 513. ServiceRouter counts an unknown exception, not load shedding. This causes exception spikes in production, also for `getStatus()`. 3. The generated handler calls a reactive delegate immediately. If the delegate throws before it returns a `Mono`, the exception goes out as a raw error. Rocket then sends APPLICATION_ERROR, and Header closes the connection. Change: - `RocketErrorUtil.fromApplicationException` converts reason 1 to OVERLOAD, reason 5 to QUEUE_OVERLOADED and reason 22 to APP_OVERLOAD. For all other exceptions, it returns null. - `RocketErrorUtil.rejected` builds the frame with the LOADSHEDDING category. The frame does not contain `load`, and the message is ASCII with a maximum of 127 characters. rsocket-java writes the error data as a UTF-8 string, so other bytes do not stay correct. - `ThriftServerRSocket` serializes the response first, so the exception hooks run one time. Then `throwIfOverloaded` sends the rejection. - For a stream, only the first response can become a rejection. Errors after the first response stay in the stream. - `ThriftServerRSocket` converts a `RejectedExecutionException` before the first response to a REJECTED frame with the code OVERLOAD. The Header transports use the same reason. - The generated request-response handler calls the delegate in `Mono.defer`. Thus a synchronous exception goes to the existing error mapping: the declared exception, the `TApplicationException`, or INTERNAL_ERROR. - When argument decoding or a `preRead` or `postRead` hook fails, the generated dispatcher sends an INTERNAL_ERROR payload. It does not send a raw error. All Java fixtures are regenerated. - The generated INTERNAL_ERROR path no longer calls `preWriteException` two times. - A `TApplicationException` from a stream handler before its first response keeps its type and message. Request-response does the same. Before this diff, the server wrapped it as INTERNAL_ERROR. - Fire-and-forget does not change. It has no reply. Result: - The server sends load shedding as a REJECTED frame with the reason code. This applies to request-response and to the first stream response. - When the off-loop scheduler is full, clients and ServiceRouter get OVERLOAD, not an unknown error. - A synchronous handler exception goes out as a normal payload on both transports. The connection stays open for the next call. Reviewed By: echistyakov Differential Revision: D129265435 fbshipit-source-id: 940a72981b61f1471a133a86474a01d3c31d7c75github.com-facebook-fbthrift · cb86a557 · 2026-11-11
- 1.7ETVUnify stream hooks into ContextChain Summary: Reland of D127768781 (backed out in D129408444). one handler list, one chain, C++ hook points. `StreamEventHandler` becomes a `ThriftEventHandler` subinterface with C++-named hooks, and `ContextChain` gains the stream/sink section: eager final handler+context lists, synchronized taps, exactly-once terminal strictly before an exactly-once `done()`. Taps fire at the C++ points; a throwing hook propagates like any other handler hook. Background: C++ keeps ONE handler list and ONE `ContextStack`, and every stream hook receives the SAME per-request context (`contextAt(i)`). The bridge subscribes at the top of the generator (after the first response), notifies next after the payload is encoded and pushed, and counts the full initial RequestN as stream credit. Problem: the Java hooks fired at the wrong points -- subscribe at request subscription (before the first response), next pre-encode -- and request completion could run `done()` ahead of the stream terminal when a cancel landed before the worker subscribed. There was no sink half at all. Change: - `StreamEventHandler` is now `public interface StreamEventHandler extends ThriftEventHandler` with default no-op C++-named hooks (`onStreamSubscribe` / `onStreamNext` / `onStreamCredit` / `handleStreamError` / `onStreamFinally` with `StreamOutcome`, plus the sink set with `SinkOutcome`). To observe streams, `implements ThriftEventHandler` becomes `implements StreamEventHandler`; the hook context is the SAME object the handler returned from `getContext`. No `interactionCreationTime` (not available cheaply on the Java dispatch path); `onStreamNextSent` and pause/resume have no Java mechanism. - `ContextChain` pairs each `StreamEventHandler` with its context eagerly in the constructor loop (no allocation when there are none) and fans out with plain indexed loops under synchronized methods -- no lock object, no laziness, no guards. `finishStream` fires the terminal plus `done()` only for a begun stream; `finishRequest` fires `done()` only for a never-begun one; the began state is read under the same monitor, so `done()` is exactly once by construction. A throwing hook propagates (it fails the stream); the terminal site still runs `done()`. The chain owns the element sequence counters, so tap sites hold no `AtomicLong`. An event-loop hook while forced off loop logs one unthrottled warning and still runs. - `ServerStreams` is one Reactor chain: subscribe tap at stream-phase subscription (after the first response), next tap post-encode, error tap before the terminal payload, full-demand credits, no stream hooks for request-level initial errors. `cancelOn` stays unconditional so user cancel cleanup never moves with registration. - `handleStreamError` fires on every stream error before `onStreamFinally`; this is Java-side behavior, not a C++ mirror (the C++ core declares `handleStreamErrorWrapped` but never calls it; only out-of-core polyglot code does). Known divergence (follow-up coming): per-element writers call `postWrite` with no `preWrite`, while C++ calls neither per item (`encode_stream_payload` touches no `ContextStack`). Result: stream, sink, and bidi hooks ride the request lifecycle with the request context. The sink/bidi server diffs above wire the sink half of this API. Perf: no guard, scan, or lock object on the request path by construction; JMH rerun deferred to quiet hardware per owner steer. Reviewed By: echistyakov Differential Revision: D131004474 fbshipit-source-id: ff6fc64ce6cf1d7ce946c5d2a7fcaffd7681b707github.com-facebook-fbthrift · 3ee1d21e · 2026-11-11
- 1.7ETVUnify stream hooks into ContextChain Summary: one handler list, one chain, C++ hook points. `StreamEventHandler` becomes a `ThriftEventHandler` subinterface with C++-named hooks, and `ContextChain` gains the stream/sink section: eager final handler+context lists, synchronized taps, exactly-once terminal strictly before an exactly-once `done()`. Taps fire at the C++ points; a throwing hook propagates like any other handler hook. Background: C++ keeps ONE handler list and ONE `ContextStack`, and every stream hook receives the SAME per-request context (`contextAt(i)`). The bridge subscribes at the top of the generator (after the first response), notifies next after the payload is encoded and pushed, and counts the full initial RequestN as stream credit. Problem: the Java hooks fired at the wrong points -- subscribe at request subscription (before the first response), next pre-encode -- and request completion could run `done()` ahead of the stream terminal when a cancel landed before the worker subscribed. There was no sink half at all. Change: - `StreamEventHandler` is now `public interface StreamEventHandler extends ThriftEventHandler` with default no-op C++-named hooks (`onStreamSubscribe` / `onStreamNext` / `onStreamCredit` / `handleStreamError` / `onStreamFinally` with `StreamOutcome`, plus the sink set with `SinkOutcome`). To observe streams, `implements ThriftEventHandler` becomes `implements StreamEventHandler`; the hook context is the SAME object the handler returned from `getContext`. No `interactionCreationTime` (not available cheaply on the Java dispatch path); `onStreamNextSent` and pause/resume have no Java mechanism. - `ContextChain` pairs each `StreamEventHandler` with its context eagerly in the constructor loop (no allocation when there are none) and fans out with plain indexed loops under synchronized methods -- no lock object, no laziness, no guards. `finishStream` fires the terminal plus `done()` only for a begun stream; `finishRequest` fires `done()` only for a never-begun one; the began state is read under the same monitor, so `done()` is exactly once by construction. A throwing hook propagates (it fails the stream); the terminal site still runs `done()`. The chain owns the element sequence counters, so tap sites hold no `AtomicLong`. An event-loop hook while forced off loop logs one unthrottled warning and still runs. - `ServerStreams` is one Reactor chain: subscribe tap at stream-phase subscription (after the first response), next tap post-encode, error tap before the terminal payload, full-demand credits, no stream hooks for request-level initial errors. `cancelOn` stays unconditional so user cancel cleanup never moves with registration. - `handleStreamError` fires on every stream error before `onStreamFinally`; this is Java-side behavior, not a C++ mirror (the C++ core declares `handleStreamErrorWrapped` but never calls it; only out-of-core polyglot code does). Known divergence (follow-up coming): per-element writers call `postWrite` with no `preWrite`, while C++ calls neither per item (`encode_stream_payload` touches no `ContextStack`). Result: stream, sink, and bidi hooks ride the request lifecycle with the request context. The sink/bidi server diffs above wire the sink half of this API. Perf: no guard, scan, or lock object on the request path by construction; JMH rerun deferred to quiet hardware per owner steer. Reviewed By: echistyakov Differential Revision: D127768781 fbshipit-source-id: 371fd1137385d87548d2ce1a5b135350e2705fd3github.com-facebook-fbthrift · f4e40412 · 2026-11-03
- 1.6ETVAdd stream integration tests for the Java server Summary: end-to-end streaming coverage over the real unified transport (RSocket via ALPN) on COMPACT and BINARY: the ResponseAndStream contract (dispose, forwarding, single subscription), long streams in bounded credit steps, cancel at every phase, admission shedding, concurrent sharing of one connection, and hook semantics. Needed because stream behavior was only proven at the unit level, never Java client to Java server end to end. Background: `ping.thrift` already declares plain, first-response, and mid-stream-error shapes, implemented by `ExtendedReactivePingService`. The existing suite covers the happy paths, bounded demand, and hook threads. Problem: nothing proves the release paths (dispose/forward/cancel), credit behavior at scale, pre-dispatch rejection, multiplexed sharing, or the hook contract (same context, throwing hooks, finally-before-done, connection-drop terminal). Change (all in `ExtendedPingStreamIntegrationTest`, same harness and leak detector; no IDL changes -- new behavior comes from test-local service subclasses): - ResponseAndStream: read-first-then-dispose drives server CANCEL plus done with the server Flux observing cancel; a handler-returned backend stream forwards client cancel to the backend CANCEL terminal; a second inner subscription fails with the actionable one-subscription error. - Scale: 10,000-element plain and first-response streams arrive in order and complete while every server grant stays within the 1000-credit request steps. - Cancel: before the first response (gated handler; handler sees cancel, no stream hooks, done fires) and after it (zero-demand inner subscribe then dispose; CANCEL plus done). - Admission: a preprocess LOADSHEDDING throw rejects before dispatch (client sees the error, handler never runs, done fires). The LOADSHEDDING type code does not survive the error-code round trip, so the test pins the rejection, not the code. - Sharing: 50 streams plus request-response calls over one client stay ordered per stream and complete (the connection limit of 10 would refuse per-call connections). - Hooks: the stream handler sees the same context in preRead and onStreamNext while a plain handler on the same list sees no stream calls; a throwing onStreamNext fails the client stream with an ERROR terminal; on cancel the terminal is recorded strictly before done. - Connection drop mid-stream drives the server CANCEL terminal plus done (the old javadoc note claiming otherwise is removed; the wiring has held since D2 and `StreamConnectionCloseTest` covers the raw-transport half). - Cancel-race determinism: take(n)/dispose tests run against a capped service that hangs past the taken elements, since unbounded demand would otherwise let the server outrun the cancel and complete. Result: release paths, scale, rejection, sharing, and hook semantics are locked in on both protocols. Reviewed By: echistyakov Differential Revision: D127769536 fbshipit-source-id: 9b5b37e9bdb508bfad30350a4c89899e949021e5github.com-facebook-fbthrift · e5bbe7d1 · 2026-11-03
- 1.6ETVAdd stream integration tests for the Java server Summary: Reland of D127769536 (backed out in D129408444). end-to-end streaming coverage over the real unified transport (RSocket via ALPN) on COMPACT and BINARY: the ResponseAndStream contract (dispose, forwarding, single subscription), long streams in bounded credit steps, cancel at every phase, admission shedding, concurrent sharing of one connection, and hook semantics. Needed because stream behavior was only proven at the unit level, never Java client to Java server end to end. Background: `ping.thrift` already declares plain, first-response, and mid-stream-error shapes, implemented by `ExtendedReactivePingService`. The existing suite covers the happy paths, bounded demand, and hook threads. Problem: nothing proves the release paths (dispose/forward/cancel), credit behavior at scale, pre-dispatch rejection, multiplexed sharing, or the hook contract (same context, throwing hooks, finally-before-done, connection-drop terminal). Change (all in `ExtendedPingStreamIntegrationTest`, same harness and leak detector; no IDL changes -- new behavior comes from test-local service subclasses): - ResponseAndStream: read-first-then-dispose drives server CANCEL plus done with the server Flux observing cancel; a handler-returned backend stream forwards client cancel to the backend CANCEL terminal; a second inner subscription fails with the actionable one-subscription error. - Scale: 10,000-element plain and first-response streams arrive in order and complete while every server grant stays within the 1000-credit request steps. - Cancel: before the first response (gated handler; handler sees cancel, no stream hooks, done fires) and after it (zero-demand inner subscribe then dispose; CANCEL plus done). - Admission: a preprocess LOADSHEDDING throw rejects before dispatch (client sees the error, handler never runs, done fires). The LOADSHEDDING type code does not survive the error-code round trip, so the test pins the rejection, not the code. - Sharing: 50 streams plus request-response calls over one client stay ordered per stream and complete (the connection limit of 10 would refuse per-call connections). - Hooks: the stream handler sees the same context in preRead and onStreamNext while a plain handler on the same list sees no stream calls; a throwing onStreamNext fails the client stream with an ERROR terminal; on cancel the terminal is recorded strictly before done. - Connection drop mid-stream drives the server CANCEL terminal plus done (the old javadoc note claiming otherwise is removed; the wiring has held since D2 and `StreamConnectionCloseTest` covers the raw-transport half). - Cancel-race determinism: take(n)/dispose tests run against a capped service that hangs past the taken elements, since unbounded demand would otherwise let the server outrun the cancel and complete. Result: release paths, scale, rejection, sharing, and hook semantics are locked in on both protocols. Reviewed By: echistyakov Differential Revision: D131004588 fbshipit-source-id: 6c48b1909435d09cb8b0d4a7e37394a5a917a8begithub.com-facebook-fbthrift · 6c7d01e7 · 2026-11-11
- 1.3ETVGenerate sink and bidi server dispatch for Java Summary: This change makes the Java code generator emit server dispatch for sink and bidirectional-stream methods, and makes the Java conformance server answer the sink and bidi cases. The dispatch uses the runtime of the parent commits. `ExtendedPing` gets sink and bidi methods, so that generated Java code runs in the integration tests. Background: The parent commits serve channel calls in the Java Rocket server and add `ServerSinks` and `ServerBidiStreams`. The generated Java service handlers do not dispatch sink or bidi methods yet, and the generated service interfaces do not declare bidi methods. Problem: A Java service cannot implement a sink or a bidi method. Thus the Java conformance server lists all its sink and bidi cases as nonconforming. Change: - `RpcServerHandler.whisker`: for each sink or bidi method (`channel_functions`), generate a `SinkMethod` or a `BidiMethod`, by the method kind, with its request readers, its sink readers (`_create_<method>_sink_readers`: the sink element at id 0, then the declared sink exceptions) and its response writers. Generate `streamingRequestStreamingResponse` only for a service that has such methods. The methods register under their wire names, like the other method kinds. - The dispatch follows the generated stream dispatch: `ContextChain` lifecycle, `RequestContextScope`, `RequestContextScope.ASSEMBLY_SENTINEL` around the delegate call, `Flux.defer`, `subscribeOn` when off-loop execution is forced, and `finishRequest`. A sink goes through `ServerSinks.handleSink`, a bidi method through `ServerBidiStreams.handleBidi`. A service that extends another service defers the methods it does not have to the parent handler, so an unknown channel method gets UNKNOWN_METHOD. - A sink without a first response passes the delegate `Mono` as its final response; `ServerSinks.handleSink` applies `single()`. A sink with a first response goes through `ServerSinks.firstAndFinal`. A bidi method uses the stream glue. - Write hooks: the channel writers follow the rule of the parent change D129265757 for streams. The writer of a stream element or a sink final fires no write hook; the first-response writer fires `postWrite`, and so does the shared empty first-response writer. D129265757 fires `preWrite` in `ServerStreams.firstPayload`, which the channel dispatch shares, so a channel call fires `preWrite` and `postWrite` once, around its first response. This change does not touch the stream writers or `ServerStreams`, so the two changes do not overlap. The writer factories take two arguments, after the parent change that removed the request payload from `ResponseWriterFactory`. - `Service.whisker`, the async and blocking wrappers and the reactive client declare the bidi methods. In the `Reactive` interface, a bidi method has a default body that throws `UnsupportedOperationException`, so a hand-written `Reactive` implementation of a service with bidi methods still compiles. The client method throws `UnsupportedOperationException`, because the Java client does not implement bidi. - `t_mstch_java_generator.cc` adds the `bidi_functions` and `channel_functions` properties. - `ping.thrift`: `ExtendedPing` gets `sinkPings` (declared function, sink and final exceptions, each with its own class), `sinkWithFirstResponse`, `bidiPings` (declared sink and stream exceptions) and `bidiSums` (a first response and boxed `i32`/`i64` elements). `ExtendedReactivePingService` implements them. The file has no www copy, so no sync is necessary. - The conformance server implements the sink and bidi methods with the record-and-answer behavior of the C++ conformance server. Each test case records its result once into its own `Sinks.One`, and `getTestResult` waits up to one second for it, because the server reads the sink off the event loop. The sink exception cases read one sink element, which must be the exception. The bidi cases share one helper that sends the stream payloads and then reads the sink. `bidiSinkUndeclaredException` removes the exception type that the bidi client puts before the message. - `nonconforming.txt` keeps `SinkChunkTimeout` (no sink chunk timer) and the Java client cases. - The Java server guide says that a sink method without a first response must throw a declared function exception: an exception that it returns as an error is undeclared, as for a stream. - The fixtures are regenerated. Only services with sink or bidi methods change. Result: 16 more Java conformance server cases are expected to conform: - Sink: Basic, InitialResponse, DeclaredException, UndeclaredException, SubsequentCredits, Fragmentation, InitialDeclaredException, ServerDeclaredException. - Bidi: Basic, InitialResponse, StreamDeclaredException, StreamUndeclaredException, SinkDeclaredException, SinkUndeclaredException, MethodDeclaredException, MethodUndeclaredException. `SinkChunkTimeout` stays nonconforming. CI runs the conformance suites, with the stricter checks of the conformance harness parent change. Known gaps: - The Java client does not implement bidi. The generated client bidi methods throw `UnsupportedOperationException`, and the channel call of the client ends its sink when the server's stream completes (`switchOnFirst` in `RSocketRpcClient.streamingRequestStreamingResponse`). The Java client bidi conformance cases stay nonconforming. - The Java client still fails three sink conformance cases against the C++ server: SinkInitialResponse, SinkDeclaredException and SinkUndeclaredException. They stay in `nonconforming.txt` as expected failures. The client fixes are in a separate change. - There is no sink chunk timer. Reviewed By: echistyakov Differential Revision: D131472235 fbshipit-source-id: 815dced5294db24e3afb4f88d3bdd2f6aa6d802cgithub.com-facebook-fbthrift · 10807a1c · 2026-11-17