Skip to content

feat(hibernation): Hibernation APIs - #1763

Merged
dinwwwh merged 4 commits into
middleapi:mainfrom
dinwwwh:claude/orpc-v2-hibernation-08c0f5
Aug 3, 2026
Merged

feat(hibernation): Hibernation APIs#1763
dinwwwh merged 4 commits into
middleapi:mainfrom
dinwwwh:claude/orpc-v2-hibernation-08c0f5

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Aug 2, 2026

Copy link
Copy Markdown
Member

Ports the v1 @orpc/server/hibernation module to v2 as a dedicated @orpc/hibernation package, so Cloudflare WebSocket Hibernation (and similar) setups work again on v2. The plugin preserves HibernationAsyncIteratorClass outputs through the RPC codec, and encodeHibernationRPCEvent emits peer event-stream messages that are byte-identical to what the normal transmitter sends — clients consume hibernated streams exactly like regular ones.

API changes vs v1

  • v2 naming (HibernationHandlerPlugin, HibernationAsyncIteratorClass) with deprecated v1 aliases so old imports keep compiling and point at the new names.
  • encodeHibernationRPCEvent is now async, takes a serializer instance (shareable with RPCHandler) and a dedicated encodePeerMessage options field; the 'done' event became 'close' to match the peer protocol.
  • The plugin runs as a routing interceptor and declares before: ['~batch']; evlog/pino logging plugins now order themselves before ~hibernation as well.

Docs

  • New Plugins page with v2 imports and an updated Cloudflare Durable Object chat-room example, including a warning that hibernation procedures must be excluded from batching.
  • @orpc/hibernation added to the package list in all READMEs.

Testing

  • 14 new tests cover the plugin (standard handler + websocket end-to-end: the callback receives the request id, only the response message hits the wire, later events decode as event-stream messages for that id) and the encoder (byte parity with encodePeerMessage, event meta, close/error events, prefix, undefined payloads).
  • Full pnpm type:check, lint, and unbuild pass; server/evlog/pino suites unaffected (450 tests green).

Port the v1 @orpc/server/hibernation module onto the v2 architecture as a
dedicated @orpc/hibernation package. HibernationHandlerPlugin restores the
HibernationAsyncIteratorClass response body that the RPC codec would
otherwise wrap, and encodeHibernationRPCEvent produces peer event-stream
messages byte-identical to the normal transmitter output.

- v2 API naming with deprecated v1 aliases (HibernationPlugin,
  HibernationEventIterator)
- encodeHibernationRPCEvent accepts a serializer instance and
  encodePeerMessage options; v1 event 'done' became 'close' to match the
  peer protocol
- evlog/pino logging plugins order themselves before ~hibernation
- docs page under Plugins with updated v2 examples; @orpc/hibernation added
  to the package list in all READMEs
@vercel

vercel Bot commented Aug 2, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
orpc Ready Ready Preview Aug 3, 2026 2:01am

@pkg-pr-new

pkg-pr-new Bot commented Aug 2, 2026

Copy link
Copy Markdown
More templates

@orpc/ai-sdk

npm i https://pkg.pr.new/middleapi/orpc/@orpc/ai-sdk@1763

@orpc/arktype

npm i https://pkg.pr.new/middleapi/orpc/@orpc/arktype@1763

@orpc/bun

npm i https://pkg.pr.new/middleapi/orpc/@orpc/bun@1763

@orpc/client

npm i https://pkg.pr.new/middleapi/orpc/@orpc/client@1763

@orpc/cloudflare

npm i https://pkg.pr.new/middleapi/orpc/@orpc/cloudflare@1763

@orpc/contract

npm i https://pkg.pr.new/middleapi/orpc/@orpc/contract@1763

@orpc/experimental-effect

npm i https://pkg.pr.new/middleapi/orpc/@orpc/experimental-effect@1763

@orpc/evlog

npm i https://pkg.pr.new/middleapi/orpc/@orpc/evlog@1763

@orpc/hibernation

npm i https://pkg.pr.new/middleapi/orpc/@orpc/hibernation@1763

@orpc/json-schema

npm i https://pkg.pr.new/middleapi/orpc/@orpc/json-schema@1763

@orpc/nest

npm i https://pkg.pr.new/middleapi/orpc/@orpc/nest@1763

@orpc/next

npm i https://pkg.pr.new/middleapi/orpc/@orpc/next@1763

@orpc/openapi

npm i https://pkg.pr.new/middleapi/orpc/@orpc/openapi@1763

@orpc/opentelemetry

npm i https://pkg.pr.new/middleapi/orpc/@orpc/opentelemetry@1763

@orpc/pinia-colada

npm i https://pkg.pr.new/middleapi/orpc/@orpc/pinia-colada@1763

@orpc/pino

npm i https://pkg.pr.new/middleapi/orpc/@orpc/pino@1763

@orpc/publisher

npm i https://pkg.pr.new/middleapi/orpc/@orpc/publisher@1763

@orpc/ratelimit

npm i https://pkg.pr.new/middleapi/orpc/@orpc/ratelimit@1763

@orpc/server

npm i https://pkg.pr.new/middleapi/orpc/@orpc/server@1763

@orpc/shared

npm i https://pkg.pr.new/middleapi/orpc/@orpc/shared@1763

@orpc/swr

npm i https://pkg.pr.new/middleapi/orpc/@orpc/swr@1763

@orpc/tanstack-query

npm i https://pkg.pr.new/middleapi/orpc/@orpc/tanstack-query@1763

@orpc/trpc

npm i https://pkg.pr.new/middleapi/orpc/@orpc/trpc@1763

@orpc/valibot

npm i https://pkg.pr.new/middleapi/orpc/@orpc/valibot@1763

@orpc/zod

npm i https://pkg.pr.new/middleapi/orpc/@orpc/zod@1763

commit: 5cada09

@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed-hq

codspeed-hq Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 25 untouched benchmarks


Comparing dinwwwh:claude/orpc-v2-hibernation-08c0f5 (5cada09) with main (d9d031f)

Open in CodSpeed

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes — port of v1 hibernation module to v2 as a new @orpc/hibernation package with plugin, encoder, deprecated aliases, docs, and README updates.

  • New @orpc/hibernation packageHibernationHandlerPlugin (routing + client interceptor), encodeHibernationRPCEvent, and HibernationAsyncIteratorClass re-export
  • Plugin ordering updates@orpc/pino and @orpc/evlog now declare before: ['~hibernation'] so logging interceptors run before the hibernation plugin
  • Docs and READMEs — VitePress page with Cloudflare Durable Object chat-room example; 20+ package READMEs now list @orpc/hibernation

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@dinwwwh dinwwwh changed the title feat(hibernation): port Hibernation APIs to v2 as @orpc/hibernation feat(hibernation): Hibernation APIs Aug 2, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes — updated docs examples to v2-idiomatic os.$context<>() patterns and added a full Cloudflare Durable Object chat room playground with hibernation.

  • Docs example modernizationonMessage and sendMessage procedures updated to use $context and .input() chaining instead of bare os.handler()
  • Cloudflare playgroundHibernationChatRoom component, chat-room.ts client with RPCLink + reconnect, and ChatRoomDO server with withoutOpenTelemetry() helper for the DO's webSocketMessage/webSocketClose handlers
  • Wrangler configCHAT_ROOM_DON binding and migration added to wrangler.jsonc

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Hibernation integrates an external platform API (Cloudflare's Hibernation
WebSocket) rather than adding an oRPC-defined pipeline feature, so the page
fits Integrations better than Plugins. Update sidebar and @see links
accordingly.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes — moved hibernation docs into the integrations section and inlined the OTEL disable helper in the playground DO.

  • Docs reorganized to integrations — hibernation page moved from docs/plugins/ to docs/integrations/, sidebar link and page heading renamed to "Hibernation Integration", and JSDoc URLs in encode-event.ts and handler-plugin.ts updated to match
  • Playground OTEL helper inlinedwithoutOpenTelemetry() wrapper removed from ChatRoomDO; each webSocketMessage/webSocketClose handler now creates and disables an ORPCInstrumentation instance directly

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@dinwwwh
dinwwwh merged commit db548c8 into middleapi:main Aug 3, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant