Skip to content

fix(server): keep websocket subscriptions owned through setup and cleanup - #7704

Merged
KATT merged 15 commits into
mainfrom
cursor/ws-subscription-ownership-fork-3334
Nov 4, 2026
Merged

KATT merged 15 commits into
mainfrom
cursor/ws-subscription-ownership-fork-3334

Conversation

@KATT

@KATT KATT commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Why

The v11 WebSocket adapter registered a subscription only after its setup, so a stop or disconnect during setup was missed, and cleanup raced with id reuse.

What

  • A subscription is registered before any await, and a duplicate id is rejected right away.
  • A stop or disconnect during setup skips the procedure, or disposes its iterator unread, and replies stopped.
  • On an iteration error, the signal aborts before disposal.
  • Protocol-visible: terminal messages go out after iterator cleanup, a failed cleanup goes to onError only, and a duplicate id's errorFormatter and onError may get ctx: undefined.
  • Clients 11.0.0, 11.6.0 and 11.23.0 get no new messages or errors. Cost: about 6% CPU and 2.1 KB per active subscription.

Links

None

Alternatives considered

Testing

With main's ws.ts, 20 of 24 tests in websocketsLifecycle.test.ts fail.

AI model

Claude Opus 5.5

Co-authored-by: Tiscs [email protected]

Open in Web Open in Cursor 

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • Bug Fixes
    • Improved WebSocket subscription cancellation during setup and active iteration, including when a connection closes.
    • Fixed cleanup of subscription resources after cancellation, completion, or errors.
    • Duplicate active subscription IDs are now rejected, and IDs can be reused after a subscription ends.
    • Improved handling of iterator and setup errors to provide clearer, more consistent responses.

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 10c47ed and 10c47ed.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
Walkthrough

The WebSocket adapter now registers subscriptions before context and procedure setup completes, handles cancellation during setup and iteration, and separates iteration errors from iterator-disposal errors. New lifecycle and memory tests cover cancellation, duplicate IDs, cleanup, and signal collection.

Changes: WebSocket subscription lifecycle

Layer / File(s) Summary
Subscription admission and cancellation
packages/server/src/adapters/ws.ts, packages/tests/server/websocketsLifecycle.test.ts, packages/tests/server/websockets.memory.test.ts
The adapter registers subscription controllers before awaiting setup and rejects duplicate active IDs. Tests cover cancellation during setup, shared context creation, duplicate IDs, admission errors, and signal collection.
Iterator cleanup and terminal responses
packages/server/src/adapters/ws.ts, packages/tests/server/websocketsLifecycle.test.ts
The adapter handles iterator completion, cancellation, and cleanup errors during request settlement. Tests cover cleanup timing, iterator failures, and client response ordering.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Client as WebSocket client
  participant Adapter as ws adapter
  participant Setup as Context and middleware
  participant Resolver as Subscription resolver
  Client->>Adapter: Send subscription request
  Adapter->>Setup: Register controller and await setup
  Client->>Adapter: Send stop request
  Adapter->>Setup: Abort setup signal
  Setup-->>Adapter: Settle setup
  Adapter-->>Client: Send stopped response
Loading

Suggested reviewers: juliusmarminge, nick-lucas

Merge Risk: Low · up to 10c47

The subscription lifecycle changes have no established merge-blocking behavioral defect. Align the new tests with the required shared setup helper; the throwing-onError concern is pre-existing.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the main change: preserving WebSocket subscription ownership through setup and cleanup.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 3 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 53a07cd and 10c47ed.

Files selected for processing: 3
  • packages/server/src/adapters/ws.ts
  • packages/tests/server/websockets.memory.test.ts
  • packages/tests/server/websocketsLifecycle.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@trpc/client

npm i https://pkg.pr.new/@trpc/client@7704

@trpc/next

npm i https://pkg.pr.new/@trpc/next@7704

@trpc/openapi

npm i https://pkg.pr.new/@trpc/openapi@7704

@trpc/react-query

npm i https://pkg.pr.new/@trpc/react-query@7704

@trpc/server

npm i https://pkg.pr.new/@trpc/server@7704

@trpc/tanstack-react-query

npm i https://pkg.pr.new/@trpc/tanstack-react-query@7704

@trpc/upgrade

npm i https://pkg.pr.new/@trpc/upgrade@7704

commit: 10c47ed

@vercel

vercel Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
examples-next-minimal-starter Ready Ready Preview Nov 3, 2026 2:00pm UTC
examples-todomvc Ready Ready Preview Nov 3, 2026 2:00pm UTC
next-prisma-starter Ready Ready Preview Nov 3, 2026 2:00pm UTC
next-prisma-websockets-starter Ready Ready Preview Nov 3, 2026 2:00pm UTC
og-image Ready Ready Preview Nov 3, 2026 2:00pm UTC
tanstack-start-sse-chat Ready Ready Preview Nov 3, 2026 2:00pm UTC
trpc-next-app-dir Ready Ready Preview Nov 3, 2026 2:00pm UTC
trpc-v12 Error Error Nov 3, 2026 2:00pm UTC
www Ready Ready Preview Nov 3, 2026 2:00pm UTC

Request Review

@trpc-bot

Copy link
Copy Markdown
Collaborator

🤖 Refactored the subscription lifecycle in ws.ts to use explicit resource management (b6ced7887):

  • The admission function now starts with a using release resource that frees the id, but only if this request still owns it. It also awaits the iteration, so the id stays reserved until the iterator's await using disposal has settled.
  • The terminal stopped/error is sent once that scope has been disposed, so the order is: iterator disposed → error reported → id freed → stopped.
  • This replaces the releaseSubscription/stopSubscription closures and their five call sites; early exits are now plain returns.
  • The abort-before-disposal on iteration failure stays a small try/catch, because it only applies when iteration fails, which a disposer can't detect without a flag. DisposableStack isn't used because the node18 build target doesn't have it.

Behaviour is unchanged: the 19 lifecycle tests pass unmodified, and swapping await iteration for void iteration makes 6 of them fail, so they do pin this. The ws/subscription files (394 tests), the server/client/tests projects (833 tests), the build, and a Bun smoke test against the ws adapter all pass. The one red check, Vercel trpc-v12, is a project misconfiguration (next/www doesn't exist on main) and unrelated.

@trpc-bot

Copy link
Copy Markdown
Collaborator

🤖 Follow-ups from @KATT's review of the using refactor:

  • Ownership check (deefe9e): it wasn't needed. Duplicate ids are rejected before registering, subscription.stop only aborts, and a disconnect clears the map with no messages arriving afterwards. The check only existed because the old release also ran for queries. Registration is now a resource: using _subscription = registerSubscription(id, controller) sets the entry on creation and deletes it on dispose, and queries bind null. A new lifecycle test pins that a query reusing an active subscription's id leaves it registered.
  • The try (deefe9e): gone. An abort disposable declared after the iterator's await using is disposed first, so the signal is aborted before return() on every failure path. It skips a natural done on purpose: main and SSE don't abort on completion, and fix(server): only abort node-http requests when the connection closes early #7664 just fixed that for HTTP. A new test pins that a completed subscription doesn't abort its signal.
  • The .then (d63ee5e): gone. handleRequest is async, its using scope is an inner execute(), and after const outcome = await settle(execute()) it sends the error or stopped with plain control flow. The AbortError classification is a named isCancelledSetup(error, signal). It's a function rather than a try block because the scope's early returns still need to end in stopped.

No behaviour change; stopped and error replies go out about a microtask later, with unchanged order per id. The lifecycle suite (now 21 tests), the ws/subscription files (396 tests), the server/client/tests projects (835 tests), the build and Bun all pass. CI is green apart from the unrelated Vercel trpc-v12 project setting (next/www doesn't exist).

Tiscs and others added 7 commits November 3, 2026 11:46
Drop the automaticallyWrappedError marker from getTRPCErrorFromUnknown.
A subscription cancelled during setup now reports `stopped` when setup
rejects with an INTERNAL_SERVER_ERROR caused by an AbortError; any other
cause or explicit code is still reported as an error. The check lives in
the setup catch so `const result = await callTRPCProcedure(...)` stays
as on main.

Also reject duplicate ids before registering instead of tracking
registration with a flag, drop the redundant readyState checks (a
disconnect aborts every registered subscription), and keep sending
`stopped` after an iteration error as main does.

Co-authored-by: Alex / KATT <[email protected]>
Replace `as` casts and non-null assertions with assert() narrowing, a
response type guard and small typed helpers.

Co-authored-by: Alex / KATT <[email protected]>
Removes the `ctxPromise!` non-null assertion: handleRequest is only
called once the context promise exists, so pass it in already narrowed.

Co-authored-by: Alex / KATT <[email protected]>
@KATT
KATT added this pull request to stack #7893 November 4, 2026 12:50
Tiscs pushed a commit to Tiscs/trpc that referenced this pull request Nov 4, 2026
…me id (trpc#7889)

<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
Closes trpc#7886

## Why

- With `retryLink` in front of `wsLink` and the default `retryDelayMs`
(0), a retry is never sent:
  - a retried query never settles;
- a retried subscription never resumes, and `onError` and `onComplete`
are never called.
- `retryLink` retries synchronously, with the same `op.id`. The retry's
request is registered while the failed request with that id is still
being cleaned up.
- `RequestManager` deletes requests by id, so that cleanup removed the
retry too, before it was sent:
- the failed request's teardown: `requestManager.ts:79`, called from
`wsClient.ts:234`;
  - `handleResponseMessage`: `wsClient.ts:419`.
- With a positive `retryDelayMs`, the retry runs after the cleanup, so
it worked.

## What

- `RequestManager.delete()` takes the outgoing message instead of its
id, and deletes only that request. A newer request with the same id
stays.
- Its four callers pass the message: the cleanup returned by
`register()`, and `wsClient.ts`'s close/error handling,
`handleResponseMessage` and the `batchSend` failure path.
- No public API change. Wire messages and ids are unchanged.

## Links

None. There are no docs or example changes.

## Alternatives considered

- **Defer the retry in `retryLink`, e.g. with `setTimeout(0)`.** It
hides the bug for `retryLink` only. Any link that resubscribes
synchronously with the same op would still lose its request.
- **Give each request its own wire id in `wsClient`, apart from
`op.id`.** It would also tell a late message for the failed request
apart from one for the retry. But it changes the ids the server sees,
and the hang doesn't need it.

## Testing

- New `packages/tests/server/websockets.retryLink.test.ts`, which uses
`retryLink` + `wsLink` against a real WebSocket server:
- a query that fails once resolves `'ok'` on the retry, and the server
is called twice;
- a tracked subscription that errors after its first event is
resubscribed with `lastEventId: 1`, gets `[1, 2]`, and has no `onError`
or `onComplete`.
- Regression check: both tests fail on `main` (8ff8793) with
`AssertionError: expected 'timed out' to be 'ok'` and `AssertionError:
expected [ [ undefined ] ] to deeply equal [ [ undefined ], [ 1 ] ]`
(the server is never called again). Both pass with the fix.
- `pnpm exec vitest run packages/tests/server packages/client
packages/server/src/observable`: 102 files, 811 tests pass.
- `tsc --noEmit` for `packages/client` and `packages/tests`, `oxlint`
and `oxfmt --check` are clean.
- With a subscription whose `return()` takes 50 ms, a retry still gets
`[1, 2]` and doesn't complete early, on `main` and on trpc#7704 merged with
`main`.

**Merge order:** independent of trpc#7704 and trpc#7865.

- trpc#7704 changes no client files.
- trpc#7865 changes `TRPCUntypedClient` and `createTRPCClient`, but not
`wsClient` or `RequestManager`.
- `git merge-tree --write-tree` is clean against trpc#7704 (10c47ed) and
trpc#7865 (38d9df4).
- The new tests pass on both heads merged with this branch.

## AI model

Claude Opus 5.5
<!-- CURSOR_AGENT_PR_BODY_END -->

<div><a
href="https://cursor.com/agents/bc-9cf4eb23-1980-4dc1-bd36-ff50b58f3334?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a
href="https://cursor.com/background-agent?bcId=bc-9cf4eb23-1980-4dc1-bd36-ff50b58f3334&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img
alt="Open in Cursor" width="131" height="28"
src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;</div>

<!-- codesmith:footer -->
---
<a
href="https://backend.blacksmith.sh/track/enable-autofix?expires=1796385672&installation_model_id=443568&pr_number=7889&ref=codesmith_pr_footer&repository=trpc%2Ftrpc&return_to=https%3A%2F%2Fgithub.com%2Ftrpc%2Ftrpc%2Fpull%2F7889&signature=4966dc49b18ed713e3508e3735c18cecc27cb6b159c8a0d1794e12289bb93a78"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-light.svg"><img
alt="Autofix with [code]smith"
src="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png"
width="190" height="28"></picture></a>
<sup><a
href="https://app.blacksmith.sh/trpc/codesmith/trpc/pr/7889?autoLogin=true&ref=codesmith_pr_footer">Open
in [code]smith</a> · Need help on this PR? Tag
<code>@codesmith-bot</code> with what you need.</sup>

<!-- codesmith:autofix:disabled -->
<!-- /codesmith:footer -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved WebSocket request handling so an older request no longer
interferes with a newer request that reuses its identifier.
* Improved WebSocket retry behavior: queries can recover after an
initial failure, and subscriptions can resume from the latest delivered
event without ending prematurely.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Cursor Agent <[email protected]>
Tiscs pushed a commit to Tiscs/trpc that referenced this pull request Nov 4, 2026
…t stops it (trpc#7888)

<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
Closes trpc#7887

## Why

- When a client stops a WebSocket subscription (`subscription.stop`, or
disconnecting), its cleanup can throw. That error never reached the
server's `onError`, and nothing was logged. This happens with:
  - an observable teardown;
  - an `async function*` whose `finally` throws once the stop wakes it.
- `ws.ts:363-371` races the pending `iterator.next()` against the stop.
On `'abort'` it breaks and stops waiting for that `next()`.
- The cleanup error rejects that `next()` after the race is decided, and
the rejection was dropped:
- With an observable, `observableToAsyncIterable` unsubscribes on abort
and rejects the pending `next()` with the teardown error (trpc#7884).
  - With a generator, the `finally` runs inside the pending `next()`.
- trpc#7884 stopped this from crashing the server, and its test checks only
that. A cleanup error when the subscription completes on its own already
goes to `onError`.

## What

- New `nextUnlessStopped()` in `ws.ts`. The subscription loop uses it in
place of `iterator.next().catch(getTRPCErrorFromUnknown)`.
- Before the stop: unchanged. A rejection becomes a `TRPCError`, and the
loop sends it to the client and `onError`.
- After the stop: the rejection goes to `onError`, and the call resolves
`'abort'`. Whichever way the race goes, it's reported once, and the
client still gets `stopped`.
- An `AbortError` isn't reported. It's how a stopped subscription
normally ends, e.g. `on(ee, 'x', { signal })`.
- No public API change. The messages the client gets are unchanged.

## Links

None. There are no docs or example changes.

## Alternatives considered

- **Make `observableToAsyncIterable`'s `return()` throw the stored
teardown error.** It covers observables only, not generators. It would
also change the helper's contract from trpc#7867 and trpc#7884, which trpc#7865
builds on.
- **Await the pending `next()` after the stop.** A hand-written iterator
whose `next()` never settles would hang the loop, and `stopped` would
never be sent. (An `async function*` that ignores the signal already
hangs at `iterator.return()` on `main`; this PR doesn't change that.)
- **Send the cleanup error to the client.** The client already stopped.
trpc#7704 also reports cleanup failures after a stop to the server only, and
sends `stopped`.

## Testing

- New `packages/tests/server/websockets.stopTeardown.test.ts`, using
`wsLink` against a real server with `onError` spied:
- an observable teardown that throws on `unsubscribe()` is reported to
`onError` once, the client gets no error, and the connection still
works;
  - a generator `finally` that throws after the stop is reported;
- a teardown that throws when the client disconnects
(`wsClient.close()`) is reported;
- an `AbortError` from a stopped `on(ee, …, { signal })` loop is not
reported.
- Regression check: the first three fail on `main` (8ff8793) with
`AssertionError: expected [] to deeply equal [ [ 'onObservable', …(1) ]
]` (and `'onGenerator'`): `onError` is never called. All four pass with
the fix.
- `pnpm exec vitest run packages/tests/server packages/client
packages/server`: 119 files, 954 tests pass.
- `tsc --noEmit` for `packages/server`, `packages/client` and
`packages/tests`, `oxlint` and `oxfmt --check` are clean.
- An independent review confirmed that each error is reported once and
never sent to the client, that `onError` fires before `stopped`, and
that no unhandled rejections remain. The new file passed 10 of 10 repeat
runs.

**Merge order:** this touches `ws.ts`, which trpc#7704 rewrites. trpc#7704 alone
doesn't fix this: it keeps the same race, and its new test covers only
an iterator whose `return()` rejects.

- The change is one line in the loop, which trpc#7704 leaves unchanged, plus
a helper in a region trpc#7704 doesn't touch, plus `isAbortError` in the
import that trpc#7704 also adds it to.
- `git merge-tree --write-tree` is clean against trpc#7704 (10c47ed),
trpc#7865 (38d9df4) and trpc#7889.
- On trpc#7704 merged with `main` and this branch, the full suite passes:
121 files, 981 tests, including trpc#7704's `websocketsLifecycle.test.ts`.
`tsc` passes too.
- Either order works. If trpc#7704 lands first, its `reportError` helper
could replace the inline `opts.onError?.(…)` callback.

## AI model

Claude Opus 5.5
<!-- CURSOR_AGENT_PR_BODY_END -->

<div><a
href="https://cursor.com/agents/bc-9cf4eb23-1980-4dc1-bd36-ff50b58f3334?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a
href="https://cursor.com/background-agent?bcId=bc-9cf4eb23-1980-4dc1-bd36-ff50b58f3334&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img
alt="Open in Cursor" width="131" height="28"
src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;</div>

<!-- codesmith:footer -->
---
<a
href="https://backend.blacksmith.sh/track/enable-autofix?expires=1796385670&installation_model_id=443568&pr_number=7888&ref=codesmith_pr_footer&repository=trpc%2Ftrpc&return_to=https%3A%2F%2Fgithub.com%2Ftrpc%2Ftrpc%2Fpull%2F7888&signature=936559c21acb17177f424e0414e8c8d52ae932907d6bf498047b7aeb60d9c166"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-light.svg"><img
alt="Autofix with [code]smith"
src="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png"
width="190" height="28"></picture></a>
<sup><a
href="https://app.blacksmith.sh/trpc/codesmith/trpc/pr/7888?autoLogin=true&ref=codesmith_pr_footer">Open
in [code]smith</a> · Need help on this PR? Tag
<code>@codesmith-bot</code> with what you need.</sup>

<!-- codesmith:autofix:disabled -->
<!-- /codesmith:footer -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* WebSocket subscription errors that occur during teardown are now
reported through server error handling, including failures after a
client unsubscribes or disconnects.
* Expected aborts after a subscription stops are not reported as errors.
Active subscription errors continue through the existing error-response
flow.
* Subscription cleanup errors are now covered by tests, including cases
where subscriptions complete and subsequent queries succeed.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Cursor Agent <[email protected]>

@trpc-bot trpc-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Approved after Alex reviewed stack #7893.

@KATT
KATT added this pull request to the merge queue Nov 4, 2026
Merged via the queue into main with commit b135fde Nov 4, 2026
55 checks passed
@KATT
KATT deleted the cursor/ws-subscription-ownership-fork-3334 branch November 4, 2026 13:37
meefs pushed a commit to meefs/trpc that referenced this pull request Nov 4, 2026
…ed frame can't end the retry (trpc#7892)

<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
Stack (#7893, bottom to top): trpc#7704 → trpc#7892 → trpc#7891.

Stacked on trpc#7704. No issue.

## Why

- `wsClient` sent each request with its `op.id`. `retryLink`
resubscribes with the failed attempt's `op.id`, so the retry goes out
under the same wire id.
- When a subscription's iterator throws, the server sends `error` and
then `stopped` for that id. If the `stopped` reaches the client after
the retry was sent, it matches the retry's pending request:
  - the retry completes: `onComplete` fires and the subscription ends;
- its `started` and data frames are then dropped, and its server
subscription runs on until the socket closes.
- Any other late frame for the failed attempt (`data`, `error`,
`started`) would reach the retry the same way.
- The bug is on `main` too: the new test fails there with the same
assertion.

## What

- `WsClient.request()` gives each subscription to its observable a new
id, counting up per client, and sends that instead of `op.id`. This
covers the request, its `subscription.stop`, and the `RequestManager`
entry.
- Frames for an earlier attempt's id find no request and are dropped.
- Not changed:
  - `op.id` in links, e.g. `loggerLink`;
- resending pending requests on reconnect: they keep their wire id on
the new socket, and `lastEventId` is still tracked on the request;
  - the `request()` signature: `op.id` is still accepted, just not sent.
- The ids the server sees no longer equal `op.id`. Nothing in tRPC
relies on that, and the docs only say the id identifies the
subscription.
- Side effect: two `createTRPCClient`s sharing one `wsClient` no longer
send clashing ids, since both count `op.id` from 1.

## Links

None. There are no docs or example changes.

## Alternatives considered

- **Delete by reference only (trpc#7889).** It stops cleanup removing the
retry, but a late frame is still matched by id, so it can't tell the
attempts apart.
- **Defer or space out retries in `retryLink`.** It narrows the window
but can't close it: the frame can arrive after any delay.
- **Have the server skip `stopped` after an `error`.** The frames would
still cross: a late `data` or `error`, or a `stopped` after a
client-side stop, would still hit the retry.

## Testing

- New `packages/tests/server/websockets.retryAttempts.test.ts`. It uses
`retryLink` + `wsLink` against a real server, with a tracked
subscription that errors after its first event:
- after sending the `error`, the server holds its later frames until it
gets the retry's `subscription` request, then sends them in order. This
stands in for the failed attempt's `stopped` arriving in a later packet;
  - it expects `onData` `[1, 2]`, and no `onComplete` or `onError`.
- Regression check: fails on trpc#7704's head (10c47ed) with
`AssertionError: expected "vi.fn()" to not be called at all, but
actually been called 1 times` at
`expect(onComplete).not.toHaveBeenCalled()`. It fails the same way on
`main` (83391b5). It passes with the fix, 11 of 11 runs.
- `pnpm exec vitest run packages/tests`: 87 files, 682 tests pass.
`packages/tanstack-react-query` and `packages/react-query`: 69 files,
361 tests pass.
- `packages/tests/server/websocket*` with `packages/client` (13 files,
133 tests), 7 runs: one failure, in `websockets.encoder.test.ts`'s
PING/PONG test at `expect(serverWsClients.length).toBe(1)`. That checks
the server has accepted the socket, which doesn't involve request ids,
and it passed 15 of 15 runs on its own.
- `tsc --noEmit` for `packages/client` and `packages/tests`, `oxlint`
and `oxfmt --check` are clean.

**Merges:** `git merge-tree --write-tree` is clean against trpc#7889
(738e78d, now merged), trpc#7891 (f7c0346) and `main` (83391b5).

- With both merged in, the websocket and client tests pass (18 files,
165 tests), and so do both `tsc` runs.
- trpc#7889's delete-by-reference becomes redundant: ids no longer repeat.
Its regression tests pass on this branch without its change. Keeping
both is harmless.
- trpc#7891 touches reconnect and the user callbacks, not `request()`.

## AI model

Claude Opus 5.5
<!-- CURSOR_AGENT_PR_BODY_END -->

<div><a
href="https://cursor.com/agents/bc-9cf4eb23-1980-4dc1-bd36-ff50b58f3334?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a
href="https://cursor.com/background-agent?bcId=bc-9cf4eb23-1980-4dc1-bd36-ff50b58f3334&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img
alt="Open in Cursor" width="131" height="28"
src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;</div>

<!-- codesmith:footer -->
---
<a
href="https://backend.blacksmith.sh/track/enable-autofix?expires=1796388565&installation_model_id=443568&pr_number=7892&ref=codesmith_pr_footer&repository=trpc%2Ftrpc&return_to=https%3A%2F%2Fgithub.com%2Ftrpc%2Ftrpc%2Fpull%2F7892&signature=5e25901a69fd9f955c116cef44ed652a487dca210601d0fc1e402bb3abffe3c3"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-light.svg"><img
alt="Autofix with [code]smith"
src="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png"
width="190" height="28"></picture></a>
<sup><a
href="https://app.blacksmith.sh/trpc/codesmith/trpc/pr/7892?autoLogin=true&ref=codesmith_pr_footer">Open
in [code]smith</a> · Need help on this PR? Tag
<code>@codesmith-bot</code> with what you need.</sup>

<!-- codesmith:autofix:disabled -->
<!-- /codesmith:footer -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

- **Bug Fixes**
- Fixed WebSocket retries so delayed responses from a failed attempt
don’t interfere with the retried subscription.
- Subscriptions can continue receiving events after reconnecting, while
subsequent queries remain available.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Cursor Agent <[email protected]>
meefs pushed a commit to meefs/trpc that referenced this pull request Nov 4, 2026
… when onClose or onError throws (trpc#7891)

<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
Closes trpc#7890

Stack (#7893, bottom to top): trpc#7704 → trpc#7892 → trpc#7891.

## Why

- **A `connectionParams` error on reconnect is swallowed.**
- `tryReconnect` wraps each attempt in a bare `catch {}`
(`wsClient.ts:302`) and retries.
- When `connectionParams` throws or rejects during a reconnect, the
error never reaches the user. The state flips between `pending` and
`connecting` / "WebSocket closed" forever.
- On the first connect, `open()` already reports the same failure:
`connecting` with an `Initialization error` whose `cause` is the thrown
error.
- **A throwing `onClose` or `onError` stops reconnects.**
- The `close` and `error` listeners call the user callback before
`this.reconnect(...)`, so a throw skips the reconnect, and subscriptions
never resume.
- With `ws`, which is an `EventEmitter`, the throw also skips the other
listeners for that event. A throwing `onError` skips `asyncWsOpen`'s
`error` listener, so the open promise never settles. The client hangs,
and even `wsClient.close()` never settles.

## What

- `tryReconnect`'s `catch` reports the error on `connectionState` as the
first connect does (`connecting`, `Initialization error`, with the
cause), then retries with backoff as before.
- It reports nothing once `close()` has turned reconnects off, so the
state still ends on `idle`.
- New `callUserCallback()` in `wsClient.ts` wraps `onClose` and
`onError`.
- A throw no longer stops the listener, so the reconnect still runs, and
so do `ws`'s other listeners.
- The error is rethrown in a `setTimeout`, so it still shows up as an
uncaught exception (or `window.onerror` in browsers), as before. It
isn't swallowed.
- `onOpen` is unchanged. It already runs inside a `catch` that treats a
throw as a failed connection.
- No public API change.

## Links

None. There are no docs or example changes.

## Alternatives considered

- **Fail pending requests and subscriptions with the `connectionParams`
error.** The first connect doesn't do this. It keeps retrying and
reports the error on the connection state, which `wsLink` forwards to
each subscription's `onConnectionStateChange`. Failing them on reconnect
only would be inconsistent, and a transient token-refresh failure would
kill subscriptions that would otherwise recover.
- **Stop retrying after a `connectionParams` error.** That would also
differ from the first connect. Users who want this can watch
`connectionState` and call `close()`.
- **Report the error through `onError`.** Its type is `(evt?: Event) =>
void`, for socket error events, so passing an `Error` would change its
contract.
- **`try { onClose() } finally { reconnect() }`.** This fixes the
reconnect, but the throw still escapes into `ws`'s emitter and skips its
other listeners. For `onError` that leaves the open promise unsettled,
so the client still hangs.
- **Catch and drop the callback error.** That swallows the user's bug,
which is the problem this PR fixes.

## Testing

- New `packages/tests/server/websockets.reconnectErrors.test.ts`. It
uses `wsLink` and `createWSClient` against a real server, with a short
`retryDelayMs`:
- **First connect (parity, passes on `main`):** a throwing
`connectionParams` shows up as `connecting` + `Initialization error`
with the cause, and the subscription starts once it stops throwing.
- **Reconnect:** the same error state appears after the server drops the
connection. Once `connectionParams` recovers, the subscription restarts
(`onStarted` twice), the state is `pending`, and `onError` isn't called.
- **Throwing `onClose`:** the subscription reconnects and gets data
again, and the error is reported once as an uncaught exception.
- **Throwing `onError`** (unused port): the client keeps retrying, every
callback error is reported, and `close()` settles.
- Regression check: on `main` (64c1ef5) plus only the test commits,
three tests fail:
- `expected [ undefined, undefined, …(177) ] to include Error:
connectionParams failed`: the error never reaches the connection state.
- `expected "vi.fn()" to be called 2 times, but got 1 times`:
`onStarted` with a throwing `onClose`, so it never reconnects.
- `expected 1 to be greater than or equal to 3`: `onError` calls, so the
client hung after the first failure.

  With the fix, all four pass.
- `pnpm exec vitest run packages/tests/server/` passes: 89 files, 701
tests. `pnpm exec vitest run packages/client` passes: 10 files, 66
tests.
- The new file passed in 10 of 10 runs.
- `tsc --noEmit` for `packages/client` and `packages/tests`, and
`oxlint` and `oxfmt --check` on the changed files, are clean.

**Merge order:** stacked on trpc#7892, so it merges after trpc#7704 and trpc#7892.

- Rebased this PR's four commits from `main` (64c1ef5) onto trpc#7892's
head (40a8312). There were no conflicts, and `git range-diff` shows
each patch unchanged. New head: 8a24d2b.
- trpc#7892 doesn't touch the `tryReconnect` catch or the `onClose` /
`onError` listeners this PR changes.
- trpc#7888 and trpc#7889 have since merged to `main`. `git merge-tree` of this
head with `main` (83391b5) is clean, and on that merge the websocket
test files and `packages/client` pass: 19 files, 169 tests.
- On the rebased head, the websocket test files (6 files, 92 tests) and
`packages/client` (8 files, 45 tests) pass. `tsc --noEmit` for
`packages/client`, `packages/tests` and `packages/server`, and `oxlint`
and `oxfmt --check` on the files changed across the stack, are clean.

## AI model

Claude Opus 5.5
<!-- CURSOR_AGENT_PR_BODY_END -->

<div><a
href="https://cursor.com/agents/bc-9cf4eb23-1980-4dc1-bd36-ff50b58f3334?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a
href="https://cursor.com/background-agent?bcId=bc-9cf4eb23-1980-4dc1-bd36-ff50b58f3334&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img
alt="Open in Cursor" width="131" height="28"
src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;</div>

<!-- codesmith:footer -->
---
<a
href="https://backend.blacksmith.sh/track/enable-autofix?expires=1796387395&installation_model_id=443568&pr_number=7891&ref=codesmith_pr_footer&repository=trpc%2Ftrpc&return_to=https%3A%2F%2Fgithub.com%2Ftrpc%2Ftrpc%2Fpull%2F7891&signature=2ababa847ae548bc839d5e382ac03bb14a27a55573e687137c2b07475d92d8a5"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-light.svg"><img
alt="Autofix with [code]smith"
src="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png"
width="190" height="28"></picture></a>
<sup><a
href="https://app.blacksmith.sh/trpc/codesmith/trpc/pr/7891?autoLogin=true&ref=codesmith_pr_footer">Open
in [code]smith</a> · Need help on this PR? Tag
<code>@codesmith-bot</code> with what you need.</sup>

<!-- codesmith:autofix:disabled -->
<!-- /codesmith:footer -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* WebSocket connection setup errors are now surfaced in the connection
state during retries, while reconnection attempts continue.
* Exceptions thrown by close and error callbacks no longer interrupt
WebSocket event handling or prevent retries. These exceptions are still
reported as uncaught errors.
* Canceling or completing a WebSocket subscription now reliably releases
its resources, including when cancellation occurs during setup.
* Retried subscriptions continue receiving events when delayed messages
from an earlier attempt arrive.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Cursor Agent <[email protected]>
cursor Bot pushed a commit that referenced this pull request Nov 4, 2026
… interop handler

A subscription stopped before it starts gets no terminal message, so
wsLink can't tell its id is free. These tests expect `stopped`, as
v11's adapter sends since #7704.

Co-authored-by: Alex / KATT <[email protected]>
cursor Bot pushed a commit that referenced this pull request Nov 4, 2026
wsLink holds a subscription's id until its `stopped`. A
`subscription.stop` that interrupted the call before `started` sent
nothing, so the id was never released, unlike v11's adapter since
#7704. A closed socket's calls still send nothing, so
dispose() keeps leaving wsLink to resend its subscriptions.

Co-authored-by: Alex / KATT <[email protected]>
cursor Bot pushed a commit that referenced this pull request Nov 4, 2026
…ate (port of #7704)

Interrupting a call (a stop, an abort or a closed socket) while its
resolver's promise is pending abandons the promise. When it later
resolved with an async iterable, nothing called its `return()`, so
whatever the procedure had opened for it stayed open; when it rejected,
the error vanished. v11's adapter disposes that iterable without
reading it, and reports the rejection, since #7704.

The resolver's promise is now awaited through `Effect.callback`: once
the call is interrupted, an iterable it resolves with is disposed with
`return()`, and a rejection other than an `AbortError` goes to the
call's `CurrentLateErrors`, so `onError` hears it.

Co-authored-by: Alex / KATT <[email protected]>
cursor Bot pushed a commit that referenced this pull request Nov 4, 2026
…l (port of #7704)

A subscription's signal aborted only when its call was interrupted. When
its iterator's `next()` failed instead, the iterator's `return()` ran
with the signal still live, so a cleanup that waits for it never
finished. v11's adapter aborts the signal whenever iteration ends other
than by `done`, before the iterator's cleanup, since #7704.

`interruptSignal()` gets `abortUnlessDone`, which aborts when a stream
fails as well as when it's interrupted, and the v11 interop socket and
the native socket wrap a subscription's events in it. A subscription
that completes still keeps its signal; `abortOnInterrupt` is unchanged.

Co-authored-by: Alex / KATT <[email protected]>
cursor Bot pushed a commit that referenced this pull request Nov 4, 2026
… interop handler

A subscription stopped before it starts gets no terminal message, so
wsLink can't tell its id is free. These tests expect `stopped`, as
v11's adapter sends since #7704.

Co-authored-by: Alex / KATT <[email protected]>
cursor Bot pushed a commit that referenced this pull request Nov 4, 2026
wsLink holds a subscription's id until its `stopped`. A
`subscription.stop` that interrupted the call before `started` sent
nothing, so the id was never released, unlike v11's adapter since
#7704. A closed socket's calls still send nothing, so
dispose() keeps leaving wsLink to resend its subscriptions.

Co-authored-by: Alex / KATT <[email protected]>
cursor Bot pushed a commit that referenced this pull request Nov 4, 2026
…ate (port of #7704)

Interrupting a call (a stop, an abort or a closed socket) while its
resolver's promise is pending abandons the promise. When it later
resolved with an async iterable, nothing called its `return()`, so
whatever the procedure had opened for it stayed open; when it rejected,
the error vanished. v11's adapter disposes that iterable without
reading it, and reports the rejection, since #7704.

The resolver's promise is now awaited through `Effect.callback`: once
the call is interrupted, an iterable it resolves with is disposed with
`return()`, and a rejection other than an `AbortError` goes to the
call's `CurrentLateErrors`, so `onError` hears it.

Co-authored-by: Alex / KATT <[email protected]>
cursor Bot pushed a commit that referenced this pull request Nov 4, 2026
…l (port of #7704)

A subscription's signal aborted only when its call was interrupted. When
its iterator's `next()` failed instead, the iterator's `return()` ran
with the signal still live, so a cleanup that waits for it never
finished. v11's adapter aborts the signal whenever iteration ends other
than by `done`, before the iterator's cleanup, since #7704.

`interruptSignal()` gets `abortUnlessDone`, which aborts when a stream
fails as well as when it's interrupted, and the v11 interop socket and
the native socket wrap a subscription's events in it. A subscription
that completes still keeps its signal; `abortOnInterrupt` is unchanged.

Co-authored-by: Alex / KATT <[email protected]>
cursor Bot pushed a commit that referenced this pull request Nov 4, 2026
… interop handler

A subscription stopped before it starts gets no terminal message, so
wsLink can't tell its id is free. These tests expect `stopped`, as
v11's adapter sends since #7704.

Co-authored-by: Alex / KATT <[email protected]>
cursor Bot pushed a commit that referenced this pull request Nov 4, 2026
wsLink holds a subscription's id until its `stopped`. A
`subscription.stop` that interrupted the call before `started` sent
nothing, so the id was never released, unlike v11's adapter since
#7704. A closed socket's calls still send nothing, so
dispose() keeps leaving wsLink to resend its subscriptions.

Co-authored-by: Alex / KATT <[email protected]>
cursor Bot pushed a commit that referenced this pull request Nov 4, 2026
…ate (port of #7704)

Interrupting a call (a stop, an abort or a closed socket) while its
resolver's promise is pending abandons the promise. When it later
resolved with an async iterable, nothing called its `return()`, so
whatever the procedure had opened for it stayed open; when it rejected,
the error vanished. v11's adapter disposes that iterable without
reading it, and reports the rejection, since #7704.

The resolver's promise is now awaited through `Effect.callback`: once
the call is interrupted, an iterable it resolves with is disposed with
`return()`, and what that or the rejection fails with goes to the call's
`SubscriptionTeardown`, so a subscription's `onError` hears it (an
`AbortError` excepted).

Co-authored-by: Alex / KATT <[email protected]>
cursor Bot pushed a commit that referenced this pull request Nov 4, 2026
…l (port of #7704)

A subscription's signal aborted only when its call was interrupted. When
its iterator's `next()` failed instead, the iterator's `return()` ran
with the signal still live, so a cleanup that waits for it never
finished. v11's adapter aborts the signal whenever iteration ends other
than by `done`, before the iterator's cleanup, since #7704.

`interruptSignal()` gets `abortUnlessDone`, which aborts when a stream
fails as well as when it's interrupted, and the v11 interop socket and
the native socket wrap a subscription's events in it. A subscription
that completes still keeps its signal; `abortOnInterrupt` is unchanged.

Co-authored-by: Alex / KATT <[email protected]>
meefs pushed a commit to meefs/trpc that referenced this pull request Nov 4, 2026
…hem with `pnpm release notes` (trpc#7903)

<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
## Why

- `pnpm release` (trpc#7832) creates the GitHub release with
`--generate-notes`: one flat list of every PR since the last tag.
- For v11.24.1 that's 18 entries. 10 are www/sponsor PRs, and six
`feat(www)` items sit above the real fixes.
- v11.24.0's notes were cleaned up by hand. This does that cleanup in
the tooling.

## What

- New `tooling/release/src/notes.ts`. `releaseNotes(root, { previousTag,
tag, to?, repo? })` returns the notes' Markdown. trpc#7837 can call the same
function.
- It walks the first-parent commits in `previousTag..to` and finds the
public packages each one changes: any file under `packages/<dir>/`
except `*.md`.
- It groups them under `## @trpc/<pkg>` (server first, in publish
order), then `### Breaking Changes` / `Features` / `Fixes` /
`Performance` / `Reverts` / … / `Other Changes`, from the
conventional-commit type.
- One bullet per PR: `* <title> by @<author> in <PR url>`. A PR that
changes several packages is listed under each. PRs that change no public
package (www, tooling, examples, README-only) are left out. So are
release commits (`chore: release vX`, lerna's `vX`).
- Titles and authors come from one GitHub GraphQL query. Commits without
`(#N)` link to the commit instead.
- New Contributors: taken from GitHub's own generate-notes (read-only
call), kept only when their first PR is in the notes.
  - Ends with the `**Full Changelog**` compare link.
- `githubRelease` passes these notes with `--notes` instead of
`--generate-notes`. This also covers `pnpm release github-release
<tag>`.
- Preview without releasing:
- `pnpm release notes [<tag>] [--to <ref>]` prints the notes. An
existing tag gets its own notes. Otherwise it previews the next patch
release of `--to` (default `HEAD`).
- `pnpm release stable <bump> --dry-run` now prints the notes it would
publish.
- No workflow changes. Nothing is published or tagged.

Output for `pnpm release notes v11.24.1 --to origin/main`:

```markdown
## @trpc/server

### Fixes

* fix(server): settle pending next() on abort and ignore teardown emissions in observableToAsyncIterable by @KATT in trpc#7867
* fix(server): don't crash when a subscription's teardown throws on abort by @KATT in trpc#7884
* fix(server): report a ws subscription's cleanup error after the client stops it by @KATT in trpc#7888
* fix(server): keep websocket subscriptions owned through setup and cleanup by @KATT in trpc#7704

## @trpc/client

### Fixes

* fix(client): send a wsLink request that retryLink retries with the same id by @KATT in trpc#7889
* fix(client): give each wsLink attempt its own wire id so a late stopped frame can't end the retry by @KATT in trpc#7892
* fix(client): surface wsClient reconnect errors, and keep reconnecting when onClose or onError throws by @KATT in trpc#7891
* fix(client): keep wsClient reconnecting when onConnectionStateChange throws by @KATT in trpc#7896

**Full Changelog**: trpc/trpc@v11.24.0...v11.24.1
```

## Links

None. This is release tooling; no docs or example changes.

## Alternatives considered

- A `.github/release.yml` with label categories. The labeler hasn't
added a label since 2023 (its config uses the v4 syntax under
`actions/labeler@v7`), and labels can't group by package.
- Filtering GitHub's generated notes down to trpc#7837's
`releasableCommits`. That would still give a flat list. The spec also
asks for "any non-Markdown file in the package", which is looser than
`releasableCommits` (it counts tests and other files in the package
directory, not just shipped files).

## Testing

- `tooling/release/src/notes.test.ts` (14 tests) covers: grouping by
package and type, a PR under each package it changes, skipping
www/README-only/release commits, section order (breaking first, other
last), GitHub titles and commit fallback, merging commits of one PR, the
New Contributors filter, the empty case, parsing GitHub's new
contributors, and `changesBetween` against a temp git repo.
- `pnpm vitest run --project release`: 40 tests pass. `pnpm test --
--watch false`: 218 files pass. `tsc` and `oxlint` are clean in
`tooling/release`.
- Ran it for real over `v11.24.0..main` (output above), and over the
v11.20.0 to v11.24.0 tags to check the existing-tag path and New
Contributors.
- Not run: a full `pnpm release stable patch --dry-run`, which builds
and packs everything. Its notes step is the same `releaseNotes` call.

## AI model

Claude Opus 5.5
<!-- CURSOR_AGENT_PR_BODY_END -->

<div><a
href="https://cursor.com/agents/bc-3ecf1435-3056-5f1d-a782-424acb0f117e?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a
href="https://cursor.com/background-agent?bcId=bc-3ecf1435-3056-5f1d-a782-424acb0f117e&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img
alt="Open in Cursor" width="131" height="28"
src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;</div>

<!-- codesmith:footer -->
---
<a
href="https://backend.blacksmith.sh/track/enable-autofix?expires=1796399234&installation_model_id=443568&pr_number=7903&ref=codesmith_pr_footer&repository=trpc%2Ftrpc&return_to=https%3A%2F%2Fgithub.com%2Ftrpc%2Ftrpc%2Fpull%2F7903&signature=50b6bceac891b5be7f6d29cbc2112f0c552927c5d76e10454276d71f885361bd"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-light.svg"><img
alt="Autofix with [code]smith"
src="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png"
width="190" height="28"></picture></a>
<sup><a
href="https://app.blacksmith.sh/trpc/codesmith/trpc/pr/7903?autoLogin=true&ref=codesmith_pr_footer">Open
in [code]smith</a> · Need help on this PR? Tag
<code>@codesmith-bot</code> with what you need.</sup>

<!-- codesmith:autofix:disabled -->
<!-- /codesmith:footer -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* Added a release-notes command to display notes for an existing release
or preview changes through a specified point in project history.
* Release notes are grouped by package and include pull request or
commit details, contributor credits, and a link to the full changelog.
Changes without a recognized category appear under “Other Changes.”
* Release creation uses the generated notes, which are also shown during
stable-release previews.
* **Bug Fixes**
* Clarified command usage and restricted release-note options to
supported combinations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Cursor Agent <[email protected]>
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 5, 2026

This branch was successfully deployed

6 active (1 outdated) deployments
Preview – www — 10c47ede Deployed Nov 3, 2026 by vercel[bot]
Preview – examples-next-minimal-starter — 10c47ede Deployed Nov 3, 2026 by vercel[bot]
Preview – trpc-next-app-dir — 10c47ede Deployed Nov 3, 2026 by vercel[bot]
Preview – next-prisma-starter — 10c47ede Deployed Nov 3, 2026 by vercel[bot]
Preview – examples-todomvc — 10c47ede Deployed Nov 3, 2026 by vercel[bot]
Preview – og-image — d63ee5e4 Deployed Oct 20, 2026 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants