Skip to content

Cap the typed-structure dictionary in RecordEncoder (v5.0, maxOwnStructures) - #1146

Merged
kriszyp merged 2 commits into
v5.0from
kris/maxownstructures-v50
Jun 5, 2026
Merged

Cap the typed-structure dictionary in RecordEncoder (v5.0, maxOwnStructures)#1146
kriszyp merged 2 commits into
v5.0from
kris/maxownstructures-v50

Conversation

@kriszyp

@kriszyp kriszyp commented Jun 5, 2026

Copy link
Copy Markdown
Member

Summary

v5.0 backport: defaults maxOwnStructures to 256 in RecordEncoder and bumps msgpackr to 1.11.13 (which adds the typed-struct cap). This is the deployed-line fix for the unbounded typed-structure dictionary that OOM-crash-looped a production cluster.

Purpose

msgpackr's random-access typed-struct dictionary (typedStructs + transition trie) is append-only and pinned on the long-lived primary-store encoder/decoder, and branches per field on the value's numeric width / string kind — so a wide/sparse schema explodes into tens of thousands of structures and grows unbounded (per-table-per-peer dictionaries × worker isolates), OOM-ing under replication catch-up of a bulk-loaded table.

msgpackr@1.11.13 adds an opt-in maxOwnStructures cap to the typed-struct path (uncapped by default; the classic shared-record cap is unchanged — see kriszyp/msgpackr#185). This wires it on at 256 (caller-overridable). Once hit, novel shapes fall back to plain msgpack; the read path is untouched so existing/persisted structs stay decodable. Mirrors the main-branch change (#1145, which uses structon for the v5.1 line).

Where to look

  • One-line change in resources/RecordEncoder.ts (options.maxOwnStructures ??= 256 before super(options)) + the msgpackr patch bump.

Validation

🤖 Generated by Claude (Opus 4.7).

The per-encoder typedStructs dictionary (msgpackr's random-access typed structs)
is append-only and pinned on the long-lived primary store. A wide/sparse schema
whose records vary by per-field value width mints a distinct structure per
shape×width combination and grows the dictionary unbounded, exhausting memory
(observed on a bulk-loaded table under replication catch-up).

Default maxOwnStructures to 256 (caller-overridable), bounding each dictionary.
Bumps msgpackr to 1.11.13, which adds the typed-struct cap (uncapped by default;
classic shared-record cap unchanged).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@kriszyp
kriszyp requested a review from cb1kenobi June 5, 2026 05:50
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedmsgpackr@​1.11.12 ⏵ 1.11.13100 +1100100 +194 +3100

View full report

@kriszyp
kriszyp marked this pull request as ready for review June 5, 2026 14:02
@kriszyp
kriszyp requested a review from a team as a code owner June 5, 2026 14:02
@kriszyp
kriszyp merged commit 5cf0626 into v5.0 Jun 5, 2026
33 of 41 checks passed
@kriszyp
kriszyp deleted the kris/maxownstructures-v50 branch June 5, 2026 14:02
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