Repository navigation
Description
What happens
On main at 793d89e and in effect 4.0.4, client.Tag(payload, { discard: true }) returns void without waiting in makeNoSerialization, and passes discard to onFromClient as a hint. After that, the call behaves like an awaited one:
RpcClient.makeignores the hint and registers an entry for every request. For a discarded call, only anExitremoves the entry. If no reply comes, the entry stays for the life of the client and keeps the caller's fiber context alive.- The client never sets
isNotification, so the request on the wire looks like any other. RpcServeranswers every request with anExit. The server encodes and sends it, and the client decodes it only to drop it. If a discarded handler dies, the server sends a connection-wideDefect, which fails the client's other pending calls.
To reproduce, connect an in-memory RpcServer.Protocol and RpcClient.Protocol that pass JSON-encoded messages, using the codecs of RpcSerialization.json. Define one RPC, Ping, that returns its payload's n, and call client.Ping({ n: 7 }, { discard: true }) as the first request. The server's send receives {"_tag":"Exit","requestId":0,"exit":{"_tag":"Success","value":7}}. With a server that drops requests, the client still decodes a late Exit for the discarded id, so the client kept the entry.
Why it matters
Every discarded call pays for a reply that nobody reads, and the client keeps state that leaks if the reply never comes. Usually the reply is cheap. It isn't where a socket write is expensive. For example, in workerd, the Cloudflare Workers runtime, a write to an idle WebSocket restarts its send pump and leaves objects in old space until the next full GC. See cloudflare/workerd#7745. In a Durable Object where most clients make a discarded call every 50 ms, dropping those replies cut V8 old-generation growth by about 20% in local tests.
Expected
discard should act as a notification. The caller does not wait, and nothing produces or tracks a reply. Cluster already treats discard this way for the entity's reply. A discarded call registers no reply entry, and a remote discarded send goes through Notify, which only acknowledges delivery, instead of the RPC that carries the entity's reply. The cluster PR #7195 also treats callers that wait for the entity's reply after discard: true as a bug.
Related
A JSON-RPC notification that reaches RpcServer decodes to id: "" and gets the reply {"jsonrpc":"2.0","id":"",...}. JSON-RPC 2.0 forbids that reply. Two concurrent notifications also collide on that id, and the server never runs the second. McpServer handles its own notification methods first. It still forwards an id-less call to a request method such as tools/call, and that call gets the reply.
Proposal
- In
RpcClient.make, use thediscardhint thatonFromClientalready receives. Send the request withisNotification: true, which already exists on the wire and in the binary codec, and register no entry for it. - In
RpcServer, run a notification without sending anything back, not even a stream chunk or a fatalDefect. Still report its failures, and give each notification its own internal id. - In the socket protocol, keep no per-request state for a notification. Over HTTP, accept an empty response for one.
HTTP and worker calls keep waiting for the handler, as they do today.
The change affects compatibility in these ways:
- A new client works with an older Effect server over the Effect serializations. The old server still replies, and the client ignores an
Exitfor an id it does not track. - Over JSON-RPC, a new client sends a discarded call without an id. An older Effect server collides overlapping calls on
"". Mixed versions should not usediscardoverjsonRpcorndJsonRpc. - A custom
RpcServer.Protocolsees noExitfor a notification.
I opened a first draft of this as a pull request, which links to this issue. It's mainly there to make the idea concrete, so please change it or close it if you'd rather solve this differently.
I investigated this with an AI coding agent, Claude Code. The agent read the source, wrote the change and its tests, and ran the tests, the repro and the workerd measurements. I reviewed the analysis before filing.
Activity
schutzelaars commentedon Oct 15, 2026
Closing in favour of #9182. The acknowledgement approach makes sense, thanks for picking it up so quickly.