Skip to content

fix(rpc): add makeMsgPack for configurable msgpackr options#2049

Merged
tim-smart merged 2 commits into
Effect-TS:mainfrom
bohdanbirdie:fix/rpc-msgpack-cf-workers
Apr 18, 2026
Merged

fix(rpc): add makeMsgPack for configurable msgpackr options#2049
tim-smart merged 2 commits into
Effect-TS:mainfrom
bohdanbirdie:fix/rpc-msgpack-cf-workers

Conversation

@bohdanbirdie

Copy link
Copy Markdown
Contributor

Problem

RpcSerialization.msgPack silently fails on Cloudflare Workers when decoding messages with 3+ same-structure objects. The Packr/Unpackr are constructed with useRecords: true, which enables msgpackr's record path. When the JIT threshold is reached, msgpackr calls new Function() — blocked by CF Workers during request handling — and the catch { return [] } in the decode path silently swallows the resulting EvalError.

Solution

Add RpcSerialization.makeMsgPack(options) factory accepting msgpackr.Options. CF Workers users pass { useRecords: false }:

Layer.succeed(RpcSerialization)(
  RpcSerialization.makeMsgPack({ useRecords: false })
)

Existing msgPack / layerMsgPack exports are unchanged. Also rethrows non-incomplete decode errors instead of returning [].

Same fix as v3: Effect-TS/effect#6161
Reproduction: https://github.com/bohdanbirdie/repro-effect-rpc-msgpack-cf-workers

@changeset-bot

changeset-bot Bot commented Apr 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 79bc12f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 26 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@bohdanbirdie bohdanbirdie marked this pull request as ready for review April 17, 2026 22:52
Comment thread packages/effect/src/unstable/rpc/RpcSerialization.ts Outdated
bohdanbirdie and others added 2 commits April 18, 2026 20:47
Adds `makeMsgPack(options)` factory that accepts `msgpackr.Options`,
allowing Cloudflare Workers users to pass `{ useRecords: false }` to
prevent msgpackr's JIT code generation via `new Function()`, which is
blocked during request handling.

Existing `msgPack` and `layerMsgPack` exports are unchanged (no
breaking change).

Also fixes silent error swallowing in the msgPack decode path —
non-incomplete errors are now rethrown instead of returning `[]`.
@tim-smart tim-smart force-pushed the fix/rpc-msgpack-cf-workers branch from a1b054c to 79bc12f Compare April 18, 2026 08:50
@tim-smart tim-smart enabled auto-merge (squash) April 18, 2026 08:50
@tim-smart tim-smart merged commit 778d2af into Effect-TS:main Apr 18, 2026
15 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

File Name Current Size Previous Size Difference
basic.ts 6.73 KB 6.73 KB 0.00 KB (0.00%)
batching.ts 9.23 KB 9.23 KB 0.00 KB (0.00%)
brand.ts 6.37 KB 6.37 KB 0.00 KB (0.00%)
cache.ts 9.98 KB 9.98 KB 0.00 KB (0.00%)
config.ts 18.37 KB 18.37 KB 0.00 KB (0.00%)
differ.ts 16.80 KB 16.80 KB 0.00 KB (0.00%)
http-client.ts 20.12 KB 20.12 KB 0.00 KB (0.00%)
logger.ts 9.20 KB 9.20 KB 0.00 KB (0.00%)
metric.ts 8.57 KB 8.57 KB 0.00 KB (0.00%)
optic.ts 7.61 KB 7.61 KB 0.00 KB (0.00%)
pubsub.ts 14.09 KB 14.09 KB 0.00 KB (0.00%)
queue.ts 11.08 KB 11.08 KB 0.00 KB (0.00%)
schedule.ts 10.29 KB 10.29 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 26.11 KB 26.11 KB 0.00 KB (0.00%)
schema-string-transformation.ts 12.05 KB 12.05 KB 0.00 KB (0.00%)
schema-string.ts 10.36 KB 10.36 KB 0.00 KB (0.00%)
schema-template-literal.ts 13.98 KB 13.98 KB 0.00 KB (0.00%)
schema-toArbitraryLazy.ts 18.44 KB 18.44 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 21.13 KB 21.13 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 17.65 KB 17.65 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 17.61 KB 17.61 KB 0.00 KB (0.00%)
schema-toFormatter.ts 17.44 KB 17.44 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 19.97 KB 19.97 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 18.03 KB 18.03 KB 0.00 KB (0.00%)
schema.ts 17.02 KB 17.02 KB 0.00 KB (0.00%)
stm.ts 11.93 KB 11.93 KB 0.00 KB (0.00%)
stream.ts 9.26 KB 9.26 KB 0.00 KB (0.00%)

@github-actions

Copy link
Copy Markdown
Contributor

📊 JSDoc Documentation Analysis

📈 Current Analysis Results
Analyzing 135 TypeScript files in packages/effect/src/ (including schema and config subdirectories)...

============================================================
         EFFECT JSDOC ANALYSIS REPORT
============================================================

📊 SUMMARY STATISTICS
------------------------------
Total files analyzed: 135
Total exported members: 4310
Missing @example: 2177 (50.5%)
Missing @category: 396 (9.2%)

🎯 TOP FILES NEEDING ATTENTION
----------------------------------------
1. Schema.ts
   📝 515 missing examples, 🏷️  202 missing categories
   📦 515 total exports
2. Array.ts
   📝 135 missing examples, 🏷️  2 missing categories
   📦 140 total exports
3. SchemaRepresentation.ts
   📝 96 missing examples, 🏷️  12 missing categories
   📦 96 total exports
4. SchemaAST.ts
   📝 77 missing examples, 🏷️  21 missing categories
   📦 77 total exports
5. Cause.ts
   📝 79 missing examples, 🏷️  2 missing categories
   📦 79 total exports
6. Channel.ts
   📝 81 missing examples, 🏷️  0 missing categories
   📦 152 total exports
7. SchemaTransformation.ts
   📝 42 missing examples, 🏷️  30 missing categories
   📦 42 total exports
8. Option.ts
   📝 66 missing examples, 🏷️  3 missing categories
   📦 66 total exports
9. Sink.ts
   📝 64 missing examples, 🏷️  2 missing categories
   📦 81 total exports
10. Predicate.ts
   📝 57 missing examples, 🏷️  0 missing categories
   📦 57 total exports
11. SchemaGetter.ts
   📝 51 missing examples, 🏷️  0 missing categories
   📦 51 total exports
12. Result.ts
   📝 46 missing examples, 🏷️  0 missing categories
   📦 46 total exports
13. Config.ts
   📝 35 missing examples, 🏷️  6 missing categories
   📦 35 total exports
14. Types.ts
   📝 39 missing examples, 🏷️  0 missing categories
   📦 39 total exports
15. Effect.ts
   📝 31 missing examples, 🏷️  2 missing categories
   📦 253 total exports

✅ PERFECTLY DOCUMENTED FILES
-----------------------------------
   Chunk.ts (86 exports)
   Clock.ts (5 exports)
   FiberHandle.ts (15 exports)
   FiberMap.ts (19 exports)
   FiberSet.ts (14 exports)
   HKT.ts (4 exports)
   HashMap.ts (44 exports)
   HashSet.ts (21 exports)
   Match.ts (57 exports)
   MutableRef.ts (17 exports)
   NonEmptyIterable.ts (3 exports)
   Random.ts (9 exports)
   Redacted.ts (9 exports)
   RegExp.ts (3 exports)
   Symbol.ts (1 exports)
   Trie.ts (29 exports)
   TxChunk.ts (22 exports)
   TxDeferred.ts (7 exports)
   TxHashMap.ts (41 exports)
   TxHashSet.ts (24 exports)
   TxPriorityQueue.ts (19 exports)
   TxReentrantLock.ts (17 exports)
   TxRef.ts (7 exports)
   TxSemaphore.ts (14 exports)
   TxSubscriptionRef.ts (12 exports)
   Unify.ts (8 exports)
   index.ts (0 exports)

🔍 SAMPLE MISSING ITEMS FROM Schema.ts
-----------------------------------
   Optionality (type, line 151): missing example, category
   Mutability (type, line 160): missing example, category
   ConstructorDefault (type, line 170): missing example, category
   MakeOptions (interface, line 184): missing example, category
   Bottom (interface, line 212): missing example, category
   declareConstructor (interface, line 270): missing example
   declareConstructor (function, line 334): missing example
   declare (interface, line 361): missing example
   declare (function, line 394): missing example
   revealBottom (function, line 434): missing example, category

📋 BREAKDOWN BY EXPORT TYPE
-----------------------------------
const: 1123 missing examples, 114 missing categories
interface: 344 missing examples, 90 missing categories
type: 251 missing examples, 79 missing categories
function: 353 missing examples, 93 missing categories
namespace: 48 missing examples, 20 missing categories
class: 58 missing examples, 0 missing categories

📈 DOCUMENTATION PROGRESS
------------------------------
Examples: 2133/4310 (49.5% complete)
Categories: 3914/4310 (90.8% complete)

============================================================
Analysis complete! 2573 items need attention.
============================================================

📄 Detailed results saved to: jsdoc-analysis-results.json

This comment is automatically updated on each push. View the analysis script for details.

@bohdanbirdie

Copy link
Copy Markdown
Contributor Author

@tim-smart would it be possible to merge the same PR for v3? I applied the same changes you suggested here
Effect-TS/effect#6161

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.

2 participants