Skip to content

fix: forward isCompatible from _saveTypedStructures to saveStructures#6

Open
kriszyp wants to merge 1 commit into
mainfrom
kris/cas-iscompatible-forward
Open

fix: forward isCompatible from _saveTypedStructures to saveStructures#6
kriszyp wants to merge 1 commit into
mainfrom
kris/cas-iscompatible-forward

Conversation

@kriszyp

@kriszyp kriszyp commented Jun 23, 2026

Copy link
Copy Markdown
Member

Summary

_saveTypedStructures now forwards isCompatible as the second argument to saveStructures, matching msgpackr's own pack call site (saveStructures(newSharedData, newSharedData.isCompatible)).

Why

prepareStructures attaches isCompatible to the returned structures object, but _saveTypedStructures called this.saveStructures(structures) and dropped it. A saveStructures implementation that runs an optimistic CAS on the parameter (e.g. Harper's RocksDB RecordEncoder override) then sees undefined and a concurrent same-length typed-struct save can silently clobber the previously persisted struct. See HarperFast/harper#1441 / #1442.

Scope / where to look

One-line fix plus a regression test. The test exercises _saveTypedStructures directly because the fast path (msgpackr ≥ 2 with struct hooks) saves structures via the base class's own pack call site, which already passes isCompatible — so the bug only bites consumers on the standalone path (a base without SUPPORTS_STRUCT_HOOKS, e.g. cbor-x) or any saveStructures that CASes on the parameter. The test asserts the forwarded arg is the isCompatible that prepareStructures attached, and fails without the fix.

🤖 Generated by an LLM (Claude Opus 4.8), defense-in-depth follow-up to the harper#1453 investigation with @kriszyp.

_saveTypedStructures called this.saveStructures(structures) without forwarding
the isCompatible function that prepareStructures attaches to the returned
structures. A saveStructures implementation that runs an optimistic CAS on the
second parameter (e.g. Harper's RocksDB override) therefore saw `undefined`, so
a concurrent same-length typed-struct save could silently clobber the previously
persisted struct. Forward it as the second arg, matching msgpackr's own pack call
site (saveStructures(newSharedData, newSharedData.isCompatible)).

See HarperFast/harper#1441 / #1442.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@kriszyp kriszyp requested review from cb1kenobi and ldt1996 June 23, 2026 13:25
@kriszyp kriszyp marked this pull request as ready for review June 23, 2026 13:26

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request updates _saveTypedStructures in index.js to forward structures.isCompatible as the second argument to this.saveStructures, matching msgpackr's call site behavior and preventing potential concurrency issues where same-length saves could clobber each other. A corresponding regression test has been added in tests/test.js to verify this behavior. There are no review comments, and I have no additional feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

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